Renamed DbMapping.isStringColumn() method to DbMapping.needsQuotes and

included DATE, TIME and TIMESTAMP in the list of types that need to be quoted.
This commit is contained in:
hns 2002-09-06 14:09:11 +00:00
parent 2f74c6cc03
commit 8d35255716
2 changed files with 19 additions and 6 deletions

View file

@ -568,10 +568,10 @@ public final class DbMapping implements Updatable {
} }
/** /**
* Return true if the column identified by the parameter is a string type. This is * Return true if values for the column identified by the parameter need
* used in query building to determine if a value needs to be quoted. * to be quoted in SQL queries.
*/ */
public boolean isStringColumn (String columnName) throws SQLException { public boolean needsQuotes (String columnName) throws SQLException {
try { try {
Schema s = getSchema (); Schema s = getSchema ();
if (s == null) if (s == null)
@ -579,7 +579,20 @@ public final class DbMapping implements Updatable {
Column c = s.getColumn (columnName); Column c = s.getColumn (columnName);
if (c == null) if (c == null)
throw new SQLException ("Column "+columnName+" not found in "+this); throw new SQLException ("Column "+columnName+" not found in "+this);
return c.isString () || c.isVarBinary () || c.isLongVarBinary (); switch (c.typeEnum()) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
return true;
default:
return false;
}
} catch (Exception x) { } catch (Exception x) {
throw new SQLException (x.getMessage ()); throw new SQLException (x.getMessage ());
} }

View file

@ -367,7 +367,7 @@ public final class Relation {
q.append (accessColumn); q.append (accessColumn);
q.append (" = "); q.append (" = ");
// check if column is string type and value needs to be quoted // check if column is string type and value needs to be quoted
if (otherType.isStringColumn (accessColumn)) { if (otherType.needsQuotes (accessColumn)) {
q.append ("'"); q.append ("'");
q.append (escape (kstr)); q.append (escape (kstr));
q.append ("'"); q.append ("'");
@ -554,7 +554,7 @@ public final class Relation {
} }
q.append (foreignName); q.append (foreignName);
q.append (" = "); q.append (" = ");
if (otherType.isStringColumn (foreignName)) { if (otherType.needsQuotes (foreignName)) {
q.append ("'"); q.append ("'");
q.append (escape (local)); q.append (escape (local));
q.append ("'"); q.append ("'");