Skip to content

Commit

Permalink
Fixed INSERT failure when there are many columns
Browse files Browse the repository at this point in the history
Fixed INSERT failure when number of columns is greater than maxBulk.
Increased maxBulk to 1000.
  • Loading branch information
noborus committed Nov 1, 2023
1 parent 4f87009 commit a3e3bec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ func (db *DB) insertImport(ctx context.Context, table *importTable, reader Reade
var stmt *sql.Stmt
defer db.stmtClose(stmt)

table.maxCap = (db.maxBulk / len(table.row)) * len(table.row)
if len(table.row) > db.maxBulk {
table.maxCap = len(table.row)
} else {
table.maxCap = (db.maxBulk / len(table.row)) * len(table.row)
}
bulk := make([]interface{}, 0, table.maxCap)

preRows := reader.PreReadRow()
Expand Down
2 changes: 1 addition & 1 deletion database_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Connect(driver, dsn string) (*DB, error) {
switch driver {
case "sqlite3", "sqlite3_ext", "sqlite":
db.quote = "`"
db.maxBulk = 500
db.maxBulk = 1000
case "mysql":
db.quote = "`"
db.maxBulk = 1000
Expand Down
2 changes: 1 addition & 1 deletion database_connect_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Connect(driver, dsn string) (*DB, error) {
switch driver {
case "sqlite3", "sqlite3_ext", "sqlite":
db.quote = "`"
db.maxBulk = 500
db.maxBulk = 10000
case "mysql":
db.quote = "`"
db.maxBulk = 1000
Expand Down

0 comments on commit a3e3bec

Please sign in to comment.