Changeset: bd00820dcba6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bd00820dcba6
Added Files:
sql/scripts/45_uuid.sql
Modified Files:
monetdb5/modules/atoms/Tests/uuid00.mal
monetdb5/modules/atoms/Tests/uuid00.stable.out
monetdb5/modules/atoms/uuid.c
monetdb5/modules/atoms/uuid.h
monetdb5/modules/atoms/uuid.mal
sql/scripts/Makefile.ag
Branch: default
Log Message:
Extended the uuid functionality
diffs (189 lines):
diff --git a/monetdb5/modules/atoms/Tests/uuid00.mal
b/monetdb5/modules/atoms/Tests/uuid00.mal
--- a/monetdb5/modules/atoms/Tests/uuid00.mal
+++ b/monetdb5/modules/atoms/Tests/uuid00.mal
@@ -1,2 +1,14 @@
-b:= uuid.generateUuid();
-io.print(b);
+b:= uuid.new();
+#io.print(b);
+
+x:= uuid.isaUUID(b);
+io.print(x);
+
+s:str:= uuid.str(b);
+#io.print(s);
+
+z:uuid:= uuid.uuid(s);
+#io.print(z);
+
+t:= z == b;
+io.print(t);
diff --git a/monetdb5/modules/atoms/Tests/uuid00.stable.out
b/monetdb5/modules/atoms/Tests/uuid00.stable.out
--- a/monetdb5/modules/atoms/Tests/uuid00.stable.out
+++ b/monetdb5/modules/atoms/Tests/uuid00.stable.out
@@ -19,10 +19,19 @@ stdout of test 'uuid00` in directory 'mo
# MonetDB/JAQL module loaded
# MonetDB/SQL module loaded
function user.main():void;
- b := uuid.generateUuid();
- io.print(b);
+ b := uuid.new();
+#io.print(b);
+ x := uuid.isaUUID(b);
+ io.print(x);
+ s:str := uuid.str(b);
+#io.print(s);
+ z:uuid := uuid.uuid(s);
+#io.print(z);
+ t := calc.==(z,b);
+ io.print(t);
end main;
-[ "43652065-902a-4914-95e5-434bc52fbe6b" ]
+[ true ]
+[ true ]
# 13:19:57 >
# 13:19:57 > "Done."
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -36,6 +36,8 @@ uuid_GenerateUuid(str *retval) {
char * s;
s = generateUUID();
+ if ( s == NULL)
+ throw(MAL, "uuid.generateUuid", "Allocation failed");
d = GDKstrdup(s);
if (d == NULL)
@@ -50,3 +52,36 @@ str
UUIDgenerateUuid(str *retval) {
return uuid_GenerateUuid(retval);
}
+
+str
+UUIDisaUUID(bit *retval, str *s) {
+ *retval = strlen(*s) == 36;
+ return MAL_SUCCEED;
+}
+
+str
+UUIDstr2uuid(str *retval, str *s) {
+ bit b=0;
+ str msg = UUIDisaUUID(&b, s);
+ if ( msg != MAL_SUCCEED)
+ return msg;
+ if ( b== 0)
+ throw(MAL,"uuid.uuid","Inconsistent UUID length");
+ *retval = GDKstrdup(*s);
+ return MAL_SUCCEED;
+}
+
+str
+UUIDuuid2str(str *retval, str *s) {
+ *retval = GDKstrdup(*s);
+ return MAL_SUCCEED;
+}
+
+str
+UUIDequal(bit *retval, str *l, str *r)
+{
+ if (*l == str_nil || *r == str_nil)
+ *retval = bit_nil;
+ *retval = strcmp(*l,*r) == 0;
+ return MAL_SUCCEED;
+}
diff --git a/monetdb5/modules/atoms/uuid.h b/monetdb5/modules/atoms/uuid.h
--- a/monetdb5/modules/atoms/uuid.h
+++ b/monetdb5/modules/atoms/uuid.h
@@ -39,5 +39,9 @@ typedef str uuid;
#endif
uuid_export str UUIDgenerateUuid(str *retval);
+uuid_export str UUIDstr2uuid(str *retval, str *s);
+uuid_export str UUIDuuid2str(str *retval, str *s);
+uuid_export str UUIDisaUUID(bit *retval, str *s);
+uuid_export str UUIDequal(bit *retval, str *l, str *r);
#endif /* AUUID_H */
diff --git a/monetdb5/modules/atoms/uuid.mal b/monetdb5/modules/atoms/uuid.mal
--- a/monetdb5/modules/atoms/uuid.mal
+++ b/monetdb5/modules/atoms/uuid.mal
@@ -2,6 +2,30 @@ module uuid;
atom uuid:str;
-command generateUuid() :uuid
+command new() :uuid
address UUIDgenerateUuid
-comment "generate uuid";
+comment "Generate uuid";
+
+command uuid(s:str):uuid
+address UUIDstr2uuid
+comment "Coerce a string to a uuid, validating its format";
+
+command calc.uuid(s:str):uuid
+address UUIDstr2uuid
+comment "Coerce a string to a uuid, validating its format";
+
+command str(u:uuid):str
+address UUIDuuid2str
+comment "Coerce a uuid to its string type";
+
+command calc.uuid(s:uuid):str
+address UUIDuuid2str
+comment "Coerce a uuid to a string type";
+
+command isaUUID(u:uuid):bit
+address UUIDisaUUID
+comment "Test a string for a UUID format";
+
+command calc.==(l:uuid,r:uuid):bit
+address UUIDequal
+comment "Compare two UUID values for equality";
diff --git a/sql/scripts/45_uuid.sql b/sql/scripts/45_uuid.sql
new file mode 100644
--- /dev/null
+++ b/sql/scripts/45_uuid.sql
@@ -0,0 +1,28 @@
+-- The contents of this file are subject to the MonetDB Public License
+-- Version 1.1 (the "License"); you may not use this file except in
+-- compliance with the License. You may obtain a copy of the License at
+-- http://www.monetdb.org/Legal/MonetDBLicense
+--
+-- Software distributed under the License is distributed on an "AS IS"
+-- basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+-- License for the specific language governing rights and limitations
+-- under the License.
+--
+-- The Original Code is the MonetDB Database System.
+--
+-- The Initial Developer of the Original Code is CWI.
+-- Copyright August 2008-2013 MonetDB B.V.
+-- All Rights Reserved.
+
+-- (co) Martin Kersten
+-- The JSON type comes with a few operators.
+
+create type uuid external name uuid;
+
+-- generate a new uuid
+create function sys.uuid()
+returns uuid external name uuid."new";
+
+create function sys.isaUUID(u uuid)
+returns uuid external name uuid."isaUUID";
+
diff --git a/sql/scripts/Makefile.ag b/sql/scripts/Makefile.ag
--- a/sql/scripts/Makefile.ag
+++ b/sql/scripts/Makefile.ag
@@ -20,7 +20,7 @@ MT_SAFE
headers_sql = {
HEADERS = sql
DIR = libdir/monetdb5/createdb
- SOURCES = 09_like.sql 10_math.sql 11_times.sql 12_url.sql 13_date.sql
14_inet.sql 15_querylog.sql 16_tracelog.sql 17_compress.sql 18_dictionary.sql
19_cluster.sql 20_vacuum.sql 21_dependency_functions.sql 22_clients.sql
23_skyserver.sql 24_zorder.sql 25_debug.sql 26_sysmon.sql 39_analytics.sql
40_json.sql 75_storagemodel.sql 99_system.sql
+ SOURCES = 09_like.sql 10_math.sql 11_times.sql 12_url.sql 13_date.sql
14_inet.sql 15_querylog.sql 16_tracelog.sql 17_compress.sql 18_dictionary.sql
19_cluster.sql 20_vacuum.sql 21_dependency_functions.sql 22_clients.sql
23_skyserver.sql 24_zorder.sql 25_debug.sql 26_sysmon.sql 39_analytics.sql
40_json.sql 45_uuid.sql 75_storagemodel.sql 99_system.sql
}
headers_moresql = {
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list