diff options
author | 2009-06-30 16:17:32 -0400 | |
---|---|---|
committer | 2009-06-30 16:17:32 -0400 | |
commit | 214f1f451fc04f7d8b5999a0f33a6794d47241f8 (patch) | |
tree | ad73b7fad0e33fa4f2162ae67248ad68d8f90489 | |
parent | b5520935745c4415fe91ecca58276a4a3cf24790 (diff) |
Validating views
-rw-r--r-- | src/cjr_print.sml | 4 | ||||
-rw-r--r-- | src/mysql.sml | 2 | ||||
-rw-r--r-- | src/postgres.sml | 24 | ||||
-rw-r--r-- | src/settings.sig | 1 | ||||
-rw-r--r-- | src/settings.sml | 1 |
5 files changed, 22 insertions, 10 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml index 7e2cbc52..7d1120b4 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -2578,6 +2578,7 @@ fun p_file env (ds, ps) = val hasDb = ref false val tables = ref [] + val views = ref [] val sequences = ref [] val dbstring = ref "" val expunge = ref 0 @@ -2592,6 +2593,8 @@ fun p_file env (ds, ps) = initialize := z) | DTable (s, xts, _, _) => tables := (s, map (fn (x, t) => (x, sql_type_in env t)) xts) :: !tables + | DView (s, xts, _) => views := (s, map (fn (x, t) => + (x, sql_type_in env t)) xts) :: !views | DSequence s => sequences := s :: !sequences | DPreparedStatements ss => prepped := ss | _ => ()) ds @@ -2666,6 +2669,7 @@ fun p_file env (ds, ps) = #init (Settings.currentDbms ()) {dbstring = !dbstring, prepared = !prepped, tables = !tables, + views = !views, sequences = !sequences} else box [string "void uw_db_init(uw_context ctx) { };", diff --git a/src/mysql.sml b/src/mysql.sml index 897b4a58..7b02c787 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -31,7 +31,7 @@ open Settings open Print.PD open Print -fun init {dbstring, prepared = ss, tables, sequences} = +fun init {dbstring, prepared = ss, tables, views, sequences} = let val host = ref NONE val user = ref NONE diff --git a/src/postgres.sml b/src/postgres.sml index 5ebda223..07a68607 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -46,11 +46,11 @@ fun p_sql_type_base t = | Client => "integer" | Nullable t => p_sql_type_base t -fun checkRel (s, xts) = +fun checkRel (table, checkNullable) (s, xts) = let val sl = CharVector.map Char.toLower s - val q = "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = '" + val q = "SELECT COUNT(*) FROM information_schema." ^ table ^ " WHERE table_name = '" ^ sl ^ "'" val q' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE table_name = '", @@ -63,12 +63,17 @@ fun checkRel (s, xts) = Char.toLower (ident x), "' AND data_type = '", p_sql_type_base t, - "' AND is_nullable = '", - if isNotNull t then - "NO" + "'", + if checkNullable then + (" AND is_nullable = '" + ^ (if isNotNull t then + "NO" + else + "YES") + ^ "'") else - "YES", - "')"]) xts), + "", + ")"]) xts), ")"] val q'' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE table_name = '", @@ -228,7 +233,7 @@ fun checkRel (s, xts) = newline] end -fun init {dbstring, prepared = ss, tables, sequences} = +fun init {dbstring, prepared = ss, tables, views, sequences} = box [if #persistent (currentProtocol ()) then box [string "static void uw_db_validate(uw_context ctx) {", newline, @@ -237,7 +242,8 @@ fun init {dbstring, prepared = ss, tables, sequences} = string "PGresult *res;", newline, newline, - p_list_sep newline checkRel tables, + p_list_sep newline (checkRel ("tables", true)) tables, + p_list_sep newline (checkRel ("views", false)) views, p_list_sep newline (fn s => diff --git a/src/settings.sig b/src/settings.sig index 0ed2924b..5406d1de 100644 --- a/src/settings.sig +++ b/src/settings.sig @@ -128,6 +128,7 @@ signature SETTINGS = sig init : {dbstring : string, prepared : (string * int) list, tables : (string * (string * sql_type) list) list, + views : (string * (string * sql_type) list) list, sequences : string list} -> Print.PD.pp_desc, (* Define uw_db_init(), uw_db_close(), uw_db_begin(), uw_db_commit(), and uw_db_rollback() *) query : {loc : ErrorMsg.span, numCols : int, diff --git a/src/settings.sml b/src/settings.sml index dbc3bf77..a242768f 100644 --- a/src/settings.sml +++ b/src/settings.sml @@ -318,6 +318,7 @@ type dbms = { init : {dbstring : string, prepared : (string * int) list, tables : (string * (string * sql_type) list) list, + views : (string * (string * sql_type) list) list, sequences : string list} -> Print.PD.pp_desc, query : {loc : ErrorMsg.span, numCols : int, doCols : ({wontLeakStrings : bool, col : int, typ : sql_type} -> Print.PD.pp_desc) |