Added #if wxODBC_BACKWARD_COMPATABILITY checking to determine whether deprecated functions/classes/enums/etc are available or not.
Cleaned up various naming conventions. from/orderBy/where are now wxString type if wxODBC_BACKWARD_COMPATABILITY is 0 Accessors added for member variables If wxODBC_BACKWARD_COMPATABILITY is 0, then member variables that have accessors are now defined in the PRIVATE: section of the class, rather than the PUBLIC:. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7138 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -371,7 +371,7 @@ private:
|
|||||||
bool getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo);
|
bool getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo);
|
||||||
bool setConnectionOptions(void);
|
bool setConnectionOptions(void);
|
||||||
void logError(const char *errMsg, const char *SQLState);
|
void logError(const char *errMsg, const char *SQLState);
|
||||||
|
#if !wxODBC_BACKWARD_COMPATABILITY
|
||||||
// ODBC handles
|
// ODBC handles
|
||||||
HENV henv; // ODBC Environment handle
|
HENV henv; // ODBC Environment handle
|
||||||
HDBC hdbc; // ODBC DB Connection handle
|
HDBC hdbc; // ODBC DB Connection handle
|
||||||
@@ -380,7 +380,35 @@ private:
|
|||||||
//Error reporting mode
|
//Error reporting mode
|
||||||
bool silent;
|
bool silent;
|
||||||
|
|
||||||
|
// Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
|
||||||
|
unsigned int nTables;
|
||||||
|
|
||||||
|
// Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
|
||||||
|
//
|
||||||
|
// This information is obtained from the ODBC driver by use of the
|
||||||
|
// SQLGetTypeInfo() function. The key piece of information is the
|
||||||
|
// type name the data source uses for each logical data type.
|
||||||
|
// e.g. VARCHAR; Oracle calls it VARCHAR2.
|
||||||
|
wxDbSqlTypeInfo typeInfVarchar;
|
||||||
|
wxDbSqlTypeInfo typeInfInteger;
|
||||||
|
wxDbSqlTypeInfo typeInfFloat;
|
||||||
|
wxDbSqlTypeInfo typeInfDate;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
|
// ODBC handles
|
||||||
|
HENV henv; // ODBC Environment handle
|
||||||
|
HDBC hdbc; // ODBC DB Connection handle
|
||||||
|
HSTMT hstmt; // ODBC Statement handle
|
||||||
|
|
||||||
|
//Error reporting mode
|
||||||
|
bool silent;
|
||||||
|
|
||||||
|
// Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
|
||||||
|
unsigned int nTables;
|
||||||
|
#endif
|
||||||
|
|
||||||
// The following structure contains database information gathered from the
|
// The following structure contains database information gathered from the
|
||||||
// datasource when the datasource is first opened.
|
// datasource when the datasource is first opened.
|
||||||
struct
|
struct
|
||||||
@@ -425,16 +453,18 @@ public:
|
|||||||
SDWORD nativeError;
|
SDWORD nativeError;
|
||||||
wxChar sqlState[20];
|
wxChar sqlState[20];
|
||||||
|
|
||||||
// Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
unsigned int nTables;
|
|
||||||
|
|
||||||
// Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
|
// Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
|
||||||
//
|
//
|
||||||
// This information is obtained from the ODBC driver by use of the
|
// This information is obtained from the ODBC driver by use of the
|
||||||
// SQLGetTypeInfo() function. The key piece of information is the
|
// SQLGetTypeInfo() function. The key piece of information is the
|
||||||
// type name the data source uses for each logical data type.
|
// type name the data source uses for each logical data type.
|
||||||
// e.g. VARCHAR; Oracle calls it VARCHAR2.
|
// e.g. VARCHAR; Oracle calls it VARCHAR2.
|
||||||
wxDbSqlTypeInfo typeInfVarchar, typeInfInteger, typeInfFloat, typeInfDate;
|
wxDbSqlTypeInfo typeInfVarchar;
|
||||||
|
wxDbSqlTypeInfo typeInfInteger;
|
||||||
|
wxDbSqlTypeInfo typeInfFloat;
|
||||||
|
wxDbSqlTypeInfo typeInfDate;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Public member functions
|
// Public member functions
|
||||||
wxDb(HENV &aHenv, bool FwdOnlyCursors=(bool)TRUE);
|
wxDb(HENV &aHenv, bool FwdOnlyCursors=(bool)TRUE);
|
||||||
@@ -466,12 +496,25 @@ public:
|
|||||||
HENV GetHENV(void) {return henv;}
|
HENV GetHENV(void) {return henv;}
|
||||||
HDBC GetHDBC(void) {return hdbc;}
|
HDBC GetHDBC(void) {return hdbc;}
|
||||||
HSTMT GetHSTMT(void) {return hstmt;}
|
HSTMT GetHSTMT(void) {return hstmt;}
|
||||||
|
int GetTableCount() {return nTables;}; // number of tables using this connection
|
||||||
|
wxDbSqlTypeInfo GetTypeInfVarchar(){return typeInfVarchar;}
|
||||||
|
wxDbSqlTypeInfo GetTypeInfInteger(){return typeInfInteger;}
|
||||||
|
wxDbSqlTypeInfo GetTypeInfFloat() {return typeInfFloat;}
|
||||||
|
wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;}
|
||||||
|
|
||||||
bool TableExists(const char *tableName, const char *userID=NULL, const char *path=NULL); // Table name can refer to a table, view, alias or synonym
|
bool TableExists(const char *tableName, const char *userID=NULL, const char *path=NULL); // Table name can refer to a table, view, alias or synonym
|
||||||
void LogError(const char *errMsg, const char *SQLState = 0) {logError(errMsg, SQLState);}
|
void LogError(const char *errMsg, const char *SQLState = 0) {logError(errMsg, SQLState);}
|
||||||
|
void SetDebugErrorMessages(bool state) { silent = !state; }
|
||||||
bool SetSqlLogging(wxDbSqlLogState state, const wxChar *filename = SQL_LOG_FILENAME, bool append = FALSE);
|
bool SetSqlLogging(wxDbSqlLogState state, const wxChar *filename = SQL_LOG_FILENAME, bool append = FALSE);
|
||||||
bool WriteSqlLog(const wxChar *logMsg);
|
bool WriteSqlLog(const wxChar *logMsg);
|
||||||
wxDBMS Dbms(void);
|
wxDBMS Dbms(void);
|
||||||
bool FwdOnlyCursors(void) {return fwdOnlyCursors;}
|
bool FwdOnlyCursors(void) {return fwdOnlyCursors;}
|
||||||
|
|
||||||
|
// These two functions are provided strictly for use by wxDbTable.
|
||||||
|
// DO NOT USE THESE FUNCTIONS, OR MEMORY LEAKS MAY OCCUR
|
||||||
|
void incrementTableCount() { nTables++; return; }
|
||||||
|
void decrementTableCount() { nTables--; return; }
|
||||||
|
|
||||||
}; // wxDb
|
}; // wxDb
|
||||||
|
|
||||||
|
|
||||||
@@ -528,7 +571,7 @@ bool WXDLLEXPORT wxDbGetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsD
|
|||||||
|
|
||||||
|
|
||||||
// Change this to 0 to remove use of all deprecated functions
|
// Change this to 0 to remove use of all deprecated functions
|
||||||
#if 1
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
//#################################################################################
|
//#################################################################################
|
||||||
//############### DEPRECATED functions for backward compatability #################
|
//############### DEPRECATED functions for backward compatability #################
|
||||||
//#################################################################################
|
//#################################################################################
|
||||||
|
@@ -108,9 +108,12 @@ private:
|
|||||||
bool execUpdate(const char *pSqlStmt);
|
bool execUpdate(const char *pSqlStmt);
|
||||||
bool query(int queryType, bool forUpdate, bool distinct, const char *pSqlStmt = 0);
|
bool query(int queryType, bool forUpdate, bool distinct, const char *pSqlStmt = 0);
|
||||||
|
|
||||||
public:
|
#if !wxODBC_BACKWARD_COMPATABILITY
|
||||||
// Pointer to the database object this table belongs to
|
// these were public
|
||||||
wxDb *pDb;
|
// Where, Order By and From clauses
|
||||||
|
wxString where; // Standard SQL where clause, minus the word WHERE
|
||||||
|
wxString orderBy; // Standard SQL order by clause, minus the ORDER BY
|
||||||
|
wxString from; // Allows for joins in a wxDbTable::Query(). Format: ",tbl,tbl..."
|
||||||
|
|
||||||
// ODBC Handles
|
// ODBC Handles
|
||||||
HENV henv; // ODBC Environment handle
|
HENV henv; // ODBC Environment handle
|
||||||
@@ -123,35 +126,93 @@ public:
|
|||||||
HSTMT hstmtInternal; // ODBC Statement handle used internally only
|
HSTMT hstmtInternal; // ODBC Statement handle used internally only
|
||||||
HSTMT *hstmtCount; // ODBC Statement handle used by Count() function (No binding of columns)
|
HSTMT *hstmtCount; // ODBC Statement handle used by Count() function (No binding of columns)
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
bool selectForUpdate;
|
||||||
|
|
||||||
|
// Pointer to the database object this table belongs to
|
||||||
|
wxDb *pDb;
|
||||||
|
|
||||||
// Table Inf.
|
// Table Inf.
|
||||||
|
char tablePath[wxDB_PATH_MAX]; // needed for dBase tables
|
||||||
char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
|
char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
|
||||||
char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
|
char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
|
||||||
int noCols; // # of columns in the table
|
int noCols; // # of columns in the table
|
||||||
bool queryOnly; // Query Only, no inserts, updates or deletes
|
bool queryOnly; // Query Only, no inserts, updates or deletes
|
||||||
|
|
||||||
char tablePath[wxDB_PATH_MAX]; // needed for dBase tables
|
|
||||||
|
|
||||||
// Column Definitions
|
// Column Definitions
|
||||||
wxDbColDef *colDefs; // Array of wxDbColDef structures
|
wxDbColDef *colDefs; // Array of wxDbColDef structures
|
||||||
|
#endif
|
||||||
|
public:
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
// Where, Order By and From clauses
|
// Where, Order By and From clauses
|
||||||
char *where; // Standard SQL where clause, minus the word WHERE
|
char *where; // Standard SQL where clause, minus the word WHERE
|
||||||
char *orderBy; // Standard SQL order by clause, minus the ORDER BY
|
char *orderBy; // Standard SQL order by clause, minus the ORDER BY
|
||||||
char *from; // Allows for joins in a wxDbTable::Query(). Format: ",tbl,tbl..."
|
char *from; // Allows for joins in a wxDbTable::Query(). Format: ",tbl,tbl..."
|
||||||
|
|
||||||
|
// ODBC Handles
|
||||||
|
HENV henv; // ODBC Environment handle
|
||||||
|
HDBC hdbc; // ODBC DB Connection handle
|
||||||
|
HSTMT hstmt; // ODBC Statement handle
|
||||||
|
HSTMT *hstmtDefault; // Default cursor
|
||||||
|
HSTMT hstmtInsert; // ODBC Statement handle used specifically for inserts
|
||||||
|
HSTMT hstmtDelete; // ODBC Statement handle used specifically for deletes
|
||||||
|
HSTMT hstmtUpdate; // ODBC Statement handle used specifically for updates
|
||||||
|
HSTMT hstmtInternal; // ODBC Statement handle used internally only
|
||||||
|
HSTMT *hstmtCount; // ODBC Statement handle used by Count() function (No binding of columns)
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
bool selectForUpdate;
|
bool selectForUpdate;
|
||||||
|
|
||||||
|
// Pointer to the database object this table belongs to
|
||||||
|
wxDb *pDb;
|
||||||
|
|
||||||
|
// Table Inf.
|
||||||
|
char tablePath[wxDB_PATH_MAX]; // needed for dBase tables
|
||||||
|
char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
|
||||||
|
char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
|
||||||
|
int noCols; // # of columns in the table
|
||||||
|
bool queryOnly; // Query Only, no inserts, updates or deletes
|
||||||
|
|
||||||
|
// Column Definitions
|
||||||
|
wxDbColDef *colDefs; // Array of wxDbColDef structures
|
||||||
|
#endif
|
||||||
// Public member functions
|
// Public member functions
|
||||||
wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
|
wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
|
||||||
const char *qryTblName = 0, bool qryOnly = !wxDB_QUERY_ONLY, const char *tblPath=NULL);
|
const char *qryTblName = 0, bool qryOnly = !wxDB_QUERY_ONLY, const char *tblPath=NULL);
|
||||||
virtual ~wxDbTable();
|
virtual ~wxDbTable();
|
||||||
|
|
||||||
bool Open(void);
|
bool Open(void);
|
||||||
bool CreateTable(bool attemptDrop=TRUE);
|
bool CreateTable(bool attemptDrop=TRUE);
|
||||||
bool DropTable(void);
|
bool DropTable(void);
|
||||||
bool CreateIndex(const char * idxName, bool unique, int noIdxCols, wxDbIdxDef *pIdxDefs, bool attemptDrop=TRUE);
|
bool CreateIndex(const char * idxName, bool unique, int noIdxCols, wxDbIdxDef *pIdxDefs, bool attemptDrop=TRUE);
|
||||||
bool DropIndex(const char * idxName);
|
bool DropIndex(const char * idxName);
|
||||||
bool CloseCursor(HSTMT cursor);
|
|
||||||
|
// Accessors
|
||||||
|
|
||||||
|
// The member variables returned by these accessors are all
|
||||||
|
// set when the wxDbTable instance is createand cannot be
|
||||||
|
// changed, hence there is no corresponding SetXxxx function
|
||||||
|
wxDb *GetDb() { return pDb; }
|
||||||
|
const char *GetTableName() { return tableName; }
|
||||||
|
const char *GetQueryTableName() { return queryTableName; }
|
||||||
|
const char *GetTablePath() { return tablePath; }
|
||||||
|
|
||||||
|
int GetNumberOfColumns() { return noCols; } // number of "defined" columns for this wxDbTable instance
|
||||||
|
|
||||||
|
const char *GetFromClause() { return from; }
|
||||||
|
const char *GetOrderByClause() { return orderBy; }
|
||||||
|
const char *GetWhereClause() { return where; }
|
||||||
|
|
||||||
|
bool IsQueryOnly() { return queryOnly; }
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
|
void SetFromClause(const char *From) { from = (char *)From; }
|
||||||
|
void SetOrderByClause(const char *OrderBy) { orderBy = (char *)OrderBy; }
|
||||||
|
void SetWhereClause(const char *Where) { where = (char *)Where; }
|
||||||
|
#else
|
||||||
|
void SetFromClause(const wxString& From) { from = From; }
|
||||||
|
void SetOrderByClause(const wxString& OrderBy) { orderBy = OrderBy; }
|
||||||
|
void SetWhereClause(const wxString& Where) { where = Where; }
|
||||||
|
#endif
|
||||||
int Insert(void);
|
int Insert(void);
|
||||||
bool Update(void);
|
bool Update(void);
|
||||||
bool Update(const char *pSqlStmt);
|
bool Update(const char *pSqlStmt);
|
||||||
@@ -163,6 +224,7 @@ public:
|
|||||||
bool QueryBySqlStmt(const char *pSqlStmt);
|
bool QueryBySqlStmt(const char *pSqlStmt);
|
||||||
bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE);
|
bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE);
|
||||||
bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
|
bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
|
||||||
|
bool Refresh(void);
|
||||||
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)); }
|
||||||
|
|
||||||
@@ -174,40 +236,61 @@ public:
|
|||||||
bool GetLast(void);
|
bool GetLast(void);
|
||||||
|
|
||||||
bool IsCursorClosedOnCommit(void);
|
bool IsCursorClosedOnCommit(void);
|
||||||
bool IsColNull(int colNo);
|
|
||||||
UWORD GetRowNum(void);
|
UWORD GetRowNum(void);
|
||||||
void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct);
|
|
||||||
void GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause = 0);
|
void BuildSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct);
|
||||||
void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = 0);
|
void BuildDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause = 0);
|
||||||
void GetWhereClause(char *pWhereClause, int typeOfWhere, const char *qualTableName = 0, bool useLikeComparison=FALSE);
|
void BuildUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = 0);
|
||||||
|
void BuildWhereClause(char *pWhereClause, int typeOfWhere, const char *qualTableName = 0, bool useLikeComparison=FALSE);
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
|
// The following member functions are deprecated. You should use the BuildXxxxxStmt functions (above)
|
||||||
|
void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
||||||
|
{ BuildSelectStmt(pSqlStmt,typeOfSelect,distinct); }
|
||||||
|
void GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause = 0)
|
||||||
|
{ BuildDeleteStmt(pSqlStmt,typeOfDel,pWhereClause); }
|
||||||
|
void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = 0)
|
||||||
|
{ BuildUpdateStmt(pSqlStmt,typeOfUpd,pWhereClause); }
|
||||||
|
void GetWhereClause(char *pWhereClause, int typeOfWhere,
|
||||||
|
const char *qualTableName = 0, bool useLikeComparison=FALSE)
|
||||||
|
{ BuildWhereClause(pWhereClause,typeOfWhere,qualTableName,useLikeComparison); }
|
||||||
|
#endif
|
||||||
bool CanSelectForUpdate(void);
|
bool CanSelectForUpdate(void);
|
||||||
bool CanUpdByROWID(void);
|
bool CanUpdByROWID(void);
|
||||||
void ClearMemberVars(void);
|
void ClearMemberVars(void);
|
||||||
bool SetQueryTimeout(UDWORD nSeconds);
|
bool SetQueryTimeout(UDWORD nSeconds);
|
||||||
void SetColDefs (int index, const char *fieldName, int dataType, void *pData, int cType,
|
|
||||||
|
wxDbColDef *GetColDefs() { return colDefs; }
|
||||||
|
void SetColDefs(int index, const char *fieldName, int dataType, void *pData, int cType,
|
||||||
int size, bool keyField = FALSE, bool upd = TRUE,
|
int size, bool keyField = FALSE, bool upd = TRUE,
|
||||||
bool insAllow = TRUE, bool derivedCol = FALSE);
|
bool insAllow = TRUE, bool derivedCol = FALSE);
|
||||||
wxDbColDataPtr* SetColDefs (wxDbColInf *colInfs, ULONG numCols);
|
wxDbColDataPtr *SetColDefs(wxDbColInf *colInfs, ULONG numCols);
|
||||||
|
|
||||||
HSTMT *NewCursor(bool setCursor = FALSE, bool bindColumns = TRUE);
|
bool CloseCursor(HSTMT cursor);
|
||||||
bool DeleteCursor(HSTMT *hstmtDel);
|
bool DeleteCursor(HSTMT *hstmtDel);
|
||||||
void SetCursor(HSTMT *hstmtActivate = (void **) wxDB_DEFAULT_CURSOR);
|
void SetCursor(HSTMT *hstmtActivate = (void **) wxDB_DEFAULT_CURSOR);
|
||||||
HSTMT GetCursor(void) { return(hstmt); }
|
HSTMT GetCursor(void) { return(hstmt); }
|
||||||
|
HSTMT *GetNewCursor(bool setCursor = FALSE, bool bindColumns = TRUE);
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
|
// The following member function is deprecated. You should use the GetNewCursor
|
||||||
|
HSTMT *NewCursor(bool setCursor = FALSE, bool bindColumns = TRUE) { return GetNewCursor(setCursor,bindColumns); }
|
||||||
|
#endif
|
||||||
|
|
||||||
ULONG Count(const char *args="*");
|
ULONG Count(const char *args="*");
|
||||||
int DB_STATUS(void) { return(pDb->DB_STATUS); }
|
int DB_STATUS(void) { return(pDb->DB_STATUS); }
|
||||||
bool Refresh(void);
|
|
||||||
|
bool IsColNull(int colNo);
|
||||||
bool SetNull(int colNo);
|
bool SetNull(int colNo);
|
||||||
bool SetNull(const char *colName);
|
bool SetNull(const char *colName);
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
ULONG GetTableID() { return tableID; };
|
ULONG GetTableID() { return tableID; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}; // wxDbTable
|
}; // wxDbTable
|
||||||
|
|
||||||
|
|
||||||
// Change this to 0 to remove use of all deprecated functions
|
// Change this to 0 to remove use of all deprecated functions
|
||||||
#if 1
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
//#################################################################################
|
//#################################################################################
|
||||||
//############### DEPRECATED functions for backward compatability #################
|
//############### DEPRECATED functions for backward compatability #################
|
||||||
//#################################################################################
|
//#################################################################################
|
||||||
@@ -225,8 +308,6 @@ const int ROWID = wxDB_ROWID_LEN;
|
|||||||
const int DEFAULT_CURSOR = wxDB_DEFAULT_CURSOR;
|
const int DEFAULT_CURSOR = wxDB_DEFAULT_CURSOR;
|
||||||
const bool QUERY_ONLY = wxDB_QUERY_ONLY;
|
const bool QUERY_ONLY = wxDB_QUERY_ONLY;
|
||||||
const bool DISABLE_VIEW = wxDB_DISABLE_VIEW;
|
const bool DISABLE_VIEW = wxDB_DISABLE_VIEW;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -828,12 +828,12 @@ bool wxDb::getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo)
|
|||||||
// BJO 991209
|
// BJO 991209
|
||||||
if (Dbms() == dbmsMY_SQL)
|
if (Dbms() == dbmsMY_SQL)
|
||||||
{
|
{
|
||||||
if (!strcmp(structSQLTypeInfo.TypeName, "middleint")) strcpy(structSQLTypeInfo.TypeName, "mediumint");
|
if (!wxStrcmp(structSQLTypeInfo.TypeName, "middleint")) wxStrcpy(structSQLTypeInfo.TypeName, "mediumint");
|
||||||
if (!strcmp(structSQLTypeInfo.TypeName, "middleint unsigned")) strcpy(structSQLTypeInfo.TypeName, "mediumint unsigned");
|
if (!wxStrcmp(structSQLTypeInfo.TypeName, "middleint unsigned")) wxStrcpy(structSQLTypeInfo.TypeName, "mediumint unsigned");
|
||||||
if (!strcmp(structSQLTypeInfo.TypeName, "integer")) strcpy(structSQLTypeInfo.TypeName, "int");
|
if (!wxStrcmp(structSQLTypeInfo.TypeName, "integer")) wxStrcpy(structSQLTypeInfo.TypeName, "int");
|
||||||
if (!strcmp(structSQLTypeInfo.TypeName, "integer unsigned")) strcpy(structSQLTypeInfo.TypeName, "int unsigned");
|
if (!wxStrcmp(structSQLTypeInfo.TypeName, "integer unsigned")) wxStrcpy(structSQLTypeInfo.TypeName, "int unsigned");
|
||||||
if (!strcmp(structSQLTypeInfo.TypeName, "middleint")) strcpy(structSQLTypeInfo.TypeName, "mediumint");
|
if (!wxStrcmp(structSQLTypeInfo.TypeName, "middleint")) wxStrcpy(structSQLTypeInfo.TypeName, "mediumint");
|
||||||
if (!strcmp(structSQLTypeInfo.TypeName, "varchar")) strcpy(structSQLTypeInfo.TypeName, "char");
|
if (!wxStrcmp(structSQLTypeInfo.TypeName, "varchar")) wxStrcpy(structSQLTypeInfo.TypeName, "char");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SQLGetData(hstmt, 3, SQL_C_LONG, (UCHAR*) &structSQLTypeInfo.Precision, 0, &cbRet) != SQL_SUCCESS)
|
if (SQLGetData(hstmt, 3, SQL_C_LONG, (UCHAR*) &structSQLTypeInfo.Precision, 0, &cbRet) != SQL_SUCCESS)
|
||||||
@@ -951,21 +951,21 @@ bool wxDb::DispAllErrors(HENV aHenv, HDBC aHdbc, HSTMT aHstmt)
|
|||||||
while (SQLError(aHenv, aHdbc, aHstmt, (UCHAR FAR *) sqlState, &nativeError, (UCHAR FAR *) errorMsg, SQL_MAX_MESSAGE_LENGTH - 1, &cbErrorMsg) == SQL_SUCCESS)
|
while (SQLError(aHenv, aHdbc, aHstmt, (UCHAR FAR *) sqlState, &nativeError, (UCHAR FAR *) errorMsg, SQL_MAX_MESSAGE_LENGTH - 1, &cbErrorMsg) == SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
odbcErrMsg.sprintf("SQL State = %s\nNative Error Code = %li\nError Message = %s\n", sqlState, nativeError, errorMsg);
|
odbcErrMsg.sprintf("SQL State = %s\nNative Error Code = %li\nError Message = %s\n", sqlState, nativeError, errorMsg);
|
||||||
logError(odbcErrMsg.GetData(), sqlState);
|
logError(odbcErrMsg.c_str(), sqlState);
|
||||||
if (!silent)
|
if (!silent)
|
||||||
{
|
{
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
// When run in console mode, use standard out to display errors.
|
// When run in console mode, use standard out to display errors.
|
||||||
cout << odbcErrMsg.GetData() << endl;
|
cout << odbcErrMsg.c_str() << endl;
|
||||||
cout << "Press any key to continue..." << endl;
|
cout << "Press any key to continue..." << endl;
|
||||||
getchar();
|
getchar();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
wxLogDebug(odbcErrMsg.GetData(),"DEBUG MESSAGE from DispAllErrors()");
|
wxLogDebug(odbcErrMsg.c_str(),wxT("ODBC DEBUG MESSAGE from DispAllErrors()"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return(FALSE); // This function always returns false.
|
return(FALSE); // This function always returns false.
|
||||||
|
|
||||||
@@ -990,18 +990,23 @@ void wxDb::DispNextError(void)
|
|||||||
wxString odbcErrMsg;
|
wxString odbcErrMsg;
|
||||||
|
|
||||||
odbcErrMsg.sprintf("SQL State = %s\nNative Error Code = %li\nError Message = %s\n", sqlState, nativeError, errorMsg);
|
odbcErrMsg.sprintf("SQL State = %s\nNative Error Code = %li\nError Message = %s\n", sqlState, nativeError, errorMsg);
|
||||||
logError(odbcErrMsg.GetData(), sqlState);
|
logError(odbcErrMsg.c_str(), sqlState);
|
||||||
|
|
||||||
if (silent)
|
if (silent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
// When run in console mode, use standard out to display errors.
|
// When run in console mode, use standard out to display errors.
|
||||||
cout << odbcErrMsg.GetData() << endl;
|
cout << odbcErrMsg.c_str() << endl;
|
||||||
cout << "Press any key to continue..." << endl;
|
cout << "Press any key to continue..." << endl;
|
||||||
getchar();
|
getchar();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __WXDEBUG__
|
||||||
|
wxLogDebug(odbcErrMsg,wxT("ODBC DEBUG MESSAGE"));
|
||||||
|
#endif // __WXDEBUG__
|
||||||
|
|
||||||
|
|
||||||
} // wxDb::DispNextError()
|
} // wxDb::DispNextError()
|
||||||
|
|
||||||
|
|
||||||
@@ -1265,12 +1270,12 @@ bool wxDb::Grant(int privileges, const char *tableName, const char *userList)
|
|||||||
sqlStmt += userList;
|
sqlStmt += userList;
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt.GetData() << endl;
|
cout << endl << sqlStmt.c_str() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WriteSqlLog(sqlStmt.GetData());
|
WriteSqlLog(sqlStmt.c_str());
|
||||||
|
|
||||||
return(ExecSql(sqlStmt.GetData()));
|
return(ExecSql(sqlStmt.c_str()));
|
||||||
|
|
||||||
} // wxDb::Grant()
|
} // wxDb::Grant()
|
||||||
|
|
||||||
@@ -1299,13 +1304,13 @@ bool wxDb::CreateView(const char *viewName, const char *colList, const char *pSq
|
|||||||
sqlStmt += " AS ";
|
sqlStmt += " AS ";
|
||||||
sqlStmt += pSqlStmt;
|
sqlStmt += pSqlStmt;
|
||||||
|
|
||||||
WriteSqlLog(sqlStmt.GetData());
|
WriteSqlLog(sqlStmt.c_str());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << sqlStmt.GetData() << endl;
|
cout << sqlStmt.c_str() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return(ExecSql(sqlStmt.GetData()));
|
return(ExecSql(sqlStmt.c_str()));
|
||||||
|
|
||||||
} // wxDb::CreateView()
|
} // wxDb::CreateView()
|
||||||
|
|
||||||
@@ -1324,13 +1329,13 @@ bool wxDb::DropView(const char *viewName)
|
|||||||
|
|
||||||
sqlStmt.sprintf("DROP VIEW %s", viewName);
|
sqlStmt.sprintf("DROP VIEW %s", viewName);
|
||||||
|
|
||||||
WriteSqlLog(sqlStmt.GetData());
|
WriteSqlLog(sqlStmt.c_str());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt.GetData() << endl;
|
cout << endl << sqlStmt.c_str() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
// Check for "Base table not found" error and ignore
|
// Check for "Base table not found" error and ignore
|
||||||
GetNextError(henv, hdbc, hstmt);
|
GetNextError(henv, hdbc, hstmt);
|
||||||
@@ -1490,7 +1495,7 @@ int wxDb::GetKeyFields(char *tableName, wxDbColInf* colInf, int noCols)
|
|||||||
{
|
{
|
||||||
for (i=0;i<noCols;i++) // Find the Column name
|
for (i=0;i<noCols;i++) // Find the Column name
|
||||||
if (!wxStrcmp(colInf[i].colName,szPkCol)) // We have found the Column, store the Information
|
if (!wxStrcmp(colInf[i].colName,szPkCol)) // We have found the Column, store the Information
|
||||||
strcpy(colInf[i].PkTableName,Temp0); // Name of the Tables where this Primary Key is used as a Foreign Key
|
wxStrcpy(colInf[i].PkTableName,Temp0.c_str()); // Name of the Tables where this Primary Key is used as a Foreign Key
|
||||||
} // if (Temp0 != "")
|
} // if (Temp0 != "")
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE); /* Close the cursor (the hstmt is still allocated). */
|
SQLFreeStmt(hstmt, SQL_CLOSE); /* Close the cursor (the hstmt is still allocated). */
|
||||||
|
|
||||||
@@ -1525,7 +1530,7 @@ int wxDb::GetKeyFields(char *tableName, wxDbColInf* colInf, int noCols)
|
|||||||
if (!wxStrcmp(colInf[i].colName,szFkCol)) // We have found the (Foreign Key) Column
|
if (!wxStrcmp(colInf[i].colName,szFkCol)) // We have found the (Foreign Key) Column
|
||||||
{
|
{
|
||||||
colInf[i].FkCol = iKeySeq; // Which Foreign Key is this (first, second usw.) ?
|
colInf[i].FkCol = iKeySeq; // Which Foreign Key is this (first, second usw.) ?
|
||||||
strcpy(colInf[i].FkTableName,szPkTable); // Name of the Table where this Foriegn is the Primary Key
|
wxStrcpy(colInf[i].FkTableName,szPkTable); // Name of the Table where this Foriegn is the Primary Key
|
||||||
} // if (!wxStrcmp(colInf[i].colName,szFkCol))
|
} // if (!wxStrcmp(colInf[i].colName,szFkCol))
|
||||||
} // for (i=0;i<noCols;i++)
|
} // for (i=0;i<noCols;i++)
|
||||||
} // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
|
} // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
|
||||||
@@ -1628,14 +1633,14 @@ wxDbColInf *wxDb::GetColumns(char *tableName[], const char *userID)
|
|||||||
|
|
||||||
// MySQL and Access cannot accept a user name when looking up column names, so we
|
// MySQL and Access cannot accept a user name when looking up column names, so we
|
||||||
// use the call below that leaves out the user name
|
// use the call below that leaves out the user name
|
||||||
if (wxStrcmp(UserID.GetData(),wxT("")) &&
|
if (wxStrcmp(UserID.c_str(),wxT("")) &&
|
||||||
Dbms() != dbmsMY_SQL &&
|
Dbms() != dbmsMY_SQL &&
|
||||||
Dbms() != dbmsACCESS)
|
Dbms() != dbmsACCESS)
|
||||||
{
|
{
|
||||||
retcode = SQLColumns(hstmt,
|
retcode = SQLColumns(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
(UCHAR *) UserID.GetData(), SQL_NTS, // Owner
|
(UCHAR *) UserID.c_str(), SQL_NTS, // Owner
|
||||||
(UCHAR *) TableName.GetData(), SQL_NTS,
|
(UCHAR *) TableName.c_str(), SQL_NTS,
|
||||||
NULL, 0); // All columns
|
NULL, 0); // All columns
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1643,7 +1648,7 @@ wxDbColInf *wxDb::GetColumns(char *tableName[], const char *userID)
|
|||||||
retcode = SQLColumns(hstmt,
|
retcode = SQLColumns(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
NULL, 0, // Owner
|
NULL, 0, // Owner
|
||||||
(UCHAR *) TableName.GetData(), SQL_NTS,
|
(UCHAR *) TableName.c_str(), SQL_NTS,
|
||||||
NULL, 0); // All columns
|
NULL, 0); // All columns
|
||||||
}
|
}
|
||||||
if (retcode != SQL_SUCCESS)
|
if (retcode != SQL_SUCCESS)
|
||||||
@@ -1793,14 +1798,14 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
|
|||||||
|
|
||||||
// MySQL and Access cannot accept a user name when looking up column names, so we
|
// MySQL and Access cannot accept a user name when looking up column names, so we
|
||||||
// use the call below that leaves out the user name
|
// use the call below that leaves out the user name
|
||||||
if (wxStrcmp(UserID.GetData(),wxT("")) &&
|
if (wxStrcmp(UserID.c_str(),wxT("")) &&
|
||||||
Dbms() != dbmsMY_SQL &&
|
Dbms() != dbmsMY_SQL &&
|
||||||
Dbms() != dbmsACCESS)
|
Dbms() != dbmsACCESS)
|
||||||
{
|
{
|
||||||
retcode = SQLColumns(hstmt,
|
retcode = SQLColumns(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
(UCHAR *) UserID.GetData(), SQL_NTS, // Owner
|
(UCHAR *) UserID.c_str(), SQL_NTS, // Owner
|
||||||
(UCHAR *) TableName.GetData(), SQL_NTS,
|
(UCHAR *) TableName.c_str(), SQL_NTS,
|
||||||
NULL, 0); // All columns
|
NULL, 0); // All columns
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1808,7 +1813,7 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
|
|||||||
retcode = SQLColumns(hstmt,
|
retcode = SQLColumns(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
NULL, 0, // Owner
|
NULL, 0, // Owner
|
||||||
(UCHAR *) TableName.GetData(), SQL_NTS,
|
(UCHAR *) TableName.c_str(), SQL_NTS,
|
||||||
NULL, 0); // All columns
|
NULL, 0); // All columns
|
||||||
}
|
}
|
||||||
if (retcode != SQL_SUCCESS)
|
if (retcode != SQL_SUCCESS)
|
||||||
@@ -1953,14 +1958,14 @@ int wxDb::GetColumnCount(char *tableName, const char *userID)
|
|||||||
|
|
||||||
// MySQL and Access cannot accept a user name when looking up column names, so we
|
// MySQL and Access cannot accept a user name when looking up column names, so we
|
||||||
// use the call below that leaves out the user name
|
// use the call below that leaves out the user name
|
||||||
if (wxStrcmp(UserID.GetData(),wxT("")) &&
|
if (wxStrcmp(UserID.c_str(),wxT("")) &&
|
||||||
Dbms() != dbmsMY_SQL &&
|
Dbms() != dbmsMY_SQL &&
|
||||||
Dbms() != dbmsACCESS)
|
Dbms() != dbmsACCESS)
|
||||||
{
|
{
|
||||||
retcode = SQLColumns(hstmt,
|
retcode = SQLColumns(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
(UCHAR *) UserID.GetData(), SQL_NTS, // Owner
|
(UCHAR *) UserID.c_str(), SQL_NTS, // Owner
|
||||||
(UCHAR *) TableName.GetData(), SQL_NTS,
|
(UCHAR *) TableName.c_str(), SQL_NTS,
|
||||||
NULL, 0); // All columns
|
NULL, 0); // All columns
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1968,7 +1973,7 @@ int wxDb::GetColumnCount(char *tableName, const char *userID)
|
|||||||
retcode = SQLColumns(hstmt,
|
retcode = SQLColumns(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
NULL, 0, // Owner
|
NULL, 0, // Owner
|
||||||
(UCHAR *) TableName.GetData(), SQL_NTS,
|
(UCHAR *) TableName.c_str(), SQL_NTS,
|
||||||
NULL, 0); // All columns
|
NULL, 0); // All columns
|
||||||
}
|
}
|
||||||
if (retcode != SQL_SUCCESS)
|
if (retcode != SQL_SUCCESS)
|
||||||
@@ -2067,13 +2072,13 @@ wxDbInf *wxDb::GetCatalog(char *userID)
|
|||||||
SQLFreeStmt(hstmt, SQL_CLOSE); // Close if Open
|
SQLFreeStmt(hstmt, SQL_CLOSE); // Close if Open
|
||||||
tblNameSave = wxT("");
|
tblNameSave = wxT("");
|
||||||
|
|
||||||
if (wxStrcmp(UserID.GetData(),wxT("")) &&
|
if (wxStrcmp(UserID.c_str(),wxT("")) &&
|
||||||
Dbms() != dbmsMY_SQL &&
|
Dbms() != dbmsMY_SQL &&
|
||||||
Dbms() != dbmsACCESS)
|
Dbms() != dbmsACCESS)
|
||||||
{
|
{
|
||||||
retcode = SQLTables(hstmt,
|
retcode = SQLTables(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
(UCHAR *) UserID.GetData(), SQL_NTS, // User specified
|
(UCHAR *) UserID.c_str(), SQL_NTS, // User specified
|
||||||
NULL, 0, // All tables
|
NULL, 0, // All tables
|
||||||
NULL, 0); // All columns
|
NULL, 0); // All columns
|
||||||
}
|
}
|
||||||
@@ -2192,13 +2197,13 @@ bool wxDb::Catalog(const char *userID, const char *fileName)
|
|||||||
if (Dbms() == dbmsORACLE)
|
if (Dbms() == dbmsORACLE)
|
||||||
UserID = UserID.Upper();
|
UserID = UserID.Upper();
|
||||||
|
|
||||||
if (wxStrcmp(UserID.GetData(),wxT("")) &&
|
if (wxStrcmp(UserID.c_str(),wxT("")) &&
|
||||||
Dbms() != dbmsMY_SQL &&
|
Dbms() != dbmsMY_SQL &&
|
||||||
Dbms() != dbmsACCESS)
|
Dbms() != dbmsACCESS)
|
||||||
{
|
{
|
||||||
retcode = SQLColumns(hstmt,
|
retcode = SQLColumns(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
(UCHAR *) UserID.GetData(), SQL_NTS, // User specified
|
(UCHAR *) UserID.c_str(), SQL_NTS, // User specified
|
||||||
NULL, 0, // All tables
|
NULL, 0, // All tables
|
||||||
NULL, 0); // All columns
|
NULL, 0); // All columns
|
||||||
}
|
}
|
||||||
@@ -2223,7 +2228,7 @@ bool wxDb::Catalog(const char *userID, const char *fileName)
|
|||||||
|
|
||||||
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
|
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
if (wxStrcmp(tblName,tblNameSave.GetData()))
|
if (wxStrcmp(tblName,tblNameSave.c_str()))
|
||||||
{
|
{
|
||||||
if (cnt)
|
if (cnt)
|
||||||
fputs("\n", fp);
|
fputs("\n", fp);
|
||||||
@@ -2234,7 +2239,7 @@ bool wxDb::Catalog(const char *userID, const char *fileName)
|
|||||||
fputs("=========\n", fp);
|
fputs("=========\n", fp);
|
||||||
outStr.sprintf(wxT("%-32s %-32s %-21s %9s %9s\n"),
|
outStr.sprintf(wxT("%-32s %-32s %-21s %9s %9s\n"),
|
||||||
wxT("TABLE NAME"), wxT("COLUMN NAME"), wxT("DATA TYPE"), wxT("PRECISION"), wxT("LENGTH"));
|
wxT("TABLE NAME"), wxT("COLUMN NAME"), wxT("DATA TYPE"), wxT("PRECISION"), wxT("LENGTH"));
|
||||||
fputs(outStr.GetData(), fp);
|
fputs(outStr.c_str(), fp);
|
||||||
fputs("================================ ", fp);
|
fputs("================================ ", fp);
|
||||||
fputs("================================ ", fp);
|
fputs("================================ ", fp);
|
||||||
fputs("===================== ", fp);
|
fputs("===================== ", fp);
|
||||||
@@ -2252,7 +2257,7 @@ bool wxDb::Catalog(const char *userID, const char *fileName)
|
|||||||
|
|
||||||
outStr.sprintf("%-32s %-32s (%04d)%-15s %9d %9d\n",
|
outStr.sprintf("%-32s %-32s (%04d)%-15s %9d %9d\n",
|
||||||
tblName, colName, sqlDataType, typeName, precision, length);
|
tblName, colName, sqlDataType, typeName, precision, length);
|
||||||
if (fputs(outStr.GetData(), fp) == EOF)
|
if (fputs(outStr.c_str(), fp) == EOF)
|
||||||
{
|
{
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@@ -2299,7 +2304,7 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta
|
|||||||
dbName.sprintf("%s.dbf",tableName);
|
dbName.sprintf("%s.dbf",tableName);
|
||||||
|
|
||||||
bool exists;
|
bool exists;
|
||||||
exists = wxFileExists(dbName.GetData());
|
exists = wxFileExists(dbName.c_str());
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2335,8 +2340,8 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta
|
|||||||
{
|
{
|
||||||
retcode = SQLTables(hstmt,
|
retcode = SQLTables(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
(UCHAR *) UserID.GetData(), SQL_NTS, // All owners
|
(UCHAR *) UserID.c_str(), SQL_NTS, // All owners
|
||||||
(UCHAR FAR *)TableName.GetData(), SQL_NTS,
|
(UCHAR FAR *)TableName.c_str(), SQL_NTS,
|
||||||
NULL, 0); // All table types
|
NULL, 0); // All table types
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2344,7 +2349,7 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta
|
|||||||
retcode = SQLTables(hstmt,
|
retcode = SQLTables(hstmt,
|
||||||
NULL, 0, // All qualifiers
|
NULL, 0, // All qualifiers
|
||||||
NULL, 0, // All owners
|
NULL, 0, // All owners
|
||||||
(UCHAR FAR *)TableName.GetData(), SQL_NTS,
|
(UCHAR FAR *)TableName.c_str(), SQL_NTS,
|
||||||
NULL, 0); // All table types
|
NULL, 0); // All table types
|
||||||
}
|
}
|
||||||
if (retcode != SQL_SUCCESS)
|
if (retcode != SQL_SUCCESS)
|
||||||
@@ -2670,7 +2675,7 @@ int wxDbCreateDataSource(const char *driverName, const char *dsn, const char *de
|
|||||||
while (k != wxNOT_FOUND);
|
while (k != wxNOT_FOUND);
|
||||||
|
|
||||||
result = SQLConfigDataSource((HWND)parent->GetHWND(), dsnLocation,
|
result = SQLConfigDataSource((HWND)parent->GetHWND(), dsnLocation,
|
||||||
driverName, setupStr.GetData());
|
driverName, setupStr.c_str());
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@@ -2683,22 +2688,21 @@ int wxDbCreateDataSource(const char *driverName, const char *dsn, const char *de
|
|||||||
SQLInstallerError(1,&retcode,errMsg,500,&cb);
|
SQLInstallerError(1,&retcode,errMsg,500,&cb);
|
||||||
if (retcode)
|
if (retcode)
|
||||||
{
|
{
|
||||||
// logError(errMsg, sqlState);
|
if (!silent)
|
||||||
// if (!silent)
|
{
|
||||||
// {
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
// When run in console mode, use standard out to display errors.
|
// When run in console mode, use standard out to display errors.
|
||||||
cout << errMsg << endl;
|
cout << errMsg << endl;
|
||||||
cout << "Press any key to continue..." << endl;
|
cout << "Press any key to continue..." << endl;
|
||||||
getchar();
|
getchar();
|
||||||
#endif // DBDEBUG_CONSOLE
|
#endif // DBDEBUG_CONSOLE
|
||||||
// }
|
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
wxLogDebug(errMsg,"DEBUG MESSAGE");
|
wxLogDebug(errMsg,wxT("ODBC DEBUG MESSAGE"));
|
||||||
#endif // __WXDEBUG__
|
#endif // __WXDEBUG__
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
|
|
||||||
@@ -2734,7 +2738,7 @@ bool wxDbGetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD D
|
|||||||
|
|
||||||
|
|
||||||
// Change this to 0 to remove use of all deprecated functions
|
// Change this to 0 to remove use of all deprecated functions
|
||||||
#if 1
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
********************************************************************
|
********************************************************************
|
||||||
*
|
*
|
||||||
@@ -2776,8 +2780,5 @@ int WXDLLEXPORT NumberDbConnectionsInUse(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// wxUSE_ODBC
|
// wxUSE_ODBC
|
||||||
|
@@ -120,9 +120,9 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
|
|||||||
colDefs = 0;
|
colDefs = 0;
|
||||||
tableID = 0;
|
tableID = 0;
|
||||||
noCols = nCols; // No. of cols in the table
|
noCols = nCols; // No. of cols in the table
|
||||||
where = 0; // Where clause
|
where = ""; // Where clause
|
||||||
orderBy = 0; // Order By clause
|
orderBy = ""; // Order By clause
|
||||||
from = 0; // From clause
|
from = ""; // From clause
|
||||||
selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase
|
selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase
|
||||||
queryOnly = qryOnly;
|
queryOnly = qryOnly;
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
|
|||||||
if (!pDb)
|
if (!pDb)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pDb->nTables++;
|
pDb->incrementTableCount();
|
||||||
|
|
||||||
wxString s;
|
wxString s;
|
||||||
tableID = ++lastTableID;
|
tableID = ++lastTableID;
|
||||||
@@ -155,7 +155,7 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
|
|||||||
TablesInUse.Append(tableInUse);
|
TablesInUse.Append(tableInUse);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pDb->WriteSqlLog(s.GetData());
|
pDb->WriteSqlLog(s.c_str());
|
||||||
|
|
||||||
// Grab the HENV and HDBC from the wxDb object
|
// Grab the HENV and HDBC from the wxDb object
|
||||||
henv = pDb->GetHENV();
|
henv = pDb->GetHENV();
|
||||||
@@ -236,7 +236,7 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make the default cursor the active cursor
|
// Make the default cursor the active cursor
|
||||||
hstmtDefault = NewCursor(FALSE,FALSE);
|
hstmtDefault = GetNewCursor(FALSE,FALSE);
|
||||||
assert(hstmtDefault);
|
assert(hstmtDefault);
|
||||||
hstmt = *hstmtDefault;
|
hstmt = *hstmtDefault;
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ wxDbTable::~wxDbTable()
|
|||||||
if (pDb)
|
if (pDb)
|
||||||
{
|
{
|
||||||
s.sprintf("wxDbTable destructor (%-20s) tableID:[%6lu] pDb:[%p]", tableName,tableID,pDb);
|
s.sprintf("wxDbTable destructor (%-20s) tableID:[%6lu] pDb:[%p]", tableName,tableID,pDb);
|
||||||
pDb->WriteSqlLog(s.GetData());
|
pDb->WriteSqlLog(s.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
@@ -267,7 +267,7 @@ wxDbTable::~wxDbTable()
|
|||||||
{
|
{
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
if (!TablesInUse.DeleteNode(pNode))
|
if (!TablesInUse.DeleteNode(pNode))
|
||||||
wxLogDebug (s.GetData(),"Unable to delete node!");
|
wxLogDebug (s.c_str(),wxT("Unable to delete node!"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pNode = pNode->Next();
|
pNode = pNode->Next();
|
||||||
@@ -275,15 +275,15 @@ wxDbTable::~wxDbTable()
|
|||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
msg.sprintf(wxT("Unable to find the tableID in the linked\nlist of tables in use.\n\n%s"),s.GetData());
|
msg.sprintf(wxT("Unable to find the tableID in the linked\nlist of tables in use.\n\n%s"),s.c_str());
|
||||||
wxLogDebug (msg.GetData(),wxT("NOTICE..."));
|
wxLogDebug (msg.c_str(),wxT("NOTICE..."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Decrement the wxDb table count
|
// Decrement the wxDb table count
|
||||||
if (pDb)
|
if (pDb)
|
||||||
pDb->nTables--;
|
pDb->decrementTableCount();
|
||||||
|
|
||||||
// Delete memory allocated for column definitions
|
// Delete memory allocated for column definitions
|
||||||
if (colDefs)
|
if (colDefs)
|
||||||
@@ -344,21 +344,21 @@ bool wxDbTable::bindInsertParams(void)
|
|||||||
switch(colDefs[i].DbDataType)
|
switch(colDefs[i].DbDataType)
|
||||||
{
|
{
|
||||||
case DB_DATA_TYPE_VARCHAR:
|
case DB_DATA_TYPE_VARCHAR:
|
||||||
fSqlType = pDb->typeInfVarchar.FsqlType;
|
fSqlType = pDb->GetTypeInfVarchar().FsqlType;
|
||||||
precision = colDefs[i].SzDataObj;
|
precision = colDefs[i].SzDataObj;
|
||||||
scale = 0;
|
scale = 0;
|
||||||
colDefs[i].CbValue = SQL_NTS;
|
colDefs[i].CbValue = SQL_NTS;
|
||||||
break;
|
break;
|
||||||
case DB_DATA_TYPE_INTEGER:
|
case DB_DATA_TYPE_INTEGER:
|
||||||
fSqlType = pDb->typeInfInteger.FsqlType;
|
fSqlType = pDb->GetTypeInfInteger().FsqlType;
|
||||||
precision = pDb->typeInfInteger.Precision;
|
precision = pDb->GetTypeInfInteger().Precision;
|
||||||
scale = 0;
|
scale = 0;
|
||||||
colDefs[i].CbValue = 0;
|
colDefs[i].CbValue = 0;
|
||||||
break;
|
break;
|
||||||
case DB_DATA_TYPE_FLOAT:
|
case DB_DATA_TYPE_FLOAT:
|
||||||
fSqlType = pDb->typeInfFloat.FsqlType;
|
fSqlType = pDb->GetTypeInfFloat().FsqlType;
|
||||||
precision = pDb->typeInfFloat.Precision;
|
precision = pDb->GetTypeInfFloat().Precision;
|
||||||
scale = pDb->typeInfFloat.MaximumScale;
|
scale = pDb->GetTypeInfFloat().MaximumScale;
|
||||||
// SQL Sybase Anywhere v5.5 returned a negative number for the
|
// SQL Sybase Anywhere v5.5 returned a negative number for the
|
||||||
// MaxScale. This caused ODBC to kick out an error on ibscale.
|
// MaxScale. This caused ODBC to kick out an error on ibscale.
|
||||||
// I check for this here and set the scale = precision.
|
// I check for this here and set the scale = precision.
|
||||||
@@ -367,8 +367,8 @@ bool wxDbTable::bindInsertParams(void)
|
|||||||
colDefs[i].CbValue = 0;
|
colDefs[i].CbValue = 0;
|
||||||
break;
|
break;
|
||||||
case DB_DATA_TYPE_DATE:
|
case DB_DATA_TYPE_DATE:
|
||||||
fSqlType = pDb->typeInfDate.FsqlType;
|
fSqlType = pDb->GetTypeInfDate().FsqlType;
|
||||||
precision = pDb->typeInfDate.Precision;
|
precision = pDb->GetTypeInfDate().Precision;
|
||||||
scale = 0;
|
scale = 0;
|
||||||
colDefs[i].CbValue = 0;
|
colDefs[i].CbValue = 0;
|
||||||
break;
|
break;
|
||||||
@@ -411,21 +411,21 @@ bool wxDbTable::bindUpdateParams(void)
|
|||||||
switch(colDefs[i].DbDataType)
|
switch(colDefs[i].DbDataType)
|
||||||
{
|
{
|
||||||
case DB_DATA_TYPE_VARCHAR:
|
case DB_DATA_TYPE_VARCHAR:
|
||||||
fSqlType = pDb->typeInfVarchar.FsqlType;
|
fSqlType = pDb->GetTypeInfVarchar().FsqlType;
|
||||||
precision = colDefs[i].SzDataObj;
|
precision = colDefs[i].SzDataObj;
|
||||||
scale = 0;
|
scale = 0;
|
||||||
colDefs[i].CbValue = SQL_NTS;
|
colDefs[i].CbValue = SQL_NTS;
|
||||||
break;
|
break;
|
||||||
case DB_DATA_TYPE_INTEGER:
|
case DB_DATA_TYPE_INTEGER:
|
||||||
fSqlType = pDb->typeInfInteger.FsqlType;
|
fSqlType = pDb->GetTypeInfInteger().FsqlType;
|
||||||
precision = pDb->typeInfInteger.Precision;
|
precision = pDb->GetTypeInfInteger().Precision;
|
||||||
scale = 0;
|
scale = 0;
|
||||||
colDefs[i].CbValue = 0;
|
colDefs[i].CbValue = 0;
|
||||||
break;
|
break;
|
||||||
case DB_DATA_TYPE_FLOAT:
|
case DB_DATA_TYPE_FLOAT:
|
||||||
fSqlType = pDb->typeInfFloat.FsqlType;
|
fSqlType = pDb->GetTypeInfFloat().FsqlType;
|
||||||
precision = pDb->typeInfFloat.Precision;
|
precision = pDb->GetTypeInfFloat().Precision;
|
||||||
scale = pDb->typeInfFloat.MaximumScale;
|
scale = pDb->GetTypeInfFloat().MaximumScale;
|
||||||
// SQL Sybase Anywhere v5.5 returned a negative number for the
|
// SQL Sybase Anywhere v5.5 returned a negative number for the
|
||||||
// MaxScale. This caused ODBC to kick out an error on ibscale.
|
// MaxScale. This caused ODBC to kick out an error on ibscale.
|
||||||
// I check for this here and set the scale = precision.
|
// I check for this here and set the scale = precision.
|
||||||
@@ -434,8 +434,8 @@ bool wxDbTable::bindUpdateParams(void)
|
|||||||
colDefs[i].CbValue = 0;
|
colDefs[i].CbValue = 0;
|
||||||
break;
|
break;
|
||||||
case DB_DATA_TYPE_DATE:
|
case DB_DATA_TYPE_DATE:
|
||||||
fSqlType = pDb->typeInfDate.FsqlType;
|
fSqlType = pDb->GetTypeInfDate().FsqlType;
|
||||||
precision = pDb->typeInfDate.Precision;
|
precision = pDb->GetTypeInfDate().Precision;
|
||||||
scale = 0;
|
scale = 0;
|
||||||
colDefs[i].CbValue = 0;
|
colDefs[i].CbValue = 0;
|
||||||
break;
|
break;
|
||||||
@@ -550,7 +550,7 @@ bool wxDbTable::query(int queryType, bool forUpdate, bool distinct, const char *
|
|||||||
// Set the SQL SELECT string
|
// Set the SQL SELECT string
|
||||||
if (queryType != DB_SELECT_STATEMENT) // A select statement was not passed in,
|
if (queryType != DB_SELECT_STATEMENT) // A select statement was not passed in,
|
||||||
{ // so generate a select statement.
|
{ // so generate a select statement.
|
||||||
GetSelectStmt(sqlStmt, queryType, distinct);
|
BuildSelectStmt(sqlStmt, queryType, distinct);
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,7 +595,7 @@ bool wxDbTable::Open(void)
|
|||||||
s += wxT("Table/view does not exist in the database.\n");
|
s += wxT("Table/view does not exist in the database.\n");
|
||||||
else
|
else
|
||||||
s += wxT("Current logged in user does not have sufficient privileges to access this table.\n");
|
s += wxT("Current logged in user does not have sufficient privileges to access this table.\n");
|
||||||
pDb->LogError(s.GetData());
|
pDb->LogError(s.c_str());
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,7 +646,7 @@ bool wxDbTable::Open(void)
|
|||||||
// pDb->WriteSqlLog(sqlStmt);
|
// pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
// Prepare the insert statement for execution
|
// Prepare the insert statement for execution
|
||||||
if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
|
||||||
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
|
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,8 +745,8 @@ bool wxDbTable::GetLast(void)
|
|||||||
} // wxDbTable::GetLast()
|
} // wxDbTable::GetLast()
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbTable::GetSelectStmt() **********/
|
/********** wxDbTable::BuildSelectStmt() **********/
|
||||||
void wxDbTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
void wxDbTable::BuildSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
||||||
{
|
{
|
||||||
char whereClause[DB_MAX_WHERE_CLAUSE_LEN];
|
char whereClause[DB_MAX_WHERE_CLAUSE_LEN];
|
||||||
|
|
||||||
@@ -762,8 +762,13 @@ void wxDbTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
|||||||
// Was a FROM clause specified to join tables to the base table?
|
// Was a FROM clause specified to join tables to the base table?
|
||||||
// Available for ::Query() only!!!
|
// Available for ::Query() only!!!
|
||||||
bool appendFromClause = FALSE;
|
bool appendFromClause = FALSE;
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
if (typeOfSelect == DB_SELECT_WHERE && from && wxStrlen(from))
|
if (typeOfSelect == DB_SELECT_WHERE && from && wxStrlen(from))
|
||||||
appendFromClause = TRUE;
|
appendFromClause = TRUE;
|
||||||
|
#else
|
||||||
|
if (typeOfSelect == DB_SELECT_WHERE && from.Length())
|
||||||
|
appendFromClause = TRUE;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Add the column list
|
// Add the column list
|
||||||
int i;
|
int i;
|
||||||
@@ -815,14 +820,18 @@ void wxDbTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
|||||||
switch(typeOfSelect)
|
switch(typeOfSelect)
|
||||||
{
|
{
|
||||||
case DB_SELECT_WHERE:
|
case DB_SELECT_WHERE:
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
if (where && wxStrlen(where)) // May not want a where clause!!!
|
if (where && wxStrlen(where)) // May not want a where clause!!!
|
||||||
|
#else
|
||||||
|
if (where.Length()) // May not want a where clause!!!
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
wxStrcat(pSqlStmt, " WHERE ");
|
wxStrcat(pSqlStmt, " WHERE ");
|
||||||
wxStrcat(pSqlStmt, where);
|
wxStrcat(pSqlStmt, where);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DB_SELECT_KEYFIELDS:
|
case DB_SELECT_KEYFIELDS:
|
||||||
GetWhereClause(whereClause, DB_WHERE_KEYFIELDS);
|
BuildWhereClause(whereClause, DB_WHERE_KEYFIELDS);
|
||||||
if (wxStrlen(whereClause))
|
if (wxStrlen(whereClause))
|
||||||
{
|
{
|
||||||
wxStrcat(pSqlStmt, " WHERE ");
|
wxStrcat(pSqlStmt, " WHERE ");
|
||||||
@@ -830,7 +839,7 @@ void wxDbTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DB_SELECT_MATCHING:
|
case DB_SELECT_MATCHING:
|
||||||
GetWhereClause(whereClause, DB_WHERE_MATCHING);
|
BuildWhereClause(whereClause, DB_WHERE_MATCHING);
|
||||||
if (wxStrlen(whereClause))
|
if (wxStrlen(whereClause))
|
||||||
{
|
{
|
||||||
wxStrcat(pSqlStmt, " WHERE ");
|
wxStrcat(pSqlStmt, " WHERE ");
|
||||||
@@ -840,7 +849,11 @@ void wxDbTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Append the ORDER BY clause
|
// Append the ORDER BY clause
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
if (orderBy && wxStrlen(orderBy))
|
if (orderBy && wxStrlen(orderBy))
|
||||||
|
#else
|
||||||
|
if (orderBy.Length())
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
wxStrcat(pSqlStmt, " ORDER BY ");
|
wxStrcat(pSqlStmt, " ORDER BY ");
|
||||||
wxStrcat(pSqlStmt, orderBy);
|
wxStrcat(pSqlStmt, orderBy);
|
||||||
@@ -852,7 +865,7 @@ void wxDbTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
|||||||
if (selectForUpdate && CanSelectForUpdate())
|
if (selectForUpdate && CanSelectForUpdate())
|
||||||
wxStrcat(pSqlStmt, " FOR UPDATE");
|
wxStrcat(pSqlStmt, " FOR UPDATE");
|
||||||
|
|
||||||
} // wxDbTable::GetSelectStmt()
|
} // wxDbTable::BuildSelectStmt()
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbTable::GetRowNum() **********/
|
/********** wxDbTable::GetRowNum() **********/
|
||||||
@@ -948,13 +961,13 @@ bool wxDbTable::CreateTable(bool attemptDrop)
|
|||||||
switch(colDefs[i].DbDataType)
|
switch(colDefs[i].DbDataType)
|
||||||
{
|
{
|
||||||
case DB_DATA_TYPE_VARCHAR:
|
case DB_DATA_TYPE_VARCHAR:
|
||||||
sqlStmt += pDb->typeInfVarchar.TypeName; break;
|
sqlStmt += pDb->GetTypeInfVarchar().TypeName; break;
|
||||||
case DB_DATA_TYPE_INTEGER:
|
case DB_DATA_TYPE_INTEGER:
|
||||||
sqlStmt += pDb->typeInfInteger.TypeName; break;
|
sqlStmt += pDb->GetTypeInfInteger().TypeName; break;
|
||||||
case DB_DATA_TYPE_FLOAT:
|
case DB_DATA_TYPE_FLOAT:
|
||||||
sqlStmt += pDb->typeInfFloat.TypeName; break;
|
sqlStmt += pDb->GetTypeInfFloat().TypeName; break;
|
||||||
case DB_DATA_TYPE_DATE:
|
case DB_DATA_TYPE_DATE:
|
||||||
sqlStmt += pDb->typeInfDate.TypeName; break;
|
sqlStmt += pDb->GetTypeInfDate().TypeName; break;
|
||||||
}
|
}
|
||||||
// For varchars, append the size of the string
|
// For varchars, append the size of the string
|
||||||
if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)
|
if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)
|
||||||
@@ -964,7 +977,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
|
|||||||
// wxStrcat(sqlStmt, itoa(colDefs[i].SzDataObj, s, 10));
|
// wxStrcat(sqlStmt, itoa(colDefs[i].SzDataObj, s, 10));
|
||||||
// wxStrcat(sqlStmt, ")");
|
// wxStrcat(sqlStmt, ")");
|
||||||
s.sprintf("(%d)", colDefs[i].SzDataObj);
|
s.sprintf("(%d)", colDefs[i].SzDataObj);
|
||||||
sqlStmt += s.GetData();
|
sqlStmt += s.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDb->Dbms() == dbmsSYBASE_ASE || pDb->Dbms() == dbmsMY_SQL)
|
if (pDb->Dbms() == dbmsSYBASE_ASE || pDb->Dbms() == dbmsMY_SQL)
|
||||||
@@ -1015,14 +1028,14 @@ bool wxDbTable::CreateTable(bool attemptDrop)
|
|||||||
// Append the closing parentheses for the create table statement
|
// Append the closing parentheses for the create table statement
|
||||||
sqlStmt += ")";
|
sqlStmt += ")";
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt.GetData());
|
pDb->WriteSqlLog(sqlStmt.c_str());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt.GetData() << endl;
|
cout << endl << sqlStmt.c_str() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Execute the CREATE TABLE statement
|
// Execute the CREATE TABLE statement
|
||||||
RETCODE retcode = SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS);
|
RETCODE retcode = SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS);
|
||||||
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
||||||
{
|
{
|
||||||
pDb->DispAllErrors(henv, hdbc, hstmt);
|
pDb->DispAllErrors(henv, hdbc, hstmt);
|
||||||
@@ -1055,13 +1068,13 @@ bool wxDbTable::DropTable()
|
|||||||
|
|
||||||
sqlStmt.sprintf("DROP TABLE %s", tableName);
|
sqlStmt.sprintf("DROP TABLE %s", tableName);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt.GetData());
|
pDb->WriteSqlLog(sqlStmt.c_str());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt.GetData() << endl;
|
cout << endl << sqlStmt.c_str() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
// Check for "Base table not found" error and ignore
|
// Check for "Base table not found" error and ignore
|
||||||
pDb->GetNextError(henv, hdbc, hstmt);
|
pDb->GetNextError(henv, hdbc, hstmt);
|
||||||
@@ -1133,14 +1146,14 @@ bool wxDbTable::CreateIndex(const char * idxName, bool unique, int noIdxCols, wx
|
|||||||
// Append closing parentheses
|
// Append closing parentheses
|
||||||
sqlStmt += ")";
|
sqlStmt += ")";
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt.GetData());
|
pDb->WriteSqlLog(sqlStmt.c_str());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt.GetData() << endl << endl;
|
cout << endl << sqlStmt.c_str() << endl << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Execute the CREATE INDEX statement
|
// Execute the CREATE INDEX statement
|
||||||
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
pDb->DispAllErrors(henv, hdbc, hstmt);
|
pDb->DispAllErrors(henv, hdbc, hstmt);
|
||||||
pDb->RollbackTrans();
|
pDb->RollbackTrans();
|
||||||
@@ -1177,13 +1190,13 @@ bool wxDbTable::DropIndex(const char * idxName)
|
|||||||
else
|
else
|
||||||
sqlStmt.sprintf("DROP INDEX %s",idxName);
|
sqlStmt.sprintf("DROP INDEX %s",idxName);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt.GetData());
|
pDb->WriteSqlLog(sqlStmt.c_str());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt.GetData() << endl;
|
cout << endl << sqlStmt.c_str() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
// Check for "Index not found" error and ignore
|
// Check for "Index not found" error and ignore
|
||||||
pDb->GetNextError(henv, hdbc, hstmt);
|
pDb->GetNextError(henv, hdbc, hstmt);
|
||||||
@@ -1256,7 +1269,7 @@ bool wxDbTable::Update(void)
|
|||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
|
||||||
// Build the SQL UPDATE statement
|
// Build the SQL UPDATE statement
|
||||||
GetUpdateStmt(sqlStmt, DB_UPD_KEYFIELDS);
|
BuildUpdateStmt(sqlStmt, DB_UPD_KEYFIELDS);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
@@ -1294,7 +1307,7 @@ bool wxDbTable::UpdateWhere(const char *pWhereClause)
|
|||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
|
||||||
// Build the SQL UPDATE statement
|
// Build the SQL UPDATE statement
|
||||||
GetUpdateStmt(sqlStmt, DB_UPD_WHERE, pWhereClause);
|
BuildUpdateStmt(sqlStmt, DB_UPD_WHERE, pWhereClause);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
@@ -1318,7 +1331,7 @@ bool wxDbTable::Delete(void)
|
|||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
|
||||||
// Build the SQL DELETE statement
|
// Build the SQL DELETE statement
|
||||||
GetDeleteStmt(sqlStmt, DB_DEL_KEYFIELDS);
|
BuildDeleteStmt(sqlStmt, DB_DEL_KEYFIELDS);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
@@ -1338,7 +1351,7 @@ bool wxDbTable::DeleteWhere(const char *pWhereClause)
|
|||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
|
||||||
// Build the SQL DELETE statement
|
// Build the SQL DELETE statement
|
||||||
GetDeleteStmt(sqlStmt, DB_DEL_WHERE, pWhereClause);
|
BuildDeleteStmt(sqlStmt, DB_DEL_WHERE, pWhereClause);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
@@ -1358,7 +1371,7 @@ bool wxDbTable::DeleteMatching(void)
|
|||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
|
||||||
// Build the SQL DELETE statement
|
// Build the SQL DELETE statement
|
||||||
GetDeleteStmt(sqlStmt, DB_DEL_MATCHING);
|
BuildDeleteStmt(sqlStmt, DB_DEL_MATCHING);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
@@ -1368,8 +1381,8 @@ bool wxDbTable::DeleteMatching(void)
|
|||||||
} // wxDbTable::DeleteMatching()
|
} // wxDbTable::DeleteMatching()
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbTable::GetUpdateStmt() **********/
|
/********** wxDbTable::BuildUpdateStmt() **********/
|
||||||
void wxDbTable::GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause)
|
void wxDbTable::BuildUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause)
|
||||||
{
|
{
|
||||||
assert(!queryOnly);
|
assert(!queryOnly);
|
||||||
if (queryOnly)
|
if (queryOnly)
|
||||||
@@ -1423,18 +1436,18 @@ void wxDbTable::GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereC
|
|||||||
}
|
}
|
||||||
// Unable to delete by ROWID, so build a WHERE
|
// Unable to delete by ROWID, so build a WHERE
|
||||||
// clause based on the keyfields.
|
// clause based on the keyfields.
|
||||||
GetWhereClause(whereClause, DB_WHERE_KEYFIELDS);
|
BuildWhereClause(whereClause, DB_WHERE_KEYFIELDS);
|
||||||
wxStrcat(pSqlStmt, whereClause);
|
wxStrcat(pSqlStmt, whereClause);
|
||||||
break;
|
break;
|
||||||
case DB_UPD_WHERE:
|
case DB_UPD_WHERE:
|
||||||
wxStrcat(pSqlStmt, pWhereClause);
|
wxStrcat(pSqlStmt, pWhereClause);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // GetUpdateStmt()
|
} // BuildUpdateStmt()
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbTable::GetDeleteStmt() **********/
|
/********** wxDbTable::BuildDeleteStmt() **********/
|
||||||
void wxDbTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause)
|
void wxDbTable::BuildDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause)
|
||||||
{
|
{
|
||||||
assert(!queryOnly);
|
assert(!queryOnly);
|
||||||
if (queryOnly)
|
if (queryOnly)
|
||||||
@@ -1479,26 +1492,26 @@ void wxDbTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereC
|
|||||||
}
|
}
|
||||||
// Unable to delete by ROWID, so build a WHERE
|
// Unable to delete by ROWID, so build a WHERE
|
||||||
// clause based on the keyfields.
|
// clause based on the keyfields.
|
||||||
GetWhereClause(whereClause, DB_WHERE_KEYFIELDS);
|
BuildWhereClause(whereClause, DB_WHERE_KEYFIELDS);
|
||||||
wxStrcat(pSqlStmt, whereClause);
|
wxStrcat(pSqlStmt, whereClause);
|
||||||
break;
|
break;
|
||||||
case DB_DEL_WHERE:
|
case DB_DEL_WHERE:
|
||||||
wxStrcat(pSqlStmt, pWhereClause);
|
wxStrcat(pSqlStmt, pWhereClause);
|
||||||
break;
|
break;
|
||||||
case DB_DEL_MATCHING:
|
case DB_DEL_MATCHING:
|
||||||
GetWhereClause(whereClause, DB_WHERE_MATCHING);
|
BuildWhereClause(whereClause, DB_WHERE_MATCHING);
|
||||||
wxStrcat(pSqlStmt, whereClause);
|
wxStrcat(pSqlStmt, whereClause);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // GetDeleteStmt()
|
} // BuildDeleteStmt()
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbTable::GetWhereClause() **********/
|
/********** wxDbTable::BuildWhereClause() **********/
|
||||||
void wxDbTable::GetWhereClause(char *pWhereClause, int typeOfWhere,
|
void wxDbTable::BuildWhereClause(char *pWhereClause, int typeOfWhere,
|
||||||
const char *qualTableName, bool useLikeComparison)
|
const char *qualTableName, bool useLikeComparison)
|
||||||
/*
|
/*
|
||||||
* Note: GetWhereClause() currently ignores timestamp columns.
|
* Note: BuildWhereClause() currently ignores timestamp columns.
|
||||||
* They are not included as part of the where clause.
|
* They are not included as part of the where clause.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
@@ -1559,7 +1572,7 @@ void wxDbTable::GetWhereClause(char *pWhereClause, int typeOfWhere,
|
|||||||
wxStrcat(pWhereClause, colValue);
|
wxStrcat(pWhereClause, colValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // wxDbTable::GetWhereClause()
|
} // wxDbTable::BuildWhereClause()
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbTable::IsColNull() **********/
|
/********** wxDbTable::IsColNull() **********/
|
||||||
@@ -1839,30 +1852,37 @@ ULONG wxDbTable::Count(const char *args)
|
|||||||
sqlStmt += args;
|
sqlStmt += args;
|
||||||
sqlStmt += ") FROM ";
|
sqlStmt += ") FROM ";
|
||||||
sqlStmt += queryTableName;
|
sqlStmt += queryTableName;
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
if (from && wxStrlen(from))
|
if (from && wxStrlen(from))
|
||||||
|
#else
|
||||||
|
if (from.Length())
|
||||||
|
#endif
|
||||||
sqlStmt += from;
|
sqlStmt += from;
|
||||||
|
|
||||||
// Add the where clause if one is provided
|
// Add the where clause if one is provided
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
if (where && wxStrlen(where))
|
if (where && wxStrlen(where))
|
||||||
|
#else
|
||||||
|
if (where.Length())
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
sqlStmt += " WHERE ";
|
sqlStmt += " WHERE ";
|
||||||
sqlStmt += where;
|
sqlStmt += where;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt.GetData());
|
pDb->WriteSqlLog(sqlStmt.c_str());
|
||||||
|
|
||||||
// Initialize the Count cursor if it's not already initialized
|
// Initialize the Count cursor if it's not already initialized
|
||||||
if (!hstmtCount)
|
if (!hstmtCount)
|
||||||
{
|
{
|
||||||
hstmtCount = NewCursor(FALSE,FALSE);
|
hstmtCount = GetNewCursor(FALSE,FALSE);
|
||||||
assert(hstmtCount);
|
assert(hstmtCount);
|
||||||
if (!hstmtCount)
|
if (!hstmtCount)
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the SQL statement
|
// Execute the SQL statement
|
||||||
if (SQLExecDirect(*hstmtCount, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(*hstmtCount, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
pDb->DispAllErrors(henv, hdbc, *hstmtCount);
|
pDb->DispAllErrors(henv, hdbc, *hstmtCount);
|
||||||
return(0);
|
return(0);
|
||||||
@@ -1900,11 +1920,14 @@ bool wxDbTable::Refresh(void)
|
|||||||
// Switch to the internal cursor so any active cursors are not corrupted
|
// Switch to the internal cursor so any active cursors are not corrupted
|
||||||
HSTMT currCursor = GetCursor();
|
HSTMT currCursor = GetCursor();
|
||||||
hstmt = hstmtInternal;
|
hstmt = hstmtInternal;
|
||||||
|
#if wxODBC_BACKWARD_COMPATABILITY
|
||||||
// Save the where and order by clauses
|
// Save the where and order by clauses
|
||||||
char *saveWhere = where;
|
char *saveWhere = where;
|
||||||
char *saveOrderBy = orderBy;
|
char *saveOrderBy = orderBy;
|
||||||
|
#else
|
||||||
|
wxString saveWhere = where;
|
||||||
|
wxString saveOrderBy = orderBy;
|
||||||
|
#endif
|
||||||
// Build a where clause to refetch the record with. Try and use the
|
// Build a where clause to refetch the record with. Try and use the
|
||||||
// ROWID if it's available, ow use the key fields.
|
// ROWID if it's available, ow use the key fields.
|
||||||
char whereClause[DB_MAX_WHERE_CLAUSE_LEN+1];
|
char whereClause[DB_MAX_WHERE_CLAUSE_LEN+1];
|
||||||
@@ -1928,11 +1951,11 @@ bool wxDbTable::Refresh(void)
|
|||||||
|
|
||||||
// If unable to use the ROWID, build a where clause from the keyfields
|
// If unable to use the ROWID, build a where clause from the keyfields
|
||||||
if (wxStrlen(whereClause) == 0)
|
if (wxStrlen(whereClause) == 0)
|
||||||
GetWhereClause(whereClause, DB_WHERE_KEYFIELDS, queryTableName);
|
BuildWhereClause(whereClause, DB_WHERE_KEYFIELDS, queryTableName);
|
||||||
|
|
||||||
// Requery the record
|
// Requery the record
|
||||||
where = whereClause;
|
where = whereClause;
|
||||||
orderBy = 0;
|
orderBy = "";
|
||||||
if (!Query())
|
if (!Query())
|
||||||
result = FALSE;
|
result = FALSE;
|
||||||
|
|
||||||
@@ -1984,8 +2007,8 @@ bool wxDbTable::SetNull(const char *colName)
|
|||||||
} // wxDbTable::SetNull(char *colName)
|
} // wxDbTable::SetNull(char *colName)
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbTable::NewCursor() **********/
|
/********** wxDbTable::GetNewCursor() **********/
|
||||||
HSTMT *wxDbTable::NewCursor(bool setCursor, bool bindColumns)
|
HSTMT *wxDbTable::GetNewCursor(bool setCursor, bool bindColumns)
|
||||||
{
|
{
|
||||||
HSTMT *newHSTMT = new HSTMT;
|
HSTMT *newHSTMT = new HSTMT;
|
||||||
assert(newHSTMT);
|
assert(newHSTMT);
|
||||||
@@ -2020,7 +2043,7 @@ HSTMT *wxDbTable::NewCursor(bool setCursor, bool bindColumns)
|
|||||||
|
|
||||||
return(newHSTMT);
|
return(newHSTMT);
|
||||||
|
|
||||||
} // wxDbTable::NewCursor()
|
} // wxDbTable::GetNewCursor()
|
||||||
|
|
||||||
|
|
||||||
/********** wxDbTable::DeleteCursor() **********/
|
/********** wxDbTable::DeleteCursor() **********/
|
||||||
|
Reference in New Issue
Block a user