#ifndef DBTABLE_DOT_H
#define DBTABLE_DOT_H
-// Use this line for wxWindows v1.x
-//#include "wx_ver.h"
-// Use this line for wxWindows v2.x
#include "wx/version.h"
-#if wxMAJOR_VERSION == 2
- #ifdef __GNUG__
- #pragma interface "dbtable.h"
- #endif
+#ifdef __GNUG__
+ #pragma interface "dbtable.h"
#endif
-#if wxMAJOR_VERSION == 2
- #include "wx/db.h"
-#else
- #include "db.h"
-#endif
+#include "wx/db.h"
+
+#include "wx/variant.h"
+#include "wx/dbkeyg.h"
const int wxDB_ROWID_LEN = 24; // 18 is the max, 24 is in case it gets larger
const int wxDB_DEFAULT_CURSOR = 0;
-const bool wxDB_QUERY_ONLY = TRUE;
-const bool wxDB_DISABLE_VIEW = TRUE;
+const bool wxDB_QUERY_ONLY = true;
+const bool wxDB_DISABLE_VIEW = true;
// Used to indicate end of a variable length list of
// column numbers passed to member functions
SWORD SqlCtype; // C data type; e.g. SQL_C_LONG
void *PtrDataObj; // Address of the data object
int SzDataObj; // Size, in bytes, of the data object
- bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields.
+ bool KeyField; // true if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields.
bool Updateable; // Specifies whether this column is updateable
bool InsertAllowed; // Specifies whether this column should be included in an INSERT statement
bool DerivedCol; // Specifies whether this column is a derived value
virtual ~wxDbTable();
- bool Open(bool checkPrivileges=FALSE, bool checkTableExists=TRUE);
- bool CreateTable(bool attemptDrop=TRUE);
+ bool Open(bool checkPrivileges=false, bool checkTableExists=true);
+ bool CreateTable(bool attemptDrop=true);
bool DropTable(void);
bool CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCols,
- wxDbIdxDef *pIdxDefs, bool attemptDrop=TRUE);
+ wxDbIdxDef *pIdxDefs, bool attemptDrop=true);
bool DropIndex(const wxString &idxName);
// Accessors
bool Delete(void);
bool DeleteWhere(const wxString &pWhereClause);
bool DeleteMatching(void);
- virtual bool Query(bool forUpdate = FALSE, bool distinct = FALSE);
+ virtual bool Query(bool forUpdate = false, bool distinct = false);
bool QueryBySqlStmt(const wxString &pSqlStmt);
- bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE);
- bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
+ bool QueryMatching(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 operator++(int) { return(getRec(SQL_FETCH_NEXT)); }
void BuildUpdateStmt(wxString &pSqlStmt, int typeOfUpd, const wxString &pWhereClause="");
void BuildUpdateStmt(wxChar *pSqlStmt, int typeOfUpd, const wxString &pWhereClause="");
- void BuildWhereClause(wxString &pWhereClause, int typeOfWhere, const wxString &qualTableName="", bool useLikeComparison=FALSE);
- void BuildWhereClause(wxChar *pWhereClause, int typeOfWhere, const wxString &qualTableName="", bool useLikeComparison=FALSE);
+ void BuildWhereClause(wxString &pWhereClause, int typeOfWhere, const wxString &qualTableName="", bool useLikeComparison=false);
+ void BuildWhereClause(wxChar *pWhereClause, int typeOfWhere, const wxString &qualTableName="", bool useLikeComparison=false);
#if wxODBC_BACKWARD_COMPATABILITY
// The following member functions are deprecated. You should use the BuildXxxxxStmt functions (above)
void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = NULL)
{ BuildUpdateStmt(pSqlStmt,typeOfUpd,pWhereClause); }
void GetWhereClause(char *pWhereClause, int typeOfWhere,
- const char *qualTableName = NULL, bool useLikeComparison=FALSE)
+ const char *qualTableName = NULL, bool useLikeComparison=false)
{ BuildWhereClause(pWhereClause,typeOfWhere,qualTableName,useLikeComparison); }
#endif
bool CanSelectForUpdate(void);
bool CanUpdByROWID(void);
- void ClearMemberVar(UWORD colNo, bool setToNull=FALSE);
- void ClearMemberVars(bool setToNull=FALSE);
+ void ClearMemberVar(UWORD colNo, bool setToNull=false);
+ void ClearMemberVars(bool setToNull=false);
bool SetQueryTimeout(UDWORD nSeconds);
wxDbColDef *GetColDefs() { return colDefs; }
void SetColDefs(UWORD index, const wxString &fieldName, int dataType,
void *pData, SWORD cType,
- int size, bool keyField = FALSE, bool upd = TRUE,
- bool insAllow = TRUE, bool derivedCol = FALSE);
+ int size, bool keyField = false, bool upd = true,
+ bool insAllow = true, bool derivedCol = false);
wxDbColDataPtr *SetColDefs(wxDbColInf *colInfs, UWORD numCols);
bool CloseCursor(HSTMT cursor);
bool DeleteCursor(HSTMT *hstmtDel);
void SetCursor(HSTMT *hstmtActivate = (void **) wxDB_DEFAULT_CURSOR);
HSTMT GetCursor(void) { return(hstmt); }
- HSTMT *GetNewCursor(bool setCursor = FALSE, bool bindColumns = TRUE);
+ 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); }
+ HSTMT *NewCursor(bool setCursor = false, bool bindColumns = true) { return GetNewCursor(setCursor,bindColumns); }
#endif
ULONG Count(const wxString &args="*");
int DB_STATUS(void) { return(pDb->DB_STATUS); }
- bool IsColNull(UWORD colNo);
- bool SetColNull(UWORD colNo, bool set=TRUE);
- bool SetColNull(const wxString &colName, bool set=TRUE);
+ bool IsColNull(UWORD colNo) const;
+ bool SetColNull(UWORD colNo, bool set=true);
+ bool SetColNull(const wxString &colName, bool set=true);
#if wxODBC_BACKWARD_COMPATABILITY
// The following member functions are deprecated. You should use the SetColNull()
- bool SetNull(int colNo, bool set=TRUE) { return (SetNull(colNo,set)); }
- bool SetNull(const char *colName, bool set=TRUE) { return (SetNull(colName,set)); }
+ bool SetNull(int colNo, bool set=true) { return (SetNull(colNo,set)); }
+ bool SetNull(const char *colName, bool set=true) { return (SetNull(colName,set)); }
#endif
#ifdef __WXDEBUG__
ULONG GetTableID() { return tableID; }
#endif
+//TODO: Need to Document
+ typedef enum { WX_ROW_MODE_QUERY , WX_ROW_MODE_INDIVIDUAL } rowmode_t;
+ virtual void SetRowMode(const rowmode_t rowmode);
+ virtual wxVariant GetCol(const int Colno) const ;
+ virtual void SetCol(const int ColNo, const wxVariant value);
+ virtual GenericKey GetKey(void);
+ virtual void SetKey(const GenericKey &key);
+
+ private:
+ HSTMT *m_hstmtGridQuery;
+ rowmode_t m_rowmode;
+ size_t m_keysize;
+
+// typedef enum {unmodified=0, UpdatePending, InsertPending } recStatus;
+
+// recStatus get_ModifiedStatus() { return m_recstatus; }
+
+// void modify() {
+// if (m_recstatus==unmodified)
+// m_recstatus=UpdatePending;
+// }
+// protected:
+// void insertify() {m_recstatus=InsertPending; }
+// void unmodify() {m_recstatus=unmodified; }
+// recStatus m_recstatus;
+//TODO: Need to Document
}; // wxDbTable
// SYNOPSIS START
// SYNOPSIS STOP
*/
+#ifdef __GNUG__
+ #pragma implementation "dbtable.h"
+#endif
-// Use this line for wxWindows v1.x
-//#include "wx_ver.h"
-// Use this line for wxWindows v2.x
#include "wx/wxprec.h"
-#include "wx/version.h"
-#if wxMAJOR_VERSION == 2
- #ifdef __GNUG__
- #pragma implementation "dbtable.h"
- #endif
+#ifdef __BORLANDC__
+ #pragma hdrstop
#endif
#ifdef DBDEBUG_CONSOLE
+ #include "iostream.h"
#include "wx/ioswrap.h"
#endif
-
-#ifdef __BORLANDC__
- #pragma hdrstop
-#endif //__BORLANDC__
-
-#if wxMAJOR_VERSION == 2
- #ifndef WX_PRECOMP
- #include "wx/string.h"
- #include "wx/object.h"
- #include "wx/list.h"
- #include "wx/utils.h"
- #include "wx/msgdlg.h"
- #include "wx/log.h"
- #endif
- #include "wx/filefn.h"
+#ifndef WX_PRECOMP
+ #include "wx/string.h"
+ #include "wx/object.h"
+ #include "wx/list.h"
+ #include "wx/utils.h"
+ #include "wx/msgdlg.h"
+ #include "wx/log.h"
#endif
-
-#if wxMAJOR_VERSION == 1
-# if defined(wx_msw) || defined(wx_x)
-# ifdef WX_PRECOMP
-# include "wx_prec.h"
-# else
-# include "wx.h"
-# endif
-# endif
-# define wxUSE_ODBC 1
-#endif
-
+#include "wx/filefn.h"
#if wxUSE_ODBC
#include <string.h>
//#include <assert.h>
-#if wxMAJOR_VERSION == 1
- #include "table.h"
-#elif wxMAJOR_VERSION == 2
- #include "wx/dbtable.h"
-#endif
+#include "wx/dbtable.h"
#ifdef __UNIX__
// The HPUX preprocessor lines below were commented out on 8/20/97
SqlCtype = SQL_C_LONG;
PtrDataObj = NULL;
SzDataObj = 0;
- KeyField = FALSE;
- Updateable = FALSE;
- InsertAllowed = FALSE;
- DerivedCol = FALSE;
+ KeyField = false;
+ Updateable = false;
+ InsertAllowed = false;
+ DerivedCol = false;
CbValue = 0;
- Null = FALSE;
+ Null = false;
- return TRUE;
+ return true;
} // wxDbColDef::Initialize()
henv = 0;
hdbc = 0;
hstmt = 0;
+ m_hstmtGridQuery = 0;
hstmtDefault = 0; // Initialized below
hstmtCount = 0; // Initialized first time it is needed
hstmtInsert = 0;
where.Empty(); // Where clause
orderBy.Empty(); // Order By clause
from.Empty(); // 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;
- insertable = TRUE;
+ insertable = true;
tablePath.Empty();
tableName.Empty();
queryTableName.Empty();
wxASSERT(pDb);
if (!pDb)
- return FALSE;
+ return false;
tableName = tblName; // Table Name
if (tblPath.Length())
{
// Should never happen
pDb->GetNextError(henv, hdbc, hstmtInternal);
- return FALSE;
+ return false;
}
}
}
}
// Make the default cursor the active cursor
- hstmtDefault = GetNewCursor(FALSE,FALSE);
+ hstmtDefault = GetNewCursor(false,false);
wxASSERT(hstmtDefault);
hstmt = *hstmtDefault;
- return TRUE;
+ return true;
} // wxDbTable::initialize()
#ifdef __WXDEBUG__
if (tableID)
{
- TablesInUse.DeleteContents(TRUE);
- bool found = FALSE;
+ TablesInUse.DeleteContents(true);
+ bool found = false;
wxNode *pNode;
pNode = TablesInUse.First();
{
if (((wxTablesInUse *)pNode->Data())->tableID == tableID)
{
- found = TRUE;
+ found = true;
if (!TablesInUse.DeleteNode(pNode))
wxLogDebug (s,wxT("Unable to delete node!"));
}
if (hstmtCount)
DeleteCursor(hstmtCount);
+
+ if (m_hstmtGridQuery)
+ DeleteCursor(m_hstmtGridQuery);
+
} // wxDbTable::cleanup()
{
wxASSERT(!queryOnly);
if (queryOnly)
- return(FALSE);
+ return(false);
SWORD fSqlType = 0;
UDWORD precision = 0;
}
// Completed successfully
- return(TRUE);
+ return(true);
} // wxDbTable::bindParams()
/********** wxDbTable::bindInsertParams() **********/
bool wxDbTable::bindInsertParams(void)
{
- return bindParams(FALSE);
+ return bindParams(false);
} // wxDbTable::bindInsertParams()
/********** wxDbTable::bindUpdateParams() **********/
bool wxDbTable::bindUpdateParams(void)
{
- return bindParams(TRUE);
+ return bindParams(true);
} // wxDbTable::bindUpdateParams()
}
// Completed successfully
- return(TRUE);
+ return(true);
} // wxDbTable::bindCols()
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
if (retcode == SQL_NO_DATA_FOUND)
- return(FALSE);
+ return(false);
else
return(pDb->DispAllErrors(henv, hdbc, hstmt));
}
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
if (retcode == SQL_NO_DATA_FOUND)
- return(FALSE);
+ return(false);
else
return(pDb->DispAllErrors(henv, hdbc, hstmt));
}
}
// Completed successfully
- return(TRUE);
+ return(true);
} // wxDbTable::getRec()
retcode == SQL_SUCCESS_WITH_INFO)
{
// Record deleted successfully
- return(TRUE);
+ return(true);
}
// Problem deleting record
retcode == SQL_SUCCESS_WITH_INFO)
{
// Record updated successfully
- return(TRUE);
+ return(true);
}
// Problem updating record
// The user may wish to select for update, but the DBMS may not be capable
selectForUpdate = CanSelectForUpdate();
else
- selectForUpdate = FALSE;
+ selectForUpdate = false;
// Set the SQL SELECT string
if (queryType != DB_SELECT_STATEMENT) // A select statement was not passed in,
// Make sure the cursor is closed first
if (!CloseCursor(hstmt))
- return(FALSE);
+ return(false);
// Execute the SQL SELECT statement
int retcode;
return(pDb->DispAllErrors(henv, hdbc, hstmt));
// Completed successfully
- return(TRUE);
+ return(true);
} // wxDbTable::query()
bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
{
if (!pDb)
- return FALSE;
+ return false;
int i;
wxString sqlStmt;
wxString s;
+// int NumKeyCols=0;
+
+ // Calculate the maximum size of the concatenated
+ // keys for use with wxDbGrid
+ m_keysize = 0;
+ for (i=0; i < noCols; i++)
+ {
+ if (colDefs[i].KeyField)
+ {
+// NumKeyCols++;
+ m_keysize += colDefs[i].SzDataObj;
+ }
+ }
s.Empty();
// Verify that the table exists in the database
p += s;
pDb->LogError(p.GetData());
- return(FALSE);
+ return(false);
}
// Bind the member variables for field exchange between
if (!queryOnly)
{
if (!bindInsertParams()) // Inserts
- return(FALSE);
+ return(false);
if (!bindUpdateParams()) // Updates
- return(FALSE);
+ return(false);
}
if (!bindCols(*hstmtDefault)) // Selects
- return(FALSE);
+ return(false);
if (!bindCols(hstmtInternal)) // Internal use only
- return(FALSE);
+ return(false);
/*
* Do NOT bind the hstmtCount cursor!!!
// Build an insert statement using parameter markers
if (!queryOnly && noCols > 0)
{
- bool needComma = FALSE;
+ bool needComma = false;
sqlStmt.Printf(wxT("INSERT INTO %s ("), tableName.c_str());
for (i = 0; i < noCols; i++)
{
if (needComma)
sqlStmt += wxT(",");
sqlStmt += colDefs[i].ColName;
- needComma = TRUE;
+ needComma = true;
}
- needComma = FALSE;
+ needComma = false;
sqlStmt += wxT(") VALUES (");
int insertableCount = 0;
if (needComma)
sqlStmt += wxT(",");
sqlStmt += wxT("?");
- needComma = TRUE;
+ needComma = true;
insertableCount++;
}
sqlStmt += wxT(")");
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
}
else
- insertable= FALSE;
+ insertable= false;
}
// Completed successfully
- return(TRUE);
+ return(true);
} // wxDbTable::Open()
{
pDb->WriteSqlLog(pSqlStmt);
- return(query(DB_SELECT_STATEMENT, FALSE, FALSE, pSqlStmt));
+ return(query(DB_SELECT_STATEMENT, false, false, pSqlStmt));
} // wxDbTable::QueryBySqlStmt()
if (pDb->FwdOnlyCursors())
{
wxFAIL_MSG(wxT("GetPrev()::Backward scrolling cursors are not enabled for this instance of wxDbTable"));
- return FALSE;
+ return false;
}
else
return(getRec(SQL_FETCH_PRIOR));
if (pDb->FwdOnlyCursors())
{
wxFAIL_MSG(wxT("operator--:Backward scrolling cursors are not enabled for this instance of wxDbTable"));
- return FALSE;
+ return false;
}
else
return(getRec(SQL_FETCH_PRIOR));
if (pDb->FwdOnlyCursors())
{
wxFAIL_MSG(wxT("GetFirst():Backward scrolling cursors are not enabled for this instance of wxDbTable"));
- return FALSE;
+ return false;
}
else
return(getRec(SQL_FETCH_FIRST));
if (pDb->FwdOnlyCursors())
{
wxFAIL_MSG(wxT("GetLast()::Backward scrolling cursors are not enabled for this instance of wxDbTable"));
- return FALSE;
+ return false;
}
else
return(getRec(SQL_FETCH_LAST));
// Was a FROM clause specified to join tables to the base table?
// Available for ::Query() only!!!
- bool appendFromClause = FALSE;
+ bool appendFromClause = false;
#if wxODBC_BACKWARD_COMPATABILITY
if (typeOfSelect == DB_SELECT_WHERE && from && wxStrlen(from))
- appendFromClause = TRUE;
+ appendFromClause = true;
#else
if (typeOfSelect == DB_SELECT_WHERE && from.Length())
- appendFromClause = TRUE;
+ appendFromClause = true;
#endif
// Add the column list
wxString whereClause;
whereClause.Empty();
- bool firstColumn = TRUE;
+ bool firstColumn = true;
pSqlStmt.Printf(wxT("UPDATE %s SET "), tableName.Upper().c_str());
if (!firstColumn)
pSqlStmt += wxT(",");
else
- firstColumn = FALSE;
+ firstColumn = false;
pSqlStmt += colDefs[i].ColName;
pSqlStmt += wxT(" = ?");
}
* They are not included as part of the where clause.
*/
{
- bool moreThanOneColumn = FALSE;
+ bool moreThanOneColumn = false;
wxString colValue;
// Loop through the columns building a where clause as you go
if (moreThanOneColumn)
pWhereClause += wxT(" AND ");
else
- moreThanOneColumn = TRUE;
+ moreThanOneColumn = true;
// Concatenate where phrase for the column
if (qualTableName.Length())
{
return(pDb->DispAllErrors(henv, hdbc, cursor));
// Completed successfully
- return(TRUE);
+ return(true);
} // wxDbTable::CloseCursor()
bool wxDbTable::CreateTable(bool attemptDrop)
{
if (!pDb)
- return FALSE;
+ return false;
int i, j;
wxString sqlStmt;
// Drop table first
if (attemptDrop && !DropTable())
- return FALSE;
+ return false;
// Create the table
#ifdef DBDEBUG_CONSOLE
switch(colDefs[i].DbDataType)
{
case DB_DATA_TYPE_VARCHAR:
- cout << pDb->typeInfVarchar.TypeName << wxT("(") << colDefs[i].SzDataObj << wxT(")");
+ cout << pDb->GetTypeInfVarchar().TypeName << wxT("(") << colDefs[i].SzDataObj << wxT(")");
break;
case DB_DATA_TYPE_INTEGER:
- cout << pDb->typeInfInteger.TypeName;
+ cout << pDb->GetTypeInfInteger().TypeName;
break;
case DB_DATA_TYPE_FLOAT:
- cout << pDb->typeInfFloat.TypeName;
+ cout << pDb->GetTypeInfFloat().TypeName;
break;
case DB_DATA_TYPE_DATE:
- cout << pDb->typeInfDate.TypeName;
+ cout << pDb->GetTypeInfDate().TypeName;
break;
case DB_DATA_TYPE_BLOB:
- cout << pDb->typeInfBlob.TypeName;
+ cout << pDb->GetTypeInfBlob().TypeName;
break;
}
cout << endl;
#endif
// Build a CREATE TABLE string from the colDefs structure.
- bool needComma = FALSE;
+ bool needComma = false;
sqlStmt.Printf(wxT("CREATE TABLE %s ("), tableName.c_str());
for (i = 0; i < noCols; i++)
}
}
- needComma = TRUE;
+ needComma = true;
}
// If there is a primary key defined, include it in the create statement
for (i = j = 0; i < noCols; i++)
pDb->DispAllErrors(henv, hdbc, hstmt);
pDb->RollbackTrans();
CloseCursor(hstmt);
- return(FALSE);
+ return(false);
}
// Commit the transaction and close the cursor
if (!pDb->CommitTrans())
- return(FALSE);
+ return(false);
if (!CloseCursor(hstmt))
- return(FALSE);
+ return(false);
// Database table created successfully
- return(TRUE);
+ return(true);
} // wxDbTable::CreateTable()
/********** wxDbTable::DropTable() **********/
bool wxDbTable::DropTable()
{
- // NOTE: This function returns TRUE if the Table does not exist, but
+ // NOTE: This function returns true if the Table does not exist, but
// only for identified databases. Code will need to be added
// below for any other databases when those databases are defined
// to handle this situation consistently
pDb->DispAllErrors(henv, hdbc, hstmt);
pDb->RollbackTrans();
// CloseCursor(hstmt);
- return(FALSE);
+ return(false);
}
}
}
// Commit the transaction and close the cursor
if (! pDb->CommitTrans())
- return(FALSE);
+ return(false);
if (! CloseCursor(hstmt))
- return(FALSE);
+ return(false);
- return(TRUE);
+ return(true);
} // wxDbTable::DropTable()
// Drop the index first
if (attemptDrop && !DropIndex(idxName))
- return (FALSE);
+ return (false);
// MySQL (and possibly Sybase ASE?? - gt) require that any columns which are used as portions
// of an index have the columns defined as "NOT NULL". During initial table creation though,
{
wxString sqlStmt;
int i;
- bool ok = TRUE;
+ bool ok = true;
for (i = 0; i < noIdxCols && ok; i++)
{
int j = 0;
- bool found = FALSE;
+ bool found = false;
// Find the column definition that has the ColName that matches the
// index column name. We need to do this to get the DB_DATA_TYPE of
// the index column, as MySQL's syntax for the ALTER column requires
while (!found && (j < this->noCols))
{
if (wxStrcmp(colDefs[j].ColName,pIdxDefs[i].ColName) == 0)
- found = TRUE;
+ found = true;
if (!found)
j++;
}
}
}
else
- ok = FALSE;
+ ok = false;
}
if (ok)
pDb->CommitTrans();
else
{
pDb->RollbackTrans();
- return(FALSE);
+ return(false);
}
}
sqlStmt += wxT(" DESC");
}
else
- wxASSERT_MSG(!pIdxDefs[i].Ascending, "Datasource does not support DESCending index columns");
+ wxASSERT_MSG(pIdxDefs[i].Ascending, "Datasource does not support DESCending index columns");
if ((i + 1) < noIdxCols)
sqlStmt += wxT(",");
pDb->DispAllErrors(henv, hdbc, hstmt);
pDb->RollbackTrans();
CloseCursor(hstmt);
- return(FALSE);
+ return(false);
}
// Commit the transaction and close the cursor
if (! pDb->CommitTrans())
- return(FALSE);
+ return(false);
if (! CloseCursor(hstmt))
- return(FALSE);
+ return(false);
// Index Created Successfully
- return(TRUE);
+ return(true);
} // wxDbTable::CreateIndex()
/********** wxDbTable::DropIndex() **********/
bool wxDbTable::DropIndex(const wxString &idxName)
{
- // NOTE: This function returns TRUE if the Index does not exist, but
+ // NOTE: This function returns true if the Index does not exist, but
// only for identified databases. Code will need to be added
// below for any other databases when those databases are defined
// to handle this situation consistently
pDb->DispAllErrors(henv, hdbc, hstmt);
pDb->RollbackTrans();
CloseCursor(hstmt);
- return(FALSE);
+ return(false);
}
}
}
// Commit the transaction and close the cursor
if (! pDb->CommitTrans())
- return(FALSE);
+ return(false);
if (! CloseCursor(hstmt))
- return(FALSE);
+ return(false);
- return(TRUE);
+ return(true);
} // wxDbTable::DropIndex()
int colNo = first; // using 'int' to be able to look for wxDB_NO_MORE_COLUN_NUMBERS
va_list argptr;
- bool abort = FALSE;
+ bool abort = false;
wxString tempStr;
va_start(argptr, first); /* Initialize variable arguments. */
// Valid columns are 0 thru noCols-1
if (colNo >= noCols || colNo < 0)
{
- abort = TRUE;
+ abort = true;
continue;
}
{
wxASSERT(!queryOnly);
if (queryOnly)
- return(FALSE);
+ return(false);
wxString sqlStmt;
{
wxASSERT(!queryOnly);
if (queryOnly)
- return(FALSE);
+ return(false);
pDb->WriteSqlLog(pSqlStmt);
{
wxASSERT(!queryOnly);
if (queryOnly)
- return(FALSE);
+ return(false);
wxString sqlStmt;
{
wxASSERT(!queryOnly);
if (queryOnly)
- return(FALSE);
+ return(false);
wxString sqlStmt;
sqlStmt.Empty();
{
wxASSERT(!queryOnly);
if (queryOnly)
- return(FALSE);
+ return(false);
wxString sqlStmt;
sqlStmt.Empty();
{
wxASSERT(!queryOnly);
if (queryOnly)
- return(FALSE);
+ return(false);
wxString sqlStmt;
sqlStmt.Empty();
/********** wxDbTable::IsColNull() **********/
-bool wxDbTable::IsColNull(UWORD colNo)
+bool wxDbTable::IsColNull(UWORD colNo) const
{
/*
- This logic is just not right. It would indicate TRUE
+ This logic is just not right. It would indicate true
if a numeric field were set to a value of 0.
switch(colDefs[colNo].SqlCtype)
TIMESTAMP_STRUCT *pDt;
pDt = (TIMESTAMP_STRUCT *) colDefs[colNo].PtrDataObj;
if (pDt->year == 0 && pDt->month == 0 && pDt->day == 0)
- return(TRUE);
+ return(true);
else
- return(FALSE);
+ return(false);
default:
- return(TRUE);
+ return(true);
}
*/
return (colDefs[colNo].Null);
bool wxDbTable::CanSelectForUpdate(void)
{
if (queryOnly)
- return FALSE;
+ return false;
if (pDb->Dbms() == dbmsMY_SQL)
- return FALSE;
+ return false;
if ((pDb->Dbms() == dbmsORACLE) ||
(pDb->dbInf.posStmts & SQL_PS_SELECT_FOR_UPDATE))
- return(TRUE);
+ return(true);
else
- return(FALSE);
+ return(false);
} // wxDbTable::CanSelectForUpdate()
bool wxDbTable::CanUpdByROWID(void)
{
/*
- * NOTE: Returning FALSE for now until this can be debugged,
+ * NOTE: Returning false for now until this can be debugged,
* as the ROWID is not getting updated correctly
*/
- return FALSE;
+ return false;
/*
if (pDb->Dbms() == dbmsORACLE)
- return(TRUE);
+ return(true);
else
- return(FALSE);
+ return(false);
*/
} // wxDbTable::CanUpdByROWID()
bool wxDbTable::IsCursorClosedOnCommit(void)
{
if (pDb->dbInf.cursorCommitBehavior == SQL_CB_PRESERVE)
- return(FALSE);
+ return(false);
else
- return(TRUE);
+ return(true);
} // wxDbTable::IsCursorClosedOnCommit()
return(pDb->DispAllErrors(henv, hdbc, hstmtInternal));
// Completed Successfully
- return(TRUE);
+ return(true);
} // wxDbTable::SetQueryTimeout()
// Derived columns by definition would NOT be "Insertable" or "Updateable"
if (derivedCol)
{
- colDefs[index].Updateable = FALSE;
- colDefs[index].InsertAllowed = FALSE;
+ colDefs[index].Updateable = false;
+ colDefs[index].InsertAllowed = false;
}
else
{
colDefs[index].InsertAllowed = insAllow;
}
- colDefs[index].Null = FALSE;
+ colDefs[index].Null = false;
} // wxDbTable::SetColDefs()
// Initialize the Count cursor if it's not already initialized
if (!hstmtCount)
{
- hstmtCount = GetNewCursor(FALSE,FALSE);
+ hstmtCount = GetNewCursor(false,false);
wxASSERT(hstmtCount);
if (!hstmtCount)
return(0);
/********** wxDbTable::Refresh() **********/
bool wxDbTable::Refresh(void)
{
- bool result = TRUE;
+ bool result = true;
// Switch to the internal cursor so any active cursors are not corrupted
HSTMT currCursor = GetCursor();
where = whereClause;
orderBy.Empty();
if (!Query())
- result = FALSE;
+ result = false;
if (result && !GetNext())
- result = FALSE;
+ result = false;
// Switch back to original cursor
SetCursor(&currCursor);
{
colDefs[colNo].Null = set;
if (set) // Blank out the values in the member variable
- ClearMemberVar(colNo,FALSE); // Must call with FALSE, or infinite recursion will happen
- return(TRUE);
+ ClearMemberVar(colNo,false); // Must call with false, or infinite recursion will happen
+ return(true);
}
else
- return(FALSE);
+ return(false);
} // wxDbTable::SetColNull()
{
colDefs[i].Null = set;
if (set) // Blank out the values in the member variable
- ClearMemberVar(i,FALSE); // Must call with FALSE, or infinite recursion will happen
- return(TRUE);
+ ClearMemberVar(i,false); // Must call with false, or infinite recursion will happen
+ return(true);
}
else
- return(FALSE);
+ return(false);
} // wxDbTable::SetColNull()
if (bindColumns)
{
- if(!bindCols(*newHSTMT))
+ if (!bindCols(*newHSTMT))
{
delete newHSTMT;
return(0);
/********** wxDbTable::DeleteCursor() **********/
bool wxDbTable::DeleteCursor(HSTMT *hstmtDel)
{
- bool result = TRUE;
+ bool result = true;
if (!hstmtDel) // Cursor already deleted
return(result);
if (SQLFreeStmt(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
{
pDb->DispAllErrors(henv, hdbc);
- result = FALSE;
+ result = false;
}
delete hstmtDel;
} // wxDbTable::DeleteCursor()
+//////////////////////////////////////////////////////////////
+// wxDbGrid support functions
+//////////////////////////////////////////////////////////////
+
+void wxDbTable::SetRowMode(const rowmode_t rowmode)
+{
+ if (!m_hstmtGridQuery)
+ {
+ m_hstmtGridQuery = GetNewCursor(false,false);
+ if (!bindCols(*m_hstmtGridQuery))
+ return;
+ }
+
+ m_rowmode = rowmode;
+ switch (m_rowmode)
+ {
+ case WX_ROW_MODE_QUERY:
+ SetCursor(m_hstmtGridQuery);
+ break;
+ case WX_ROW_MODE_INDIVIDUAL:
+ SetCursor(hstmtDefault);
+ break;
+ default:
+ assert(0);
+ }
+} // wxDbTable::SetRowMode()
+
+
+wxVariant wxDbTable::GetCol(const int col) const
+{
+ wxVariant val;
+ if ((col < noCols) && (!IsColNull(col)))
+ {
+ switch (colDefs[col].SqlCtype)
+ {
+ case SQL_CHAR:
+ case SQL_VARCHAR:
+ val = (char *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_LONG:
+ case SQL_C_SLONG:
+ val = *(long *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_SHORT:
+ case SQL_C_SSHORT:
+ val = (long int )(*(short *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_ULONG:
+ val = (long)(*(unsigned long *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_TINYINT:
+ val = (long)(*(char *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_UTINYINT:
+ val = (long)(*(unsigned char *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_USHORT:
+ val = (long)(*(UWORD *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_DATE:
+ val = (DATE_STRUCT *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_TIME:
+ val = (TIME_STRUCT *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_TIMESTAMP:
+ val = (TIMESTAMP_STRUCT *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_DOUBLE:
+ val = *(double *)(colDefs[col].PtrDataObj);
+ break;
+ default:
+ assert(0);
+ }
+ }
+ return val;
+} // wxDbTable::GetCol()
+
+
+void csstrncpyt(char *s, const char *t, int n)
+{
+ while ((*s++ = *t++) && --n)
+ {};
+
+ *s = '\0';
+}
+
+void wxDbTable::SetCol(const int col, const wxVariant val)
+{
+ //FIXME: Add proper wxDateTime support to wxVariant..
+ wxDateTime dateval;
+
+ SetColNull(col, val.IsNull());
+
+ if (!val.IsNull())
+ {
+ if ((colDefs[col].SqlCtype == SQL_C_DATE)
+ || (colDefs[col].SqlCtype == SQL_C_TIME)
+ || (colDefs[col].SqlCtype == SQL_C_TIMESTAMP))
+ {
+ //Returns null if invalid!
+ if (!dateval.ParseDate(val.GetString()))
+ SetColNull(col,true);
+ }
+
+ switch (colDefs[col].SqlCtype)
+ {
+ case SQL_CHAR:
+ case SQL_VARCHAR:
+ csstrncpyt((char *)(colDefs[col].PtrDataObj),
+ val.GetString().c_str(),
+ colDefs[col].SzDataObj-1);
+ break;
+ case SQL_C_LONG:
+ case SQL_C_SLONG:
+ *(long *)(colDefs[col].PtrDataObj) = val;
+ break;
+ case SQL_C_SHORT:
+ case SQL_C_SSHORT:
+ *(short *)(colDefs[col].PtrDataObj) = val.GetLong();
+ break;
+ case SQL_C_ULONG:
+ *(unsigned long *)(colDefs[col].PtrDataObj) = val.GetLong();
+ break;
+ case SQL_C_TINYINT:
+ *(char *)(colDefs[col].PtrDataObj) = val.GetChar();
+ break;
+ case SQL_C_UTINYINT:
+ *(unsigned char *)(colDefs[col].PtrDataObj) = val.GetChar();
+ break;
+ case SQL_C_USHORT:
+ *(unsigned short *)(colDefs[col].PtrDataObj) = val.GetLong();
+ break;
+ //FIXME: Add proper wxDateTime support to wxVariant..
+ case SQL_C_DATE:
+ {
+ DATE_STRUCT *dataptr =
+ (DATE_STRUCT *)colDefs[col].PtrDataObj;
+
+ dataptr->year = dateval.GetYear();
+ dataptr->month = dateval.GetMonth()+1;
+ dataptr->day = dateval.GetDay();
+ }
+ break;
+ case SQL_C_TIME:
+ {
+ TIME_STRUCT *dataptr =
+ (TIME_STRUCT *)colDefs[col].PtrDataObj;
+
+ dataptr->hour = dateval.GetHour();
+ dataptr->minute = dateval.GetMinute();
+ dataptr->second = dateval.GetSecond();
+ }
+ break;
+ case SQL_C_TIMESTAMP:
+ {
+ TIMESTAMP_STRUCT *dataptr =
+ (TIMESTAMP_STRUCT *)colDefs[col].PtrDataObj;
+ dataptr->year = dateval.GetYear();
+ dataptr->month = dateval.GetMonth()+1;
+ dataptr->day = dateval.GetDay();
+
+ dataptr->hour = dateval.GetHour();
+ dataptr->minute = dateval.GetMinute();
+ dataptr->second = dateval.GetSecond();
+ }
+ break;
+ case SQL_C_DOUBLE:
+ *(double *)(colDefs[col].PtrDataObj) = val;
+ break;
+ default:
+ assert(0);
+ } // switch
+ } // if (!val.IsNull())
+} // wxDbTable::SetCol()
+
+
+GenericKey wxDbTable::GetKey()
+{
+ void *blk;
+ char *blkptr;
+
+ blk = malloc(m_keysize);
+ blkptr = (char *) blk;
+
+ int i;
+ for (i=0; i < noCols; i++)
+ {
+ if (colDefs[i].KeyField)
+ {
+ memcpy(blkptr,colDefs[i].PtrDataObj, colDefs[i].SzDataObj);
+ blkptr += colDefs[i].SzDataObj;
+ }
+ }
+
+ GenericKey k = GenericKey(blk, m_keysize);
+ free(blk);
+
+ return k;
+} // wxDbTable::GetKey()
+
+
+void wxDbTable::SetKey(const GenericKey& k)
+{
+ void *blk;
+ char *blkptr;
+
+ blk = k.GetBlk();
+ blkptr = (char *)blk;
+
+ int i;
+ for (i=0; i < noCols; i++)
+ {
+ if (colDefs[i].KeyField)
+ {
+ SetColNull(i, false);
+ memcpy(colDefs[i].PtrDataObj, blkptr, colDefs[i].SzDataObj);
+ blkptr += colDefs[i].SzDataObj;
+ }
+ }
+} // wxDbTable::SetKey()
+
+
#endif // wxUSE_ODBC