diff options
author | Adam Chlipala <adam@chlipala.net> | 2011-11-18 17:44:12 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2011-11-18 17:44:12 -0500 |
commit | 13eb7555000c10b0c54e11364c42e0da75b98ca7 (patch) | |
tree | 683cd859883db5175662045e278f0b10056e587a | |
parent | aabcc562d7ad7266b6b1e338a14a19224c1169df (diff) |
Fix catalog querying about empty tables
-rw-r--r-- | src/mysql.sml | 42 | ||||
-rw-r--r-- | src/postgres.sml | 46 | ||||
-rw-r--r-- | tests/emptyTable.ur | 1 | ||||
-rw-r--r-- | tests/emptyTable.urp | 4 |
4 files changed, 51 insertions, 42 deletions
diff --git a/src/mysql.sml b/src/mysql.sml index a8a10da7..0715d253 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -83,26 +83,28 @@ fun checkRel (table, checkNullable) (s, xts) = val q' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE ", both, " AND (", - String.concatWith " OR " - (map (fn (x, t) => - String.concat ["(column_name IN ('uw_", - CharVector.map - Char.toLower (ident x), - "', 'uw_", - ident x, - "') AND data_type = '", - p_sql_type_base t, - "'", - if checkNullable then - (" AND is_nullable = '" - ^ (if isNotNull t then - "NO" - else - "YES") - ^ "'") - else - "", - ")"]) xts), + case String.concatWith " OR " + (map (fn (x, t) => + String.concat ["(column_name IN ('uw_", + CharVector.map + Char.toLower (ident x), + "', 'uw_", + ident x, + "') AND data_type = '", + p_sql_type_base t, + "'", + if checkNullable then + (" AND is_nullable = '" + ^ (if isNotNull t then + "NO" + else + "YES") + ^ "'") + else + "", + ")"]) xts) of + "" => "FALSE" + | s => s, ")"] val q'' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE ", diff --git a/src/postgres.sml b/src/postgres.sml index a66c85d9..f3b9e3f1 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -70,28 +70,30 @@ fun checkRel (table, checkNullable) (s, xts) = val q' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE table_name = '", sl, "' AND (", - String.concatWith " OR " - (map (fn (x, t) => - String.concat ["(column_name = 'uw_", - CharVector.map - Char.toLower (ident x), - (case p_sql_type_base t of - "bigint" => - "' AND data_type IN ('bigint', 'numeric')" - | t => - String.concat ["' AND data_type = '", - t, - "'"]), - if checkNullable then - (" AND is_nullable = '" - ^ (if isNotNull t then - "NO" - else - "YES") - ^ "'") - else - "", - ")"]) xts), + case String.concatWith " OR " + (map (fn (x, t) => + String.concat ["(column_name = 'uw_", + CharVector.map + Char.toLower (ident x), + (case p_sql_type_base t of + "bigint" => + "' AND data_type IN ('bigint', 'numeric')" + | t => + String.concat ["' AND data_type = '", + t, + "'"]), + if checkNullable then + (" AND is_nullable = '" + ^ (if isNotNull t then + "NO" + else + "YES") + ^ "'") + else + "", + ")"]) xts) of + "" => "FALSE" + | s => s, ")"] val q'' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE table_name = '", diff --git a/tests/emptyTable.ur b/tests/emptyTable.ur new file mode 100644 index 00000000..d9469be4 --- /dev/null +++ b/tests/emptyTable.ur @@ -0,0 +1 @@ +table tricky : {} diff --git a/tests/emptyTable.urp b/tests/emptyTable.urp new file mode 100644 index 00000000..c8a7ca25 --- /dev/null +++ b/tests/emptyTable.urp @@ -0,0 +1,4 @@ +database dbname=test +sql emptyTable.sql + +emptyTable |