Skip to content

Commit

Permalink
Merge pull request #3753 from mwisnicki/mssql-mode-newsequentialid
Browse files Browse the repository at this point in the history
Add missing NEWSEQUENTIALID function in MSSQLServer mode.
  • Loading branch information
katzyn committed Mar 14, 2023
2 parents bd670c1 + 3d5ecd4 commit 1d21f2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion h2/src/main/org/h2/mode/FunctionsMSSQLServer.java
Expand Up @@ -39,7 +39,9 @@ public final class FunctionsMSSQLServer extends ModeFunction {

private static final int NEWID = LEN + 1;

private static final int SCOPE_IDENTITY = NEWID + 1;
private static final int NEWSEQUENTIALID = NEWID + 1;

private static final int SCOPE_IDENTITY = NEWSEQUENTIALID + 1;

private static final TypeInfo SCOPE_IDENTITY_TYPE = TypeInfo.getTypeInfo(Value.NUMERIC, 38, 0, null);

Expand All @@ -48,6 +50,7 @@ public final class FunctionsMSSQLServer extends ModeFunction {
FUNCTIONS.put("GETDATE", new FunctionInfo("GETDATE", GETDATE, 0, Value.TIMESTAMP, false, true));
FUNCTIONS.put("LEN", new FunctionInfo("LEN", LEN, 1, Value.INTEGER, true, true));
FUNCTIONS.put("NEWID", new FunctionInfo("NEWID", NEWID, 0, Value.UUID, true, false));
FUNCTIONS.put("NEWSEQUENTIALID", new FunctionInfo("NEWSEQUENTIALID", NEWSEQUENTIALID, 0, Value.UUID, true, false));
FUNCTIONS.put("ISNULL", new FunctionInfo("ISNULL", ISNULL, 2, Value.NULL, false, true));
FUNCTIONS.put("SCOPE_IDENTITY",
new FunctionInfo("SCOPE_IDENTITY", SCOPE_IDENTITY, 0, Value.NUMERIC, true, false));
Expand Down Expand Up @@ -127,6 +130,7 @@ public Expression optimize(SessionLocal session) {
case ISNULL:
return new CoalesceFunction(CoalesceFunction.COALESCE, args).optimize(session);
case NEWID:
case NEWSEQUENTIALID:
return new RandFunction(null, RandFunction.RANDOM_UUID).optimize(session);
case SCOPE_IDENTITY:
type = SCOPE_IDENTITY_TYPE;
Expand Down
Expand Up @@ -12,6 +12,9 @@ SELECT RANDOM_UUID() = RANDOM_UUID();
SELECT NEWID();
> exception FUNCTION_NOT_FOUND_1

SELECT NEWSEQUENTIALID();
> exception FUNCTION_NOT_FOUND_1

SELECT SYS_GUID();
> exception FUNCTION_NOT_FOUND_1

Expand All @@ -21,6 +24,9 @@ SET MODE MSSQLServer;
SELECT CHAR_LENGTH(CAST(NEWID() AS VARCHAR));
>> 36

SELECT CHAR_LENGTH(CAST(NEWSEQUENTIALID() AS VARCHAR));
>> 36

SET MODE Oracle;
> ok

Expand Down

0 comments on commit 1d21f2e

Please sign in to comment.