Changeset: 1f9bc78e052b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1f9bc78e052b
Modified Files:
        sql/server/rel_dump.c
Branch: default
Log Message:

Merge with Mar2025 branch.


diffs (truncated from 1394 to 300 lines):

diff --git a/clients/Tests/mclient-uri.SQL.py b/clients/Tests/mclient-uri.SQL.py
--- a/clients/Tests/mclient-uri.SQL.py
+++ b/clients/Tests/mclient-uri.SQL.py
@@ -1,7 +1,36 @@
 import os, sys
 from MonetDBtesting import process
 
-with process.client('sql', 
dbname='mapi:monetdb://{}:{}/{}?language=sql&user=monetdb'.format(os.getenv('HOST',
 'localhost'), os.getenv('MAPIPORT', 50000), os.getenv('TSTDB', 'demo')), 
host='', port='', format='csv', echo=False, stdin=process.PIPE, 
stdout=process.PIPE, stderr=process.PIPE) as c:
+host = os.getenv('HOST', 'localhost')
+port = os.getenv('MAPIPORT', 50000)
+db = os.getenv('TSTDB', 'demo')
+mapihost = os.getenv('MAPIHOST', '/tmp') # not used on Windows
+
+with process.client('sql',
+                    
dbname=f'mapi:monetdb://{host}:{port}/{db}?language=sql&user=monetdb',
+                    host='',
+                    port='',
+                    format='csv',
+                    echo=False,
+                    stdin=process.PIPE,
+                    stdout=process.PIPE,
+                    stderr=process.PIPE) as c:
+    out, err = c.communicate('select 1;\n')
+
+if out != '1\n':
+    print(out)
+if err:
+    print(err, file=sys.stderr)
+
+with process.client('sql',
+                    
dbname=f'monetdb://{host}:{port}/{db}?language=sql&user=monetdb&password=monetdb',
+                    host='',
+                    port='',
+                    format='csv',
+                    echo=False,
+                    stdin=process.PIPE,
+                    stdout=process.PIPE,
+                    stderr=process.PIPE) as c:
     out, err = c.communicate('select 1;\n')
 
 if out != '1\n':
@@ -10,10 +39,34 @@ if err:
     print(err, file=sys.stderr)
 
 if os.name != 'nt':
-    with process.client('sql', 
dbname='mapi:monetdb://{}/.s.monetdb.{}?database={}&language=sql&user=monetdb'.format(os.getenv('MAPIHOST',
 '/tmp'), os.getenv('MAPIPORT', 50000), os.getenv('TSTDB', 'demo')), host='', 
port='', format='csv', echo=False, stdin=process.PIPE, stdout=process.PIPE, 
stderr=process.PIPE) as c:
+    with process.client('sql',
+                        
dbname=f'mapi:monetdb://{mapihost}/.s.monetdb.{port}?database={db}&language=sql&user=monetdb',
+                        host='',
+                        port='',
+                        format='csv',
+                        echo=False,
+                        stdin=process.PIPE,
+                        stdout=process.PIPE,
+                        stderr=process.PIPE) as c:
         out, err = c.communicate('select 1;\n')
 
     if out != '1\n':
         print(out)
     if err:
         print(err, file=sys.stderr)
+
+    with process.client('sql',
+                        
dbname=f'monetdb:///{db}?sock={mapihost}/.s.monetdb.{port}&language=sql&user=monetdb&password=monetdb',
+                        host='',
+                        port='',
+                        format='csv',
+                        echo=False,
+                        stdin=process.PIPE,
+                        stdout=process.PIPE,
+                        stderr=process.PIPE) as c:
+        out, err = c.communicate('select 1;\n')
+
+    if out != '1\n':
+        print(out)
+    if err:
+        print(err, file=sys.stderr)
diff --git a/clients/odbc/driver/ODBCConvert.c 
b/clients/odbc/driver/ODBCConvert.c
--- a/clients/odbc/driver/ODBCConvert.c
+++ b/clients/odbc/driver/ODBCConvert.c
@@ -43,16 +43,6 @@ typedef struct {
 #endif
 } bignum_t;
 
