From: George Tasker Date: Thu, 4 Nov 2004 21:31:12 +0000 (+0000) Subject: Unicode support X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e4e45573151c64a0a9d423eca7b29879640b9d77?hp=be7eecf834108f09d5b00fc7e774e9f8c90fcf8d Unicode support Several error conditions when connecting to databases are corrected git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30270 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/db.h b/include/wx/db.h index ba591bd6b8..795b7912f5 100644 --- a/include/wx/db.h +++ b/include/wx/db.h @@ -83,6 +83,11 @@ } #endif +#if wxUSE_UNICODE +#define SQL_C_WXCHAR SQL_C_WCHAR +#else +#define SQL_C_WXCHAR SQL_C_CHAR +#endif typedef float SFLOAT; typedef double SDOUBLE; @@ -365,7 +370,7 @@ public: ~wxDbColFor(){} void Initialize(); - int Format(int Nation, int dbDataType, SWORD sqlDataType, short columnSize, short decimalDigits); + int Format(int Nation, int dbDataType, SWORD sqlDataType, short columnLength, short decimalDigits); }; @@ -378,8 +383,8 @@ public: wxChar colName[DB_MAX_COLUMN_NAME_LEN+1]; SWORD sqlDataType; wxChar typeName[128+1]; - SWORD columnSize; - SWORD bufferLength; + SWORD columnLength; + SWORD bufferSize; short decimalDigits; short numPrecRadix; short nullable; @@ -750,8 +755,8 @@ int WXDLLEXPORT wxDbCreateDataSource(const wxString &driverName, const wxString // the first time using SQL_FETCH_FIRST. Continue to call it // using SQL_FETCH_NEXT until you've exhausted the list. bool WXDLLIMPEXP_ODBC -wxDbGetDataSource(HENV henv, wxChar *Dsn, SWORD DsnMax, wxChar *DsDesc, - SWORD DsDescMax, UWORD direction = SQL_FETCH_NEXT); +wxDbGetDataSource(HENV henv, wxChar *Dsn, SWORD DsnMaxLength, wxChar *DsDesc, + SWORD DsDescMaxLength, UWORD direction = SQL_FETCH_NEXT); // Change this to 0 to remove use of all deprecated functions @@ -791,7 +796,7 @@ int WXDLLIMPEXP_ODBC NumberDbConnectionsInUse(void); bool SqlLog(sqlLog state, const wxChar *filename = SQL_LOG_FILENAME); bool WXDLLIMPEXP_ODBC -GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax, +GetDataSource(HENV henv, char *Dsn, SWORD DsnMaxLength, char *DsDesc, SWORD DsDescMaxLength, UWORD direction = SQL_FETCH_NEXT); #endif // Deprecated structures/classes/functions diff --git a/src/common/db.cpp b/src/common/db.cpp index 1182d61b7e..da7698256d 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -261,7 +261,7 @@ void wxDbColFor::Initialize() /********** wxDbColFor::Format() **********/ int wxDbColFor::Format(int Nation, int dbDataType, SWORD sqlDataType, - short columnSize, short decimalDigits) + short columnLength, short decimalDigits) { // ---------------------------------------------------------------------------------------- // -- 19991224 : mj10777 : Create @@ -314,8 +314,8 @@ int wxDbColFor::Format(int Nation, int dbDataType, SWORD sqlDataType, if (decimalDigits == 0) decimalDigits = 2; tempStr = wxT("%"); - tempStr.Printf(wxT("%s%d.%d"),tempStr.c_str(),columnSize,decimalDigits); - s_Field.Printf(wxT("%sf"),tempStr.c_str()); + tempStr.Printf(wxT("%s%d.%d"), tempStr.c_str(),columnLength, decimalDigits); + s_Field.Printf(wxT("%sf"), tempStr.c_str()); break; case DB_DATA_TYPE_DATE: if (i_Nation == 0) // timestamp YYYY-MM-DD HH:MM:SS.SSS (tested for SYBASE) @@ -340,17 +340,16 @@ int wxDbColFor::Format(int Nation, int dbDataType, SWORD sqlDataType, } break; case DB_DATA_TYPE_BLOB: - s_Field.Printf(wxT("Unable to format(%d)-SQL(%d)"),dbDataType,sqlDataType); // + s_Field.Printf(wxT("Unable to format(%d)-SQL(%d)"), dbDataType,sqlDataType); // break; default: - s_Field.Printf(wxT("Unknown Format(%d)-SQL(%d)"),dbDataType,sqlDataType); // + s_Field.Printf(wxT("Unknown Format(%d)-SQL(%d)"), dbDataType,sqlDataType); // break; }; return TRUE; } // wxDbColFor::Format() - /********** wxDbColInf Constructor **********/ wxDbColInf::wxDbColInf() { @@ -375,8 +374,8 @@ bool wxDbColInf::Initialize() colName[0] = 0; sqlDataType = 0; typeName[0] = 0; - columnSize = 0; - bufferLength = 0; + columnLength = 0; + bufferSize = 0; decimalDigits = 0; numPrecRadix = 0; nullable = 0; @@ -1008,11 +1007,14 @@ bool wxDb::setConnectionOptions(void) // I need to get the DBMS name here, because some of the connection options // are database specific and need to call the Dbms() function. - if (SQLGetInfo(hdbc, SQL_DBMS_NAME, (UCHAR*) dbInf.dbmsName, 40, &cb) != SQL_SUCCESS) + RETCODE retcode; + + retcode = SQLGetInfo(hdbc, SQL_DBMS_NAME, (UCHAR *) dbInf.dbmsName, sizeof(dbInf.dbmsName), &cb); + if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) return(DispAllErrors(henv, hdbc)); - SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF); - SQLSetConnectOption(hdbc, SQL_OPT_TRACE, SQL_OPT_TRACE_OFF); + retcode = SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF); + retcode = SQLSetConnectOption(hdbc, SQL_OPT_TRACE, SQL_OPT_TRACE_OFF); // SQLSetConnectOption(hdbc, SQL_TXN_ISOLATION, SQL_TXN_READ_COMMITTED); // No dirty reads // By default, MS Sql Server closes cursors on commit and rollback. The following @@ -1024,7 +1026,7 @@ bool wxDb::setConnectionOptions(void) { const long SQL_PRESERVE_CURSORS = 1204L; const long SQL_PC_ON = 1L; - SQLSetConnectOption(hdbc, SQL_PRESERVE_CURSORS, SQL_PC_ON); + retcode = SQLSetConnectOption(hdbc, SQL_PRESERVE_CURSORS, SQL_PC_ON); } // Display the connection options to verify them @@ -1032,15 +1034,17 @@ bool wxDb::setConnectionOptions(void) long l; cout << wxT("****** CONNECTION OPTIONS ******") << endl; - if (SQLGetConnectOption(hdbc, SQL_AUTOCOMMIT, &l) != SQL_SUCCESS) + retcode = SQLGetConnectOption(hdbc, SQL_AUTOCOMMIT, &l); + if (retcode != SQL_SUCCESS) return(DispAllErrors(henv, hdbc)); cout << wxT("AUTOCOMMIT: ") << (l == SQL_AUTOCOMMIT_OFF ? "OFF" : "ON") << endl; - if (SQLGetConnectOption(hdbc, SQL_ODBC_CURSORS, &l) != SQL_SUCCESS) + retcode = SQLGetConnectOption(hdbc, SQL_ODBC_CURSORS, &l); + if (retcode != SQL_SUCCESS) return(DispAllErrors(henv, hdbc)); cout << wxT("ODBC CURSORS: "); switch(l) - { + { case(SQL_CUR_USE_IF_NEEDED): cout << wxT("SQL_CUR_USE_IF_NEEDED"); break; @@ -1050,10 +1054,11 @@ bool wxDb::setConnectionOptions(void) case(SQL_CUR_USE_DRIVER): cout << wxT("SQL_CUR_USE_DRIVER"); break; - } - cout << endl; + } + cout << endl; - if (SQLGetConnectOption(hdbc, SQL_OPT_TRACE, &l) != SQL_SUCCESS) + retcode = SQLGetConnectOption(hdbc, SQL_OPT_TRACE, &l) + if (retcode != SQL_SUCCESS) return(DispAllErrors(henv, hdbc)); cout << wxT("TRACING: ") << (l == SQL_OPT_TRACE_OFF ? wxT("OFF") : wxT("ON")) << endl; @@ -1072,7 +1077,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) SWORD cb; RETCODE retcode; - retcode = SQLGetInfo(hdbc, SQL_SERVER_NAME, (UCHAR*) dbInf.serverName, 80, &cb); + retcode = SQLGetInfo(hdbc, SQL_SERVER_NAME, (UCHAR*) dbInf.serverName, sizeof(dbInf.serverName), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1080,7 +1085,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_DATABASE_NAME, (UCHAR*) dbInf.databaseName, 128, &cb); + retcode = SQLGetInfo(hdbc, SQL_DATABASE_NAME, (UCHAR*) dbInf.databaseName, sizeof(dbInf.databaseName), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1088,7 +1093,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_DBMS_NAME, (UCHAR*) dbInf.dbmsName, 40, &cb); + retcode = SQLGetInfo(hdbc, SQL_DBMS_NAME, (UCHAR*) dbInf.dbmsName, sizeof(dbInf.dbmsName), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1099,7 +1104,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) // 16-Mar-1999 // After upgrading to MSVC6, the original 20 char buffer below was insufficient, // causing database connectivity to fail in some cases. - retcode = SQLGetInfo(hdbc, SQL_DBMS_VER, (UCHAR*) dbInf.dbmsVer, 64, &cb); + retcode = SQLGetInfo(hdbc, SQL_DBMS_VER, (UCHAR*) dbInf.dbmsVer, sizeof(dbInf.dbmsVer), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1123,7 +1128,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_DRIVER_NAME, (UCHAR*) dbInf.driverName, 40, &cb); + retcode = SQLGetInfo(hdbc, SQL_DRIVER_NAME, (UCHAR*) dbInf.driverName, sizeof(dbInf.driverName), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1131,7 +1136,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_DRIVER_ODBC_VER, (UCHAR*) dbInf.odbcVer, 60, &cb); + retcode = SQLGetInfo(hdbc, SQL_DRIVER_ODBC_VER, (UCHAR*) dbInf.odbcVer, sizeof(dbInf.odbcVer), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1139,7 +1144,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_ODBC_VER, (UCHAR*) dbInf.drvMgrOdbcVer, 60, &cb); + retcode = SQLGetInfo(hdbc, SQL_ODBC_VER, (UCHAR*) dbInf.drvMgrOdbcVer, sizeof(dbInf.drvMgrOdbcVer), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) { DispAllErrors(henv, hdbc); @@ -1147,7 +1152,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_DRIVER_VER, (UCHAR*) dbInf.driverVer, 60, &cb); + retcode = SQLGetInfo(hdbc, SQL_DRIVER_VER, (UCHAR*) dbInf.driverVer, sizeof(dbInf.driverVer), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1181,7 +1186,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_OUTER_JOINS, (UCHAR*) dbInf.outerJoins, 2, &cb); + retcode = SQLGetInfo(hdbc, SQL_OUTER_JOINS, (UCHAR*) dbInf.outerJoins, sizeof(dbInf.outerJoins), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1189,7 +1194,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_PROCEDURES, (UCHAR*) dbInf.procedureSupport, 2, &cb); + retcode = SQLGetInfo(hdbc, SQL_PROCEDURES, (UCHAR*) dbInf.procedureSupport, sizeof(dbInf.procedureSupport), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1197,7 +1202,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_ACCESSIBLE_TABLES, (UCHAR*) dbInf.accessibleTables, 2, &cb); + retcode = SQLGetInfo(hdbc, SQL_ACCESSIBLE_TABLES, (UCHAR*) dbInf.accessibleTables, sizeof(dbInf.accessibleTables), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1229,7 +1234,7 @@ bool wxDb::getDbInfo(bool failOnDataTypeUnsupported) return false; } - retcode = SQLGetInfo(hdbc, SQL_ODBC_SQL_OPT_IEF, (UCHAR*) dbInf.supportIEF, 2, &cb); + retcode = SQLGetInfo(hdbc, SQL_ODBC_SQL_OPT_IEF, (UCHAR*) dbInf.supportIEF, sizeof(dbInf.supportIEF), &cb); if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ) { DispAllErrors(henv, hdbc); @@ -1558,7 +1563,7 @@ bool wxDb::getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo) wxChar typeName[DB_TYPE_NAME_LEN+1]; // Obtain columns from the record - if (SQLGetData(hstmt, 1, SQL_C_CHAR, (UCHAR*) typeName, DB_TYPE_NAME_LEN, &cbRet) != SQL_SUCCESS) + if (SQLGetData(hstmt, 1, SQL_C_WXCHAR, typeName, sizeof(typeName), &cbRet) != SQL_SUCCESS) return(DispAllErrors(henv, hdbc, hstmt)); structSQLTypeInfo.TypeName = typeName; @@ -2178,7 +2183,12 @@ bool wxDb::GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SDWORD FA wxASSERT(pData); wxASSERT(cbReturned); - if (SQLGetData(hstmt, colNo, cType, pData, maxLen, cbReturned) == SQL_SUCCESS) + long bufferSize = maxLen; + + if (cType == SQL_C_WXCHAR) + bufferSize = maxLen * sizeof(wxChar); + + if (SQLGetData(hstmt, colNo, cType, pData, bufferSize, cbReturned) == SQL_SUCCESS) return true; else { @@ -2232,7 +2242,7 @@ int wxDb::GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCo retcode = SQLFetch(hstmt); if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { - GetData( 4, SQL_C_CHAR, szPkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb); + GetData( 4, SQL_C_WXCHAR, szPkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb); GetData( 5, SQL_C_SSHORT, &iKeySeq, 0, &cb); //------- for (i=0;inumTables == 0) { - GetData( 1, SQL_C_CHAR, (UCHAR*) pDbInf->catalog, 128+1, &cb); - GetData( 2, SQL_C_CHAR, (UCHAR*) pDbInf->schema, 128+1, &cb); + GetData( 1, SQL_C_WXCHAR, (UCHAR*) pDbInf->catalog, 128+1, &cb); + GetData( 2, SQL_C_WXCHAR, (UCHAR*) pDbInf->schema, 128+1, &cb); } pDbInf->numTables++; // Counter for Tables } // if (pass == 1) @@ -3191,9 +3201,9 @@ wxDbInf *wxDb::GetCatalog(const wxChar *userID) noTab = 0; } // if (pDbInf->pTableInf == NULL) // Has the Table Array been created - GetData( 3, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableName, DB_MAX_TABLE_NAME_LEN+1, &cb); - GetData( 4, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableType, 30+1, &cb); - GetData( 5, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableRemarks, 254+1, &cb); + GetData( 3, SQL_C_WXCHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableName, DB_MAX_TABLE_NAME_LEN+1, &cb); + GetData( 4, SQL_C_WXCHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableType, 30+1, &cb); + GetData( 5, SQL_C_WXCHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableRemarks, 254+1, &cb); noTab++; } // if @@ -3286,12 +3296,12 @@ bool wxDb::Catalog(const wxChar *userID, const wxString &fileName) if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) break; - GetData(3,SQL_C_CHAR, (UCHAR *) tblName, DB_MAX_TABLE_NAME_LEN+1, &cb); - GetData(4,SQL_C_CHAR, (UCHAR *) colName, DB_MAX_COLUMN_NAME_LEN+1,&cb); - GetData(5,SQL_C_SSHORT,(UCHAR *)&sqlDataType, 0, &cb); - GetData(6,SQL_C_CHAR, (UCHAR *) typeName, sizeof(typeName), &cb); - GetData(7,SQL_C_SLONG, (UCHAR *)&precision, 0, &cb); - GetData(8,SQL_C_SLONG, (UCHAR *)&length, 0, &cb); + GetData(3,SQL_C_WXCHAR, (UCHAR *) tblName, DB_MAX_TABLE_NAME_LEN+1, &cb); + GetData(4,SQL_C_WXCHAR, (UCHAR *) colName, DB_MAX_COLUMN_NAME_LEN+1,&cb); + GetData(5,SQL_C_SSHORT, (UCHAR *)&sqlDataType, 0, &cb); + GetData(6,SQL_C_WXCHAR, (UCHAR *) typeName, sizeof(typeName), &cb); + GetData(7,SQL_C_SLONG, (UCHAR *)&precision, 0, &cb); + GetData(8,SQL_C_SLONG, (UCHAR *)&length, 0, &cb); if (wxStrcmp(tblName, tblNameSave.c_str())) { @@ -3473,31 +3483,31 @@ bool wxDb::TablePrivileges(const wxString &tableName, const wxString &priv, cons #endif if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)) - return(DispAllErrors(henv, hdbc, hstmt)); + return (DispAllErrors(henv, hdbc, hstmt)); bool failed = false; retcode = SQLFetch(hstmt); while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { - if (SQLGetData(hstmt, 1, SQL_C_CHAR, (UCHAR*) result.tableQual, sizeof(result.tableQual), &cbRetVal) != SQL_SUCCESS) + if (SQLGetData(hstmt, 1, SQL_C_WXCHAR, (UCHAR*) result.tableQual, sizeof(result.tableQual), &cbRetVal) != SQL_SUCCESS) failed = true; - if (!failed && SQLGetData(hstmt, 2, SQL_C_CHAR, (UCHAR*) result.tableOwner, sizeof(result.tableOwner), &cbRetVal) != SQL_SUCCESS) + if (!failed && SQLGetData(hstmt, 2, SQL_C_WXCHAR, (UCHAR*) result.tableOwner, sizeof(result.tableOwner), &cbRetVal) != SQL_SUCCESS) failed = true; - if (!failed && SQLGetData(hstmt, 3, SQL_C_CHAR, (UCHAR*) result.tableName, sizeof(result.tableName), &cbRetVal) != SQL_SUCCESS) + if (!failed && SQLGetData(hstmt, 3, SQL_C_WXCHAR, (UCHAR*) result.tableName, sizeof(result.tableName), &cbRetVal) != SQL_SUCCESS) failed = true; - if (!failed && SQLGetData(hstmt, 4, SQL_C_CHAR, (UCHAR*) result.grantor, sizeof(result.grantor), &cbRetVal) != SQL_SUCCESS) + if (!failed && SQLGetData(hstmt, 4, SQL_C_WXCHAR, (UCHAR*) result.grantor, sizeof(result.grantor), &cbRetVal) != SQL_SUCCESS) failed = true; - if (!failed && SQLGetData(hstmt, 5, SQL_C_CHAR, (UCHAR*) result.grantee, sizeof(result.grantee), &cbRetVal) != SQL_SUCCESS) + if (!failed && SQLGetData(hstmt, 5, SQL_C_WXCHAR, (UCHAR*) result.grantee, sizeof(result.grantee), &cbRetVal) != SQL_SUCCESS) failed = true; - if (!failed && SQLGetData(hstmt, 6, SQL_C_CHAR, (UCHAR*) result.privilege, sizeof(result.privilege), &cbRetVal) != SQL_SUCCESS) + if (!failed && SQLGetData(hstmt, 6, SQL_C_WXCHAR, (UCHAR*) result.privilege, sizeof(result.privilege), &cbRetVal) != SQL_SUCCESS) failed = true; - if (!failed && SQLGetData(hstmt, 7, SQL_C_CHAR, (UCHAR*) result.grantable, sizeof(result.grantable), &cbRetVal) != SQL_SUCCESS) + if (!failed && SQLGetData(hstmt, 7, SQL_C_WXCHAR, (UCHAR*) result.grantable, sizeof(result.grantable), &cbRetVal) != SQL_SUCCESS) failed = true; if (failed) @@ -4186,8 +4196,8 @@ int wxDbCreateDataSource(const wxString &driverName, const wxString &dsn, const /********** wxDbGetDataSource() **********/ -bool wxDbGetDataSource(HENV henv, wxChar *Dsn, SWORD DsnMax, wxChar *DsDesc, - SWORD DsDescMax, UWORD direction) +bool wxDbGetDataSource(HENV henv, wxChar *Dsn, SWORD DsnMaxLength, wxChar *DsDesc, + SWORD DsDescMaxLength, UWORD direction) /* * Dsn and DsDesc will contain the data source name and data source * description upon return @@ -4195,8 +4205,8 @@ bool wxDbGetDataSource(HENV henv, wxChar *Dsn, SWORD DsnMax, wxChar *DsDesc, { SWORD cb1,cb2; - if (SQLDataSources(henv, direction, (SQLTCHAR FAR *) Dsn, DsnMax, &cb1, - (SQLTCHAR FAR *) DsDesc, DsDescMax, &cb2) == SQL_SUCCESS) + if (SQLDataSources(henv, direction, (SQLTCHAR FAR *) Dsn, DsnMaxLength*sizeof(wxChar), &cb1, + (SQLTCHAR FAR *) DsDesc, DsDescMaxLength*sizeof(wxChar), &cb2) == SQL_SUCCESS) return true; else return false; diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index c6bc966f6d..3e33499159 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -434,7 +434,7 @@ void wxDbTable::setCbValueForColumn(int columnIndex) if (colDefs[columnIndex].Null) colDefs[columnIndex].CbValue = SQL_NULL_DATA; else - if (colDefs[columnIndex].SqlCtype == SQL_C_CHAR) + if (colDefs[columnIndex].SqlCtype == SQL_C_WXCHAR) colDefs[columnIndex].CbValue = SQL_NTS; else colDefs[columnIndex].CbValue = SQL_LEN_DATA_AT_EXEC(colDefs[columnIndex].SzDataObj); @@ -779,7 +779,7 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists) // reliable! if (// *(pDb->dbInf.accessibleTables) == 'N' && !pDb->TablePrivileges(tableName,wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath)) - s = wxT("Current logged in user does not have sufficient privileges to access this table.\n"); + s = wxT("Connecting user does not have sufficient privileges to access this table.\n"); } if (!s.IsEmpty()) @@ -998,7 +998,7 @@ void wxDbTable::BuildDeleteStmt(wxString &pSqlStmt, int typeOfDel, const wxStrin // Get the ROWID value. If not successful retreiving the ROWID, // simply fall down through the code and build the WHERE clause // based on the key fields. - if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS) + if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_WXCHAR, (UCHAR*) rowid, sizeof(rowid), &cb) == SQL_SUCCESS) { pSqlStmt += wxT("ROWID = '"); pSqlStmt += rowid; @@ -1216,7 +1216,7 @@ void wxDbTable::BuildUpdateStmt(wxString &pSqlStmt, int typeOfUpd, const wxStrin // Get the ROWID value. If not successful retreiving the ROWID, // simply fall down through the code and build the WHERE clause // based on the key fields. - if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS) + if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_WXCHAR, (UCHAR*) rowid, sizeof(rowid), &cb) == SQL_SUCCESS) { pSqlStmt += wxT("ROWID = '"); pSqlStmt += rowid; @@ -1283,7 +1283,7 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere, } pWhereClause += pDb->SQLColumnName(colDefs[colNo].ColName); - if (useLikeComparison && (colDefs[colNo].SqlCtype == SQL_C_CHAR)) + if (useLikeComparison && (colDefs[colNo].SqlCtype == SQL_C_WXCHAR)) pWhereClause += wxT(" LIKE "); else pWhereClause += wxT(" = "); @@ -1291,6 +1291,8 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere, switch(colDefs[colNo].SqlCtype) { case SQL_C_CHAR: + case SQL_C_WCHAR: + //case SQL_C_WXCHAR: SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[colNo].PtrDataObj); break; case SQL_C_SHORT: @@ -1395,7 +1397,7 @@ bool wxDbTable::CreateTable(bool attemptDrop) switch(colDefs[i].DbDataType) { case DB_DATA_TYPE_VARCHAR: - cout << pDb->GetTypeInfVarchar().TypeName << wxT("(") << colDefs[i].SzDataObj << wxT(")"); + cout << pDb->GetTypeInfVarchar().TypeName << wxT("(") << (int)(colDefs[i].SzDataObj / sizeof(wxChar)) << wxT(")"); break; case DB_DATA_TYPE_INTEGER: cout << pDb->GetTypeInfInteger().TypeName; @@ -1457,7 +1459,7 @@ bool wxDbTable::CreateTable(bool attemptDrop) // colDefs[i].DbDataType == DB_DATA_TYPE_BLOB) { wxString s; - s.Printf(wxT("(%d)"), colDefs[i].SzDataObj); + s.Printf(wxT("(%d)"), (int)(colDefs[i].SzDataObj / sizeof(wxChar))); sqlStmt += s; } @@ -1531,7 +1533,7 @@ bool wxDbTable::CreateTable(bool attemptDrop) colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR) { wxString s; - s.Printf(wxT("(%d)"), colDefs[i].SzDataObj); + s.Printf(wxT("(%d)"), (int)(colDefs[i].SzDataObj / sizeof(wxChar))); sqlStmt += s; } } @@ -1673,7 +1675,7 @@ bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCol if (found) { ok = pDb->ModifyColumn(tableName, pIdxDefs[i].ColName, - colDefs[j].DbDataType, colDefs[j].SzDataObj, + colDefs[j].DbDataType, (int)(colDefs[j].SzDataObj / sizeof(wxChar)), wxT("NOT NULL")); if (!ok) @@ -1735,7 +1737,7 @@ bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCol if ( colDefs[j].DbDataType == DB_DATA_TYPE_VARCHAR) { wxString s; - s.Printf(wxT("(%d)"), colDefs[i].SzDataObj); + s.Printf(wxT("(%d)"), (int)(colDefs[i].SzDataObj / sizeof(wxChar))); sqlStmt += s; } } @@ -2090,6 +2092,8 @@ bool wxDbTable::IsColNull(UWORD colNo) const switch(colDefs[colNo].SqlCtype) { case SQL_C_CHAR: + case SQL_C_WCHAR: + //case SQL_C_WXCHAR: SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR return(((UCHAR FAR *) colDefs[colNo].PtrDataObj)[0] == 0); case SQL_C_SSHORT: return(( *((SWORD *) colDefs[colNo].PtrDataObj)) == 0); @@ -2173,6 +2177,8 @@ void wxDbTable::ClearMemberVar(UWORD colNo, bool setToNull) switch(colDefs[colNo].SqlCtype) { case SQL_C_CHAR: + case SQL_C_WCHAR: + //case SQL_C_WXCHAR: SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR ((UCHAR FAR *) colDefs[colNo].PtrDataObj)[0] = 0; break; case SQL_C_SSHORT: @@ -2271,7 +2277,7 @@ void wxDbTable::SetColDefs(UWORD index, const wxString &fieldName, int dataType, colDefs[index].DbDataType = dataType; colDefs[index].PtrDataObj = pData; colDefs[index].SqlCtype = cType; - colDefs[index].SzDataObj = size; + colDefs[index].SzDataObj = size; //TODO: glt ??? * sizeof(wxChar) ??? colDefs[index].KeyField = keyField; colDefs[index].DerivedCol = derivedCol; // Derived columns by definition would NOT be "Insertable" or "Updateable" @@ -2309,13 +2315,13 @@ wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, UWORD numCols) switch (pColInfs[index].dbDataType) { case DB_DATA_TYPE_VARCHAR: - pColDataPtrs[index].PtrDataObj = new wxChar[pColInfs[index].bufferLength+1]; - pColDataPtrs[index].SzDataObj = pColInfs[index].columnSize; - pColDataPtrs[index].SqlCtype = SQL_C_CHAR; + pColDataPtrs[index].PtrDataObj = new wxChar[pColInfs[index].bufferSize+(1*sizeof(wxChar))]; + pColDataPtrs[index].SzDataObj = pColInfs[index].bufferSize+(1*sizeof(wxChar)); + pColDataPtrs[index].SqlCtype = SQL_C_WXCHAR; break; case DB_DATA_TYPE_INTEGER: // Can be long or short - if (pColInfs[index].bufferLength == sizeof(long)) + if (pColInfs[index].bufferSize == sizeof(long)) { pColDataPtrs[index].PtrDataObj = new long; pColDataPtrs[index].SzDataObj = sizeof(long); @@ -2330,7 +2336,7 @@ wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, UWORD numCols) break; case DB_DATA_TYPE_FLOAT: // Can be float or double - if (pColInfs[index].bufferLength == sizeof(float)) + if (pColInfs[index].bufferSize == sizeof(float)) { pColDataPtrs[index].PtrDataObj = new float; pColDataPtrs[index].SzDataObj = sizeof(float); @@ -2483,12 +2489,12 @@ bool wxDbTable::Refresh(void) if (CanUpdByROWID()) { SDWORD cb; - wxChar rowid[wxDB_ROWID_LEN+1]; + wxChar rowid[wxDB_ROWID_LEN+1]; // Get the ROWID value. If not successful retreiving the ROWID, // simply fall down through the code and build the WHERE clause // based on the key fields. - if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS) + if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_WXCHAR, (UCHAR*) rowid, sizeof(rowid), &cb) == SQL_SUCCESS) { whereClause += pDb->SQLTableName(queryTableName); // whereClause += queryTableName; @@ -2739,7 +2745,7 @@ void wxDbTable::SetCol(const int colNo, const wxVariant val) case SQL_VARCHAR: csstrncpyt((wxChar *)(colDefs[colNo].PtrDataObj), val.GetString().c_str(), - colDefs[colNo].SzDataObj-1); + colDefs[colNo].SzDataObj-1); //TODO: glt ??? * sizeof(wxChar) ??? break; case SQL_C_LONG: case SQL_C_SLONG: