From 3101960af6d13eb44c12dfb1ca2381fd16136f0a Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Fri, 31 May 2019 13:32:19 -0400 Subject: MySQL forces NOT NULL TIMESTAMPs to have default values --- src/cjr_print.sml | 8 +++++++- src/mysql.sml | 1 + src/postgres.sml | 1 + src/settings.sig | 1 + src/settings.sml | 2 ++ src/sqlite.sml | 1 + 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cjr_print.sml b/src/cjr_print.sml index b9795194..5dcfbe89 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -3791,7 +3791,13 @@ fun p_sql env (ds, _) = string ts, case t of Nullable _ => box [] - | _ => string " NOT NULL"] + | _ => string " NOT NULL", + case t of + Time => if #requiresTimestampDefaults (Settings.currentDbms ()) then + string " DEFAULT CURRENT_TIMESTAMP" + else + box [] + | _ => box []] end) xts, case (pk, csts) of ("", []) => box [] diff --git a/src/mysql.sml b/src/mysql.sml index e2b0b3b0..ff1c379d 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -1609,6 +1609,7 @@ val () = addDbms {name = "mysql", onlyUnion = true, nestedRelops = false, windowFunctions = false, + requiresTimestampDefaults = true, supportsIsDistinctFrom = true, supportsSHA512 = SOME {InitializeDb = "", GenerateHash = fn name => "SHA2(" ^ name ^ ", 512)"}} diff --git a/src/postgres.sml b/src/postgres.sml index 2b0a710d..94f0e42e 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -1153,6 +1153,7 @@ val () = addDbms {name = "postgres", onlyUnion = false, nestedRelops = true, windowFunctions = true, + requiresTimestampDefaults = false, supportsIsDistinctFrom = true, supportsSHA512 = SOME {InitializeDb = "CREATE EXTENSION pgcrypto;", GenerateHash = fn name => "DIGEST(" ^ name ^ ", 'sha512')"}} diff --git a/src/settings.sig b/src/settings.sig index 7ca7a0cd..a2a56407 100644 --- a/src/settings.sig +++ b/src/settings.sig @@ -221,6 +221,7 @@ signature SETTINGS = sig onlyUnion : bool, nestedRelops : bool, windowFunctions : bool, + requiresTimestampDefaults : bool, supportsIsDistinctFrom : bool, supportsSHA512 : {InitializeDb : string, GenerateHash : string -> string} option diff --git a/src/settings.sml b/src/settings.sml index a31f5cda..a85e8053 100644 --- a/src/settings.sml +++ b/src/settings.sml @@ -651,6 +651,7 @@ type dbms = { onlyUnion : bool, nestedRelops : bool, windowFunctions: bool, + requiresTimestampDefaults : bool, supportsIsDistinctFrom : bool, supportsSHA512 : {InitializeDb : string, GenerateHash : string -> string} option } @@ -685,6 +686,7 @@ val curDb = ref ({name = "", onlyUnion = false, nestedRelops = false, windowFunctions = false, + requiresTimestampDefaults = false, supportsIsDistinctFrom = false, supportsSHA512 = NONE} : dbms) diff --git a/src/sqlite.sml b/src/sqlite.sml index 0a3ae4ea..9bb86ecf 100644 --- a/src/sqlite.sml +++ b/src/sqlite.sml @@ -855,6 +855,7 @@ val () = addDbms {name = "sqlite", onlyUnion = false, nestedRelops = false, windowFunctions = false, + requiresTimestampDefaults = false, supportsIsDistinctFrom = false, supportsSHA512 = NONE} -- cgit v1.2.3