public <T> void prepareMerge(SQLStatement stat, String schemaName, String tableName,\r
TableDefinition<T> def, Object obj) {\r
\r
- if (databaseVersion < 9.5f) {\r
+ FieldDefinition primaryKey = null;\r
+ for (FieldDefinition field : def.fields) {\r
+ if (field.isPrimaryKey) {\r
+ primaryKey = field;\r
+ }\r
+ }\r
+\r
+ if (primaryKey == null || databaseVersion < 9.5f) {\r
// simulated UPSERT for <= 9.4 release\r
super.prepareMerge(stat, schemaName, tableName, def, obj);\r
return;\r
Object parameter = serialize(value, field.typeAdapter);\r
stat.addParameter(parameter);\r
}\r
- buff.append(") ON CONFLICT DO UPDATE SET");\r
+\r
+ buff.append(") ON CONFLICT (");\r
+ buff.resetCount();\r
+ for (FieldDefinition field : def.fields) {\r
+ if (field.isPrimaryKey) {\r
+ buff.appendExceptFirst(", ");\r
+ buff.append(field.columnName);\r
+ }\r
+ }\r
+ buff.append(") DO UPDATE SET ");\r
+ buff.resetCount();\r
+ for (FieldDefinition field : def.fields) {\r
+ buff.appendExceptFirst(", ");\r
+ buff.append(field.columnName);\r
+ buff.append("=?");\r
+ Object value = def.getValue(obj, field);\r
+ Object parameter = serialize(value, field.typeAdapter);\r
+ stat.addParameter(parameter);\r
+ }\r
stat.setSQL(buff.toString());\r
}\r
\r