This commit is contained in:
Redkale
2018-05-05 11:22:26 +08:00
parent 1807287321
commit 1abdb3b874

View File

@@ -671,15 +671,16 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
join1 = multisplit('[', ']', ",", new StringBuilder(), joinstr, 0); join1 = multisplit('[', ']', ",", new StringBuilder(), joinstr, 0);
join2 = multisplit('{', '}', " AND ", new StringBuilder(), joinstr, 0); join2 = multisplit('{', '}', " AND ", new StringBuilder(), joinstr, 0);
} }
String alias = "postgresql".equals(writePool.dbtype) ? null : "a"; //postgresql的BUG UPDATE的SET中不能含别名
if (value instanceof byte[]) { if (value instanceof byte[]) {
String sql = "UPDATE " + info.getTable(node) + " a " + (join1 == null ? "" : (", " + join1)) String sql = "UPDATE " + info.getTable(node) + " a " + (join1 == null ? "" : (", " + join1))
+ " SET " + info.getSQLColumn("a", column) + " = " + prepareParamSign(1) + " SET " + info.getSQLColumn(alias, column) + " = " + prepareParamSign(1)
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2)) + ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2)))); : (" WHERE " + where + (join2 == null ? "" : (" AND " + join2))));
return updateDB(info, null, sql, true, value); return updateDB(info, null, sql, true, value);
} else { } else {
String sql = "UPDATE " + info.getTable(node) + " a " + (join1 == null ? "" : (", " + join1)) String sql = "UPDATE " + info.getTable(node) + " a " + (join1 == null ? "" : (", " + join1))
+ " SET " + info.getSQLColumn("a", column) + " = " + info.formatToString(value) + " SET " + info.getSQLColumn(alias, column) + " = " + info.formatToString(value)
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2)) + ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2)))); : (" WHERE " + where + (join2 == null ? "" : (" AND " + join2))));
return updateDB(info, null, sql, false); return updateDB(info, null, sql, false);
@@ -816,11 +817,12 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
StringBuilder setsql = new StringBuilder(); StringBuilder setsql = new StringBuilder();
List<byte[]> blobs = null; List<byte[]> blobs = null;
int index = 0; int index = 0;
String alias = "postgresql".equals(writePool.dbtype) ? null : "a"; //postgresql的BUG UPDATE的SET中不能含别名
for (ColumnValue col : values) { for (ColumnValue col : values) {
Attribute<T, Serializable> attr = info.getUpdateAttribute(col.getColumn()); Attribute<T, Serializable> attr = info.getUpdateAttribute(col.getColumn());
if (attr == null) continue; if (attr == null) continue;
if (setsql.length() > 0) setsql.append(", "); if (setsql.length() > 0) setsql.append(", ");
String c = info.getSQLColumn("a", col.getColumn()); String c = info.getSQLColumn(alias, col.getColumn());
if (col.getValue() instanceof byte[]) { if (col.getValue() instanceof byte[]) {
if (blobs == null) blobs = new ArrayList<>(); if (blobs == null) blobs = new ArrayList<>();
blobs.add((byte[]) col.getValue()); blobs.add((byte[]) col.getValue());
@@ -949,10 +951,11 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
StringBuilder setsql = new StringBuilder(); StringBuilder setsql = new StringBuilder();
List<byte[]> blobs = null; List<byte[]> blobs = null;
int index = 0; int index = 0;
String alias = "postgresql".equals(writePool.dbtype) ? null : "a"; //postgresql的BUG UPDATE的SET中不能含别名
for (Attribute<T, Serializable> attr : info.updateAttributes) { for (Attribute<T, Serializable> attr : info.updateAttributes) {
if (!selects.test(attr.field())) continue; if (!selects.test(attr.field())) continue;
if (setsql.length() > 0) setsql.append(", "); if (setsql.length() > 0) setsql.append(", ");
setsql.append(info.getSQLColumn("a", attr.field())); setsql.append(info.getSQLColumn(alias, attr.field()));
Serializable val = attr.get(bean); Serializable val = attr.get(bean);
if (val instanceof byte[]) { if (val instanceof byte[]) {
if (blobs == null) blobs = new ArrayList<>(); if (blobs == null) blobs = new ArrayList<>();
@@ -980,7 +983,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
return updateDB(info, null, sql, true, blobs.toArray()); return updateDB(info, null, sql, true, blobs.toArray());
} else { } else {
final Serializable id = info.getPrimary().get(bean); final Serializable id = info.getPrimary().get(bean);
String sql = "UPDATE " + info.getTable(id) + " SET " + setsql + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(id); String sql = "UPDATE " + info.getTable(id) + " a SET " + setsql + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(id);
if (blobs == null) return updateDB(info, null, sql, false); if (blobs == null) return updateDB(info, null, sql, false);
return updateDB(info, null, sql, true, blobs.toArray()); return updateDB(info, null, sql, true, blobs.toArray());
} }