#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"
#include "wx/db.h"
#endif
-DbList WXDLLEXPORT *PtrBegDbList = 0;
+WXDLLEXPORT_DATA(wxDbList*) PtrBegDbList = 0;
char const *SQL_LOG_FILENAME = "sqllog.txt";
char const *SQL_CATALOG_FILENAME = "catalog.txt";
#endif
// SQL Log defaults to be used by GetDbConnection
-enum sqlLog SQLLOGstate = sqlLogOFF;
+wxSqlLogState SQLLOGstate = sqlLogOFF;
//char SQLLOGfn[DB_PATH_MAX+1] = SQL_LOG_FILENAME;
char *SQLLOGfn = (char*) SQL_LOG_FILENAME;
if (SQLGetInfo(hdbc, SQL_PROCEDURES, (UCHAR*) dbInf.procedureSupport, 2, &cb) != SQL_SUCCESS)
return(DispAllErrors(henv, hdbc));
- if (SQLGetInfo(hdbc, SQL_ACCESSIBLE_TABLES, (UCHAR*) dbInf.accessibleTables, 2, &cb) != SQL_SUCCESS)
- return(DispAllErrors(henv, hdbc));
-
if (SQLGetInfo(hdbc, SQL_CURSOR_COMMIT_BEHAVIOR, (UCHAR*) &dbInf.cursorCommitBehavior, sizeof(dbInf.cursorCommitBehavior), &cb) != SQL_SUCCESS)
return(DispAllErrors(henv, hdbc));
cout << "Max. Connections: " << dbInf.maxConnections << endl;
cout << "Outer Joins: " << dbInf.outerJoins << endl;
cout << "Support for Procedures: " << dbInf.procedureSupport << endl;
- cout << "All tables accessible : " << dbInf.accessibleTables << endl;
cout << "Cursor COMMIT Behavior: ";
switch(dbInf.cursorCommitBehavior)
/********** wxDB::getDataTypeInfo() **********/
-bool wxDB::getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo)
+bool wxDB::getDataTypeInfo(SWORD fSqlType, wxSqlTypeInfo &structSQLTypeInfo)
{
/*
* fSqlType will be something like SQL_VARCHAR. This parameter determines
* the data type inf. is gathered for.
*
- * SqlTypeInfo is a structure that is filled in with data type information,
+ * wxSqlTypeInfo is a structure that is filled in with data type information,
*/
RETCODE retcode;
SDWORD cbRet;
assert(nTables == 0);
#ifdef __WXDEBUG__
- CstructTablesInUse *tiu;
+ wxTablesInUse *tiu;
wxNode *pNode;
pNode = TablesInUse.First();
wxString s,s2;
while (pNode)
{
- tiu = (CstructTablesInUse *)pNode->Data();
+ tiu = (wxTablesInUse *)pNode->Data();
if (tiu->pDb == this)
{
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
}
* userID == "" ... UserID set equal to 'this->uid'
* 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
+ * to avoid undesired unbinding of columns.
*/
{
int noCols = 0;
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))
// 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))
} // wxDB::TableExists()
-
-/********** wxDB::TablePrivileges() **********/
-bool wxDB::TablePrivileges(const char* privilege, const char *tableName,
- const char *userID, const char *tablePath)
-{
- SqlPrivilegesInfo result;
- SDWORD cbRetVal;
- RETCODE retcode;
-
- //We probably need to be able to dynamically set this based on
- //the driver type, and state. - roger gammans
- char curRole[]="public";
-
- wxString UserID;
- wxString TableName;
-
- assert(tableName && wxStrlen(tableName));
-
- if (userID)
- {
- if (!wxStrlen(userID))
- UserID = uid;
- else
- UserID = userID;
- }
- else
- UserID = "";
-
- // Oracle user names may only be in uppercase, so force
- // the name to uppercase
- // if (Dbms() == dbmsORACLE)
- // UserID = UserID.Upper();
- //
- // However we fors case-insentive compare so it shouldn't matter.
-
-
- TableName = tableName;
- // 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();
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
-
- retcode = SQLTablePrivileges(hstmt,
- NULL, 0, // All qualifiers
- NULL, 0, // All owners
- (UCHAR FAR *)TableName.GetData(), SQL_NTS);
-
-#ifdef DBDEBUG_CONSOLE
- fprintf(stderr ,"SQLTablePrivileges() returned %i \n",retcode);
-#endif
-/*
- retcode = SQLBindCol (hstmt, 1, SQL_C_CHAR, &result.TableQualifier, 128, &cbRetVal);
- retcode = SQLBindCol (hstmt, 2, SQL_C_CHAR, &result.TableOwner, 128, &cbRetVal);
- retcode = SQLBindCol (hstmt, 3, SQL_C_CHAR, &result.TableName, 128, &cbRetVal);
- retcode = SQLBindCol (hstmt, 4, SQL_C_CHAR, &result.Grantor, 128, &cbRetVal);
- retcode = SQLBindCol (hstmt, 5, SQL_C_CHAR, &result.Grantee, 128, &cbRetVal);
- retcode = SQLBindCol (hstmt, 6, SQL_C_CHAR, &result.Privilege, 128, &cbRetVal);
- retcode = SQLBindCol (hstmt, 7, SQL_C_CHAR, &result.Grantable, 3, &cbRetVal);
-*/
- retcode = SQLFetch(hstmt);
- while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
- GetData(1, SQL_C_CHAR, &result.TableQualifier, 128, &cbRetVal);
- GetData(2, SQL_C_CHAR, &result.TableOwner, 128, &cbRetVal);
- GetData(3, SQL_C_CHAR, &result.TableName, 128, &cbRetVal);
- GetData(4, SQL_C_CHAR, &result.Grantor, 128, &cbRetVal);
- GetData(5, SQL_C_CHAR, &result.Grantee, 128, &cbRetVal);
- GetData(6, SQL_C_CHAR, &result.Privilege, 128, &cbRetVal);
- GetData(7, SQL_C_CHAR, &result.Grantable, 3, &cbRetVal);
-
-#ifdef DBDEBUG_CONSOLE
- fprintf(stderr,"Scanning %s privilege on table %s.%s granted by %s to %s\n",
- result.Privilege,result.TableOwner,result.TableName,
- result.Grantor, result.Grantee);
-#endif
- if (UserID.IsSameAs(result.TableOwner,false))
- {
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return true;
- }
- if (UserID.IsSameAs(result.Grantee,false) &&
- !strcmp(result.Privilege, privilege))
- {
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return true;
- }
- if (!strcmp(result.Grantee,curRole) &&
- !strcmp(result.Privilege, privilege))
- {
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return true;
- }
- retcode = SQLFetch(hstmt);
- }
-
- SQLFreeStmt(hstmt, SQL_CLOSE);
- return false;
-} // wxDB::TablePrivileges()
-
-
/********** wxDB::SqlLog() **********/
-bool wxDB::SqlLog(enum sqlLog state, const char *filename, bool append)
+bool wxDB::SqlLog(wxSqlLogState state, const char *filename, bool append)
{
- assert(state == sqlLogON || state == sqlLogOFF);
- assert(state == sqlLogOFF || filename);
+ assert(state == sqlLogON || state == sqlLogOFF);
+ assert(state == sqlLogOFF || filename);
- if (state == sqlLogON)
- {
- if (fpSqlLog == 0)
- {
- fpSqlLog = fopen(filename, (append ? "at" : "wt"));
- if (fpSqlLog == NULL)
- return(FALSE);
- }
- }
- else // sqlLogOFF
- {
- if (fpSqlLog)
- {
- if (fclose(fpSqlLog))
- return(FALSE);
- fpSqlLog = 0;
- }
- }
+ if (state == sqlLogON)
+ {
+ if (fpSqlLog == 0)
+ {
+ fpSqlLog = fopen(filename, (append ? "at" : "wt"));
+ if (fpSqlLog == NULL)
+ return(FALSE);
+ }
+ }
+ else // sqlLogOFF
+ {
+ if (fpSqlLog)
+ {
+ if (fclose(fpSqlLog))
+ return(FALSE);
+ fpSqlLog = 0;
+ }
+ }
- sqlLogState = state;
- return(TRUE);
+ sqlLogState = state;
+ return(TRUE);
} // wxDB::SqlLog()
/********** wxDB::Dbms() **********/
-DBMS wxDB::Dbms(void)
+wxDBMS wxDB::Dbms(void)
/*
* Be aware that not all database engines use the exact same syntax, and not
* every ODBC compliant database is compliant to the same level of compliancy.
* DBASE
* - Does not support the SQL_TIMESTAMP structure
* - Supports only one cursor and one connect (apparently? with Microsoft driver only?)
- * - Does not automatically create the primary index if the 'keyField' param of SetColDef
- * is TRUE. The user must create ALL indexes from their program.
+ * - Does not automatically create the primary index if the 'keyField' param of SetColDef
+ * is TRUE. The user must create ALL indexes from their program.
* - Table names can only be 8 characters long
* - Column names can only be 10 characters long
*
} // wxDB::Dbms()
-/********** GetDbConnection() **********/
-wxDB WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors)
+/********** wxDbGetConnection() **********/
+wxDB WXDLLEXPORT *wxDbGetConnection(wxDbConnectInf *pDbConfig, bool FwdOnlyCursors)
{
- DbList *pList;
+ wxDbList *pList;
// Scan the linked list searching for an available database connection
// that's already been opened but is currently not in use.
{
// The database connection must be for the same datasource
// name and must currently not be in use.
- if (pList->Free && (! wxStrcmp(pDbStuff->Dsn, pList->Dsn))) // Found a free connection
+ if (pList->Free && (! wxStrcmp(pDbConfig->Dsn, pList->Dsn))) // Found a free connection
{
pList->Free = FALSE;
return(pList->PtrDb);
// Find the end of the list
for (pList = PtrBegDbList; pList->PtrNext; pList = pList->PtrNext);
// Append a new list item
- pList->PtrNext = new DbList;
+ pList->PtrNext = new wxDbList;
pList->PtrNext->PtrPrev = pList;
pList = pList->PtrNext;
}
else // Empty list
{
// Create the first node on the list
- pList = PtrBegDbList = new DbList;
+ pList = PtrBegDbList = new wxDbList;
pList->PtrPrev = 0;
}
// Initialize new node in the linked list
pList->PtrNext = 0;
pList->Free = FALSE;
- wxStrcpy(pList->Dsn, pDbStuff->Dsn);
- pList->PtrDb = new wxDB(pDbStuff->Henv,FwdOnlyCursors);
+ wxStrcpy(pList->Dsn, pDbConfig->Dsn);
+ pList->PtrDb = new wxDB(pDbConfig->Henv,FwdOnlyCursors);
// Connect to the datasource
- if (pList->PtrDb->Open(pDbStuff->Dsn, pDbStuff->Uid, pDbStuff->AuthStr))
+ if (pList->PtrDb->Open(pDbConfig->Dsn, pDbConfig->Uid, pDbConfig->AuthStr))
{
pList->PtrDb->SqlLog(SQLLOGstate,SQLLOGfn,TRUE);
return(pList->PtrDb);
return(0);
}
-} // GetDbConnection()
+} // wxDbGetConnection()
-/********** FreeDbConnection() **********/
-bool WXDLLEXPORT FreeDbConnection(wxDB *pDb)
+/********** wxDbFreeConnection() **********/
+bool WXDLLEXPORT wxDbFreeConnection(wxDB *pDb)
{
- DbList *pList;
+ wxDbList *pList;
// Scan the linked list searching for the database connection
for (pList = PtrBegDbList; pList; pList = pList->PtrNext)
// Never found the database object, return failure
return(FALSE);
-} // FreeDbConnection()
+} // wxDbFreeConnection()
-/********** CloseDbConnections() **********/
-void WXDLLEXPORT CloseDbConnections(void)
+/********** wxDbCloseConnections() **********/
+void WXDLLEXPORT wxDbCloseConnections(void)
{
- DbList *pList, *pNext;
+ wxDbList *pList, *pNext;
// Traverse the linked list closing database connections and freeing memory as I go.
for (pList = PtrBegDbList; pList; pList = pNext)
// Mark the list as empty
PtrBegDbList = 0;
-} // CloseDbConnections()
+} // wxDbCloseConnections()
-/********** NumberDbConnectionsInUse() **********/
-int WXDLLEXPORT NumberDbConnectionsInUse(void)
+/********** wxDbNumberConnectionsInUse() **********/
+int WXDLLEXPORT wxDbConnectionsInUse(void)
{
- DbList *pList;
+ wxDbList *pList;
int cnt = 0;
// Scan the linked list counting db connections that are currently in use
return(cnt);
-} // NumberDbConnectionsInUse()
+} // wxDbConnectionsInUse()
-/********** SqlLog() **********/
-bool SqlLog(enum sqlLog state, char *filename)
+/********** wxDbSqlLog() **********/
+bool wxDbSqlLog(wxSqlLogState state, char *filename)
{
bool append = FALSE;
- DbList *pList;
+ wxDbList *pList;
for (pList = PtrBegDbList; pList; pList = pList->PtrNext)
{
return(TRUE);
-} // SqlLog()
+} // wxDbSqlLog()
-/********** GetDataSource() **********/
-bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax,
+#if 0
+/********** wxDbCreateDataSource() **********/
+int wxDbCreateDataSource(const char *driverName, const char *dsn, const char *description,
+ bool sysDSN, const char *defDir, wxWindow *parent)
+/*
+ * !!!! ONLY FUNCTIONAL UNDER MSW with VC6 !!!!
+ * Very rudimentary creation of an ODBC data source.
+ */
+{
+ int result = FALSE;
+
+#ifdef __WXMSW__
+ int dsnLocation;
+ wxString setupStr;
+
+ if (sysDSN)
+ dsnLocation = ODBC_ADD_SYS_DSN;
+ else
+ dsnLocation = ODBC_ADD_DSN;
+
+ // NOTE: The decimal 2 is an invalid character in all keyword pairs
+ // so that is why I used it, as wxString does not deal well with
+ // embedded nulls in strings
+ setupStr.sprintf("DSN=%s%cDescription=%s%cDefaultDir=%s%c",dsn,2,description,2,defDir,2);
+
+ // Replace the separator from above with the '\0' seperator needed
+ // by the SQLConfigDataSource() function
+ int k;
+ do
+ {
+ k = setupStr.Find((wxChar)2,TRUE);
+ if (k != wxNOT_FOUND)
+ setupStr[(UINT)k] = '\0';
+ }
+ while (k != wxNOT_FOUND);
+
+ result = SQLConfigDataSource((HWND)parent->GetHWND(), dsnLocation,
+ driverName, setupStr.GetData());
+
+ if (!result)
+ {
+ // check for errors caused by ConfigDSN based functions
+ DWORD retcode = 0;
+ WORD cb;
+ wxChar errMsg[500+1];
+ errMsg[0] = '\0';
+
+ SQLInstallerError(1,&retcode,errMsg,500,&cb);
+ if (retcode)
+ {
+// logError(errMsg, sqlState);
+// if (!silent)
+// {
+#ifdef DBDEBUG_CONSOLE
+ // When run in console mode, use standard out to display errors.
+ cout << errMsg << endl;
+ cout << "Press any key to continue..." << endl;
+ getchar();
+#endif // DBDEBUG_CONSOLE
+// }
+
+#ifdef __WXDEBUG__
+ wxLogDebug(errMsg,"DEBUG MESSAGE");
+#endif // __WXDEBUG__
+ }
+ }
+ else
+ result = TRUE;
+
+#else // __WXMSW__
+#ifdef __WXDEBUG__
+ wxLogDebug("wxDbCreateDataSource() not available except under MSW","DEBUG MESSAGE");
+#endif
+#endif // __WXMSW__
+
+ return result;
+
+} // wxDbCreateDataSource()
+#endif
+
+
+/********** wxDbGetDataSource() **********/
+bool wxDbGetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax,
UWORD direction)
/*
* Dsn and DsDesc will contain the data source name and data source
else
return(FALSE);
-} // GetDataSource()
+} // wxDbGetDataSource()
+
+// Change this to 0 to remove use of all deprecated functions
+#if 1
+/********************************************************************
+ ********************************************************************
+ *
+ * The following functions are all DEPRECATED and are included for
+ * backward compatability reasons only
+ *
+ ********************************************************************
+ ********************************************************************/
+bool SqlLog(sqlLog state, char *filename)
+{
+ return wxDbSqlLog((enum wxSqlLogState)state, filename);
+}
+/***** DEPRECATED: use wxGetDataSource() *****/
+bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax,
+ UWORD direction)
+{
+ return wxDbGetDataSource(henv, Dsn, DsnMax, DsDesc, DsDescMax, direction);
+}
+/***** DEPRECATED: use wxDbGetConnection() *****/
+wxDB WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors)
+{
+ return wxDbGetConnection((wxDbConnectInf *)pDbStuff, FwdOnlyCursors);
+}
+/***** DEPRECATED: use wxDbFreeConnection() *****/
+bool WXDLLEXPORT FreeDbConnection(wxDB *pDb)
+{
+ return wxDbFreeConnection(pDb);
+}
+/***** DEPRECATED: use wxDbCloseConnections() *****/
+void WXDLLEXPORT CloseDbConnections(void)
+{
+ wxDbCloseConnections();
+}
+/***** DEPRECATED: use wxDbConnectionsInUse() *****/
+int WXDLLEXPORT NumberDbConnectionsInUse(void)
+{
+ return wxDbConnectionsInUse();
+}
#endif
- // wxUSE_ODBC
+
+
+
+
+#endif
+ // wxUSE_ODBC