Browse Source

实现数据输出

master
VIVIMAN 3 years ago
parent
commit
0dbff67bb8
  1. 58
      golang_learn/data_office/get_hy_sql/main.go
  2. 5
      golang_learn/data_office/get_hzb_sql/go_to_hzb/main.go

58
golang_learn/data_office/get_hy_sql/main.go

@ -4,9 +4,65 @@ package main
思路: 脚本按照顺序拼接旧文件按照 utf8 格式清空
*/
import ()
import (
"database/sql"
"os"
"time"
_ "github.com/go-sql-driver/mysql"
)
//存在所有对象信息 - 集合
func main() {
db, _ := sql.Open("mysql", "root:admin@tcp(127.0.0.1:35017)/hy_qggwy?charset=utf8")
// 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")
QuerySQL(db, "select * from a02 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a02 values", "a02")
QuerySQL(db, "select * from a05 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a05 values", "a05")
QuerySQL(db, "select * from a06 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a06 values", "a06")
QuerySQL(db, "select * from a08 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a08 values", "a08")
QuerySQL(db, "select * from a14 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a14 values", "a14")
QuerySQL(db, "select * from a15 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a15 values", "a15")
QuerySQL(db, "select * from a36 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a36 values", "a36")
QuerySQL(db, "select * from a99z1 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a99z1 values", "a99z1")
QuerySQL(db, "select * from a30 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a30 values", "a30")
QuerySQL(db, "select * from a33 where a0000 in (select a0000 from a01 where a0184 in (select d from kk))", "insert into a33 values", "a33")
}
// 获取表数据
func QuerySQL(db *sql.DB, sqlStr, insertSQL, tableName string) {
rows, _ := db.Query(sqlStr)
defer rows.Close()
cloumns, _ := rows.Columns()
values := make([]sql.RawBytes, len(cloumns))
scanArgs := make([]interface{}, len(values))
for i := range values {
scanArgs[i] = &values[i]
}
aa := insertSQL
for rows.Next() {
_ = rows.Scan(scanArgs...)
value, v := "(", ""
for _, col := range values {
if col == nil {
v = ""
} else {
v = string(col)
}
if value == "(" {
value = value + "'" + v
} else {
value = value + "','" + v
}
}
value = value + "'),\n"
aa = aa + value
}
var path string
path = "./" + tableName + "_" + time.Now().Format("2006102150405") + ".sql"
file3, _ := os.Create(path)
file3.WriteString(aa)
file3.Close()
}

5
golang_learn/data_office/get_hzb_sql/go_to_hzb/main.go

@ -0,0 +1,5 @@
package main
func main() {
}
Loading…
Cancel
Save