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