if ((updateColumns != null) && (mode != MODE_UPDATE))
throw new RuntimeException("Property 'updateColumns' only support with MODE_UPDATE.");
if ((updateColumns == null) && (mode == MODE_UPDATE))
throw new RuntimeException("MODE_UPDATE must set property 'updateColumns'.");
ResultSetMeta metaInfos = getTableMetaInfos(tableName);
ColumnInfo[] columnInfos = metaInfos.getColumns();
if ((mode == MODE_INSERT_INTO) || (mode == MODE_REPLACE_INTO) || (mode == MODE_INSERT_IGNORE_INTO)) {
if (metaInfos.isAutoIncrement() && (mode == MODE_INSERT_INTO)) {
ColumnInfo[] columnInfos2 = new ColumnInfo[columnInfos.length -1];
System.arraycopy(columnInfos, 1, columnInfos2, 0, columnInfos2.length);
columnInfos = columnInfos2;
}
StringBuilder strFields = new StringBuilder();
StringBuilder strValues = new StringBuilder();
for (int i=0; i <columnInfos.length; i++) {
if (i > 0) {
strFields.append(", ");
strValues.append(", ");
}
strFields.append(columnInfos[i].getName());
strValues.append('?');
}
this.sql = (mode == MODE_INSERT_INTO ? "INSERT INTO" : (mode == MODE_REPLACE_INTO ? "REPLACE INTO" : "INSERT IGNORE INTO")) +" "+ this.tableName
+"("+ strFields.toString() +") VALUES ("+ strValues.toString() +")";
this.columnInfos = columnInfos;
}
else if (mode == MODE_DELETE) {
if (metaInfos.getKeyColumnCount() <= 0)
throw new RuntimeException("Table for DELETE must have PRIMARY KEY");
ColumnInfo[] keyColumns = new ColumnInfo[metaInfos.getKeyColumnCount()];
System.arraycopy(columnInfos, 0, keyColumns, 0, keyColumns.length);
StringBuilder strWhere = new StringBuilder();
for (int i=0; i < keyColumns.length; i++) {
if (i > 0) strWhere.append(" AND ");
strWhere.append(keyColumns[i].getName());
strWhere.append("=?");
}
this.sql = "DELETE FROM " + this.tableName +" WHERE "+ strWhere.toString();
this.columnInfos = keyColumns;
}
else if (mode == MODE_UPDATE) {
if (metaInfos.getKeyColumnCount() <= 0)
throw new RuntimeException("Table for UPDATE must have PRIMARY KEY");
ColumnInfo[] keyColumns = new ColumnInfo[metaInfos.getKeyColumnCount()];
System.arraycopy(columnInfos, 0, keyColumns, 0, keyColumns.length);
StringBuilder strWhere = new StringBuilder();
for (int i=0; i < keyColumns.length; i++) {
if (i > 0) strWhere.append(" AND ");
strWhere.append(keyColumns[i].getName());