1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implementation of the wxDbTable class.
5 // Modified by: George Tasker
10 // Copyright: (c) 1996 Remstar International, Inc.
11 // Licence: wxWindows licence, plus:
12 // Notice: This class library and its intellectual design are free of charge for use,
13 // modification, enhancement, debugging under the following conditions:
14 // 1) These classes may only be used as part of the implementation of a
15 // wxWindows-based application
16 // 2) All enhancements and bug fixes are to be submitted back to the wxWindows
17 // user groups free of all charges for use with the wxWindows library.
18 // 3) These classes may not be distributed as part of any other class library,
19 // DLL, text (written or electronic), other than a complete distribution of
20 // the wxWindows GUI development toolkit.
21 ///////////////////////////////////////////////////////////////////////////////
28 // Use this line for wxWindows v1.x
30 // Use this line for wxWindows v2.x
31 #include "wx/wxprec.h"
32 #include "wx/version.h"
34 #if wxMAJOR_VERSION == 2
36 #pragma implementation "dbtable.h"
40 #ifdef DBDEBUG_CONSOLE
41 #include "wx/ioswrap.h"
49 #if wxMAJOR_VERSION == 2
51 #include "wx/string.h"
52 #include "wx/object.h"
55 #include "wx/msgdlg.h"
58 #include "wx/filefn.h"
61 #if wxMAJOR_VERSION == 1
62 # if defined(wx_msw) || defined(wx_x)
80 #if wxMAJOR_VERSION == 1
82 #elif wxMAJOR_VERSION == 2
83 #include "wx/dbtable.h"
87 // The HPUX preprocessor lines below were commented out on 8/20/97
88 // because macros.h currently redefines DEBUG and is unneeded.
90 // # include <macros.h>
93 # include <sys/minmax.h>
97 ULONG lastTableID
= 0;
105 /********** wxDbColDef::wxDbColDef() Constructor **********/
106 wxDbColDef::wxDbColDef()
112 bool wxDbColDef::Initialize()
115 DbDataType
= DB_DATA_TYPE_INTEGER
;
116 SqlCtype
= SQL_C_LONG
;
121 InsertAllowed
= FALSE
;
127 } // wxDbColDef::Initialize()
130 /********** wxDbTable::wxDbTable() Constructor **********/
131 wxDbTable::wxDbTable(wxDb
*pwxDb
, const wxString
&tblName
, const int nCols
,
132 const wxString
&qryTblName
, bool qryOnly
, const wxString
&tblPath
)
134 if (!initialize(pwxDb
, tblName
, nCols
, qryTblName
, qryOnly
, tblPath
))
136 } // wxDbTable::wxDbTable()
139 /***** DEPRECATED: use wxDbTable::wxDbTable() format above *****/
140 wxDbTable::wxDbTable(wxDb
*pwxDb
, const wxString
&tblName
, const int nCols
,
141 const wxChar
*qryTblName
, bool qryOnly
, const wxString
&tblPath
)
143 wxString tempQryTblName
;
144 tempQryTblName
= qryTblName
;
145 if (!initialize(pwxDb
, tblName
, nCols
, tempQryTblName
, qryOnly
, tblPath
))
147 } // wxDbTable::wxDbTable()
150 /********** wxDbTable::~wxDbTable() **********/
151 wxDbTable::~wxDbTable()
154 } // wxDbTable::~wxDbTable()
157 bool wxDbTable::initialize(wxDb
*pwxDb
, const wxString
&tblName
, const int nCols
,
158 const wxString
&qryTblName
, bool qryOnly
, const wxString
&tblPath
)
160 // Initializing member variables
161 pDb
= pwxDb
; // Pointer to the wxDb object
165 hstmtDefault
= 0; // Initialized below
166 hstmtCount
= 0; // Initialized first time it is needed
173 noCols
= nCols
; // No. of cols in the table
174 where
.Empty(); // Where clause
175 orderBy
.Empty(); // Order By clause
176 from
.Empty(); // From clause
177 selectForUpdate
= FALSE
; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase
182 queryTableName
.Empty();
184 wxASSERT(tblName
.Length());
190 tableName
= tblName
; // Table Name
191 if (tblPath
.Length())
192 tablePath
= tblPath
; // Table Path - used for dBase files
196 if (qryTblName
.Length()) // Name of the table/view to query
197 queryTableName
= qryTblName
;
199 queryTableName
= tblName
;
201 pDb
->incrementTableCount();
204 tableID
= ++lastTableID
;
205 s
.Printf(wxT("wxDbTable constructor (%-20s) tableID:[%6lu] pDb:[%p]"), tblName
.c_str(), tableID
, pDb
);
208 wxTablesInUse
*tableInUse
;
209 tableInUse
= new wxTablesInUse();
210 tableInUse
->tableName
= tblName
;
211 tableInUse
->tableID
= tableID
;
212 tableInUse
->pDb
= pDb
;
213 TablesInUse
.Append(tableInUse
);
218 // Grab the HENV and HDBC from the wxDb object
219 henv
= pDb
->GetHENV();
220 hdbc
= pDb
->GetHDBC();
222 // Allocate space for column definitions
224 colDefs
= new wxDbColDef
[noCols
]; // Points to the first column definition
226 // Allocate statement handles for the table
229 // Allocate a separate statement handle for performing inserts
230 if (SQLAllocStmt(hdbc
, &hstmtInsert
) != SQL_SUCCESS
)
231 pDb
->DispAllErrors(henv
, hdbc
);
232 // Allocate a separate statement handle for performing deletes
233 if (SQLAllocStmt(hdbc
, &hstmtDelete
) != SQL_SUCCESS
)
234 pDb
->DispAllErrors(henv
, hdbc
);
235 // Allocate a separate statement handle for performing updates
236 if (SQLAllocStmt(hdbc
, &hstmtUpdate
) != SQL_SUCCESS
)
237 pDb
->DispAllErrors(henv
, hdbc
);
239 // Allocate a separate statement handle for internal use
240 if (SQLAllocStmt(hdbc
, &hstmtInternal
) != SQL_SUCCESS
)
241 pDb
->DispAllErrors(henv
, hdbc
);
243 // Set the cursor type for the statement handles
244 cursorType
= SQL_CURSOR_STATIC
;
246 if (SQLSetStmtOption(hstmtInternal
, SQL_CURSOR_TYPE
, cursorType
) != SQL_SUCCESS
)
248 // Check to see if cursor type is supported
249 pDb
->GetNextError(henv
, hdbc
, hstmtInternal
);
250 if (! wxStrcmp(pDb
->sqlState
, wxT("01S02"))) // Option Value Changed
252 // Datasource does not support static cursors. Driver
253 // will substitute a cursor type. Call SQLGetStmtOption()
254 // to determine which cursor type was selected.
255 if (SQLGetStmtOption(hstmtInternal
, SQL_CURSOR_TYPE
, &cursorType
) != SQL_SUCCESS
)
256 pDb
->DispAllErrors(henv
, hdbc
, hstmtInternal
);
257 #ifdef DBDEBUG_CONSOLE
258 cout
<< wxT("Static cursor changed to: ");
261 case SQL_CURSOR_FORWARD_ONLY
:
262 cout
<< wxT("Forward Only");
264 case SQL_CURSOR_STATIC
:
265 cout
<< wxT("Static");
267 case SQL_CURSOR_KEYSET_DRIVEN
:
268 cout
<< wxT("Keyset Driven");
270 case SQL_CURSOR_DYNAMIC
:
271 cout
<< wxT("Dynamic");
274 cout
<< endl
<< endl
;
277 if (pDb
->FwdOnlyCursors() && cursorType
!= SQL_CURSOR_FORWARD_ONLY
)
279 // Force the use of a forward only cursor...
280 cursorType
= SQL_CURSOR_FORWARD_ONLY
;
281 if (SQLSetStmtOption(hstmtInternal
, SQL_CURSOR_TYPE
, cursorType
) != SQL_SUCCESS
)
283 // Should never happen
284 pDb
->GetNextError(henv
, hdbc
, hstmtInternal
);
291 pDb
->DispNextError();
292 pDb
->DispAllErrors(henv
, hdbc
, hstmtInternal
);
295 #ifdef DBDEBUG_CONSOLE
297 cout
<< wxT("Cursor Type set to STATIC") << endl
<< endl
;
302 // Set the cursor type for the INSERT statement handle
303 if (SQLSetStmtOption(hstmtInsert
, SQL_CURSOR_TYPE
, SQL_CURSOR_FORWARD_ONLY
) != SQL_SUCCESS
)
304 pDb
->DispAllErrors(henv
, hdbc
, hstmtInsert
);
305 // Set the cursor type for the DELETE statement handle
306 if (SQLSetStmtOption(hstmtDelete
, SQL_CURSOR_TYPE
, SQL_CURSOR_FORWARD_ONLY
) != SQL_SUCCESS
)
307 pDb
->DispAllErrors(henv
, hdbc
, hstmtDelete
);
308 // Set the cursor type for the UPDATE statement handle
309 if (SQLSetStmtOption(hstmtUpdate
, SQL_CURSOR_TYPE
, SQL_CURSOR_FORWARD_ONLY
) != SQL_SUCCESS
)
310 pDb
->DispAllErrors(henv
, hdbc
, hstmtUpdate
);
313 // Make the default cursor the active cursor
314 hstmtDefault
= GetNewCursor(FALSE
,FALSE
);
315 wxASSERT(hstmtDefault
);
316 hstmt
= *hstmtDefault
;
320 } // wxDbTable::initialize()
323 void wxDbTable::cleanup()
328 s
.Printf(wxT("wxDbTable destructor (%-20s) tableID:[%6lu] pDb:[%p]"), tableName
.c_str(), tableID
, pDb
);
335 TablesInUse
.DeleteContents(TRUE
);
339 pNode
= TablesInUse
.First();
340 while (pNode
&& !found
)
342 if (((wxTablesInUse
*)pNode
->Data())->tableID
== tableID
)
345 if (!TablesInUse
.DeleteNode(pNode
))
346 wxLogDebug (s
,wxT("Unable to delete node!"));
349 pNode
= pNode
->Next();
354 msg
.Printf(wxT("Unable to find the tableID in the linked\nlist of tables in use.\n\n%s"),s
);
355 wxLogDebug (msg
,wxT("NOTICE..."));
360 // Decrement the wxDb table count
362 pDb
->decrementTableCount();
364 // Delete memory allocated for column definitions
368 // Free statement handles
374 ODBC 3.0 says to use this form
375 if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
377 if (SQLFreeStmt(hstmtInsert
, SQL_DROP
) != SQL_SUCCESS
)
378 pDb
->DispAllErrors(henv
, hdbc
);
384 ODBC 3.0 says to use this form
385 if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
387 if (SQLFreeStmt(hstmtDelete
, SQL_DROP
) != SQL_SUCCESS
)
388 pDb
->DispAllErrors(henv
, hdbc
);
394 ODBC 3.0 says to use this form
395 if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
397 if (SQLFreeStmt(hstmtUpdate
, SQL_DROP
) != SQL_SUCCESS
)
398 pDb
->DispAllErrors(henv
, hdbc
);
404 if (SQLFreeStmt(hstmtInternal
, SQL_DROP
) != SQL_SUCCESS
)
405 pDb
->DispAllErrors(henv
, hdbc
);
408 // Delete dynamically allocated cursors
410 DeleteCursor(hstmtDefault
);
413 DeleteCursor(hstmtCount
);
414 } // wxDbTable::cleanup()
417 /***************************** PRIVATE FUNCTIONS *****************************/
420 /********** wxDbTable::bindUpdateParams() **********/
421 bool wxDbTable::bindParams(bool forUpdate
)
423 wxASSERT(!queryOnly
);
428 UDWORD precision
= 0;
431 // Bind each column of the table that should be bound
432 // to a parameter marker
434 for (i
= 0, colNo
= 1; i
< noCols
; i
++)
438 if (! colDefs
[i
].Updateable
)
443 if (! colDefs
[i
].InsertAllowed
)
447 switch(colDefs
[i
].DbDataType
)
449 case DB_DATA_TYPE_VARCHAR
:
450 fSqlType
= pDb
->GetTypeInfVarchar().FsqlType
;
451 precision
= colDefs
[i
].SzDataObj
;
454 colDefs
[i
].CbValue
= SQL_NULL_DATA
;
456 colDefs
[i
].CbValue
= SQL_NTS
;
458 case DB_DATA_TYPE_INTEGER
:
459 fSqlType
= pDb
->GetTypeInfInteger().FsqlType
;
460 precision
= pDb
->GetTypeInfInteger().Precision
;
463 colDefs
[i
].CbValue
= SQL_NULL_DATA
;
465 colDefs
[i
].CbValue
= 0;
467 case DB_DATA_TYPE_FLOAT
:
468 fSqlType
= pDb
->GetTypeInfFloat().FsqlType
;
469 precision
= pDb
->GetTypeInfFloat().Precision
;
470 scale
= pDb
->GetTypeInfFloat().MaximumScale
;
471 // SQL Sybase Anywhere v5.5 returned a negative number for the
472 // MaxScale. This caused ODBC to kick out an error on ibscale.
473 // I check for this here and set the scale = precision.
475 // scale = (short) precision;
477 colDefs
[i
].CbValue
= SQL_NULL_DATA
;
479 colDefs
[i
].CbValue
= 0;
481 case DB_DATA_TYPE_DATE
:
482 fSqlType
= pDb
->GetTypeInfDate().FsqlType
;
483 precision
= pDb
->GetTypeInfDate().Precision
;
486 colDefs
[i
].CbValue
= SQL_NULL_DATA
;
488 colDefs
[i
].CbValue
= 0;
493 if (SQLBindParameter(hstmtUpdate
, colNo
++, SQL_PARAM_INPUT
, colDefs
[i
].SqlCtype
,
494 fSqlType
, precision
, scale
, (UCHAR
*) colDefs
[i
].PtrDataObj
,
495 precision
+1, &colDefs
[i
].CbValue
) != SQL_SUCCESS
)
497 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtUpdate
));
502 if (SQLBindParameter(hstmtInsert
, colNo
++, SQL_PARAM_INPUT
, colDefs
[i
].SqlCtype
,
503 fSqlType
, precision
, scale
, (UCHAR
*) colDefs
[i
].PtrDataObj
,
504 precision
+1,&colDefs
[i
].CbValue
) != SQL_SUCCESS
)
506 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtInsert
));
511 // Completed successfully
514 } // wxDbTable::bindParams()
517 /********** wxDbTable::bindInsertParams() **********/
518 bool wxDbTable::bindInsertParams(void)
520 return bindParams(FALSE
);
521 } // wxDbTable::bindInsertParams()
524 /********** wxDbTable::bindUpdateParams() **********/
525 bool wxDbTable::bindUpdateParams(void)
527 return bindParams(TRUE
);
528 } // wxDbTable::bindUpdateParams()
531 /********** wxDbTable::bindCols() **********/
532 bool wxDbTable::bindCols(HSTMT cursor
)
534 //RG-NULL static SDWORD cb;
536 // Bind each column of the table to a memory address for fetching data
538 for (i
= 0; i
< noCols
; i
++)
540 if (SQLBindCol(cursor
, i
+1, colDefs
[i
].SqlCtype
, (UCHAR
*) colDefs
[i
].PtrDataObj
,
541 //RG-NULL colDefs[i].SzDataObj, &cb) != SQL_SUCCESS)
542 colDefs
[i
].SzDataObj
, &colDefs
[i
].CbValue
) != SQL_SUCCESS
)
544 return (pDb
->DispAllErrors(henv
, hdbc
, cursor
));
548 // Completed successfully
551 } // wxDbTable::bindCols()
554 /********** wxDbTable::getRec() **********/
555 bool wxDbTable::getRec(UWORD fetchType
)
559 if (!pDb
->FwdOnlyCursors())
561 // Fetch the NEXT, PREV, FIRST or LAST record, depending on fetchType
565 retcode
= SQLExtendedFetch(hstmt
, fetchType
, 0, &cRowsFetched
, &rowStatus
);
566 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
568 if (retcode
== SQL_NO_DATA_FOUND
)
571 return(pDb
->DispAllErrors(henv
, hdbc
, hstmt
));
575 // Set the Null member variable to indicate the Null state
576 // of each column just read in.
578 for (i
= 0; i
< noCols
; i
++)
579 colDefs
[i
].Null
= (colDefs
[i
].CbValue
== SQL_NULL_DATA
);
584 // Fetch the next record from the record set
585 retcode
= SQLFetch(hstmt
);
586 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
588 if (retcode
== SQL_NO_DATA_FOUND
)
591 return(pDb
->DispAllErrors(henv
, hdbc
, hstmt
));
595 // Set the Null member variable to indicate the Null state
596 // of each column just read in.
598 for (i
= 0; i
< noCols
; i
++)
599 colDefs
[i
].Null
= (colDefs
[i
].CbValue
== SQL_NULL_DATA
);
603 // Completed successfully
606 } // wxDbTable::getRec()
609 /********** wxDbTable::execDelete() **********/
610 bool wxDbTable::execDelete(const wxString
&pSqlStmt
)
612 // Execute the DELETE statement
613 if (SQLExecDirect(hstmtDelete
, (UCHAR FAR
*) pSqlStmt
.c_str(), SQL_NTS
) != SQL_SUCCESS
)
614 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtDelete
));
616 // Record deleted successfully
619 } // wxDbTable::execDelete()
622 /********** wxDbTable::execUpdate() **********/
623 bool wxDbTable::execUpdate(const wxString
&pSqlStmt
)
625 // Execute the UPDATE statement
626 if (SQLExecDirect(hstmtUpdate
, (UCHAR FAR
*) pSqlStmt
.c_str(), SQL_NTS
) != SQL_SUCCESS
)
627 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtUpdate
));
629 // Record deleted successfully
632 } // wxDbTable::execUpdate()
635 /********** wxDbTable::query() **********/
636 bool wxDbTable::query(int queryType
, bool forUpdate
, bool distinct
, const wxString
&pSqlStmt
)
641 // The user may wish to select for update, but the DBMS may not be capable
642 selectForUpdate
= CanSelectForUpdate();
644 selectForUpdate
= FALSE
;
646 // Set the SQL SELECT string
647 if (queryType
!= DB_SELECT_STATEMENT
) // A select statement was not passed in,
648 { // so generate a select statement.
649 BuildSelectStmt(sqlStmt
, queryType
, distinct
);
650 pDb
->WriteSqlLog(sqlStmt
);
653 This is the block of code that got added during the 2.2.1 merge with
654 the 2.2 main branch that somehow got added here when it should not have. - gt
657 wxStrcpy(sqlStmt, pSqlStmt);
659 SQLFreeStmt(hstmt, SQL_CLOSE);
660 if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) == SQL_SUCCESS)
664 pDb->DispAllErrors(henv, hdbc, hstmt);
668 // Make sure the cursor is closed first
669 if (!CloseCursor(hstmt
))
672 // Execute the SQL SELECT statement
674 retcode
= SQLExecDirect(hstmt
, (UCHAR FAR
*) (queryType
== DB_SELECT_STATEMENT
? pSqlStmt
.c_str() : sqlStmt
.c_str()), SQL_NTS
);
675 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
676 return(pDb
->DispAllErrors(henv
, hdbc
, hstmt
));
678 // Completed successfully
681 } // wxDbTable::query()
684 /***************************** PUBLIC FUNCTIONS *****************************/
687 /********** wxDbTable::Open() **********/
688 bool wxDbTable::Open(bool checkPrivileges
)
698 // Verify that the table exists in the database
699 if (!pDb
->TableExists(tableName
,/*pDb->GetUsername()*/NULL
,tablePath
))
701 s
= wxT("Table/view does not exist in the database");
702 if ( *(pDb
->dbInf
.accessibleTables
) == wxT('Y'))
703 s
+= wxT(", or you have no permissions.\n");
707 else if (checkPrivileges
)
709 // Verify the user has rights to access the table.
710 // Shortcut boolean evaluation to optimize out call to
713 // Unfortunately this optimization doesn't seem to be
715 if (// *(pDb->dbInf.accessibleTables) == 'N' &&
716 !pDb
->TablePrivileges(tableName
,wxT("SELECT"),NULL
,pDb
->GetUsername(),tablePath
))
717 s
= wxT("Current logged in user does not have sufficient privileges to access this table.\n");
724 if (!tablePath
.IsEmpty())
725 p
.Printf(wxT("Error opening '%s/%s'.\n"),tablePath
.c_str(),tableName
.c_str());
727 p
.Printf(wxT("Error opening '%s'.\n"), tableName
.c_str());
730 pDb
->LogError(p
.GetData());
735 // Bind the member variables for field exchange between
736 // the wxDbTable object and the ODBC record.
739 if (!bindInsertParams()) // Inserts
742 if (!bindUpdateParams()) // Updates
746 if (!bindCols(*hstmtDefault
)) // Selects
749 if (!bindCols(hstmtInternal
)) // Internal use only
753 * Do NOT bind the hstmtCount cursor!!!
756 // Build an insert statement using parameter markers
757 if (!queryOnly
&& noCols
> 0)
759 bool needComma
= FALSE
;
760 sqlStmt
.Printf(wxT("INSERT INTO %s ("), tableName
.c_str());
761 for (i
= 0; i
< noCols
; i
++)
763 if (! colDefs
[i
].InsertAllowed
)
767 sqlStmt
+= colDefs
[i
].ColName
;
771 sqlStmt
+= wxT(") VALUES (");
773 int insertableCount
= 0;
775 for (i
= 0; i
< noCols
; i
++)
777 if (! colDefs
[i
].InsertAllowed
)
787 // Prepare the insert statement for execution
790 if (SQLPrepare(hstmtInsert
, (UCHAR FAR
*) sqlStmt
.c_str(), SQL_NTS
) != SQL_SUCCESS
)
791 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtInsert
));
797 // Completed successfully
800 } // wxDbTable::Open()
803 /********** wxDbTable::Query() **********/
804 bool wxDbTable::Query(bool forUpdate
, bool distinct
)
807 return(query(DB_SELECT_WHERE
, forUpdate
, distinct
));
809 } // wxDbTable::Query()
812 /********** wxDbTable::QueryBySqlStmt() **********/
813 bool wxDbTable::QueryBySqlStmt(const wxString
&pSqlStmt
)
815 pDb
->WriteSqlLog(pSqlStmt
);
817 return(query(DB_SELECT_STATEMENT
, FALSE
, FALSE
, pSqlStmt
));
819 } // wxDbTable::QueryBySqlStmt()
822 /********** wxDbTable::QueryMatching() **********/
823 bool wxDbTable::QueryMatching(bool forUpdate
, bool distinct
)
826 return(query(DB_SELECT_MATCHING
, forUpdate
, distinct
));
828 } // wxDbTable::QueryMatching()
831 /********** wxDbTable::QueryOnKeyFields() **********/
832 bool wxDbTable::QueryOnKeyFields(bool forUpdate
, bool distinct
)
835 return(query(DB_SELECT_KEYFIELDS
, forUpdate
, distinct
));
837 } // wxDbTable::QueryOnKeyFields()
840 /********** wxDbTable::GetPrev() **********/
841 bool wxDbTable::GetPrev(void)
843 if (pDb
->FwdOnlyCursors())
845 wxFAIL_MSG(wxT("GetPrev()::Backward scrolling cursors are not enabled for this instance of wxDbTable"));
849 return(getRec(SQL_FETCH_PRIOR
));
851 } // wxDbTable::GetPrev()
854 /********** wxDbTable::operator-- **********/
855 bool wxDbTable::operator--(int)
857 if (pDb
->FwdOnlyCursors())
859 wxFAIL_MSG(wxT("operator--:Backward scrolling cursors are not enabled for this instance of wxDbTable"));
863 return(getRec(SQL_FETCH_PRIOR
));
865 } // wxDbTable::operator--
868 /********** wxDbTable::GetFirst() **********/
869 bool wxDbTable::GetFirst(void)
871 if (pDb
->FwdOnlyCursors())
873 wxFAIL_MSG(wxT("GetFirst():Backward scrolling cursors are not enabled for this instance of wxDbTable"));
877 return(getRec(SQL_FETCH_FIRST
));
879 } // wxDbTable::GetFirst()
882 /********** wxDbTable::GetLast() **********/
883 bool wxDbTable::GetLast(void)
885 if (pDb
->FwdOnlyCursors())
887 wxFAIL_MSG(wxT("GetLast()::Backward scrolling cursors are not enabled for this instance of wxDbTable"));
891 return(getRec(SQL_FETCH_LAST
));
893 } // wxDbTable::GetLast()
896 /********** wxDbTable::BuildDeleteStmt() **********/
897 void wxDbTable::BuildDeleteStmt(wxString
&pSqlStmt
, int typeOfDel
, const wxString
&pWhereClause
)
899 wxASSERT(!queryOnly
);
903 wxString whereClause
;
907 // Handle the case of DeleteWhere() and the where clause is blank. It should
908 // delete all records from the database in this case.
909 if (typeOfDel
== DB_DEL_WHERE
&& (pWhereClause
.Length() == 0))
911 pSqlStmt
.Printf(wxT("DELETE FROM %s"), tableName
.c_str());
915 pSqlStmt
.Printf(wxT("DELETE FROM %s WHERE "), tableName
.c_str());
917 // Append the WHERE clause to the SQL DELETE statement
920 case DB_DEL_KEYFIELDS
:
921 // If the datasource supports the ROWID column, build
922 // the where on ROWID for efficiency purposes.
923 // e.g. DELETE FROM PARTS WHERE ROWID = '111.222.333'
927 wxChar rowid
[wxDB_ROWID_LEN
+1];
929 // Get the ROWID value. If not successful retreiving the ROWID,
930 // simply fall down through the code and build the WHERE clause
931 // based on the key fields.
932 if (SQLGetData(hstmt
, noCols
+1, SQL_C_CHAR
, (UCHAR
*) rowid
, wxDB_ROWID_LEN
, &cb
) == SQL_SUCCESS
)
934 pSqlStmt
+= wxT("ROWID = '");
936 pSqlStmt
+= wxT("'");
940 // Unable to delete by ROWID, so build a WHERE
941 // clause based on the keyfields.
942 BuildWhereClause(whereClause
, DB_WHERE_KEYFIELDS
);
943 pSqlStmt
+= whereClause
;
946 pSqlStmt
+= pWhereClause
;
948 case DB_DEL_MATCHING
:
949 BuildWhereClause(whereClause
, DB_WHERE_MATCHING
);
950 pSqlStmt
+= whereClause
;
954 } // BuildDeleteStmt()
957 /***** DEPRECATED: use wxDbTable::BuildDeleteStmt(wxString &....) form *****/
958 void wxDbTable::BuildDeleteStmt(wxChar
*pSqlStmt
, int typeOfDel
, const wxString
&pWhereClause
)
960 wxString tempSqlStmt
;
961 BuildDeleteStmt(tempSqlStmt
, typeOfDel
, pWhereClause
);
962 wxStrcpy(pSqlStmt
, tempSqlStmt
);
963 } // wxDbTable::BuildDeleteStmt()
966 /********** wxDbTable::BuildSelectStmt() **********/
967 void wxDbTable::BuildSelectStmt(wxString
&pSqlStmt
, int typeOfSelect
, bool distinct
)
969 wxString whereClause
;
972 // Build a select statement to query the database
973 pSqlStmt
= wxT("SELECT ");
975 // SELECT DISTINCT values only?
977 pSqlStmt
+= wxT("DISTINCT ");
979 // Was a FROM clause specified to join tables to the base table?
980 // Available for ::Query() only!!!
981 bool appendFromClause
= FALSE
;
982 #if wxODBC_BACKWARD_COMPATABILITY
983 if (typeOfSelect
== DB_SELECT_WHERE
&& from
&& wxStrlen(from
))
984 appendFromClause
= TRUE
;
986 if (typeOfSelect
== DB_SELECT_WHERE
&& from
.Length())
987 appendFromClause
= TRUE
;
990 // Add the column list
992 for (i
= 0; i
< noCols
; i
++)
994 // If joining tables, the base table column names must be qualified to avoid ambiguity
995 if (appendFromClause
)
997 pSqlStmt
+= queryTableName
;
998 pSqlStmt
+= wxT(".");
1000 pSqlStmt
+= colDefs
[i
].ColName
;
1002 pSqlStmt
+= wxT(",");
1005 // If the datasource supports ROWID, get this column as well. Exception: Don't retrieve
1006 // the ROWID if querying distinct records. The rowid will always be unique.
1007 if (!distinct
&& CanUpdByROWID())
1009 // If joining tables, the base table column names must be qualified to avoid ambiguity
1010 if (appendFromClause
)
1012 pSqlStmt
+= wxT(",");
1013 pSqlStmt
+= queryTableName
;
1014 pSqlStmt
+= wxT(".ROWID");
1017 pSqlStmt
+= wxT(",ROWID");
1020 // Append the FROM tablename portion
1021 pSqlStmt
+= wxT(" FROM ");
1022 pSqlStmt
+= queryTableName
;
1024 // Sybase uses the HOLDLOCK keyword to lock a record during query.
1025 // The HOLDLOCK keyword follows the table name in the from clause.
1026 // Each table in the from clause must specify HOLDLOCK or
1027 // NOHOLDLOCK (the default). Note: The "FOR UPDATE" clause
1028 // is parsed but ignored in SYBASE Transact-SQL.
1029 if (selectForUpdate
&& (pDb
->Dbms() == dbmsSYBASE_ASA
|| pDb
->Dbms() == dbmsSYBASE_ASE
))
1030 pSqlStmt
+= wxT(" HOLDLOCK");
1032 if (appendFromClause
)
1035 // Append the WHERE clause. Either append the where clause for the class
1036 // or build a where clause. The typeOfSelect determines this.
1037 switch(typeOfSelect
)
1039 case DB_SELECT_WHERE
:
1040 #if wxODBC_BACKWARD_COMPATABILITY
1041 if (where
&& wxStrlen(where
)) // May not want a where clause!!!
1043 if (where
.Length()) // May not want a where clause!!!
1046 pSqlStmt
+= wxT(" WHERE ");
1050 case DB_SELECT_KEYFIELDS
:
1051 BuildWhereClause(whereClause
, DB_WHERE_KEYFIELDS
);
1052 if (whereClause
.Length())
1054 pSqlStmt
+= wxT(" WHERE ");
1055 pSqlStmt
+= whereClause
;
1058 case DB_SELECT_MATCHING
:
1059 BuildWhereClause(whereClause
, DB_WHERE_MATCHING
);
1060 if (whereClause
.Length())
1062 pSqlStmt
+= wxT(" WHERE ");
1063 pSqlStmt
+= whereClause
;
1068 // Append the ORDER BY clause
1069 #if wxODBC_BACKWARD_COMPATABILITY
1070 if (orderBy
&& wxStrlen(orderBy
))
1072 if (orderBy
.Length())
1075 pSqlStmt
+= wxT(" ORDER BY ");
1076 pSqlStmt
+= orderBy
;
1079 // SELECT FOR UPDATE if told to do so and the datasource is capable. Sybase
1080 // parses the FOR UPDATE clause but ignores it. See the comment above on the
1081 // HOLDLOCK for Sybase.
1082 if (selectForUpdate
&& CanSelectForUpdate())
1083 pSqlStmt
+= wxT(" FOR UPDATE");
1085 } // wxDbTable::BuildSelectStmt()
1088 /***** DEPRECATED: use wxDbTable::BuildSelectStmt(wxString &....) form *****/
1089 void wxDbTable::BuildSelectStmt(wxChar
*pSqlStmt
, int typeOfSelect
, bool distinct
)
1091 wxString tempSqlStmt
;
1092 BuildSelectStmt(tempSqlStmt
, typeOfSelect
, distinct
);
1093 wxStrcpy(pSqlStmt
, tempSqlStmt
);
1094 } // wxDbTable::BuildSelectStmt()
1097 /********** wxDbTable::BuildUpdateStmt() **********/
1098 void wxDbTable::BuildUpdateStmt(wxString
&pSqlStmt
, int typeOfUpd
, const wxString
&pWhereClause
)
1100 wxASSERT(!queryOnly
);
1104 wxString whereClause
;
1105 whereClause
.Empty();
1107 bool firstColumn
= TRUE
;
1109 pSqlStmt
.Printf(wxT("UPDATE %s SET "), tableName
.c_str());
1111 // Append a list of columns to be updated
1113 for (i
= 0; i
< noCols
; i
++)
1115 // Only append Updateable columns
1116 if (colDefs
[i
].Updateable
)
1119 pSqlStmt
+= wxT(",");
1121 firstColumn
= FALSE
;
1122 pSqlStmt
+= colDefs
[i
].ColName
;
1123 pSqlStmt
+= wxT(" = ?");
1127 // Append the WHERE clause to the SQL UPDATE statement
1128 pSqlStmt
+= wxT(" WHERE ");
1131 case DB_UPD_KEYFIELDS
:
1132 // If the datasource supports the ROWID column, build
1133 // the where on ROWID for efficiency purposes.
1134 // e.g. UPDATE PARTS SET Col1 = ?, Col2 = ? WHERE ROWID = '111.222.333'
1135 if (CanUpdByROWID())
1138 wxChar rowid
[wxDB_ROWID_LEN
+1];
1140 // Get the ROWID value. If not successful retreiving the ROWID,
1141 // simply fall down through the code and build the WHERE clause
1142 // based on the key fields.
1143 if (SQLGetData(hstmt
, noCols
+1, SQL_C_CHAR
, (UCHAR
*) rowid
, wxDB_ROWID_LEN
, &cb
) == SQL_SUCCESS
)
1145 pSqlStmt
+= wxT("ROWID = '");
1147 pSqlStmt
+= wxT("'");
1151 // Unable to delete by ROWID, so build a WHERE
1152 // clause based on the keyfields.
1153 BuildWhereClause(whereClause
, DB_WHERE_KEYFIELDS
);
1154 pSqlStmt
+= whereClause
;
1157 pSqlStmt
+= pWhereClause
;
1160 } // BuildUpdateStmt()
1163 /***** DEPRECATED: use wxDbTable::BuildUpdateStmt(wxString &....) form *****/
1164 void wxDbTable::BuildUpdateStmt(wxChar
*pSqlStmt
, int typeOfUpd
, const wxString
&pWhereClause
)
1166 wxString tempSqlStmt
;
1167 BuildUpdateStmt(tempSqlStmt
, typeOfUpd
, pWhereClause
);
1168 wxStrcpy(pSqlStmt
, tempSqlStmt
);
1169 } // BuildUpdateStmt()
1172 /********** wxDbTable::BuildWhereClause() **********/
1173 void wxDbTable::BuildWhereClause(wxString
&pWhereClause
, int typeOfWhere
,
1174 const wxString
&qualTableName
, bool useLikeComparison
)
1176 * Note: BuildWhereClause() currently ignores timestamp columns.
1177 * They are not included as part of the where clause.
1180 bool moreThanOneColumn
= FALSE
;
1183 // Loop through the columns building a where clause as you go
1185 for (i
= 0; i
< noCols
; i
++)
1187 // Determine if this column should be included in the WHERE clause
1188 if ((typeOfWhere
== DB_WHERE_KEYFIELDS
&& colDefs
[i
].KeyField
) ||
1189 (typeOfWhere
== DB_WHERE_MATCHING
&& (!IsColNull(i
))))
1191 // Skip over timestamp columns
1192 if (colDefs
[i
].SqlCtype
== SQL_C_TIMESTAMP
)
1194 // If there is more than 1 column, join them with the keyword "AND"
1195 if (moreThanOneColumn
)
1196 pWhereClause
+= wxT(" AND ");
1198 moreThanOneColumn
= TRUE
;
1199 // Concatenate where phrase for the column
1200 if (qualTableName
.Length())
1202 pWhereClause
+= qualTableName
;
1203 pWhereClause
+= wxT(".");
1205 pWhereClause
+= colDefs
[i
].ColName
;
1206 if (useLikeComparison
&& (colDefs
[i
].SqlCtype
== SQL_C_CHAR
))
1207 pWhereClause
+= wxT(" LIKE ");
1209 pWhereClause
+= wxT(" = ");
1210 switch(colDefs
[i
].SqlCtype
)
1213 colValue
.Printf(wxT("'%s'"), (UCHAR FAR
*) colDefs
[i
].PtrDataObj
);
1216 colValue
.Printf(wxT("%hi"), *((SWORD
*) colDefs
[i
].PtrDataObj
));
1219 colValue
.Printf(wxT("%hu"), *((UWORD
*) colDefs
[i
].PtrDataObj
));
1222 colValue
.Printf(wxT("%li"), *((SDWORD
*) colDefs
[i
].PtrDataObj
));
1225 colValue
.Printf(wxT("%lu"), *((UDWORD
*) colDefs
[i
].PtrDataObj
));
1228 colValue
.Printf(wxT("%.6f"), *((SFLOAT
*) colDefs
[i
].PtrDataObj
));
1231 colValue
.Printf(wxT("%.6f"), *((SDOUBLE
*) colDefs
[i
].PtrDataObj
));
1234 pWhereClause
+= colValue
;
1237 } // wxDbTable::BuildWhereClause()
1240 /***** DEPRECATED: use wxDbTable::BuildWhereClause(wxString &....) form *****/
1241 void wxDbTable::BuildWhereClause(wxChar
*pWhereClause
, int typeOfWhere
,
1242 const wxString
&qualTableName
, bool useLikeComparison
)
1244 wxString tempSqlStmt
;
1245 BuildWhereClause(tempSqlStmt
, typeOfWhere
, qualTableName
, useLikeComparison
);
1246 wxStrcpy(pWhereClause
, tempSqlStmt
);
1247 } // wxDbTable::BuildWhereClause()
1250 /********** wxDbTable::GetRowNum() **********/
1251 UWORD
wxDbTable::GetRowNum(void)
1255 if (SQLGetStmtOption(hstmt
, SQL_ROW_NUMBER
, (UCHAR
*) &rowNum
) != SQL_SUCCESS
)
1257 pDb
->DispAllErrors(henv
, hdbc
, hstmt
);
1261 // Completed successfully
1262 return((UWORD
) rowNum
);
1264 } // wxDbTable::GetRowNum()
1267 /********** wxDbTable::CloseCursor() **********/
1268 bool wxDbTable::CloseCursor(HSTMT cursor
)
1270 if (SQLFreeStmt(cursor
, SQL_CLOSE
) != SQL_SUCCESS
)
1271 return(pDb
->DispAllErrors(henv
, hdbc
, cursor
));
1273 // Completed successfully
1276 } // wxDbTable::CloseCursor()
1279 /********** wxDbTable::CreateTable() **********/
1280 bool wxDbTable::CreateTable(bool attemptDrop
)
1288 #ifdef DBDEBUG_CONSOLE
1289 cout
<< wxT("Creating Table ") << tableName
<< wxT("...") << endl
;
1293 if (attemptDrop
&& !DropTable())
1297 #ifdef DBDEBUG_CONSOLE
1298 for (i
= 0; i
< noCols
; i
++)
1300 // Exclude derived columns since they are NOT part of the base table
1301 if (colDefs
[i
].DerivedCol
)
1303 cout
<< i
+ 1 << wxT(": ") << colDefs
[i
].ColName
<< wxT("; ");
1304 switch(colDefs
[i
].DbDataType
)
1306 case DB_DATA_TYPE_VARCHAR
:
1307 cout
<< pDb
->typeInfVarchar
.TypeName
<< wxT("(") << colDefs
[i
].SzDataObj
<< wxT(")");
1309 case DB_DATA_TYPE_INTEGER
:
1310 cout
<< pDb
->typeInfInteger
.TypeName
;
1312 case DB_DATA_TYPE_FLOAT
:
1313 cout
<< pDb
->typeInfFloat
.TypeName
;
1315 case DB_DATA_TYPE_DATE
:
1316 cout
<< pDb
->typeInfDate
.TypeName
;
1323 // Build a CREATE TABLE string from the colDefs structure.
1324 bool needComma
= FALSE
;
1325 sqlStmt
.Printf(wxT("CREATE TABLE %s ("), tableName
.c_str());
1327 for (i
= 0; i
< noCols
; i
++)
1329 // Exclude derived columns since they are NOT part of the base table
1330 if (colDefs
[i
].DerivedCol
)
1334 sqlStmt
+= wxT(",");
1336 sqlStmt
+= colDefs
[i
].ColName
;
1337 sqlStmt
+= wxT(" ");
1339 switch(colDefs
[i
].DbDataType
)
1341 case DB_DATA_TYPE_VARCHAR
:
1342 sqlStmt
+= pDb
->GetTypeInfVarchar().TypeName
;
1344 case DB_DATA_TYPE_INTEGER
:
1345 sqlStmt
+= pDb
->GetTypeInfInteger().TypeName
;
1347 case DB_DATA_TYPE_FLOAT
:
1348 sqlStmt
+= pDb
->GetTypeInfFloat().TypeName
;
1350 case DB_DATA_TYPE_DATE
:
1351 sqlStmt
+= pDb
->GetTypeInfDate().TypeName
;
1354 // For varchars, append the size of the string
1355 if (colDefs
[i
].DbDataType
== DB_DATA_TYPE_VARCHAR
)
1358 s
.Printf(wxT("(%d)"), colDefs
[i
].SzDataObj
);
1362 if (pDb
->Dbms() == dbmsDB2
||
1363 pDb
->Dbms() == dbmsMY_SQL
||
1364 pDb
->Dbms() == dbmsSYBASE_ASE
||
1365 pDb
->Dbms() == dbmsMS_SQL_SERVER
)
1367 if (colDefs
[i
].KeyField
)
1369 sqlStmt
+= wxT(" NOT NULL");
1375 // If there is a primary key defined, include it in the create statement
1376 for (i
= j
= 0; i
< noCols
; i
++)
1378 if (colDefs
[i
].KeyField
)
1384 if (j
&& pDb
->Dbms() != dbmsDBASE
) // Found a keyfield
1386 if (pDb
->Dbms() != dbmsMY_SQL
)
1388 sqlStmt
+= wxT(",CONSTRAINT ");
1389 sqlStmt
+= tableName
;
1390 sqlStmt
+= wxT("_PIDX PRIMARY KEY (");
1394 /* MySQL goes out on this one. We also declare the relevant key NON NULL above */
1395 sqlStmt
+= wxT(", PRIMARY KEY (");
1398 // List column name(s) of column(s) comprising the primary key
1399 for (i
= j
= 0; i
< noCols
; i
++)
1401 if (colDefs
[i
].KeyField
)
1403 if (j
++) // Multi part key, comma separate names
1404 sqlStmt
+= wxT(",");
1405 sqlStmt
+= colDefs
[i
].ColName
;
1408 sqlStmt
+= wxT(")");
1410 // Append the closing parentheses for the create table statement
1411 sqlStmt
+= wxT(")");
1413 pDb
->WriteSqlLog(sqlStmt
);
1415 #ifdef DBDEBUG_CONSOLE
1416 cout
<< endl
<< sqlStmt
.c_str() << endl
;
1419 // Execute the CREATE TABLE statement
1420 RETCODE retcode
= SQLExecDirect(hstmt
, (UCHAR FAR
*) sqlStmt
.c_str(), SQL_NTS
);
1421 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
1423 pDb
->DispAllErrors(henv
, hdbc
, hstmt
);
1424 pDb
->RollbackTrans();
1429 // Commit the transaction and close the cursor
1430 if (!pDb
->CommitTrans())
1432 if (!CloseCursor(hstmt
))
1435 // Database table created successfully
1438 } // wxDbTable::CreateTable()
1441 /********** wxDbTable::DropTable() **********/
1442 bool wxDbTable::DropTable()
1444 // NOTE: This function returns TRUE if the Table does not exist, but
1445 // only for identified databases. Code will need to be added
1446 // below for any other databases when those databases are defined
1447 // to handle this situation consistently
1451 sqlStmt
.Printf(wxT("DROP TABLE %s"), tableName
.c_str());
1453 pDb
->WriteSqlLog(sqlStmt
);
1455 #ifdef DBDEBUG_CONSOLE
1456 cout
<< endl
<< sqlStmt
.c_str() << endl
;
1459 if (SQLExecDirect(hstmt
, (UCHAR FAR
*) sqlStmt
.c_str(), SQL_NTS
) != SQL_SUCCESS
)
1461 // Check for "Base table not found" error and ignore
1462 pDb
->GetNextError(henv
, hdbc
, hstmt
);
1463 if (wxStrcmp(pDb
->sqlState
, wxT("S0002")) &&
1464 wxStrcmp(pDb
->sqlState
, wxT("S1000"))) // "Base table not found"
1466 // Check for product specific error codes
1467 if (!((pDb
->Dbms() == dbmsSYBASE_ASA
&& !wxStrcmp(pDb
->sqlState
,wxT("42000"))) || // 5.x (and lower?)
1468 (pDb
->Dbms() == dbmsSYBASE_ASE
&& !wxStrcmp(pDb
->sqlState
,wxT("37000"))) ||
1469 (pDb
->Dbms() == dbmsPOSTGRES
&& !wxStrcmp(pDb
->sqlState
,wxT("08S01")))))
1471 pDb
->DispNextError();
1472 pDb
->DispAllErrors(henv
, hdbc
, hstmt
);
1473 pDb
->RollbackTrans();
1480 // Commit the transaction and close the cursor
1481 if (! pDb
->CommitTrans())
1483 if (! CloseCursor(hstmt
))
1487 } // wxDbTable::DropTable()
1490 /********** wxDbTable::CreateIndex() **********/
1491 bool wxDbTable::CreateIndex(const wxString
&idxName
, bool unique
, int noIdxCols
, wxDbIdxDef
*pIdxDefs
, bool attemptDrop
)
1495 // Drop the index first
1496 if (attemptDrop
&& !DropIndex(idxName
))
1499 // MySQL (and possibly Sybase ASE?? - gt) require that any columns which are used as portions
1500 // of an index have the columns defined as "NOT NULL". During initial table creation though,
1501 // it may not be known which columns are necessarily going to be part of an index (e.g. the
1502 // table was created, then months later you determine that an additional index while
1503 // give better performance, so you want to add an index).
1505 // The following block of code will modify the column definition to make the column be
1506 // defined with the "NOT NULL" qualifier.
1507 if (pDb
->Dbms() == dbmsMY_SQL
)
1512 for (i
= 0; i
< noIdxCols
&& ok
; i
++)
1516 // Find the column definition that has the ColName that matches the
1517 // index column name. We need to do this to get the DB_DATA_TYPE of
1518 // the index column, as MySQL's syntax for the ALTER column requires
1520 while (!found
&& (j
< this->noCols
))
1522 if (wxStrcmp(colDefs
[j
].ColName
,pIdxDefs
[i
].ColName
) == 0)
1530 ok
= pDb
->ModifyColumn(tableName
, pIdxDefs
[i
].ColName
,
1531 colDefs
[j
].DbDataType
, colDefs
[j
].SzDataObj
,
1536 wxODBC_ERRORS retcode
;
1537 // Oracle returns a DB_ERR_GENERAL_ERROR if the column is already
1538 // defined to be NOT NULL, but reportedly MySQL doesn't mind.
1539 // This line is just here for debug checking of the value
1540 retcode
= (wxODBC_ERRORS
)pDb
->DB_STATUS
;
1550 pDb
->RollbackTrans();
1555 // Build a CREATE INDEX statement
1556 sqlStmt
= wxT("CREATE ");
1558 sqlStmt
+= wxT("UNIQUE ");
1560 sqlStmt
+= wxT("INDEX ");
1562 sqlStmt
+= wxT(" ON ");
1563 sqlStmt
+= tableName
;
1564 sqlStmt
+= wxT(" (");
1566 // Append list of columns making up index
1568 for (i
= 0; i
< noIdxCols
; i
++)
1570 sqlStmt
+= pIdxDefs
[i
].ColName
;
1571 /* Postgres doesn't cope with ASC */
1572 if (pDb
->Dbms() != dbmsPOSTGRES
)
1574 if (pIdxDefs
[i
].Ascending
)
1575 sqlStmt
+= wxT(" ASC");
1577 sqlStmt
+= wxT(" DESC");
1580 if ((i
+ 1) < noIdxCols
)
1581 sqlStmt
+= wxT(",");
1584 // Append closing parentheses
1585 sqlStmt
+= wxT(")");
1587 pDb
->WriteSqlLog(sqlStmt
);
1589 #ifdef DBDEBUG_CONSOLE
1590 cout
<< endl
<< sqlStmt
.c_str() << endl
<< endl
;
1593 // Execute the CREATE INDEX statement
1594 if (SQLExecDirect(hstmt
, (UCHAR FAR
*) sqlStmt
.c_str(), SQL_NTS
) != SQL_SUCCESS
)
1596 pDb
->DispAllErrors(henv
, hdbc
, hstmt
);
1597 pDb
->RollbackTrans();
1602 // Commit the transaction and close the cursor
1603 if (! pDb
->CommitTrans())
1605 if (! CloseCursor(hstmt
))
1608 // Index Created Successfully
1611 } // wxDbTable::CreateIndex()
1614 /********** wxDbTable::DropIndex() **********/
1615 bool wxDbTable::DropIndex(const wxString
&idxName
)
1617 // NOTE: This function returns TRUE if the Index does not exist, but
1618 // only for identified databases. Code will need to be added
1619 // below for any other databases when those databases are defined
1620 // to handle this situation consistently
1624 if (pDb
->Dbms() == dbmsACCESS
|| pDb
->Dbms() == dbmsMY_SQL
)
1625 sqlStmt
.Printf(wxT("DROP INDEX %s ON %s"),idxName
.c_str(), tableName
.c_str());
1626 else if ((pDb
->Dbms() == dbmsMS_SQL_SERVER
) ||
1627 (pDb
->Dbms() == dbmsSYBASE_ASE
))
1628 sqlStmt
.Printf(wxT("DROP INDEX %s.%s"),tableName
.c_str(), idxName
.c_str());
1630 sqlStmt
.Printf(wxT("DROP INDEX %s"),idxName
.c_str());
1632 pDb
->WriteSqlLog(sqlStmt
);
1634 #ifdef DBDEBUG_CONSOLE
1635 cout
<< endl
<< sqlStmt
.c_str() << endl
;
1638 if (SQLExecDirect(hstmt
, (UCHAR FAR
*) sqlStmt
.c_str(), SQL_NTS
) != SQL_SUCCESS
)
1640 // Check for "Index not found" error and ignore
1641 pDb
->GetNextError(henv
, hdbc
, hstmt
);
1642 if (wxStrcmp(pDb
->sqlState
,wxT("S0012"))) // "Index not found"
1644 // Check for product specific error codes
1645 if (!((pDb
->Dbms() == dbmsSYBASE_ASA
&& !wxStrcmp(pDb
->sqlState
,wxT("42000"))) || // v5.x (and lower?)
1646 (pDb
->Dbms() == dbmsSYBASE_ASE
&& !wxStrcmp(pDb
->sqlState
,wxT("37000"))) ||
1647 (pDb
->Dbms() == dbmsMS_SQL_SERVER
&& !wxStrcmp(pDb
->sqlState
,wxT("S1000"))) ||
1648 (pDb
->Dbms() == dbmsSYBASE_ASE
&& !wxStrcmp(pDb
->sqlState
,wxT("S0002"))) || // Base table not found
1649 (pDb
->Dbms() == dbmsMY_SQL
&& !wxStrcmp(pDb
->sqlState
,wxT("42S12"))) || // tested by Christopher Ludwik Marino-Cebulski using v3.23.21beta
1650 (pDb
->Dbms() == dbmsPOSTGRES
&& !wxStrcmp(pDb
->sqlState
,wxT("08S01")))
1653 pDb
->DispNextError();
1654 pDb
->DispAllErrors(henv
, hdbc
, hstmt
);
1655 pDb
->RollbackTrans();
1662 // Commit the transaction and close the cursor
1663 if (! pDb
->CommitTrans())
1665 if (! CloseCursor(hstmt
))
1669 } // wxDbTable::DropIndex()
1672 /********** wxDbTable::SetOrderByColNums() **********/
1673 bool wxDbTable::SetOrderByColNums(int first
, ... )
1681 va_start(argptr
, first
); /* Initialize variable arguments. */
1682 while (!abort
&& (colNo
!= wxDB_NO_MORE_COLUMN_NUMBERS
))
1684 // Make sure the passed in column number
1685 // is within the valid range of columns
1687 // Valid columns are 0 thru noCols-1
1688 if (colNo
>= noCols
|| colNo
< 0)
1695 tempStr
+= wxT(",");
1697 tempStr
+= colDefs
[colNo
].ColName
;
1698 colNo
= va_arg (argptr
, int);
1700 va_end (argptr
); /* Reset variable arguments. */
1702 SetOrderByClause(tempStr
);
1705 } // wxDbTable::SetOrderByColNums()
1708 /********** wxDbTable::Insert() **********/
1709 int wxDbTable::Insert(void)
1711 wxASSERT(!queryOnly
);
1712 if (queryOnly
|| !insertable
)
1717 // Insert the record by executing the already prepared insert statement
1719 retcode
=SQLExecute(hstmtInsert
);
1720 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
1722 // Check to see if integrity constraint was violated
1723 pDb
->GetNextError(henv
, hdbc
, hstmtInsert
);
1724 if (! wxStrcmp(pDb
->sqlState
, wxT("23000"))) // Integrity constraint violated
1725 return(DB_ERR_INTEGRITY_CONSTRAINT_VIOL
);
1728 pDb
->DispNextError();
1729 pDb
->DispAllErrors(henv
, hdbc
, hstmtInsert
);
1734 // Record inserted into the datasource successfully
1737 } // wxDbTable::Insert()
1740 /********** wxDbTable::Update() **********/
1741 bool wxDbTable::Update(void)
1743 wxASSERT(!queryOnly
);
1749 // Build the SQL UPDATE statement
1750 BuildUpdateStmt(sqlStmt
, DB_UPD_KEYFIELDS
);
1752 pDb
->WriteSqlLog(sqlStmt
);
1754 #ifdef DBDEBUG_CONSOLE
1755 cout
<< endl
<< sqlStmt
.c_str() << endl
<< endl
;
1758 // Execute the SQL UPDATE statement
1759 return(execUpdate(sqlStmt
));
1761 } // wxDbTable::Update()
1764 /********** wxDbTable::Update(pSqlStmt) **********/
1765 bool wxDbTable::Update(const wxString
&pSqlStmt
)
1767 wxASSERT(!queryOnly
);
1771 pDb
->WriteSqlLog(pSqlStmt
);
1773 return(execUpdate(pSqlStmt
));
1775 } // wxDbTable::Update(pSqlStmt)
1778 /********** wxDbTable::UpdateWhere() **********/
1779 bool wxDbTable::UpdateWhere(const wxString
&pWhereClause
)
1781 wxASSERT(!queryOnly
);
1787 // Build the SQL UPDATE statement
1788 BuildUpdateStmt(sqlStmt
, DB_UPD_WHERE
, pWhereClause
);
1790 pDb
->WriteSqlLog(sqlStmt
);
1792 #ifdef DBDEBUG_CONSOLE
1793 cout
<< endl
<< sqlStmt
.c_str() << endl
<< endl
;
1796 // Execute the SQL UPDATE statement
1797 return(execUpdate(sqlStmt
));
1799 } // wxDbTable::UpdateWhere()
1802 /********** wxDbTable::Delete() **********/
1803 bool wxDbTable::Delete(void)
1805 wxASSERT(!queryOnly
);
1812 // Build the SQL DELETE statement
1813 BuildDeleteStmt(sqlStmt
, DB_DEL_KEYFIELDS
);
1815 pDb
->WriteSqlLog(sqlStmt
);
1817 // Execute the SQL DELETE statement
1818 return(execDelete(sqlStmt
));
1820 } // wxDbTable::Delete()
1823 /********** wxDbTable::DeleteWhere() **********/
1824 bool wxDbTable::DeleteWhere(const wxString
&pWhereClause
)
1826 wxASSERT(!queryOnly
);
1833 // Build the SQL DELETE statement
1834 BuildDeleteStmt(sqlStmt
, DB_DEL_WHERE
, pWhereClause
);
1836 pDb
->WriteSqlLog(sqlStmt
);
1838 // Execute the SQL DELETE statement
1839 return(execDelete(sqlStmt
));
1841 } // wxDbTable::DeleteWhere()
1844 /********** wxDbTable::DeleteMatching() **********/
1845 bool wxDbTable::DeleteMatching(void)
1847 wxASSERT(!queryOnly
);
1854 // Build the SQL DELETE statement
1855 BuildDeleteStmt(sqlStmt
, DB_DEL_MATCHING
);
1857 pDb
->WriteSqlLog(sqlStmt
);
1859 // Execute the SQL DELETE statement
1860 return(execDelete(sqlStmt
));
1862 } // wxDbTable::DeleteMatching()
1865 /********** wxDbTable::IsColNull() **********/
1866 bool wxDbTable::IsColNull(int colNo
)
1869 This logic is just not right. It would indicate TRUE
1870 if a numeric field were set to a value of 0.
1872 switch(colDefs[colNo].SqlCtype)
1875 return(((UCHAR FAR *) colDefs[colNo].PtrDataObj)[0] == 0);
1877 return(( *((SWORD *) colDefs[colNo].PtrDataObj)) == 0);
1879 return(( *((UWORD*) colDefs[colNo].PtrDataObj)) == 0);
1881 return(( *((SDWORD *) colDefs[colNo].PtrDataObj)) == 0);
1883 return(( *((UDWORD *) colDefs[colNo].PtrDataObj)) == 0);
1885 return(( *((SFLOAT *) colDefs[colNo].PtrDataObj)) == 0);
1887 return((*((SDOUBLE *) colDefs[colNo].PtrDataObj)) == 0);
1888 case SQL_C_TIMESTAMP:
1889 TIMESTAMP_STRUCT *pDt;
1890 pDt = (TIMESTAMP_STRUCT *) colDefs[colNo].PtrDataObj;
1891 if (pDt->year == 0 && pDt->month == 0 && pDt->day == 0)
1899 return (colDefs
[colNo
].Null
);
1900 } // wxDbTable::IsColNull()
1903 /********** wxDbTable::CanSelectForUpdate() **********/
1904 bool wxDbTable::CanSelectForUpdate(void)
1909 if (pDb
->Dbms() == dbmsMY_SQL
)
1912 if ((pDb
->Dbms() == dbmsORACLE
) ||
1913 (pDb
->dbInf
.posStmts
& SQL_PS_SELECT_FOR_UPDATE
))
1918 } // wxDbTable::CanSelectForUpdate()
1921 /********** wxDbTable::CanUpdByROWID() **********/
1922 bool wxDbTable::CanUpdByROWID(void)
1925 * NOTE: Returning FALSE for now until this can be debugged,
1926 * as the ROWID is not getting updated correctly
1930 if (pDb
->Dbms() == dbmsORACLE
)
1935 } // wxDbTable::CanUpdByROWID()
1938 /********** wxDbTable::IsCursorClosedOnCommit() **********/
1939 bool wxDbTable::IsCursorClosedOnCommit(void)
1941 if (pDb
->dbInf
.cursorCommitBehavior
== SQL_CB_PRESERVE
)
1946 } // wxDbTable::IsCursorClosedOnCommit()
1950 /********** wxDbTable::ClearMemberVar() **********/
1951 void wxDbTable::ClearMemberVar(int colNo
, bool setToNull
)
1953 wxASSERT(colNo
< noCols
);
1955 switch(colDefs
[colNo
].SqlCtype
)
1958 ((UCHAR FAR
*) colDefs
[colNo
].PtrDataObj
)[0] = 0;
1961 *((SWORD
*) colDefs
[colNo
].PtrDataObj
) = 0;
1964 *((UWORD
*) colDefs
[colNo
].PtrDataObj
) = 0;
1967 *((SDWORD
*) colDefs
[colNo
].PtrDataObj
) = 0;
1970 *((UDWORD
*) colDefs
[colNo
].PtrDataObj
) = 0;
1973 *((SFLOAT
*) colDefs
[colNo
].PtrDataObj
) = 0.0f
;
1976 *((SDOUBLE
*) colDefs
[colNo
].PtrDataObj
) = 0.0f
;
1978 case SQL_C_TIMESTAMP
:
1979 TIMESTAMP_STRUCT
*pDt
;
1980 pDt
= (TIMESTAMP_STRUCT
*) colDefs
[colNo
].PtrDataObj
;
1993 } // wxDbTable::ClearMemberVar()
1996 /********** wxDbTable::ClearMemberVars() **********/
1997 void wxDbTable::ClearMemberVars(bool setToNull
)
2001 // Loop through the columns setting each member variable to zero
2002 for (i
=0; i
< noCols
; i
++)
2003 ClearMemberVar(i
,setToNull
);
2005 } // wxDbTable::ClearMemberVars()
2008 /********** wxDbTable::SetQueryTimeout() **********/
2009 bool wxDbTable::SetQueryTimeout(UDWORD nSeconds
)
2011 if (SQLSetStmtOption(hstmtInsert
, SQL_QUERY_TIMEOUT
, nSeconds
) != SQL_SUCCESS
)
2012 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtInsert
));
2013 if (SQLSetStmtOption(hstmtUpdate
, SQL_QUERY_TIMEOUT
, nSeconds
) != SQL_SUCCESS
)
2014 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtUpdate
));
2015 if (SQLSetStmtOption(hstmtDelete
, SQL_QUERY_TIMEOUT
, nSeconds
) != SQL_SUCCESS
)
2016 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtDelete
));
2017 if (SQLSetStmtOption(hstmtInternal
, SQL_QUERY_TIMEOUT
, nSeconds
) != SQL_SUCCESS
)
2018 return(pDb
->DispAllErrors(henv
, hdbc
, hstmtInternal
));
2020 // Completed Successfully
2023 } // wxDbTable::SetQueryTimeout()
2026 /********** wxDbTable::SetColDefs() **********/
2027 void wxDbTable::SetColDefs(int index
, const wxString
&fieldName
, int dataType
, void *pData
,
2028 int cType
, int size
, bool keyField
, bool upd
,
2029 bool insAllow
, bool derivedCol
)
2031 if (!colDefs
) // May happen if the database connection fails
2034 if (fieldName
.Length() > (unsigned int) DB_MAX_COLUMN_NAME_LEN
)
2036 wxStrncpy (colDefs
[index
].ColName
, fieldName
, DB_MAX_COLUMN_NAME_LEN
);
2037 colDefs
[index
].ColName
[DB_MAX_COLUMN_NAME_LEN
] = 0;
2040 wxStrcpy(colDefs
[index
].ColName
, fieldName
);
2042 colDefs
[index
].DbDataType
= dataType
;
2043 colDefs
[index
].PtrDataObj
= pData
;
2044 colDefs
[index
].SqlCtype
= cType
;
2045 colDefs
[index
].SzDataObj
= size
;
2046 colDefs
[index
].KeyField
= keyField
;
2047 colDefs
[index
].DerivedCol
= derivedCol
;
2048 // Derived columns by definition would NOT be "Insertable" or "Updateable"
2051 colDefs
[index
].Updateable
= FALSE
;
2052 colDefs
[index
].InsertAllowed
= FALSE
;
2056 colDefs
[index
].Updateable
= upd
;
2057 colDefs
[index
].InsertAllowed
= insAllow
;
2060 colDefs
[index
].Null
= FALSE
;
2062 } // wxDbTable::SetColDefs()
2065 /********** wxDbTable::SetColDefs() **********/
2066 wxDbColDataPtr
* wxDbTable::SetColDefs(wxDbColInf
*pColInfs
, ULONG numCols
)
2069 wxDbColDataPtr
*pColDataPtrs
= NULL
;
2075 pColDataPtrs
= new wxDbColDataPtr
[numCols
+1];
2077 for (index
= 0; index
< numCols
; index
++)
2079 // Process the fields
2080 switch (pColInfs
[index
].dbDataType
)
2082 case DB_DATA_TYPE_VARCHAR
:
2083 pColDataPtrs
[index
].PtrDataObj
= new wxChar
[pColInfs
[index
].bufferLength
+1];
2084 pColDataPtrs
[index
].SzDataObj
= pColInfs
[index
].columnSize
;
2085 pColDataPtrs
[index
].SqlCtype
= SQL_C_CHAR
;
2087 case DB_DATA_TYPE_INTEGER
:
2088 // Can be long or short
2089 if (pColInfs
[index
].bufferLength
== sizeof(long))
2091 pColDataPtrs
[index
].PtrDataObj
= new long;
2092 pColDataPtrs
[index
].SzDataObj
= sizeof(long);
2093 pColDataPtrs
[index
].SqlCtype
= SQL_C_SLONG
;
2097 pColDataPtrs
[index
].PtrDataObj
= new short;
2098 pColDataPtrs
[index
].SzDataObj
= sizeof(short);
2099 pColDataPtrs
[index
].SqlCtype
= SQL_C_SSHORT
;
2102 case DB_DATA_TYPE_FLOAT
:
2103 // Can be float or double
2104 if (pColInfs
[index
].bufferLength
== sizeof(float))
2106 pColDataPtrs
[index
].PtrDataObj
= new float;
2107 pColDataPtrs
[index
].SzDataObj
= sizeof(float);
2108 pColDataPtrs
[index
].SqlCtype
= SQL_C_FLOAT
;
2112 pColDataPtrs
[index
].PtrDataObj
= new double;
2113 pColDataPtrs
[index
].SzDataObj
= sizeof(double);
2114 pColDataPtrs
[index
].SqlCtype
= SQL_C_DOUBLE
;
2117 case DB_DATA_TYPE_DATE
:
2118 pColDataPtrs
[index
].PtrDataObj
= new TIMESTAMP_STRUCT
;
2119 pColDataPtrs
[index
].SzDataObj
= sizeof(TIMESTAMP_STRUCT
);
2120 pColDataPtrs
[index
].SqlCtype
= SQL_C_TIMESTAMP
;
2123 SetColDefs (index
,pColInfs
[index
].colName
,pColInfs
[index
].dbDataType
, pColDataPtrs
[index
].PtrDataObj
, pColDataPtrs
[index
].SqlCtype
, pColDataPtrs
[index
].SzDataObj
);
2127 return (pColDataPtrs
);
2129 } // wxDbTable::SetColDefs()
2132 /********** wxDbTable::SetCursor() **********/
2133 void wxDbTable::SetCursor(HSTMT
*hstmtActivate
)
2135 if (hstmtActivate
== wxDB_DEFAULT_CURSOR
)
2136 hstmt
= *hstmtDefault
;
2138 hstmt
= *hstmtActivate
;
2140 } // wxDbTable::SetCursor()
2143 /********** wxDbTable::Count(const wxString &) **********/
2144 ULONG
wxDbTable::Count(const wxString
&args
)
2150 // Build a "SELECT COUNT(*) FROM queryTableName [WHERE whereClause]" SQL Statement
2151 sqlStmt
= wxT("SELECT COUNT(");
2153 sqlStmt
+= wxT(") FROM ");
2154 sqlStmt
+= queryTableName
;
2155 #if wxODBC_BACKWARD_COMPATABILITY
2156 if (from
&& wxStrlen(from
))
2162 // Add the where clause if one is provided
2163 #if wxODBC_BACKWARD_COMPATABILITY
2164 if (where
&& wxStrlen(where
))
2169 sqlStmt
+= wxT(" WHERE ");
2173 pDb
->WriteSqlLog(sqlStmt
);
2175 // Initialize the Count cursor if it's not already initialized
2178 hstmtCount
= GetNewCursor(FALSE
,FALSE
);
2179 wxASSERT(hstmtCount
);
2184 // Execute the SQL statement
2185 if (SQLExecDirect(*hstmtCount
, (UCHAR FAR
*) sqlStmt
.c_str(), SQL_NTS
) != SQL_SUCCESS
)
2187 pDb
->DispAllErrors(henv
, hdbc
, *hstmtCount
);
2192 if (SQLFetch(*hstmtCount
) != SQL_SUCCESS
)
2194 pDb
->DispAllErrors(henv
, hdbc
, *hstmtCount
);
2198 // Obtain the result
2199 if (SQLGetData(*hstmtCount
, 1, SQL_C_ULONG
, &count
, sizeof(count
), &cb
) != SQL_SUCCESS
)
2201 pDb
->DispAllErrors(henv
, hdbc
, *hstmtCount
);
2206 if (SQLFreeStmt(*hstmtCount
, SQL_CLOSE
) != SQL_SUCCESS
)
2207 pDb
->DispAllErrors(henv
, hdbc
, *hstmtCount
);
2209 // Return the record count
2212 } // wxDbTable::Count()
2215 /********** wxDbTable::Refresh() **********/
2216 bool wxDbTable::Refresh(void)
2220 // Switch to the internal cursor so any active cursors are not corrupted
2221 HSTMT currCursor
= GetCursor();
2222 hstmt
= hstmtInternal
;
2223 #if wxODBC_BACKWARD_COMPATABILITY
2224 // Save the where and order by clauses
2225 char *saveWhere
= where
;
2226 char *saveOrderBy
= orderBy
;
2228 wxString saveWhere
= where
;
2229 wxString saveOrderBy
= orderBy
;
2231 // Build a where clause to refetch the record with. Try and use the
2232 // ROWID if it's available, ow use the key fields.
2233 wxString whereClause
;
2234 whereClause
.Empty();
2236 if (CanUpdByROWID())
2239 wxChar rowid
[wxDB_ROWID_LEN
+1];
2241 // Get the ROWID value. If not successful retreiving the ROWID,
2242 // simply fall down through the code and build the WHERE clause
2243 // based on the key fields.
2244 if (SQLGetData(hstmt
, noCols
+1, SQL_C_CHAR
, (UCHAR
*) rowid
, wxDB_ROWID_LEN
, &cb
) == SQL_SUCCESS
)
2246 whereClause
+= queryTableName
;
2247 whereClause
+= wxT(".ROWID = '");
2248 whereClause
+= rowid
;
2249 whereClause
+= wxT("'");
2253 // If unable to use the ROWID, build a where clause from the keyfields
2254 if (wxStrlen(whereClause
) == 0)
2255 BuildWhereClause(whereClause
, DB_WHERE_KEYFIELDS
, queryTableName
);
2257 // Requery the record
2258 where
= whereClause
;
2263 if (result
&& !GetNext())
2266 // Switch back to original cursor
2267 SetCursor(&currCursor
);
2269 // Free the internal cursor
2270 if (SQLFreeStmt(hstmtInternal
, SQL_CLOSE
) != SQL_SUCCESS
)
2271 pDb
->DispAllErrors(henv
, hdbc
, hstmtInternal
);
2273 // Restore the original where and order by clauses
2275 orderBy
= saveOrderBy
;
2279 } // wxDbTable::Refresh()
2282 /********** wxDbTable::SetColNull(int colNo, bool set) **********/
2283 bool wxDbTable::SetColNull(int colNo
, bool set
)
2287 colDefs
[colNo
].Null
= set
;
2288 if (set
) // Blank out the values in the member variable
2289 ClearMemberVar(colNo
,FALSE
); // Must call with FALSE, or infinite recursion will happen
2295 } // wxDbTable::SetColNull()
2298 /********** wxDbTable::SetColNull(const wxString &colName, bool set) **********/
2299 bool wxDbTable::SetColNull(const wxString
&colName
, bool set
)
2302 for (i
= 0; i
< noCols
; i
++)
2304 if (!wxStricmp(colName
, colDefs
[i
].ColName
))
2310 colDefs
[i
].Null
= set
;
2311 if (set
) // Blank out the values in the member variable
2312 ClearMemberVar(i
,FALSE
); // Must call with FALSE, or infinite recursion will happen
2318 } // wxDbTable::SetColNull()
2321 /********** wxDbTable::GetNewCursor() **********/
2322 HSTMT
*wxDbTable::GetNewCursor(bool setCursor
, bool bindColumns
)
2324 HSTMT
*newHSTMT
= new HSTMT
;
2329 if (SQLAllocStmt(hdbc
, newHSTMT
) != SQL_SUCCESS
)
2331 pDb
->DispAllErrors(henv
, hdbc
);
2336 if (SQLSetStmtOption(*newHSTMT
, SQL_CURSOR_TYPE
, cursorType
) != SQL_SUCCESS
)
2338 pDb
->DispAllErrors(henv
, hdbc
, *newHSTMT
);
2345 if(!bindCols(*newHSTMT
))
2353 SetCursor(newHSTMT
);
2357 } // wxDbTable::GetNewCursor()
2360 /********** wxDbTable::DeleteCursor() **********/
2361 bool wxDbTable::DeleteCursor(HSTMT
*hstmtDel
)
2365 if (!hstmtDel
) // Cursor already deleted
2369 ODBC 3.0 says to use this form
2370 if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
2373 if (SQLFreeStmt(*hstmtDel
, SQL_DROP
) != SQL_SUCCESS
)
2375 pDb
->DispAllErrors(henv
, hdbc
);
2383 } // wxDbTable::DeleteCursor()
2385 #endif // wxUSE_ODBC