Changeset: fbd2907111ae for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fbd2907111ae
Modified Files:
        clients/odbc/ChangeLog
        clients/odbc/driver/SQLTables.c
        clients/odbc/tests/ODBCmetadata.c
Branch: default
Log Message:

Enhanced SQLTables() by adding support for table type names: 'BASE TABLE', 
'GLOBAL TEMPORARY' and 'LOCAL TEMPORARY' in parameter TableType.
These are synonyms of: 'TABLE', 'GLOBAL TEMPORARY TABLE' and 'LOCAL TEMPORARY 
TABLE'.


diffs (74 lines):

diff --git a/clients/odbc/ChangeLog b/clients/odbc/ChangeLog
--- a/clients/odbc/ChangeLog
+++ b/clients/odbc/ChangeLog
@@ -1,3 +1,8 @@
 # ChangeLog file for odbc
 # This file is updated with Maddlog
 
+* Thu Apr 13 2023 Martin van Dinther <[email protected]>
+- Enhanced SQLTables() by adding support for table type names: 'BASE TABLE',
+  'GLOBAL TEMPORARY' and 'LOCAL TEMPORARY' in parameter TableType. These are
+  synonyms of: 'TABLE', 'GLOBAL TEMPORARY TABLE' and 'LOCAL TEMPORARY TABLE'.
+
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
@@ -221,6 +221,18 @@ MNDBTables(ODBCStmt *stmt,
                                                continue;
                                        }
                                        buf[j] = 0;
+                                       /* Some ODBC applications use different 
table type names.
+                                        * Replace those names to valid MonetDB 
table type names
+                                        * as defined in sys.tables_types */
+                                       if (strcmp("BASE TABLE", buf) == 0) {
+                                               strcpy(buf, "TABLE");
+                                       } else
+                                       if (strcmp("GLOBAL TEMPORARY", buf) == 
0) {
+                                               strcpy(buf, "GLOBAL TEMPORARY 
TABLE");
+                                       } else
+                                       if (strcmp("LOCAL TEMPORARY", buf) == 
0) {
+                                               strcpy(buf, "LOCAL TEMPORARY 
TABLE");
+                                       }
                                        pos += snprintf(query + pos, querylen - 
pos, "'%s',", buf);
                                        j = 0;
                                } else if (j < sizeof(buf) &&
diff --git a/clients/odbc/tests/ODBCmetadata.c 
b/clients/odbc/tests/ODBCmetadata.c
--- a/clients/odbc/tests/ODBCmetadata.c
+++ b/clients/odbc/tests/ODBCmetadata.c
@@ -529,6 +529,36 @@ main(int argc, char **argv)
                "NULL   odbctst pk2c    TABLE   NULL\n"
                "NULL   odbctst pk_uc   TABLE   odbctst.pk_uc table comment\n");
 
+       ret = SQLTables(stmt, (SQLCHAR*)"", SQL_NTS,
+                       (SQLCHAR*)"odbctst", SQL_NTS, (SQLCHAR*)"%", SQL_NTS,
+                       (SQLCHAR*)"BASE TABLE,GLOBAL TEMPORARY,LOCAL 
TEMPORARY", SQL_NTS);
+       compareResult(stmt, ret, "SQLTables (odbctst, %)",
+               "Resultset with 5 columns\n"
+               "Resultset with 7 rows\n"
+               "TABLE_CAT      TABLE_SCHEM     TABLE_NAME      TABLE_TYPE      
REMARKS\n"
+               "WVARCHAR(1)    WVARCHAR(1024)  WVARCHAR(1024)  WVARCHAR(25)    
WVARCHAR(65000)\n"
+               "NULL   odbctst CUSTOMERS       TABLE   NULL\n"
+               "NULL   odbctst LINES   TABLE   NULL\n"
+               "NULL   odbctst ORDERS  TABLE   NULL\n"
+               "NULL   odbctst fk2c    TABLE   NULL\n"
+               "NULL   odbctst nopk_twoucs     TABLE   odbctst.nopk_twoucs 
table comment\n"
+               "NULL   odbctst pk2c    TABLE   NULL\n"
+               "NULL   odbctst pk_uc   TABLE   odbctst.pk_uc table comment\n");
+
+       // All user tables in schema tmp
+       ret = SQLTables(stmt, (SQLCHAR*)"", SQL_NTS,
+                       (SQLCHAR*)"tmp", SQL_NTS, (SQLCHAR*)"%", SQL_NTS,
+                       (SQLCHAR*)"'BASE TABLE','GLOBAL TEMPORARY','LOCAL 
TEMPORARY'", SQL_NTS);
+       compareResult(stmt, ret, "SQLTables (tmp, %)",
+               "Resultset with 5 columns\n"
+               "Resultset with 4 rows\n"
+               "TABLE_CAT      TABLE_SCHEM     TABLE_NAME      TABLE_TYPE      
REMARKS\n"
+               "WVARCHAR(1)    WVARCHAR(1024)  WVARCHAR(1024)  WVARCHAR(25)    
WVARCHAR(65000)\n"
+               "NULL   tmp     glbl_nopk_twoucs        GLOBAL TEMPORARY TABLE  
NULL\n"
+               "NULL   tmp     glbl_pk_uc      GLOBAL TEMPORARY TABLE  NULL\n"
+               "NULL   tmp     tmp_nopk_twoucs LOCAL TEMPORARY TABLE   NULL\n"
+               "NULL   tmp     tmp_pk_uc       LOCAL TEMPORARY TABLE   
NULL\n");
+
        // All user tables and views in schema odbctst
        ret = SQLTables(stmt, (SQLCHAR*)"", SQL_NTS,
                        (SQLCHAR*)"odbctst", SQL_NTS, (SQLCHAR*)"%", SQL_NTS,
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to