Changeset: ce05cd41c38b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ce05cd41c38b
Modified Files:
        sql/backends/monet5/vaults/odbc/odbc_loader.c
Branch: Mar2025
Log Message:

Fix compilation error for Windows.
Add TRC_ERROR/INFO/DEBUG(LOADER, ...) statements to replace if (trace_enabled) 
printf() statements.


diffs (truncated from 433 to 300 lines):

diff --git a/sql/backends/monet5/vaults/odbc/odbc_loader.c 
b/sql/backends/monet5/vaults/odbc/odbc_loader.c
--- a/sql/backends/monet5/vaults/odbc/odbc_loader.c
+++ b/sql/backends/monet5/vaults/odbc/odbc_loader.c
@@ -443,8 +443,6 @@ fraction2msec(SQLUINTEGER fraction, SQLS
 static str
 odbc_query(int caller, mvc *sql, sql_subfunc *f, char *url, list *res_exps, 
MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       bool trace_enabled = false;     /* used for development only */
-
        if (sql == NULL)
                return "Missing mvc value.";
        if (f == NULL)
@@ -482,9 +480,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                return "Missing ODBC connection string.";
        }
 
-       // trace_enabled = true;
-       if (trace_enabled)
-               printf("\nExtracted ODBC connection string: %s\n  and SQL 
query: %s\n", odbc_con_str, query);
+       TRC_INFO(LOADER, "\nExtracted ODBC connection string: %s\n  and SQL 
query: %s\n", odbc_con_str, query);
 
        /* now we can (try to) connect to the ODBC driver and execute the SQL 
query */
        SQLRETURN ret = SQL_INVALID_HANDLE;
@@ -531,11 +527,11 @@ odbc_query(int caller, mvc *sql, sql_sub
        if (ret == SQL_SUCCESS_WITH_INFO && caller == ODBC_RELATION) {
                /* show the info warning, but only once */
                char * ODBCmsg = getErrMsg(SQL_HANDLE_DBC, dbc);
-               printf("SQLDriverConnect(%s) returned %s ODBCmsg: %s\n", 
odbc_con_str, nameOfRetCode(ret), (ODBCmsg) ? ODBCmsg : "");
+               TRC_INFO(LOADER, "SQLDriverConnect(%s) returned %s ODBCmsg: 
%s\n", odbc_con_str, nameOfRetCode(ret), (ODBCmsg) ? ODBCmsg : "");
                if (ODBCmsg)
                        GDKfree(ODBCmsg);
-       } else if (trace_enabled) {
-               printf("SQLDriverConnect(%s) returned %s\n", odbc_con_str, 
nameOfRetCode(ret));
+       } else {
+               TRC_DEBUG(LOADER, "SQLDriverConnect(%s) returned %s\n", 
odbc_con_str, nameOfRetCode(ret));
        }
        if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
                errmsg = "SQLDriverConnect failed.";
@@ -556,13 +552,11 @@ odbc_query(int caller, mvc *sql, sql_sub
                char DBMSname[128];
                ret = SQLGetInfo(dbc, SQL_DBMS_NAME, (SQLPOINTER) &DBMSname, 
127, NULL);
                if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) {
-                       if (trace_enabled)
-                               printf("SQLGetInfo(dbc, SQL_DBMS_NAME) returned 
%s\n", DBMSname);
+                       TRC_DEBUG(LOADER, "SQLGetInfo(dbc, SQL_DBMS_NAME) 
returned %s\n", DBMSname);
                        if (strcmp("MonetDB", DBMSname) == 0) {
-                               /* enable the MonetDB ODBC driver to return 
SQL_HUGEINT as column datatype */
+                               /* instruct the MonetDB ODBC driver to return 
SQL_HUGEINT as column datatype */
                                ret = SQLGetTypeInfo(stmt, SQL_HUGEINT);
-                               if (trace_enabled)
-                                       printf("SQLGetTypeInfo(stmt, 
SQL_HUGEINT) returned %s\n", nameOfRetCode(ret));
+                               TRC_DEBUG(LOADER, "SQLGetTypeInfo(stmt, 
SQL_HUGEINT) returned %s\n", nameOfRetCode(ret));
                                if (ret == SQL_SUCCESS || ret == 
SQL_SUCCESS_WITH_INFO) {
                                        ret = SQLCloseCursor(stmt);
                                }
@@ -582,11 +576,11 @@ odbc_query(int caller, mvc *sql, sql_sub
        if (ret == SQL_SUCCESS_WITH_INFO && caller == ODBC_RELATION) {
                /* show the info warning, but only once */
                char * ODBCmsg = getErrMsg(SQL_HANDLE_STMT, stmt);
-               printf("SQLExecDirect(%s) returned %s ODBCmsg: %s\n", query, 
nameOfRetCode(ret), (ODBCmsg) ? ODBCmsg : "");
+               TRC_INFO(LOADER, "SQLExecDirect(%s) returned %s ODBCmsg: %s\n", 
query, nameOfRetCode(ret), (ODBCmsg) ? ODBCmsg : "");
                if (ODBCmsg)
                        GDKfree(ODBCmsg);
-       } else if (trace_enabled) {
-               printf("SQLExecDirect(%s) returned %s\n", query, 
nameOfRetCode(ret));
+       } else {
+               TRC_DEBUG(LOADER, "SQLExecDirect(%s) returned %s\n", query, 
nameOfRetCode(ret));
        }
        if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
                errmsg = "SQLExecDirect query failed.";
@@ -606,12 +600,11 @@ odbc_query(int caller, mvc *sql, sql_sub
                errmsg = "ODBC query did not return a resultset.";
                goto finish;
        }
-       if (trace_enabled)
-               printf("Query has %d result columns\n", nr_cols);
+       TRC_INFO(LOADER, "Query has %d result columns\n", nr_cols);
        if (nr_cols > QUERY_MAX_COLUMNS) {
                /* limit the number of data columns, as we do not want to block 
or blow up the mserver */
                nr_cols = QUERY_MAX_COLUMNS;
-               printf("\nODBC_loader limited Query result to first %d 
columns.\n", nr_cols);
+               TRC_INFO(LOADER, "ODBC_loader limited Query result to first %d 
columns.\n", nr_cols);
        }
 
        /* when called from odbc_relation() */
@@ -636,8 +629,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                errmsg = "SQLDescribeCol failed.";
                                goto finish;
                        }
-                       if (trace_enabled)
-                               printf("ResCol %u, name: %s, type %d (%s), size 
%u, decdigits %d\n",
+                       TRC_DEBUG(LOADER, "ResCol %u, name: %s, type %d (%s), 
size %u, decdigits %d\n",
                                        col, cname, dataType, 
nameofSQLtype(dataType), (unsigned int)columnSize, decimalDigits);
                        sql_mtype = map_rescol_type(dataType, columnSize, 
decimalDigits, sql);
                        if (sql_mtype == NULL)
@@ -726,8 +718,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                GDKfree(colmetadata);
                                goto finish;
                        }
-                       if (trace_enabled)
-                               printf("DescCol %u, name: %s, type %d (%s), 
size %u, decdigits %d\n",
+                       TRC_DEBUG(LOADER, "DescCol %u, name: %s, type %d (%s), 
size %u, decdigits %d\n",
                                        col+1, cname, dataType, 
nameofSQLtype(dataType), (unsigned int)columnSize, decimalDigits);
 
                        colmetadata[col].dataType = dataType;
@@ -752,6 +743,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                        largestStringSize = columnSize;
                                }
                        } else
+#ifdef HAVE_HGE
                        if (battype == TYPE_hge) {
                                if (dataType == SQL_HUGEINT) {
                                        /* read it as string */
@@ -766,6 +758,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                        colmetadata[col].bufferLength = 
largestStringSize;
                                }
                        } else
+#endif
                        if (battype == TYPE_blob) {
                                hasBlobCols = true;
                                if (columnSize > largestBlobSize) {
@@ -914,17 +907,14 @@ odbc_query(int caller, mvc *sql, sql_sub
                                        break;
                        }
 
-                       if (trace_enabled)
-                               printf("ResCol %u, name: %s, type %d (%s), size 
%u, decdigits %d, battype %d\n",
+                       TRC_INFO(LOADER, "ResCol %u, name: %s, type %d (%s), 
size %u, decdigits %d, battype %d\n",
                                        col+1, cname, dataType, 
nameofSQLtype(dataType), (unsigned int)columnSize, decimalDigits, battype);
 
-                       if (trace_enabled)
-                               printf("Before create BAT %d type %d\n", col+1, 
battype);
+                       TRC_DEBUG(LOADER, "Before create BAT %d type %d\n", 
col+1, battype);
                        b = bat_create(battype, 0);
                        if (b) {
                                colmetadata[col].bat = b;
-                               if (trace_enabled)
-                                       printf("Created BAT %d\n", col+1);
+                               TRC_DEBUG(LOADER, "Created BAT %d\n", col+1);
                        } else {
                                errmsg = "Failed to create bat.";
                                /* cleanup already created bats */
@@ -952,8 +942,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                        errmsg = "Failed to alloc memory for largest rescol 
string buffer.";
                        goto finish_fetch;
                }
-               if (trace_enabled)
-                       printf("Allocated str_val buffer of size %zu\n", 
(largestStringSize +1) * sizeof(char));
+               TRC_DEBUG(LOADER, "Allocated str_val buffer of size %zu\n", 
(largestStringSize +1) * sizeof(char));
 
                if (hasBlobCols) {
                        if (largestBlobSize == 0)       // no valid blob/binary 
data size, assume 1048576 (1MB) as default
@@ -965,8 +954,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                errmsg = "Failed to alloc memory for largest 
rescol binary data buffer.";
                                goto finish_fetch;
                        }
-                       if (trace_enabled)
-                               printf("Allocated bin_data buffer of size 
%zu\n", largestBlobSize * sizeof(uint8_t));
+                       TRC_DEBUG(LOADER, "Allocated bin_data buffer of size 
%zu\n", largestBlobSize * sizeof(uint8_t));
                }
 
                /* after allocation of var sized buffers, update targetValuePtr 
and bufferLength for those columns */
@@ -991,8 +979,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                ret = SQLFetch(stmt);   // TODO optimisation: use 
SQLExtendedFetch() to pull data array wise and use BUNappendmulti()
                while (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) {
                        row++;
-                       if (trace_enabled)
-                               printf("Fetched row %lu\n", row);
+                       TRC_DEBUG(LOADER, "Fetched row %lu\n", row);
 
                        for (SQLUSMALLINT col = 0; col < (SQLUSMALLINT) 
nr_cols; col++) {
                                SQLSMALLINT sqltype = colmetadata[col].dataType;
@@ -1002,28 +989,23 @@ odbc_query(int caller, mvc *sql, sql_sub
                                SQLLEN bufferLength = 
colmetadata[col].bufferLength;
                                SQLLEN strLen = 0;
 
-                               if (trace_enabled)
-                                       printf("Before SQLGetData(col %u C_type 
%d buflen %d\n", col+1, targetType, (int)bufferLength);
+                               TRC_DEBUG(LOADER, "Before SQLGetData(col %u 
C_type %d buflen %d\n", col+1, targetType, (int)bufferLength);
                                ret = SQLGetData(stmt, col+1, targetType, 
targetValuePtr, bufferLength, &strLen);
                                if (ret != SQL_SUCCESS && ret != 
SQL_SUCCESS_WITH_INFO) {
-                                       if (trace_enabled) {
-                                               char * ODBCmsg = 
getErrMsg(SQL_HANDLE_STMT, stmt);
-                                               printf("Failed to get C_type %d 
data for col %u of row %lu. ODBCmsg: %s\n",
+                                       char * ODBCmsg = 
getErrMsg(SQL_HANDLE_STMT, stmt);
+                                       TRC_DEBUG(LOADER, "Failed to get C_type 
%d data for col %u of row %lu. ODBCmsg: %s\n",
                                                        targetType, col+1, row, 
(ODBCmsg) ? ODBCmsg : "");
-                                               if (ODBCmsg)
-                                                       GDKfree(ODBCmsg);
-                                       }
+                                       if (ODBCmsg)
+                                               GDKfree(ODBCmsg);
+
                                        /* as all bats need to be the same 
length, append NULL value */
                                        if (BUNappend(b, ATOMnilptr(b->ttype), 
false) != GDK_SUCCEED)
-                                               if (trace_enabled)
-                                                       printf("BUNappend(b, 
NULL, false) failed\n");
+                                               TRC_ERROR(LOADER, "BUNappend(b, 
ATOMnilptr(b->ttype), false) failed after SQLGetData failed\n");
                                } else {
                                        if (strLen == SQL_NULL_DATA) {
-                                               if (trace_enabled)
-                                                       printf("Data row %lu 
col %u: NULL\n", row, col+1);
+                                               TRC_DEBUG(LOADER, "Data row %lu 
col %u: NULL\n", row, col+1);
                                                if (BUNappend(b, 
ATOMnilptr(b->ttype), false) != GDK_SUCCEED)
-                                                       if (trace_enabled)
-                                                               
printf("BUNappend(b, ATOMnilptr(b->ttype), false) failed\n");
+                                                       TRC_ERROR(LOADER, 
"BUNappend(b, ATOMnilptr(b->ttype), false) failed for setting SQL_NULL_DATA\n");
                                        } else {
                                                switch(sqltype) {
                                                        case SQL_CHAR:
@@ -1043,8 +1025,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                                
        str_val[largestStringSize] = '\0';
                                                                        }
                                                                }
-                                                               if 
(trace_enabled)
-                                                                       
printf("Data row %lu col %u: %s\n", row, col+1, str_val);
+                                                               
TRC_DEBUG(LOADER, "Data row %lu col %u: %s\n", row, col+1, str_val);
                                                                switch 
(colmetadata[col].battype) {
                                                                        case 
TYPE_str:
                                                                                
gdkret = BUNappend(b, (void *) str_val, false);
@@ -1063,8 +1044,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                break;
                                                        case SQL_BIT:
                                                                if 
(colmetadata[col].battype == TYPE_bit) {
-                                                                       if 
(trace_enabled)
-                                                                               
printf("Data row %lu col %u: %x\n", row, col+1, bit_val);
+                                                                       
TRC_DEBUG(LOADER, "Data row %lu col %u: %x\n", row, col+1, bit_val);
                                                                        gdkret 
= BUNappend(b, (void *) &bit_val, false);
                                                                } else {
                                                                        gdkret 
= BUNappend(b, ATOMnilptr(b->ttype), false);
@@ -1072,8 +1052,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                break;
                                                        case SQL_TINYINT:
                                                                if 
(colmetadata[col].battype == TYPE_bte) {
-                                                                       if 
(trace_enabled)
-                                                                               
printf("Data row %lu col %u: %hd\n", row, col+1, (sht) bte_val);
+                                                                       
TRC_DEBUG(LOADER, "Data row %lu col %u: %hd\n", row, col+1, (sht) bte_val);
                                                                        gdkret 
= BUNappend(b, (void *) &bte_val, false);
                                                                } else {
                                                                        gdkret 
= BUNappend(b, ATOMnilptr(b->ttype), false);
@@ -1081,8 +1060,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                break;
                                                        case SQL_SMALLINT:
                                                                if 
(colmetadata[col].battype == TYPE_sht) {
-                                                                       if 
(trace_enabled)
-                                                                               
printf("Data row %lu col %u: %hd\n", row, col+1, sht_val);
+                                                                       
TRC_DEBUG(LOADER, "Data row %lu col %u: %hd\n", row, col+1, sht_val);
                                                                        gdkret 
= BUNappend(b, (void *) &sht_val, false);
                                                                } else {
                                                                        gdkret 
= BUNappend(b, ATOMnilptr(b->ttype), false);
@@ -1090,8 +1068,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                break;
                                                        case SQL_INTEGER:
                                                                if 
(colmetadata[col].battype == TYPE_int) {
-                                                                       if 
(trace_enabled)
-                                                                               
printf("Data row %lu col %u: %d\n", row, col+1, int_val);
+                                                                       
TRC_DEBUG(LOADER, "Data row %lu col %u: %d\n", row, col+1, int_val);
                                                                        gdkret 
= BUNappend(b, (void *) &int_val, false);
                                                                } else {
                                                                        gdkret 
= BUNappend(b, ATOMnilptr(b->ttype), false);
@@ -1099,8 +1076,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                break;
                                                        case SQL_BIGINT:
                                                                if 
(colmetadata[col].battype == TYPE_lng) {
-                                                                       if 
(trace_enabled)
-                                                                               
printf("Data row %lu col %u: %" PRId64 "\n", row, col+1, lng_val);
+                                                                       
TRC_DEBUG(LOADER, "Data row %lu col %u: %" PRId64 "\n", row, col+1, lng_val);
                                                                        gdkret 
= BUNappend(b, (void *) &lng_val, false);
                                                                } else {
                                                                        gdkret 
= BUNappend(b, ATOMnilptr(b->ttype), false);
@@ -1119,8 +1095,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                                
                str_val[largestStringSize] = '\0';
                                                                                
}
                                                                        }
-                                                                       if 
(trace_enabled)
-                                                                               
printf("Data row %lu col %u: %s\n", row, col+1, str_val);
+                                                                       
TRC_DEBUG(LOADER, "Data row %lu col %u: %s\n", row, col+1, str_val);
                                                                        gdkret 
= BUNappend(b, (void *) str_val, false);
                                                                } else {
                                                                        gdkret 
= BUNappend(b, ATOMnilptr(b->ttype), false);
@@ -1130,8 +1105,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                break;
                                                        case SQL_REAL:
                                                                if 
(colmetadata[col].battype == TYPE_flt) {
-                                                                       if 
(trace_enabled)
-                                                                               
printf("Data row %lu col %u: %f\n", row, col+1, flt_val);
+                                                                       
TRC_DEBUG(LOADER, "Data row %lu col %u: %f\n", row, col+1, flt_val);
                                                                        gdkret 
= BUNappend(b, (void *) &flt_val, false);
                                                                } else {
                                                                        gdkret 
= BUNappend(b, ATOMnilptr(b->ttype), false);
@@ -1139,8 +1113,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                                                                break;
                                                        case SQL_DOUBLE:
                                                                if 
(colmetadata[col].battype == TYPE_dbl) {
-                                                                       if 
(trace_enabled)
-                                                                               
printf("Data row %lu col %u: %f\n", row, col+1, dbl_val);
+                                                                       
TRC_DEBUG(LOADER, "Data row %lu col %u: %f\n", row, col+1, dbl_val);
                                                                        gdkret 
= BUNappend(b, (void *) &dbl_val, false);
                                                                } else {
                                                                        gdkret 
= BUNappend(b, ATOMnilptr(b->ttype), false);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to