changeset 1600:8128fcb2d4a4

Fix catalog querying about empty tables
author Adam Chlipala <adam@chlipala.net>
date Fri, 18 Nov 2011 17:44:12 -0500
parents 252e05bf199d
children 78e0d56b594e
files src/mysql.sml src/postgres.sml tests/emptyTable.ur tests/emptyTable.urp
diffstat 4 files changed, 51 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/src/mysql.sml	Fri Nov 18 17:17:22 2011 -0500
+++ b/src/mysql.sml	Fri Nov 18 17:44:12 2011 -0500
@@ -83,26 +83,28 @@
         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 ",
--- a/src/postgres.sml	Fri Nov 18 17:17:22 2011 -0500
+++ b/src/postgres.sml	Fri Nov 18 17:44:12 2011 -0500
@@ -70,28 +70,30 @@
         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 = '",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/emptyTable.ur	Fri Nov 18 17:44:12 2011 -0500
@@ -0,0 +1,1 @@
+table tricky : {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/emptyTable.urp	Fri Nov 18 17:44:12 2011 -0500
@@ -0,0 +1,4 @@
+database dbname=test
+sql emptyTable.sql
+
+emptyTable