-typedef union {
-       SQLGUID g;
-       struct {
-               uint32_t d1;
-               uint16_t d2, d3;
-               uint8_t d4[8];
-       } d;
-       uint8_t u[16];
-} uuid_t;
-
 /* Parse a number and store in a bignum_t.
  * 1 is returned if all is well;
  * 2 is returned if there is loss of precision (i.e. overflow of the value);
@@ -2815,25 +2805,17 @@ ODBCFetch(ODBCStmt *stmt,
 #ifdef ODBCDEBUG
                ODBCLOG("Writing 16 bytes to %p\n", ptr);
 #endif
-               uuid_t u;
-               if (sscanf(data, "%2"SCNx8"%2"SCNx8"%2"SCNx8"%2"SCNx8
-                          "-%2"SCNx8"%2"SCNx8
-                          "-%2"SCNx8"%2"SCNx8
-                          "-%2"SCNx8"%2"SCNx8
-                          "-%2"SCNx8"%2"SCNx8"%2"SCNx8"%2"
-                          SCNx8"%2"SCNx8"%2"SCNx8,
-                          &u.u[3], &u.u[2], &u.u[1], &u.u[0],
-                          &u.u[5], &u.u[4],
-                          &u.u[7], &u.u[6],
-                          &u.u[8], &u.u[9],
-                          &u.u[10], &u.u[11], &u.u[12],
-                          &u.u[13], &u.u[14], &u.u[15]) != 16) {
-                       /* Restricted data type attribute
-                        * violation */
-                       addStmtError(stmt, "07006", NULL, 0);
-                       return SQL_ERROR;
-               }
-               WriteData(ptr, u.g, SQLGUID);
+               SQLGUID su;
+               sscanf(data,
+                      "%8"SCNx32
+                      "-%4"SCNx16
+                      "-%4"SCNx16
+                      "-%2"SCNx8"%2"SCNx8
+                      "-%2"SCNx8"%2"SCNx8"%2"SCNx8"%2"SCNx8"%2"SCNx8"%2"SCNx8,
+                      &su.Data1, &su.Data2, &su.Data3,
+                      &su.Data4[0], &su.Data4[1],
+                      &su.Data4[2], &su.Data4[3], &su.Data4[4], &su.Data4[5], 
&su.Data4[6], &su.Data4[7]);
+               WriteData(ptr, su, SQLGUID);
                if (lenp)
                        *lenp = sizeof(SQLGUID);
                break;
@@ -2905,7 +2887,7 @@ ODBCStore(ODBCStmt *stmt,
        TIMESTAMP_STRUCT tsval;
        int ivalprec = 0;       /* interval second precision */
        SQL_INTERVAL_STRUCT ival;
-       uuid_t u;
+       SQLGUID u;
        char *buf = *bufp;
        size_t bufpos = *bufposp;
        size_t buflen = *buflenp;
@@ -3364,20 +3346,17 @@ ODBCStore(ODBCStmt *stmt,
                        }
                        break;
                case SQL_C_GUID:
-                       u.g = *(SQLGUID *)ptr;
+                       u = *(SQLGUID *)ptr;
                        snprintf(data, sizeof(data),
-                                "%02"PRIx8"%02"PRIx8"%02"PRIx8"%02"PRIx8
-                                "-%02"PRIx8"%02"PRIx8
-                                "-%02"PRIx8"%02"PRIx8
+                                "%08"PRIx32"-%04"PRIx16"-%04"PRIx16
                                 "-%02"PRIx8"%02"PRIx8
                                 "-%02"PRIx8"%02"PRIx8"%02"PRIx8
                                 "%02"PRIx8"%02"PRIx8"%02"PRIx8,
-                                u.u[3], u.u[2], u.u[1], u.u[0],
-                                u.u[5], u.u[4],
-                                u.u[7], u.u[6],
-                                u.u[8], u.u[9],
-                                u.u[10], u.u[11], u.u[12],
-                                u.u[13], u.u[14], u.u[15]);
+                                u.Data1, u.Data2, u.Data3,
+                                u.Data4[0], u.Data4[1],
+                                u.Data4[2], u.Data4[3],
+                                u.Data4[4], u.Data4[5],
+                                u.Data4[6], u.Data4[7]);
                        break;
                }
                assign(buf, bufpos, buflen, '\'', stmt);
@@ -3907,36 +3886,29 @@ ODBCStore(ODBCStmt *stmt,
                                addStmtError(stmt, "22018", NULL, 0);
                                goto failure;
                        }
