[#430] Add support for the Firebird database - Fixed DATE TIME
arithmetic
This commit is contained in:
parent
dfb0bfda4c
commit
426ec1fed9
@ -82,6 +82,9 @@ class DateDiff extends AbstractFunction<Integer> {
|
||||
case DERBY:
|
||||
return field("{fn {timestampdiff}({sql_tsi_day}, {0}, {1}) }", getDataType(), date2, date1);
|
||||
|
||||
case FIREBIRD:
|
||||
return field("{datediff}(day, {0}, {1})", getDataType(), date2, date1);
|
||||
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
return field("{datediff}('day', {0}, {1})", getDataType(), date2, date1);
|
||||
|
||||
@ -129,6 +129,10 @@ class Expression<T> extends AbstractFunction<T> {
|
||||
final Field<T> getFunction0(Configuration configuration) {
|
||||
SQLDialect dialect = configuration.getDialect();
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// XXX: Bitwise operators
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
// DB2, H2 and HSQLDB know functions, instead of operators
|
||||
if (BIT_AND == operator && asList(DB2, H2, HSQLDB, ORACLE).contains(dialect)) {
|
||||
return function("bitand", getDataType(), getArguments());
|
||||
@ -188,6 +192,10 @@ class Expression<T> extends AbstractFunction<T> {
|
||||
return (Field<T>) bitNot(bitXor(lhsAsNumber(), rhsAsNumber()));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// XXX: Date time arithmetic operators
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
// [#585] Date time arithmetic for numeric or interval RHS
|
||||
else if (asList(ADD, SUBTRACT).contains(operator) &&
|
||||
lhs.getDataType().isDateTime() &&
|
||||
@ -197,6 +205,10 @@ class Expression<T> extends AbstractFunction<T> {
|
||||
return new DateExpression();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// XXX: Other operators
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
// Use the default operator expression for all other cases
|
||||
else {
|
||||
return new DefaultExpression();
|
||||
@ -362,6 +374,15 @@ class Expression<T> extends AbstractFunction<T> {
|
||||
}
|
||||
}
|
||||
|
||||
case FIREBIRD: {
|
||||
if (rhs.get(0).getType() == YearToMonth.class) {
|
||||
return field("{dateadd}({month}, {0}, {1})", getDataType(), val(sign * rhsAsYTM().intValue()), lhs);
|
||||
}
|
||||
else {
|
||||
return field("{dateadd}({millisecond}, {0}, {1})", getDataType(), val(sign * (long) rhsAsDTS().getTotalMilli()), lhs);
|
||||
}
|
||||
}
|
||||
|
||||
case H2: {
|
||||
if (rhs.get(0).getType() == YearToMonth.class) {
|
||||
return field("{dateadd}('month', {0}, {1})", getDataType(), val(sign * rhsAsYTM().intValue()), lhs);
|
||||
@ -399,6 +420,7 @@ class Expression<T> extends AbstractFunction<T> {
|
||||
private final Field<T> getNumberExpression(Configuration configuration) {
|
||||
switch (configuration.getDialect()) {
|
||||
case ASE:
|
||||
case FIREBIRD:
|
||||
case SQLSERVER:
|
||||
case SYBASE: {
|
||||
if (operator == ADD) {
|
||||
|
||||
@ -97,6 +97,9 @@ class TimestampDiff extends AbstractFunction<DayToSecond> {
|
||||
case DERBY:
|
||||
return (Field) field("1000 * {fn {timestampdiff}({sql_tsi_second}, {0}, {1}) }", INTEGER, timestamp2, timestamp1);
|
||||
|
||||
case FIREBIRD:
|
||||
return field("{datediff}(millisecond, {0}, {1})", getDataType(), timestamp2, timestamp1);
|
||||
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
return field("{datediff}('ms', {0}, {1})", getDataType(), timestamp2, timestamp1);
|
||||
|
||||
@ -68,15 +68,14 @@ public class FirebirdDataType<T> extends AbstractDataType<T> {
|
||||
public static final FirebirdDataType<Short> SMALLINT = new FirebirdDataType<Short>(SQLDataType.SMALLINT, "smallint");
|
||||
public static final FirebirdDataType<Integer> INTEGER = new FirebirdDataType<Integer>(SQLDataType.INTEGER, "integer");
|
||||
public static final FirebirdDataType<Integer> INT = new FirebirdDataType<Integer>(SQLDataType.INTEGER, "int");
|
||||
public static final FirebirdDataType<Long> INT64 = new FirebirdDataType<Long>(SQLDataType.BIGINT, "int64");
|
||||
public static final FirebirdDataType<Long> BIGINT = new FirebirdDataType<Long>(SQLDataType.BIGINT, "bigint");
|
||||
public static final FirebirdDataType<Double> DOUBLEPRECISION = new FirebirdDataType<Double>(SQLDataType.DOUBLE, "double precision");
|
||||
public static final FirebirdDataType<Float> FLOAT = new FirebirdDataType<Float>(SQLDataType.REAL, "float");
|
||||
public static final FirebirdDataType<Boolean> BOOLEAN = new FirebirdDataType<Boolean>(SQLDataType.BOOLEAN, "boolean");
|
||||
public static final FirebirdDataType<BigDecimal> DECIMAL = new FirebirdDataType<BigDecimal>(SQLDataType.DECIMAL, "decimal");
|
||||
public static final FirebirdDataType<BigDecimal> NUMERIC = new FirebirdDataType<BigDecimal>(SQLDataType.NUMERIC, "numeric");
|
||||
public static final FirebirdDataType<String> VARCHAR = new FirebirdDataType<String>(SQLDataType.VARCHAR, "varchar", "varchar(32672)");
|
||||
public static final FirebirdDataType<String> CHARACTERVARYING = new FirebirdDataType<String>(SQLDataType.VARCHAR, "character varying", "varchar(32672)");
|
||||
public static final FirebirdDataType<String> VARCHAR = new FirebirdDataType<String>(SQLDataType.VARCHAR, "varchar", "varchar(2000)");
|
||||
public static final FirebirdDataType<String> CHARACTERVARYING = new FirebirdDataType<String>(SQLDataType.VARCHAR, "character varying", "varchar(2000)");
|
||||
public static final FirebirdDataType<String> CHAR = new FirebirdDataType<String>(SQLDataType.CHAR, "char");
|
||||
public static final FirebirdDataType<String> CHARACTER = new FirebirdDataType<String>(SQLDataType.CHAR, "character");
|
||||
public static final FirebirdDataType<String> CLOB = new FirebirdDataType<String>(SQLDataType.CLOB, "blob sub_type text");
|
||||
@ -100,10 +99,10 @@ public class FirebirdDataType<T> extends AbstractDataType<T> {
|
||||
protected static final FirebirdDataType<Double> __FLOAT = new FirebirdDataType<Double>(SQLDataType.FLOAT, "double precision");
|
||||
protected static final FirebirdDataType<String> __LONGNVARCHAR = new FirebirdDataType<String>(SQLDataType.LONGNVARCHAR, "blob sub_type text");
|
||||
protected static final FirebirdDataType<byte[]> __LONGVARBINARY = new FirebirdDataType<byte[]>(SQLDataType.LONGVARBINARY, "blob");
|
||||
protected static final FirebirdDataType<String> __LONGVARCHAR = new FirebirdDataType<String>(SQLDataType.LONGVARCHAR, "varchar", "varchar(32672)");
|
||||
protected static final FirebirdDataType<String> __LONGVARCHAR = new FirebirdDataType<String>(SQLDataType.LONGVARCHAR, "varchar", "varchar(2000)");
|
||||
protected static final FirebirdDataType<String> __NCHAR = new FirebirdDataType<String>(SQLDataType.NCHAR, "char");
|
||||
protected static final FirebirdDataType<String> __NCLOB = new FirebirdDataType<String>(SQLDataType.NCLOB, "clob");
|
||||
protected static final FirebirdDataType<String> __NVARCHAR = new FirebirdDataType<String>(SQLDataType.NVARCHAR, "varchar", "varchar(32672)");
|
||||
protected static final FirebirdDataType<String> __NVARCHAR = new FirebirdDataType<String>(SQLDataType.NVARCHAR, "varchar", "varchar(2000)");
|
||||
protected static final FirebirdDataType<Byte> __TINYINT = new FirebirdDataType<Byte>(SQLDataType.TINYINT, "smallint");
|
||||
protected static final FirebirdDataType<byte[]> __VARBINARY = new FirebirdDataType<byte[]>(SQLDataType.VARBINARY, "blob");
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user