mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-22 00:42:47 +08:00
🐛 fix(sync/mysql): 修复批量导入占位符超限
- 识别 MySQL Prepared Statement 占位符超限错误 - 对被服务端拒绝的批量 INSERT 自动递归拆批重试 - 增加 24 列 1000 行数据同步回归测试
This commit is contained in:
@@ -163,6 +163,13 @@ func execParameterizedInsertBatch(config parameterizedInsertConfig, rows []prepa
|
||||
)
|
||||
res, err := config.Exec(query, args...)
|
||||
if err != nil {
|
||||
if len(rows) > 1 && isPreparedStatementPlaceholderLimitError(err) {
|
||||
middle := len(rows) / 2
|
||||
if err := execParameterizedInsertBatch(config, rows[:middle]); err != nil {
|
||||
return err
|
||||
}
|
||||
return execParameterizedInsertBatch(config, rows[middle:])
|
||||
}
|
||||
return localizedDatabaseRuntimeError("db.backend.error.batch_insert_failed", map[string]any{"detail": err.Error()})
|
||||
}
|
||||
if config.RequireAffected {
|
||||
@@ -173,6 +180,13 @@ func execParameterizedInsertBatch(config parameterizedInsertConfig, rows []prepa
|
||||
return nil
|
||||
}
|
||||
|
||||
func isPreparedStatementPlaceholderLimitError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(strings.ToLower(err.Error()), "prepared statement contains too many placeholders")
|
||||
}
|
||||
|
||||
func requireInsertAffected(result sql.Result) error {
|
||||
if result == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user