From 62a20c839009db883a9056a095ebc9cbcee339d5 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期四, 14 五月 2020 20:03:56 +0800 Subject: [PATCH] fix ExecuteWriteSql --- sync.go | 36 +++++++++++++++++++++--------------- 1 files changed, 21 insertions(+), 15 deletions(-) diff --git a/sync.go b/sync.go index 30870a3..3ca64f2 100755 --- a/sync.go +++ b/sync.go @@ -5,7 +5,7 @@ sdb "basic.com/Android/syncdb.git" "basic.com/valib/logger.git" "encoding/json" - "github.com/micro/go-micro/logger" + "fmt" "strings" ) type ReceiveSqlInterface2 interface { @@ -16,7 +16,7 @@ sdb.RegisterReceiveSqlInterface(c) } -func InitAgent(devID string) bool { +/*func InitAgent(devID string) bool { var nodeIps []string sqlFindAllCluster := string("select * from " + dBNameCluster) clusters, err := sdb.ExecuteQuerySql([]string{sqlFindAllCluster}) @@ -43,7 +43,7 @@ } return true -} +}*/ func SyncInit(clusterID string, password string, nodeID string, strAddrs string, snapshotPath string) bool { var ips []string @@ -64,11 +64,19 @@ return true } -func RegisterDbHandler(h sdb.DbHandler) { +type DbHandlerInterface interface { + sdb.DbHandler +} + +type DbDumpHandlerInterface interface { + sdb.DbDumpHandler +} + +func RegisterDbHandler(h DbHandlerInterface) { sdb.RegisterDbHandler(h) } -func RegisterDbDumpHandler(h sdb.DbDumpHandler) { +func RegisterDbDumpHandler(h DbDumpHandlerInterface) { sdb.RegisterDbDumpHandler(h) } @@ -144,12 +152,12 @@ sqls = append(sqls, delSql) } - var dumpSqls *[]string dumpSqls, err := agent.GetTableDataFromCluster(syncTables) - if dumpSqls != nil { - for _, dumpSql := range *dumpSqls { - sqls = append(sqls, dumpSql) - } + fmt.Println("len(dumpSqls):", len(*dumpSqls), "err:",err) + if dumpSqls != nil && len(*dumpSqls) > 0 { + sqls = append(sqls, *dumpSqls) + } else { + return false } logger.Debug("鎴愬姛鑾峰彇闆嗙兢涓暟鎹�,err:",err) @@ -190,8 +198,7 @@ func UpdateClusterName(clusterName, clusterID string) bool { sql := string("update cluster set cluster_name='" + clusterName + "' where cluster_id='" + clusterID + "'") - _, err := sdb.ExecuteWriteSql([]string{sql}, false) - if err != nil { + if !sdb.DbHandle.Execute(sql) { return false } @@ -209,10 +216,9 @@ agent.Shutdown() agent = nil - sqls := []string{"delete from cluster_node", "delete from cluster"} + sqls := "delete from cluster_node;delete from cluster;" - _, err = sdb.ExecuteWriteSql(sqls, false) - if err != nil { + if !sdb.DbHandle.Execute(sqls) { return false } } -- Gitblit v1.8.0