Changeset: 64fc9cb5d862 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=64fc9cb5d862
Modified Files:
        clients/odbc/driver/SQLColumnPrivileges.c
        clients/odbc/driver/SQLSpecialColumns.c
        clients/odbc/driver/SQLTablePrivileges.c
Branch: Mar2018
Log Message:

Cleanup of some ODBC queries.


diffs (truncated from 382 to 300 lines):

diff --git a/clients/odbc/driver/SQLColumnPrivileges.c 
b/clients/odbc/driver/SQLColumnPrivileges.c
--- a/clients/odbc/driver/SQLColumnPrivileges.c
+++ b/clients/odbc/driver/SQLColumnPrivileges.c
@@ -141,52 +141,50 @@ MNDBColumnPrivileges(ODBCStmt *stmt,
           is_grantable VARCHAR
         */
 
-       strcpy(query_end,
-              "select e.value as table_cat, "
-                     "s.name as table_schem, "
-                     "t.name as table_name, "
-                     "c.name as column_name, "
-                     "case a.id "
-                          "when s.owner "
-                          "then '_SYSTEM' "
-                          "else g.name "
-                          "end as grantor, "
-                     "case a.name "
-                          "when 'public' "
-                          "then 'PUBLIC' "
-                          "else a.name "
-                          "end as grantee, "
-                     "pc.privilege_code_name as privilege, "
-                     "case p.grantable "
-                          "when 1 "
-                          "then 'YES' "
-                          "when 0 "
-                          "then 'NO' "
-                          "end as is_grantable "
-              "from sys.schemas as s, "
-                   "sys._tables as t, "
-                   "sys._columns as c, "
-                   "sys.auths as a, "
-                   "sys.privileges as p, "
-                   "sys.auths as g, "
-                   "sys.env() as e, "
-              /* this can eventually be replaced by
-               * sys.privilege_codes as pc
-               * see 51_sys_schema_extensionl.sql */
-                   "(values (1, 'SELECT'), "
-                           "(2, 'UPDATE'), "
-                           "(4, 'INSERT'), "
-                           "(8, 'DELETE'), "
-                           "(16, 'EXECUTE'), "
-                           "(32, 'GRANT')) as pc(privilege_code_id, 
privilege_code_name) "
-              "where p.obj_id = c.id and "
-                    "c.table_id = t.id and "
-                    "p.auth_id = a.id and "
-                    "t.schema_id = s.id and "
-                    "t.system = false and "
-                    "p.grantor = g.id and "
-                    "e.name = 'gdk_dbname' and "
-                    "p.privileges = pc.privilege_code_id");
+       sprintf(query_end,
+               "select e.value as table_cat, "
+                      "s.name as table_schem, "
+                      "t.name as table_name, "
+                      "c.name as column_name, "
+                      "case a.id "
+                           "when s.owner "
+                           "then '_SYSTEM' "
+                           "else g.name "
+                           "end as grantor, "
+                      "case a.name "
+                           "when 'public' then 'PUBLIC' "
+                           "else a.name "
+                           "end as grantee, "
+                      "pc.privilege_code_name as privilege, "
+                      "case p.grantable "
+                           "when 1 then 'YES' "
+                           "when 0 then 'NO' "
+                           "end as is_grantable "
+               "from sys.schemas as s, "
+                    "sys._tables as t, "
+                    "sys._columns as c, "
+                    "sys.auths as a, "
+                    "sys.privileges as p, "
+                    "sys.auths as g, "
+                    "sys.env() as e, "
+                    "%s "
+               "where p.obj_id = c.id and "
+                     "c.table_id = t.id and "
+                     "p.auth_id = a.id and "
+                     "t.schema_id = s.id and "
+                     "not t.system and "
+                     "p.grantor = g.id and "
+                     "e.name = 'gdk_dbname' and "
+                     "p.privileges = pc.privilege_code_id",
+               /* a server that supports sys.columns also supports
+                * sys.privilege_codes */
+               stmt->Dbc->has_comment ? "sys.privilege_codes as pc" :
+                    "(values (1, 'SELECT'), "
+                            "(2, 'UPDATE'), "
+                            "(4, 'INSERT'), "
+                            "(8, 'DELETE'), "
+                            "(16, 'EXECUTE'), "
+                            "(32, 'GRANT')) as pc(privilege_code_id, 
privilege_code_name)");
        assert(strlen(query) < 1100);
        query_end += strlen(query_end);
 
