|
|
@ -6,6 +6,7 @@ package main |
|
|
|
*/ |
|
|
|
import ( |
|
|
|
"database/sql" |
|
|
|
log2 "log" |
|
|
|
"os" |
|
|
|
"time" |
|
|
|
|
|
|
@ -14,8 +15,8 @@ import ( |
|
|
|
|
|
|
|
//存在所有对象信息 - 集合
|
|
|
|
func main() { |
|
|
|
db, _ := sql.Open("mysql", "root:admin@tcp(127.0.0.1:35017)/hy_qggwy?charset=utf8") |
|
|
|
|
|
|
|
db, _ := sql.Open("mysql", "hy_qggwy:hy_qggwy@tcp(192.168.0.110:35017)/hy_qggwy?charset=utf8") |
|
|
|
log2.Print("操作数据库连接:", db) |
|
|
|
// db.Exec("source E:/hy_qggwy_kk.sql")
|
|
|
|
|
|
|
|
QuerySQL(db, "select * from a01 where a0184 in (select d from kk)", "insert into a01 values", "a01") |
|
|
@ -33,7 +34,8 @@ func main() { |
|
|
|
|
|
|
|
// 获取表数据
|
|
|
|
func QuerySQL(db *sql.DB, sqlStr, insertSQL, tableName string) { |
|
|
|
rows, _ := db.Query(sqlStr) |
|
|
|
rows, err := db.Query(sqlStr) |
|
|
|
log2.Print("开始备份数据:", tableName, "处理数据:", rows, "异常情况:", err) |
|
|
|
defer rows.Close() |
|
|
|
cloumns, _ := rows.Columns() |
|
|
|
values := make([]sql.RawBytes, len(cloumns)) |
|
|
@ -41,10 +43,11 @@ func QuerySQL(db *sql.DB, sqlStr, insertSQL, tableName string) { |
|
|
|
for i := range values { |
|
|
|
scanArgs[i] = &values[i] |
|
|
|
} |
|
|
|
aa := insertSQL |
|
|
|
aa := "" |
|
|
|
for rows.Next() { |
|
|
|
_ = rows.Scan(scanArgs...) |
|
|
|
value, v := "(", "" |
|
|
|
aa = aa + insertSQL |
|
|
|
for _, col := range values { |
|
|
|
if col == nil { |
|
|
|
v = "" |
|
|
@ -57,7 +60,7 @@ func QuerySQL(db *sql.DB, sqlStr, insertSQL, tableName string) { |
|
|
|
value = value + "','" + v |
|
|
|
} |
|
|
|
} |
|
|
|
value = value + "'),\n" |
|
|
|
value = value + "');\n" |
|
|
|
aa = aa + value |
|
|
|
} |
|
|
|
var path string |
|
|
|