提交 9ec412a8 authored 作者: Thomas Mueller's avatar Thomas Mueller

The functions LENGTH, OCTET_LENGTH, and BIT_LENGTH now return BIGINT.

上级 a63e3768
......@@ -2303,7 +2303,7 @@ Returns the ASCII value of the first character in the string.
ASCII('Hi')
"
"Functions (String)","BIT_LENGTH","
BIT_LENGTH(string): int
BIT_LENGTH(string): long
","
Returns the number of bits in a string. For BLOB, CLOB, BYTES and JAVA_OBJECT,
the precision is used. Each character needs 16 bits.
......@@ -2312,7 +2312,7 @@ BIT_LENGTH(NAME)
"
"Functions (String)","LENGTH","
{LENGTH | CHAR_LENGTH | CHARACTER_LENGTH}(string): int
{LENGTH | CHAR_LENGTH | CHARACTER_LENGTH}(string): long
","
Returns the number of characters in a string. For BLOB, CLOB, BYTES and
JAVA_OBJECT, the precision is used.
......@@ -2321,7 +2321,7 @@ LENGTH(NAME)
"
"Functions (String)","OCTET_LENGTH","
OCTET_LENGTH(string): int
OCTET_LENGTH(string): long
","
Returns the number of bytes in a string. For BLOB, CLOB, BYTES and JAVA_OBJECT,
the precision is used. Each character needs 2 bytes.
......
......@@ -201,7 +201,7 @@ public class Function extends Expression implements FunctionCall {
addFunctionNotDeterministic("SYS_GUID", RANDOM_UUID, 0, Value.UUID);
// string
addFunction("ASCII", ASCII, 1, Value.INT);
addFunction("BIT_LENGTH", BIT_LENGTH, 1, Value.INT);
addFunction("BIT_LENGTH", BIT_LENGTH, 1, Value.LONG);
addFunction("CHAR", CHAR, 1, Value.STRING);
addFunction("CHR", CHAR, 1, Value.STRING);
addFunction("CHAR_LENGTH", CHAR_LENGTH, 1, Value.INT);
......@@ -213,14 +213,14 @@ public class Function extends Expression implements FunctionCall {
addFunctionWithNull("INSERT", INSERT, 4, Value.STRING);
addFunction("LCASE", LCASE, 1, Value.STRING);
addFunction("LEFT", LEFT, 2, Value.STRING);
addFunction("LENGTH", LENGTH, 1, Value.INT);
addFunction("LENGTH", LENGTH, 1, Value.LONG);
// 2 or 3 arguments
addFunction("LOCATE", LOCATE, VAR_ARGS, Value.INT);
// same as LOCATE with 2 arguments
addFunction("POSITION", LOCATE, 2, Value.INT);
addFunction("INSTR", INSTR, VAR_ARGS, Value.INT);
addFunction("LTRIM", LTRIM, VAR_ARGS, Value.STRING);
addFunction("OCTET_LENGTH", OCTET_LENGTH, 1, Value.INT);
addFunction("OCTET_LENGTH", OCTET_LENGTH, 1, Value.LONG);
addFunction("RAWTOHEX", RAWTOHEX, 1, Value.STRING);
addFunction("REPEAT", REPEAT, 2, Value.STRING);
addFunctionWithNull("REPLACE", REPLACE, VAR_ARGS, Value.STRING);
......@@ -524,17 +524,17 @@ public class Function extends Expression implements FunctionCall {
break;
}
case BIT_LENGTH:
result = ValueInt.get(16 * length(v0));
result = ValueLong.get(16 * length(v0));
break;
case CHAR:
result = ValueString.get(String.valueOf((char) v0.getInt()));
break;
case CHAR_LENGTH:
case LENGTH:
result = ValueInt.get(length(v0));
result = ValueLong.get(length(v0));
break;
case OCTET_LENGTH:
result = ValueInt.get(2 * length(v0));
result = ValueLong.get(2 * length(v0));
break;
case CONCAT: {
result = ValueNull.INSTANCE;
......@@ -1157,13 +1157,13 @@ public class Function extends Expression implements FunctionCall {
return database.getSchema(schemaName).getSequence(sequenceName);
}
private int length(Value v) {
private long length(Value v) {
switch (v.getType()) {
case Value.BLOB:
case Value.CLOB:
case Value.BYTES:
case Value.JAVA_OBJECT:
return (int) v.getPrecision();
return v.getPrecision();
default:
return v.getString().length();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论