github.com/team-ide/go-dialect@v1.9.20/sql_test.go (about)

     1  package main
     2  
     3  import (
     4  	"database/sql"
     5  	"encoding/json"
     6  	"fmt"
     7  	"github.com/team-ide/go-dialect/dialect"
     8  	"github.com/team-ide/go-dialect/worker"
     9  	"github.com/team-ide/go-driver/db_dm"
    10  	"github.com/team-ide/go-driver/db_gbase"
    11  	"github.com/team-ide/go-driver/db_kingbase_v8r3"
    12  	"github.com/team-ide/go-driver/db_kingbase_v8r6"
    13  	"github.com/team-ide/go-driver/db_mysql"
    14  	"github.com/team-ide/go-driver/db_oracle"
    15  	"github.com/team-ide/go-driver/db_shentong"
    16  	"github.com/team-ide/go-driver/db_sqlite3"
    17  	"strings"
    18  	"testing"
    19  )
    20  
    21  var testDialectList []*testDialect
    22  var testDialectCache = make(map[string]*testDialect)
    23  
    24  type testDialect struct {
    25  	table       *dialect.TableModel
    26  	mapping     *dialect.SqlMapping
    27  	dialect     dialect.Dialect
    28  	owner       *dialect.OwnerModel
    29  	db          func() (db *sql.DB, err error)
    30  	ownerDb     func(owner *dialect.OwnerModel) (ownerDb *sql.DB, err error)
    31  	killSession func(owner *dialect.OwnerModel, db *sql.DB)
    32  }
    33  
    34  func (this_ *testDialect) init() {
    35  	this_.table = this_.mapping.GenDemoTable()
    36  	var err error
    37  	this_.dialect, err = dialect.NewMappingDialect(this_.mapping)
    38  	if err != nil {
    39  		panic(err)
    40  	}
    41  }
    42  
    43  func init() {
    44  	appendTestDialectMysql()
    45  	appendTestDialectSqlite()
    46  	//appendTestDialectOracle()
    47  	appendTestDialectShenTong()
    48  	appendTestDialectDM()
    49  	appendTestDialectKingBase()
    50  }
    51  
    52  func appendTestDialectMysql() {
    53  	one := &testDialect{}
    54  	testDialectCache["mysql"] = one
    55  	testDialectList = append(testDialectList, one)
    56  	one.mapping = dialect.NewMappingMysql()
    57  
    58  	one.owner = &dialect.OwnerModel{
    59  		OwnerName:             "TEST_DB",
    60  		OwnerCharacterSetName: "utf8mb4",
    61  	}
    62  	one.db = func() (db *sql.DB, err error) {
    63  		db, err = db_mysql.Open(db_mysql.GetDSN("root", "123456", "127.0.0.1", 3306, ""))
    64  		return
    65  	}
    66  	one.ownerDb = func(owner *dialect.OwnerModel) (ownerDb *sql.DB, err error) {
    67  		ownerDb, err = db_mysql.Open(db_mysql.GetDSN("root", "123456", "127.0.0.1", 3306, owner.OwnerName))
    68  		return
    69  	}
    70  	one.init()
    71  }
    72  
    73  func appendTestDialectSqlite() {
    74  	one := &testDialect{}
    75  	testDialectCache["sqlite"] = one
    76  	testDialectList = append(testDialectList, one)
    77  	one.mapping = dialect.NewMappingSqlite()
    78  
    79  	one.owner = &dialect.OwnerModel{
    80  		OwnerName: "",
    81  	}
    82  	one.db = func() (db *sql.DB, err error) {
    83  		db, err = db_sqlite3.Open(db_sqlite3.GetDSN("temp/sqlite.test.db"))
    84  		return
    85  	}
    86  	one.ownerDb = func(owner *dialect.OwnerModel) (ownerDb *sql.DB, err error) {
    87  		ownerDb, err = db_sqlite3.Open(db_sqlite3.GetDSN("temp/sqlite.test.db"))
    88  		return
    89  	}
    90  	one.init()
    91  }
    92  
    93  func appendTestDialectOracle() {
    94  	one := &testDialect{}
    95  	testDialectCache["oracle"] = one
    96  	testDialectList = append(testDialectList, one)
    97  	one.mapping = dialect.NewMappingOracle()
    98  
    99  	one.owner = &dialect.OwnerModel{
   100  		OwnerName:     "TEST_DB",
   101  		OwnerPassword: "123456",
   102  	}
   103  	one.db = func() (db *sql.DB, err error) {
   104  		db, err = db_oracle.Open(db_oracle.GetDSN("root", "123456", "127.0.0.1", 1521, "xe"))
   105  		return
   106  	}
   107  	one.ownerDb = func(owner *dialect.OwnerModel) (ownerDb *sql.DB, err error) {
   108  		dsn_ := db_oracle.GetDSN(owner.OwnerName, owner.OwnerPassword, "127.0.0.1", 1521, "xe")
   109  		ownerDb, err = db_oracle.Open(dsn_)
   110  		return
   111  	}
   112  	one.killSession = func(owner *dialect.OwnerModel, db *sql.DB) {
   113  
   114  		var err error
   115  		var list []map[string]interface{}
   116  		list, err = worker.DoQuery(db, `SELECT * FROM V$SESSION WHERE USERNAME = '`+owner.OwnerName+`'`, nil)
   117  		if err != nil {
   118  			println(err)
   119  			return
   120  		}
   121  
   122  		if len(list) == 0 {
   123  			return
   124  		} else {
   125  			fmt.Println("session list:")
   126  			for _, one := range list {
   127  				bs, _ := json.Marshal(one)
   128  				fmt.Println(string(bs))
   129  				sid := dialect.GetStringValue(one["SID"])
   130  				serial := dialect.GetStringValue(one["SERIAL#"])
   131  				_, _, _, err = worker.DoExecs(db, []string{`ALTER SYSTEM KILL SESSION '` + sid + `,` + serial + `'`}, nil)
   132  				if err != nil {
   133  					println(err)
   134  					continue
   135  				}
   136  			}
   137  		}
   138  	}
   139  	one.init()
   140  }
   141  
   142  func appendTestDialectDM() {
   143  	one := &testDialect{}
   144  	testDialectCache["dm"] = one
   145  	testDialectList = append(testDialectList, one)
   146  	one.mapping = dialect.NewMappingDM()
   147  
   148  	one.owner = &dialect.OwnerModel{
   149  		OwnerName:     "TEST_DB_USER",
   150  		OwnerPassword: "123456789",
   151  	}
   152  	one.db = func() (db *sql.DB, err error) {
   153  		db, err = db_dm.Open(db_dm.GetDSN("SYSDBA", "SYSDBA", "127.0.0.1", 5236))
   154  		return
   155  	}
   156  	one.ownerDb = func(owner *dialect.OwnerModel) (ownerDb *sql.DB, err error) {
   157  		ownerDb, err = db_dm.Open(db_dm.GetDSN(owner.OwnerName, owner.OwnerPassword, "127.0.0.1", 5236))
   158  		return
   159  	}
   160  	one.init()
   161  }
   162  
   163  func appendTestDialectKingBase() {
   164  	one := &testDialect{}
   165  	testDialectCache["kingbase"] = one
   166  	testDialectList = append(testDialectList, one)
   167  	one.mapping = dialect.NewMappingKingBase()
   168  
   169  	one.owner = &dialect.OwnerModel{
   170  		OwnerName:     "TEST_DB_USER",
   171  		OwnerPassword: "123456",
   172  	}
   173  	one.db = func() (db *sql.DB, err error) {
   174  		db, err = db_kingbase_v8r3.Open(db_kingbase_v8r3.GetDSN("SYSTEM", "123456", "127.0.0.1", 54321, "TEST"))
   175  		return
   176  	}
   177  	one.ownerDb = func(owner *dialect.OwnerModel) (ownerDb *sql.DB, err error) {
   178  		dsn := db_kingbase_v8r3.GetDSN(owner.OwnerName, owner.OwnerPassword, "127.0.0.1", 54321, "TEST")
   179  		dsn += "&search_path=" + owner.OwnerName
   180  		ownerDb, err = db_kingbase_v8r3.Open(dsn)
   181  		return
   182  	}
   183  	one.init()
   184  }
   185  
   186  func appendTestDialectShenTong() {
   187  	one := &testDialect{}
   188  	testDialectCache["shentong"] = one
   189  	testDialectList = append(testDialectList, one)
   190  	one.mapping = dialect.NewMappingShenTong()
   191  
   192  	one.owner = &dialect.OwnerModel{
   193  		OwnerName:     "TEST_DB",
   194  		OwnerPassword: "123456",
   195  	}
   196  	one.db = func() (db *sql.DB, err error) {
   197  		db, err = db_shentong.Open(db_shentong.GetDSN("sysdba", "szoscar55", "127.0.0.1", 2003, "OSRDB"))
   198  		return
   199  	}
   200  	one.ownerDb = func(owner *dialect.OwnerModel) (ownerDb *sql.DB, err error) {
   201  		ownerDb, err = db_shentong.Open(db_shentong.GetDSN(owner.OwnerName, owner.OwnerPassword, "127.0.0.1", 2003, "OSRDB"))
   202  		return
   203  	}
   204  	one.init()
   205  }
   206  
   207  func TestMysql(t *testing.T) {
   208  
   209  	db, err := db_mysql.Open(db_mysql.GetDSN("root", "123456", "127.0.0.1", 3306, ""))
   210  	if err != nil {
   211  		panic(err)
   212  	}
   213  	//list, err := worker.DoQuery(db, `select * from ALL_TableS`)
   214  	//list, err := worker.DoQuery(db, `select * from ALL_OBJECTS`)
   215  	//list, err := worker.DoQuery(db, `select * from SYS_CLASS`)
   216  	list, err := worker.DoQuery(db, `set global show_compatibility_56=on`, nil)
   217  
   218  	if err != nil {
   219  		panic(err)
   220  	}
   221  	for _, one := range list {
   222  		bs, _ := json.Marshal(one)
   223  		fmt.Println(string(bs))
   224  	}
   225  }
   226  func TestKingBase(t *testing.T) {
   227  
   228  	db, err := db_kingbase_v8r3.Open(db_kingbase_v8r3.GetDSN("SYSTEM", "123456", "127.0.0.1", 54321, "TEST"))
   229  	if err != nil {
   230  		panic(err)
   231  	}
   232  	//list, err := worker.DoQuery(db, `select * from ALL_TableS`)
   233  	//list, err := worker.DoQuery(db, `select * from ALL_OBJECTS`)
   234  	//list, err := worker.DoQuery(db, `select * from SYS_CLASS`)
   235  	//list, err := worker.DoQuery(db, `SELECT * FROM information_schema.TABLES`)
   236  	//list, err := worker.DoQuery(db, `SELECT * FROM information_schema.schemata`)
   237  
   238  	//list, err := worker.DoQuery(db, `DROP SCHEMA TEST_DB`)
   239  	//owners, err := worker.OwnersSelect(db, testDialectCache["kingbase"].dialect, nil)
   240  	//for _, owner := range owners {
   241  	//	tables, err := worker.TablesSelect(db, testDialectCache["kingbase"].dialect, nil, owner.OwnerName)
   242  	//	if err != nil {
   243  	//		println(err)
   244  	//		//panic(err)
   245  	//		continue
   246  	//	}
   247  	//	for _, one := range tables {
   248  	//		//bs, _ := json.Marshal(one)
   249  	//		//fmt.Println(string(bs))
   250  	//		if strings.EqualFold(one.TableName, "dba_free_space") ||
   251  	//			strings.EqualFold(one.TableName, "SYS_FREESPACES") {
   252  	//			//	strings.EqualFold(one.TableName, "dba_cons_columns") ||
   253  	//			//	strings.EqualFold(one.TableName, "dba_col_privs") ||
   254  	//			//	strings.EqualFold(one.TableName, "dba_col_comments") ||
   255  	//			//	strings.EqualFold(one.TableName, "ALL_VIEWS") ||
   256  	//			//	strings.EqualFold(one.TableName, "all_users") ||
   257  	//			//	strings.EqualFold(one.TableName, "all_triggers") ||
   258  	//			//	strings.EqualFold(one.TableName, "all_trigger_cols") {
   259  	//			continue
   260  	//		}
   261  	//
   262  	//		sqlInfo := `
   263  	//	SELECT * from ` + owner.OwnerName + `.` + one.TableName + `
   264  	//	`
   265  	//		fmt.Println("table:", owner.OwnerName, ".", one.TableName)
   266  	//		list, err := worker.DoQuery(db, sqlInfo)
   267  	//
   268  	//		if err != nil {
   269  	//			println(err)
   270  	//			//panic(err)
   271  	//			continue
   272  	//		}
   273  	//		for _, one := range list {
   274  	//			bs, _ := json.Marshal(one)
   275  	//			str := string(bs)
   276  	//			if strings.Contains(str, "TEST_DB_TABLE_DEMO_col_3") ||
   277  	//				strings.Contains(str, "TEST_DB_TABLE_DEMO_col_4") {
   278  	//				fmt.Println(string(bs))
   279  	//			}
   280  	//		}
   281  	//	}
   282  	//}
   283  
   284  	sqlInfo := `
   285  	SELECT
   286  	   *
   287  	FROM ALL_INDEXES
   288  	WHERE TABLE_NAME='TABLE_DEMO'
   289  		`
   290  	list, err := worker.DoQuery(db, sqlInfo, nil)
   291  
   292  	if err != nil {
   293  		panic(err)
   294  	}
   295  	for _, one := range list {
   296  		bs, _ := json.Marshal(one)
   297  		fmt.Println(string(bs))
   298  	}
   299  }
   300  
   301  func TestKingBaseSchema(t *testing.T) {
   302  	schema := "TEST_DB"
   303  
   304  	dsn := db_kingbase_v8r6.GetDSN("TEST_DB", "123456", "127.0.0.1", 54321, "TEST")
   305  	dsn += "&search_path=" + schema
   306  	db, err := db_kingbase_v8r6.Open(dsn)
   307  	if err != nil {
   308  		panic(err)
   309  	}
   310  	db.SetMaxIdleConns(1)
   311  	db.SetMaxOpenConns(2)
   312  	err = db.Ping()
   313  	if err != nil {
   314  		panic(err)
   315  	}
   316  	sqlInfo := `
   317  show superuser_reserved_connections;
   318  		`
   319  	//errsSql, err := worker.DoExec(db, []string{`select * from "TEST_DB"."TABLE_DEMO1"`, sqlInfo})
   320  	//if err != nil {
   321  	//	fmt.Println("errsSql:", errsSql)
   322  	//	panic(err)
   323  	//}
   324  	list, err := worker.DoQuery(db, sqlInfo, nil)
   325  
   326  	if err != nil {
   327  		panic(err)
   328  	}
   329  	fmt.Println("list:", len(list))
   330  	for _, one := range list {
   331  		bs, _ := json.Marshal(one)
   332  		fmt.Println(string(bs))
   333  	}
   334  }
   335  
   336  func TestDm(t *testing.T) {
   337  	//var a dm.DmClob
   338  	db, err := db_dm.Open(db_dm.GetDSN("SYSDBA", "SYSDBA", "127.0.0.1", 5236))
   339  	if err != nil {
   340  		panic(err)
   341  	}
   342  	db.SetMaxIdleConns(1)
   343  	db.SetMaxOpenConns(2)
   344  	err = db.Ping()
   345  	if err != nil {
   346  		panic(err)
   347  	}
   348  	sqlInfo := `
   349  SELECT 
   350  	*
   351  FROM VRV_JOB.JOB_EXECUTOR_LOG
   352  `
   353  	list, err := worker.DoQuery(db, sqlInfo, nil)
   354  
   355  	if err != nil {
   356  		panic(err)
   357  	}
   358  	fmt.Println("list:", len(list))
   359  	for _, one := range list {
   360  		bs, _ := json.Marshal(one)
   361  		fmt.Println(string(bs))
   362  	}
   363  }
   364  func TestOracle(t *testing.T) {
   365  
   366  	db, err := db_oracle.Open(db_oracle.GetDSN("root", "123456", "127.0.0.1", 1521, "xe"))
   367  	if err != nil {
   368  		panic(err)
   369  	}
   370  	//list, err := worker.DoQuery(db, `select * FROM ALL_CONS_COLUMNS`)
   371  	list, err := worker.DoQuery(db, `SELECT * FROM V$SESSION`, nil)
   372  	if err != nil {
   373  		panic(err)
   374  	}
   375  	for _, one := range list {
   376  		bs, _ := json.Marshal(one)
   377  		fmt.Println(string(bs))
   378  	}
   379  }
   380  func TestGBase(t *testing.T) {
   381  	dsn := `DRIVER=com.gbasebt.jdbc.Driver;NEWCODESET=UTF8,zh_cn.UTF8,57372;DB_LOCALE=zh_cn.57372;DELIMIDENT=Y;CLIENT_LOCALE=zh_cn.57372;ServerName=gbase01;host=127.0.0.1;service=9088;uid=gbasedbt;pwd=GBase123;DATABASE=VRV_JOB1;`
   382  	db, err := db_gbase.Open(dsn)
   383  	if err != nil {
   384  		panic(err)
   385  	}
   386  
   387  	dia, err := dialect.NewDialect("GBase")
   388  	if err != nil {
   389  		panic(err)
   390  	}
   391  	owners, err := worker.OwnersSelect(db, dia, nil)
   392  	if err != nil {
   393  		panic(err)
   394  	}
   395  	for _, one := range owners {
   396  		if !strings.EqualFold(one.OwnerName, "im_dbconfig") {
   397  			continue
   398  		}
   399  		bs, _ := json.Marshal(one)
   400  		fmt.Println("owner:", string(bs))
   401  
   402  		tables, err := worker.TablesDetail(db, dia, nil, one.OwnerName, false)
   403  		if err != nil {
   404  			panic(err)
   405  		}
   406  		for _, one := range tables {
   407  			bs, _ := json.Marshal(one)
   408  			fmt.Println("table:", string(bs))
   409  		}
   410  	}
   411  
   412  }
   413  func TestAllTableSql(t *testing.T) {
   414  	for _, one := range testDialectList {
   415  		sqlList, err := one.dialect.TableCreateSql(nil, one.owner.OwnerName, one.table)
   416  		if err != nil {
   417  			panic(err)
   418  		}
   419  		fmt.Println("-----dialect [" + one.dialect.DialectType().Name + "] create table sql---")
   420  		for _, sqlOne := range sqlList {
   421  			fmt.Println(sqlOne, ";")
   422  		}
   423  
   424  		for _, to := range testDialectList {
   425  			if to == one {
   426  				continue
   427  			}
   428  			toTableSql(one, to)
   429  		}
   430  	}
   431  }
   432  
   433  func toTableSql(from *testDialect, to *testDialect) {
   434  	sqlList, err := to.dialect.TableCreateSql(nil, to.owner.OwnerName, from.table)
   435  	if err != nil {
   436  		panic(err)
   437  	}
   438  	fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] to dialect [" + to.dialect.DialectType().Name + "] create table sql---")
   439  	for _, sqlOne := range sqlList {
   440  		fmt.Println(sqlOne, ";")
   441  	}
   442  }
   443  
   444  func TestToTableSql(t *testing.T) {
   445  	toTableSql(testDialectCache["oracle"], testDialectCache["mysql"])
   446  }
   447  
   448  func TestAllSql(t *testing.T) {
   449  	param := &dialect.ParamModel{}
   450  
   451  	var err error
   452  	var bs []byte
   453  	//var aa godror.Number
   454  	//aa.String()
   455  	for _, from := range testDialectList {
   456  		fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] create table---")
   457  
   458  		bs, err = json.Marshal(from.table)
   459  		if err != nil {
   460  			panic(err)
   461  		}
   462  		fmt.Println(string(bs))
   463  
   464  		db, err := from.db()
   465  		if err != nil {
   466  			panic(err)
   467  		}
   468  		err = db.Ping()
   469  		if err != nil {
   470  			panic(err)
   471  		}
   472  		if from.owner.OwnerName != "" {
   473  			fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] owner [" + from.owner.OwnerName + "] cover---")
   474  			_, err = worker.OwnerCover(db, from.dialect, param, from.owner)
   475  			if err != nil {
   476  				panic(err)
   477  			}
   478  			fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] owner [" + from.owner.OwnerName + "] success---")
   479  		}
   480  		dialectDb, err := from.ownerDb(from.owner)
   481  		if err != nil {
   482  			panic(err)
   483  		}
   484  		err = dialectDb.Ping()
   485  		if err != nil {
   486  			panic(err)
   487  		}
   488  		err = worker.TableCover(dialectDb, from.dialect, param, from.owner.OwnerName, from.table)
   489  		if err != nil {
   490  			panic(err)
   491  		}
   492  		table, err := worker.TableDetail(db, from.dialect, param, from.owner.OwnerName, from.table.TableName, false)
   493  		if err != nil {
   494  			panic(err)
   495  		}
   496  		if table == nil {
   497  			panic("dialect [" + from.dialect.DialectType().Name + "]  ownerName [" + from.owner.OwnerName + "] tableName [" + from.table.TableName + "] is null.")
   498  		}
   499  
   500  		var dataList []map[string]interface{}
   501  
   502  		//var a dm.DmBlob
   503  		var data = make(map[string]interface{})
   504  		for i, column := range from.table.ColumnList {
   505  			info, _ := from.dialect.GetColumnTypeInfo(column)
   506  
   507  			if info.IsNumber {
   508  				data[column.ColumnName] = 1
   509  			} else if info.IsString {
   510  				data[column.ColumnName] = "s" + fmt.Sprint(i)
   511  			} else if info.IsBytes {
   512  				if info.Name != "BFILE" {
   513  					data[column.ColumnName] = []byte{1}
   514  				}
   515  			} else if info.IsBoolean {
   516  				data[column.ColumnName] = true
   517  			} else if info.IsDateTime {
   518  				//data[column.ColumnName] = time.Now().Local()
   519  				//if info.Name == "YEAR" {
   520  				//	data[column.ColumnName] = 22
   521  				//}
   522  			}
   523  
   524  		}
   525  		dataList = append(dataList, data)
   526  
   527  		_, _, batchSqlList, batchValuesList, err := from.dialect.DataListInsertSql(nil, from.owner.OwnerName, from.table.TableName, from.table.ColumnList, dataList)
   528  		if err != nil {
   529  			panic(err)
   530  		}
   531  		_, errSql, errArgs, err := worker.DoExecs(dialectDb, batchSqlList, batchValuesList)
   532  		if err != nil {
   533  			fmt.Println("error sql :", errSql)
   534  			fmt.Println("error args:", errArgs)
   535  			panic(err)
   536  		}
   537  
   538  		selectSql := "select * from "
   539  		selectSql += from.dialect.OwnerTablePack(nil, from.owner.OwnerName, from.table.TableName)
   540  		list, err := worker.DoQuery(dialectDb, selectSql, nil)
   541  		if err != nil {
   542  			panic(err)
   543  		}
   544  		for _, one := range dataList {
   545  			bs, _ := json.Marshal(one)
   546  			fmt.Println("insert data:", string(bs))
   547  		}
   548  		for _, one := range list {
   549  			bs, _ := json.Marshal(one)
   550  			fmt.Println(string(bs))
   551  			fmt.Println("select data:", string(bs))
   552  		}
   553  		_ = dialectDb.Close()
   554  		if from.killSession != nil {
   555  			from.killSession(from.owner, db)
   556  		}
   557  		_ = db.Close()
   558  
   559  		//for columnIndex, fromColumn := range from.table.ColumnList {
   560  		//	savedColumn := table.ColumnList[columnIndex]
   561  		//	if fromColumn.ColumnName != savedColumn.ColumnName ||
   562  		//		//fromColumn.ColumnDataType != savedColumn.ColumnDataType ||
   563  		//		fromColumn.ColumnLength != savedColumn.ColumnLength ||
   564  		//		fromColumn.ColumnPrecision != savedColumn.ColumnPrecision ||
   565  		//		fromColumn.ColumnScale != savedColumn.ColumnScale {
   566  		//		fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] table column not eq---")
   567  		//		bs, err = json.Marshal(fromColumn)
   568  		//		if err != nil {
   569  		//			panic(err)
   570  		//		}
   571  		//		fmt.Println("fromColumn:", string(bs))
   572  		//		bs, err = json.Marshal(savedColumn)
   573  		//		if err != nil {
   574  		//			panic(err)
   575  		//		}
   576  		//		fmt.Println("savedColumn:", string(bs))
   577  		//		if fromColumn.ColumnLength == 0 &&
   578  		//			fromColumn.ColumnPrecision == 0 &&
   579  		//			fromColumn.ColumnScale == 0 {
   580  		//			continue
   581  		//		} else if fromColumn.ColumnLength != savedColumn.ColumnLength &&
   582  		//			fromColumn.ColumnPrecision == savedColumn.ColumnPrecision &&
   583  		//			fromColumn.ColumnScale == savedColumn.ColumnScale {
   584  		//			continue
   585  		//		}
   586  		//		//panic("字段不一致")
   587  		//	}
   588  		//}
   589  
   590  		//bs, err = json.Marshal(table)
   591  		//if err != nil {
   592  		//	panic(err)
   593  		//}
   594  		fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] create table result---")
   595  		//fmt.Println(string(bs))
   596  
   597  		//for _, to := range testDialectList {
   598  		//if from == to {
   599  		//	continue
   600  		//}
   601  		//	fromTableToTableSql(from, table, to)
   602  		//}
   603  	}
   604  }
   605  
   606  func fromTableToTableSql(from *testDialect, fromTable *dialect.TableModel, to *testDialect) {
   607  	fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] to dialect [" + to.dialect.DialectType().Name + "] create table---")
   608  
   609  	for _, column := range fromTable.ColumnList {
   610  		column.ColumnDefault = ""
   611  		if to.dialect.DialectType() == dialect.TypeMysql {
   612  			info, _ := to.dialect.GetColumnTypeInfo(column)
   613  			if info != nil {
   614  				if info.Name == "TIMESTAMP" {
   615  					column.ColumnDefault = "current_timestamp"
   616  				}
   617  			}
   618  		}
   619  	}
   620  	bs, err := json.Marshal(fromTable)
   621  	if err != nil {
   622  		panic(err)
   623  	}
   624  	fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] to dialect [" + to.dialect.DialectType().Name + "] create from table---")
   625  	fmt.Println(string(bs))
   626  
   627  	db, err := to.db()
   628  	if err != nil {
   629  		panic(err)
   630  	}
   631  	err = db.Ping()
   632  	if err != nil {
   633  		panic(err)
   634  	}
   635  	var dialectDb *sql.DB
   636  	param := &dialect.ParamModel{}
   637  	if to.owner.OwnerName != "" {
   638  		_, err = worker.OwnerCover(db, to.dialect, param, to.owner)
   639  		if err != nil {
   640  			panic(err)
   641  		}
   642  	}
   643  	dialectDb, err = to.ownerDb(to.owner)
   644  	if err != nil {
   645  		panic(err)
   646  	}
   647  	err = dialectDb.Ping()
   648  	if err != nil {
   649  		panic(err)
   650  	}
   651  	err = worker.TableCover(dialectDb, to.dialect, param, to.owner.OwnerName, fromTable)
   652  	if err != nil {
   653  		panic(err)
   654  	}
   655  	table, err := worker.TableDetail(db, to.dialect, param, to.owner.OwnerName, fromTable.TableName, false)
   656  	if err != nil {
   657  		panic(err)
   658  	}
   659  	if table == nil {
   660  		panic("dialect [" + from.dialect.DialectType().Name + "]  ownerName [" + from.owner.OwnerName + "] tableName [" + from.table.TableName + "] is null.")
   661  	}
   662  	_ = dialectDb.Close()
   663  	if from.killSession != nil {
   664  		from.killSession(from.owner, db)
   665  	}
   666  	_ = db.Close()
   667  	bs, err = json.Marshal(table)
   668  	if err != nil {
   669  		panic(err)
   670  	}
   671  	fmt.Println("-----dialect [" + from.dialect.DialectType().Name + "] to dialect [" + to.dialect.DialectType().Name + "] create to table---")
   672  	fmt.Println(string(bs))
   673  }