提交 394ac43a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Parse CHARINDEX(), GETDATE(), and LEN() only in SQL Server compatibility mode

上级 5b022f39
...@@ -240,12 +240,8 @@ public class Function extends Expression implements FunctionCall { ...@@ -240,12 +240,8 @@ public class Function extends Expression implements FunctionCall {
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.LONG); addFunction("LENGTH", LENGTH, 1, Value.LONG);
// alias for MSSQLServer
addFunction("LEN", 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);
// alias for MSSQLServer
addFunction("CHARINDEX", 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);
...@@ -293,9 +289,6 @@ public class Function extends Expression implements FunctionCall { ...@@ -293,9 +289,6 @@ public class Function extends Expression implements FunctionCall {
addFunction("TO_TIMESTAMP", TO_TIMESTAMP, VAR_ARGS, Value.TIMESTAMP); addFunction("TO_TIMESTAMP", TO_TIMESTAMP, VAR_ARGS, Value.TIMESTAMP);
addFunction("ADD_MONTHS", ADD_MONTHS, 2, Value.TIMESTAMP); addFunction("ADD_MONTHS", ADD_MONTHS, 2, Value.TIMESTAMP);
addFunction("TO_TIMESTAMP_TZ", TO_TIMESTAMP_TZ, VAR_ARGS, Value.TIMESTAMP_TZ); addFunction("TO_TIMESTAMP_TZ", TO_TIMESTAMP_TZ, VAR_ARGS, Value.TIMESTAMP_TZ);
// alias for MSSQLServer
addFunctionNotDeterministic("GETDATE", CURDATE,
0, Value.DATE);
addFunctionNotDeterministic("CURRENT_TIME", CURRENT_TIME, addFunctionNotDeterministic("CURRENT_TIME", CURRENT_TIME,
VAR_ARGS, Value.TIME); VAR_ARGS, Value.TIME);
addFunctionNotDeterministic("LOCALTIME", CURRENT_TIME, addFunctionNotDeterministic("LOCALTIME", CURRENT_TIME,
......
...@@ -19,6 +19,9 @@ public final class FunctionsMSSQLServer extends FunctionsBase { ...@@ -19,6 +19,9 @@ public final class FunctionsMSSQLServer extends FunctionsBase {
private static final HashMap<String, FunctionInfo> FUNCTIONS = new HashMap<>(); private static final HashMap<String, FunctionInfo> FUNCTIONS = new HashMap<>();
static { static {
copyFunction(FUNCTIONS, "LOCATE", "CHARINDEX");
copyFunction(FUNCTIONS, "CURRENT_DATE", "GETDATE");
copyFunction(FUNCTIONS, "LENGTH", "LEN");
copyFunction(FUNCTIONS, "RANDOM_UUID", "NEWID"); copyFunction(FUNCTIONS, "RANDOM_UUID", "NEWID");
} }
......
...@@ -9,8 +9,23 @@ create memory table test(id int primary key, name varchar(255)); ...@@ -9,8 +9,23 @@ create memory table test(id int primary key, name varchar(255));
insert into test values(1, 'Hello'); insert into test values(1, 'Hello');
> update count: 1 > update count: 1
select length(null) en, len(null) en2, length('This has 17 chars') e_17, len('MSSQLServer uses the len keyword') e_32 from test; select length(null) en, length('This has 17 chars') e_17 from test;
> EN EN2 E_17 E_32 > EN E_17
> ---- ---- ---- ---- > ---- ----
> null null 17 32 > null 17
> rows: 1 > rows: 1
SELECT LEN(NULL);
> exception FUNCTION_NOT_FOUND_1
SET MODE MSSQLServer;
> ok
select len(null) en, len('MSSQLServer uses the len keyword') e_32 from test;
> EN E_32
> ---- ----
> null 32
> rows: 1
SET MODE Regular;
> ok
\ No newline at end of file
...@@ -20,3 +20,18 @@ select locate('World', 'Hello World') e7, locate('hi', 'abchihihi', 2) e3 from t ...@@ -20,3 +20,18 @@ select locate('World', 'Hello World') e7, locate('hi', 'abchihihi', 2) e3 from t
> -- -- > -- --
> 7 4 > 7 4
> rows: 1 > rows: 1
SELECT CHARINDEX('test', 'test');
> exception FUNCTION_NOT_FOUND_1
SET MODE MSSQLServer;
> ok
select charindex('World', 'Hello World') e7, charindex('hi', 'abchihihi', 2) e3 from test;
> E7 E3
> -- --
> 7 4
> rows: 1
SET MODE Regular;
> ok
...@@ -14,3 +14,15 @@ select length(curdate()) c1, length(current_date()) c2, substring(curdate(), 5, ...@@ -14,3 +14,15 @@ select length(curdate()) c1, length(current_date()) c2, substring(curdate(), 5,
> -- -- -- > -- -- --
> 10 10 - > 10 10 -
> rows: 1 > rows: 1
SELECT GETDATE();
> exception FUNCTION_NOT_FOUND_1
SET MODE MSSQLServer;
> ok
SELECT CURRENT_DATE = GETDATE();
>> TRUE
SET MODE Regular;
> ok
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论