- if (SQLSetStmtOption(c0, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, c0);
- if (SQLSetStmtOption(c2, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, c2);
-// if (SQLSetStmtOption(c3, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc, c3);
-// if (SQLSetStmtOption(c4, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc, c4);
-// if (SQLSetStmtOption(c5, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc, c5);
-
- // Set the cursor type for the INSERT statement handle
- if (SQLSetStmtOption(hstmtInsert, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtInsert);
- // Set the cursor type for the DELETE statement handle
- if (SQLSetStmtOption(hstmtDelete, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtDelete);
- // Set the cursor type for the UPDATE statement handle
- if (SQLSetStmtOption(hstmtUpdate, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtUpdate);
- // Set the cursor type for the COUNT(*) statement handle
- if (SQLSetStmtOption(hstmtCount, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtCount);
-
- // Copy cursor 1 to the default cursor
- hstmt = c1;
- currCursorNo = DB_CURSOR1;
-
-} // wxTable::wxTable()
-
-/********** wxTable::~wxTable() **********/
-wxTable::~wxTable()
+} // 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;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[i].CbValue = SQL_NTS;
+ break;
+ case DB_DATA_TYPE_INTEGER:
+ fSqlType = pDb->GetTypeInfInteger().FsqlType;
+ precision = pDb->GetTypeInfInteger().Precision;
+ scale = 0;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ 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;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[i].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_DATE:
+ fSqlType = pDb->GetTypeInfDate().FsqlType;
+ precision = pDb->GetTypeInfDate().Precision;
+ scale = 0;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[i].CbValue = 0;
+ break;
+ }
+ // Null values
+//RG-NULL
+//RG-NULL if (colDefs[i].Null)
+//RG-NULL {
+//RG-NULL colDefs[i].CbValue = SQL_NULL_DATA;
+//RG-NULL colDefs[i].Null = FALSE;
+//RG-NULL }
+
+ 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;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[i].CbValue = SQL_NTS;
+ break;
+ case DB_DATA_TYPE_INTEGER:
+ fSqlType = pDb->GetTypeInfInteger().FsqlType;
+ precision = pDb->GetTypeInfInteger().Precision;
+ scale = 0;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ 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;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[i].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_DATE:
+ fSqlType = pDb->GetTypeInfDate().FsqlType;
+ precision = pDb->GetTypeInfDate().Precision;
+ scale = 0;
+ if (colDefs[i].Null)
+ colDefs[i].CbValue = SQL_NULL_DATA;
+ else
+ 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)