diff --git a/advisor/heuristic.go b/advisor/heuristic.go index c8feba434285e91c5fadcc80b02fef1298d91861..82e101d2758da22b17bfb6380336ceebce61aedb 100644 --- a/advisor/heuristic.go +++ b/advisor/heuristic.go @@ -309,7 +309,7 @@ func (idxAdv *IndexAdvisor) RuleImplicitConversion() Rule { // 列与值比较 for _, val := range values { if colList[0].DataType == "" { - common.Log.Debug("Can't get %s data type", colList[0].Name) + common.Log.Warn("Can't get %s data type", colList[0].Name) break } diff --git a/advisor/index_test.go b/advisor/index_test.go index 314655f5ca0eb48de6e0c3cd30f3b85282c6717d..fc9ecd206490eb9a02a1073602dfff979be7d9b6 100644 --- a/advisor/index_test.go +++ b/advisor/index_test.go @@ -357,8 +357,9 @@ func TestIndexAdvise(t *testing.T) { } func TestIndexAdviseNoEnv(t *testing.T) { - common.Config.OnlineDSN.Disable = true common.Log.Debug("Entering function: %s", common.GetFunctionName()) + orgOnlineDSNStatus := common.Config.OnlineDSN.Disable + common.Config.OnlineDSN.Disable = true vEnv, rEnv := env.BuildEnv() defer vEnv.CleanUp() @@ -384,6 +385,7 @@ func TestIndexAdviseNoEnv(t *testing.T) { } } } + common.Config.OnlineDSN.Disable = orgOnlineDSNStatus common.Log.Debug("Exiting function: %s", common.GetFunctionName()) } diff --git a/ast/rewrite_test.go b/ast/rewrite_test.go index 043acb9080d0783b6bec8a4f24a57562d1ff9e74..b0758e43bd7ed647804497112a18af589212c38a 100644 --- a/ast/rewrite_test.go +++ b/ast/rewrite_test.go @@ -25,6 +25,7 @@ import ( ) func TestRewrite(t *testing.T) { + orgTestDSNStatus := common.Config.TestDSN.Disable common.Config.TestDSN.Disable = false testSQL := []map[string]string{ { @@ -97,9 +98,11 @@ func TestRewrite(t *testing.T) { t.Errorf("want: %s\ngot: %s", sql["output"], rw.NewSQL) } } + common.Config.TestDSN.Disable = orgTestDSNStatus } func TestRewriteStar2Columns(t *testing.T) { + orgTestDSNStatus := common.Config.TestDSN.Disable common.Config.TestDSN.Disable = false testSQL := []map[string]string{ { @@ -127,6 +130,7 @@ func TestRewriteStar2Columns(t *testing.T) { t.Errorf("want: %s\ngot: %s", sql["output"], rw.NewSQL) } } + common.Config.TestDSN.Disable = orgTestDSNStatus } func TestRewriteInsertColumns(t *testing.T) { @@ -427,6 +431,7 @@ func TestRewriteAlwaysTrue(t *testing.T) { // TODO: func TestRewriteSubQuery2Join(t *testing.T) { + orgTestDSNStatus := common.Config.TestDSN.Disable common.Config.TestDSN.Disable = true testSQL := []map[string]string{ { @@ -452,6 +457,7 @@ func TestRewriteSubQuery2Join(t *testing.T) { t.Errorf("want: %s\ngot: %s", sql["output"], rw.NewSQL) } } + common.Config.TestDSN.Disable = orgTestDSNStatus } func TestRewriteDML2Select(t *testing.T) { diff --git a/database/show.go b/database/show.go index db4604324668dcb990d99fb57116cc43f9c734c8..a49dc5e978e9f3051b4a72ad695d1f0681b3c805 100644 --- a/database/show.go +++ b/database/show.go @@ -371,7 +371,8 @@ func (td TableDesc) Columns() []string { // showCreate show create func (db *Connector) showCreate(createType, name string) (string, error) { - // 执行 show create table + // 执行 show create table|database + // createType = [table|database] res, err := db.Query(fmt.Sprintf("show create %s `%s`", createType, name)) if err != nil { return "", err @@ -461,14 +462,17 @@ func (db *Connector) FindColumn(name, dbName string, tables ...string) ([]*commo var col common.Column for res.Rows.Next() { - var character, collation string - res.Rows.Scan(&col.Table, + var character, collation []byte + res.Rows.Scan( + &col.Table, &col.DB, &col.DataType, &character, - &collation) - col.Character = character - col.Collation = collation + &collation, + ) + col.Name = name + col.Character = string(character) + col.Collation = string(collation) // 填充字符集和排序规则 if col.Character == "" { // 当从`INFORMATION_SCHEMA`.`COLUMNS`表中查询不到相关列的character和collation的信息时 diff --git a/database/testdata/TestFindColumn.golden b/database/testdata/TestFindColumn.golden index c7deffee353e83627e818875dd3bf283304ce80d..1a7d85e04cf919839f826a2b5b9ae9125994164b 100644 --- a/database/testdata/TestFindColumn.golden +++ b/database/testdata/TestFindColumn.golden @@ -1,6 +1,6 @@ []*common.Column{ &common.Column{ - Name: "", + Name: "film_id", Alias: nil, Table: "film", DB: "sakila",