提交 fd53ce0b authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Parse DATE as TIMESTAMP(0) in Oracle Mode

上级 07e4ef94
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
package org.h2.engine; package org.h2.engine;
import java.sql.Types;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
...@@ -289,7 +290,11 @@ public class Mode { ...@@ -289,7 +290,11 @@ public class Mode {
mode.supportedClientInfoPropertiesRegEx = mode.supportedClientInfoPropertiesRegEx =
Pattern.compile(".*\\..*"); Pattern.compile(".*\\..*");
mode.prohibitEmptyInPredicate = true; mode.prohibitEmptyInPredicate = true;
mode.typeByNameMap.put("DATE", DataType.getDataType(Value.TIMESTAMP)); DataType dt = DataType.createDate(/* 2001-01-01 23:59:59 */ 19, 19, "DATE", false, 0, 0);
dt.type = Value.TIMESTAMP;
dt.sqlType = Types.TIMESTAMP;
dt.name = "DATE";
mode.typeByNameMap.put("DATE", dt);
add(mode); add(mode);
mode = new Mode(ModeEnum.PostgreSQL); mode = new Mode(ModeEnum.PostgreSQL);
......
...@@ -466,7 +466,18 @@ public class DataType { ...@@ -466,7 +466,18 @@ public class DataType {
return dataType; return dataType;
} }
private static DataType createDate(int maxPrecision, int precision, String prefix, /**
* Create a date-time data type.
*
* @param maxPrecision maximum supported precision
* @param precision default precision
* @param prefix the prefix for SQL literal representation
* @param supportsScale whether the scale parameter is supported
* @param scale default scale
* @param maxScale highest possible scale
* @return data type
*/
public static DataType createDate(int maxPrecision, int precision, String prefix,
boolean supportsScale, int scale, int maxScale) { boolean supportsScale, int scale, int maxScale) {
DataType dataType = new DataType(); DataType dataType = new DataType();
dataType.prefix = prefix + " '"; dataType.prefix = prefix + " '";
......
...@@ -263,12 +263,12 @@ public class TestCompatibilityOracle extends TestDb { ...@@ -263,12 +263,12 @@ public class TestCompatibilityOracle extends TestDb {
Timestamp t4 = Timestamp.valueOf("2018-01-10 22:10:01"); Timestamp t4 = Timestamp.valueOf("2018-01-10 22:10:01");
stat.execute("CREATE TABLE TEST (ID INT PRIMARY KEY, D DATE)"); stat.execute("CREATE TABLE TEST (ID INT PRIMARY KEY, D DATE)");
stat.executeUpdate("INSERT INTO TEST VALUES(1, TIMESTAMP '2011-02-03 12:11:10')"); stat.executeUpdate("INSERT INTO TEST VALUES(1, TIMESTAMP '2011-02-03 12:11:10.1')");
stat.executeUpdate("INSERT INTO TEST VALUES(2, CAST ('1999-10-15 13:14:15' AS DATE))"); stat.executeUpdate("INSERT INTO TEST VALUES(2, CAST ('1999-10-15 13:14:15.1' AS DATE))");
stat.executeUpdate("INSERT INTO TEST VALUES(3, '2030-11-22 11:22:33')"); stat.executeUpdate("INSERT INTO TEST VALUES(3, '2030-11-22 11:22:33.1')");
PreparedStatement ps = conn.prepareStatement("INSERT INTO TEST VALUES (?, ?)"); PreparedStatement ps = conn.prepareStatement("INSERT INTO TEST VALUES (?, ?)");
ps.setInt(1, 4); ps.setInt(1, 4);
ps.setTimestamp(2, t4); ps.setTimestamp(2, Timestamp.valueOf("2018-01-10 22:10:01.1"));
ps.executeUpdate(); ps.executeUpdate();
ResultSet rs = stat.executeQuery("SELECT D FROM TEST ORDER BY ID"); ResultSet rs = stat.executeQuery("SELECT D FROM TEST ORDER BY ID");
rs.next(); rs.next();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论