From a3e3bececf6a6a19c94286dcc83708e9f99d4f54 Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Wed, 1 Nov 2023 10:00:09 +0900 Subject: [PATCH] Fixed INSERT failure when there are many columns Fixed INSERT failure when number of columns is greater than maxBulk. Increased maxBulk to 1000. --- database.go | 6 +++++- database_connect.go | 2 +- database_connect_cgo.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/database.go b/database.go index 7e91d2b..501e7a0 100644 --- a/database.go +++ b/database.go @@ -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() diff --git a/database_connect.go b/database_connect.go index 7367fca..9b4f1d7 100644 --- a/database_connect.go +++ b/database_connect.go @@ -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 diff --git a/database_connect_cgo.go b/database_connect_cgo.go index 2f9a0f1..702be9a 100644 --- a/database_connect_cgo.go +++ b/database_connect_cgo.go @@ -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