*** sqliteodbc-0.77-orig/sqlite3odbc.c Sun Jan 6 18:30:34 2008 --- sqliteodbc-0.77/sqlite3odbc.c Wed Jul 2 22:50:04 2008 *************** *** 368,374 **** #if defined(_WIN32) && defined(WINTERFACE) /* MS Access hack part 1 (reserved error -7748) */ ! static COL statSpec[]; #endif #if (MEMORY_DEBUG < 1) --- 368,389 ---- #if defined(_WIN32) && defined(WINTERFACE) /* MS Access hack part 1 (reserved error -7748) */ ! /*static COL statSpec[];*/ ! static COL statSpec[] = { ! { "SYSTEM", "STATISTICS", "TABLE_QUALIFIER", SCOL_VARCHAR, 50 }, ! { "SYSTEM", "STATISTICS", "TABLE_OWNER", SCOL_VARCHAR, 50 }, ! { "SYSTEM", "STATISTICS", "TABLE_NAME", SCOL_VARCHAR, 255 }, ! { "SYSTEM", "STATISTICS", "NON_UNIQUE", SQL_SMALLINT, 50 }, ! { "SYSTEM", "STATISTICS", "INDEX_QUALIFIER", SCOL_VARCHAR, 255 }, ! { "SYSTEM", "STATISTICS", "INDEX_NAME", SCOL_VARCHAR, 255 }, ! { "SYSTEM", "STATISTICS", "TYPE", SQL_SMALLINT, 50 }, ! { "SYSTEM", "STATISTICS", "ORDINAL_POSITION", SQL_SMALLINT, 50 }, ! { "SYSTEM", "STATISTICS", "COLUMN_NAME", SCOL_VARCHAR, 255 }, ! { "SYSTEM", "STATISTICS", "ASC_OR_DESC", SCOL_CHAR, 1 }, ! { "SYSTEM", "STATISTICS", "CARDINALITY", SQL_INTEGER, 50 }, ! { "SYSTEM", "STATISTICS", "PAGES", SQL_INTEGER, 50 }, ! { "SYSTEM", "STATISTICS", "FILTER_CONDITION", SCOL_VARCHAR, 255 } ! }; #endif #if (MEMORY_DEBUG < 1) *************** *** 3596,3619 **** --- 3611,3654 ---- } } #endif + if (type = SQL_C_CHAR) { + dp = wmb_to_utf(data, len); + if (!dp) { + return nomem(s); + } + } dlen = strlen(dp); freep(&p->parbuf); p->parbuf = xmalloc(dlen + 1); if (!p->parbuf) { #ifdef WINTERFACE + if (type == SQL_C_WCHAR) { if (dp != data) { uc_free(dp); } + } #endif + if (type = SQL_C_CHAR) { + if (dp != data) { + uc_free(dp); + } + } return nomem(s); } p->param = p->parbuf; strcpy(p->param, dp); #ifdef WINTERFACE + if (type == SQL_C_WCHAR) { if (dp != data) { uc_free(dp); } + } #endif + if (type = SQL_C_CHAR) { + if (dp != data) { + uc_free(dp); + } + } p->len = dlen; p->need = -1; } else if (len <= 0) { *************** *** 3650,3663 **** } p->parbuf = p->param = np; p->len = nlen; } else { *((char *) p->param + p->len) = '\0'; } p->need = (type == SQL_C_CHAR || type == SQL_C_WCHAR) ? -1 : 0; #else ! *((char *) p->param + p->len) = '\0'; ! p->need = (type == SQL_C_CHAR) ? -1 : 0; #endif #ifdef _WIN32 if (p->type == SQL_C_WCHAR && --- 3685,3742 ---- } p->parbuf = p->param = np; p->len = nlen; + } else if (type == SQL_C_CHAR) { + char *dp = wmb_to_utf(p->param, p->len); + char *np; + int nlen; + + if (!dp) { + return nomem(s); + } + nlen = strlen(dp); + np = xmalloc(nlen + 1); + if (!np) { + uc_free(dp); + return nomem(s); + } + strcpy(np, dp); + uc_free(dp); + if (p->param == p->parbuf) { + freep(&p->parbuf); + } + p->parbuf = p->param = np; + p->len = nlen; } else { *((char *) p->param + p->len) = '\0'; } p->need = (type == SQL_C_CHAR || type == SQL_C_WCHAR) ? -1 : 0; #else ! if (type == SQL_C_CHAR) { ! char *dp = wmb_to_utf(p->param, p->len); ! char *np; ! int nlen; ! ! if (!dp) { ! return nomem(s); ! } ! nlen = strlen(dp); ! np = xmalloc(nlen + 1); ! if (!np) { ! uc_free(dp); ! return nomem(s); ! } ! strcpy(np, dp); ! uc_free(dp); ! if (p->param == p->parbuf) { ! freep(&p->parbuf); ! } ! p->parbuf = p->param = np; ! p->len = nlen; ! } else { ! *((char *) p->param + p->len) = '\0'; ! p->need = (type == SQL_C_CHAR) ? -1 : 0; ! } #endif #ifdef _WIN32 if (p->type == SQL_C_WCHAR && *************** *** 3820,3840 **** } else #endif if (type == SQL_C_CHAR) { ! p->s3val = p->param; ! if (needalloc) { ! char *dp; freep(&p->parbuf); - dp = xmalloc(p->len + 1); - if (!dp) { - return nomem(s); - } - memcpy(dp, p->param, p->len); - dp[p->len] = '\0'; - p->parbuf = p->param = dp; - p->s3val = p->param; - p->s3size = p->len; } } break; case SQL_C_UTINYINT: --- 3899,3917 ---- } else #endif if (type == SQL_C_CHAR) { ! char *dp = wmb_to_utf(p->param, p->max); + if (!dp) { + return nomem(s); + } + if (p->param == p->parbuf) { freep(&p->parbuf); } + p->parbuf = p->param = dp; + p->len = strlen(p->param); + p->s3val = p->param; + p->s3size = p->len; + p->s3val = p->param; } break; case SQL_C_UTINYINT: *************** *** 4874,4885 **** SQLCHAR *schema, SQLSMALLINT schemaLen, SQLCHAR *table, SQLSMALLINT tableLen) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvprimarykeys(stmt, cat, catLen, schema, schemaLen, ! table, tableLen); HSTMT_UNLOCK(stmt); return ret; } #endif --- 4951,4988 ---- SQLCHAR *schema, SQLSMALLINT schemaLen, SQLCHAR *table, SQLSMALLINT tableLen) { + char *c = NULL, *s = NULL, *t = NULL; SQLRETURN ret; HSTMT_LOCK(stmt); ! if (cat) { ! c = wmb_to_utf(cat, catLen); ! if (!c) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (schema) { ! s = wmb_to_utf(schema, schemaLen); ! if (!s) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (table) { ! t = wmb_to_utf(table, tableLen); ! if (!t) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! ret = drvprimarykeys(stmt, (SQLCHAR *) c, SQL_NTS, ! (SQLCHAR *) s, SQL_NTS, (SQLCHAR *) t, SQL_NTS); ! done: HSTMT_UNLOCK(stmt); + uc_free(t); + uc_free(s); + uc_free(c); return ret; } #endif *************** *** 5252,5263 **** SQLCHAR *table, SQLSMALLINT tableLen, SQLUSMALLINT scope, SQLUSMALLINT nullable) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvspecialcolumns(stmt, id, cat, catLen, schema, schemaLen, ! table, tableLen, scope, nullable); HSTMT_UNLOCK(stmt); return ret; } #endif --- 5355,5393 ---- SQLCHAR *table, SQLSMALLINT tableLen, SQLUSMALLINT scope, SQLUSMALLINT nullable) { + char *c = NULL, *s = NULL, *t = NULL; SQLRETURN ret; HSTMT_LOCK(stmt); ! if (cat) { ! c = wmb_to_utf(cat, catLen); ! if (!c) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (schema) { ! s = wmb_to_utf(schema, schemaLen); ! if (!s) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (table) { ! t = wmb_to_utf(table, tableLen); ! if (!t) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! ret = drvspecialcolumns(stmt, id, (SQLCHAR *) c, SQL_NTS, ! (SQLCHAR *) s, SQL_NTS, (SQLCHAR *) t, SQL_NTS, ! scope, nullable); ! done: HSTMT_UNLOCK(stmt); + uc_free(t); + uc_free(s); + uc_free(c); return ret; } #endif *************** *** 5687,5702 **** SQLCHAR *FKschema, SQLSMALLINT FKschemaLen, SQLCHAR *FKtable, SQLSMALLINT FKtableLen) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvforeignkeys(stmt, ! PKcatalog, PKcatalogLen, ! PKschema, PKschemaLen, PKtable, PKtableLen, ! FKcatalog, FKcatalogLen, ! FKschema, FKschemaLen, ! FKtable, FKtableLen); HSTMT_UNLOCK(stmt); return ret; } #endif --- 5817,5881 ---- SQLCHAR *FKschema, SQLSMALLINT FKschemaLen, SQLCHAR *FKtable, SQLSMALLINT FKtableLen) { + char *pc = NULL, *ps = NULL, *pt = NULL; + char *fc = NULL, *fs = NULL, *ft = NULL; SQLRETURN ret; HSTMT_LOCK(stmt); ! if (PKcatalog) { ! pc = wmb_to_utf(PKcatalog, PKcatalogLen); ! if (!pc) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (PKschema) { ! ps = wmb_to_utf(PKschema, PKschemaLen); ! if (!ps) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (PKtable) { ! pt = wmb_to_utf(PKtable, PKtableLen); ! if (!pt) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (FKcatalog) { ! fc = wmb_to_utf(FKcatalog, FKcatalogLen); ! if (!fc) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (FKschema) { ! fs = wmb_to_utf(FKschema, FKschemaLen); ! if (!fs) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (FKtable) { ! ft = wmb_to_utf(FKtable, FKtableLen); ! if (!ft) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! ret = drvforeignkeys(stmt, (SQLCHAR *) pc, SQL_NTS, ! (SQLCHAR *) ps, SQL_NTS, (SQLCHAR *) pt, SQL_NTS, ! (SQLCHAR *) fc, SQL_NTS, (SQLCHAR *) fs, SQL_NTS, ! (SQLCHAR *) ft, SQL_NTS); ! done: HSTMT_UNLOCK(stmt); + uc_free(ft); + uc_free(fs); + uc_free(fc); + uc_free(pt); + uc_free(ps); + uc_free(pc); return ret; } #endif *************** *** 9076,9086 **** SQLCHAR *uid, SQLSMALLINT uidLen, SQLCHAR *pass, SQLSMALLINT passLen) { SQLRETURN ret; HDBC_LOCK(dbc); ! ret = drvconnect(dbc, dsn, dsnLen, 0); HDBC_UNLOCK(dbc); return ret; } #endif --- 9255,9278 ---- SQLCHAR *uid, SQLSMALLINT uidLen, SQLCHAR *pass, SQLSMALLINT passLen) { + char *dsna = NULL; SQLRETURN ret; HDBC_LOCK(dbc); ! if (dsn) { ! dsna = wmb_to_utf(dsn, dsnLen); ! if (!dsna) { ! DBC *d = (DBC *) dbc; ! ! setstatd(d, -1, "out of memory", (*d->ov3) ? "HY000" : "S1000"); ! ret = SQL_ERROR; ! goto done; ! } ! } ! ret = drvconnect(dbc, (SQLCHAR *) dsna, SQL_NTS, 1); ! done: HDBC_UNLOCK(dbc); + uc_free(dsna); return ret; } #endif *************** *** 9744,9754 **** SQLRETURN SQL_API SQLSetCursorName(SQLHSTMT stmt, SQLCHAR *cursor, SQLSMALLINT len) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvsetcursorname(stmt, cursor, len); HSTMT_UNLOCK(stmt); return ret; } #endif --- 9936,9956 ---- SQLRETURN SQL_API SQLSetCursorName(SQLHSTMT stmt, SQLCHAR *cursor, SQLSMALLINT len) { + char *c = NULL; SQLRETURN ret; HSTMT_LOCK(stmt); ! if (cursor) { ! c = wmb_to_utf(cursor, len); ! if (!c) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! ret = drvsetcursorname(stmt, (SQLCHAR *) c, SQL_NTS); ! done: HSTMT_UNLOCK(stmt); + uc_free(c); return ret; } #endif *************** *** 10303,10308 **** --- 10505,10511 ---- int offs = 0; #ifdef WINTERFACE SQLWCHAR *ucdata = NULL; + SQLCHAR *wmbdata = NULL; #endif #if defined(_WIN32) && defined(WINTERFACE) *************** *** 10339,10349 **** --- 10542,10560 ---- #else doz = (type == SQL_C_CHAR) ? 1 : 0; #endif + if (type == SQL_C_CHAR) { + wmbdata = utf_to_wmb((SQLCHAR *) *data, dlen); + if (!wmbdata) { + return nomem(s); + } + dlen = strlen(wmbdata); + } if (partial && len && s->bindcols) { if (dlen && s->bindcols[col].offs >= dlen) { s->bindcols[col].offs = 0; #ifdef WINTERFACE uc_free(ucdata); + if (wmbdata) xfree(wmbdata); #endif return SQL_NO_DATA; } *************** *** 10355,10360 **** --- 10566,10573 ---- if (type == SQL_C_WCHAR) { uc_strncpy(val, ucdata + offs / sizeof (SQLWCHAR), (len - doz) / sizeof (SQLWCHAR)); + } else if (type == SQL_C_CHAR) { + strncpy(val, wmbdata + offs, len - doz); } else { strncpy(val, *data + offs, len - doz); } *************** *** 10385,10390 **** --- 10598,10604 ---- } #ifdef WINTERFACE uc_free(ucdata); + if (wmbdata) free(wmbdata); #endif if (partial && len && s->bindcols) { if (*lenp == SQL_NO_TOTAL) { *************** *** 10776,10787 **** SQLCHAR *table, SQLSMALLINT tableLen, SQLCHAR *type, SQLSMALLINT typeLen) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvtables(stmt, cat, catLen, schema, schemaLen, ! table, tableLen, type, typeLen); HSTMT_UNLOCK(stmt); return ret; } #endif --- 10990,11035 ---- SQLCHAR *table, SQLSMALLINT tableLen, SQLCHAR *type, SQLSMALLINT typeLen) { + char *c = NULL, *s = NULL, *t = NULL, *y = NULL; SQLRETURN ret; HSTMT_LOCK(stmt); ! if (cat) { ! c = wmb_to_utf(cat, catLen); ! if (!c) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (schema) { ! s = wmb_to_utf(schema, schemaLen); ! if (!s) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (table) { ! t = wmb_to_utf(table, tableLen); ! if (!t) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (type) { ! y = wmb_to_utf(type, typeLen); ! if (!y) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! ret = drvtables(stmt, (SQLCHAR *) c, SQL_NTS, (SQLCHAR *) s, SQL_NTS, ! (SQLCHAR *) t, SQL_NTS, (SQLCHAR *) y, SQL_NTS); ! done: HSTMT_UNLOCK(stmt); + uc_free(y); + uc_free(t); + uc_free(s); + uc_free(c); return ret; } #endif *************** *** 11217,11228 **** SQLCHAR *table, SQLSMALLINT tableLen, SQLCHAR *col, SQLSMALLINT colLen) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvcolumns(stmt, cat, catLen, schema, schemaLen, ! table, tableLen, col, colLen); HSTMT_UNLOCK(stmt); return ret; } #endif --- 11465,11510 ---- SQLCHAR *table, SQLSMALLINT tableLen, SQLCHAR *col, SQLSMALLINT colLen) { + char *c = NULL, *s = NULL, *t = NULL, *k = NULL; SQLRETURN ret; HSTMT_LOCK(stmt); ! if (cat) { ! c = wmb_to_utf(cat, catLen); ! if (!c) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (schema) { ! s = wmb_to_utf(schema, schemaLen); ! if (!s) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (table) { ! t = wmb_to_utf(table, tableLen); ! if (!t) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (col) { ! k = wmb_to_utf(col, colLen); ! if (!k) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! ret = drvcolumns(stmt, (SQLCHAR *) c, SQL_NTS, (SQLCHAR *) s, SQL_NTS, ! (SQLCHAR *) t, SQL_NTS, (SQLCHAR *) k, SQL_NTS); ! done: HSTMT_UNLOCK(stmt); + uc_free(k); + uc_free(t); + uc_free(s); + uc_free(c); return ret; } #endif *************** *** 11697,11717 **** * Columns for result set of SQLStatistics(). */ - static COL statSpec[] = { - { "SYSTEM", "STATISTICS", "TABLE_QUALIFIER", SCOL_VARCHAR, 50 }, - { "SYSTEM", "STATISTICS", "TABLE_OWNER", SCOL_VARCHAR, 50 }, - { "SYSTEM", "STATISTICS", "TABLE_NAME", SCOL_VARCHAR, 255 }, - { "SYSTEM", "STATISTICS", "NON_UNIQUE", SQL_SMALLINT, 50 }, - { "SYSTEM", "STATISTICS", "INDEX_QUALIFIER", SCOL_VARCHAR, 255 }, - { "SYSTEM", "STATISTICS", "INDEX_NAME", SCOL_VARCHAR, 255 }, - { "SYSTEM", "STATISTICS", "TYPE", SQL_SMALLINT, 50 }, - { "SYSTEM", "STATISTICS", "ORDINAL_POSITION", SQL_SMALLINT, 50 }, - { "SYSTEM", "STATISTICS", "COLUMN_NAME", SCOL_VARCHAR, 255 }, - { "SYSTEM", "STATISTICS", "ASC_OR_DESC", SCOL_CHAR, 1 }, - { "SYSTEM", "STATISTICS", "CARDINALITY", SQL_INTEGER, 50 }, - { "SYSTEM", "STATISTICS", "PAGES", SQL_INTEGER, 50 }, - { "SYSTEM", "STATISTICS", "FILTER_CONDITION", SCOL_VARCHAR, 255 } - }; /** * Internal return statistic information on table indices. --- 11979,11984 ---- *************** *** 11973,11984 **** SQLCHAR *table, SQLSMALLINT tableLen, SQLUSMALLINT itype, SQLUSMALLINT resv) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvstatistics(stmt, cat, catLen, schema, schemaLen, ! table, tableLen, itype, resv); HSTMT_UNLOCK(stmt); return ret; } #endif --- 12240,12277 ---- SQLCHAR *table, SQLSMALLINT tableLen, SQLUSMALLINT itype, SQLUSMALLINT resv) { + char *c = NULL, *s = NULL, *t = NULL; SQLRETURN ret; HSTMT_LOCK(stmt); ! if (cat) { ! c = wmb_to_utf(cat, catLen); ! if (!c) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (schema) { ! s = wmb_to_utf(schema, schemaLen); ! if (!s) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! if (table) { ! t = wmb_to_utf(table, tableLen); ! if (!t) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! } ! ret = drvstatistics(stmt, (SQLCHAR *) c, SQL_NTS, (SQLCHAR *) s, SQL_NTS, ! (SQLCHAR *) t, SQL_NTS, itype, resv); ! done: HSTMT_UNLOCK(stmt); + uc_free(t); + uc_free(s); + uc_free(c); return ret; } #endif *************** *** 14137,14145 **** SQLPrepare(SQLHSTMT stmt, SQLCHAR *query, SQLINTEGER queryLen) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvprepare(stmt, query, queryLen); HSTMT_UNLOCK(stmt); return ret; } --- 14430,14445 ---- SQLPrepare(SQLHSTMT stmt, SQLCHAR *query, SQLINTEGER queryLen) { SQLRETURN ret; + char *q = wmb_to_utf(query, queryLen); HSTMT_LOCK(stmt); ! if (!q) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! ret = drvprepare(stmt, (SQLCHAR *) q, SQL_NTS); ! uc_free(q); ! done: HSTMT_UNLOCK(stmt); return ret; } *************** *** 14203,14214 **** SQLExecDirect(SQLHSTMT stmt, SQLCHAR *query, SQLINTEGER queryLen) { SQLRETURN ret; HSTMT_LOCK(stmt); ! ret = drvprepare(stmt, query, queryLen); if (ret == SQL_SUCCESS) { ret = drvexecute(stmt, 1); } HSTMT_UNLOCK(stmt); return ret; } --- 14503,14521 ---- SQLExecDirect(SQLHSTMT stmt, SQLCHAR *query, SQLINTEGER queryLen) { SQLRETURN ret; + char *q = wmb_to_utf(query, queryLen); HSTMT_LOCK(stmt); ! if (!q) { ! ret = nomem((STMT *) stmt); ! goto done; ! } ! ret = drvprepare(stmt, (SQLCHAR *) q, SQL_NTS); ! uc_free(q); if (ret == SQL_SUCCESS) { ret = drvexecute(stmt, 1); } + done: HSTMT_UNLOCK(stmt); return ret; }