@@ -218,7 +216,8 @@ MNDBColumnPrivileges(ODBCStmt *stmt,
 
        /* add the ordering */
        strcpy(query_end,
-              " order by table_cat, table_schem, table_name, column_name, 
privilege");
+              " order by table_cat, table_schem, table_name, "
+              "column_name, privilege");
        query_end += strlen(query_end);
 
        /* query the MonetDB data dictionary tables */
diff --git a/clients/odbc/driver/SQLSpecialColumns.c 
b/clients/odbc/driver/SQLSpecialColumns.c
--- a/clients/odbc/driver/SQLSpecialColumns.c
+++ b/clients/odbc/driver/SQLSpecialColumns.c
@@ -28,6 +28,7 @@
 #include "ODBCGlobal.h"
 #include "ODBCStmt.h"
 #include "ODBCUtil.h"
+#include "ODBCQueries.h"
 
 
 #ifdef ODBCDEBUG
@@ -223,169 +224,11 @@ MNDBSpecialColumns(ODBCStmt *stmt,
                        "select t.id as table_id, k.type as type, "
                               "cast(%d as smallint) as scope, "
                               "c.name as column_name, "
-                              "case c.type "
-                                   "when 'bigint' then %d "
-                                   "when 'blob' then %d "
-                                   "when 'boolean' then %d "
-                                   "when 'char' then %d "
-                                   "when 'clob' then %d "
-                                   "when 'date' then %d "
-                                   "when 'decimal' then %d "
-                                   "when 'double' then %d "
-                                   "when 'hugeint' then %d "
-                                   "when 'int' then %d "
-                                   "when 'month_interval' then "
-                                        "case c.type_digits "
-                                             "when 1 then %d "
-                                             "when 2 then %d "
-                                             "when 3 then %d "
-                                        "end "
-                                   "when 'real' then %d "
-                                   "when 'sec_interval' then "
-                                        "case c.type_digits "
-                                             "when 4 then %d "
-                                             "when 5 then %d "
-                                             "when 6 then %d "
-                                             "when 7 then %d "
-                                             "when 8 then %d "
-                                             "when 9 then %d "
-                                             "when 10 then %d "
-                                             "when 11 then %d "
-                                             "when 12 then %d "
-                                             "when 13 then %d "
-                                        "end "
-                                   "when 'smallint' then %d "
-                                   "when 'timestamp' then %d "
-                                   "when 'timestamptz' then %d "
-                                   "when 'time' then %d "
-                                   "when 'timetz' then %d "
-                                   "when 'tinyint' then %d "
-                                   "when 'varchar' then %d "
-                              "end as data_type, "
-                              "case c.type "
-                                   "when 'bigint' then 'BIGINT' "
-                                   "when 'blob' then 'BINARY LARGE OBJECT' "
-                                   "when 'boolean' then 'BOOLEAN' "
-                                   "when 'char' then 'CHARACTER' "
-                                   "when 'clob' then 'CHARACTER LARGE OBJECT' "
-                                   "when 'date' then 'DATE' "
-                                   "when 'decimal' then 'DECIMAL' "
-                                   "when 'double' then 'DOUBLE' "
-                                   "when 'hugeint' then 'HUGEINT' "
-                                   "when 'int' then 'INTEGER' "
-                                   "when 'month_interval' then "
-                                        "case c.type_digits "
-                                             "when 1 then 'INTERVAL YEAR' "
-                                             "when 2 then 'INTERVAL YEAR TO 
MONTH' "
-                                             "when 3 then 'INTERVAL MONTH' "
-                                        "end "
-                                   "when 'real' then 'REAL' "
-                                   "when 'sec_interval' then "
-                                        "case c.type_digits "
-                                             "when 4 then 'INTERVAL DAY' "
-                                             "when 5 then 'INTERVAL DAY TO 
HOUR' "
-                                             "when 6 then 'INTERVAL DAY TO 
MINUTE' "
-                                             "when 7 then 'INTERVAL DAY TO 
SECOND' "
-                                             "when 8 then 'INTERVAL HOUR' "
-                                             "when 9 then 'INTERVAL HOUR TO 
MINUTE' "
-                                             "when 10 then 'INTERVAL HOUR TO 
SECOND' "
-                                             "when 11 then 'INTERVAL MINUTE' "
-                                             "when 12 then 'INTERVAL MINUTE TO 
SECOND' "
-                                             "when 13 then 'INTERVAL SECOND' "
-                                        "end "
-                                   "when 'smallint' then 'SMALLINT' "
-                                   "when 'timestamp' then 'TIMESTAMP' "
-                                   "when 'timestamptz' then 'TIMESTAMP' "
-                                   "when 'time' then 'TIME' "
-                                   "when 'timetz' then 'TIME' "
-                                   "when 'tinyint' then 'TINYINT' "
-                                   "when 'varchar' then 'VARCHAR' "
-                              "end as type_name, "
-                              "case c.type "
-                                   "when 'month_interval' then "
-                                        "case c.type_digits "
-                                             "when 1 then 26 "
-                                             "when 2 then 38 "
-                                             "when 3 then 27 "
-                                        "end "
-                                   "when 'sec_interval' then "
-                                        "case c.type_digits "
-                                             "when 4 then 25 "
-                                             "when 5 then 36 "
-                                             "when 6 then 41 "
-                                             "when 7 then 47 "
-                                             "when 8 then 26 "
-                                             "when 9 then 39 "
-                                             "when 10 then 45 "
-                                             "when 11 then 28 "
-                                             "when 12 then 44 "
-                                             "when 13 then 30 "
-                                        "end "
-                                   "when 'date' then 10 "
-                                   "when 'time' then 12 "
-                                   "when 'timetz' then 12 "
-                                   "when 'timestamp' then 23 "
-                                   "when 'timestamptz' then 23 "
-                                   "else c.type_digits "
-                              "end as column_size, "
-                              "case c.type "
-                                   "when 'month_interval' then "
-                                        "case c.type_digits "
-                                             "when 1 then 26 "
-                                             "when 2 then 38 "
-                                             "when 3 then 27 "
-                                        "end "
-                                   "when 'sec_interval' then "
-                                        "case c.type_digits "
-                                             "when 4 then 25 "
-                                             "when 5 then 36 "
-                                             "when 6 then 41 "
-                                             "when 7 then 47 "
-                                             "when 8 then 26 "
-                                             "when 9 then 39 "
-                                             "when 10 then 45 "
-                                             "when 11 then 28 "
-                                             "when 12 then 44 "
-                                             "when 13 then 30 "
-                                        "end "
-                                   "when 'date' then 10 "
-                                   "when 'time' then 12 "
-                                   "when 'timetz' then 12 "
-                                   "when 'timestamp' then 23 "
-                                   "when 'timestamptz' then 23 "
-                                   "when 'bigint' then 20 "
-                                   "when 'hugeint' then 40 "
-                                   "when 'int' then 11 "
-                                   "when 'smallint' then 6 "
-                                   "when 'tinyint' then 4 "
-                                   "when 'char' then 6 * c.type_digits "
-                                   "when 'varchar' then 6 * c.type_digits "
-                                   "when 'double' then 24 "
-                                   "when 'real' then 14 "
-                                   "else c.type_digits "
-                              "end as buffer_length, "
-                              "case c.type "
-                                   "when 'time' then c.type_digits - 1 "
-                                   "when 'timetz' then c.type_digits - 1 "
-                                   "when 'timestamp' then c.type_digits - 1 "
-                                   "when 'timestamptz' then c.type_digits - 1 "
-                                   "when 'sec_interval' then 0 "
-                                   "when 'month_interval' then 0 "
-                                   "when 'real' then "
-                                        "case when c.type_digits = 24 and 
c.type_scale = 0 then 7 "
-                                        "else c.type_digits "
-                                        "end "
-                                   "when 'double' then "
-                                        "case when c.type_digits = 53 and 
c.type_scale = 0 then 15 "
-                                        "else c.type_digits "
-                                        "end "
-                                   "when 'decimal' then c.type_digits "
-                                   "when 'bigint' then 19 "
-                                   "when 'hugeint' then 39 "
-                                   "when 'int' then 10 "
-                                   "when 'smallint' then 5 "
-                                   "when 'tinyint' then 3 "
-                              "end as decimal_digits, "
+                       DATA_TYPE(c) ", "
+                       TYPE_NAME(c) ", "
+                       COLUMN_SIZE(c) ", "
+                       BUFFER_LENGTH(c) ", "
+                       DECIMAL_DIGITS(c) ", "
                               "cast(%d as smallint) as pseudo_column "
                         "from sys.schemas s, "
                              "sys.tables t, "
@@ -402,19 +245,21 @@ MNDBSpecialColumns(ODBCStmt *stmt,
                               "e.name = 'gdk_dbname'",
                        /* scope: */
                        SQL_SCOPE_TRANSACTION,
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to