// source such as opening and closing the data source.
// Author: Doug Card
// Modified by: George Tasker
-// Mods: Dec, 1998:
+// Mods: Dec, 1998:
// -Added support for SQL statement logging and database cataloging
// Mods: April, 1999
// -Added QUERY_ONLY mode support to reduce default number of cursors
#endif
#ifdef DBDEBUG_CONSOLE
- #include <iostream.h>
+ #include "wx/ioswrap.h"
#endif
#ifdef __BORLANDC__
#include "wx/list.h"
#include "wx/utils.h"
#include "wx/msgdlg.h"
+ #include "wx/log.h"
#endif
#include "wx/filefn.h"
#include "wx/wxchar.h"
DbList WXDLLEXPORT *PtrBegDbList = 0;
+char const *SQL_LOG_FILENAME = "sqllog.txt";
+char const *SQL_CATALOG_FILENAME = "catalog.txt";
+
#ifdef __WXDEBUG__
extern wxList TablesInUse;
#endif
enum sqlLog SQLLOGstate = sqlLogOFF;
//char SQLLOGfn[DB_PATH_MAX+1] = SQL_LOG_FILENAME;
-char *SQLLOGfn = SQL_LOG_FILENAME;
+char *SQLLOGfn = (char*) SQL_LOG_FILENAME;
// The wxDB::errorList is copied to this variable when the wxDB object
// is closed. This way, the error list is still available after the
-// database object is closed. This is necessary if the database
+// database object is closed. This is necessary if the database
// connection fails so the calling application can show the operator
// why the connection failed. Note: as each wxDB object is closed, it
-// will overwrite the errors of the previously destroyed wxDB object in
+// will overwrite the errors of the previously destroyed wxDB object in
// this variable.
char DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
fpSqlLog = 0; // Sql Log file pointer
sqlLogState = sqlLogOFF; // By default, logging is turned off
nTables = 0;
-
+
wxStrcpy(sqlState,"");
wxStrcpy(errorMsg,"");
nativeError = cbErrorMsg = 0;
typeInfDate.Precision = 0;
typeInfDate.CaseSensitive = 0;
typeInfDate.MaximumScale = 0;
-
+
// Error reporting is turned OFF by default
silent = TRUE;
-
+
// Copy the HENV into the db class
henv = aHenv;
fwdOnlyCursors = FwdOnlyCursors;
// Display the connection options to verify them
#ifdef DBDEBUG_CONSOLE
long l;
- cout << ">>>>> CONNECTION OPTIONS <<<<<<" << endl;
-
+ cout << "****** CONNECTION OPTIONS ******" << endl;
+
if (SQLGetConnectOption(hdbc, SQL_AUTOCOMMIT, &l) != SQL_SUCCESS)
return(DispAllErrors(henv, hdbc));
cout << "AUTOCOMMIT: " << (l == SQL_AUTOCOMMIT_OFF ? "OFF" : "ON") << endl;
-
+
if (SQLGetConnectOption(hdbc, SQL_ODBC_CURSORS, &l) != SQL_SUCCESS)
return(DispAllErrors(henv, hdbc));
cout << "ODBC CURSORS: ";
break;
}
cout << endl;
-
+
if (SQLGetConnectOption(hdbc, SQL_OPT_TRACE, &l) != SQL_SUCCESS)
return(DispAllErrors(henv, hdbc));
cout << "TRACING: " << (l == SQL_OPT_TRACE_OFF ? "OFF" : "ON") << endl;
return(DispAllErrors(henv, hdbc));
#ifdef DBDEBUG_CONSOLE
- cout << ">>>>> DATA SOURCE INFORMATION <<<<<" << endl;
+ cout << "***** DATA SOURCE INFORMATION *****" << endl;
cout << "SERVER Name: " << dbInf.serverName << endl;
cout << "DBMS Name: " << dbInf.dbmsName << "; DBMS Version: " << dbInf.dbmsVer << endl;
cout << "ODBC Version: " << dbInf.odbcVer << "; Driver Version: " << dbInf.driverVer << endl;
{
s.sprintf("(%-20s) tableID:[%6lu] pDb:[%p]", tiu->tableName,tiu->tableID,tiu->pDb);
s2.sprintf("Orphaned found using pDb:[%p]",this);
- wxMessageBox (s,s2);
+ wxLogDebug (s.c_str(),s2.c_str());
}
pNode = pNode->Next();
}
}
#ifdef __WXDEBUG__
- wxMessageBox(odbcErrMsg.GetData(),"DEBUG MESSAGE from DispAllErrors()");
+ wxLogDebug(odbcErrMsg.GetData(),"DEBUG MESSAGE from DispAllErrors()");
#endif
}
} // wxDB::TranslateSqlState()
-
+
/********** wxDB::Grant() **********/
bool wxDB::Grant(int privileges, const char *tableName, const char *userList)
{
// Build the create view statement
sqlStmt = "CREATE VIEW ";
sqlStmt += viewName;
-
+
if (wxStrlen(colList))
{
sqlStmt += " (";
* userID != "" ... UserID set equal to 'userID'
*
* NOTE: ALL column bindings associated with this wxDB instance are unbound
- * by this function. This function should use its own wxDB instance
+ * by this function. This function should use its own wxDB instance
* to avoid undesired unbinding of columns.
*/
{
if (Dbms() == dbmsDBASE)
UserID = "";
- // Oracle user names may only be in uppercase, so force
+ // Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
UserID = UserID.Upper();
for (tbl = 0; tableName[tbl]; tbl++)
{
TableName = tableName[tbl];
- // Oracle table names are uppercase only, so force
+ // Oracle table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this
if (Dbms() == dbmsORACLE)
TableName = TableName.Upper();
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_CHAR, (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))
+ {
+ if (colInf[colNo].columnSize < 1)
+ {
+ // IODBC does not return a correct columnSize, so we set
+ // columnSize = bufferLength if no column size was returned
+ colInf[colNo].columnSize = colInf[colNo].bufferLength;
+ }
colInf[colNo].dbDataType = DB_DATA_TYPE_VARCHAR;
+ }
else if (!wxStricmp(typeInfInteger.TypeName,colInf[colNo].typeName))
colInf[colNo].dbDataType = DB_DATA_TYPE_INTEGER;
else if (!wxStricmp(typeInfFloat.TypeName,colInf[colNo].typeName))
* userID != "" ... UserID set equal to 'userID'
*
* NOTE: ALL column bindings associated with this wxDB instance are unbound
- * by this function. This function should use its own wxDB instance
+ * by this function. This function should use its own wxDB instance
* to avoid undesired unbinding of columns.
*/
{
if (Dbms() == dbmsDBASE)
UserID = "";
- // Oracle user names may only be in uppercase, so force
+ // Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
UserID = UserID.Upper();
}
TableName = tableName;
- // Oracle table names are uppercase only, so force
+ // Oracle table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this
if (Dbms() == dbmsORACLE)
TableName = TableName.Upper();
GetData( 6, SQL_C_CHAR, (UCHAR*) colInf[colNo].typeName, 128+1, &cb);
GetData( 7, SQL_C_SLONG, (UCHAR*) &colInf[colNo].columnSize, 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( 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);
// 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))
+ {
+ if (colInf[colNo].columnSize < 1)
+ {
+ // IODBC does not return a correct columnSize, so we set
+ // columnSize = bufferLength if no column size was returned
+ colInf[colNo].columnSize = colInf[colNo].bufferLength;
+ }
colInf[colNo].dbDataType = DB_DATA_TYPE_VARCHAR;
+ }
else if (!wxStricmp(typeInfInteger.TypeName,colInf[colNo].typeName))
colInf[colNo].dbDataType = DB_DATA_TYPE_INTEGER;
else if (!wxStricmp(typeInfFloat.TypeName,colInf[colNo].typeName))
* userID != "" ... UserID set equal to 'userID'
*
* NOTE: ALL column bindings associated with this wxDB instance are unbound
- * by this function. This function should use its own wxDB instance
+ * by this function. This function should use its own wxDB instance
* to avoid undesired unbinding of columns.
*/
{
if (Dbms() == dbmsDBASE)
UserID = "";
- // Oracle user names may only be in uppercase, so force
+ // Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
UserID = UserID.Upper();
// Loop through each table name
{
TableName = tableName;
- // Oracle table names are uppercase only, so force
+ // Oracle table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this
if (Dbms() == dbmsORACLE)
TableName = TableName.Upper();
* userID != "" ... UserID set equal to 'userID'
*
* NOTE: ALL column bindings associated with this wxDB instance are unbound
- * by this function. This function should use its own wxDB instance
+ * by this function. This function should use its own wxDB instance
* to avoid undesired unbinding of columns.
*/
{
if (Dbms() == dbmsDBASE)
UserID = "";
- // Oracle user names may only be in uppercase, so force
+ // Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
UserID = UserID.Upper();
* userID != "" ... UserID set equal to 'userID'
*
* NOTE: ALL column bindings associated with this wxDB instance are unbound
- * by this function. This function should use its own wxDB instance
+ * by this function. This function should use its own wxDB instance
* to avoid undesired unbinding of columns.
*/
{
if (Dbms() == dbmsDBASE)
UserID = "";
- // Oracle user names may only be in uppercase, so force
+ // Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
UserID = UserID.Upper();
else
UserID = "";
- // Oracle user names may only be in uppercase, so force
+ // Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
UserID = UserID.Upper();
TableName = tableName;
- // Oracle table names are uppercase only, so force
+ // Oracle table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this
if (Dbms() == dbmsORACLE)
TableName = TableName.Upper();
* - Cannot support selecting for update [::CanSelectForUpdate()]. Always returns FALSE
*
* POSTGRES
- * - Does not support the keywords 'ASC' or 'DESC' as of release v6.5.0
+ * - Does not support the keywords 'ASC' or 'DESC' as of release v6.5.0
*
*
*/
wxStrncpy(baseName,dbInf.dbmsName,25);
if (!wxStricmp(dbInf.dbmsName,"Adaptive Server Anywhere"))
return(dbmsSYBASE_ASA);
- if (!wxStricmp(dbInf.dbmsName,"SQL Server")) // Sybase Adaptive Server
+ if (!wxStricmp(dbInf.dbmsName,"SQL Server")) // Sybase Adaptive Server
return(dbmsSYBASE_ASE);
if (!wxStricmp(dbInf.dbmsName,"Microsoft SQL Server"))
return(dbmsMS_SQL_SERVER);
void WXDLLEXPORT CloseDbConnections(void)
{
DbList *pList, *pNext;
-
+
// Traverse the linked list closing database connections and freeing memory as I go.
for (pList = PtrBegDbList; pList; pList = pNext)
{
#endif
// wxUSE_ODBC
-