Changeset: ae491bc2025a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ae491bc2025a
Modified Files:
        clients/odbc/driver/ODBCConvert.c
        clients/odbc/driver/ODBCUtil.c
        clients/odbc/driver/SQLBindParameter.c
        clients/odbc/driver/SQLColumns.c
        clients/odbc/driver/SQLExecute.c
        clients/odbc/driver/SQLGetTypeInfo.c
        clients/odbc/driver/SQLPrepare.c
        clients/odbc/driver/SQLSpecialColumns.c
Branch: Feb2013
Log Message:

Inside the ODBC driver, treat server's character data as wide characters.
This solves another part of bug 3337: the string data is now displayed
correctly.


diffs (truncated from 592 to 300 lines):

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
@@ -1090,8 +1090,6 @@ ODBCFetch(ODBCStmt *stmt,
 
        /* see SQLExecute.c for possible types */
        switch (sql_type) {
-       case SQL_CHAR:
-               break;
        case SQL_DECIMAL:
        case SQL_TINYINT:
        case SQL_SMALLINT:
@@ -1238,7 +1236,10 @@ ODBCFetch(ODBCStmt *stmt,
                        if (data != NULL &&
                            (sql_type == SQL_CHAR ||
                             sql_type == SQL_VARCHAR ||
-                            sql_type == SQL_LONGVARCHAR))
+                            sql_type == SQL_LONGVARCHAR ||
+                            sql_type == SQL_WCHAR ||
+                            sql_type == SQL_WVARCHAR ||
+                            sql_type == SQL_WLONGVARCHAR))
                                buflen = (SQLLEN) datalen + 1; /* but this is 
certainly enough for strings */
                        ptr = malloc(buflen);
 
@@ -1251,6 +1252,9 @@ ODBCFetch(ODBCStmt *stmt,
                case SQL_CHAR:
                case SQL_VARCHAR:
                case SQL_LONGVARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
+               case SQL_WLONGVARCHAR:
                        copyString(data, datalen, ptr, buflen, lenp, SQLLEN, 
addStmtError, stmt, return SQL_ERROR);
                        break;
                case SQL_BINARY:
@@ -1822,6 +1826,9 @@ ODBCFetch(ODBCStmt *stmt,
 
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                case SQL_DECIMAL:
                case SQL_TINYINT:
                case SQL_SMALLINT:
@@ -1860,6 +1867,9 @@ ODBCFetch(ODBCStmt *stmt,
                        *lenp = 1;
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                        if (!parsedouble(data, &fval)) {
                                /* Invalid character value for cast
                                   specification */
@@ -1957,6 +1967,9 @@ ODBCFetch(ODBCStmt *stmt,
                }
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                case SQL_DOUBLE:
                case SQL_REAL:
                        /* reparse double and float, parse char */
@@ -2055,6 +2068,9 @@ ODBCFetch(ODBCStmt *stmt,
                maxval--;
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                case SQL_DOUBLE:
                case SQL_REAL:
                        /* reparse double and float, parse char */
@@ -2118,6 +2134,9 @@ ODBCFetch(ODBCStmt *stmt,
 
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                case SQL_DOUBLE:
                case SQL_REAL:
                        /* reparse double and float, parse char */
@@ -2173,6 +2192,9 @@ ODBCFetch(ODBCStmt *stmt,
        case SQL_C_DOUBLE:
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                        if (!parsedouble(data, &fval)) {
                                /* Invalid character value for cast
                                 * specification */
@@ -2237,6 +2259,9 @@ ODBCFetch(ODBCStmt *stmt,
                i = 1;
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                        i = parsetimestamp(data, &tsval);
                        /* fall through */
                case SQL_TYPE_TIMESTAMP:        /* note i==1 unless we fell 
through */
@@ -2273,6 +2298,9 @@ ODBCFetch(ODBCStmt *stmt,
                i = 1;
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                        i = parsetimestamp(data, &tsval);
                        /* fall through */
                case SQL_TYPE_TIMESTAMP:        /* note i==1 unless we fell 
through */
@@ -2309,6 +2337,9 @@ ODBCFetch(ODBCStmt *stmt,
                i = 1;
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                        i = parsetimestamp(data, &tsval);
                        if (i == 0) {
                                i = parsetime(data, &tval);
@@ -2370,6 +2401,9 @@ ODBCFetch(ODBCStmt *stmt,
 
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                        if (parsemonthintervalstring(&data, NULL, &ival) == 
SQL_ERROR) {
                                /* Invalid character value for cast
                                 * specification */
@@ -2447,6 +2481,9 @@ ODBCFetch(ODBCStmt *stmt,
 
                switch (sql_type) {
                case SQL_CHAR:
+               case SQL_VARCHAR:
+               case SQL_WCHAR:
+               case SQL_WVARCHAR:
                        if (parsesecondintervalstring(&data, NULL, &ival, 
&ivalprec) == SQL_ERROR) {
                                /* Invalid character value for cast
                                 * specification */
@@ -2974,6 +3011,9 @@ ODBCStore(ODBCStmt *stmt,
        case SQL_CHAR:
        case SQL_VARCHAR:
        case SQL_LONGVARCHAR:
+       case SQL_WCHAR:
+       case SQL_WVARCHAR:
+       case SQL_WLONGVARCHAR:
                assign(buf, bufpos, buflen, '\'', stmt);
                switch (ctype) {
                case SQL_C_CHAR:
diff --git a/clients/odbc/driver/ODBCUtil.c b/clients/odbc/driver/ODBCUtil.c
--- a/clients/odbc/driver/ODBCUtil.c
+++ b/clients/odbc/driver/ODBCUtil.c
@@ -133,7 +133,13 @@ ODBCwchar2utf8(const SQLWCHAR *s, SQLLEN
                                        *errmsg = "High surrogate not followed 
by low surrogate";
                                return NULL;
                        }
+#if 1
+                       if (errmsg)
+                               *errmsg = "Code points larger than U+FFFF are 
not supported";
+                       return NULL;
+#else
                        c = (c << 10) + *s1 + SURROGATE_OFFSET;
+#endif
                } else if (0xDC00 <= c && c <= 0xDFFF) {
                        /* low surrogate--illegal */
                        if (errmsg)
@@ -236,11 +242,15 @@ ODBCutf82wchar(const SQLCHAR *s,
                                *p++ = c;
                        len++;
                } else {
+#if 1
+                       return "Code points larger than U+FFFF are not 
supported";
+#else
                        if ((buflen -= 2) > 0 && p != NULL) {
                                *p++ = LEAD_OFFSET + (c >> 10);
                                *p++ = 0xDC00 + (c & 0x3FF);
                        }
                        len += 2;
+#endif
                }
        }
        if (p != NULL)
diff --git a/clients/odbc/driver/SQLBindParameter.c 
b/clients/odbc/driver/SQLBindParameter.c
--- a/clients/odbc/driver/SQLBindParameter.c
+++ b/clients/odbc/driver/SQLBindParameter.c
@@ -196,9 +196,9 @@ SQLBindParameter_(ODBCStmt *stmt,
        case SQL_DOUBLE:
                ipdrec->sql_desc_precision = (SQLSMALLINT) ColumnSize;
                break;
-/*     case SQL_WCHAR: */
-/*     case SQL_WVARCHAR: */
-/*     case SQL_WLONGVARCHAR: */
+       case SQL_WCHAR:
+       case SQL_WVARCHAR:
+       case SQL_WLONGVARCHAR:
        case SQL_BIT:
        case SQL_TINYINT:
        case SQL_SMALLINT:
@@ -226,9 +226,6 @@ SQLBindParameter_(ODBCStmt *stmt,
        case SQL_INTERVAL_MINUTE_TO_SECOND:
        case SQL_NUMERIC:
        case SQL_FLOAT:
-       case SQL_WCHAR:
-       case SQL_WVARCHAR:
-       case SQL_WLONGVARCHAR:
        case SQL_GUID:
                /* Optional feature not implemented */
                addStmtError(stmt, "HYC00", NULL, 0);
diff --git a/clients/odbc/driver/SQLColumns.c b/clients/odbc/driver/SQLColumns.c
--- a/clients/odbc/driver/SQLColumns.c
+++ b/clients/odbc/driver/SQLColumns.c
@@ -192,9 +192,9 @@ SQLColumns_(ODBCStmt *stmt,
                                     " when 13 then %d"
                                " end"
                           " when 'smallint' then %d"
+                          " when 'time' 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"
@@ -235,9 +235,9 @@ SQLColumns_(ODBCStmt *stmt,
                                     " when 13 then 'INTERVAL SECOND'"
                                " end"
                           " when 'smallint' then 'SMALLINT'"
+                          " when 'time' then 'TIME'"
                           " when 'timestamp' then 'TIMESTAMP'"
                           " when 'timestamptz' then 'TIMESTAMP'"
-                          " when 'time' then 'TIME'"
                           " when 'timetz' then 'TIME'"
                           " when 'tinyint' then 'TINYINT'"
                           " when 'varchar' then 'VARCHAR'"
@@ -248,6 +248,7 @@ SQLColumns_(ODBCStmt *stmt,
                                " end"
                      " end as type_name,"
                      " case c.\"type\""
+                          " when 'date' then 10"
                           " when 'month_interval' then"
                                " case c.type_digits"
                                     " when 1 then 26"
@@ -267,20 +268,26 @@ SQLColumns_(ODBCStmt *stmt,
                                     " 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 'timetz' then 12"
                           " else c.type_digits"
                      " end as column_size,"
                      " case c.\"type\""
+                          " when 'bigint' then 20"
+                          " when 'char' then 2 * c.type_digits"
+                          " when 'clob' then 2 * c.type_digits"
+                          " when 'date' then 10"
+                          " when 'double' then 24"
+                          " when 'int' then 11"
                           " when 'month_interval' then"
                                " case c.type_digits"
                                     " when 1 then 26"
                                     " when 2 then 38"
                                     " when 3 then 27"
                                " end"
+                          " when 'real' then 14"
                           " when 'sec_interval' then"
                                " case c.type_digits"
                                     " when 4 then 25"
@@ -294,19 +301,13 @@ SQLColumns_(ODBCStmt *stmt,
                                     " when 12 then 44"
                                     " when 13 then 30"
                                " end"
-                          " when 'date' then 10"
+                          " when 'smallint' then 6"
                           " when 'time' then 12"
-                          " when 'timetz' then 12"
                           " when 'timestamp' then 23"
                           " when 'timestamptz' then 23"
-                          " when 'bigint' then 20"
-                          " when 'int' then 11"
-                          " when 'smallint' then 6"
+                          " when 'timetz' then 12"
                           " 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"
+                          " when 'varchar' then 2 * c.type_digits"
                           " when 'wrd' then"
                                " case c.type_digits"
                                     " when 32 then 11"
@@ -315,45 +316,46 @@ SQLColumns_(ODBCStmt *stmt,
                           " else c.type_digits"
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to