[patch] odbc without W
Nirgal <[email protected]> Thu, 25 Aug 2011 19:28:50 +0000
| Newsgroups | gmane.comp.db.mdb-tools.devel |
|---|---|
| Message-ID | <[email protected]> |
I had a look at the recent changes in odbc, and could finally test it. I encountered a batch of problems with the unicode functions: Some clients like pyodbc really don't like the fact that some wide functions are missing: It wants all of them or none of them. Also, the code assume we are a little endian platform, with a lot casts of pointer to numbers of different sizes. The patch attached enclose the W functions in a #ifdef ENABLE_ODBC_W that is *disabled* by default. I'm affraid we'll get too many problems otherwise. It also fixed some of the problems if you enable the macro. Does anyone know how to add some nice parameters to libtools? Right now, you need to add a -D to compile flags if you want wide odbc. Utf8 is usually enough IMHO. ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ mdbtools-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mdbtools-dev
odbc.diff
(text/x-patch, 37.1 KB)
Description:
Remove many warnings
Remove SQLfunction_ when SQLfunction is identical
Added SQLErrorW
Index: mdbtools-0.6pre1/src/odbc/odbc.c
===================================================================
--- mdbtools-0.6pre1.orig/src/odbc/odbc.c
+++ mdbtools-0.6pre1/src/odbc/odbc.c
@@ -27,12 +27,19 @@
#include "connectparams.h"
+//#define TRACE(x) fprintf(stderr,"Function %s\n", x);
+#define TRACE(x)
+
+//#define ENABLE_ODBC_W
+
+#ifdef ENABLE_ODBC_W
static iconv_t iconv_in,iconv_out;
+#endif //ENABLE_ODBC_W
static SQLSMALLINT _odbc_get_client_type(int srv_type);
static int _odbc_fix_literals(struct _hstmt *stmt);
-static int _odbc_get_server_type(int clt_type);
-static int _odbc_get_string_size(int size, char *str);
+//static int _odbc_get_server_type(int clt_type);
+static int _odbc_get_string_size(int size, SQLCHAR FAR *str);
static SQLRETURN SQL_API _SQLAllocConnect(SQLHENV henv, SQLHDBC FAR *phdbc);
static SQLRETURN SQL_API _SQLAllocEnv(SQLHENV FAR *phenv);
static SQLRETURN SQL_API _SQLAllocStmt(SQLHDBC hdbc, SQLHSTMT FAR *phstmt);
@@ -51,9 +58,6 @@
static char lastError[_MAX_ERROR_LEN+1];
static char sqlState[6];
-//#define TRACE(x) fprintf(stderr,"Function %s\n", x);
-#define TRACE(x)
-
typedef struct {
SQLCHAR *type_name;
SQLSMALLINT data_type;
@@ -93,12 +97,38 @@
#define NUM_TYPE_INFO_COLS 19
#define MAX_TYPE_INFO 11
+#ifdef ENABLE_ODBC_W
void __attribute__ ((constructor)) my_init(){
- iconv_out = iconv_open("UCS-2LE", "UTF-8");
- iconv_in = iconv_open("UTF-8", "UCS-2LE");
+ TRACE("my_init");
+ int endian = 1;
+ const char* wcharset;
+ if (sizeof(SQLWCHAR) == 2)
+ if (*(char*)&endian == 1)
+ wcharset = "UCS-2LE";
+ else
+ wcharset = "UCS-2BE";
+ else if (sizeof(SQLWCHAR) == 4)
+ if (*(char*)&endian == 1)
+ wcharset = "UCS-4LE";
+ else
+ wcharset = "UCS-4BE";
+ else
+ fprintf(stderr, "Unsupported SQLWCHAR width %d\n", sizeof(SQLWCHAR));
+
+ //fprintf(stderr, "SQLWCHAR width %d\n", sizeof(SQLWCHAR));
+/*
+#if __SIZEOF_WCHAR_T__ == 4 || __WCHAR_MAX__ > 0x10000
+ #define WCHAR_CHARSET "UCS-4LE"
+#else
+ #define WCHAR_CHARSET "UCS-2LE"
+#endif
+*/
+ iconv_out = iconv_open(wcharset, "UTF-8");
+ iconv_in = iconv_open("UTF-8", wcharset);
}
void __attribute__ ((destructor)) my_fini(){
+ TRACE("my_fini");
if(iconv_out != (iconv_t)-1)iconv_close(iconv_out);
if(iconv_in != (iconv_t)-1)iconv_close(iconv_in);
}
@@ -120,8 +150,12 @@
}
int sqlwlen(SQLWCHAR *p){
- int r=0;for(;*p;r++)p++;return r;
+ int r=0;
+ for(;*p;r++)
+ p++;
+ return r;
}
+#endif // ENABLE_ODBC_W
/* The SQL engine is presently non-reenterrant and non-thread safe.
See _SQLExecute for details.
@@ -148,20 +182,18 @@
static SQLRETURN do_connect (
SQLHDBC hdbc,
- SQLCHAR FAR *database
-)
+ char *database)
{
- struct _hdbc *dbc = (struct _hdbc *) hdbc;
- struct _henv *env = (struct _henv *) dbc->henv;
+ struct _hdbc *dbc = (struct _hdbc *) hdbc;
+ struct _henv *env = (struct _henv *) dbc->henv;
- if (mdb_sql_open(env->sql,database)) {
- return SQL_SUCCESS;
- } else {
- return SQL_ERROR;
- }
+ if (mdb_sql_open(env->sql, database))
+ return SQL_SUCCESS;
+ else
+ return SQL_ERROR;
}
-SQLRETURN SQL_API SQLDriverConnect_(
+SQLRETURN SQL_API SQLDriverConnect(
SQLHDBC hdbc,
SQLHWND hwnd,
SQLCHAR FAR *szConnStrIn,
@@ -171,8 +203,8 @@
SQLSMALLINT FAR *pcbConnStrOut,
SQLUSMALLINT fDriverCompletion)
{
- SQLCHAR FAR* dsn = NULL;
- SQLCHAR FAR* database = NULL;
+ char* dsn = NULL;
+ char* database = NULL;
ConnectParams* params;
SQLRETURN ret;
@@ -181,12 +213,12 @@
params = ((ODBCConnection*) hdbc)->params;
- if (dsn = ExtractDSN (params, szConnStrIn)){
+ if ((dsn = ExtractDSN (params, (gchar*)szConnStrIn))) {
if (!LookupDSN (params, dsn)){
LogError ("Could not find DSN in odbc.ini");
return SQL_ERROR;
}
- SetConnectString (params, szConnStrIn);
+ SetConnectString (params, (gchar*)szConnStrIn);
if (!(database = GetConnectParam (params, "Database"))){
LogError ("Could not find Database parameter");
return SQL_ERROR;
@@ -194,7 +226,7 @@
ret = do_connect (hdbc, database);
return ret;
}
- if (database = ExtractDBQ (params, szConnStrIn)){
+ if ((database = ExtractDBQ (params, (gchar*)szConnStrIn))) {
ret = do_connect (hdbc, database);
return ret;
}
@@ -202,19 +234,7 @@
return SQL_ERROR;
}
-SQLRETURN SQL_API SQLDriverConnect(
- SQLHDBC hdbc,
- SQLHWND hwnd,
- SQLCHAR FAR *szConnStrIn,
- SQLSMALLINT cbConnStrIn,
- SQLCHAR FAR *szConnStrOut,
- SQLSMALLINT cbConnStrOutMax,
- SQLSMALLINT FAR *pcbConnStrOut,
- SQLUSMALLINT fDriverCompletion)
-{
- return SQLDriverConnect_(hdbc,hwnd,szConnStrIn,cbConnStrIn,szConnStrOut,cbConnStrOutMax,pcbConnStrOut,fDriverCompletion);
-}
-
+#ifdef ENABLE_ODBC_W
SQLRETURN SQL_API SQLDriverConnectW(
SQLHDBC hdbc,
SQLHWND hwnd,
@@ -228,15 +248,21 @@
if(cbConnStrIn==SQL_NTS)
cbConnStrIn=sqlwlen(szConnStrIn);
{
- SQLCHAR *tmp=calloc(cbConnStrIn*4,1);
- int l=cbConnStrIn*4,z=cbConnStrIn*2;
+ unsigned int l = cbConnStrIn*sizeof(SQLWCHAR), z = (cbConnStrIn+1)*3;
+ SQLCHAR *tmp = malloc(z);
SQLRETURN ret;
- unicode2ascii(szConnStrIn, &z, tmp, &l);
- ret=SQLDriverConnect_(hdbc,hwnd,tmp,l,NULL,0,pcbConnStrOut,fDriverCompletion);
+ unicode2ascii((char*)szConnStrIn, &l, (char*)tmp, &z);
+ tmp[z] = 0;
+ ret=SQLDriverConnect(hdbc,hwnd,tmp,SQL_NTS,NULL,0,pcbConnStrOut,fDriverCompletion);
free(tmp);
+ if (szConnStrOut && cbConnStrOutMax>0)
+ szConnStrOut[0] = 0;
+ if (pcbConnStrOut)
+ *pcbConnStrOut = 0;
return ret;
}
}
+#endif // ENABLE_ODBC_W
SQLRETURN SQL_API SQLBrowseConnect(
SQLHDBC hdbc,
@@ -284,9 +310,9 @@
SQLULEN *pcrow,
SQLUSMALLINT FAR *rgfRowStatus)
{
-struct _hstmt *stmt = (struct _hstmt *) hstmt;
-struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
-struct _henv *env = (struct _henv *) dbc->henv;
+ struct _hstmt *stmt = (struct _hstmt *) hstmt;
+ struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
+ struct _henv *env = (struct _henv *) dbc->henv;
TRACE("SQLExtendedFetch");
if (fFetchType!=SQL_FETCH_NEXT) {
@@ -463,17 +489,17 @@
SQLLEN cbValueMax,
SQLLEN FAR *pcbValue)
{
-struct _hstmt *stmt;
+ /*struct _hstmt *stmt;*/
TRACE("SQLBindParameter");
- stmt = (struct _hstmt *) hstmt;
+ /*stmt = (struct _hstmt *) hstmt;*/
return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLAllocHandle(
- SQLSMALLINT HandleType,
- SQLHANDLE InputHandle,
- SQLHANDLE * OutputHandle)
+ SQLSMALLINT HandleType,
+ SQLHANDLE InputHandle,
+ SQLHANDLE * OutputHandle)
{
TRACE("SQLAllocHandle");
switch(HandleType) {
@@ -536,11 +562,11 @@
SQLHDBC hdbc,
SQLHSTMT FAR *phstmt)
{
-struct _hdbc *dbc;
-struct _hstmt *stmt;
+ /*struct _hdbc *dbc;*/
+ struct _hstmt *stmt;
TRACE("_SQLAllocStmt");
- dbc = (struct _hdbc *) hdbc;
+ /*dbc = (struct _hdbc *) hdbc;*/
stmt = (SQLHSTMT) g_malloc0(sizeof(struct _hstmt));
stmt->hdbc=hdbc;
@@ -611,7 +637,7 @@
return SQL_SUCCESS;
}
-SQLRETURN SQL_API SQLConnect_(
+SQLRETURN SQL_API SQLConnect(
SQLHDBC hdbc,
SQLCHAR FAR *szDSN,
SQLSMALLINT cbDSN,
@@ -620,44 +646,33 @@
SQLCHAR FAR *szAuthStr,
SQLSMALLINT cbAuthStr)
{
- SQLCHAR FAR* database = NULL;
- ConnectParams* params;
- SQLRETURN ret;
+ char* database = NULL;
+ ConnectParams* params;
+ SQLRETURN ret;
TRACE("SQLConnect");
- strcpy (lastError, "");
-
- params = ((ODBCConnection*) hdbc)->params;
+ strcpy (lastError, "");
- params->dsnName = g_string_assign (params->dsnName, szDSN);
+ params = ((ODBCConnection*) hdbc)->params;
- if (!LookupDSN (params, szDSN))
- {
- LogError ("Could not find DSN in odbc.ini");
- return SQL_ERROR;
- }
- else if (!(database = GetConnectParam (params, "Database")))
- {
- LogError ("Could not find Database parameter");
- return SQL_ERROR;
- }
+ params->dsnName = g_string_assign (params->dsnName, (gchar*)szDSN);
- ret = do_connect (hdbc, database);
- return ret;
-}
+ if (!LookupDSN (params, (gchar*)szDSN))
+ {
+ LogError ("Could not find DSN in odbc.ini");
+ return SQL_ERROR;
+ }
+ else if (!(database = GetConnectParam (params, "Database")))
+ {
+ LogError ("Could not find Database parameter");
+ return SQL_ERROR;
+ }
-SQLRETURN SQL_API SQLConnect(
- SQLHDBC hdbc,
- SQLCHAR FAR *szDSN,
- SQLSMALLINT cbDSN,
- SQLCHAR FAR *szUID,
- SQLSMALLINT cbUID,
- SQLCHAR FAR *szAuthStr,
- SQLSMALLINT cbAuthStr)
-{
- return SQLConnect_(hdbc,szDSN,cbDSN,szUID,cbUID,szAuthStr,cbAuthStr);
+ ret = do_connect (hdbc, database);
+ return ret;
}
+#ifdef ENABLE_ODBC_W
SQLRETURN SQL_API SQLConnectW(
SQLHDBC hdbc,
SQLWCHAR FAR *szDSN,
@@ -672,20 +687,21 @@
if(cbAuthStr==SQL_NTS)cbAuthStr=sqlwlen(szAuthStr);
{
SQLCHAR *tmp1=calloc(cbDSN*4,1),*tmp2=calloc(cbUID*4,1),*tmp3=calloc(cbAuthStr*4,1);
- int l1=cbDSN*4,z1=cbDSN*2;
- int l2=cbUID*4,z2=cbUID*2;
- int l3=cbAuthStr*4,z3=cbAuthStr*2;
+ unsigned int l1=cbDSN*4,z1=cbDSN*2;
+ unsigned int l2=cbUID*4,z2=cbUID*2;
+ unsigned int l3=cbAuthStr*4,z3=cbAuthStr*2;
SQLRETURN ret;
- unicode2ascii(szDSN, &z1, tmp1, &l1);
- unicode2ascii(szUID, &z2, tmp2, &l2);
- unicode2ascii(szAuthStr, &z3, tmp3, &l3);
- ret=SQLConnect_(hdbc,tmp1,l1,tmp2,l2,tmp3,l3);
+ unicode2ascii((char*)szDSN, &z1, (char*)tmp1, &l1);
+ unicode2ascii((char*)szUID, &z2, (char*)tmp2, &l2);
+ unicode2ascii((char*)szAuthStr, &z3, (char*)tmp3, &l3);
+ ret=SQLConnect(hdbc,tmp1,l1,tmp2,l2,tmp3,l3);
free(tmp1),free(tmp2),free(tmp3);
return ret;
}
}
+#endif //ENABLE_ODBC_W
-SQLRETURN SQL_API SQLDescribeCol_(
+SQLRETURN SQL_API SQLDescribeCol(
SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLCHAR FAR *szColName,
@@ -709,20 +725,20 @@
if (icol<1 || icol>sql->num_columns) {
return SQL_ERROR;
}
- sqlcol = g_ptr_array_index(sql->columns,icol - 1);
+ sqlcol = g_ptr_array_index(sql->columns,icol - 1);
table = sql->cur_table;
- for (i=0;i<table->num_cols;i++) {
- col=g_ptr_array_index(table->columns,i);
- if (!strcasecmp(sqlcol->name, col->name)) {
+ for (i=0;i<table->num_cols;i++) {
+ col=g_ptr_array_index(table->columns,i);
+ if (!strcasecmp(sqlcol->name, col->name)) {
break;
- }
- }
+ }
+ }
if (szColName) {
namelen = MIN(cbColNameMax,strlen(sqlcol->name));
- strncpy(szColName, sqlcol->name, namelen);
+ strncpy((char*)szColName, sqlcol->name, namelen);
szColName[namelen]='\0';
- *pcbColName=namelen;
+ *pcbColName=namelen;
}
if (pfSqlType) { //Currently libmdbodbc.so returns values as string in SQLGetData() even though it is a number.
*pfSqlType = SQL_VARCHAR;//_odbc_get_client_type(col->col_type);
@@ -741,20 +757,7 @@
return SQL_SUCCESS;
}
-SQLRETURN SQL_API SQLDescribeCol(
- SQLHSTMT hstmt,
- SQLUSMALLINT icol,
- SQLCHAR FAR *szColName,
- SQLSMALLINT cbColNameMax,
- SQLSMALLINT FAR *pcbColName,
- SQLSMALLINT FAR *pfSqlType,
- SQLUINTEGER FAR *pcbColDef, /* precision */
- SQLSMALLINT FAR *pibScale,
- SQLSMALLINT FAR *pfNullable)
-{
- return SQLDescribeCol_(hstmt,icol,szColName,cbColNameMax,pcbColName,pfSqlType,pcbColDef,pibScale,pfNullable);
-}
-
+#ifdef ENABLE_ODBC_W
SQLRETURN SQL_API SQLDescribeColW(
SQLHSTMT hstmt,
SQLUSMALLINT icol,
@@ -770,16 +773,17 @@
cbColNameMax=sqlwlen(szColName);
{
SQLCHAR *tmp=calloc(cbColNameMax*4,1);
- int l=cbColNameMax*4;
- SQLRETURN ret=SQLDescribeCol_(hstmt,icol,tmp,cbColNameMax*4,&l,pfSqlType,pcbColDef,pibScale,pfNullable);
- ascii2unicode(tmp, &l, szColName, pcbColName);
- *pcbColName/=2;
+ unsigned int l=cbColNameMax*4;
+ SQLRETURN ret=SQLDescribeCol(hstmt,icol,tmp,cbColNameMax*4,&l,pfSqlType,pcbColDef,pibScale,pfNullable);
+ ascii2unicode((char*)tmp, &l, (char*)szColName, pcbColName);
+ *pcbColName/=sizeof(SQLWCHAR);
free(tmp);
return ret;
}
}
+#endif //ENABLE_ODBC_W
-SQLRETURN SQL_API SQLColAttributes_(
+SQLRETURN SQL_API SQLColAttributes(
SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLUSMALLINT fDescType,
@@ -845,18 +849,7 @@
return SQL_SUCCESS;
}
-SQLRETURN SQL_API SQLColAttributes(
- SQLHSTMT hstmt,
- SQLUSMALLINT icol,
- SQLUSMALLINT fDescType,
- SQLPOINTER rgbDesc,
- SQLSMALLINT cbDescMax,
- SQLSMALLINT FAR *pcbDesc,
- SQLINTEGER FAR *pfDesc)
-{
- return SQLColAttributes_(hstmt,icol,fDescType,rgbDesc,cbDescMax,pcbDesc,pfDesc);
-}
-
+#ifdef ENABLE_ODBC_W
SQLRETURN SQL_API SQLColAttributesW(
SQLHSTMT hstmt,
SQLUSMALLINT icol,
@@ -866,18 +859,19 @@
SQLSMALLINT FAR *pcbDesc,
SQLINTEGER FAR *pfDesc)
{
- if(fDescType!=SQL_COLUMN_NAME&&fDescType!=SQL_COLUMN_LABEL)
- return SQLColAttributes_(hstmt,icol,fDescType,rgbDesc,cbDescMax,pcbDesc,pfDesc);
+ if (fDescType!=SQL_COLUMN_NAME && fDescType!=SQL_COLUMN_LABEL)
+ return SQLColAttributes(hstmt,icol,fDescType,rgbDesc,cbDescMax,pcbDesc,pfDesc);
else{
SQLCHAR *tmp=calloc(cbDescMax*4,1);
- int l=cbDescMax*4;
- SQLRETURN ret=SQLColAttributes_(hstmt,icol,fDescType,tmp,cbDescMax*4,l,pfDesc);
- ascii2unicode(tmp, &l, rgbDesc, pcbDesc);
- *pcbDesc/=2;
+ unsigned int l=cbDescMax*4;
+ SQLRETURN ret=SQLColAttributes(hstmt,icol,fDescType,tmp,cbDescMax*4,l,pfDesc);
+ ascii2unicode((char*)tmp, &l, (char*)rgbDesc, pcbDesc);
+ *pcbDesc/=sizeof(SQLWCHAR);
free(tmp);
return ret;
}
}
+#endif //ENABLE_ODBC_W
SQLRETURN SQL_API SQLDisconnect(
SQLHDBC hdbc)
@@ -904,25 +898,56 @@
SQLSMALLINT cbErrorMsgMax,
SQLSMALLINT FAR *pcbErrorMsg)
{
- SQLRETURN result = SQL_NO_DATA_FOUND;
+ SQLRETURN result = SQL_NO_DATA_FOUND;
TRACE("SQLError");
- if (strlen (lastError) > 0)
- {
- strcpy (szSqlState, "08001");
- strcpy (szErrorMsg, lastError);
- if (pcbErrorMsg)
- *pcbErrorMsg = strlen (lastError);
- if (pfNativeError)
- *pfNativeError = 1;
-
- result = SQL_SUCCESS;
- strcpy (lastError, "");
- }
+ if (strlen (lastError) > 0)
+ {
+ strcpy ((char*)szSqlState, "08001");
+ strcpy ((char*)szErrorMsg, lastError);
+ if (pcbErrorMsg)
+ *pcbErrorMsg = strlen (lastError);
+ if (pfNativeError)
+ *pfNativeError = 1;
+
+ result = SQL_SUCCESS;
+ strcpy (lastError, "");
+ }
- return result;
+ return result;
}
+#ifdef ENABLE_ODBC_W
+SQLRETURN SQL_API SQLErrorW(
+ SQLHENV henv,
+ SQLHDBC hdbc,
+ SQLHSTMT hstmt,
+ SQLWCHAR FAR *szSqlState,
+ SQLINTEGER FAR *pfNativeError,
+ SQLWCHAR FAR *szErrorMsg,
+ SQLSMALLINT cbErrorMsgMax,
+ SQLSMALLINT FAR *pcbErrorMsg)
+{
+ SQLCHAR szSqlState8[6];
+ SQLCHAR szErrorMsg8[3*cbErrorMsgMax+1];
+ SQLSMALLINT pcbErrorMsg8;
+ SQLRETURN result;
+
+ TRACE("SQLErrorW");
+
+ result = SQLError(henv, hdbc, hstmt, szSqlState8, pfNativeError, szErrorMsg8, 3*cbErrorMsgMax+1, &pcbErrorMsg8);
+ if (result == SQL_SUCCESS) {
+ unsigned int l=6, z=6*sizeof(SQLWCHAR);
+ ascii2unicode((char*)szSqlState8, &l, (char*)szSqlState, &z);
+ l = cbErrorMsgMax;
+ ascii2unicode((char*)szErrorMsg8, (unsigned int*)&pcbErrorMsg8, (char*)szErrorMsg, &l);
+ if (pcbErrorMsg)
+ *pcbErrorMsg = l;
+ }
+ return result;
+}
+#endif // ENABLE_ODBC_W
+
static SQLRETURN SQL_API _SQLExecute( SQLHSTMT hstmt)
{
struct _hstmt *stmt = (struct _hstmt *) hstmt;
@@ -931,27 +956,27 @@
TRACE("_SQLExecute");
- /* fprintf(stderr,"query = %s\n",stmt->query); */
- _odbc_fix_literals(stmt);
+ /* fprintf(stderr,"query = %s\n",stmt->query); */
+ _odbc_fix_literals(stmt);
- mdb_sql_reset(env->sql);
+ mdb_sql_reset(env->sql);
- /* calls to yyparse would need to be serialized for thread safety */
+ /* calls to yyparse would need to be serialized for thread safety */
- /* begin unsafe */
- g_input_ptr = stmt->query;
- _mdb_sql(env->sql);
- if (yyparse()) {
- /* end unsafe */
- LogError("Couldn't parse SQL\n");
- mdb_sql_reset(env->sql);
- return SQL_ERROR;
- } else {
- return SQL_SUCCESS;
- }
+ /* begin unsafe */
+ g_input_ptr = stmt->query;
+ _mdb_sql(env->sql);
+ if (yyparse()) {
+ /* end unsafe */
+ LogError("Couldn't parse SQL\n");
+ mdb_sql_reset(env->sql);
+ return SQL_ERROR;
+ } else {
+ return SQL_SUCCESS;
+ }
}
-SQLRETURN SQL_API SQLExecDirect_(
+SQLRETURN SQL_API SQLExecDirect(
SQLHSTMT hstmt,
SQLCHAR FAR *szSqlStr,
SQLINTEGER cbSqlStr)
@@ -959,19 +984,12 @@
struct _hstmt *stmt = (struct _hstmt *) hstmt;
TRACE("SQLExecDirect");
- strcpy(stmt->query, szSqlStr);
+ strcpy(stmt->query, (char*)szSqlStr);
return _SQLExecute(hstmt);
}
-SQLRETURN SQL_API SQLExecDirect(
- SQLHSTMT hstmt,
- SQLCHAR FAR *szSqlStr,
- SQLINTEGER cbSqlStr)
-{
- return SQLExecDirect_(hstmt,szSqlStr,cbSqlStr);
-}
-
+#ifdef ENABLE_ODBC_W
SQLRETURN SQL_API SQLExecDirectW(
SQLHSTMT hstmt,
SQLWCHAR FAR *szSqlStr,
@@ -981,59 +999,62 @@
cbSqlStr=sqlwlen(szSqlStr);
{
SQLCHAR *tmp=calloc(cbSqlStr*4,1);
- int l=cbSqlStr*4,z=cbSqlStr*2;
+ unsigned int l=cbSqlStr*4,z=cbSqlStr*2;
SQLRETURN ret;
- unicode2ascii(szSqlStr, &z, tmp, &l);
- ret=SQLExecDirect_(hstmt,tmp,l);
+ unicode2ascii((char*)szSqlStr, &z, (char*)tmp, &l);
+ ret=SQLExecDirect(hstmt,tmp,l);
free(tmp);
return ret;
}
}
+#endif // ENABLE_ODBC_W
SQLRETURN SQL_API SQLExecute(
SQLHSTMT hstmt)
{
TRACE("SQLExecute");
- return _SQLExecute(hstmt);
+ return _SQLExecute(hstmt);
}
+
static void
bind_columns(struct _hstmt *stmt)
{
-struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
-struct _henv *env = (struct _henv *) dbc->henv;
-struct _sql_bind_info *cur;
-
- if (stmt->rows_affected==0) {
- cur = stmt->bind_head;
- while (cur) {
- if (cur->column_number>0 &&
- cur->column_number <= env->sql->num_columns) {
- mdb_sql_bind_column(env->sql, cur->column_number,
- cur->varaddr, cur->column_lenbind);
- } else {
- /* log error ? */
- }
- cur = cur->next;
- }
- }
+ struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
+ struct _henv *env = (struct _henv *) dbc->henv;
+ struct _sql_bind_info *cur;
+
+ if (stmt->rows_affected==0) {
+ cur = stmt->bind_head;
+ while (cur) {
+ if (cur->column_number>0 &&
+ cur->column_number <= env->sql->num_columns) {
+ mdb_sql_bind_column(env->sql, cur->column_number,
+ cur->varaddr, cur->column_lenbind);
+ } else {
+ /* log error ? */
+ }
+ cur = cur->next;
+ }
+ }
}
+
SQLRETURN SQL_API SQLFetch(
SQLHSTMT hstmt)
{
-struct _hstmt *stmt = (struct _hstmt *) hstmt;
-struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
-struct _henv *env = (struct _henv *) dbc->henv;
+ struct _hstmt *stmt = (struct _hstmt *) hstmt;
+ struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
+ struct _henv *env = (struct _henv *) dbc->henv;
TRACE("SQLFetch");
- /* if we bound columns, transfer them to res_info now that we have one */
+ /* if we bound columns, transfer them to res_info now that we have one */
bind_columns(stmt);
- //cur = stmt->bind_head;
- //while (cur) {
- //if (cur->column_number>0 &&
- //cur->column_number <= env->sql->num_columns) {
+ //cur = stmt->bind_head;
+ //while (cur) {
+ //if (cur->column_number>0 &&
+ //cur->column_number <= env->sql->num_columns) {
// if (cur->column_lenbind) *(cur->column_lenbind) = 4;
//}
- //cur = cur->next;
+ //cur = cur->next;
//}
if (mdb_fetch_row(env->sql->cur_table)) {
@@ -1045,8 +1066,8 @@
}
SQLRETURN SQL_API SQLFreeHandle(
- SQLSMALLINT HandleType,
- SQLHANDLE Handle)
+ SQLSMALLINT HandleType,
+ SQLHANDLE Handle)
{
TRACE("SQLFreeHandle");
switch(HandleType) {
@@ -1066,14 +1087,14 @@
static SQLRETURN SQL_API _SQLFreeConnect(
SQLHDBC hdbc)
{
- ODBCConnection* dbc = (ODBCConnection*) hdbc;
+ ODBCConnection* dbc = (ODBCConnection*) hdbc;
TRACE("_SQLFreeConnect");
- FreeConnectParams(dbc->params);
- g_free(dbc);
+ FreeConnectParams(dbc->params);
+ g_free(dbc);
- return SQL_SUCCESS;
+ return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLFreeConnect(
SQLHDBC hdbc)
@@ -1129,7 +1150,7 @@
SQLINTEGER * StringLength)
{
TRACE("SQLGetStmtAttr");
- return SQL_SUCCESS;
+ return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLGetCursorName(
@@ -1146,9 +1167,9 @@
SQLHSTMT hstmt,
SQLSMALLINT FAR *pccol)
{
-struct _hstmt *stmt = (struct _hstmt *) hstmt;
-struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
-struct _henv *env = (struct _henv *) dbc->henv;
+ struct _hstmt *stmt = (struct _hstmt *) hstmt;
+ struct _hdbc *dbc = (struct _hdbc *) stmt->hdbc;
+ struct _henv *env = (struct _henv *) dbc->henv;
TRACE("SQLNumResultCols");
*pccol = env->sql->num_columns;
@@ -1165,7 +1186,7 @@
TRACE("SQLPrepare");
- strncpy(stmt->query, szSqlStr, sqllen);
+ strncpy(stmt->query, (char*)szSqlStr, sqllen);
stmt->query[sqllen]='\0';
return SQL_SUCCESS;
@@ -1215,7 +1236,7 @@
return SQL_SUCCESS;
}
-SQLRETURN SQL_API SQLColumns_(
+SQLRETURN SQL_API SQLColumns(
SQLHSTMT hstmt,
SQLCHAR FAR *szCatalogName,
SQLSMALLINT cbCatalogName,
@@ -1276,16 +1297,16 @@
for (i=0; i<mdb->num_catalog; i++) {
entry = g_ptr_array_index(mdb->catalog, i);
/* TODO: Do more advanced matching */
- if (strcasecmp(szTableName, entry->object_name) != 0)
+ if (strcasecmp((char*)szTableName, entry->object_name) != 0)
continue;
table = mdb_read_table(entry);
mdb_read_columns(table);
for (j=0; j<table->num_cols; j++) {
col = g_ptr_array_index(table->columns, j);
- ts2 = mdb_ascii2unicode(mdb, table->name, 0, t2, MDB_BIND_SIZE);
- ts3 = mdb_ascii2unicode(mdb, col->name, 0, t3, MDB_BIND_SIZE);
- ts5 = mdb_ascii2unicode(mdb, "FIX ME", 0, t5, MDB_BIND_SIZE);
+ ts2 = mdb_ascii2unicode(mdb, table->name, 0, (char*)t2, MDB_BIND_SIZE);
+ ts3 = mdb_ascii2unicode(mdb, col->name, 0, (char*)t3, MDB_BIND_SIZE);
+ ts5 = mdb_ascii2unicode(mdb, "FIX ME", 0, (char*)t5, MDB_BIND_SIZE);
nullable = SQL_NO_NULLS;
datatype = _odbc_get_client_type(col->col_type);
sqldatatype = _odbc_get_client_type(col->col_type);
@@ -1315,20 +1336,7 @@
return SQL_SUCCESS;
}
-SQLRETURN SQL_API SQLColumns(
- SQLHSTMT hstmt,
- SQLCHAR FAR *szCatalogName,
- SQLSMALLINT cbCatalogName,
- SQLCHAR FAR *szSchemaName,
- SQLSMALLINT cbSchemaName,
- SQLCHAR FAR *szTableName,
- SQLSMALLINT cbTableName,
- SQLCHAR FAR *szColumnName,
- SQLSMALLINT cbColumnName)
-{
- return SQLColumns_(hstmt,szCatalogName,cbCatalogName,szSchemaName,cbSchemaName,szTableName,cbTableName,szColumnName,cbColumnName);
-}
-
+#ifdef ENABLE_ODBC_W
SQLRETURN SQL_API SQLColumnsW(
SQLHSTMT hstmt,
SQLWCHAR FAR *szCatalogName,
@@ -1343,14 +1351,15 @@
if(cbTableName==SQL_NTS)cbTableName=sqlwlen(szTableName);
{
SQLCHAR *tmp=calloc(cbTableName*4,1);
- int l=cbTableName*4,z=cbTableName*2;
+ unsigned int l=cbTableName*4,z=cbTableName*2;
SQLRETURN ret;
- unicode2ascii(szTableName, &z, tmp, &l);
- ret=SQLColumns_(hstmt,NULL,0,NULL,0,tmp,l,NULL,0);
+ unicode2ascii((char*)szTableName, &z, (char*)tmp, &l);
+ ret=SQLColumns(hstmt,NULL,0,NULL,0,tmp,l,NULL,0);
free(tmp);
return ret;
}
}
+#endif //ENABLE_ODBC_W
SQLRETURN SQL_API SQLGetConnectOption(
SQLHDBC hdbc,
@@ -1361,7 +1370,7 @@
return SQL_SUCCESS;
}
-SQLRETURN SQL_API SQLGetData_(
+SQLRETURN SQL_API SQLGetData(
SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLSMALLINT fCType,
@@ -1440,17 +1449,7 @@
return SQL_SUCCESS;
}
-SQLRETURN SQL_API SQLGetData(
- SQLHSTMT hstmt,
- SQLUSMALLINT icol,
- SQLSMALLINT fCType,
- SQLPOINTER rgbValue,
- SQLINTEGER cbValueMax,
- SQLINTEGER FAR *pcbValue)
-{
- return SQLGetData_(hstmt,icol,fCType,rgbValue,cbValueMax,pcbValue);
-}
-
+#ifdef ENABLE_ODBC_W
SQLRETURN SQL_API SQLGetDataW(
SQLHSTMT hstmt,
SQLUSMALLINT icol,
@@ -1460,21 +1459,22 @@
SQLINTEGER FAR *pcbValue)
{
SQLCHAR *tmp=calloc(cbValueMax*4,1);
- int l=cbValueMax*4;
- SQLRETURN ret=SQLGetData_(hstmt,icol,fCType,tmp,cbValueMax*4,l);
- ascii2unicode(tmp, &l, rgbValue, pcbValue);
- *pcbValue/=2;
+ unsigned int l=cbValueMax*4;
+ SQLRETURN ret=SQLGetData(hstmt,icol,fCType,tmp,cbValueMax*4,(SQLINTEGER FAR*)&l);
+ ascii2unicode((char*)tmp, &l, (char*)rgbValue, (unsigned int*)pcbValue);
+ *pcbValue/=sizeof(SQLWCHAR);
free(tmp);
return ret;
}
+#endif //ENABLE_ODBC_W
static void _set_func_exists(SQLUSMALLINT FAR *pfExists, SQLUSMALLINT fFunction)
{
-SQLUSMALLINT FAR *mod;
-
+ SQLUSMALLINT FAR *mod;
mod = pfExists + (fFunction >> 4);
*mod |= (1 << (fFunction & 0x0f));
}
+
SQLRETURN SQL_API SQLGetFunctions(
SQLHDBC hdbc,
SQLUSMALLINT fFunction,
@@ -1485,11 +1485,7 @@
switch (fFunction) {
#if ODBCVER >= 0x0300
case SQL_API_ODBC3_ALL_FUNCTIONS:
-
-/* for (i=0;i<SQL_API_ODBC3_ALL_FUNCTIONS_SIZE;i++) {
- pfExists[i] = 0xFFFF;
- }
-*/
+ bzero(pfExists, SQL_API_ODBC3_ALL_FUNCTIONS_SIZE);
_set_func_exists(pfExists,SQL_API_SQLALLOCCONNECT);
_set_func_exists(pfExists,SQL_API_SQLALLOCENV);
_set_func_exists(pfExists,SQL_API_SQLALLOCHANDLE);
@@ -1497,33 +1493,33 @@
_set_func_exists(pfExists,SQL_API_SQLBINDCOL);
_set_func_exists(pfExists,SQL_API_SQLBINDPARAMETER);
_set_func_exists(pfExists,SQL_API_SQLCANCEL);
- _set_func_exists(pfExists,SQL_API_SQLCLOSECURSOR);
+ //_set_func_exists(pfExists,SQL_API_SQLCLOSECURSOR);
_set_func_exists(pfExists,SQL_API_SQLCOLATTRIBUTE);
_set_func_exists(pfExists,SQL_API_SQLCOLUMNS);
_set_func_exists(pfExists,SQL_API_SQLCONNECT);
- _set_func_exists(pfExists,SQL_API_SQLCOPYDESC);
+ //_set_func_exists(pfExists,SQL_API_SQLCOPYDESC);
_set_func_exists(pfExists,SQL_API_SQLDATASOURCES);
_set_func_exists(pfExists,SQL_API_SQLDESCRIBECOL);
_set_func_exists(pfExists,SQL_API_SQLDISCONNECT);
- _set_func_exists(pfExists,SQL_API_SQLENDTRAN);
+ //_set_func_exists(pfExists,SQL_API_SQLENDTRAN);
_set_func_exists(pfExists,SQL_API_SQLERROR);
_set_func_exists(pfExists,SQL_API_SQLEXECDIRECT);
_set_func_exists(pfExists,SQL_API_SQLEXECUTE);
_set_func_exists(pfExists,SQL_API_SQLFETCH);
- _set_func_exists(pfExists,SQL_API_SQLFETCHSCROLL);
+ //_set_func_exists(pfExists,SQL_API_SQLFETCHSCROLL);
_set_func_exists(pfExists,SQL_API_SQLFREECONNECT);
_set_func_exists(pfExists,SQL_API_SQLFREEENV);
_set_func_exists(pfExists,SQL_API_SQLFREEHANDLE);
_set_func_exists(pfExists,SQL_API_SQLFREESTMT);
- _set_func_exists(pfExists,SQL_API_SQLGETCONNECTATTR);
+ //_set_func_exists(pfExists,SQL_API_SQLGETCONNECTATTR);
_set_func_exists(pfExists,SQL_API_SQLGETCONNECTOPTION);
_set_func_exists(pfExists,SQL_API_SQLGETCURSORNAME);
_set_func_exists(pfExists,SQL_API_SQLGETDATA);
- _set_func_exists(pfExists,SQL_API_SQLGETDESCFIELD);
- _set_func_exists(pfExists,SQL_API_SQLGETDESCREC);
- _set_func_exists(pfExists,SQL_API_SQLGETDIAGFIELD);
- _set_func_exists(pfExists,SQL_API_SQLGETDIAGREC);
- _set_func_exists(pfExists,SQL_API_SQLGETENVATTR);
+ //_set_func_exists(pfExists,SQL_API_SQLGETDESCFIELD);
+ //_set_func_exists(pfExists,SQL_API_SQLGETDESCREC);
+ //_set_func_exists(pfExists,SQL_API_SQLGETDIAGFIELD);
+ //_set_func_exists(pfExists,SQL_API_SQLGETDIAGREC);
+ //_set_func_exists(pfExists,SQL_API_SQLGETENVATTR);
_set_func_exists(pfExists,SQL_API_SQLGETFUNCTIONS);
_set_func_exists(pfExists,SQL_API_SQLGETINFO);
_set_func_exists(pfExists,SQL_API_SQLGETSTMTATTR);
@@ -1534,30 +1530,29 @@
_set_func_exists(pfExists,SQL_API_SQLPREPARE);
_set_func_exists(pfExists,SQL_API_SQLPUTDATA);
_set_func_exists(pfExists,SQL_API_SQLROWCOUNT);
- _set_func_exists(pfExists,SQL_API_SQLSETCONNECTATTR);
+ //_set_func_exists(pfExists,SQL_API_SQLSETCONNECTATTR);
_set_func_exists(pfExists,SQL_API_SQLSETCONNECTOPTION);
_set_func_exists(pfExists,SQL_API_SQLSETCURSORNAME);
- _set_func_exists(pfExists,SQL_API_SQLSETDESCFIELD);
- _set_func_exists(pfExists,SQL_API_SQLSETDESCREC);
+ //_set_func_exists(pfExists,SQL_API_SQLSETDESCFIELD);
+ //_set_func_exists(pfExists,SQL_API_SQLSETDESCREC);
_set_func_exists(pfExists,SQL_API_SQLSETENVATTR);
_set_func_exists(pfExists,SQL_API_SQLSETPARAM);
- _set_func_exists(pfExists,SQL_API_SQLSETSTMTATTR);
+ //_set_func_exists(pfExists,SQL_API_SQLSETSTMTATTR);
_set_func_exists(pfExists,SQL_API_SQLSETSTMTOPTION);
_set_func_exists(pfExists,SQL_API_SQLSPECIALCOLUMNS);
_set_func_exists(pfExists,SQL_API_SQLSTATISTICS);
_set_func_exists(pfExists,SQL_API_SQLTABLES);
_set_func_exists(pfExists,SQL_API_SQLTRANSACT);
-
- return SQL_SUCCESS;
break;
#endif
case SQL_API_ALL_FUNCTIONS:
+ bzero(pfExists, 100); // 100 by spec
_set_func_exists(pfExists,SQL_API_SQLALLOCCONNECT);
_set_func_exists(pfExists,SQL_API_SQLALLOCENV);
_set_func_exists(pfExists,SQL_API_SQLALLOCSTMT);
_set_func_exists(pfExists,SQL_API_SQLBINDCOL);
_set_func_exists(pfExists,SQL_API_SQLCANCEL);
- _set_func_exists(pfExists,SQL_API_SQLCOLATTRIBUTES);
+ _set_func_exists(pfExists,SQL_API_SQLCOLATTRIBUTE);
_set_func_exists(pfExists,SQL_API_SQLCOLUMNS);
_set_func_exists(pfExists,SQL_API_SQLCONNECT);
_set_func_exists(pfExists,SQL_API_SQLDATASOURCES);
@@ -1569,12 +1564,14 @@
_set_func_exists(pfExists,SQL_API_SQLFETCH);
_set_func_exists(pfExists,SQL_API_SQLFREECONNECT);
_set_func_exists(pfExists,SQL_API_SQLFREEENV);
+ _set_func_exists(pfExists,SQL_API_SQLFREEHANDLE);
_set_func_exists(pfExists,SQL_API_SQLFREESTMT);
_set_func_exists(pfExists,SQL_API_SQLGETCONNECTOPTION);
_set_func_exists(pfExists,SQL_API_SQLGETCURSORNAME);
_set_func_exists(pfExists,SQL_API_SQLGETDATA);
_set_func_exists(pfExists,SQL_API_SQLGETFUNCTIONS);
_set_func_exists(pfExists,SQL_API_SQLGETINFO);
+ _set_func_exists(pfExists,SQL_API_SQLGETSTMTATTR);
_set_func_exists(pfExists,SQL_API_SQLGETSTMTOPTION);
_set_func_exists(pfExists,SQL_API_SQLGETTYPEINFO);
_set_func_exists(pfExists,SQL_API_SQLNUMRESULTCOLS);
@@ -1584,17 +1581,61 @@
_set_func_exists(pfExists,SQL_API_SQLROWCOUNT);
_set_func_exists(pfExists,SQL_API_SQLSETCONNECTOPTION);
_set_func_exists(pfExists,SQL_API_SQLSETCURSORNAME);
+ _set_func_exists(pfExists,SQL_API_SQLSETENVATTR);
_set_func_exists(pfExists,SQL_API_SQLSETPARAM);
_set_func_exists(pfExists,SQL_API_SQLSETSTMTOPTION);
_set_func_exists(pfExists,SQL_API_SQLSPECIALCOLUMNS);
_set_func_exists(pfExists,SQL_API_SQLSTATISTICS);
_set_func_exists(pfExists,SQL_API_SQLTABLES);
_set_func_exists(pfExists,SQL_API_SQLTRANSACT);
- return SQL_SUCCESS;
break;
- default:
+
+ case SQL_API_SQLALLOCCONNECT:
+ case SQL_API_SQLALLOCENV:
+ case SQL_API_SQLALLOCSTMT:
+ case SQL_API_SQLBINDCOL:
+ case SQL_API_SQLCANCEL:
+ case SQL_API_SQLCOLATTRIBUTE:
+ case SQL_API_SQLCOLUMNS:
+ case SQL_API_SQLCONNECT:
+ case SQL_API_SQLDATASOURCES:
+ case SQL_API_SQLDESCRIBECOL:
+ case SQL_API_SQLDISCONNECT:
+ case SQL_API_SQLERROR:
+ case SQL_API_SQLEXECDIRECT:
+ case SQL_API_SQLEXECUTE:
+ case SQL_API_SQLFETCH:
+ case SQL_API_SQLFREECONNECT:
+ case SQL_API_SQLFREEENV:
+ case SQL_API_SQLFREEHANDLE:
+ case SQL_API_SQLFREESTMT:
+ case SQL_API_SQLGETCONNECTOPTION:
+ case SQL_API_SQLGETCURSORNAME:
+ case SQL_API_SQLGETDATA:
+ case SQL_API_SQLGETFUNCTIONS:
+ case SQL_API_SQLGETINFO:
+ case SQL_API_SQLGETSTMTATTR:
+ case SQL_API_SQLGETSTMTOPTION:
+ case SQL_API_SQLGETTYPEINFO:
+ case SQL_API_SQLNUMRESULTCOLS:
+ case SQL_API_SQLPARAMDATA:
+ case SQL_API_SQLPREPARE:
+ case SQL_API_SQLPUTDATA:
+ case SQL_API_SQLROWCOUNT:
+ case SQL_API_SQLSETCONNECTOPTION:
+ case SQL_API_SQLSETCURSORNAME:
+ case SQL_API_SQLSETENVATTR:
+ case SQL_API_SQLSETPARAM:
+ case SQL_API_SQLSETSTMTOPTION:
+ case SQL_API_SQLSPECIALCOLUMNS:
+ case SQL_API_SQLSTATISTICS:
+ case SQL_API_SQLTABLES:
+ case SQL_API_SQLTRANSACT:
*pfExists = 1; /* SQL_TRUE */
- return SQL_SUCCESS;
+ break;
+
+ default:
+ *pfExists = 0; /* SQL_FALSE */
break;
}
return SQL_SUCCESS;
@@ -1696,11 +1737,11 @@
if (fSqlType && (fSqlType != type_info[i].data_type))
continue;
- ts0 = mdb_ascii2unicode(mdb, type_info[i].type_name, 0, t0, MDB_BIND_SIZE);
- ts3 = mdb_ascii2unicode(mdb, type_info[i].literal_prefix, 0, t3, MDB_BIND_SIZE);
- ts4 = mdb_ascii2unicode(mdb, type_info[i].literal_suffix, 0, t4, MDB_BIND_SIZE);
- ts5 = mdb_ascii2unicode(mdb, type_info[i].create_params, 0, t5, MDB_BIND_SIZE);
- ts12 = mdb_ascii2unicode(mdb, type_info[i].local_type_name, 0, t12, MDB_BIND_SIZE);
+ ts0 = mdb_ascii2unicode(mdb, (char*)type_info[i].type_name, 0, (char*)t0, MDB_BIND_SIZE);
+ ts3 = mdb_ascii2unicode(mdb, (char*)type_info[i].literal_prefix, 0, (char*)t3, MDB_BIND_SIZE);
+ ts4 = mdb_ascii2unicode(mdb, (char*)type_info[i].literal_suffix, 0, (char*)t4, MDB_BIND_SIZE);
+ ts5 = mdb_ascii2unicode(mdb, (char*)type_info[i].create_params, 0, (char*)t5, MDB_BIND_SIZE);
+ ts12 = mdb_ascii2unicode(mdb, (char*)type_info[i].local_type_name, 0, (char*)t12, MDB_BIND_SIZE);
FILL_FIELD(&fields[0], t0, ts0);
FILL_FIELD(&fields[1],&type_info[i].data_type, 0);
@@ -1818,7 +1859,7 @@
MdbField fields[5];
MdbCatalogEntry *entry;
unsigned char row_buffer[MDB_PGSIZE];
- unsigned char *table_types[] = {"TABLE", "SYSTEM TABLE", "VIEW"};
+ char *table_types[] = {"TABLE", "SYSTEM TABLE", "VIEW"};
unsigned int i, j, row_size, ttype;
unsigned int ts2, ts3;
unsigned char t2[MDB_BIND_SIZE],
@@ -1854,8 +1895,8 @@
FILL_FIELD(&fields[j], NULL, 0);
}
- ts2 = mdb_ascii2unicode(mdb, entry->object_name, 0, t2, MDB_BIND_SIZE);
- ts3 = mdb_ascii2unicode(mdb, table_types[ttype], 0, t3, MDB_BIND_SIZE);
+ ts2 = mdb_ascii2unicode(mdb, entry->object_name, 0, (char*)t2, MDB_BIND_SIZE);
+ ts3 = mdb_ascii2unicode(mdb, table_types[ttype], 0, (char*)t3, MDB_BIND_SIZE);
FILL_FIELD(&fields[2], t2, ts2);
FILL_FIELD(&fields[3], t3, ts3);
@@ -1886,14 +1927,14 @@
static int _odbc_fix_literals(struct _hstmt *stmt)
{
-char tmp[4096],begin_tag[11];
-char *s, *d, *p;
-int i, quoted = 0, find_end = 0;
-char quote_char;
-
- s=stmt->query;
- d=tmp;
- while (*s) {
+ char tmp[4096],begin_tag[11];
+ char *s, *d, *p;
+ int i, quoted = 0, find_end = 0;
+ char quote_char;
+
+ s=stmt->query;
+ d=tmp;
+ while (*s) {
if (!quoted && (*s=='"' || *s=='\'')) {
quoted = 1;
quote_char = *s;
@@ -1917,25 +1958,26 @@
} else {
*d++=*s++;
}
- }
+ }
*d='\0';
strcpy(stmt->query,tmp);
return 0;
}
-static int _odbc_get_string_size(int size, char *str)
+static int _odbc_get_string_size(int size, SQLCHAR FAR *str)
{
if (!str) {
return 0;
}
if (size==SQL_NTS) {
- return strlen(str);
+ return strlen((char*)str);
} else {
return size;
}
return 0;
}
+/*
static int _odbc_get_server_type(int clt_type)
{
switch (clt_type) {
@@ -1953,7 +1995,7 @@
break;
}
return 0;
-}
+}*/
static SQLSMALLINT _odbc_get_client_type(int srv_type)
{
switch (srv_type) {
Index: mdbtools-0.6pre1/src/odbc/connectparams.c
===================================================================
--- mdbtools-0.6pre1.orig/src/odbc/connectparams.c
+++ mdbtools-0.6pre1/src/odbc/connectparams.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
+#include <ctype.h>
#include "connectparams.h"
#ifdef HAVE_CONFIG_H
@@ -46,10 +47,12 @@
static char line[max_line];
static guint HashFunction (gconstpointer key);
+#if !HAVE_SQLGETPRIVATEPROFILESTRING
static GString* GetIniFileName ();
static int FileExists (const gchar* name);
static int FindSection (FILE* stream, const char* section);
static int GetNextItem (FILE* stream, char** name, char** value);
+#endif //!HAVE_SQLGETPRIVATEPROFILESTRING
static void visit (gpointer key, gpointer value, gpointer user_data);
static gboolean cleanup (gpointer key, gpointer value, gpointer user_data);
@@ -360,6 +363,20 @@
* Begin local function definitions
*/
+/*
+ * Make a hash from all the characters
+ */
+static guint HashFunction (gconstpointer key)
+{
+ guint value = 0;
+ const char* s = key;
+
+ while (*s) value += *s++;
+
+ return value;
+}
+
+#if !HAVE_SQLGETPRIVATEPROFILESTRING
static GString* GetIniFileName ()
{
char* setting;
@@ -438,19 +455,6 @@
return 0;
}
-/*
- * Make a hash from all the characters
- */
-static guint HashFunction (gconstpointer key)
-{
- guint value = 0;
- const char* s = key;
-
- while (*s) value += *s++;
-
- return value;
-}
-
static int GetNextItem (FILE* stream, char** name, char** value)
{
char* s;
@@ -499,12 +503,12 @@
return 1;
}
+#endif //!HAVE_SQLGETPRIVATEPROFILESTRING
static void visit (gpointer key, gpointer value, gpointer user_data)
{
FILE* output = (FILE*) user_data;
-
- g_printerr ("Parameter: %s, Value: %s\n", key, value);
+ fprintf(output, "Parameter: %s, Value: %s\n", (char*)key, (char*)value);
}
static gboolean cleanup (gpointer key, gpointer value, gpointer user_data)