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
This commit is contained in:
@@ -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;i<noCols;i++) // Find the Column name
|
||||
@@ -2264,11 +2274,11 @@ int wxDb::GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCo
|
||||
retcode = SQLFetch(hstmt);
|
||||
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
|
||||
{
|
||||
GetData( 3, SQL_C_CHAR, szPkTable, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 4, SQL_C_CHAR, szPkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 5, SQL_C_SSHORT, &iKeySeq, 0, &cb);
|
||||
GetData( 7, SQL_C_CHAR, szFkTable, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 8, SQL_C_CHAR, szFkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 3, SQL_C_WXCHAR, szPkTable, DB_MAX_TABLE_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);
|
||||
GetData( 7, SQL_C_WXCHAR, szFkTable, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 8, SQL_C_WXCHAR, szFkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
tempStr.Printf(wxT("%s[%s] "),tempStr.c_str(),szFkTable); // [ ] in case there is a blank in the Table name
|
||||
} // if
|
||||
} // while
|
||||
@@ -2306,9 +2316,9 @@ int wxDb::GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCo
|
||||
retcode = SQLFetch(hstmt);
|
||||
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
|
||||
{
|
||||
GetData( 3, SQL_C_CHAR, szPkTable, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 5, SQL_C_SSHORT, &iKeySeq, 0, &cb);
|
||||
GetData( 8, SQL_C_CHAR, szFkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 3, SQL_C_WXCHAR, szPkTable, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 5, SQL_C_SSHORT, &iKeySeq, 0, &cb);
|
||||
GetData( 8, SQL_C_WXCHAR, szFkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
//-------
|
||||
for (i=0; i<noCols; i++) // Find the Column name
|
||||
{
|
||||
@@ -2440,30 +2450,30 @@ wxDbColInf *wxDb::GetColumns(wxChar *tableName[], const wxChar *userID)
|
||||
if (colNo < noCols) // Some extra error checking to prevent memory overwrites
|
||||
{
|
||||
// NOTE: Only the ODBC 1.x fields are retrieved
|
||||
GetData( 1, SQL_C_CHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
|
||||
GetData( 2, SQL_C_CHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
|
||||
GetData( 3, SQL_C_CHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 4, SQL_C_CHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 1, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
|
||||
GetData( 2, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
|
||||
GetData( 3, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 4, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
|
||||
GetData( 6, SQL_C_CHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
|
||||
GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnSize, 0, &cb);
|
||||
GetData( 8, SQL_C_SLONG, (UCHAR*) &colInf[colNo].bufferLength, 0, &cb);
|
||||
GetData( 6, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
|
||||
GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnLength, 0, &cb);
|
||||
GetData( 8, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].bufferSize, 0, &cb);
|
||||
GetData( 9, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].decimalDigits,0, &cb);
|
||||
GetData(10, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].numPrecRadix, 0, &cb);
|
||||
GetData(11, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].nullable, 0, &cb);
|
||||
GetData(12, SQL_C_CHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb);
|
||||
GetData(12, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb);
|
||||
|
||||
// Determine the wxDb data type that is used to represent the native data type of this data source
|
||||
colInf[colNo].dbDataType = 0;
|
||||
if (!wxStricmp(typeInfVarchar.TypeName,colInf[colNo].typeName))
|
||||
{
|
||||
#ifdef _IODBC_
|
||||
// IODBC does not return a correct columnSize, so we set
|
||||
// columnSize = bufferLength if no column size was returned
|
||||
// IODBC returns the columnSize in bufferLength.. (bug)
|
||||
if (colInf[colNo].columnSize < 1)
|
||||
// IODBC does not return a correct columnLength, so we set
|
||||
// columnLength = bufferSize if no column length was returned
|
||||
// IODBC returns the columnLength in bufferSize. (bug)
|
||||
if (colInf[colNo].columnLength < 1)
|
||||
{
|
||||
colInf[colNo].columnSize = colInf[colNo].bufferLength;
|
||||
colInf[colNo].columnLength = colInf[colNo].bufferSize;
|
||||
}
|
||||
#endif
|
||||
colInf[colNo].dbDataType = DB_DATA_TYPE_VARCHAR;
|
||||
@@ -2597,19 +2607,19 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, UWORD *numCols, const wx
|
||||
if (colNo < noCols) // Some extra error checking to prevent memory overwrites
|
||||
{
|
||||
// NOTE: Only the ODBC 1.x fields are retrieved
|
||||
GetData( 1, SQL_C_CHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
|
||||
GetData( 2, SQL_C_CHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
|
||||
GetData( 3, SQL_C_CHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 4, SQL_C_CHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
|
||||
GetData( 6, SQL_C_CHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
|
||||
GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnSize, 0, &cb);
|
||||
GetData( 1, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
|
||||
GetData( 2, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
|
||||
GetData( 3, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 4, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
|
||||
GetData( 6, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
|
||||
GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnLength, 0, &cb);
|
||||
// BJO 991214 : SQL_C_SSHORT instead of SQL_C_SLONG, otherwise fails on Sparc (probably all 64 bit architectures)
|
||||
GetData( 8, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].bufferLength, 0, &cb);
|
||||
GetData( 9, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].decimalDigits,0, &cb);
|
||||
GetData(10, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].numPrecRadix, 0, &cb);
|
||||
GetData(11, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].nullable, 0, &cb);
|
||||
GetData(12, SQL_C_CHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb);
|
||||
GetData( 8, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].bufferSize, 0, &cb);
|
||||
GetData( 9, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].decimalDigits,0, &cb);
|
||||
GetData(10, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].numPrecRadix, 0, &cb);
|
||||
GetData(11, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].nullable, 0, &cb);
|
||||
GetData(12, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb);
|
||||
// Start Values for Primary/Foriegn Key (=No)
|
||||
colInf[colNo].PkCol = 0; // Primary key column 0=No; 1= First Key, 2 = Second Key etc.
|
||||
colInf[colNo].PkTableName[0] = 0; // Tablenames where Primary Key is used as a Foreign Key
|
||||
@@ -2629,12 +2639,12 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, UWORD *numCols, const wx
|
||||
if (!wxStricmp(typeInfVarchar.TypeName, colInf[colNo].typeName))
|
||||
{
|
||||
#ifdef _IODBC_
|
||||
// IODBC does not return a correct columnSize, so we set
|
||||
// columnSize = bufferLength if no column size was returned
|
||||
// IODBC returns the columnSize in bufferLength.. (bug)
|
||||
if (colInf[colNo].columnSize < 1)
|
||||
// IODBC does not return a correct columnLength, so we set
|
||||
// columnLength = bufferSize if no column length was returned
|
||||
// IODBC returns the columnLength in bufferSize. (bug)
|
||||
if (colInf[colNo].columnLength < 1)
|
||||
{
|
||||
colInf[colNo].columnSize = colInf[colNo].bufferLength;
|
||||
colInf[colNo].columnLength = colInf[colNo].bufferSize;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2852,18 +2862,18 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh
|
||||
if (colNo < noCols) // Some extra error checking to prevent memory overwrites
|
||||
{
|
||||
// NOTE: Only the ODBC 1.x fields are retrieved
|
||||
GetData( 1, SQL_C_CHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
|
||||
GetData( 2, SQL_C_CHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
|
||||
GetData( 3, SQL_C_CHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 4, SQL_C_CHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
|
||||
GetData( 6, SQL_C_CHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
|
||||
GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnSize, 0, &cb);
|
||||
GetData( 8, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].bufferLength, 0, &cb);
|
||||
GetData( 9, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].decimalDigits,0, &cb);
|
||||
GetData(10, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].numPrecRadix, 0, &cb);
|
||||
GetData(11, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].nullable, 0, &cb);
|
||||
GetData(12, SQL_C_CHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb);
|
||||
GetData( 1, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].catalog, 128+1, &cb);
|
||||
GetData( 2, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].schema, 128+1, &cb);
|
||||
GetData( 3, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].tableName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
GetData( 4, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
GetData( 5, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].sqlDataType, 0, &cb);
|
||||
GetData( 6, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
|
||||
GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnLength, 0, &cb);
|
||||
GetData( 8, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].bufferSize, 0, &cb);
|
||||
GetData( 9, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].decimalDigits,0, &cb);
|
||||
GetData(10, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].numPrecRadix, 0, &cb);
|
||||
GetData(11, SQL_C_SSHORT, (UCHAR*) &colInf[colNo].nullable, 0, &cb);
|
||||
GetData(12, SQL_C_WXCHAR, (UCHAR*) colInf[colNo].remarks, 254+1, &cb);
|
||||
// Start Values for Primary/Foriegn Key (=No)
|
||||
colInf[colNo].PkCol = 0; // Primary key column 0=No; 1= First Key, 2 = Second Key etc.
|
||||
colInf[colNo].PkTableName[0] = 0; // Tablenames where Primary Key is used as a Foreign Key
|
||||
@@ -2871,12 +2881,12 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh
|
||||
colInf[colNo].FkTableName[0] = 0; // Foreign key table name
|
||||
|
||||
#ifdef _IODBC_
|
||||
// IODBC does not return a correct columnSize, so we set
|
||||
// columnSize = bufferLength if no column size was returned
|
||||
// IODBC returns the columnSize in bufferLength.. (bug)
|
||||
if (colInf[colNo].columnSize < 1)
|
||||
// IODBC does not return a correct columnLength, so we set
|
||||
// columnLength = bufferSize if no column length was returned
|
||||
// IODBC returns the columnLength in bufferSize. (bug)
|
||||
if (colInf[colNo].columnLength < 1)
|
||||
{
|
||||
colInf[colNo].columnSize = colInf[colNo].bufferLength;
|
||||
colInf[colNo].columnLength = colInf[colNo].bufferSize;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3178,8 +3188,8 @@ wxDbInf *wxDb::GetCatalog(const wxChar *userID)
|
||||
{
|
||||
if (pDbInf->numTables == 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;
|
||||
|
Reference in New Issue
Block a user