Use default values for the values section of an insert statement for hsqldb as well as postgres

It blows up expecting a column name in the values parenthesis, but the default values string that
postgres was working seems to work. It's not in http://hsqldb.org/doc/guide/ch09.html, but so it
goes.
This commit is contained in:
Charlie Groves
2011-06-24 19:25:57 +00:00
parent a28990116c
commit 7ba475e61c
5 changed files with 75 additions and 22 deletions
@@ -919,6 +919,12 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
}
}
// output the column name and value portion of an insert when all values are defaulted
protected void appendEmptyInsertValues ()
{
_builder.append("default values");
}
// output the column names and values for an insert
protected void appendInsertColumns (InsertClause insertClause)
{
@@ -928,6 +934,18 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
Set<String> idFields = insertClause.getIdentityFields();
ColumnExp<?>[] fields = marsh.getColumnFieldNames();
boolean insertingSomething = false;
for (ColumnExp<?> field : fields) {
if (!idFields.contains(field.name)) {
insertingSomething = true;
break;
}
}
if (!insertingSomething) {
appendEmptyInsertValues();
return;
}
_builder.append("(");
boolean comma = false;
for (ColumnExp<?> field : fields) {
@@ -155,6 +155,11 @@ public class MySQLBuilder
bindValue(fullText.getQuery());
_builder.append(" in boolean mode)");
}
@Override protected void appendEmptyInsertValues ()
{
_builder.append("() values ()");
}
}
public MySQLBuilder (DepotTypes types)
@@ -22,8 +22,6 @@ import com.samskivert.depot.Exps;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.annotation.FullTextIndex.Configuration;
import com.samskivert.depot.annotation.FullTextIndex;
import com.samskivert.depot.clause.InsertClause;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.impl.expression.IntervalExp;
import com.samskivert.depot.impl.expression.DateFun.DatePart;
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
@@ -121,22 +119,6 @@ public class PostgreSQLBuilder
_builder.append("\"").append(field).append("\"");
}
@Override protected void appendInsertColumns (InsertClause insertClause)
{
// see if we will be inserting any columns whatsoever
Class<? extends PersistentRecord> pClass = insertClause.getPersistentClass();
Set<String> idFields = insertClause.getIdentityFields();
for (ColumnExp<?> field : _types.getMarshaller(pClass).getColumnFieldNames()) {
if (!idFields.contains(field.name)) {
// we found a field we're inserting, so call super and finish
super.appendInsertColumns(insertClause);
return;
}
}
// we never found anything we'll actually be inserting
_builder.append("default values");
}
protected PGBuildVisitor (DepotTypes types)
{
super(types, true);