Mercurial > urweb
changeset 872:9654bce27cff
Validating views
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 30 Jun 2009 16:17:32 -0400 |
parents | 3ae6b655ced0 |
children | 41971801b62d |
files | src/cjr_print.sml src/mysql.sml src/postgres.sml src/settings.sig src/settings.sml |
diffstat | 5 files changed, 22 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cjr_print.sml Tue Jun 30 15:59:41 2009 -0400 +++ b/src/cjr_print.sml Tue Jun 30 16:17:32 2009 -0400 @@ -2578,6 +2578,7 @@ val hasDb = ref false val tables = ref [] + val views = ref [] val sequences = ref [] val dbstring = ref "" val expunge = ref 0 @@ -2592,6 +2593,8 @@ 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 @@ #init (Settings.currentDbms ()) {dbstring = !dbstring, prepared = !prepped, tables = !tables, + views = !views, sequences = !sequences} else box [string "void uw_db_init(uw_context ctx) { };",
--- a/src/mysql.sml Tue Jun 30 15:59:41 2009 -0400 +++ b/src/mysql.sml Tue Jun 30 16:17:32 2009 -0400 @@ -31,7 +31,7 @@ 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
--- a/src/postgres.sml Tue Jun 30 15:59:41 2009 -0400 +++ b/src/postgres.sml Tue Jun 30 16:17:32 2009 -0400 @@ -46,11 +46,11 @@ | 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 @@ 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 @@ 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 @@ 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 =>
--- a/src/settings.sig Tue Jun 30 15:59:41 2009 -0400 +++ b/src/settings.sig Tue Jun 30 16:17:32 2009 -0400 @@ -128,6 +128,7 @@ 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,
--- a/src/settings.sml Tue Jun 30 15:59:41 2009 -0400 +++ b/src/settings.sml Tue Jun 30 16:17:32 2009 -0400 @@ -318,6 +318,7 @@ 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)