// specified before the connection is made.
retcode = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_IF_NEEDED);
- #ifdef DBDEBUG_CONSOLE
+#ifdef DBDEBUG_CONSOLE
if (retcode == SQL_SUCCESS)
cout << "SQLSetConnectOption(CURSOR_LIB) successful" << endl;
else
cout << "SQLSetConnectOption(CURSOR_LIB) failed" << endl;
- #endif
+#endif
#endif
} // wxDB::DispNextError()
/********** wxDB::logError() **********/
-void wxDB::logError(char *errMsg, char *SQLState)
+void wxDB::logError(const char *errMsg, const char *SQLState)
{
assert(errMsg && wxStrlen(errMsg));
} // wxDB::logError()
/**********wxDB::TranslateSqlState() **********/
-int wxDB::TranslateSqlState(char *SQLState)
+int wxDB::TranslateSqlState(const char *SQLState)
{
if (!wxStrcmp(SQLState, "01000"))
return(DB_ERR_GENERAL_WARNING);
} // wxDB::TranslateSqlState()
/********** wxDB::Grant() **********/
-bool wxDB::Grant(int privileges, char *tableName, char *userList)
+bool wxDB::Grant(int privileges, const char *tableName, const char *userList)
{
char sqlStmt[DB_MAX_STATEMENT_LEN];
} // wxDB::Grant()
/********** wxDB::CreateView() **********/
-bool wxDB::CreateView(char *viewName, char *colList, char *pSqlStmt, bool attemptDrop)
+bool wxDB::CreateView(const char *viewName, const char *colList, const char *pSqlStmt, bool attemptDrop)
{
char sqlStmt[DB_MAX_STATEMENT_LEN];
} // wxDB::CreateView()
/********** wxDB::DropView() **********/
-bool wxDB::DropView(char *viewName)
+bool wxDB::DropView(const char *viewName)
{
// NOTE: This function returns TRUE if the View does not exist, but
// only for identified databases. Code will need to be added
/********** wxDB::ExecSql() **********/
-bool wxDB::ExecSql(char *pSqlStmt)
+bool wxDB::ExecSql(const char *pSqlStmt)
{
SQLFreeStmt(hstmt, SQL_CLOSE);
if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) == SQL_SUCCESS)
* delete [] colInf;
* }
*/
-CcolInf *wxDB::GetColumns(char *tableName[], char *userID)
+CcolInf *wxDB::GetColumns(char *tableName[], const char *userID)
{
- UINT noCols = 0;
- UINT colNo = 0;
+ UINT noCols = 0;
+ UINT colNo = 0;
CcolInf *colInf = 0;
- RETCODE retcode;
- SDWORD cb;
- char tblName[DB_MAX_TABLE_NAME_LEN+1];
- char colName[DB_MAX_COLUMN_NAME_LEN+1];
- SWORD sqlDataType;
- char userIdUC[80+1];
- char tableNameUC[DB_MAX_TABLE_NAME_LEN+1];
+
+ RETCODE retcode;
+ SDWORD cb;
+ char tblName[DB_MAX_TABLE_NAME_LEN+1];
+ char colName[DB_MAX_COLUMN_NAME_LEN+1];
+ SWORD sqlDataType;
+
+ wxString UserID;
+ wxString TableName;
if (!userID || !wxStrlen(userID))
- userID = uid;
+ UserID = uid;
+ else
+ UserID = userID;
// dBase does not use user names, and some drivers fail if you try to pass one
if (Dbms() == dbmsDBASE)
- userID = "";
+ UserID = "";
// Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
- {
- int i = 0;
- for (char *p = userID; *p; p++)
- userIdUC[i++] = toupper(*p);
- userIdUC[i] = 0;
- userID = userIdUC;
- }
+ UserID = UserID.Upper();
// Pass 1 - Determine how many columns there are.
// Pass 2 - Allocate the CcolInf array and fill in
int tbl;
for (tbl = 0; tableName[tbl]; tbl++)
{
+ TableName = tableName[tbl];
// Oracle table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this
if (Dbms() == dbmsORACLE)
- {
- int i = 0;
- for (char *p = tableName[tbl]; *p; p++)
- tableNameUC[i++] = toupper(*p);
- tableNameUC[i] = 0;
- }
- else
- sprintf(tableNameUC,tableName[tbl]);
+ TableName = TableName.Upper();
SQLFreeStmt(hstmt, SQL_CLOSE);
// 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
- if (wxStrcmp(userID,"") &&
+ if (wxStrcmp(UserID.GetData(),"") &&
Dbms() != dbmsMY_SQL &&
Dbms() != dbmsACCESS)
{
retcode = SQLColumns(hstmt,
NULL, 0, // All qualifiers
- (UCHAR *) userID, SQL_NTS, // Owner
- (UCHAR *) tableNameUC, SQL_NTS,
+ (UCHAR *) UserID.GetData(), SQL_NTS, // Owner
+ (UCHAR *) TableName.GetData(), SQL_NTS,
NULL, 0); // All columns
}
else
retcode = SQLColumns(hstmt,
NULL, 0, // All qualifiers
NULL, 0, // Owner
- (UCHAR *) tableNameUC, SQL_NTS,
+ (UCHAR *) TableName.GetData(), SQL_NTS,
NULL, 0); // All columns
}
if (retcode != SQL_SUCCESS)
SQLFreeStmt(hstmt, SQL_CLOSE);
return(0);
}
- SQLBindCol(hstmt, 3, SQL_C_CHAR, (UCHAR*) tblName, DB_MAX_TABLE_NAME_LEN+1, &cb);
- SQLBindCol(hstmt, 4, SQL_C_CHAR, (UCHAR*) colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
+ SQLBindCol(hstmt, 3, SQL_C_CHAR, (UCHAR*) tblName, DB_MAX_TABLE_NAME_LEN+1, &cb);
+ SQLBindCol(hstmt, 4, SQL_C_CHAR, (UCHAR*) colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
SQLBindCol(hstmt, 5, SQL_C_SSHORT, (UCHAR*) &sqlDataType, 0, &cb);
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
{
/********** wxDB::Catalog() **********/
-bool wxDB::Catalog(char *userID, char *fileName)
+bool wxDB::Catalog(const char *userID, const char *fileName)
{
assert(fileName && wxStrlen(fileName));
char typeName[30+1];
SWORD precision, length;
+ wxString UserID;
+
FILE *fp = fopen(fileName,"wt");
if (fp == NULL)
return(FALSE);
SQLFreeStmt(hstmt, SQL_CLOSE);
if (!userID || !wxStrlen(userID))
- userID = uid;
+ UserID = uid;
+ else
+ UserID = userID;
- char userIdUC[80+1];
// Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
- {
- int i = 0;
- for (char *p = userID; *p; p++)
- userIdUC[i++] = toupper(*p);
- userIdUC[i] = 0;
- userID = userIdUC;
- }
+ UserID = UserID.Upper();
- if (wxStrcmp(userID,""))
+ if (wxStrcmp(UserID.GetData(),""))
{
retcode = SQLColumns(hstmt,
NULL, 0, // All qualifiers
- (UCHAR *) userID, SQL_NTS, // User specified
+ (UCHAR *) UserID.GetData(), SQL_NTS, // User specified
NULL, 0, // All tables
NULL, 0); // All columns
}
// if the object exists in the database. This function does not indicate
// whether or not the user has privleges to query or perform other functions
// on the table.
-bool wxDB::TableExists(char *tableName, char *userID, char *tablePath)
+bool wxDB::TableExists(const char *tableName, const char *userID, const char *tablePath)
{
+ wxString UserID;
+ wxString TableName;
+
assert(tableName && wxStrlen(tableName));
if (Dbms() == dbmsDBASE)
dbName.sprintf("%s/%s.dbf",tablePath,tableName);
else
dbName.sprintf("%s.dbf",tableName);
- bool glt;
- glt = wxFileExists(dbName.GetData());
- return glt;
+
+ bool exists;
+ exists = wxFileExists(dbName.GetData());
+ return exists;
}
if (!userID || !wxStrlen(userID))
- userID = uid;
+ UserID = uid;
+ else
+ UserID = userID;
- char userIdUC[80+1];
// Oracle user names may only be in uppercase, so force
// the name to uppercase
if (Dbms() == dbmsORACLE)
- {
- int i = 0;
- for (char *p = userID; *p; p++)
- userIdUC[i++] = toupper(*p);
- userIdUC[i] = 0;
- userID = userIdUC;
- }
+ UserID = UserID.Upper();
- char tableNameUC[DB_MAX_TABLE_NAME_LEN+1];
+ TableName = tableName;
// Oracle table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this
if (Dbms() == dbmsORACLE)
- {
- int i = 0;
- for (char *p = tableName; *p; p++)
- tableNameUC[i++] = toupper(*p);
- tableNameUC[i] = 0;
- }
- else
- sprintf(tableNameUC,tableName);
+ TableName = TableName.Upper();
SQLFreeStmt(hstmt, SQL_CLOSE);
RETCODE retcode;
// MySQL and Access cannot accept a user name when looking up table names, so we
// use the call below that leaves out the user name
- if (wxStrcmp(userID,"") &&
+ if (wxStrcmp(UserID,"") &&
Dbms() != dbmsMY_SQL &&
Dbms() != dbmsACCESS)
{
retcode = SQLTables(hstmt,
- NULL, 0, // All qualifiers
- (UCHAR *) userID, SQL_NTS, // All owners
- (UCHAR FAR *)tableNameUC, SQL_NTS,
- NULL, 0); // All table types
+ NULL, 0, // All qualifiers
+ (UCHAR *) UserID.GetData(), SQL_NTS, // All owners
+ (UCHAR FAR *)TableName.GetData(), SQL_NTS,
+ NULL, 0); // All table types
}
else
{
retcode = SQLTables(hstmt,
- NULL, 0, // All qualifiers
- NULL, 0, // All owners
- (UCHAR FAR *)tableNameUC, SQL_NTS,
- NULL, 0); // All table types
+ NULL, 0, // All qualifiers
+ NULL, 0, // All owners
+ (UCHAR FAR *)TableName.GetData(), SQL_NTS,
+ NULL, 0); // All table types
}
if (retcode != SQL_SUCCESS)
return(DispAllErrors(henv, hdbc, hstmt));
/********** wxDB::SqlLog() **********/
-bool wxDB::SqlLog(enum sqlLog state, char *filename, bool append)
+bool wxDB::SqlLog(enum sqlLog state, const char *filename, bool append)
{
assert(state == sqlLogON || state == sqlLogOFF);
assert(state == sqlLogOFF || filename);
/********** wxDB::WriteSqlLog() **********/
-bool wxDB::WriteSqlLog(char *logMsg)
+bool wxDB::WriteSqlLog(const char *logMsg)
{
assert(logMsg);
} // SqlLog()
/********** GetDataSource() **********/
-bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax,
+bool GetDataSource(HENV henv, const char *Dsn, SWORD DsnMax, const char *DsDesc, SWORD DsDescMax,
UWORD direction)
{
SWORD cb;
/********** wxTable::wxTable() **********/
wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols,
- const char *qryTblName, bool qryOnly, char *tblPath)
+ const char *qryTblName, bool qryOnly, const char *tblPath)
{
pDb = pwxDB; // Pointer to the wxDB object
henv = 0;
} // wxTable::~wxTable()
+/***************************** PRIVATE FUNCTIONS *****************************/
+
+/********** wxTable::bindInsertParams() **********/
+bool wxTable::bindInsertParams(void)
+{
+ assert(!queryOnly);
+ if (queryOnly)
+ return(FALSE);
+
+ SWORD fSqlType = 0;
+ UDWORD precision = 0;
+ SWORD scale = 0;
+
+ // Bind each column (that can be inserted) of the table to a parameter marker
+ int i;
+ for (i = 0; i < noCols; i++)
+ {
+ if (! colDefs[i].InsertAllowed)
+ continue;
+ switch(colDefs[i].DbDataType)
+ {
+ case DB_DATA_TYPE_VARCHAR:
+ fSqlType = pDb->typeInfVarchar.FsqlType;
+ precision = colDefs[i].SzDataObj;
+ scale = 0;
+ colDefs[i].CbValue = SQL_NTS;
+ break;
+ case DB_DATA_TYPE_INTEGER:
+ fSqlType = pDb->typeInfInteger.FsqlType;
+ precision = pDb->typeInfInteger.Precision;
+ scale = 0;
+ colDefs[i].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_FLOAT:
+ fSqlType = pDb->typeInfFloat.FsqlType;
+ precision = pDb->typeInfFloat.Precision;
+ scale = pDb->typeInfFloat.MaximumScale;
+ // SQL Sybase Anywhere v5.5 returned a negative number for the
+ // MaxScale. This caused ODBC to kick out an error on ibscale.
+ // I check for this here and set the scale = precision.
+ //if (scale < 0)
+ // scale = (short) precision;
+ colDefs[i].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_DATE:
+ fSqlType = pDb->typeInfDate.FsqlType;
+ precision = pDb->typeInfDate.Precision;
+ scale = 0;
+ colDefs[i].CbValue = 0;
+ break;
+ }
+ // Null values
+ if (colDefs[i].Null)
+ {
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ colDefs[i].Null = FALSE;
+ }
+ if (SQLBindParameter(hstmtInsert, i+1, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
+ fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
+ precision+1,&colDefs[i].CbValue) != SQL_SUCCESS)
+ return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
+ }
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxTable::bindInsertParams()
+
+/********** wxTable::bindUpdateParams() **********/
+bool wxTable::bindUpdateParams(void)
+{
+ assert(!queryOnly);
+ if (queryOnly)
+ return(FALSE);
+
+ SWORD fSqlType = 0;
+ UDWORD precision = 0;
+ SWORD scale = 0;
+
+ // Bind each UPDATEABLE column of the table to a parameter marker
+ int i,colNo;
+ for (i = 0, colNo = 1; i < noCols; i++)
+ {
+ if (! colDefs[i].Updateable)
+ continue;
+ switch(colDefs[i].DbDataType)
+ {
+ case DB_DATA_TYPE_VARCHAR:
+ fSqlType = pDb->typeInfVarchar.FsqlType;
+ precision = colDefs[i].SzDataObj;
+ scale = 0;
+ colDefs[i].CbValue = SQL_NTS;
+ break;
+ case DB_DATA_TYPE_INTEGER:
+ fSqlType = pDb->typeInfInteger.FsqlType;
+ precision = pDb->typeInfInteger.Precision;
+ scale = 0;
+ colDefs[i].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_FLOAT:
+ fSqlType = pDb->typeInfFloat.FsqlType;
+ precision = pDb->typeInfFloat.Precision;
+ scale = pDb->typeInfFloat.MaximumScale;
+ // SQL Sybase Anywhere v5.5 returned a negative number for the
+ // MaxScale. This caused ODBC to kick out an error on ibscale.
+ // I check for this here and set the scale = precision.
+ //if (scale < 0)
+ // scale = (short) precision;
+ colDefs[i].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_DATE:
+ fSqlType = pDb->typeInfDate.FsqlType;
+ precision = pDb->typeInfDate.Precision;
+ scale = 0;
+ colDefs[i].CbValue = 0;
+ break;
+ }
+ if (SQLBindParameter(hstmtUpdate, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
+ fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
+ precision+1, &colDefs[i].CbValue) != SQL_SUCCESS)
+ return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
+ }
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxTable::bindUpdateParams()
+
+/********** wxTable::bindCols() **********/
+bool wxTable::bindCols(HSTMT cursor)
+{
+ static SDWORD cb;
+
+ // Bind each column of the table to a memory address for fetching data
+ int i;
+ for (i = 0; i < noCols; i++)
+ {
+ if (SQLBindCol(cursor, i+1, colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
+ colDefs[i].SzDataObj, &cb) != SQL_SUCCESS)
+ return(pDb->DispAllErrors(henv, hdbc, cursor));
+ }
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxTable::bindCols()
+
+/********** wxTable::getRec() **********/
+bool wxTable::getRec(UWORD fetchType)
+{
+ RETCODE retcode;
+
+#if !wxODBC_FWD_ONLY_CURSORS
+
+ // Fetch the NEXT, PREV, FIRST or LAST record, depending on fetchType
+ UDWORD cRowsFetched;
+ UWORD rowStatus;
+
+// if ((retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus)) != SQL_SUCCESS)
+ retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
+ if (retcode == SQL_NO_DATA_FOUND)
+ return(FALSE);
+ else
+ return(pDb->DispAllErrors(henv, hdbc, hstmt));
+#else
+
+ // Fetch the next record from the record set
+ retcode = SQLFetch(hstmt);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
+ {
+ if (retcode == SQL_NO_DATA_FOUND)
+ return(FALSE);
+ else
+ return(pDb->DispAllErrors(henv, hdbc, hstmt));
+ }
+#endif
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxTable::getRec()
+
+/********** wxTable::execDelete() **********/
+bool wxTable::execDelete(const char *pSqlStmt)
+{
+ // Execute the DELETE statement
+ if (SQLExecDirect(hstmtDelete, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
+ return(pDb->DispAllErrors(henv, hdbc, hstmtDelete));
+
+ // Record deleted successfully
+ return(TRUE);
+
+} // wxTable::execDelete()
+
+/********** wxTable::execUpdate() **********/
+bool wxTable::execUpdate(const char *pSqlStmt)
+{
+ // Execute the UPDATE statement
+ if (SQLExecDirect(hstmtUpdate, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
+ return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
+
+ // Record deleted successfully
+ return(TRUE);
+
+} // wxTable::execUpdate()
+
+/********** wxTable::query() **********/
+bool wxTable::query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt)
+{
+ char sqlStmt[DB_MAX_STATEMENT_LEN];
+
+ // Set the selectForUpdate member variable
+ if (forUpdate)
+ // The user may wish to select for update, but the DBMS may not be capable
+ selectForUpdate = CanSelectForUpdate();
+ else
+ selectForUpdate = FALSE;
+
+ // Set the SQL SELECT string
+ if (queryType != DB_SELECT_STATEMENT) // A select statement was not passed in,
+ { // so generate a select statement.
+ GetSelectStmt(sqlStmt, queryType, distinct);
+ pDb->WriteSqlLog(sqlStmt);
+ }
+
+ // Make sure the cursor is closed first
+ if (! CloseCursor(hstmt))
+ return(FALSE);
+
+ // Execute the SQL SELECT statement
+ int retcode;
+
+ retcode = SQLExecDirect(hstmt, (UCHAR FAR *) (queryType == DB_SELECT_STATEMENT ? pSqlStmt : sqlStmt), SQL_NTS);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
+ return(pDb->DispAllErrors(henv, hdbc, hstmt));
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxTable::query()
+
+
+
/********** wxTable::Open() **********/
bool wxTable::Open(void)
{
} // wxTable::QueryOnKeyFields()
-/********** wxTable::query() **********/
-bool wxTable::query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt)
-{
- char sqlStmt[DB_MAX_STATEMENT_LEN];
-
- // Set the selectForUpdate member variable
- if (forUpdate)
- // The user may wish to select for update, but the DBMS may not be capable
- selectForUpdate = CanSelectForUpdate();
- else
- selectForUpdate = FALSE;
-
- // Set the SQL SELECT string
- if (queryType != DB_SELECT_STATEMENT) // A select statement was not passed in,
- { // so generate a select statement.
- GetSelectStmt(sqlStmt, queryType, distinct);
- pDb->WriteSqlLog(sqlStmt);
- }
-
- // Make sure the cursor is closed first
- if (! CloseCursor(hstmt))
- return(FALSE);
-
- // Execute the SQL SELECT statement
- int retcode;
-
- retcode = SQLExecDirect(hstmt, (UCHAR FAR *) (queryType == DB_SELECT_STATEMENT ? pSqlStmt : sqlStmt), SQL_NTS);
- if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
- return(pDb->DispAllErrors(henv, hdbc, hstmt));
-
- // Completed successfully
- return(TRUE);
-
-} // wxTable::query()
-
/********** wxTable::GetSelectStmt() **********/
void wxTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
{
} // wxTable::GetSelectStmt()
-/********** wxTable::getRec() **********/
-bool wxTable::getRec(UWORD fetchType)
-{
- RETCODE retcode;
-
-#if !wxODBC_FWD_ONLY_CURSORS
-
- // Fetch the NEXT, PREV, FIRST or LAST record, depending on fetchType
- UDWORD cRowsFetched;
- UWORD rowStatus;
-
-// if ((retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus)) != SQL_SUCCESS)
- retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus);
- if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
- if (retcode == SQL_NO_DATA_FOUND)
- return(FALSE);
- else
- return(pDb->DispAllErrors(henv, hdbc, hstmt));
-#else
-
- // Fetch the next record from the record set
- retcode = SQLFetch(hstmt);
- if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
- {
- if (retcode == SQL_NO_DATA_FOUND)
- return(FALSE);
- else
- return(pDb->DispAllErrors(henv, hdbc, hstmt));
- }
-#endif
-
- // Completed successfully
- return(TRUE);
-
-} // wxTable::getRec()
-
/********** wxTable::GetRowNum() **********/
UWORD wxTable::GetRowNum(void)
{
} // wxTable::GetRowNum()
-/********** wxTable::bindInsertParams() **********/
-bool wxTable::bindInsertParams(void)
-{
- assert(!queryOnly);
- if (queryOnly)
- return(FALSE);
-
- SWORD fSqlType = 0;
- UDWORD precision = 0;
- SWORD scale = 0;
-
- // Bind each column (that can be inserted) of the table to a parameter marker
- int i;
- for (i = 0; i < noCols; i++)
- {
- if (! colDefs[i].InsertAllowed)
- continue;
- switch(colDefs[i].DbDataType)
- {
- case DB_DATA_TYPE_VARCHAR:
- fSqlType = pDb->typeInfVarchar.FsqlType;
- precision = colDefs[i].SzDataObj;
- scale = 0;
- colDefs[i].CbValue = SQL_NTS;
- break;
- case DB_DATA_TYPE_INTEGER:
- fSqlType = pDb->typeInfInteger.FsqlType;
- precision = pDb->typeInfInteger.Precision;
- scale = 0;
- colDefs[i].CbValue = 0;
- break;
- case DB_DATA_TYPE_FLOAT:
- fSqlType = pDb->typeInfFloat.FsqlType;
- precision = pDb->typeInfFloat.Precision;
- scale = pDb->typeInfFloat.MaximumScale;
- // SQL Sybase Anywhere v5.5 returned a negative number for the
- // MaxScale. This caused ODBC to kick out an error on ibscale.
- // I check for this here and set the scale = precision.
- //if (scale < 0)
- // scale = (short) precision;
- colDefs[i].CbValue = 0;
- break;
- case DB_DATA_TYPE_DATE:
- fSqlType = pDb->typeInfDate.FsqlType;
- precision = pDb->typeInfDate.Precision;
- scale = 0;
- colDefs[i].CbValue = 0;
- break;
- }
- // Null values
- if (colDefs[i].Null)
- {
- colDefs[i].CbValue = SQL_NULL_DATA;
- colDefs[i].Null = FALSE;
- }
- if (SQLBindParameter(hstmtInsert, i+1, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
- fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
- precision+1,&colDefs[i].CbValue) != SQL_SUCCESS)
- return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
- }
-
- // Completed successfully
- return(TRUE);
-
-} // wxTable::bindInsertParams()
-
-/********** wxTable::bindUpdateParams() **********/
-bool wxTable::bindUpdateParams(void)
-{
- assert(!queryOnly);
- if (queryOnly)
- return(FALSE);
-
- SWORD fSqlType = 0;
- UDWORD precision = 0;
- SWORD scale = 0;
-
- // Bind each UPDATEABLE column of the table to a parameter marker
- int i,colNo;
- for (i = 0, colNo = 1; i < noCols; i++)
- {
- if (! colDefs[i].Updateable)
- continue;
- switch(colDefs[i].DbDataType)
- {
- case DB_DATA_TYPE_VARCHAR:
- fSqlType = pDb->typeInfVarchar.FsqlType;
- precision = colDefs[i].SzDataObj;
- scale = 0;
- colDefs[i].CbValue = SQL_NTS;
- break;
- case DB_DATA_TYPE_INTEGER:
- fSqlType = pDb->typeInfInteger.FsqlType;
- precision = pDb->typeInfInteger.Precision;
- scale = 0;
- colDefs[i].CbValue = 0;
- break;
- case DB_DATA_TYPE_FLOAT:
- fSqlType = pDb->typeInfFloat.FsqlType;
- precision = pDb->typeInfFloat.Precision;
- scale = pDb->typeInfFloat.MaximumScale;
- // SQL Sybase Anywhere v5.5 returned a negative number for the
- // MaxScale. This caused ODBC to kick out an error on ibscale.
- // I check for this here and set the scale = precision.
- //if (scale < 0)
- // scale = (short) precision;
- colDefs[i].CbValue = 0;
- break;
- case DB_DATA_TYPE_DATE:
- fSqlType = pDb->typeInfDate.FsqlType;
- precision = pDb->typeInfDate.Precision;
- scale = 0;
- colDefs[i].CbValue = 0;
- break;
- }
- if (SQLBindParameter(hstmtUpdate, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
- fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
- precision+1, &colDefs[i].CbValue) != SQL_SUCCESS)
- return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
- }
-
- // Completed successfully
- return(TRUE);
-
-} // wxTable::bindUpdateParams()
-
-/********** wxTable::bindCols() **********/
-bool wxTable::bindCols(HSTMT cursor)
-{
- static SDWORD cb;
-
- // Bind each column of the table to a memory address for fetching data
- int i;
- for (i = 0; i < noCols; i++)
- {
- if (SQLBindCol(cursor, i+1, colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
- colDefs[i].SzDataObj, &cb) != SQL_SUCCESS)
- return(pDb->DispAllErrors(henv, hdbc, cursor));
- }
-
- // Completed successfully
- return(TRUE);
-
-} // wxTable::bindCols()
-
/********** wxTable::CloseCursor() **********/
bool wxTable::CloseCursor(HSTMT cursor)
{
} // wxTable::DropTable()
/********** wxTable::CreateIndex() **********/
-bool wxTable::CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs, bool attemptDrop)
+bool wxTable::CreateIndex(const char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs, bool attemptDrop)
{
char sqlStmt[DB_MAX_STATEMENT_LEN];
} // wxTable::CreateIndex()
/********** wxTable::DropIndex() **********/
-bool wxTable::DropIndex(char * idxName)
+bool wxTable::DropIndex(const char * idxName)
{
// NOTE: This function returns TRUE if the Index does not exist, but
// only for identified databases. Code will need to be added
} // wxTable::Insert()
-/********** wxTable::Update(pSqlStmt) **********/
-bool wxTable::Update(char *pSqlStmt)
-{
- assert(!queryOnly);
- if (queryOnly)
- return(FALSE);
-
- pDb->WriteSqlLog(pSqlStmt);
-
- return(execUpdate(pSqlStmt));
-
-} // wxTable::Update(pSqlStmt)
-
/********** wxTable::Update() **********/
bool wxTable::Update(void)
{
} // wxTable::Update()
+/********** wxTable::Update(pSqlStmt) **********/
+bool wxTable::Update(const char *pSqlStmt)
+{
+ assert(!queryOnly);
+ if (queryOnly)
+ return(FALSE);
+
+ pDb->WriteSqlLog(pSqlStmt);
+
+ return(execUpdate(pSqlStmt));
+
+} // wxTable::Update(pSqlStmt)
+
/********** wxTable::UpdateWhere() **********/
-bool wxTable::UpdateWhere(char *pWhereClause)
+bool wxTable::UpdateWhere(const char *pWhereClause)
{
assert(!queryOnly);
if (queryOnly)
} // wxTable::Delete()
/********** wxTable::DeleteWhere() **********/
-bool wxTable::DeleteWhere(char *pWhereClause)
+bool wxTable::DeleteWhere(const char *pWhereClause)
{
assert(!queryOnly);
if (queryOnly)
} // wxTable::DeleteMatching()
-/********** wxTable::execDelete() **********/
-bool wxTable::execDelete(char *pSqlStmt)
-{
- // Execute the DELETE statement
- if (SQLExecDirect(hstmtDelete, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
- return(pDb->DispAllErrors(henv, hdbc, hstmtDelete));
-
- // Record deleted successfully
- return(TRUE);
-
-} // wxTable::execDelete()
-
-/********** wxTable::execUpdate() **********/
-bool wxTable::execUpdate(char *pSqlStmt)
-{
- // Execute the UPDATE statement
- if (SQLExecDirect(hstmtUpdate, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
- return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
-
- // Record deleted successfully
- return(TRUE);
-
-} // wxTable::execUpdate()
-
/********** wxTable::GetUpdateStmt() **********/
-void wxTable::GetUpdateStmt(char *pSqlStmt, int typeOfUpd, char *pWhereClause)
+void wxTable::GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause)
{
assert(!queryOnly);
if (queryOnly)
wxStrcat(pSqlStmt, pWhereClause);
break;
}
-
} // GetUpdateStmt()
/********** wxTable::GetDeleteStmt() **********/
-void wxTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause)
+void wxTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause)
{
assert(!queryOnly);
if (queryOnly)
* They are not included as part of the where clause.
*/
-void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere, char *qualTableName)
+void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere, const char *qualTableName)
{
bool moreThanOneColumn = FALSE;
char colValue[255];
} // wxTable::SetQueryTimeout()
/********** wxTable::SetColDefs() **********/
-void wxTable::SetColDefs (int index, char *fieldName, int dataType, void *pData,
+void wxTable::SetColDefs (int index, const char *fieldName, int dataType, void *pData,
int cType, int size, bool keyField, bool upd,
bool insAllow, bool derivedCol)
{
} // wxTable::SetNull(UINT colNo)
/********** wxTable::SetNull(char *colName) **********/
-bool wxTable::SetNull(char *colName)
+bool wxTable::SetNull(const char *colName)
{
int i;
for (i = 0; i < noCols; i++)