Added support for creating forward or backward scrolling cursors support at run-time versus compile time. Default behavior will be determined by wxODBC_FWD_ONLY_CURSORS set in setup.h
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -328,6 +328,8 @@ private:
|
|||||||
bool setConnectionOptions(void);
|
bool setConnectionOptions(void);
|
||||||
void logError(const char *errMsg, const char *SQLState);
|
void logError(const char *errMsg, const char *SQLState);
|
||||||
|
|
||||||
|
bool fwdOnlyCursors;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// The following structure contains database information gathered from the
|
// The following structure contains database information gathered from the
|
||||||
@@ -393,7 +395,7 @@ public:
|
|||||||
SqlTypeInfo typeInfVarchar, typeInfInteger, typeInfFloat, typeInfDate;
|
SqlTypeInfo typeInfVarchar, typeInfInteger, typeInfFloat, typeInfDate;
|
||||||
|
|
||||||
// Public member functions
|
// Public member functions
|
||||||
wxDB(HENV &aHenv);
|
wxDB(HENV &aHenv, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
|
||||||
bool Open(char *Dsn, char *Uid, char *AuthStr); // Data Source Name, User ID, Password
|
bool Open(char *Dsn, char *Uid, char *AuthStr); // Data Source Name, User ID, Password
|
||||||
void Close(void);
|
void Close(void);
|
||||||
bool CommitTrans(void);
|
bool CommitTrans(void);
|
||||||
@@ -423,6 +425,7 @@ public:
|
|||||||
bool SqlLog(enum sqlLog state, const char *filename = "sqllog.txt", bool append = FALSE);
|
bool SqlLog(enum sqlLog state, const char *filename = "sqllog.txt", bool append = FALSE);
|
||||||
bool WriteSqlLog(const char *logMsg);
|
bool WriteSqlLog(const char *logMsg);
|
||||||
DBMS Dbms(void);
|
DBMS Dbms(void);
|
||||||
|
bool FwdOnlyCursors(void) {return fwdOnlyCursors;}
|
||||||
|
|
||||||
}; // wxDB
|
}; // wxDB
|
||||||
|
|
||||||
@@ -456,7 +459,7 @@ class CstructTablesInUse : public wxObject
|
|||||||
// for other code segments to use, or close all of them when the application has
|
// for other code segments to use, or close all of them when the application has
|
||||||
// completed.
|
// completed.
|
||||||
|
|
||||||
wxDB WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff);
|
wxDB WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
|
||||||
bool WXDLLEXPORT FreeDbConnection(wxDB *pDb);
|
bool WXDLLEXPORT FreeDbConnection(wxDB *pDb);
|
||||||
void WXDLLEXPORT CloseDbConnections(void);
|
void WXDLLEXPORT CloseDbConnections(void);
|
||||||
int WXDLLEXPORT NumberDbConnectionsInUse(void);
|
int WXDLLEXPORT NumberDbConnectionsInUse(void);
|
||||||
|
@@ -157,12 +157,14 @@ public:
|
|||||||
bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
|
bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
|
||||||
bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); }
|
bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); }
|
||||||
bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); }
|
bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); }
|
||||||
#if !wxODBC_FWD_ONLY_CURSORS
|
|
||||||
bool GetPrev(void) { return(getRec(SQL_FETCH_PRIOR)); }
|
/***** These four functions only work with wxDB instances that are defined *****
|
||||||
bool operator--(int) { return(getRec(SQL_FETCH_PRIOR)); }
|
***** as not being FwdOnlyCursors *****/
|
||||||
bool GetFirst(void) { return(getRec(SQL_FETCH_FIRST)); }
|
bool GetPrev(void);
|
||||||
bool GetLast(void) { return(getRec(SQL_FETCH_LAST)); }
|
bool operator--(int);
|
||||||
#endif
|
bool GetFirst(void);
|
||||||
|
bool GetLast(void);
|
||||||
|
|
||||||
bool IsCursorClosedOnCommit(void);
|
bool IsCursorClosedOnCommit(void);
|
||||||
bool IsColNull(int colNo);
|
bool IsColNull(int colNo);
|
||||||
UWORD GetRowNum(void);
|
UWORD GetRowNum(void);
|
||||||
|
@@ -111,7 +111,7 @@ char SQLLOGfn[DB_PATH_MAX+1] = "sqllog.txt";
|
|||||||
char DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
|
char DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
|
||||||
|
|
||||||
/********** wxDB Constructor **********/
|
/********** wxDB Constructor **********/
|
||||||
wxDB::wxDB(HENV &aHenv)
|
wxDB::wxDB(HENV &aHenv, bool FwdOnlyCursors)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -155,6 +155,7 @@ wxDB::wxDB(HENV &aHenv)
|
|||||||
|
|
||||||
// Copy the HENV into the db class
|
// Copy the HENV into the db class
|
||||||
henv = aHenv;
|
henv = aHenv;
|
||||||
|
fwdOnlyCursors = FwdOnlyCursors;
|
||||||
|
|
||||||
// Allocate a data source connection handle
|
// Allocate a data source connection handle
|
||||||
if (SQLAllocConnect(henv, &hdbc) != SQL_SUCCESS)
|
if (SQLAllocConnect(henv, &hdbc) != SQL_SUCCESS)
|
||||||
@@ -178,11 +179,11 @@ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr)
|
|||||||
|
|
||||||
RETCODE retcode;
|
RETCODE retcode;
|
||||||
|
|
||||||
#if !wxODBC_FWD_ONLY_CURSORS
|
if (!FwdOnlyCursors())
|
||||||
|
{
|
||||||
// Specify that the ODBC cursor library be used, if needed. This must be
|
// Specify that the ODBC cursor library be used, if needed. This must be
|
||||||
// specified before the connection is made.
|
// specified before the connection is made.
|
||||||
retcode = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_IF_NEEDED);
|
retcode = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_IF_NEEDED);
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
if (retcode == SQL_SUCCESS)
|
if (retcode == SQL_SUCCESS)
|
||||||
@@ -190,8 +191,7 @@ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr)
|
|||||||
else
|
else
|
||||||
cout << "SQLSetConnectOption(CURSOR_LIB) failed" << endl;
|
cout << "SQLSetConnectOption(CURSOR_LIB) failed" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Connect to the data source
|
// Connect to the data source
|
||||||
retcode = SQLConnect(hdbc, (UCHAR FAR *) Dsn, SQL_NTS,
|
retcode = SQLConnect(hdbc, (UCHAR FAR *) Dsn, SQL_NTS,
|
||||||
@@ -1688,15 +1688,12 @@ bool wxDB::WriteSqlLog(const char *logMsg)
|
|||||||
*/
|
*/
|
||||||
DBMS wxDB::Dbms(void)
|
DBMS wxDB::Dbms(void)
|
||||||
{
|
{
|
||||||
wxChar baseName[25];
|
wxChar baseName[25+1];
|
||||||
|
|
||||||
wxStrncpy(baseName,dbInf.dbmsName,6);
|
wxStrncpy(baseName,dbInf.dbmsName,25);
|
||||||
baseName[6] = 0;
|
|
||||||
if (!wxStricmp(baseName,"Oracle"))
|
|
||||||
return(dbmsORACLE);
|
|
||||||
if (!wxStricmp(dbInf.dbmsName,"Adaptive Server Anywhere"))
|
if (!wxStricmp(dbInf.dbmsName,"Adaptive Server Anywhere"))
|
||||||
return(dbmsSYBASE_ASA);
|
return(dbmsSYBASE_ASA);
|
||||||
if (!wxStricmp(dbInf.dbmsName,"SQL Server")) // Sybase Adaptive Server Enterprise
|
if (!wxStricmp(dbInf.dbmsName,"SQL Server")) // Sybase Adaptive Server
|
||||||
return(dbmsSYBASE_ASE);
|
return(dbmsSYBASE_ASE);
|
||||||
if (!wxStricmp(dbInf.dbmsName,"Microsoft SQL Server"))
|
if (!wxStricmp(dbInf.dbmsName,"Microsoft SQL Server"))
|
||||||
return(dbmsMS_SQL_SERVER);
|
return(dbmsMS_SQL_SERVER);
|
||||||
@@ -1704,24 +1701,29 @@ DBMS wxDB::Dbms(void)
|
|||||||
return(dbmsMY_SQL);
|
return(dbmsMY_SQL);
|
||||||
if (!wxStricmp(dbInf.dbmsName,"PostgreSQL")) // v6.5.0
|
if (!wxStricmp(dbInf.dbmsName,"PostgreSQL")) // v6.5.0
|
||||||
return(dbmsPOSTGRES);
|
return(dbmsPOSTGRES);
|
||||||
if (!wxStricmp(dbInf.dbmsName,"ACCESS"))
|
|
||||||
return(dbmsACCESS);
|
|
||||||
wxStrncpy(baseName,dbInf.dbmsName,5);
|
|
||||||
baseName[5] = 0;
|
|
||||||
if (!wxStricmp(baseName,"DBASE"))
|
|
||||||
return(dbmsDBASE);
|
|
||||||
wxStrncpy(baseName,dbInf.dbmsName,8);
|
|
||||||
baseName[8] = 0;
|
baseName[8] = 0;
|
||||||
if (!wxStricmp(baseName,"Informix"))
|
if (!wxStricmp(baseName,"Informix"))
|
||||||
return(dbmsINFORMIX);
|
return(dbmsINFORMIX);
|
||||||
|
|
||||||
return(dbmsUNIDENTIFIED);
|
baseName[6] = 0;
|
||||||
|
if (!wxStricmp(baseName,"Oracle"))
|
||||||
|
return(dbmsORACLE);
|
||||||
|
if (!wxStricmp(dbInf.dbmsName,"ACCESS"))
|
||||||
|
return(dbmsACCESS);
|
||||||
|
if (!wxStricmp(dbInf.dbmsName,"MySQL"))
|
||||||
|
return(dbmsMY_SQL);
|
||||||
|
|
||||||
|
baseName[5] = 0;
|
||||||
|
if (!wxStricmp(baseName,"DBASE"))
|
||||||
|
return(dbmsDBASE);
|
||||||
|
|
||||||
|
return(dbmsUNIDENTIFIED);
|
||||||
} // wxDB::Dbms()
|
} // wxDB::Dbms()
|
||||||
|
|
||||||
|
|
||||||
/********** GetDbConnection() **********/
|
/********** GetDbConnection() **********/
|
||||||
wxDB WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff)
|
wxDB WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors)
|
||||||
{
|
{
|
||||||
DbList *pList;
|
DbList *pList;
|
||||||
|
|
||||||
@@ -1760,7 +1762,7 @@ wxDB WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff)
|
|||||||
pList->PtrNext = 0;
|
pList->PtrNext = 0;
|
||||||
pList->Free = FALSE;
|
pList->Free = FALSE;
|
||||||
wxStrcpy(pList->Dsn, pDbStuff->Dsn);
|
wxStrcpy(pList->Dsn, pDbStuff->Dsn);
|
||||||
pList->PtrDb = new wxDB(pDbStuff->Henv);
|
pList->PtrDb = new wxDB(pDbStuff->Henv,FwdOnlyCursors);
|
||||||
|
|
||||||
// Connect to the datasource
|
// Connect to the datasource
|
||||||
if (pList->PtrDb->Open(pDbStuff->Dsn, pDbStuff->Uid, pDbStuff->AuthStr))
|
if (pList->PtrDb->Open(pDbStuff->Dsn, pDbStuff->Uid, pDbStuff->AuthStr))
|
||||||
|
@@ -461,31 +461,31 @@ bool wxTable::getRec(UWORD fetchType)
|
|||||||
{
|
{
|
||||||
RETCODE retcode;
|
RETCODE retcode;
|
||||||
|
|
||||||
#if !wxODBC_FWD_ONLY_CURSORS
|
if (!pDb->FwdOnlyCursors())
|
||||||
|
|
||||||
// Fetch the NEXT, PREV, FIRST or LAST record, depending on fetchType
|
|
||||||
UDWORD cRowsFetched;
|
|
||||||
UWORD rowStatus;
|
|
||||||
|
|
||||||
// if ((retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus)) != SQL_SUCCESS)
|
|
||||||
retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus);
|
|
||||||
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
|
||||||
if (retcode == SQL_NO_DATA_FOUND)
|
|
||||||
return(FALSE);
|
|
||||||
else
|
|
||||||
return(pDb->DispAllErrors(henv, hdbc, hstmt));
|
|
||||||
#else
|
|
||||||
|
|
||||||
// Fetch the next record from the record set
|
|
||||||
retcode = SQLFetch(hstmt);
|
|
||||||
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
|
||||||
{
|
{
|
||||||
if (retcode == SQL_NO_DATA_FOUND)
|
// Fetch the NEXT, PREV, FIRST or LAST record, depending on fetchType
|
||||||
return(FALSE);
|
UDWORD cRowsFetched;
|
||||||
else
|
UWORD rowStatus;
|
||||||
return(pDb->DispAllErrors(henv, hdbc, hstmt));
|
|
||||||
|
retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus);
|
||||||
|
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
||||||
|
if (retcode == SQL_NO_DATA_FOUND)
|
||||||
|
return(FALSE);
|
||||||
|
else
|
||||||
|
return(pDb->DispAllErrors(henv, hdbc, hstmt));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fetch the next record from the record set
|
||||||
|
retcode = SQLFetch(hstmt);
|
||||||
|
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
||||||
|
{
|
||||||
|
if (retcode == SQL_NO_DATA_FOUND)
|
||||||
|
return(FALSE);
|
||||||
|
else
|
||||||
|
return(pDb->DispAllErrors(henv, hdbc, hstmt));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Completed successfully
|
// Completed successfully
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
@@ -660,6 +660,54 @@ bool wxTable::QueryOnKeyFields(bool forUpdate, bool distinct)
|
|||||||
|
|
||||||
} // wxTable::QueryOnKeyFields()
|
} // wxTable::QueryOnKeyFields()
|
||||||
|
|
||||||
|
/********** wxTable::GetPrev() **********/
|
||||||
|
bool wxTable::GetPrev(void)
|
||||||
|
{
|
||||||
|
if (pDb->FwdOnlyCursors())
|
||||||
|
{
|
||||||
|
wxFAIL_MSG(wxT("GetPrev()::Backward scrolling cursors are not enabled for this instance of wxTable"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return(getRec(SQL_FETCH_PRIOR));
|
||||||
|
} // wxTable::GetPrev()
|
||||||
|
|
||||||
|
/********** wxTable::operator-- **********/
|
||||||
|
bool wxTable::operator--(int)
|
||||||
|
{
|
||||||
|
if (pDb->FwdOnlyCursors())
|
||||||
|
{
|
||||||
|
wxFAIL_MSG(wxT("operator--:Backward scrolling cursors are not enabled for this instance of wxTable"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return(getRec(SQL_FETCH_PRIOR));
|
||||||
|
} // wxTable::operator--
|
||||||
|
|
||||||
|
/********** wxTable::GetFirst() **********/
|
||||||
|
bool wxTable::GetFirst(void)
|
||||||
|
{
|
||||||
|
if (pDb->FwdOnlyCursors())
|
||||||
|
{
|
||||||
|
wxFAIL_MSG(wxT("GetFirst():Backward scrolling cursors are not enabled for this instance of wxTable"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return(getRec(SQL_FETCH_FIRST));
|
||||||
|
} // wxTable::GetFirst()
|
||||||
|
|
||||||
|
/********** wxTable::GetLast() **********/
|
||||||
|
bool wxTable::GetLast(void)
|
||||||
|
{
|
||||||
|
if (pDb->FwdOnlyCursors())
|
||||||
|
{
|
||||||
|
wxFAIL_MSG(wxT("GetLast()::Backward scrolling cursors are not enabled for this instance of wxTable"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return(getRec(SQL_FETCH_LAST));
|
||||||
|
} // wxTable::GetLast()
|
||||||
|
|
||||||
/********** wxTable::GetSelectStmt() **********/
|
/********** wxTable::GetSelectStmt() **********/
|
||||||
void wxTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
void wxTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user