-                       for (i = 0; i < 36; i++) {
-                               if (strchr("0123456789abcdefABCDEF-",
-                                          sval[i]) == NULL) {
-                                       /* not sure this is the
-                                        * correct error */
-                                       /* Invalid character value for
-                                        * cast specification */
-                                       addStmtError(stmt, "22018", NULL, 0);
-                                       goto failure;
-                               }
+                       if (sval[strspn(sval, "0123456789abcdefABCDEF-")] != 0) 
{
+                               /* not sure this is the correct error */
+                               /* Invalid character value for cast
+                                * specification */
+                               addStmtError(stmt, "22018", NULL, 0);
+                               goto failure;
                        }
                        snprintf(data, sizeof(data), "%.36s", sval);
                        break;
                case SQL_C_GUID:
-                       u.g = *(SQLGUID *)ptr;
+                       u = *(SQLGUID *)ptr;
                        snprintf(data, sizeof(data),
                                 "UUID '"
-                                "%02"PRIx8"%02"PRIx8"%02"PRIx8"%02"PRIx8
-                                "-%02"PRIx8"%02"PRIx8
-                                "-%02"PRIx8"%02"PRIx8
+                                "%08"PRIx32"-%04"PRIx16"-%04"PRIx16
                                 "-%02"PRIx8"%02"PRIx8
                                 "-%02"PRIx8"%02"PRIx8"%02"PRIx8
                                 "%02"PRIx8"%02"PRIx8"%02"PRIx8
                                 "'",
-                                u.u[3], u.u[2], u.u[1], u.u[0],
-                                u.u[5], u.u[4],
-                                u.u[7], u.u[6],
-                                u.u[8], u.u[9],
-                                u.u[10], u.u[11], u.u[12],
-                                u.u[13], u.u[14], u.u[15]);
+                                u.Data1, u.Data2, u.Data3,
+                                u.Data4[0], u.Data4[1],
+                                u.Data4[2], u.Data4[3],
+                                u.Data4[4], u.Data4[5],
+                                u.Data4[6], u.Data4[7]);
                        break;
                default:
                        /* Restricted data type attribute violation */
diff --git a/clients/odbc/tests/ODBCtester.c b/clients/odbc/tests/ODBCtester.c
--- a/clients/odbc/tests/ODBCtester.c
+++ b/clients/odbc/tests/ODBCtester.c
@@ -212,6 +212,85 @@ testGetDataTruncatedString(SQLHANDLE stm
        return ret;
 }
 
