Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
3faa8cd2
S
soar
项目概览
Xiaomi
/
soar
大约 2 年 前同步成功
通知
467
Star
8513
Fork
1329
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
soar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3faa8cd2
编写于
12月 20, 2018
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dynamic column use go-sql-driver
上级
ad1b1e0b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
22 deletion
+54
-22
database/explain.go
database/explain.go
+7
-1
database/show.go
database/show.go
+47
-21
未找到文件。
database/explain.go
浏览文件 @
3faa8cd2
...
@@ -967,8 +967,14 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
...
@@ -967,8 +967,14 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
}
}
cols
,
err
:=
res
.
Rows
.
Columns
()
cols
,
err
:=
res
.
Rows
.
Columns
()
common
.
LogIfError
(
err
,
""
)
common
.
LogIfError
(
err
,
""
)
var
colByPass
[]
byte
for
_
,
col
:=
range
cols
{
for
_
,
col
:=
range
cols
{
explainFields
=
append
(
explainFields
,
fields
[
col
])
if
_
,
ok
:=
fields
[
col
];
ok
{
explainFields
=
append
(
explainFields
,
fields
[
col
])
}
else
{
common
.
Log
.
Debug
(
"ParseExplainResult by pass column %s"
,
col
)
explainFields
=
append
(
explainFields
,
&
colByPass
)
}
}
}
// 补全 ExplainRows
// 补全 ExplainRows
...
...
database/show.go
浏览文件 @
3faa8cd2
...
@@ -142,8 +142,14 @@ func (db *Connector) ShowTableStatus(tableName string) (*TableStatInfo, error) {
...
@@ -142,8 +142,14 @@ func (db *Connector) ShowTableStatus(tableName string) (*TableStatInfo, error) {
}
}
cols
,
err
:=
res
.
Rows
.
Columns
()
cols
,
err
:=
res
.
Rows
.
Columns
()
common
.
LogIfError
(
err
,
""
)
common
.
LogIfError
(
err
,
""
)
var
colByPass
[]
byte
for
_
,
col
:=
range
cols
{
for
_
,
col
:=
range
cols
{
statusFields
=
append
(
statusFields
,
fields
[
col
])
if
_
,
ok
:=
fields
[
col
];
ok
{
statusFields
=
append
(
statusFields
,
fields
[
col
])
}
else
{
common
.
Log
.
Debug
(
"ShowTableStatus by pass column %s"
,
col
)
statusFields
=
append
(
statusFields
,
&
colByPass
)
}
}
}
// 获取值
// 获取值
for
res
.
Rows
.
Next
()
{
for
res
.
Rows
.
Next
()
{
...
@@ -161,7 +167,7 @@ type TableIndexInfo struct {
...
@@ -161,7 +167,7 @@ type TableIndexInfo struct {
Rows
[]
TableIndexRow
Rows
[]
TableIndexRow
}
}
// TableIndexRow 用以存放show index
之后获取的每一条index
信息
// TableIndexRow 用以存放show index
之后获取的每一条 index
信息
type
TableIndexRow
struct
{
type
TableIndexRow
struct
{
Table
string
// 表名
Table
string
// 表名
NonUnique
int
// 0:unique key,1:not unique
NonUnique
int
// 0:unique key,1:not unique
...
@@ -224,8 +230,14 @@ func (db *Connector) ShowIndex(tableName string) (*TableIndexInfo, error) {
...
@@ -224,8 +230,14 @@ func (db *Connector) ShowIndex(tableName string) (*TableIndexInfo, error) {
}
}
cols
,
err
:=
res
.
Rows
.
Columns
()
cols
,
err
:=
res
.
Rows
.
Columns
()
common
.
LogIfError
(
err
,
""
)
common
.
LogIfError
(
err
,
""
)
var
colByPass
[]
byte
for
_
,
col
:=
range
cols
{
for
_
,
col
:=
range
cols
{
indexFields
=
append
(
indexFields
,
fields
[
col
])
if
_
,
ok
:=
fields
[
col
];
ok
{
indexFields
=
append
(
indexFields
,
fields
[
col
])
}
else
{
common
.
Log
.
Debug
(
"ShowIndex by pass column %s"
,
col
)
indexFields
=
append
(
indexFields
,
&
colByPass
)
}
}
}
// 获取值
// 获取值
for
res
.
Rows
.
Next
()
{
for
res
.
Rows
.
Next
()
{
...
@@ -348,10 +360,15 @@ func (db *Connector) ShowColumns(tableName string) (*TableDesc, error) {
...
@@ -348,10 +360,15 @@ func (db *Connector) ShowColumns(tableName string) (*TableDesc, error) {
}
}
cols
,
err
:=
res
.
Rows
.
Columns
()
cols
,
err
:=
res
.
Rows
.
Columns
()
common
.
LogIfError
(
err
,
""
)
common
.
LogIfError
(
err
,
""
)
var
colByPass
[]
byte
for
_
,
col
:=
range
cols
{
for
_
,
col
:=
range
cols
{
columnFields
=
append
(
columnFields
,
fields
[
col
])
if
_
,
ok
:=
fields
[
col
];
ok
{
columnFields
=
append
(
columnFields
,
fields
[
col
])
}
else
{
common
.
Log
.
Debug
(
"ShowColumns by pass column %s"
,
col
)
columnFields
=
append
(
columnFields
,
&
colByPass
)
}
}
}
// 获取值
// 获取值
for
res
.
Rows
.
Next
()
{
for
res
.
Rows
.
Next
()
{
res
.
Rows
.
Scan
(
columnFields
...
)
res
.
Rows
.
Scan
(
columnFields
...
)
...
@@ -371,34 +388,43 @@ func (td TableDesc) Columns() []string {
...
@@ -371,34 +388,43 @@ func (td TableDesc) Columns() []string {
// showCreate show create
// showCreate show create
func
(
db
*
Connector
)
showCreate
(
createType
,
name
string
)
(
string
,
error
)
{
func
(
db
*
Connector
)
showCreate
(
createType
,
name
string
)
(
string
,
error
)
{
// 执行 show create table|database
// SHOW CREATE DATABASE db_name
// createType = [table|database|view]
// SHOW CREATE EVENT event_name
// SHOW CREATE FUNCTION func_name
// SHOW CREATE PROCEDURE proc_name
// SHOW CREATE TABLE tbl_name
// SHOW CREATE TRIGGER trigger_name
// SHOW CREATE VIEW view_name
res
,
err
:=
db
.
Query
(
fmt
.
Sprintf
(
"show create %s `%s`"
,
createType
,
name
))
res
,
err
:=
db
.
Query
(
fmt
.
Sprintf
(
"show create %s `%s`"
,
createType
,
name
))
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
// columns info
// columns info
var
colByPass
[]
byte
var
create
string
var
create
string
createFields
:=
make
([]
interface
{},
0
)
createFields
:=
make
([]
interface
{},
0
)
fields
:=
map
[
string
]
interface
{}{
fields
:=
map
[
string
]
interface
{}{
"Create View"
:
&
create
,
"Create View"
:
&
create
,
"Create Table"
:
&
create
,
"Create Table"
:
&
create
,
"Create Database"
:
&
create
,
"Create Database"
:
&
create
,
"Table"
:
&
colByPass
,
"Create Event"
:
&
create
,
"Database"
:
&
colByPass
,
"Statement"
:
&
create
,
// show create trigger
"View"
:
&
colByPass
,
"Create Function"
:
&
create
,
"character_set_client"
:
&
colByPass
,
"Create Procedure"
:
&
create
,
"collation_connection"
:
&
colByPass
,
}
}
cols
,
err
:=
res
.
Rows
.
Columns
()
cols
,
err
:=
res
.
Rows
.
Columns
()
common
.
LogIfError
(
err
,
""
)
common
.
LogIfError
(
err
,
""
)
var
colByPass
[]
byte
for
_
,
col
:=
range
cols
{
for
_
,
col
:=
range
cols
{
createFields
=
append
(
createFields
,
fields
[
col
])
if
_
,
ok
:=
fields
[
col
];
ok
{
createFields
=
append
(
createFields
,
fields
[
col
])
}
else
{
common
.
Log
.
Debug
(
"showCreate by pass column %s"
,
col
)
createFields
=
append
(
createFields
,
&
colByPass
)
}
}
}
// 获取 CREATE
TABLE|VIEW|DATABASE
语句
// 获取 CREATE 语句
for
res
.
Rows
.
Next
()
{
for
res
.
Rows
.
Next
()
{
res
.
Rows
.
Scan
(
createFields
...
)
res
.
Rows
.
Scan
(
createFields
...
)
}
}
...
@@ -494,9 +520,9 @@ func (db *Connector) FindColumn(name, dbName string, tables ...string) ([]*commo
...
@@ -494,9 +520,9 @@ func (db *Connector) FindColumn(name, dbName string, tables ...string) ([]*commo
col
.
Collation
=
string
(
collation
)
col
.
Collation
=
string
(
collation
)
// 填充字符集和排序规则
// 填充字符集和排序规则
if
col
.
Character
==
""
{
if
col
.
Character
==
""
{
// 当从
`INFORMATION_SCHEMA`.`COLUMNS`表中查询不到相关列的character和collation
的信息时
// 当从
`INFORMATION_SCHEMA`.`COLUMNS` 表中查询不到相关列的 character 和 collation
的信息时
// 认为该列使用的
character和collation
与其所处的表一致
// 认为该列使用的
character 和 collation
与其所处的表一致
// 由于
`INFORMATION_SCHEMA`.`TABLES`表中未找到表的character,所以从按照MySQL中collation的规则从中截取
character
// 由于
`INFORMATION_SCHEMA`.`TABLES` 表中未找到表的 character,所以从按照 MySQL 中 collation 的规则从中截取
character
sql
=
fmt
.
Sprintf
(
"SELECT `t`.`TABLE_COLLATION` FROM `INFORMATION_SCHEMA`.`TABLES` AS `t` "
+
sql
=
fmt
.
Sprintf
(
"SELECT `t`.`TABLE_COLLATION` FROM `INFORMATION_SCHEMA`.`TABLES` AS `t` "
+
"WHERE `t`.`TABLE_NAME`='%s' AND `t`.`TABLE_SCHEMA` = '%s'"
,
col
.
Table
,
col
.
DB
)
"WHERE `t`.`TABLE_NAME`='%s' AND `t`.`TABLE_SCHEMA` = '%s'"
,
col
.
Table
,
col
.
DB
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录