Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
fixed #79 prepare escape string
Browse files Browse the repository at this point in the history
  • Loading branch information
wentaojin committed Jan 12, 2024
1 parent 731039e commit 8db898e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion database/oracle/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func (o *Oracle) GetOracleTableRowsData(querySQL string, insertBatchSize, callTi
return fmt.Errorf("column [%s] charset convert failed, %v", columnNames[i], err)
}

convertTargetRaw, err := common.CharsetConvert([]byte(common.SpecialLettersUsingMySQL(convertUtf8Raw)), common.CharsetUTF8MB4, targetDBCharset)
convertTargetRaw, err := common.CharsetConvert(convertUtf8Raw, common.CharsetUTF8MB4, targetDBCharset)
if err != nil {
return fmt.Errorf("column [%s] charset convert failed, %v", columnNames[i], err)
}
Expand Down
41 changes: 33 additions & 8 deletions test/m.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func main() {
// MySQL 数据库连接信息
dsn := "root:@tcp(123.912.139.333:4000)/marvin"
dsn := "root:@tcp(120.92.19.233:4000)/marvin"

// 打开数据库连接
db, err := sql.Open("mysql", dsn)
Expand All @@ -34,7 +34,7 @@ func main() {
defer db.Close()

// 准备 SQL 语句
sqlStatement := "INSERT INTO user (name, age) VALUES (?, ?)"
sqlStatement := "INSERT INTO marvin01 (mdate) VALUES (?)"
stmt, err := db.Prepare(sqlStatement)
if err != nil {
log.Fatal(err)
Expand All @@ -55,14 +55,13 @@ func main() {

// 批量插入数据
for _, data := range []struct {
Name string
Age int
mdate string
}{
{"John", 25},
{"Alice", 30},
{"Bob", 22},
{"18\\:49\\:26"},
{"18\\:49\\:26"},
{"18\\:49\\:26"},
} {
_, err := tx.Stmt(stmt).Exec(data.Name, data.Age)
_, err := tx.Stmt(stmt).Exec(data.mdate)
if err != nil {
log.Fatal(err)
}
Expand All @@ -74,6 +73,32 @@ func main() {
log.Fatal(err)
}

for _, data := range []struct {
mdate string
}{
{"18\\:50\\:26"},
{"18\\:50\\:26"},
{"18\\:50\\:26"},
} {
_, err = db.Exec("INSERT INTO marvin01 (mdate) VALUES (?)", data.mdate)
if err != nil {
log.Fatal(err)
}
}

for _, data := range []struct {
mdate string
}{
{"18\\:52\\:26"},
{"18\\:52\\:26"},
{"18\\:52\\:26"},
} {
_, err = db.Exec(fmt.Sprintf("INSERT INTO marvin01 (mdate) VALUES ('%v')", data.mdate))
if err != nil {
log.Fatal(err)
}
}

fmt.Println("Batch insert successful.")

}

0 comments on commit 8db898e

Please sign in to comment.