From 3d5ecd433389603aadb2b445b98e4f43f0d7fbf5 Mon Sep 17 00:00:00 2001 From: Marcin Wisnicki Date: Mon, 13 Mar 2023 19:24:53 -0400 Subject: [PATCH] Add missing NEWSEQUENTIALID function in MSSQLServer mode. Does not attempt to be sequential but that should be good enough. --- h2/src/main/org/h2/mode/FunctionsMSSQLServer.java | 6 +++++- .../org/h2/test/scripts/functions/numeric/random-uuid.sql | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/h2/src/main/org/h2/mode/FunctionsMSSQLServer.java b/h2/src/main/org/h2/mode/FunctionsMSSQLServer.java index 67d640de76..eaea218273 100644 --- a/h2/src/main/org/h2/mode/FunctionsMSSQLServer.java +++ b/h2/src/main/org/h2/mode/FunctionsMSSQLServer.java @@ -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); @@ -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)); @@ -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; diff --git a/h2/src/test/org/h2/test/scripts/functions/numeric/random-uuid.sql b/h2/src/test/org/h2/test/scripts/functions/numeric/random-uuid.sql index afb1c231df..a5d33fac81 100644 --- a/h2/src/test/org/h2/test/scripts/functions/numeric/random-uuid.sql +++ b/h2/src/test/org/h2/test/scripts/functions/numeric/random-uuid.sql @@ -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 @@ -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