Fix upsert for mysql

This commit is contained in:
Patrick O'brien 2016-09-19 17:51:06 +10:00
parent b869d2be8b
commit 4a9e7a1b1a

View file

@ -190,6 +190,17 @@ func BuildUpsertQueryMySQL(dia Dialect, tableName string, update, whitelist []st
buf := strmangle.GetBuffer()
defer strmangle.PutBuffer(buf)
if len(update) == 0 {
fmt.Fprintf(
buf,
"INSERT IGNORE INTO %s (%s) VALUES (%s)",
tableName,
strings.Join(whitelist, ", "),
strmangle.Placeholders(dia.IndexPlaceholders, len(whitelist), 1, 1),
)
return buf.String()
}
fmt.Fprintf(
buf,
"INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE ",