提交 1c47ba6b authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add limited support for MONEY and SMALLMONEY data types in compatibility modes

上级 fd53ce0b
......@@ -259,6 +259,16 @@ public class Mode {
// MS SQL Server does not support client info properties. See
// https://msdn.microsoft.com/en-Us/library/dd571296%28v=sql.110%29.aspx
mode.supportedClientInfoPropertiesRegEx = null;
DataType dt = DataType.createDecimal(19, 19, 4, 21, false, false);
dt.type = Value.DECIMAL;
dt.sqlType = Types.NUMERIC;
dt.name = "MONEY";
mode.typeByNameMap.put("MONEY", dt);
dt = DataType.createDecimal(10, 10, 4, 12, false, false);
dt.type = Value.DECIMAL;
dt.sqlType = Types.NUMERIC;
dt.name = "MONEY";
mode.typeByNameMap.put("SMALLMONEY", dt);
add(mode);
mode = new Mode(ModeEnum.MySQL);
......@@ -290,7 +300,7 @@ public class Mode {
mode.supportedClientInfoPropertiesRegEx =
Pattern.compile(".*\\..*");
mode.prohibitEmptyInPredicate = true;
DataType dt = DataType.createDate(/* 2001-01-01 23:59:59 */ 19, 19, "DATE", false, 0, 0);
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";
......@@ -318,6 +328,11 @@ public class Mode {
disallowedTypes.add("TINYINT");
disallowedTypes.add("BLOB");
mode.disallowedTypes = disallowedTypes;
dt = DataType.createDecimal(19, 19, 2, 21, false, false);
dt.type = Value.DECIMAL;
dt.sqlType = Types.NUMERIC;
dt.name = "MONEY";
mode.typeByNameMap.put("MONEY", dt);
add(mode);
mode = new Mode(ModeEnum.Ignite);
......
......@@ -448,7 +448,18 @@ public class DataType {
}
}
private static DataType createDecimal(int maxPrecision,
/**
* Create a numeric data type.
*
* @param maxPrecision maximum supported precision
* @param defaultPrecision default precision
* @param defaultScale default scale
* @param defaultDisplaySize default display size
* @param needsPrecisionAndScale where precision and scale are supported
* @param autoInc whether the data type is an auto-increment type
* @return data type
*/
public static DataType createDecimal(int maxPrecision,
int defaultPrecision, int defaultScale, int defaultDisplaySize,
boolean needsPrecisionAndScale, boolean autoInc) {
DataType dataType = new DataType();
......
......@@ -5,6 +5,7 @@
*/
package org.h2.test.db;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
......@@ -276,6 +277,21 @@ public class TestCompatibility extends TestDb {
/* Expected! */
}
}
/* Test MONEY data type */
stat.execute("DROP TABLE IF EXISTS TEST");
stat.execute("CREATE TABLE TEST(M MONEY)");
stat.execute("INSERT INTO TEST(M) VALUES (-92233720368547758.08)");
stat.execute("INSERT INTO TEST(M) VALUES (0.11111)");
stat.execute("INSERT INTO TEST(M) VALUES (92233720368547758.07)");
ResultSet rs = stat.executeQuery("SELECT M FROM TEST ORDER BY M");
assertTrue(rs.next());
assertEquals(new BigDecimal("-92233720368547758.08"), rs.getBigDecimal(1));
assertTrue(rs.next());
assertEquals(new BigDecimal("0.11"), rs.getBigDecimal(1));
assertTrue(rs.next());
assertEquals(new BigDecimal("92233720368547758.07"), rs.getBigDecimal(1));
assertFalse(rs.next());
}
private void testMySQL() throws SQLException {
......@@ -496,6 +512,36 @@ public class TestCompatibility extends TestDb {
// UNIQUEIDENTIFIER is MSSQL's equivalent of UUID
stat.execute("create table test3 (id UNIQUEIDENTIFIER)");
/* Test MONEY data type */
stat.execute("DROP TABLE IF EXISTS TEST");
stat.execute("CREATE TABLE TEST(M MONEY)");
stat.execute("INSERT INTO TEST(M) VALUES (-922337203685477.5808)");
stat.execute("INSERT INTO TEST(M) VALUES (0.11111)");
stat.execute("INSERT INTO TEST(M) VALUES (922337203685477.5807)");
rs = stat.executeQuery("SELECT M FROM TEST ORDER BY M");
assertTrue(rs.next());
assertEquals(new BigDecimal("-922337203685477.5808"), rs.getBigDecimal(1));
assertTrue(rs.next());
assertEquals(new BigDecimal("0.1111"), rs.getBigDecimal(1));
assertTrue(rs.next());
assertEquals(new BigDecimal("922337203685477.5807"), rs.getBigDecimal(1));
assertFalse(rs.next());
/* Test SMALLMONEY data type */
stat.execute("DROP TABLE IF EXISTS TEST");
stat.execute("CREATE TABLE TEST(M SMALLMONEY)");
stat.execute("INSERT INTO TEST(M) VALUES (-214748.3648)");
stat.execute("INSERT INTO TEST(M) VALUES (0.11111)");
stat.execute("INSERT INTO TEST(M) VALUES (214748.3647)");
rs = stat.executeQuery("SELECT M FROM TEST ORDER BY M");
assertTrue(rs.next());
assertEquals(new BigDecimal("-214748.3648"), rs.getBigDecimal(1));
assertTrue(rs.next());
assertEquals(new BigDecimal("0.1111"), rs.getBigDecimal(1));
assertTrue(rs.next());
assertEquals(new BigDecimal("214748.3647"), rs.getBigDecimal(1));
assertFalse(rs.next());
}
private void testDB2() throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论