Skip to content

Commit

Permalink
Merge pull request #249 from noborus/fix-maxbulk
Browse files Browse the repository at this point in the history
Fixed INSERT failure when there are many columns
  • Loading branch information
noborus authored Nov 1, 2023
2 parents 4f87009 + a3e3bec commit 1ac533b
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 1ac533b

Please sign in to comment.