+static SQLRETURN
+testGetDataGUID(SQLHANDLE stmt)
+{
+       SQLRETURN ret;
+       SQLLEN RowCount = 0;
+       SWORD NumResultCols = 0;
+
+       size_t outp_len = 1800;
+       char * outp = malloc(outp_len);
+       size_t pos = 0;
+
+       char * sql = "select cast(NULL as uuid) as valnil, 
cast('eda7b074-3e0f-4bef-bdec-19c61bedb18f' as uuid) as val1, 
cast('beefc4f7-0264-4735-9b7a-75fd371ef803' as uuid) as val2;";
+       ret = SQLExecDirect(stmt, (SQLCHAR *) sql, SQL_NTS);
+       pos += snprintf(outp + pos, outp_len - pos, "SQLExecDirect\n");
+       check(ret, SQL_HANDLE_STMT, stmt, "SQLExecDirect");
+
+       ret = SQLRowCount(stmt, &RowCount);
+       pos += snprintf(outp + pos, outp_len - pos, "SQLRowCount is " LLFMT 
"\n", (int64_t) RowCount);
+       check(ret, SQL_HANDLE_STMT, stmt, "SQLRowCount");
+
+       ret = SQLNumResultCols(stmt, &NumResultCols);
+       pos += snprintf(outp + pos, outp_len - pos, "SQLNumResultCols is %d\n", 
NumResultCols);
+       check(ret, SQL_HANDLE_STMT, stmt, "SQLNumResultCols");
+
+       ret = SQLFetch(stmt);
+       pos += snprintf(outp + pos, outp_len - pos, "SQLFetch\n");
+       check(ret, SQL_HANDLE_STMT, stmt, "SQLFetch");
+
+       for (SWORD col = 1; col <= NumResultCols; col++) {
+               char buf[99];
+               SQLGUID guid_val;
+               char guid_str_val[40];
+               SQLLEN vallen = 0;
+               SQLLEN NumAttr = 0;
+
+               /* retrieve query result column metadata */
+               ret = SQLColAttribute(stmt, (UWORD)col, SQL_DESC_CONCISE_TYPE, 
(PTR)&buf, (SQLLEN)20, NULL, &NumAttr);
+               pos += snprintf(outp + pos, outp_len - pos, 
"SQLColAttribute(%d, SQL_DESC_CONCISE_TYPE) returns %d, NumAttr " LLFMT "\n", 
col, ret, (int64_t) NumAttr);
+               ret = SQLColAttribute(stmt, (UWORD)col, SQL_DESC_DISPLAY_SIZE, 
(PTR)&buf, (SQLLEN)20, NULL, &NumAttr);
+               pos += snprintf(outp + pos, outp_len - pos, 
"SQLColAttribute(%d, SQL_DESC_DISPLAY_SIZE) returns %d, NumAttr " LLFMT "\n", 
col, ret, (int64_t) NumAttr);
+
+               /* test SQLGetData(SQL_C_CHAR) */
+               ret = SQLGetData(stmt, (UWORD)col, (SWORD)SQL_C_CHAR, 
(PTR)&guid_str_val, (SQLLEN)40, &vallen);
+               pos += snprintf(outp + pos, outp_len - pos, "SQLGetData(%d, 
SQL_C_CHAR, 36) returns %d, vallen " LLFMT ", str_val: '%s'\n",
+                       col, ret, (int64_t) vallen, (vallen == SQL_NULL_DATA) ? 
"NULL" : guid_str_val);
+               check(ret, SQL_HANDLE_STMT, stmt, "SQLGetData(col)");
+
+               /* test SQLGetData(SQL_C_GUID) */
+               ret = SQLGetData(stmt, (UWORD)col, (SWORD)SQL_C_GUID, 
(PTR)&guid_val, (SQLLEN)16, &vallen);
+               pos += snprintf(outp + pos, outp_len - pos, "SQLGetData(%d, 
SQL_C_GUID, 16) returns %d, vallen " LLFMT ", data_val: ", col, ret, (int64_t) 
vallen);
+               if (vallen == SQL_NULL_DATA)
+                       pos += snprintf(outp + pos, outp_len - pos, "NULL\n");
+               else
+                       pos += snprintf(outp + pos, outp_len - pos, 
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
+                               guid_val.Data1, guid_val.Data2, guid_val.Data3,
+                               guid_val.Data4[0], guid_val.Data4[1], 
guid_val.Data4[2], guid_val.Data4[3], guid_val.Data4[4], guid_val.Data4[5], 
guid_val.Data4[6], guid_val.Data4[7]);
+               check(ret, SQL_HANDLE_STMT, stmt, "SQLGetData(col)");
+       }
+
+       compareResult("testGetDataGUID()", outp,
+                       "SQLExecDirect\nSQLRowCount is 1\nSQLNumResultCols is 
3\nSQLFetch\n"
+                       "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr -11\n"    /* -11 = SQL_GUID */
+                       "SQLColAttribute(1, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 36\n"
+                       "SQLGetData(1, SQL_C_CHAR, 36) returns 0, vallen -1, 
str_val: 'NULL'\n"
+                       "SQLGetData(1, SQL_C_GUID, 16) returns 0, vallen -1, 
data_val: NULL\n"
+                       "SQLColAttribute(2, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr -11\n"    /* -11 = SQL_GUID */
+                       "SQLColAttribute(2, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 36\n"
+                       "SQLGetData(2, SQL_C_CHAR, 36) returns 0, vallen 36, 
str_val: 'eda7b074-3e0f-4bef-bdec-19c61bedb18f'\n"
+                       "SQLGetData(2, SQL_C_GUID, 16) returns 0, vallen 16, 
data_val: eda7b074-3e0f-4bef-bdec-19c61bedb18f\n"
+                       "SQLColAttribute(3, SQL_DESC_CONCISE_TYPE) returns 0, 
NumAttr -11\n"    /* -11 = SQL_GUID */
+                       "SQLColAttribute(3, SQL_DESC_DISPLAY_SIZE) returns 0, 
NumAttr 36\n"
+                       "SQLGetData(3, SQL_C_CHAR, 36) returns 0, vallen 36, 
str_val: 'beefc4f7-0264-4735-9b7a-75fd371ef803'\n"
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to