| | |
| | | |
| | | func ExecuteSqlByGorm(sqls []string) (bool,error) { |
| | | if localDb != nil { |
| | | localDb.LogMode(false) |
| | | defer localDb.LogMode(true) |
| | | var err error |
| | | tx := localDb.Begin() |
| | | defer func() { |
| | |
| | | }() |
| | | for _,sql :=range sqls { |
| | | result := tx.Exec(sql) |
| | | if result.Error !=nil { |
| | | err = result.Error |
| | | if err !=nil { |
| | | return false,result.Error |
| | | } |
| | | if result.RowsAffected == 0{ |
| | |
| | | } |
| | | |
| | | func ExecuteQueryByGorm(tableNames []string) ([]string, error) { |
| | | localDb.LogMode(false) |
| | | defer localDb.LogMode(true) |
| | | if tableNames !=nil { |
| | | var arr []string |
| | | var dumpSql []DumpSql |
| | |
| | | for _,col :=range tDescArr { |
| | | columnNames = append(columnNames, fmt.Sprintf(`'||quote("%s")||'`, col.Name)) |
| | | } |
| | | tSql = fmt.Sprintf(`SELECT 'INSERT INTO "%s" VALUES(%s)' as sql FROM "%s";`, |
| | | table, |
| | | strings.Join(columnNames, ","), |
| | | table) |
| | | if table == "dbTables" { |
| | | tSql = fmt.Sprintf(`SELECT 'INSERT INTO "%s" VALUES(%s)' as sql FROM "%s" where (analyServerId='' or analyServerId is NULL);`, |
| | | table, |
| | | strings.Join(columnNames, ","), |
| | | table) |
| | | } else if table == "dbtablepersons" { |
| | | tSql = fmt.Sprintf(`SELECT 'INSERT INTO "%s" VALUES(%s)' as sql FROM "%s" where tableId in (select id from dbTables where (analyServerId='' or analyServerId is NULL));`, |
| | | table, |
| | | strings.Join(columnNames, ","), |
| | | table) |
| | | } else { |
| | | tSql = fmt.Sprintf(`SELECT 'INSERT INTO "%s" VALUES(%s)' as sql FROM "%s";`, |
| | | table, |
| | | strings.Join(columnNames, ","), |
| | | table) |
| | | } |
| | | |
| | | fmt.Println("tSql:",tSql) |
| | | |
| | | err = localDb.Raw(tSql).Scan(&dumpSql).Error |