-#endif
- // Decrement the wxDB table count
- if (pDb)
- pDb->nTables--;
-
- // Delete memory allocated for column definitions
- if (colDefs)
- delete [] colDefs;
-
- // Free statement handles
- if (!queryOnly)
- {
- if (hstmtInsert)
- if (SQLFreeStmt(hstmtInsert, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (hstmtDelete)
- if (SQLFreeStmt(hstmtDelete, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (hstmtUpdate)
- if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- }
- if (hstmtInternal)
- if (SQLFreeStmt(hstmtInternal, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
-
- // Delete dynamically allocated cursors
- if (hstmtDefault)
- DeleteCursor(hstmtDefault);
- if (hstmtCount)
- DeleteCursor(hstmtCount);
-
-} // wxTable::~wxTable()
-
-/********** wxTable::Open() **********/
-bool wxTable::Open(void)
+
+ // Decrement the wxDb table count
+ if (pDb)
+ pDb->decrementTableCount();
+
+ // Delete memory allocated for column definitions
+ if (colDefs)
+ delete [] colDefs;
+
+ // Free statement handles
+ if (!queryOnly)
+ {
+ if (hstmtInsert)
+ if (SQLFreeStmt(hstmtInsert, SQL_DROP) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+
+ if (hstmtDelete)
+ if (SQLFreeStmt(hstmtDelete, SQL_DROP) != SQL_SUCCESS)
+
+ if (hstmtUpdate)
+ if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ }
+
+ if (hstmtInternal)
+ if (SQLFreeStmt(hstmtInternal, SQL_DROP) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+
+ // Delete dynamically allocated cursors
+ if (hstmtDefault)
+ DeleteCursor(hstmtDefault);
+
+ if (hstmtCount)
+ DeleteCursor(hstmtCount);
+
+} // wxDbTable::~wxDbTable()
+
+
+
+/***************************** PRIVATE FUNCTIONS *****************************/
+
+
+
+/********** wxDbTable::bindInsertParams() **********/
+bool wxDbTable::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,colNo;
+ for (i = 0, colNo = 1; i < noCols; i++)
+ {
+ if (! colDefs[i].InsertAllowed)
+ continue;
+ switch(colDefs[i].DbDataType)
+ {
+ case DB_DATA_TYPE_VARCHAR:
+ fSqlType = pDb->GetTypeInfVarchar().FsqlType;
+ precision = colDefs[i].SzDataObj;
+ scale = 0;
+ colDefs[i].CbValue = SQL_NTS;
+ break;
+ case DB_DATA_TYPE_INTEGER:
+ fSqlType = pDb->GetTypeInfInteger().FsqlType;
+ precision = pDb->GetTypeInfInteger().Precision;
+ scale = 0;
+ colDefs[i].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_FLOAT:
+ fSqlType = pDb->GetTypeInfFloat().FsqlType;
+ precision = pDb->GetTypeInfFloat().Precision;
+ scale = pDb->GetTypeInfFloat().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->GetTypeInfDate().FsqlType;
+ precision = pDb->GetTypeInfDate().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, 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, hstmtInsert));
+ }
+ }
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxDbTable::bindInsertParams()
+
+
+/********** wxDbTable::bindUpdateParams() **********/
+bool wxDbTable::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->GetTypeInfVarchar().FsqlType;
+ precision = colDefs[i].SzDataObj;
+ scale = 0;
+ colDefs[i].CbValue = SQL_NTS;
+ break;
+ case DB_DATA_TYPE_INTEGER:
+ fSqlType = pDb->GetTypeInfInteger().FsqlType;
+ precision = pDb->GetTypeInfInteger().Precision;
+ scale = 0;
+ colDefs[i].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_FLOAT:
+ fSqlType = pDb->GetTypeInfFloat().FsqlType;
+ precision = pDb->GetTypeInfFloat().Precision;
+ scale = pDb->GetTypeInfFloat().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->GetTypeInfDate().FsqlType;
+ precision = pDb->GetTypeInfDate().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);
+
+} // wxDbTable::bindUpdateParams()
+
+
+/********** wxDbTable::bindCols() **********/
+bool wxDbTable::bindCols(HSTMT cursor)