提交 fa65d743 authored 作者: Thomas Mueller's avatar Thomas Mueller

Timestamp columns such as TIMESTAMP(6) were not compatible to other database.

上级 854bdc17
...@@ -3244,8 +3244,8 @@ public class Parser { ...@@ -3244,8 +3244,8 @@ public class Parser {
dataType = DataType.getTypeByName(original); dataType = DataType.getTypeByName(original);
} }
if (dataType.type == Value.NULL) { if (dataType.type == Value.NULL) {
// we do support NULL in the database meta data, // We do support NULL in the database meta data,
// but not actually when creating tables // but not actually when creating tables.
throw Message.getSQLException(ErrorCode.UNKNOWN_DATA_TYPE_1, original); throw Message.getSQLException(ErrorCode.UNKNOWN_DATA_TYPE_1, original);
} }
if (regular) { if (regular) {
...@@ -3256,35 +3256,42 @@ public class Parser { ...@@ -3256,35 +3256,42 @@ public class Parser {
scale = scale == -1 ? dataType.defaultScale : scale; scale = scale == -1 ? dataType.defaultScale : scale;
if (dataType.supportsPrecision || dataType.supportsScale) { if (dataType.supportsPrecision || dataType.supportsScale) {
if (readIf("(")) { if (readIf("(")) {
precision = readLong(); long p = readLong();
if (readIf("K")) { if (readIf("K")) {
precision *= 1024; p *= 1024;
} else if (readIf("M")) { } else if (readIf("M")) {
precision *= 1024 * 1024; p *= 1024 * 1024;
} else if (readIf("G")) { } else if (readIf("G")) {
precision *= 1024 * 1024 * 1024; p *= 1024 * 1024 * 1024;
} }
if (precision > Long.MAX_VALUE) { if (p > Long.MAX_VALUE) {
precision = Long.MAX_VALUE; p = Long.MAX_VALUE;
} }
displaySize = MathUtils.convertLongToInt(precision); original += "(" + p;
original += "(" + precision; // Oracle syntax
// oracle syntax
readIf("CHAR"); readIf("CHAR");
if (dataType.supportsScale) { if (dataType.supportsScale) {
if (readIf(",")) { if (readIf(",")) {
scale = getInt(); scale = getInt();
original += ", " + scale; original += ", " + scale;
} else {
// special case: TIMESTAMP(5) actually means TIMESTAMP(23, 5)
if (dataType.type == Value.TIMESTAMP) {
scale = MathUtils.convertLongToInt(p);
p = precision;
} else { } else {
scale = 0; scale = 0;
} }
} }
}
precision = p;
displaySize = MathUtils.convertLongToInt(precision);
original += ")"; original += ")";
read(")"); read(")");
} }
} else if (readIf("(")) { } else if (readIf("(")) {
// support for MySQL: INT(11), MEDIUMINT(8) and so on. Just ignore // Support for MySQL: INT(11), MEDIUMINT(8) and so on.
// the precision. // Just ignore the precision.
getPositiveInt(); getPositiveInt();
read(")"); read(")");
} }
......
--- special grammar and test cases --------------------------------------------------------------------------------------------- --- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(t0 timestamp(0), t1 timestamp(1), t4 timestamp(4));
> ok
select column_name, numeric_scale from information_schema.columns c where c.table_name = 'TEST' order by column_name;
> COLUMN_NAME NUMERIC_SCALE
> ----------- -------------
> T0 0
> T1 1
> T4 4
> rows (ordered): 3
drop table test;
> ok
create table test(id int); create table test(id int);
> ok > ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论