Changeset: f7431fb44149 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f7431fb44149
Modified Files:
        clients/odbc/driver/SQLTables.c
        java/ChangeLog.Jul2015
        java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java
        java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java
Branch: default
Log Message:

Merge with Jul2015 branch.


diffs (truncated from 521 to 300 lines):

diff --git a/clients/odbc/driver/SQLTables.c b/clients/odbc/driver/SQLTables.c
--- a/clients/odbc/driver/SQLTables.c
+++ b/clients/odbc/driver/SQLTables.c
@@ -224,55 +224,96 @@ MNDBTables(ODBCStmt *stmt,
                }
 
                /* construct the query now */
-               query = (char *) malloc(1000 + (cat ? strlen(cat) : 0) + (sch ? 
strlen(sch) : 0) + (tab ? strlen(tab) : 0) + ((NameLength4 + 1) / 5) * 67);
+               query = (char *) malloc(1200 + (cat ? strlen(cat) : 0) + (sch ? 
strlen(sch) : 0) + (tab ? strlen(tab) : 0) + ((NameLength4 + 1) / 5) * 67);
                if (query == NULL)
                        goto nomem;
                query_end = query;
 
-               strcpy(query_end,
-                      "select e.value as table_cat, "
-                             "s.name as table_schem, "
-                             "t.name as table_name, "
-                             "case when t.type = 0 and "
-                                       "t.system = false and "
-                                       "t.temporary = 0 and "
-                                       "s.name <> 'tmp' "
-                                  "then cast('TABLE' as varchar(20)) "
-                                  "when t.type = 10 and "
-                                       "t.system = true and "
-                                       "t.temporary = 0 "
-                                  "then cast('SYSTEM TABLE' as varchar(20)) "
-                                  "when t.type = 11 and "
-                                       "t.system = true and "
-                                       "t.temporary = 0 "
-                                  "then cast('SYSTEM VIEW' as varchar(20)) "
-                                  "when t.type = 1 "
-                                  "then cast('VIEW' as varchar(20)) "
-                                  "when t.type = 3 "
-                                  "then cast('MERGE TABLE' as varchar(20)) "
-                                  "when t.type = 4 "
-                                  "then cast('STREAM TABLE' as varchar(20)) "
-                                  "when t.type = 5 "
-                                  "then cast('REMOTE TABLE' as varchar(20)) "
-                                  "when t.type = 6 "
-                                  "then cast('REPLICA TABLE' as varchar(20)) "
-                                  "when t.type = 20 and "
-                                       "t.system = false and "
-                                       "t.temporary = 1 and "
-                                       "s.name = 'tmp' "
-                                  "then cast('GLOBAL TEMPORARY' as 
varchar(20)) "
-                                  "when t.type = 30 and "
-                                       "t.system = false and "
-                                       "t.temporary = 1 "
-                                  "then cast('LOCAL TEMPORARY' as varchar(20)) 
"
-                                  "else cast('INTERNAL TABLE TYPE' as 
varchar(20)) end as table_type, "
-                             "cast(null as varchar(1)) as remarks "
-                      "from sys.schemas s, "
-                           "sys.tables t, "
-                           "sys.env() e "
-                      "where s.id = t.schema_id and "
-                            "e.name = 'gdk_dbname'");
-               assert(strlen(query) < 900);
+               strcpy(query_end, "with ot as (");
+               query_end += strlen(query_end);
+
+               if (stmt->Dbc->major < 11 || (stmt->Dbc->major == 11 && 
stmt->Dbc->minor < 21)) {
+                       strcpy(query_end,
+                              "select e.value as table_cat, "
+                                     "s.name as table_schem, "
+                                     "t.name as table_name, "
+                                     "case when t.type = 0 and "
+                                               "t.system = false and "
+                                               "t.temporary = 0 and "
+                                               "s.name <> 'tmp' "
+                                          "then cast('TABLE' as varchar(20)) "
+                                          "when t.type = 0 and "
+                                               "t.system = false and "
+                                               "t.temporary = 0 and "
+                                               "s.name = 'tmp' "
+                                          "then cast('GLOBAL TEMPORARY' as 
varchar(20)) "
+                                          "when t.type = 0 and "
+                                               "t.system = true and "
+                                               "t.temporary = 0 "
+                                          "then cast('SYSTEM TABLE' as 
varchar(20)) "
+                                          "when t.type = 1 and "
+                                               "t.system = true and "
+                                               "t.temporary = 0 "
+                                          "then cast('SYSTEM VIEW' as 
varchar(20)) "
+                                          "when t.type = 1 "
+                                          "then cast('VIEW' as varchar(20)) "
+                                          "when t.type = 0 and "
+                                               "t.system = false and "
+                                               "t.temporary = 1 "
+                                          "then cast('LOCAL TEMPORARY' as 
varchar(20)) "
+                                          "else cast('INTERNAL TABLE TYPE' as 
varchar(20)) end as table_type, "
+                                     "cast(null as varchar(1)) as remarks "
+                              "from sys.schemas s, "
+                                   "sys.tables t, "
+                                   "sys.env() e "
+                              "where s.id = t.schema_id and "
+                                    "e.name = 'gdk_dbname'");
+               } else {
+                       strcpy(query_end,
+                              "select e.value as table_cat, "
+                                     "s.name as table_schem, "
+                                     "t.name as table_name, "
+                                     "case when t.type = 0 and "
+                                               "t.system = false and "
+                                               "t.temporary = 0 and "
+                                               "s.name <> 'tmp' "
+                                          "then cast('TABLE' as varchar(20)) "
+                                          "when t.type = 10 and "
+                                               "t.system = true and "
+                                               "t.temporary = 0 "
+                                          "then cast('SYSTEM TABLE' as 
varchar(20)) "
+                                          "when t.type = 11 and "
+                                               "t.system = true and "
+                                               "t.temporary = 0 "
+                                          "then cast('SYSTEM VIEW' as 
varchar(20)) "
+                                          "when t.type = 1 "
+                                          "then cast('VIEW' as varchar(20)) "
+                                          "when t.type = 3 "
+                                          "then cast('MERGE TABLE' as 
varchar(20)) "
+                                          "when t.type = 4 "
+                                          "then cast('STREAM TABLE' as 
varchar(20)) "
+                                          "when t.type = 5 "
+                                          "then cast('REMOTE TABLE' as 
varchar(20)) "
+                                          "when t.type = 6 "
+                                          "then cast('REPLICA TABLE' as 
varchar(20)) "
+                                          "when t.type = 20 and "
+                                               "t.system = false and "
+                                               "t.temporary = 1 and "
+                                               "s.name = 'tmp' "
+                                          "then cast('GLOBAL TEMPORARY' as 
varchar(20)) "
+                                          "when t.type = 30 and "
+                                               "t.system = false and "
+                                               "t.temporary = 1 "
+                                          "then cast('LOCAL TEMPORARY' as 
varchar(20)) "
+                                          "else cast('INTERNAL TABLE TYPE' as 
varchar(20)) end as table_type, "
+                                     "cast(null as varchar(1)) as remarks "
+                              "from sys.schemas s, "
+                                   "sys.tables t, "
+                                   "sys.env() e "
+                              "where s.id = t.schema_id and "
+                                    "e.name = 'gdk_dbname'");
+               }
+               assert(strlen(query) < 1100);
                query_end += strlen(query_end);
 
                /* dependent on the input parameter values we must add a
@@ -298,12 +339,15 @@ MNDBTables(ODBCStmt *stmt,
                        free(tab);
                }
 
+               strcpy(query_end, ") select * from ot");
+               query_end += strlen(query_end);
+
                if (NameLength4 > 0) {
                        /* filtering requested on table type */
                        char buf[17];   /* the longest string is "GLOBAL 
TEMPORARY" */
                        int i, j;
 
