summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2019-05-31 13:32:19 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2019-05-31 13:32:19 -0400
commit3101960af6d13eb44c12dfb1ca2381fd16136f0a (patch)
tree793b51214dc1abf4c474b71a5a01179667166012
parent96f0331923f4ff4508175ab36a018e92525f7849 (diff)
MySQL forces NOT NULL TIMESTAMPs to have default values
-rw-r--r--src/cjr_print.sml8
-rw-r--r--src/mysql.sml1
-rw-r--r--src/postgres.sml1
-rw-r--r--src/settings.sig1
-rw-r--r--src/settings.sml2
-rw-r--r--src/sqlite.sml1
6 files changed, 13 insertions, 1 deletions
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}