/********** wxDbTable::wxDbTable() Constructor **********/
-wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const int nCols,
+wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
const wxString &qryTblName, bool qryOnly, const wxString &tblPath)
{
- if (!initialize(pwxDb, tblName, nCols, qryTblName, qryOnly, tblPath))
+ if (!initialize(pwxDb, tblName, numColumns, qryTblName, qryOnly, tblPath))
cleanup();
} // wxDbTable::wxDbTable()
/***** DEPRECATED: use wxDbTable::wxDbTable() format above *****/
-wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const int nCols,
+wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
const wxChar *qryTblName, bool qryOnly, const wxString &tblPath)
{
wxString tempQryTblName;
tempQryTblName = qryTblName;
- if (!initialize(pwxDb, tblName, nCols, tempQryTblName, qryOnly, tblPath))
+ if (!initialize(pwxDb, tblName, numColumns, tempQryTblName, qryOnly, tblPath))
cleanup();
} // wxDbTable::wxDbTable()
} // wxDbTable::~wxDbTable()
-bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const int nCols,
+bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
const wxString &qryTblName, bool qryOnly, const wxString &tblPath)
{
// Initializing member variables
hstmtInternal = 0;
colDefs = 0;
tableID = 0;
- noCols = nCols; // No. of cols in the table
+ noCols = numColumns; // Number of cols in the table
where.Empty(); // Where clause
orderBy.Empty(); // Order By clause
from.Empty(); // From clause
// Bind each column of the table that should be bound
// to a parameter marker
- int i,colNo;
+ int i;
+ UWORD colNo;
for (i = 0, colNo = 1; i < noCols; i++)
{
if (forUpdate)
//RG-NULL static SDWORD cb;
// Bind each column of the table to a memory address for fetching data
- int i;
+ UWORD i;
for (i = 0; i < noCols; i++)
{
- if (SQLBindCol(cursor, i+1, colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
-//RG-NULL colDefs[i].SzDataObj, &cb) != SQL_SUCCESS)
+ if (SQLBindCol(cursor, (UWORD)(i+1), colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
colDefs[i].SzDataObj, &colDefs[i].CbValue ) != SQL_SUCCESS)
{
return (pDb->DispAllErrors(henv, hdbc, cursor));
/********** wxDbTable::Open() **********/
-bool wxDbTable::Open(bool checkPrivileges)
+bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
{
if (!pDb)
return FALSE;
s.Empty();
// Verify that the table exists in the database
- if (!pDb->TableExists(tableName,/*pDb->GetUsername()*/NULL,tablePath))
+ if (checkTableExists && !pDb->TableExists(tableName, pDb->GetUsername(), tablePath))
{
s = wxT("Table/view does not exist in the database");
if ( *(pDb->dbInf.accessibleTables) == wxT('Y'))
// Unfortunately this optimization doesn't seem to be
// reliable!
if (// *(pDb->dbInf.accessibleTables) == 'N' &&
- !pDb->TablePrivileges(tableName,wxT("SELECT"),NULL,pDb->GetUsername(),tablePath))
+ !pDb->TablePrivileges(tableName,wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath))
s = wxT("Current logged in user does not have sufficient privileges to access this table.\n");
}
// Get the ROWID value. If not successful retreiving the ROWID,
// simply fall down through the code and build the WHERE clause
// based on the key fields.
- if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
+ if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
{
pSqlStmt += wxT("ROWID = '");
pSqlStmt += rowid;
// Get the ROWID value. If not successful retreiving the ROWID,
// simply fall down through the code and build the WHERE clause
// based on the key fields.
- if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
+ if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
{
pSqlStmt += wxT("ROWID = '");
pSqlStmt += rowid;
}
if (j && pDb->Dbms() != dbmsDBASE) // Found a keyfield
{
- if (pDb->Dbms() != dbmsMY_SQL)
- {
- sqlStmt += wxT(",CONSTRAINT ");
- sqlStmt += tableName;
- sqlStmt += wxT("_PIDX PRIMARY KEY (");
- }
- else
+ switch (pDb->Dbms())
{
- /* MySQL goes out on this one. We also declare the relevant key NON NULL above */
- sqlStmt += wxT(", PRIMARY KEY (");
+ case dbmsSYBASE_ASA:
+ case dbmsSYBASE_ASE:
+ case dbmsMY_SQL:
+ {
+ /* MySQL goes out on this one. We also declare the relevant key NON NULL above */
+ sqlStmt += wxT(",PRIMARY KEY (");
+ break;
+ }
+ default:
+ {
+ sqlStmt += wxT(",CONSTRAINT ");
+ sqlStmt += tableName;
+ sqlStmt += wxT("_PIDX PRIMARY KEY (");
+ break;
+ }
}
// List column name(s) of column(s) comprising the primary key
}
}
sqlStmt += wxT(")");
+
+ if (pDb->Dbms() == dbmsSYBASE_ASA ||
+ pDb->Dbms() == dbmsSYBASE_ASE)
+ {
+ sqlStmt += wxT(" CONSTRAINT ");
+ sqlStmt += tableName;
+ sqlStmt += wxT("_PIDX");
+ }
}
// Append the closing parentheses for the create table statement
sqlStmt += wxT(")");
/********** wxDbTable::CreateIndex() **********/
-bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, int noIdxCols, wxDbIdxDef *pIdxDefs, bool attemptDrop)
+bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCols,
+ wxDbIdxDef *pIdxDefs, bool attemptDrop)
{
wxString sqlStmt;
/********** wxDbTable::SetOrderByColNums() **********/
-bool wxDbTable::SetOrderByColNums(int first, ... )
+bool wxDbTable::SetOrderByColNums(UWORD first, ... )
{
- int colNo = first;
+ int colNo = first; // using 'int' to be able to look for wxDB_NO_MORE_COLUN_NUMBERS
va_list argptr;
bool abort = FALSE;
/********** wxDbTable::IsColNull() **********/
-bool wxDbTable::IsColNull(int colNo)
+bool wxDbTable::IsColNull(UWORD colNo)
{
/*
This logic is just not right. It would indicate TRUE
* as the ROWID is not getting updated correctly
*/
return FALSE;
-
+/*
if (pDb->Dbms() == dbmsORACLE)
return(TRUE);
else
return(FALSE);
-
+*/
} // wxDbTable::CanUpdByROWID()
/********** wxDbTable::ClearMemberVar() **********/
-void wxDbTable::ClearMemberVar(int colNo, bool setToNull)
+void wxDbTable::ClearMemberVar(UWORD colNo, bool setToNull)
{
wxASSERT(colNo < noCols);
/********** wxDbTable::SetColDefs() **********/
-void wxDbTable::SetColDefs(int index, const wxString &fieldName, int dataType, void *pData,
- int cType, int size, bool keyField, bool upd,
+void wxDbTable::SetColDefs(UWORD index, const wxString &fieldName, int dataType, void *pData,
+ SWORD cType, int size, bool keyField, bool upd,
bool insAllow, bool derivedCol)
{
if (!colDefs) // May happen if the database connection fails
/********** wxDbTable::SetColDefs() **********/
-wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, ULONG numCols)
+wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, UWORD numCols)
{
wxASSERT(pColInfs);
wxDbColDataPtr *pColDataPtrs = NULL;
if (pColInfs)
{
- ULONG index;
+ UWORD index;
pColDataPtrs = new wxDbColDataPtr[numCols+1];
}
// Obtain the result
- if (SQLGetData(*hstmtCount, 1, SQL_C_ULONG, &count, sizeof(count), &cb) != SQL_SUCCESS)
+ if (SQLGetData(*hstmtCount, (UWORD)1, SQL_C_ULONG, &count, sizeof(count), &cb) != SQL_SUCCESS)
{
pDb->DispAllErrors(henv, hdbc, *hstmtCount);
return(0);
// Get the ROWID value. If not successful retreiving the ROWID,
// simply fall down through the code and build the WHERE clause
// based on the key fields.
- if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
+ if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
{
whereClause += queryTableName;
whereClause += wxT(".ROWID = '");
} // wxDbTable::Refresh()
-/********** wxDbTable::SetColNull(int colNo, bool set) **********/
-bool wxDbTable::SetColNull(int colNo, bool set)
+/********** wxDbTable::SetColNull() **********/
+bool wxDbTable::SetColNull(UWORD colNo, bool set)
{
if (colNo < noCols)
{
} // wxDbTable::SetColNull()
-/********** wxDbTable::SetColNull(const wxString &colName, bool set) **********/
+/********** wxDbTable::SetColNull() **********/
bool wxDbTable::SetColNull(const wxString &colName, bool set)
{
int i;