-                       strcpy(query_end, " and (");
+                       strcpy(query_end, " where ");
                        query_end += strlen(query_end);
                        for (i = j = 0; i < NameLength4 + 1; i++) {
                                if (i == NameLength4 || TableType[i] == ',') {
@@ -314,33 +358,18 @@ MNDBTables(ODBCStmt *stmt,
                                                continue;
                                        }
                                        buf[j] = 0;
-                                       if (strcmp(buf, "VIEW") == 0) {
-                                               strcpy(query_end, "t.type = 1 
or ");
-                                       } else if (strcmp(buf, "TABLE") == 0) {
-                                               strcpy(query_end,
-                                                      "(t.type = 0 and 
t.system = false and t.temporary = 0 and s.name <> 'tmp') or ");
-                                       } else if (strcmp(buf, "MERGE TABLE") 
== 0) {
-                                               strcpy(query_end, "t.type = 3 
or ");
-                                       } else if (strcmp(buf, "STREAM TABLE") 
== 0) {
-                                               strcpy(query_end, "t.type = 4 
or ");
-                                       } else if (strcmp(buf, "REMOTE TABLE") 
== 0) {
-                                               strcpy(query_end, "t.type = 5 
or ");
-                                       } else if (strcmp(buf, "REPLICA TABLE") 
== 0) {
-                                               strcpy(query_end, "t.type = 6 
or ");
-                                       } else if (strcmp(buf, "SYSTEM TABLE") 
== 0) {
-                                               strcpy(query_end,
-                                                      "(t.type = 10 and 
t.system = true and t.temporary = 0) or ");
-                                       } else if (strcmp(buf, "SYSTEM VIEW") 
== 0) {
-                                               strcpy(query_end,
-                                                      "(t.type = 11 and 
t.system = true and t.temporary = 0) or ");
-                                       } else if (strcmp(buf, "GLOBAL 
TEMPORARY") == 0) {
-                                               strcpy(query_end,
-                                                      "(t.type = 20 and 
t.system = false and t.temporary = 1 and s.name = 'tmp') or ");
-                                       } else if (strcmp(buf, "LOCAL 
TEMPORARY") == 0) {
-                                               strcpy(query_end,
-                                                      "(t.type = 30 and 
t.system = false and t.temporary = 1) or ");
+                                       if (strcmp(buf, "VIEW") == 0 ||
+                                           strcmp(buf, "TABLE") == 0 ||
+                                           strcmp(buf, "MERGE TABLE") == 0 ||
+                                           strcmp(buf, "STREAM TABLE") == 0 ||
+                                           strcmp(buf, "REMOTE TABLE") == 0 ||
+                                           strcmp(buf, "REPLICA TABLE") == 0 ||
+                                           strcmp(buf, "SYSTEM TABLE") == 0 ||
+                                           strcmp(buf, "SYSTEM VIEW") == 0 ||
+                                           strcmp(buf, "GLOBAL TEMPORARY") == 
0 ||
+                                           strcmp(buf, "LOCAL TEMPORARY") == 
0) {
+                                               query_end += 
snprintf(query_end, 38, "table_type = '%s' or ", buf);
                                        }
-                                       query_end += strlen(query_end);
                                        j = 0;
                                } else if (j < (int) sizeof(buf) &&
                                           TableType[i] != '\'' &&
@@ -348,16 +377,14 @@ MNDBTables(ODBCStmt *stmt,
                                            (j > 0 && buf[j - 1] != ' ')))
                                        buf[j++] = TableType[i];
                        }
-                       if (query_end[-1] == '(') {
-                               /* no extra tests added, so remove " and (" */
-                               query_end -= 6;
-                               *query_end = 0;
+                       if (strcmp(query_end - 7, " where ") == 0) {
+                               /* no extra tests added, so remove " where " */
+                               query_end -= 7;
                        } else {
                                /* remove extra " or " at end */
                                query_end -= 4;
-                               *query_end++ = ')';
-                               *query_end = 0;
                        }
+                       *query_end = 0;
                }
 
                /* add the ordering */
diff --git a/java/ChangeLog.Jul2015 b/java/ChangeLog.Jul2015
--- a/java/ChangeLog.Jul2015
+++ b/java/ChangeLog.Jul2015
@@ -1,6 +1,12 @@
 # ChangeLog file for java
 # This file is updated with Maddlog
 
+* Thu Aug  6 2015 Martin van Dinther <[email protected]>
+- Improved JDBC driver to not throw NullPointerException anymore
+  when calling isNullable() or getPrecision() or getScale() or
+  getColumnDisplaySize() or getSchemaName() or getTableName() or
+  getColumnClassName() on a ResultSet object.
+
 * Thu Jul 16 2015 Sjoerd Mullender <[email protected]>
 - We now compile the Java classes using the latest Java 1.8 version, and
   we tell it to compile for Java 1.7.
diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java 
b/java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java
--- a/java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java
+++ b/java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java
@@ -1575,18 +1575,22 @@ public class MonetDatabaseMetaData exten
                String select;
                String orderby;
                String cat = getEnv("gdk_dbname");
+               // as of Jul2015 release the sys.tables.type values (0 through 
6) is extended with new values 10, 11, 20, and 30 (for system and temp 
tables/views).
+               // for correct behavior we need to know if the server is using 
the old (pre Jul2015) or new sys.tables.type values
+               boolean preJul2015 = 
("11.19.15".compareTo(getDatabaseProductVersion()) >= 0);
+               /* for debug: System.out.println("getDatabaseProductVersion() 
is " + getDatabaseProductVersion() + "  preJul2015 is " + preJul2015); */
 
                select =
                        "SELECT * FROM ( " +
                        "SELECT '" + cat + "' AS \"TABLE_CAT\", 
\"schemas\".\"name\" AS \"TABLE_SCHEM\", \"tables\".\"name\" AS \"TABLE_NAME\", 
" +
-                               "CASE WHEN \"tables\".\"system\" = true AND 
\"tables\".\"type\" = 10 AND \"tables\".\"temporary\" = 0 THEN 'SYSTEM TABLE' " 
+
-                               "WHEN \"tables\".\"system\" = true AND 
\"tables\".\"type\" = 11 AND \"tables\".\"temporary\" = 0 THEN 'SYSTEM VIEW' " +
+                               "CASE WHEN \"tables\".\"system\" = true AND 
\"tables\".\"type\" = " + (preJul2015 ? "0" : "10") + " AND 
\"tables\".\"temporary\" = 0 THEN 'SYSTEM TABLE' " +
+                               "WHEN \"tables\".\"system\" = true AND 
\"tables\".\"type\" = " + (preJul2015 ? "1" : "11") + " AND 
\"tables\".\"temporary\" = 0 THEN 'SYSTEM VIEW' " +
                                "WHEN \"tables\".\"system\" = false AND 
\"tables\".\"type\" = 0 AND \"tables\".\"temporary\" = 0 THEN 'TABLE' " +
                                "WHEN \"tables\".\"system\" = false AND 
\"tables\".\"type\" = 1 AND \"tables\".\"temporary\" = 0 THEN 'VIEW' " +
-                               "WHEN \"tables\".\"system\" = true AND 
\"tables\".\"type\" = 20 AND \"tables\".\"temporary\" = 1 THEN 'SYSTEM SESSION 
TABLE' " +
-                               "WHEN \"tables\".\"system\" = true AND 
\"tables\".\"type\" = 21 AND \"tables\".\"temporary\" = 1 THEN 'SYSTEM SESSION 
VIEW' " +
-                               "WHEN \"tables\".\"system\" = false AND 
\"tables\".\"type\" = 30 AND \"tables\".\"temporary\" = 1 THEN 'SESSION TABLE' 
" +
-                               "WHEN \"tables\".\"system\" = false AND 
\"tables\".\"type\" = 31 AND \"tables\".\"temporary\" = 1 THEN 'SESSION VIEW' " 
+
+                               "WHEN \"tables\".\"system\" = true AND 
\"tables\".\"type\" = " + (preJul2015 ? "0" : "20") + " AND 
\"tables\".\"temporary\" = 1 THEN 'SYSTEM SESSION TABLE' " +
+                               "WHEN \"tables\".\"system\" = true AND 
\"tables\".\"type\" = " + (preJul2015 ? "1" : "21") + " AND 
\"tables\".\"temporary\" = 1 THEN 'SYSTEM SESSION VIEW' " +
+                               "WHEN \"tables\".\"system\" = false AND 
\"tables\".\"type\" = " + (preJul2015 ? "0" : "30") + " AND 
\"tables\".\"temporary\" = 1 THEN 'SESSION TABLE' " +
+                               "WHEN \"tables\".\"system\" = false AND 
\"tables\".\"type\" = " + (preJul2015 ? "1" : "31") + " AND 
\"tables\".\"temporary\" = 1 THEN 'SESSION VIEW' " +
                                "END AS \"TABLE_TYPE\", \"tables\".\"query\" AS 
\"REMARKS\", null AS \"TYPE_CAT\", null AS \"TYPE_SCHEM\", " +
                                "null AS \"TYPE_NAME\", 'rowid' AS 
\"SELF_REFERENCING_COL_NAME\", 'SYSTEM' AS \"REF_GENERATION\" " +
                        "FROM \"sys\".\"tables\" AS \"tables\", 
\"sys\".\"schemas\" AS \"schemas\" WHERE \"tables\".\"schema_id\" = 
\"schemas\".\"id\" " +
@@ -1713,19 +1717,21 @@ public class MonetDatabaseMetaData exten
                String[][] results;
 
                columns = new String[1];
+               columns[0] = "TABLE_TYPE";
+
                types = new String[1];
+               types[0] = "varchar";
+
                results = new String[8][1];
-
-               columns[0] = "TABLE_TYPE";
-               types[0] = "varchar";
-               results[0][0] = "SYSTEM TABLE";
-               results[1][0] = "TABLE";
-               results[2][0] = "SYSTEM VIEW";
-               results[3][0] = "VIEW";
-               results[4][0] = "SYSTEM SESSION TABLE";
-               results[5][0] = "SESSION TABLE";
-               results[6][0] = "SYSTEM SESSION VIEW";
-               results[7][0] = "SESSION VIEW";
+               // The results need to be ordered by TABLE_TYPE
+               results[0][0] = "SESSION TABLE";
+               results[1][0] = "SESSION VIEW";
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to