]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/db.tex
fixed SubString docs
[wxWidgets.git] / docs / latex / wx / db.tex
1 \section{\class{wxDb}}\label{wxdb}
2
3 A wxDb instance is a connection to an ODBC datasource which may
4 be opened, closed, and re-opened an unlimited number of times. A
5 database connection allows function to be performed directly on the
6 datasource, as well as allowing access to any tables/views defined in
7 the datasource to which the user has sufficient privileges.
8
9 \wxheading{Include files}
10
11 <wx/db.h>
12
13 \wxheading{Helper classes and data structures}
14
15 The following classes and structs are defined in db.cpp/.h for use with the wxDb class.
16
17 \begin{itemize}\itemsep=0pt
18 \item \helpref{wxDbColFor}{wxdbcolfor}
19 \item \helpref{wxDbColInf}{wxdbcolinf}
20 \item \helpref{wxDbTableInf}{wxdbtableinf}
21 \item \helpref{wxDbInf}{wxdbinf}
22 \end{itemize}
23
24 \wxheading{Constants}
25
26 NOTE: In a future release, all ODBC class constants will be prefaced with 'wx'
27
28 \begin{verbatim}
29
30 wxDB_PATH_MAX Maximum path length allowed to be passed to
31 the ODBC driver to indicate where the data
32 file(s) are located.
33
34 DB_MAX_COLUMN_NAME_LEN Maximum supported length for the name of a
35 column
36
37 DB_MAX_ERROR_HISTORY Maximum number of error messages retained in
38 the queue before being overwritten by new
39 errors.
40
41 DB_MAX_ERROR_MSG_LEN Maximum supported length of an error message
42 returned by the ODBC classes
43
44 DB_MAX_STATEMENT_LEN Maximum supported length for a complete SQL
45 statement to be passed to the ODBC driver
46
47 DB_MAX_TABLE_NAME_LEN Maximum supported length for the name of a
48 table
49
50 DB_MAX_WHERE_CLAUSE_LEN Maximum supported WHERE clause length that
51 can be passed to the ODBC driver
52
53 DB_TYPE_NAME_LEN Maximum length of the name of a column's
54 data type
55 \end{verbatim}
56
57
58 \subsection{Enumerated types}\label{wxdbenumeratedtypes}
59
60 \docparam{enum {\bf wxDbSqlLogState}}{sqlLogOFF, sqlLogON}
61
62 {\it enum {\bf wxDBMS}}
63
64 These are the databases currently tested and working with the ODBC classes. A call to \helpref{wxDb::Dbms}{wxdbdbms} will return one of these enumerated values listed below.
65
66 \begin{verbatim}
67 dbmsUNIDENTIFIED
68 dbmsORACLE
69 dbmsSYBASE_ASA // Adaptive Server Anywhere
70 dbmsSYBASE_ASE // Adaptive Server Enterprise
71 dbmsMS_SQL_SERVER
72 dbmsMY_SQL
73 dbmsPOSTGRES
74 dbmsACCESS
75 dbmsDBASE
76 dbmsINFORMIX
77 dbmsVIRTUOSO
78 dbmsDB2
79 dbmdINTERBASE
80 \end{verbatim}
81
82 See the remarks in \helpref{wxDb::Dbms}{wxdbdbms} for exceptions/issues with each of these database engines.
83
84 \wxheading{Public member variables}
85
86 \docparam{SWORD {\bf wxDb::cbErrorMsg}}{This member variable is populated as a result of calling \helpref{wxDb::GetNextError}{wxdbgetnexterror}. Contains the count of bytes in the wxDb::errorMsg string.}
87
88 \docparam{int {\bf wxDb::DB\_STATUS}}{The last ODBC error/status that occurred on this data connection. Possible codes are:}
89
90 \begin{verbatim}
91 DB_ERR_GENERAL_WARNING // SqlState = '01000'
92 DB_ERR_DISCONNECT_ERROR // SqlState = '01002'
93 DB_ERR_DATA_TRUNCATED // SqlState = '01004'
94 DB_ERR_PRIV_NOT_REVOKED // SqlState = '01006'
95 DB_ERR_INVALID_CONN_STR_ATTR // SqlState = '01S00'
96 DB_ERR_ERROR_IN_ROW // SqlState = '01S01'
97 DB_ERR_OPTION_VALUE_CHANGED // SqlState = '01S02'
98 DB_ERR_NO_ROWS_UPD_OR_DEL // SqlState = '01S03'
99 DB_ERR_MULTI_ROWS_UPD_OR_DEL // SqlState = '01S04'
100 DB_ERR_WRONG_NO_OF_PARAMS // SqlState = '07001'
101 DB_ERR_DATA_TYPE_ATTR_VIOL // SqlState = '07006'
102 DB_ERR_UNABLE_TO_CONNECT // SqlState = '08001'
103 DB_ERR_CONNECTION_IN_USE // SqlState = '08002'
104 DB_ERR_CONNECTION_NOT_OPEN // SqlState = '08003'
105 DB_ERR_REJECTED_CONNECTION // SqlState = '08004'
106 DB_ERR_CONN_FAIL_IN_TRANS // SqlState = '08007'
107 DB_ERR_COMM_LINK_FAILURE // SqlState = '08S01'
108 DB_ERR_INSERT_VALUE_LIST_MISMATCH // SqlState = '21S01'
109 DB_ERR_DERIVED_TABLE_MISMATCH // SqlState = '21S02'
110 DB_ERR_STRING_RIGHT_TRUNC // SqlState = '22001'
111 DB_ERR_NUMERIC_VALUE_OUT_OF_RNG // SqlState = '22003'
112 DB_ERR_ERROR_IN_ASSIGNMENT // SqlState = '22005'
113 DB_ERR_DATETIME_FLD_OVERFLOW // SqlState = '22008'
114 DB_ERR_DIVIDE_BY_ZERO // SqlState = '22012'
115 DB_ERR_STR_DATA_LENGTH_MISMATCH // SqlState = '22026'
116 DB_ERR_INTEGRITY_CONSTRAINT_VIOL // SqlState = '23000'
117 DB_ERR_INVALID_CURSOR_STATE // SqlState = '24000'
118 DB_ERR_INVALID_TRANS_STATE // SqlState = '25000'
119 DB_ERR_INVALID_AUTH_SPEC // SqlState = '28000'
120 DB_ERR_INVALID_CURSOR_NAME // SqlState = '34000'
121 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL // SqlState = '37000'
122 DB_ERR_DUPLICATE_CURSOR_NAME // SqlState = '3C000'
123 DB_ERR_SERIALIZATION_FAILURE // SqlState = '40001'
124 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2 // SqlState = '42000'
125 DB_ERR_OPERATION_ABORTED // SqlState = '70100'
126 DB_ERR_UNSUPPORTED_FUNCTION // SqlState = 'IM001'
127 DB_ERR_NO_DATA_SOURCE // SqlState = 'IM002'
128 DB_ERR_DRIVER_LOAD_ERROR // SqlState = 'IM003'
129 DB_ERR_SQLALLOCENV_FAILED // SqlState = 'IM004'
130 DB_ERR_SQLALLOCCONNECT_FAILED // SqlState = 'IM005'
131 DB_ERR_SQLSETCONNECTOPTION_FAILED // SqlState = 'IM006'
132 DB_ERR_NO_DATA_SOURCE_DLG_PROHIB // SqlState = 'IM007'
133 DB_ERR_DIALOG_FAILED // SqlState = 'IM008'
134 DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL // SqlState = 'IM009'
135 DB_ERR_DATA_SOURCE_NAME_TOO_LONG // SqlState = 'IM010'
136 DB_ERR_DRIVER_NAME_TOO_LONG // SqlState = 'IM011'
137 DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR // SqlState = 'IM012'
138 DB_ERR_TRACE_FILE_ERROR // SqlState = 'IM013'
139 DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS // SqlState = 'S0001'
140 DB_ERR_TABLE_NOT_FOUND // SqlState = 'S0002'
141 DB_ERR_INDEX_ALREADY_EXISTS // SqlState = 'S0011'
142 DB_ERR_INDEX_NOT_FOUND // SqlState = 'S0012'
143 DB_ERR_COLUMN_ALREADY_EXISTS // SqlState = 'S0021'
144 DB_ERR_COLUMN_NOT_FOUND // SqlState = 'S0022'
145 DB_ERR_NO_DEFAULT_FOR_COLUMN // SqlState = 'S0023'
146 DB_ERR_GENERAL_ERROR // SqlState = 'S1000'
147 DB_ERR_MEMORY_ALLOCATION_FAILURE // SqlState = 'S1001'
148 DB_ERR_INVALID_COLUMN_NUMBER // SqlState = 'S1002'
149 DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE // SqlState = 'S1003'
150 DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE // SqlState = 'S1004'
151 DB_ERR_OPERATION_CANCELLED // SqlState = 'S1008'
152 DB_ERR_INVALID_ARGUMENT_VALUE // SqlState = 'S1009'
153 DB_ERR_FUNCTION_SEQUENCE_ERROR // SqlState = 'S1010'
154 DB_ERR_OPERATION_INVALID_AT_THIS_TIME // SqlState = 'S1011'
155 DB_ERR_INVALID_TRANS_OPERATION_CODE // SqlState = 'S1012'
156 DB_ERR_NO_CURSOR_NAME_AVAIL // SqlState = 'S1015'
157 DB_ERR_INVALID_STR_OR_BUF_LEN // SqlState = 'S1090'
158 DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE // SqlState = 'S1091'
159 DB_ERR_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1092'
160 DB_ERR_INVALID_PARAM_NO // SqlState = 'S1093'
161 DB_ERR_INVALID_SCALE_VALUE // SqlState = 'S1094'
162 DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE // SqlState = 'S1095'
163 DB_ERR_INF_TYPE_OUT_OF_RANGE // SqlState = 'S1096'
164 DB_ERR_COLUMN_TYPE_OUT_OF_RANGE // SqlState = 'S1097'
165 DB_ERR_SCOPE_TYPE_OUT_OF_RANGE // SqlState = 'S1098'
166 DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE // SqlState = 'S1099'
167 DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1100'
168 DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1101'
169 DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE // SqlState = 'S1103'
170 DB_ERR_INVALID_PRECISION_VALUE // SqlState = 'S1104'
171 DB_ERR_INVALID_PARAM_TYPE // SqlState = 'S1105'
172 DB_ERR_FETCH_TYPE_OUT_OF_RANGE // SqlState = 'S1106'
173 DB_ERR_ROW_VALUE_OUT_OF_RANGE // SqlState = 'S1107'
174 DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE // SqlState = 'S1108'
175 DB_ERR_INVALID_CURSOR_POSITION // SqlState = 'S1109'
176 DB_ERR_INVALID_DRIVER_COMPLETION // SqlState = 'S1110'
177 DB_ERR_INVALID_BOOKMARK_VALUE // SqlState = 'S1111'
178 DB_ERR_DRIVER_NOT_CAPABLE // SqlState = 'S1C00'
179 DB_ERR_TIMEOUT_EXPIRED // SqlState = 'S1T00'
180 \end{verbatim}
181
182 \docparam{struct {\bf wxDb::dbInf}}{This structure is internal to the
183 wxDb class and contains details of the ODBC datasource that the current
184 instance of the wxDb is connected to in its members. When the datasource
185 is opened, all of the information contained in the dbInf structure is
186 queried from the datasource. This information is used almost exclusively
187 within the ODBC class library. Where there may be a need for particular
188 portions of this information outside of the class library, member
189 functions (e.g.
190 \helpref{wxDbTable::IsCursorClosedOnCommit}{wxdbtableiscursorclosedoncommit})
191 have been added for ease of use.}
192
193 \begin{verbatim}
194 char dbmsName[40] - Name of the dbms product
195 char dbmsVer[64] - Version # of the dbms product
196 char driverName[40] - Driver name
197 char odbcVer[60] - ODBC version of the driver
198 char drvMgrOdbcVer[60] - ODBC version of the driver manager
199 char driverVer[60] - Driver version
200 char serverName[80] - Server Name, typically a connect string
201 char databaseName[128] - Database filename
202 char outerJoins[2] - Does datasource support outer joins
203 char procedureSupport[2] - Does datasource support stored
204 procedures
205 UWORD maxConnections - Maximum # of connections datasource
206 supports
207 UWORD maxStmts - Maximum # of HSTMTs per HDBC
208 UWORD apiConfLvl - ODBC API conformance level
209 UWORD cliConfLvl - Is datasource SAG compliant
210 UWORD sqlConfLvl - SQL conformance level
211 UWORD cursorCommitBehavior - How cursors are affected on db commit
212 UWORD cursorRollbackBehavior - How cursors are affected on db
213 rollback
214 UWORD supportNotNullClause - Does datasource support NOT NULL
215 clause
216 char supportIEF[2] - Integrity Enhancement Facility (Ref.
217 Integrity)
218 UDWORD txnIsolation - Transaction isolation level supported by
219 driver
220 UDWORD txnIsolationOptions - Transaction isolation level options
221 available
222 UDWORD fetchDirections - Fetch directions supported
223 UDWORD lockTypes - Lock types supported in SQLSetPos
224 UDWORD posOperations - Position operations supported in
225 SQLSetPos
226 UDWORD posStmts - Position statements supported
227 UDWORD scrollConcurrency - Scrollable cursor concurrency options
228 supported
229 UDWORD scrollOptions - Scrollable cursor options supported
230 UDWORD staticSensitivity - Can additions/deletions/updates be
231 detected
232 UWORD txnCapable - Indicates if datasource supports
233 transactions
234 UDWORD loginTimeout - Number seconds to wait for a login
235 request
236 \end{verbatim}
237
238 \docparam{char {\bf wxDb::errorList}[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN]}{The last n ODBC errors that have occurred on this database connection.}
239
240 \docparam{char {\bf wxDb::errorMsg}[SQL_MAX_MESSAGE_LENGTH]}{This member variable is populated as a result of calling \helpref{wxDb::GetNextError}{wxdbgetnexterror}. It contains the ODBC error message text.}
241
242 \docparam{SDWORD {\bf wxDb::nativeError}}{Set by wxDb::DispAllErrors, wxDb::GetNextError, and wxDb::DispNextError. It contains the datasource-specific error code returned by the datasource to the ODBC driver. Used for reporting ODBC errors.}
243
244 \docparam{wxChar {\bf wxDb::sqlState}[20]}{Set by wxDb::TranslateSqlState(). Indicates the error state after a failed ODBC operation. Used for reporting ODBC errors.}
245
246 \wxheading{Remarks}
247
248 Default cursor scrolling is defined by wxODBC_FWD_ONLY_CURSORS in setup.h
249 when the wxWindows library is built. This behavior can be overridden when
250 an instance of a wxDb is created (see \helpref{wxDb constructor}{wxdbconstr}).
251 Default setting of this value TRUE, as not all databases/drivers support
252 both types of cursors.
253
254 \wxheading{See also}
255
256 \helpref{wxDbColFor}{wxdbcolfor}, \helpref{wxDbColInf}{wxdbcolinf}, \helpref{wxDbTable}{wxdbtable}, \helpref{wxDbTableInf}{wxdbtableinf}, \helpref{wxDbInf}{wxdbinf}
257
258 \subsection{Associated non-class functions}\label{wxdbfunctions}
259
260 The following functions are used in conjunction with the wxDb class.
261
262 \func{wxDb *}{wxDbGetConnection}{\param{wxDbConnectInf *}{pDbConfig}, \param{bool }{FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS}}
263
264 \wxheading{Remarks}
265
266 This function is used to request a "new" wxDb instance for use by the program.
267 The wxDb instance returned is also opened (see \helpref{wxDb::Open}{wxdbopen}).
268
269 This function (along with wxDbFreeConnection() and wxDbCloseConnection())
270 maintain a cached of wxDb instances for user/re-use by a program. When a
271 program needs a wxDb instance, it may call this function to obtain a wxDb
272 instance. If there is a wxDb instance in the cache that is currently unused
273 that matches the connection requirements specified in {\it'pDbConfig'} then
274 that cached connection is marked as no longer being free, and a pointer to
275 the wxDb instance is returned.
276
277 If there are no connections available in the cache that meet the requirements
278 given in {\it'pDbConfig'}, then a new wxDb instance is created to connect
279 to the datasource specified in {\it'pDbConfig'} using the userID and password
280 given in {\it'pDbConfig'}.
281
282 NOTE: The caching routine also uses the \helpref{wxDb::Open}{wxdbopen}
283 connection datatype copying code. If the call to wxDbGetConnection()
284 requests a connection to a datasource, and there is not one available in the
285 cache, a new connection is created. But when the connection is opened,
286 instead of polling the datasource over again for its datatypes, if a
287 connection to the same datasource (using the same userID/password) has already
288 been done previously, the new connection skips querying the datasource for
289 its datatypes, and uses the same datatypes determined previously by the
290 other connection(s) for that same datasource. This cuts down greatly on
291 network traffic, database load, and connection creation time.
292
293 When the program is done using a connection created through a call to
294 wxDbGetConnection(), the program shoudl call wxDbFreeConnection() to release
295 the wxDb instance back to the cache. DO NOT DELETE THE wxDb INSTANCE!
296 Deleting the wxDb instance returned can cause a crash/memory corruption
297 later in the program when the cache is cleaned up.
298
299 When exiting the program, call wxDbCloseConnections() to close all the
300 cached connections created by calls to wxDbGetConnection().
301
302
303 \func{bool}{wxDbFreeConnection}{\param{wxDb *}{pDb}}
304
305 \wxheading{Remarks}
306
307 Searches the list of cached database connections connection for one matching
308 the passed in wxDb instance. If found, that cached connection is freed.
309
310 Freeing a connection means that it is marked as available (free) in the
311 cache of connections, so that a call to \helpref{wxDbGetConnection}{wxdbfunctions}
312 is able to return a pointer to the wxDb instance for use. Freeing a
313 connection does NOT close the connection, it only makes the connection
314 available again.
315
316
317 \func{void}{wxDbCloseConnections}{\void}
318
319 \wxheading{Remarks}
320
321 Closes all cached connections that have been made through use of the
322 \helpref{wxDbGetConnection}{wxdbfunctions} function.
323
324 NOTE: These connections are closed regardless of whether they are in use
325 or not. This function should only be called after the program has
326 finished using the connections and all wxDbTable instances that use any of
327 the connections have been closed.
328
329 This function performs a \helpref{wxDb::CommitTrans}{wxdbcommittrans}
330 on the connection before closing it to commit any changes tht are still
331 pending, as well as to avoid any function sequence errors upon closing
332 each connection.
333
334
335 \func{int }{wxDbConnectionsInUse}{\void}
336
337 \wxheading{Remarks}
338
339 Returns a count of how many database connections are currently free ( not
340 being used) that have been cached through use of the \helpref{wxDbGetConnection}{wxdbfunctions}
341 function.
342
343
344 \func{bool}{wxDbSqlLog}{\param{wxDbSqlLogState }{state}, \param{const wxChar *}{filename = SQL_LOG_FILENAME}}
345
346 \wxheading{Remarks}
347
348 This function sets the sql log state for all open wxDb objects
349
350
351 \func{bool}{wxDbGetDataSource}{\param{HENV }{henv}, \param{char *}{Dsn}, \param{SWORD }{DsnMax}, \param{char *}{DsDesc}, \param{SWORD }{DsDescMax}, \param{UWORD }{direction = SQL_FETCH_NEXT}}
352
353 \wxheading{Remarks}
354
355 This routine queries the ODBC driver manager for a list of available
356 datasources. Repeatedly call this function to obtain all the datasources
357 available through the ODBC driver manager on the current workstation.
358
359 wxStringList strList;
360
361 while (wxDbGetDataSource(DbConnectInf.Henv, Dsn, SQL_MAX_DSN_LENGTH+1, DsDesc, 255))
362 strList.Add(Dsn);
363
364
365 \latexignore{\rtfignore{\wxheading{Members}}}
366
367 \membersection{wxDb::wxDb}\label{wxdbconstr}
368
369 \func{}{wxDb}{\void}
370
371 Default constructor.
372
373 \func{}{wxDb}{\param{HENV &}{aHenv}, \param{bool }{FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS}}
374
375 Constructor, used to create an ODBC connection to a datasource.
376
377 \wxheading{Parameters}
378
379 \docparam{aHenv}{Environment handle used for this connection.}
380
381 \docparam{FwdOnlyCursors}{Will cursors created for use with this datasource connection only allow forward scrolling cursors.}
382
383 \wxheading{Remarks}
384
385 This is the constructor for the wxDb class. The wxDb object must
386 be created and opened before any database activity can occur.
387
388 \wxheading{Example}
389
390 \begin{verbatim}
391 wxDbConnectInf ConnectInf;
392 ....Set values for member variables of ConnectInf here
393
394 wxDb sampleDB(ConnectInf.Henv);
395 if (!sampleDB.Open(ConnectInf.Dsn, ConnectInf.Uid, ConnectInf.AuthStr))
396 {
397 // Error opening datasource
398 }
399 \end{verbatim}
400
401 \wxheading{See also}
402
403 \helpref{wxDbGetConnection}{wxdbfunctions},
404
405
406 \membersection{wxDb::Catalog}\label{wxdbcatalog}
407
408 \func{bool}{Catalog}{\param{char *}{ userID}, \param{char *}{fileName = SQL_CATALOG_FILENAME}}
409
410 Allows a data "dictionary" of the datasource to be created, dumping pertinent information about all data tables to which the user specified in userID has access.
411
412 \wxheading{Parameters}
413
414 \docparam{userID}{Database user name to use in accessing the database. All tables to which this user has rights will be evaluated in the catalog.}
415
416 \docparam{fileName}{{\it OPTIONAL}. Name of the text file to create and write
417 the DB catalog to. Default is SQL_CATALOG_FILENAME.}
418
419 \wxheading{Return value}
420
421 Returns TRUE if the catalog request was successful, or FALSE if there was some
422 reason that the catalog could not be generated.
423
424 \wxheading{Example}
425
426 \begin{verbatim}
427 ============== ============== ================ ========= =======
428 TABLE NAME COLUMN NAME DATA TYPE PRECISION LENGTH
429 ============== ============== ================ ========= =======
430 EMPLOYEE RECID (0008)NUMBER 15 8
431 EMPLOYEE USER_ID (0012)VARCHAR2 13 13
432 EMPLOYEE FULL_NAME (0012)VARCHAR2 26 26
433 EMPLOYEE PASSWORD (0012)VARCHAR2 26 26
434 EMPLOYEE START_DATE (0011)DATE 19 16
435 \end{verbatim}
436
437
438 \membersection{wxDb::Close}\label{wxdbclose}
439
440 \func{void}{Close}{\void}
441
442 Closes the database connection.
443
444 \wxheading{Remarks}
445
446 At the end of your program, when you have finished all of your database work, you must close the ODBC connection to the datasource. There are actually four steps involved in doing this as illustrated in the example.
447
448 Any wxDbTable instances which use this connection must be deleted before closing the database connection.
449
450 \wxheading{Example}
451
452 \begin{verbatim}
453 // Commit any open transactions on the datasource
454 sampleDB.CommitTrans();
455
456 // Delete any remaining wxDbTable objects allocated with new
457 delete parts;
458
459 // Close the wxDb connection when finished with it
460 sampleDB.Close();
461
462 // Free Environment Handle that ODBC uses
463 //
464 // Be certain that no wxDb instances still exist
465 // that were created using this handle! If you
466 // use wxDbGetConnection() to get all the wxDb
467 // instances, you can use wxDbConnectionsInUse()
468 // to find out if any connections have not been
469 // closed before calling this
470 if (SQLFreeEnv(Db.Henv) != SQL_SUCCESS)
471 {
472 // Error freeing environment handle
473 }
474 \end{verbatim}
475
476
477 \membersection{wxDb::CommitTrans}\label{wxdbcommittrans}
478
479 \func{bool}{CommitTrans}{\void}
480
481 Permanently "commits" changes (insertions/deletions/updates) to the database.
482
483 \wxheading{Return value}
484
485 Returns TRUE if the commit was successful, or FALSE if the commit failed.
486
487 \wxheading{Remarks}
488
489 Transactions begin implicitly as soon as you make a change to the database
490 with an insert/update/delete, or any other direct SQL command that performs
491 one of these operations against the datasource.
492 At any time thereafter, to save the changes to disk permanently, "commit"
493 them by calling this function.
494
495 Calling this member function commits ALL open transactions on this ODBC
496 connection. For example, if three different wxDbTable instances used the
497 same connection to the datasource, commiting changes made on one of those
498 wxDbTable instances commits any pending transactions on all three wxDbTable
499 instances.
500
501 Until a call to wxDb::CommitTrans() is made, no other user or cursor is able
502 to see any changes made to the row(s) that have been inserted/modifed/deleted.
503
504
505 \wxheading{Special Note : {\it Cursors} }
506
507 \normalbox{It is important to understand that different database/ODBC driver combinations handle
508 transactions differently. One thing in particular that you must pay attention to is
509 cursors, in regard to transactions. Cursors are what allow you to scroll through
510 records forward and backward and to manipulate records as you scroll through them.
511 When you issue a query, a cursor is created behind the scenes. The cursor keeps track
512 of the query and keeps track of the current record pointer. After you commit or
513 rollback a transaction, the cursor may be closed automatically. This is database
514 dependent, and with some databases this behavior can be controlled through
515 management functions. This means you would need to
516 requery the datasource before you can perform any additional work using this
517 cursor. This is only necessary however if the datasource closes the cursor after a
518 commit or rollback. Use the \helpref{wxDbTable::IsCursorClosedOnCommit}{wxdbtableiscursorclosedoncommit} member function to
519 determine the datasource's transaction behavior. Note, in many situations
520 it is very inefficient to assume the cursor is closed and always requery. This could put
521 a significant, unnecessary load on datasources that leave the cursors open after a
522 transaction.}
523
524
525 \membersection{wxDb::CreateView}\label{wxdbcreateviews}
526
527 \func{bool}{CreateView}{\param{char *}{ viewName}, \param{char *}{ colList}, \param{char *}{pSqlStmt}}
528
529 Creates a SQL VIEW of one or more tables in a single datasource. Note that
530 this function will only work against databases which support views (currently
531 only Oracle as of November 21 2000).
532
533 \wxheading{Parameters}
534
535 \docparam{viewName}{The name of the view. e.g. PARTS_V}
536
537 \docparam{colList}{{\it OPTIONAL} Pass in a comma delimited list of column
538 names if you wish to explicitly name each column in the result set. If not
539 desired, pass in an empty string and the column names from the associated
540 table(s) will be used.}
541
542 \docparam{pSqlStmt}{Pointer to the select statement portion of the CREATE VIEW statement. Must be a complete, valid SQL SELECT statement.}
543
544 \wxheading{Remarks}
545
546 A 'view' is a logical table that derives columns from one or more other tables or views. Once the view is created, it can be queried exactly like any other table in the database.
547
548 NOTE: Views are not available with all datasources. Oracle is one example of a datasouce which does support views.
549
550 \wxheading{Example}
551
552 \begin{verbatim}
553 // Incomplete code sample
554 db.CreateView("PARTS_SD1", "PN, PD, QTY",
555 "SELECT PART_NO, PART_DESC, QTY_ON_HAND * 1.1 FROM PARTS \
556 WHERE STORAGE_DEVICE = 1");
557
558 // PARTS_SD1 can now be queried just as if it were a data table.
559 // e.g. SELECT PN, PD, QTY FROM PARTS_SD1
560 \end{verbatim}
561
562
563 \membersection{wxDb::Dbms}\label{wxdbdbms}
564
565 \func{wxDBMS }{Dbms}{\void}
566
567 \wxheading{Remarks}
568
569 The return value will be of the enumerated type wxDBMS. This enumerated
570 type contains a list of all the currently tested and supported databases.
571
572 Additional databases may work with these classes, but the databases
573 returned by this function have been tested and confirmed to work with
574 these ODBC classes.
575
576 Possible values returned by this function can be viewed in the
577 \helpref{Enumerated types}{wxdbenumeratedtypes} section of wxDb.
578
579 There are known issues with conformance to the ODBC standards with several
580 datasources supported by the wxWindows ODBC classes. Please see the overview
581 for specific details on which datasource have which issues.
582
583 \wxheading{Return value}
584
585 The return value will indicate which of the supported datasources is
586 currently connected to by this connection. In the event that the
587 datasource is not recognized, a value of 'dbmsUNIDENTIFIED' is returned.
588
589
590 \membersection{wxDb::DispAllErrors}\label{wxdbdispallerrors}
591
592 \func{bool}{DispAllErrors}{\param{HENV}{ aHenv}, {\param}{HDBC}{ aHdbc = SQL_NULL_HDBC}, {\param}{HSTMT}{ aHstmt = SQL_NULL_HSTMT}}
593
594 Used to log all database errors that occurred as a result of an executed
595 database command. This logging is automatic and also includes debug logging
596 when compiled in debug mode via \helpref{wxLogDebug}{wxlogdebug}. If logging
597 is turned on via \helpref{wxDb::SetSqlLogging}{wxdbsetsqllogging}, then an
598 entry is also logged to the defined log file.
599
600 \wxheading{Parameters}
601
602 \docparam{aHenv}{Handle to the ODBC environment.}
603
604 \docparam{aHdbc}{Handle to the ODBC connection. Pass this in if the ODBC function call that erred required a hdbc or hstmt argument.}
605
606 \docparam{AHstmt}{Handle to the ODBC statement being executed against. Pass this in if the ODBC function call that erred out required a hstmt argument.}
607
608 \wxheading{Remarks}
609
610 This member function will log all of the ODBC error messages for the last
611 ODBC function call that was made. This function is normally used internally
612 within the ODBC class library, but can be used programmatically after calling
613 ODBC functions directly (i.e. SQLFreeEnv()).
614
615 \wxheading{Return value}
616
617 The function always returns FALSE, so a call to this function can be made
618 in the return statement of a code block in the event of a failure to
619 perform an action (see the example below).
620
621 \wxheading{See also}
622
623 \helpref{wxDb::SetSqlLogging}{wxdbsetsqllogging}, wxDbSqlLog
624
625 \wxheading{Example}
626
627 \begin{verbatim}
628 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
629 // Display all ODBC errors for this stmt
630 return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
631 \end{verbatim}
632
633
634 \membersection{wxDb::DispNextError}\label{wxdbdispnexterror}
635
636 \func{void}{DispNextError}{\void}
637
638 \wxheading{Remarks}
639
640 This function is normally used internally within the ODBC class library.
641 It could be used programmatically after calling ODBC functions directly. This
642 function works in conjunction with \helpref{wxDb::GetNextError}{wxdbgetnexterror} when errors (or
643 sometimes informational messages) returned from ODBC need to be analyzed
644 rather than simply displaying them as an error. GetNextError() retrieves
645 the next ODBC error from the ODBC error queue. The wxDb member variables
646 "sqlState", "nativeError" and "errorMsg" could then be evaluated. To
647 display the error retrieved, DispNextError() could then be called.
648 The combination of GetNextError() and DispNextError() can be used to
649 iteratively step through the errors returned from ODBC evaluating each
650 one in context and displaying the ones you choose.
651
652 \wxheading{Example}
653
654 \begin{verbatim}
655 // Drop the table before attempting to create it
656 sprintf(sqlStmt, "DROP TABLE %s", tableName);
657 // Execute the drop table statement
658 if (SQLExecDirect(hstmt,(UCHAR FAR *)sqlStmt,SQL_NTS) != SQL_SUCCESS)
659 {
660 // Check for sqlState = S0002, "Table or view not found".
661 // Ignore this error, bomb out on any other error.
662 pDb->GetNextError(henv, hdbc, hstmt);
663 if (strcmp(pDb->sqlState, "S0002"))
664 {
665 pDb->DispNextError(); // Displayed error retrieved
666 pDb->DispAllErrors(henv, hdbc, hstmt); // Display all other errors, if any
667 pDb->RollbackTrans(); // Rollback the transaction
668 CloseCursor(); // Close the cursor
669 return(FALSE); // Return Failure
670 }
671 }
672 \end{verbatim}
673
674
675 \membersection{wxDb::DropView}\label{wxdbdropview}
676
677 \func{bool}{DropView}{\param{const char *}{viewName}}
678
679 Drops the data table view named in 'viewName'.
680
681 \wxheading{Parameters}
682
683 \docparam{viewName}{Name of the view to be dropped.}
684
685 \wxheading{Remarks}
686
687 If the view does not exist, this function will return TRUE. Note that views are not supported with all datasources.
688
689 \membersection{wxDb::ExecSql}\label{wxdbexecsql}
690
691 \func{bool}{ExecSql}{\param{char *}{pSqlStmt}}
692
693 Allows a native SQL command to be executed directly against the datasource. In addition to being able to run any standard SQL command, use of this function allows a user to (potentially) utilize features specific to the datasource they are connected to that may not be available through ODBC. The ODBC driver will pass the specified command directly to the datasource.
694
695 \wxheading{Parameters}
696
697 \docparam{pSqlStmt}{Pointer to the SQL statement to be executed.}
698
699 \wxheading{Remarks}
700
701 This member extends the wxDb class and allows you to build and execute ANY VALID
702 SQL statement against the datasource. This allows you to extend the class
703 library by being able to issue any SQL statement that the datasource is capable
704 of processing.
705
706 \wxheading{See also}
707
708 \helpref{wxDb::GetData}{wxdbgetdata}, \helpref{wxDb::GetNext}{wxdbgetnext}
709
710
711 \membersection{wxDb::GetCatalog}\label{wxdbgetcatalog}
712
713 \func{wxDbInf *}{GetCatalog}{\param{char *}{userID}}
714
715 Returns a \helpref{wxDbInf}{wxdbinf} pointer that points to the catalog
716 (datasource) name, schema, number of tables accessible to the current user,
717 and a wxDbTableInf pointer to all data pertaining to all tables in the users
718 catalog.
719
720 \wxheading{Parameters}
721
722 \docparam{userID}{Owner/Schema of the table. Specify a userID when the datasource you are connected to allows multiple unique tables with the same name to be owned by different users. {\it userID} is evaluated as follows:}
723
724 \begin{verbatim}
725 userID == NULL ... UserID is ignored (DEFAULT)
726 userID == "" ... UserID set equal to 'this->uid'
727 userID != "" ... UserID set equal to 'userID'
728 \end{verbatim}
729
730 \wxheading{Remarks}
731
732 The returned catalog will only contain catalog entries for tables to which the user specified in 'userID' has sufficient privileges. If no user is specified (NULL passed in), a catalog pertaining to all tables in the datasource accessible to the connected user (permissions apply) via this connection will be returned.
733
734 \membersection{wxDb::GetColumnCount}\label{wxdbgetcolumncount}
735
736 \func{int }{GetColumnCount}{\param{char *}{tableName}, \param{const char *}{userID}}
737
738 \wxheading{Parameters}
739
740 \docparam{tableName}{The table name you wish to obtain column information about.}
741
742 \docparam{userID}{Name of the user that owns the table(s) (also referred to as schema). Required for some datasources for situations where there may be multiple tables with the same name in the datasource, but owned by different users. {\it userID} is evaluated in the following manner:}
743
744 \begin{verbatim}
745 userID == NULL ... UserID is ignored (DEFAULT)
746 userID == "" ... UserID set equal to 'this->uid'
747 userID != "" ... UserID set equal to 'userID'
748 \end{verbatim}
749
750 \wxheading{Return value}
751
752 Returns a count of how many columns are in the specified table. If an error
753 occurs retrieving the number of columns, this function will return a -1.
754
755 \membersection{wxDb::GetColumns}\label{wxdbgetcolumns}
756
757 \func{wxDbColInf *}{GetColumns}{\param{char *}{tableName}, \param{int *}{numCols}, \param{const char *}{userID=NULL}}
758
759 \func{wxDbColInf *}{GetColumns}{\param{char *}{tableName[]}, \param{const char *}{userID}}
760
761 \wxheading{Parameters}
762
763 \docparam{tableName}{The table name you wish to obtain column information about.}
764 \docparam{numCols}{Pointer to an integer which will hold a count of the number of columns returned by this function}
765 \docparam{tableName[]}{An array of pointers to table names you wish to obtain column information about. The last element of this array must be a NULL string.}
766 \docparam{userID}{Name of the user that owns the table(s) (also referred to as schema). Required for some datasources for situations where there may be multiple tables with the same name in the datasource, but owned by different users. {\it userID} is evaluated in the following manner:}
767
768 \begin{verbatim}
769 userID == NULL ... UserID is ignored (DEFAULT)
770 userID == "" ... UserID set equal to 'this->uid'
771 userID != "" ... UserID set equal to 'userID'
772 \end{verbatim}
773
774 \wxheading{Return value}
775
776 This function returns a pointer to an array of \helpref{wxDbColInf}{wxdbcolinf}
777 structures, allowing you to obtain information regarding the columns of the
778 named table(s). If no columns were found, or an error occurred, this pointer
779 will be NULL.
780
781 THE CALLING FUNCTION IS RESPONSIBLE FOR DELETING THE {\it wxDbColInf} MEMORY WHEN IT IS
782 FINISHED WITH IT.
783
784 \normalbox{ALL column bindings associated with this wxDb instance are unbound
785 by this function, including those used by any wxDbTable instances that use
786 this wxDb instance. This function should use its own wxDb instance
787 to avoid undesired unbinding of columns.}
788
789 \wxheading{See also}
790
791 \helpref{wxDbColInf}{wxdbcolinf}
792
793 \wxheading{Example}
794
795 \begin{verbatim}
796 char *tableList[] = {"PARTS", 0};
797 wxDbColInf *colInf = pDb->GetColumns(tableList);
798 if (colInf)
799 {
800 // Use the column inf
801 .......
802 // Destroy the memory
803 delete [] colInf;
804 }
805 \end{verbatim}
806
807
808 \membersection{wxDb::GetData}\label{wxdbgetdata}
809
810 \func{bool}{GetData}{\param{UWORD}{ colNo}, \param{SWORD}{ cType}, \param{PTR}{ pData}, \param{SDWORD}{ maxLen}, \param{SDWORD FAR *}{ cbReturned} }
811
812 Used to retrieve result set data without binding column values to memory variables (i.e. not using a wxDbTable instance to access table data).
813
814 \wxheading{Parameters}
815
816 \docparam{colNo}{Ordinal number of the desired column in the result set to be returned.}
817 \docparam{cType}{The C data type that is to be returned. See a partial list in \helpref{wxDbTable::SetColDefs}{wxdbtablesetcoldefs}}
818 \docparam{pData}{Memory buffer which will hold the data returned by the call to this function.}
819 \docparam{maxLen}{Maximum size of the buffer {\it 'pData'} in characters. NOTE: Not UNICODE safe. If this is a numeric field, a value of 0 may be passed for this parameter, as the API knows the size of the expected return value.}
820 \docparam{cbReturned}{Pointer to the buffer containing the length of the actual data returned. If this value comes back as SQL_NULL_DATA, then the wxDb::GetData() call has failed.}
821
822 \wxheading{See also}
823
824 \helpref{wxDb::GetNext}{wxdbgetnext}, \helpref{wxDb::ExecSql}{wxdbexecsql}
825
826 \wxheading{Example}
827
828 \begin{verbatim}
829 SDWORD cb;
830 ULONG reqQty;
831 wxString sqlStmt;
832 sqlStmt = "SELECT SUM(REQUIRED_QTY - PICKED_QTY) FROM ORDER_TABLE WHERE \
833 PART_RECID = 1450 AND REQUIRED_QTY > PICKED_QTY";
834
835 // Perform the query
836 if (!pDb->ExecSql(sqlStmt.c_str()))
837 {
838 // ERROR
839 return(0);
840 }
841
842 // Request the first row of the result set
843 if (!pDb->GetNext())
844 {
845 // ERROR
846 return(0);
847 }
848
849 // Read column #1 of the row returned by the call to ::GetNext()
850 // and return the value in 'reqQty'
851 if (!pDb->GetData(1, SQL_C_ULONG, &reqQty, 0, &cb))
852 {
853 // ERROR
854 return(0);
855 }
856
857 // Check for a NULL result
858 if (cb == SQL_NULL_DATA)
859 return(0);
860 \end{verbatim}
861
862 \wxheading{Remarks}
863
864 When requesting multiple columns to be returned from the result set (for example, the SQL query
865 requested 3 columns be returned), the calls to this function must request the columns in ordinal
866 sequence (1,2,3 or 1,3 or 2,3).
867
868 \membersection{wxDb::GetDatabaseName}\label{wxdbgetdatabasename}
869
870 \func{const char *}{GetDatabaseName}{\void}
871
872 Returns the name of the database engine.
873
874 \membersection{wxDb::GetDatasourceName}\label{wxdbgetdatasourcename}
875
876 \func{const char *}{GetDatasourceName}{\void}
877
878 Returns the ODBC datasource name.
879
880 \membersection{wxDb::GetHDBC}\label{wxdbgethdbc}
881
882 \func{HDBC}{GetHDBC}{\void}
883
884 Returns the ODBC handle to the database connection.
885
886 \membersection{wxDb::GetHENV}\label{wxdbgethenv}
887
888 \func{HENV}{GetHENV}{\void}
889
890 Returns the ODBC environment handle.
891
892 \membersection{wxDb::GetHSTMT}\label{wxdbgethstmt}
893
894 \func{HSTMT}{GetHSTMT}{\void}
895
896 Returns the ODBC statement handle associated with this database connection.
897
898 \membersection{wxDb::GetKeyFields}\label{wxdbgetkeyfields}
899
900 \func{int }{GetKeyFields}{\param{char *}{tableName}, \param{wxDbColInf *}{colInf}, \param{int }{nocols}}
901
902 Used to determine which columns are members of primary or non-primary indexes on the specified table. If a column is a member of a foreign key for some other table, that information is detected also.
903
904 This function is primarily for use by the \helpref{wxDb::GetColumns}{wxdbgetcolumns} function, but may be called if desired from the client application.
905
906 \wxheading{Parameters}
907
908 \docparam{tableName}{Name of the table for which the columns will be evaluated as to their inclusion in any indexes.}
909 \docparam{colInf}{Data structure containing the column definitions (obtained with \helpref{wxDb::GetColumns}{wxdbgetcolumns}). This function populates the PkCol, PkTableName, and FkTableName members of the colInf structure.}
910 \docparam{nocols}{Number of columns defined in the instance of colInf.}
911
912 \wxheading{Return value}
913
914 Currently always returns TRUE.
915
916 \wxheading{See also}
917
918 \helpref{wxDbColInf}{wxdbcolinf}, \helpref{wxDb::GetColumns}{wxdbgetcolumns}
919
920 \membersection{wxDb::GetNext}\label{wxdbgetnext}
921
922 \func{bool}{GetNext}{\void}
923
924 Called after executing a query, this function requests the next row
925 in the result set after the current position of the cursor.
926
927 \wxheading{See also}
928
929 \helpref{wxDb::ExecSql}{wxdbexecsql}, \helpref{wxDb::GetData}{wxdbgetdata}
930
931 \membersection{wxDb::GetNextError}\label{wxdbgetnexterror}
932
933 \func{bool}{GetNextError}{\param{HENV}{ aHenv}, \param{HDBC}{ aHdbc = SQL_NULL_HDBC}, \param{HSTMT}{ aHstmt = SQL_NULL_HSTMT}}
934
935 \wxheading{Parameters}
936
937 \docparam{aHenv}{A handle to the ODBC environment.}
938 \docparam{aHdbc}{{\it OPTIONAL.} A handle to the ODBC connection. Pass this in if the ODBC function call that
939 erred out required a hdbc or hstmt argument.}
940 \docparam{AHstmt}{{\it OPTIONAL.}A handle to the ODBC statement being executed against. Pass this in if the
941 ODBC function call that erred out requires a hstmt argument.}
942
943 \wxheading{See also}
944
945 \helpref{wxDb::DispNextError}{wxdbdispnexterror}, \helpref{wxDb::DispAllErrors}{wxdbdispallerrors}
946
947 \wxheading{Example}
948
949 \begin{verbatim}
950 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
951 {
952 // Display all ODBC errors for this stmt
953 return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
954 }
955 \end{verbatim}
956
957
958 \membersection{wxDb::GetPassword}\label{wxdbgetpassword}
959
960 \func{const char *}{GetPassword}{\void}
961
962 Returns the password used to establish this connection to the datasource.
963
964
965 \membersection{wxDb::GetTableCount}\label{wxdbgettablecount}
966
967 \func{int }{GetTableCount}{\void}
968
969 Returns the number of wxDbTable() instances currently using this datasource connection.
970
971
972 \membersection{wxDb::GetUsername}\label{wxdbgetusername}
973
974 \func{const char *}{GetUsername}{\void}
975
976 Returns the user name (uid) used to establish this connection to the datasource.
977
978
979 \membersection{wxDb::Grant}\label{wxdbgrant}
980
981 \func{bool}{Grant}{\param{int }{privileges}, \param{char *}{tableName}, \param{char *}{userList = "PUBLIC"}}
982
983 Use this member function to GRANT privileges to users for accessing tables in the datasource.
984
985 \wxheading{Parameters}
986
987 \docparam{privileges}{Use this argument to select which privileges you want to grant. Pass DB_GRANT_ALL to grant all privileges. To grant individual privileges pass one or more of the following OR'd together:}
988
989 \begin{verbatim}
990 DB_GRANT_SELECT = 1
991 DB_GRANT_INSERT = 2
992 DB_GRANT_UPDATE = 4
993 DB_GRANT_DELETE = 8
994 DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT |
995 DB_GRANT_UPDATE | DB_GRANT_DELETE
996 \end{verbatim}
997
998 \docparam{tableName}{The name of the table you wish to grant privileges on.}
999 \docparam{userList}{{\it OPTIONAL.} A comma delimited list of users to grant the privileges to. If this argument is not passed in, the privileges will be given to the general PUBLIC.}
1000
1001 \wxheading{Remarks}
1002
1003 Some databases require user names to be specified in all capital letters (i.e. Oracle). This function does not automatically capitalize the user names passed in the comma-separated list. This is the responsibility of the calling routine.
1004
1005 The currently logged in user must have sufficient grantor privileges for this
1006 function to be able to successfully grant the indicated privileges.
1007
1008 \wxheading{Example}
1009
1010 \begin{verbatim}
1011 db.Grant(DB_GRANT_SELECT | DB_GRANT_INSERT, "PARTS", "mary, sue");
1012 \end{verbatim}
1013
1014
1015 \membersection{wxDb::IsFwdOnlyCursors}\label{wxdbisfwdonlycursors}
1016
1017 \func{bool}{IsFwdOnlyCursors}{\void}
1018
1019 This setting indicates whether this database connection was created
1020 as being capable of using only forward scrolling cursors.
1021
1022 This function does NOT indicate if the ODBC driver or datasource supports
1023 backward scrolling cursors. There is no standard way of detecting if the
1024 driver or datasource can support backward scrolling cursors.
1025
1026 If a wxDb instance was created as being capable of only forward scrolling
1027 cursors, then even if the datasource and ODBC driver support backward
1028 scrolling cursors, tables using this database connection would only be able
1029 to use forward scrolling cursors.
1030
1031 The default setting of whether a wxDb connection to a database allows
1032 forward-only or also backward scrolling cursors is defined in setup.h by the
1033 value of wxODBC_FWD_ONLY_CURSORS. This default setting can be overridden
1034 when the wxDb connection is initially created (see
1035 \helpref{wxDb constructor}{wxdbconstr} and \helpref{wxDbGetConnection}{wxdbfunctions}).
1036
1037 \wxheading{Return value}
1038
1039 Returns TRUE if this datasource connection is defined as using only forward
1040 scrolling cursors, or FALSE if the connection is defined as being allowed to
1041 use backward scrolling cursors and their associated functions (see note above).
1042
1043 \wxheading{Remarks}
1044
1045 Added as of wxWindows v2.4 release, this function is a renamed version of
1046 wxDb::FwdOnlyCursors() to match the normal wxWindows naming conventions for
1047 class member functions.
1048
1049 This function is not available in versions prior to v2.4. You should
1050 use \helpref{wxDb::FwdOnlyCursors}{wxdbfwdonlycursors} for wxWindows
1051 versions prior to 2.4.
1052
1053 \wxheading{See also}
1054
1055 \helpref{wxDb constructor}{wxdbconstr}, \helpref{wxDbGetConnection}{wxdbfunctions}
1056
1057
1058 \membersection{wxDb::IsOpen}\label{wxdbisopen}
1059
1060 \func{bool}{IsOpen}{\void}
1061
1062 Indicates whether the database connection to the datasource is currently
1063 opened.
1064
1065 \wxheading{Remarks}
1066
1067 This function may indicate that the database connection is open, even if
1068 the call to \helpref{wxDb::Open}{wxdbopen} may have failed to fully
1069 initialize the connection correctly. The connection to the database
1070 {\it is} open and can be used via the direct SQL commands, if this
1071 function returns TRUE. Other functions which depend on the
1072 \helpref{wxDb::Open}{wxdbopen} to have completed correctly may not function
1073 as expected. The return result from \helpref{wxDb::Open}{wxdbopen} is the
1074 only way to know if complete initialization of this wxDb connection was
1075 successful or not. See \helpref{wxDb::Open}{wxdbopen} for more details on
1076 partial failures to open a connection instance.
1077
1078
1079 \membersection{wxDb::LogError}\label{wxdblogerror}
1080
1081 \func{void}{LogError}{\param{const char *}{errMsg} \param{const char *}{SQLState=NULL}}
1082
1083 \docparam{errMsg}{Free-form text to display describing the error/text to be logged.}
1084 \docparam{SQLState}{{\it OPTIONAL.} Native SQL state error. Default is 0.}
1085
1086 \wxheading{Remarks}
1087
1088 Calling this function will enter a log message in the error list maintained
1089 for the database connection. This log message is free form and can be
1090 anything the programmer wants to enter in the error list.
1091
1092 If SQL logging is turned on, the call to this function will also log the
1093 text into the SQL log file.
1094
1095 \wxheading{See also}
1096
1097 \helpref{wxDb::WriteSqlLog}{wxdbwritesqllog}
1098
1099
1100 \membersection{wxDb::Open}\label{wxdbopen}
1101
1102 \func{bool}{Open}{\param{char *}{Dsn}, \param{char *}{Uid}, \param{char *}{AuthStr}}
1103
1104 \func{bool}{Open}{\param{wxDb *}{copyDb}}
1105
1106 Opens a connection to the datasource, sets certain behaviors of the datasource
1107 to confirm to the accepted behaviors (e.g. cursor position maintained on
1108 commits), and queries the datasource for its representations of the basic
1109 datatypes to determine the form in which the data going to/from columns in
1110 the data tables are to be handled.
1111
1112 The second form of this function, which accepts a "wxDb *" as a parameter,
1113 can be used to avoid the overhead (execution time, database load, network
1114 traffic) which are needed to determine the data types and representations
1115 of data that are necessary for cross-datasource support by these classes.
1116
1117 Normally the first form of the wxDb::Open() function will open the connection
1118 and then send a series of queries to the datasource asking it for its
1119 representation of data types, and all the features it supports. If one
1120 connection to the datasource has already been made previously, the information
1121 gathered when that connection was created can just be copied to any new
1122 connections to the same datasource by passing a pointer to the first
1123 connection in as a parameter to the wxDb::Open() function. Note that this
1124 new connection created from the first connections information will use the
1125 same Dsn/Uid/AuthStr as the first connection used.
1126
1127 \wxheading{Parameters}
1128
1129 \docparam{Dsn}{datasource name. The name of the ODBC datasource as
1130 assigned when the datasource is initially set up through the ODBC data
1131 source manager.}
1132 \docparam{Uid}{User ID. The name (ID) of the user you wish to connect as
1133 to the datasource. The user name (ID) determines what objects you
1134 have access to in the datasource and what datasource privileges you have.
1135 Privileges include being able to create new objects, update objects, delete
1136 objects and so on. Users and privileges are normally administered by the
1137 database administrator.}
1138 \docparam{AuthStr}{The password associated with the Uid.}
1139 \docparam{copyDb}{Already completely configured and opened datasource connection
1140 from which all Dsn, Uid, AuthStr, and data typing information is to be copied
1141 from for use by this datasource connection.}
1142
1143 \wxheading{Remarks}
1144
1145 After a wxDb instance is created, it must then be opened. When opening a
1146 datasource, there must be three pieces of information passed. The data
1147 source name, user name (ID) and the password for the user. No database
1148 activity on the datasource can be performed until the connection is opened.
1149 This is normally done at program startup and the datasource remains
1150 open for the duration of the program/module run.
1151
1152 It is possible to have connections to multiple datasources open at the same
1153 time to support distributed database connections by having separate instances
1154 of wxDb objects that use either the same or different Dsn/Uid/AuthStr settings.
1155
1156 If this function returns a value of FALSE, it does not necessarily mean that
1157 the connection to the datasource was not opened. It may mean that some
1158 portion of the initialization of the connection failed (such as a datatype not
1159 being able to be determined how the datasource represents it). To determine
1160 if the connection to the database failed, use the \helpref{wxDb::IsOpen}{wxdbisopen}
1161 function after receiving a FALSE result back from this function to determine if
1162 the connection was opened or not. If this function returns FALSE, but \helpref{wxDb::IsOpen}{wxdbisopen}
1163 returns TRUE, then direct SQL commands may be passed to the database
1164 connection and can be successfully executed, but use of the datatypes (such as
1165 by a wxDbTable instance) that are normally determined during open will not be
1166 possible.
1167
1168 \normalbox{The {\it Dsn}, {\it Uid}, and {\it AuthStr} string pointers that are passed in
1169 are copied. NOT the strings themselves, only the pointers. The calling routine
1170 must maintain the memory for these three strings for the life of the wxDb instance.}
1171
1172 \wxheading{Example}
1173
1174 \begin{verbatim}
1175 wxDb sampleDB(Db.Henv);
1176 if (!sampleDB.Open("Oracle 7.1 HP/UX", "gtasker", "myPassword"))
1177 {
1178 if (sampleDb.IsOpen())
1179 {
1180 // Connection is open, but the initialization of
1181 // datatypes and parameter settings failed
1182 }
1183 else
1184 {
1185 // Error opening datasource
1186 }
1187 }
1188 \end{verbatim}
1189
1190
1191 \membersection{wxDb::RollbackTrans}\label{wxdbrollbacktrans}
1192
1193 \func{bool}{RollbackTrans}{\void}
1194
1195 Function to "undo" changes made to the database. After an insert/update/delete, the operation may be "undone" by issuing this command any time before a \helpref{wxDb::CommitTrans}{wxdbcommittrans} is called on the database connection.
1196
1197 \wxheading{Remarks}
1198
1199 Transactions begin implicitly as soon as you make a change to the database. The
1200 transaction continues until either a commit or rollback is executed. Calling
1201 wxDb::RollbackTrans() will result in ALL changes done using this database
1202 connection that have not already been committed to be "undone" back to the last
1203 commit/rollback that was successfully executed.
1204
1205 \normalbox{Calling this member function rolls back ALL open (uncommitted)
1206 transactions on this ODBC connection, including all wxDbTable instances that
1207 use this connection.}
1208
1209 \wxheading{See also}
1210
1211 \helpref{wxDb::CommitTrans}{wxdbcommittrans} for a special note on cursors
1212
1213
1214 \membersection{wxDb::SetDebugErrorMessages}\label{wxdbsetdebugerrormessages}
1215
1216 \func{void}{SetDebugErrorMessages}{\param{bool }{state}}
1217
1218 \docparam{state}{Either TRUE (debug messages are logged) or FALSE (debug
1219 messages are not logged.}
1220
1221 \wxheading{Remarks}
1222
1223 Turns on/off debug error messages from the ODBC class library. When
1224 this function is passed TRUE, errors are reported to the user/logged automatically
1225 in a text or pop-up dialog when an ODBC error occurs. When passed FALSE,
1226 errors are silently handled.
1227
1228 When compiled in release mode (FINAL=1), this setting has no affect.
1229
1230 \wxheading{See also}
1231
1232 \helpref{wxDb constructor}{wxdbconstr}
1233
1234
1235 \membersection{wxDb::SetSqlLogging}\label{wxdbsetsqllogging}
1236
1237 \func{bool}{SetSqlLogging}{\param{wxDbSqlLogState}{ state}, \param{const wxChar *}{filename = SQL_LOG_FILENAME}, \param{bool }{ append = FALSE}}
1238
1239 \wxheading{Parameters}
1240
1241 \docparam{state}{Either sqlLogOFF or sqlLogON (see \helpref{enum wxDbSqlLogState}{wxdbcolfor}). Turns logging of SQL commands sent to the datasource OFF or ON.}
1242 \docparam{filename}{{\it OPTIONAL}. Name of the file to which the log text is to be written. Default is SQL_LOG_FILENAME.}
1243 \docparam{append}{{\it OPTIONAL}. Whether the file is appended to or overwritten. Default is FALSE.}
1244
1245 \wxheading{Remarks}
1246
1247 When called with {\it sqlLogON}, all commands sent to the datasource engine are logged to the file specified by {\it filename}. Logging is done by embedded riteSqlLog() calls in the database member functions, or may be manually logged by adding calls to \helpref{wxDb::WriteSqlLog}{wxdbwritesqllog} in your own source code.
1248
1249 When called with {\it sqlLogOFF}, the logging file is closed, and any calls to \helpref{wxDb::WriteSqlLog}{wxdbwritesqllog} are ignored.
1250
1251
1252 \membersection{wxDb::TableExists}\label{wxdbtableexists}
1253
1254 \func{bool}{TableExists}{\param{const char *}{tableName}, \param{const char *}{userID=NULL}, \param{const char *}{path=NULL}}
1255
1256 Checks the ODBC datasource for the existence of a table. If a {\it userID}
1257 is specified, then the table must be accessible by that user (user must have
1258 at least minimal privileges to the table).
1259
1260 \wxheading{Parameters}
1261
1262 \docparam{tableName}{Name of the table to check for the existence of.}
1263 \docparam{userID}{Owner of the table (also referred to as schema). Specify a userID when the datasource you are connected
1264 to allows multiple unique tables with the same name to be owned by different users. {\it userID}
1265 is evaluated as follows:}
1266
1267 \begin{verbatim}
1268 userID == NULL ... UserID is ignored (DEFAULT)
1269 userID == "" ... UserID set equal to 'this->uid'
1270 userID != "" ... UserID set equal to 'userID'
1271 \end{verbatim}
1272
1273 \wxheading{Remarks}
1274
1275 {\it tableName} may refer to a table, view, alias or synonym.
1276
1277 This function does not indicate whether or not the user has privileges to query or perform other functions on the table. Use the \helpref{wxDb::TablePrivileges}{wxdbtableprivileges} to determine if the user has sufficient privileges or not.
1278
1279 \wxheading{See also}
1280
1281 \helpref{wxDb::TablePrivileges}{wxdbtableprivileges}
1282
1283
1284 \membersection{wxDb::TablePrivileges}\label{wxdbtableprivileges}
1285
1286 \func{bool}{TablePrivileges}{\param{const char *}{tableName}, \param{const char *}{priv}, \param{const char *}{userID=""}, \param{const char *}{schema=NULL}, \param{const char *}{path=""}}
1287
1288 Checks the ODBC datasource for the existence of a table. If a {\it userID}
1289 is specified, then the table must be accessible by that user (user must have
1290 at least minimal privileges to the table).
1291
1292 \wxheading{Parameters}
1293
1294 \docparam{tableName}{Name of the table on which to check privileges.
1295 {\it tableName} may refer to a table, view, alias or synonym.}
1296 \docparam{priv}{The table privilege being evaluated. May be one of the
1297 following (or a datasource specific privilege):}
1298
1299 \begin{verbatim}
1300 SELECT : The connected user is permitted to retrieve data for
1301 one or more columns of the table.
1302
1303 INSERT : The connected user is permitted to insert new rows
1304 containing data for one or more columns into the
1305 table.
1306
1307 UPDATE : The connected user is permitted to update the data in
1308 one or more columns of the table.
1309
1310 DELETE : The connected user is permitted to delete rows of
1311 data from the table.
1312
1313 REFERENCES : Is the connected user permitted to refer to one or
1314 more columns of the table within a constraint (for
1315 example, a unique, referential, or table check
1316 constraint).
1317 \end{verbatim}
1318 \docparam{userID}{{\it OPTIONAL.} User for which to determine if the privilege
1319 specified to be checked is granted or not. Default is "".
1320 {\it userID} is evaluated as follows:
1321
1322 \begin{verbatim}
1323 userID == NULL ... NOT ALLOWED!
1324 userID == "" ... UserID set equal to 'this->uid'
1325 userID != "" ... UserID set equal to 'userID'
1326 \end{verbatim}
1327 }
1328 \docparam{schema}{{\it OPTIONAL.} Owner of the table. Specify a userID when the datasource
1329 you are connected to allows multiple unique tables with the same name to be
1330 owned by different users. Specifying the table owner makes determination of the
1331 users privileges MUCH faster. Default is NULL. {\it userID} is evaluated as follows:
1332
1333 \begin{verbatim}
1334 schema == NULL ... Any owner (DEFAULT)
1335 schema == "" ... Owned by 'this->uid'
1336 schema != "" ... Owned by userID specified in 'schema'
1337 \end{verbatim}
1338 }
1339 \docparam{path}{{\it OPTIONAL.} Path to the table. Default is "".
1340 Currently unused.}
1341
1342 \wxheading{Remarks}
1343
1344 The scope of privilege allowed to the connected user by a given table
1345 privilege is datasource dependent.
1346
1347 For example, the privilege UPDATE might allow the connected user to update
1348 all columns in a table on one datasource, but only those columns for
1349 which the grantor (the user that granted the connected user) has the UPDATE
1350 privilege on another datasource.
1351
1352 Looking up a user's privileges to a table can be time consuming depending on the
1353 datasource and ODBC driver. This time can be minimized by passing a {\it schema}
1354 as a parameter. With some datasources/drivers, the difference can be several
1355 seconds of time difference.
1356
1357
1358 \membersection{wxDb::TranslateSqlState}\label{wxdbtranslatesqlstate}
1359
1360 \func{int }{TranslateSqlState}{\param{const wxChar *}{SQLState}}
1361
1362 Converts an ODBC sqlstate to an internal error code.
1363
1364 \wxheading{Parameters}
1365
1366 \docparam{SQLState}{State to be converted.}
1367
1368 \wxheading{Return value}
1369
1370 Returns the internal class DB_ERR code. See \helpref{wxDb::DB_STATUS}{wxdb} definition.
1371
1372
1373 \membersection{wxDb::WriteSqlLog}\label{wxdbwritesqllog}
1374
1375 \func{bool}{WriteSqlLog}{\param{const wxChar *}{logMsg}}
1376
1377 \wxheading{Parameters}
1378
1379 \docparam{logMsg}{Free form string to be written to the log file.}
1380
1381 \wxheading{Remarks}
1382
1383 Very useful debugging tool that may be turned on/off during run time (see
1384 (see \helpref{wxDb::SetSqlLogging}{wxdbsetsqllogging} for details on
1385 turning logging on/off). The passed in string {\it logMsg} will be written to
1386 a log file if SQL logging is turned on.
1387
1388 \wxheading{Return value}
1389
1390 If SQL logging is off when a call to WriteSqlLog() is made, or there is a
1391 failure to write the log message to the log file, the function returns
1392 FALSE without performing the requested log, otherwise TRUE is returned.
1393
1394 \wxheading{See also}
1395
1396 \helpref{wxDb::SetSqlLogging}{wxdbsetsqllogging}
1397
1398
1399 \section{\class{wxDbColDataPtr}}\label{wxdbcoldataptr}
1400
1401 Pointer to dynamic column definitions for use with a wxDbTable instance.
1402 Currently there are no member functions for this class.
1403
1404 \begin{verbatim}
1405 void *PtrDataObj;
1406 int SzDataObj;
1407 int SqlCtype;
1408 \end{verbatim}
1409
1410
1411 \section{\class{wxDbColDef}}\label{wxdbcoldef}
1412
1413 This class is used to hold information about the columns bound to an
1414 instance of a wxDbTable object.
1415
1416 Each instance of this class describes one column in the wxDbTable
1417 object. When calling the \helpref{wxDb constructor}{wxdbconstr}, a
1418 parameter passed in indicates the number of columns that will be defined for
1419 the wxDbTable object. The constructor uses this information to allocate
1420 adequate memory for all of the column descriptions in your wxDbTable object.
1421 Private member wxDbTable::colDefs is a pointer to this chunk of memory
1422 maintained by the wxDbTable class (and can be retrieved using the
1423 \helpref{wxDbTable::GetColDefs}{wxdbtablegetcoldefs} function).
1424 To access the nth column definition of your wxDbTable object, just reference
1425 wxDbColDefs element [n - 1].
1426
1427 Currently there are no member functions for this class.
1428
1429 Typically, \helpref{wxDbTable::SetColDefs}{wxdbtablesetcoldefs} is used to
1430 populate an array of these data structures for the wxDbTable instance.
1431
1432 \begin{verbatim}
1433 char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name
1434 int DbDataType; - Logical Data Type;
1435 e.g. DB_DATA_TYPE_INTEGER
1436 int SqlCtype; - C data type; e.g. SQL_C_LONG
1437 void *PtrDataObj; - Address of the data object
1438 int SzDataObj; - Size, in bytes, of the data object
1439 bool KeyField; - Is column part of the PRIMARY KEY for the
1440 table? -- Date fields should NOT be
1441 KeyFields
1442 bool Updateable; - Column is updateable?
1443 bool InsertAllowed; - Column included in INSERT statements?
1444 bool DerivedCol; - Column is a derived value?
1445 SDWORD CbValue; - !!!Internal use only!!!
1446 bool Null; - NOT FULLY IMPLEMENTED
1447 Allows NULL values in Inserts and Updates
1448 \end{verbatim}
1449
1450 \wxheading{See also}
1451
1452 \helpref{wxDbTable::GetColDefs}{wxdbtablegetcoldefs}, \helpref{wxDb constructor}{wxdbconstr}
1453
1454
1455 \section{\class{wxDbColInf}}\label{wxdbcolinf}
1456
1457 Used with the \helpref{wxDb::GetColumns}{wxdbgetcolumns} functions for obtaining all retrievable information about a column's definition.
1458
1459 \begin{verbatim}
1460 char catalog[128+1];
1461 char schema[128+1];
1462 char tableName[DB_MAX_TABLE_NAME_LEN+1];
1463 char colName[DB_MAX_COLUMN_NAME_LEN+1];
1464 SWORD sqlDataType;
1465 char typeName[128+1];
1466 SWORD columnSize;
1467 SWORD bufferLength;
1468 short decimalDigits;
1469 short numPrecRadix;
1470 short nullable;
1471 char remarks[254+1];
1472 int dbDataType; // conversion of the 'sqlDataType'
1473 // to the generic data type used by
1474 // these classes
1475 int PkCol; // Primary key column
1476 0 = No
1477 1 = First Key
1478 2 = Second Key, etc...
1479 char PkTableName[DB_MAX_TABLE_NAME_LEN+1];
1480 // Tables that use this PKey as a FKey
1481 int FkCol; // Foreign key column
1482 0 = No
1483 1 = First Key
1484 2 = Second Key, etc...
1485 char FkTableName[DB_MAX_TABLE_NAME_LEN+1];
1486 // Foreign key table name
1487 wxDbColFor *pColFor; // How should this column be formatted
1488 \end{verbatim}
1489
1490 The constructor for this class initializes all the values to zero or NULL.
1491
1492 The destructor for this class takes care of deleting the pColFor member if
1493 it is non-NULL.
1494
1495
1496 \section{\class{wxDbColFor}}\label{wxdbcolfor}
1497
1498 Beginning support for handling international formatting specifically on dates and floats.
1499
1500 \begin{verbatim}
1501 wxString s_Field; // Formated String for Output
1502 wxString s_Format[7]; // Formated Objects - TIMESTAMP has
1503 the biggest (7)
1504 wxString s_Amount[7]; // Formated Objects - amount of
1505 things that can be formatted
1506 int i_Amount[7]; // Formated Objects -
1507 TT MM YYYY HH MM SS m
1508 int i_Nation; // 0 = timestamp
1509 1 = EU
1510 2 = UK
1511 3 = International
1512 4 = US
1513 int i_dbDataType; // conversion of the 'sqlDataType'
1514 to the generic data type used by
1515 these classes
1516 SWORD i_sqlDataType;
1517 \end{verbatim}
1518
1519 The constructor for this class initializes all the values to zero or NULL.
1520
1521 The destructor does nothing at this time.
1522
1523 Only one function is provided with this class currently:
1524
1525 \membersection{wxDbColFor::Format}\label{wxdbcolforformat}
1526
1527 \func{int }{Format}{\param{int }{Nation}, \param{int }{dbDataType}, \param{SWORD }{sqlDataType}, \param{short }{columnSize}, \param{short }{decimalDigits}}\label{wxdbcolforformat}
1528
1529 Work in progress, and should be inter-related with wxLocale eventually.
1530
1531
1532 \section{\class{wxDbIdxDef}}\label{wxdbidxdef}
1533
1534 Used in creation of non-primary indexes. Currently there are no member
1535 functions for this class.
1536
1537 \begin{verbatim}
1538 char ColName[DB_MAX_COLUMN_NAME_LEN+1]
1539 // Name of column
1540 bool Ascending // Is index maintained in
1541 ASCENDING sequence?
1542 \end{verbatim}
1543
1544 There are no constructors/destructors as of this time, and no member functions.
1545
1546
1547 \section{\class{wxDbInf}}\label{wxdbinf}
1548
1549 Contains information regarding the database connection (datasource name,
1550 number of tables, etc). A pointer to a wxDbTableInf is included in this
1551 class so a program can create a wxDbTableInf array instance to maintain all
1552 information about all tables in the datasource to have all the datasource's
1553 information in one memory structure.
1554
1555 Primarily, this class is used internally by the wxWindows ODBC classes.
1556
1557 \begin{verbatim}
1558 char catalog[128+1];
1559 char schema[128+1]; // typically means owner of table(s)
1560 int numTables; // How many tables does this
1561 datasource have
1562 wxDbTableInf *pTableInf; // Equals a new
1563 wxDbTableInf[numTables];
1564 \end{verbatim}
1565
1566 The constructor for this class initializes all the values to zero or NULL.
1567
1568 The destructor for this class takes care of deleting the pTableInf member if
1569 it is non-NULL.
1570
1571
1572 \section{\class{wxDbTable}}\label{wxdbtable}
1573
1574 A wxDbTable instance provides re-usable access to rows of data in
1575 a table contained within the associated ODBC datasource
1576
1577 \wxheading{Include files}
1578
1579 <wx/dbtable.h>\\
1580 <wx/db.h>
1581
1582 \latexignore{\rtfignore{\wxheading{Members}}}
1583 \wxheading{Helper classes and data structures}
1584
1585 The following classes and structs are defined in dbtable.cpp/.h for use with the wxDbTable class.
1586
1587 \begin{itemize}\itemsep=0pt
1588 \item \helpref{wxDbColDef}{wxdbcoldef}
1589 \item \helpref{wxDbColDataPtr}{wxdbcoldataptr}
1590 \item \helpref{wxDbIdxDef}{wxdbidxdef}
1591 \end{itemize}
1592
1593 \wxheading{Constants}
1594
1595 \begin{verbatim}
1596 wxDB_DEFAULT_CURSOR Primary cursor normally used for cursor based
1597 operations.
1598
1599 wxDB_QUERY_ONLY Used to indicate whether a table that is opened
1600 is for query only, or if insert/update/deletes
1601 will be performed on the table. Less overhead
1602 (cursors and memory) are allocated for query
1603 only tables, plus read access times are faster
1604 with some datasources.
1605
1606 wxDB_ROWID_LEN [Oracle only] - Used when CanUpdateByRowID()
1607 is true. Optimizes updates so they are faster
1608 by updating on the Oracle-specific ROWID column
1609 rather than some other index.
1610
1611
1612 wxDB_DISABLE_VIEW Use to indicate when a database view should not
1613 be if a table is normally set up to use a view.
1614 [Currently unsupported.]
1615
1616 \end{verbatim}
1617
1618
1619 \latexignore{\rtfignore{\wxheading{Members}}}
1620
1621 \membersection{wxDbTable::wxDbTable}\label{wxdbtableconstr}
1622
1623 \func{}{wxDbTable}{\param{wxDb *}{pwxDb}, \param{const char *}{tblName}, \param{const int }{nCols}, \param{const char *}{qryTblName = NULL}, \param{bool }{qryOnly = !wxDB_QUERY_ONLY}, \param{const char *}{tblPath=NULL}}
1624
1625 Default constructor.
1626
1627 \wxheading{Parameters}
1628
1629 \docparam{pwxDb}{Pointer to the wxDb instance to be used by this wxDbTable
1630 instance.}
1631 \docparam{tblName}{The name of the table in the RDBMS.}
1632 \docparam{nCols}{The number of columns in the table. (Do NOT include the ROWID
1633 column in the count if using Oracle).}
1634 \docparam{qryTblName}{{\it OPTIONAL}. The name of the table or view to base
1635 your queries on. This argument allows you to specify a table/view other than
1636 the base table for this object to base your queries on. This allows you to
1637 query on a view for example, but all of the INSERT, UPDATE and DELETES will
1638 still be performed on the base table for this wxDbTable object. Basing your
1639 queries on a view can provide a substantial performance increase in cases where
1640 your queries involve many tables with multiple joins. Default is NULL.}
1641 \docparam{qryOnly}{{\it OPTIONAL}. Indicates whether the table will be
1642 accessible for query purposes only, or should the table create the necessary
1643 cursors to be able to insert, update, and delete data from the table.
1644 Default is !wxDB_QUERY_ONLY.}
1645 \docparam{tblPath}{{\it OPTIONAL}. Some datasources (such as dBase)
1646 require a path to where the table is stored on the system. Default is NULL.}
1647
1648 \membersection{wxDbTable::wxDbTable}\label{wxdbtabledestr}
1649
1650 \func{virtual}{\destruct{wxDbTable}}{}
1651
1652 Virtual default destructor.
1653
1654
1655 \membersection{wxDbTable::BuildDeleteStmt}\label{wxdbtablebuilddeletestmt}
1656
1657 \func{void}{BuildDeleteStmt}{\param{char *}{pSqlStmt}, \param{int }{typeOfDel}, \param{const char *}{pWhereClause=NULL}}
1658
1659 Constructs the full SQL statement that can be used to delete all rows matching
1660 the criteria in the pWhereClause.
1661
1662 \wxheading{Parameters}
1663
1664 \docparam{pSqlStmt}{Pointer to buffer for the SQL statement retrieved. To be
1665 sure you have adequate space allocated for the SQL statement, allocate
1666 DB_MAX_STATEMENT_LEN bytes.}
1667 \docparam{typeOfDel}{The type of delete statement being performed. Can be one
1668 of three values: DB_DEL_KEYFIELDS, DB_DEL_WHERE or DB_DEL_MATCHING}
1669 \docparam{pWhereClause}{{\it OPTIONAL}. If the typeOfDel is DB_DEL_WHERE,
1670 then you must also pass in a SQL WHERE clause in this argument. Default
1671 is NULL.}
1672
1673 \wxheading{Remarks}
1674
1675 This member function constructs a SQL DELETE statement. This can be used for
1676 debugging purposes if you are having problems executing your SQL statement.
1677
1678 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
1679 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
1680 this function.
1681
1682
1683 \membersection{wxDbTable::BuildSelectStmt}\label{wxdbtablebuildselectstmt}
1684
1685 \func{void}{BuildSelectStmt}{\param{char *}{pSqlStmt}, \param{int }{typeOfSelect}, \param{bool }{distinct}}
1686
1687 Constructs the full SQL statement that can be used to select all rows matching
1688 the criteria in the pWhereClause. This function is called internally in the
1689 wxDbTable class whenever the function \helpref{wxDbTable::Query}{wxdbtablequery}
1690 is called.
1691
1692 NOTE: Only the columns specified in \helpref{wxDbTable::SetColDefs}{wxdbtablesetcoldefs}
1693 statements are included in the list of columns returned by the SQL statement
1694 created by a call to this function.
1695
1696 \wxheading{Parameters}
1697
1698 \docparam{pSqlStmt}{Pointer to storage for the SQL statement retrieved. To be
1699 sure you have adequate space allocated for the SQL statement, allocate
1700 DB_MAX_STATEMENT_LEN bytes.}
1701 \docparam{typeOfSelect}{The type of select statement being performed. Can be
1702 one of four values: DB_SELECT_KEYFIELDS, DB_SELECT_WHERE, DB_SELECT_MATCHING
1703 or DB_SELECT_STATEMENT.}
1704 \docparam{distinct}{Whether to select distinct records only.}
1705
1706 \wxheading{Remarks}
1707
1708 This member function constructs a SQL SELECT statement. This can be used for
1709 debugging purposes if you are having problems executing your SQL statement.
1710
1711 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
1712 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
1713 this function.
1714
1715
1716 \membersection{wxDbTable::BuildUpdateStmt}\label{wxdbtablebuildupdatestmt}
1717
1718 \func{void}{BuildSelectStmt}{\param{char *}{pSqlStmt}, \param{int }{typeOfUpd}, \param{const char *}{pWhereClause=NULL}}
1719
1720 Constructs the full SQL statement that can be used to update all rows matching
1721 the criteria in the pWhereClause.
1722
1723 If typeOfUpd is DB_UPD_KEYFIELDS, then the current values in the bound columns
1724 are used to determine which row(s) in the table are to be updated. The
1725 exception to this is when a datasource supports ROW IDs (Oracle). The ROW ID
1726 column is used for efficiency purposes when available.
1727
1728 NOTE: Only the columns specified in \helpref{wxDbTable::SetColDefs}{wxdbtablesetcoldefs}
1729 statements are included in the list of columns updated by the SQL statement
1730 created by a call to this function. Any column definitions that were defined
1731 as being non-updateable will be excluded from the SQL UPDATE statement created
1732 by this function.
1733
1734 \wxheading{Parameters}
1735
1736 \docparam{pSqlStmt}{Pointer to storage for the SQL statement retrieved. To be
1737 sure you have adequate space allocated for the SQL statement, allocate
1738 DB_MAX_STATEMENT_LEN bytes.}
1739 \docparam{typeOfUpd}{The type of update statement being performed. Can be one
1740 of two values: DB_UPD_KEYFIELDS or DB_UPD_WHERE.}
1741 \docparam{pWhereClause}{{\it OPTIONAL}. If the typeOfUpd is DB_UPD_WHERE,
1742 then you must also pass in a SQL WHERE clause in this argument. Default
1743 is NULL.}
1744
1745 \wxheading{Remarks}
1746
1747 This member function allows you to see what the SQL UPDATE statement looks like
1748 that the ODBC class library builds. This can be used for debugging purposes if
1749 you are having problems executing your SQL statement.
1750
1751 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
1752 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
1753 this function.
1754
1755
1756 \membersection{wxDbTable::BuildWhereStmt}\label{wxdbtablebuildwherestmt}
1757
1758 \func{void}{BuildSelectStmt}{\param{char *}{pWhereClause}, \param{int }{typeOfWhere}, \param{const char *}{qualTableName=NULL}, \param{const char *}{useLikeComparison=FALSE}}
1759
1760 Constructs the portion of a SQL statement which would follow the word 'WHERE'
1761 in a SQL statement to be passed to the datasource. The returned string
1762 does NOT include the word 'WHERE'.
1763
1764 \wxheading{Parameters}
1765
1766 \docparam{pWhereClause}{Pointer to storage for the SQL statement retrieved.
1767 To be sure you have adequate space allocated for the SQL statement, allocate
1768 DB_MAX_STATEMENT_LEN bytes.}
1769 \docparam{typeOfWhere}{The type of where clause to generate. Can be one of
1770 two values: DB_WHERE_KEYFIELDS or DB_WHERE_MATCHING.}
1771 \docparam{qualTableName}{{\it OPTIONAL}. Prepended to all base table
1772 column names. For use when a FROM clause has been specified with the
1773 \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause},
1774 to clarify which table a column name reference belongs to. Default is NULL.}
1775 \docparam{useLikeComparison}{{\it OPTIONAL}. Should the constructed WHERE
1776 clause utilize the LIKE comparison operator. If FALSE, then the '='
1777 operator is used. Default is FALSE.}
1778
1779 \wxheading{Remarks}
1780
1781 This member function allows you to see what the SQL WHERE clause looks like
1782 that the ODBC class library builds. This can be used for debugging purposes
1783 if you are having problems executing your own SQL statements.
1784
1785 If using 'typeOfWhere' set to DB_WHERE_MATCHING, any bound columns currently
1786 containing a NULL value are not included in the WHERE clause's list of
1787 columns to use in the comparison.
1788
1789
1790 \membersection{wxDbTable::CanSelectForUpdate}\label{wxdbtablecanselectforupdate}
1791
1792 \func{bool}{CanSelectForUpdate}{\void}
1793
1794 Use this function to determine if the datasource supports SELECT ... FOR UPDATE.
1795 When the keywords "FOR UPDATE" are included as part of your SQL SELECT statement,
1796 all records {\it retrieved} (not just queried, but actually retrieved using
1797 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}, etc) from the result set are
1798 locked.
1799
1800 \wxheading{Remarks}
1801
1802 Not all datasources support the "FOR UPDATE" clause, so you must use this
1803 member function to determine if the datasource currently connected to supports
1804 this behavior or not before trying to select using "FOR UPDATE".
1805
1806 If the wxDbTable instance was created with the parameter wxDB_QUERY_ONLY, then
1807 this function will return FALSE. For all known databases which do not support
1808 the FOR UPDATE clause, this function will return FALSE also.
1809
1810
1811 \membersection{wxDbTable::CanUpdateByROWID}\label{wxdbtablecanupdatebyrowid}
1812
1813 \func{bool}{CanUpdateByROWID}{\void}
1814
1815 CURRENTLY ONLY POSSIBLE IF USING ORACLE.
1816
1817 --- CURRENTLY DISABLED FOR *ALL* DATASOURCES --- NOV 1 2000 - gt
1818
1819 Every Oracle table has a hidden column named ROWID. This is a pointer to the
1820 physical location of the record in the datasource and allows for very fast
1821 updates and deletes. The key is to retrieve this ROWID during your query so
1822 it is available during an update or delete operation.
1823
1824 Use of the ROWID feature is always handled by the class library except in the
1825 case of \helpref{wxDbTable::QueryBySqlStmt}{wxdbtablequerybysqlstmt}. Since
1826 you are passing in the SQL SELECT statement,
1827 it is up to you to include the ROWID column in your query. If you do not,
1828 the application will still work, but may not be as optimized. The ROWID is
1829 always the last column in the column list in your SQL SELECT statement.
1830 The ROWID is not a column in the normal sense and should not be considered
1831 part of the column definitions for the wxDbTable object.
1832
1833 \wxheading{Remarks}
1834
1835 The decision to include the ROWID in your SQL SELECT statement must be
1836 deferred until runtime since it depends on whether you are connected
1837 to an Oracle datasource or not.
1838
1839 \wxheading{Example}
1840
1841 \begin{verbatim}
1842 // Incomplete code sample
1843 wxDbTable parts;
1844 .....
1845 if (parts.CanUpdByROWID())
1846 {
1847 // Note that the ROWID column must always be the last column selected
1848 sqlStmt = "SELECT PART_NO, PART_DESC, ROWID" FROM PARTS";
1849 }
1850 else
1851 sqlStmt = "SELECT PART_NO, PART_DESC" FROM PARTS";
1852 \end{verbatim}
1853
1854
1855 \membersection{wxDbTable::ClearMemberVar}\label{wxdbtableclearmembervar}
1856
1857 \func{void}{ClearMemberVar}{\param{int }{colNo}, \param{bool }{setToNull=FALSE}}
1858
1859 Same as \helpref{wxDbTable::ClearMemberVars}{wxdbtableclearmembervars} except
1860 that this function clears only the specified column of its values, and
1861 optionally sets the column to be a NULL column.
1862
1863 \docparam{colNo}{Column number that is to be cleared. This number (between 0 and (noCols-1)) is the index of the column definition created using the \helpref{wxDbTable::SetColDefs}{wxdbtablesetcoldefs} function.}
1864 \docparam{setToNull}{{\it OPTIONAL}. Indicates whether the column should be flagged as being a NULL value stored in the bound memory variable. If TRUE, then any value stored in the bound member variable is cleared. Default is FALSE.}
1865
1866
1867 \membersection{wxDbTable::ClearMemberVars}\label{wxdbtableclearmembervars}
1868
1869 \func{void}{ClearMemberVars}{\param{bool }{setToNull=FALSE}}
1870
1871 Initializes all bound columns of the wxDbTable instance to zero. In the case
1872 of a string, zero is copied to the first byte of the string.
1873
1874 \docparam{setToNull}{{\it OPTIONAL}. Indicates whether all columns should be flagged as having a NULL value stored in the bound memory variable. If TRUE, then any value stored in the bound member variable is cleared. Default is FALSE.}
1875
1876 \wxheading{Remarks}
1877
1878 This is useful before calling functions such as \helpref{wxDbTable::QueryMatching}{wxdbtablequerymatching} or
1879 \helpref{wxDbTable::DeleteMatching}{wxdbtabledeletematching} since these
1880 functions build their WHERE clauses from non-zero columns. To call either
1881 \helpref{wxDbTable::QueryMatching}{wxdbtablequerymatching} or
1882 \helpref{wxDbTable::DeleteMatching}{wxdbtabledeletematching} use this sequence:
1883
1884 \begin{verbatim}
1885 1) ClearMemberVars()
1886 2) Assign columns values you wish to match on
1887 3) Call wxDbTable::QueryMatching() or wxDbTable::DeleteMatching()
1888 \end{verbatim}
1889
1890
1891 \membersection{wxDbTable::CloseCursor}\label{wxdbtableclosecursor}
1892
1893 \func{bool}{CloseCursor}{\param{HSTMT}{cursor}}
1894
1895 Closes the specified cursor associated with the wxDbTable object.
1896
1897 \wxheading{Parameters}
1898
1899 \docparam{cursor}{The cursor to be closed.}
1900
1901 \wxheading{Remarks}
1902
1903 Typically handled internally by the ODBC class library, but may be used by the
1904 programmer if desired.
1905
1906
1907 \normalbox{DO NOT CLOSE THE wxDB_DEFAULT_CURSOR!}
1908
1909
1910 \membersection{wxDbTable::Count}\label{wxdbtablecount}
1911
1912 \func{ULONG }{Count}{\param{const char *}{args="*"}}
1913
1914 Returns the number of records which would be in the result set using the
1915 current query parameters specified in the WHERE and FROM clauses.
1916
1917 \wxheading{Parameters}
1918
1919 \docparam{args}{{\it OPTIONAL}. This arguement allows the use of the
1920 DISTINCT keyword against a column name to cause the returned count to
1921 only indicate the number of rows in the result set that have a unique
1922 value in the specified column. An example is shown below. Default is "*",
1923 meaning a count of the total number of rows matching is returned, regardless of
1924 uniqueness.}
1925
1926 \wxheading{Remarks}
1927
1928 This function can be called before or after an actual query to obtain the
1929 count of records in the result set. Count() uses its own cursor, so result
1930 set cursor positioning is not affected by calls to Count().
1931
1932 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
1933 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} ARE used by
1934 this function.
1935
1936 \wxheading{Example}
1937
1938 \begin{verbatim}
1939
1940 USERS TABLE
1941
1942 FIRST_NAME LAST_NAME
1943 ----------- ----------
1944 John Doe
1945 Richard Smith
1946 Michael Jones
1947 John Carpenter
1948
1949 // Incomplete code sample
1950 wxDbTable users;
1951 .....
1952 users.SetWhereClause("");
1953
1954 // This Count() will return 4, as there are four users listed above
1955 // that match the query parameters
1956 totalNumberOfUsers = users.Count();
1957
1958 // This Count() will return 3, as there are only 3 unique first names
1959 // in the table above - John, Richard, Michael.
1960 totalNumberOfUniqueFirstNames = users.Count("DISTINCT FIRST_NAME");
1961 \end{verbatim}
1962
1963
1964 \membersection{wxDbTable::CreateIndex}\label{wxdbtablecreateindex}
1965
1966 \func{bool}{CreateIndex}{\param{const char *}{idxName}, \param{bool }{unique}, \param{int }{noIdxCols}, \param{wxDbIdxDef *}{pIdxDefs}, \param{bool }{attemptDrop=TRUE}}
1967
1968 This member function allows you to create secondary (non primary) indexes on
1969 your tables. You first create your table, normally specifying a primary
1970 index, and then create any secondary indexes on the table. Indexes in
1971 relational model are not required. You do not need indexes to look up records
1972 in a table or to join two tables together. In the relational model, indexes,
1973 if available, provide a quicker means to look up data in a table. To enjoy
1974 the performance benefits of indexes, the indexes must be defined on the
1975 appropriate columns and your SQL code must be written in such a way as to
1976 take advantage of those indexes.
1977
1978 \wxheading{Parameters}
1979
1980 \docparam{idxName}{Name of the Index. Name must be unique within the table space of the datasource.}
1981 \docparam{unique}{Indicates if this index is unique.}
1982 \docparam{noIdxCols}{Number of columns in the index.}
1983 \docparam{pIdxDefs}{A pointer to an array wxDbIdxDef structures. }
1984 \docparam{attemptDrop}{{\it OPTIONAL}. Indicates if the function should try
1985 to execute a \helpref{wxDbTable::DropIndex}{wxdbtabledropindex} on the index
1986 name provided before trying to create the index name. Default is TRUE.}
1987
1988 \wxheading{Remarks}
1989
1990 The first parameter, index name, must be unique and should be given a
1991 meaningful name. Common practice is to include the table name as a prefix
1992 in the index name (e.g. For table PARTS, you might want to call your index
1993 PARTS_IDX1). This will allow you to easily view all
1994 of the indexes defined for a given table grouped together alphabetically.
1995
1996 The second parameter indicates if the index is unique or not. Uniqueness
1997 is enforced at the RDBMS level preventing rows which would have duplicate
1998 indexes from being inserted into the table when violating a unique index's
1999 uniqueness.
2000
2001 In the third parameter, specify how many columns are in your index. This
2002 number must match the number of columns defined in the 'pIdxDefs' parameter.
2003
2004 The fourth parameter specifies which columns make up the index using the
2005 wxDbIdxDef structure. For each column in the index, you must specify two
2006 things, the column name and the sort order (ascending / descending). See
2007 the example below to see how to build and pass in the wxDbIdxDef structure.
2008
2009 The fifth parameter is provided to handle the differences in datasources as
2010 to whether they will automatically overwrite existing indexes with the same
2011 name or not. Some datasources require that the existing index must be dropped
2012 first, so this is the default behavior.
2013
2014 Some datasources (MySQL, and possibly others) require columns which are to be
2015 part of an index to be defined as NOT NULL. When this function is called, if
2016 a column is not defined to be NOT NULL, a call to this function will modify
2017 the column definition to change any columns included in the index to be
2018 NOT NULL. In this situation, if a NULL value already exists in one of the
2019 columns that is being modified, creation of the index will fail.
2020
2021 PostGres is unable to handle index definitions which specify whether the index
2022 is ascending or descending, and defaults to the system default when the index
2023 is created.
2024
2025 It is not necessary to call \helpref{wxDb::CommitTrans}{wxdbcommittrans}
2026 after executing this function.
2027
2028 \wxheading{Example}
2029
2030 \begin{verbatim}
2031 // Create a secondary index on the PARTS table
2032 wxDbIdxDef idxDef[2]; // 2 columns make up the index
2033
2034 strcpy(idxDef[0].ColName, "PART_DESC"); // Column 1
2035 idxDef[0].Ascending = TRUE;
2036
2037 strcpy(idxDef[1].ColName, "SERIAL_NO"); // Column 2
2038 idxDef[1].Ascending = FALSE;
2039
2040 // Create a name for the index based on the table's name
2041 wxString indexName;
2042 indexName.sprintf("%s_IDX1",parts->GetTableName());
2043 parts->CreateIndex(indexName.c_str(), TRUE, 2, idxDef);
2044 \end{verbatim}
2045
2046
2047 \membersection{wxDbTable::CreateTable}\label{wxdbtablecreatetable}
2048
2049 \func{bool}{CreateTable}{\param{bool }{attemptDrop=TRUE}}
2050
2051 Creates a table based on the definitions previously defined for this
2052 wxDbTable instance.
2053
2054 \wxheading{Parameters}
2055
2056 \docparam{attemptDrop}{{\it OPTIONAL}. Indicates whether the driver should
2057 attempt to drop the table before trying to create it. Some datasources will
2058 not allow creation of a table if the table already exists in the table space
2059 being used. Default is TRUE.}
2060
2061 \wxheading{Remarks}
2062
2063 This function creates the table and primary index (if any) in the table space
2064 associated with the connected datasource. The owner of these objects will
2065 be the user id that was given when \helpref{wxDb::Open}{wxdbopen} was called. The objects will
2066 be created in the default schema/table space for that user.
2067
2068 In your derived wxDbTable object constructor, the columns and primary index
2069 of the table are described through the \helpref{wxDbColDef}{wxdbcoldef} structure.
2070 \helpref{wxDbTable::CreateTable}{wxdbtablecreatetable} uses this information to create the table and to add
2071 the primary index. See \helpref{wxDbTable}{wxdbtable} ctor and wxDbColDef
2072 description for additional information on describing the columns of the table.
2073
2074 It is not necessary to call \helpref{wxDb::CommitTrans}{wxdbcommittrans}
2075 after executing this function.
2076
2077
2078 \membersection{wxDbTable::DB_STATUS}\label{wxdbtabledbstatus}
2079
2080 \func{bool}{DB_STATUS}{\void}
2081
2082 Accessor function that returns the wxDb private member variable DB_STATUS for
2083 the database connection used by this instance of wxDbTable.
2084
2085
2086 \membersection{wxDbTable::Delete}\label{wxdbtabledelete}
2087
2088 \func{bool}{Delete}{\void}
2089
2090 Deletes the row from the table indicated by the current cursor.
2091
2092 \wxheading{Remarks}
2093
2094 Use \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst}, \helpref{wxDbTable::GetLast}{wxdbtablegetlast},
2095 \helpref{wxDbTable::GetNext}{wxdbtablegetnext} or
2096 \helpref{wxDbTable::GetPrev}{wxdbtablegetprev} to position the cursor to
2097 a valid record. Once positioned on a record, call this function to delete
2098 the row from the table.
2099
2100 A \helpref{wxDb::CommitTrans}{wxdbcommittrans} or
2101 \helpref{wxDb::RollbackTrans}{wxdbrollbacktrans} must be called after use of
2102 this function to commit or rollback the deletion.
2103
2104 NOTE: Most datasources have a limited size "rollback" segment. This means
2105 that it is only possible to insert/update/delete a finite number of rows
2106 without performing a \helpref{wxDb::CommitTrans}{wxdbcommittrans} or
2107 \helpref{wxDb::RollbackTrans}{wxdbrollbacktrans}. Size of the rollback
2108 segment varies from database to database, and is user configurable in
2109 most databases. Therefore it is usually best to try to perform a commit
2110 or rollback at relatively small intervals when processing a larger number
2111 of actions that insert/update/delete rows in a table.
2112
2113
2114 \membersection{wxDbTable::DeleteCursor}\label{wxdbtabledeletecursor}
2115
2116 \func{bool}{DeleteCursor}{\param{HSTMT *}{hstmtDel}}
2117
2118 Allows a program to delete a cursor.
2119
2120 \wxheading{Parameters}
2121
2122 \docparam{hstmtDel}{Handle of the cursor to delete.}
2123
2124 \wxheading{Remarks}
2125
2126 For default cursors associated with the instance of wxDbTable, it is not
2127 necessary to specifically delete the cursors. This is automatically done
2128 in the wxDbTable destructor.
2129
2130 NOTE: If the cursor could not be deleted for some reason, an error is logged
2131 indicating the reason. Even if the cursor could not be deleted, the HSTMT
2132 that is passed in is deleted, and the pointer is set to NULL.
2133
2134 \normalbox{DO NOT DELETE THE wxDB_DEFAULT_CURSOR!}
2135
2136
2137 \membersection{wxDbTable::DeleteMatching}\label{wxdbtabledeletematching}
2138
2139 \func{bool}{DeleteMatching}{\void}
2140
2141 This member function allows you to delete records from your wxDbTable object
2142 by specifying the data in the columns to match on.
2143
2144 \wxheading{Remarks}
2145
2146 To delete all users with a first name of "JOHN", do the following:
2147
2148 \begin{verbatim}
2149 1) Clear all "columns" using wxDbTable::ClearMemberVars().
2150 2) Set the FIRST_NAME column equal to "JOHN".
2151 3) Call wxDbTable::DeleteMatching().
2152 \end{verbatim}
2153
2154 The WHERE clause is built by the ODBC class library based on all non-NULL
2155 columns. This allows deletion of records
2156 by matching on any column(s) in your wxDbTable instance, without having to
2157 write the SQL WHERE clause.
2158
2159 A \helpref{wxDb::CommitTrans}{wxdbcommittrans} or
2160 \helpref{wxDb::RollbackTrans}{wxdbrollbacktrans} must be called after use of
2161 this function to commit or rollback the deletion.
2162
2163 NOTE: Row(s) should be locked before deleting them to make sure they are
2164 not already in use. This can be achieved by calling \helpref{wxDbTable::QueryMatching}{wxdbtablequerymatching},
2165 and then retrieving the records, locking each as you go (assuming FOR UPDATE
2166 is allowed on the datasource). After the row(s) have been successfully locked,
2167 call this function.
2168
2169 NOTE: Most datasources have a limited "rollback" segment. This means
2170 that it is only possible to insert/update/delete a finite number of rows
2171 without performing a \helpref{wxDb::CommitTrans}{wxdbcommittrans} or
2172 \helpref{wxDb::RollbackTrans}{wxdbrollbacktrans}. Size of the rollback
2173 segment varies from database to database, and is user configurable in
2174 most databases. Therefore it is usually best to try to perform a commit
2175 or rollback at relatively small intervals when processing a larger number
2176 of actions that insert/update/delete rows in a table.
2177
2178
2179 \wxheading{Example}
2180
2181 \begin{verbatim}
2182 // Incomplete code sample to delete all users with a first name
2183 // of "JOHN"
2184 users.ClearMemberVars();
2185 strcpy(users.FirstName,"JOHN");
2186 users.DeleteMatching();
2187 \end{verbatim}
2188
2189
2190 \membersection{wxDbTable::DeleteWhere}\label{wxdbtabledeletewhere}
2191
2192 \func{bool}{DeleteWhere}{\param{const char *}{pWhereClause}}
2193
2194 Deletes all rows from the table which match the criteria specified in the
2195 WHERE clause that is passed in.
2196
2197 \wxheading{Parameters}
2198
2199 \docparam{pWhereClause}{SQL WHERE clause. This WHERE clause determines which
2200 records will be deleted from the table interfaced through the wxDbTable
2201 instance. The WHERE clause passed in must be compliant with the SQL 92
2202 grammar. Do not include the keyword 'WHERE'
2203 }
2204
2205 \wxheading{Remarks}
2206
2207 This is the most powerful form of the wxDbTable delete functions. This
2208 function gives access to the full power of SQL. This function can be used
2209 to delete records by passing a valid SQL WHERE clause. Sophisticated
2210 deletions can be performed based on multiple criteria using the full
2211 functionality of the SQL language.
2212
2213 A \helpref{wxDb::CommitTrans}{wxdbcommittrans} must be called after use of
2214 this function to commit the deletions.
2215
2216 Note: This function is limited to deleting records from the table associated
2217 with this wxDbTable object only. Deletions on joined tables is not possible.
2218
2219 NOTE: Most datasources have a limited size "rollback" segment. This means
2220 that it is only possible to insert/update/delete a finite number of rows
2221 without performing a \helpref{wxDb::CommitTrans}{wxdbcommittrans} or
2222 \helpref{wxDb::RollbackTrans}{wxdbrollbacktrans}. Size of the rollback
2223 segment varies from database to database, and is user configurable in
2224 most databases. Therefore it is usually best to try to perform a commit
2225 or rollback at relatively small intervals when processing a larger number
2226 of actions that insert/update/delete rows in a table.
2227
2228 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
2229 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
2230 this function.
2231
2232 \wxheading{Example}
2233
2234 \begin{verbatim}
2235 // Delete parts 1 thru 10 from containers 'X', 'Y' and 'Z' that
2236 // are magenta in color
2237 parts.DeleteWhere("(PART_NUMBER BETWEEN 1 AND 10) AND \
2238 CONTAINER IN ('X', 'Y', 'Z') AND \
2239 UPPER(COLOR) = 'MAGENTA'");
2240 \end{verbatim}
2241
2242
2243 \membersection{wxDbTable::DropIndex}\label{wxdbtabledropindex}
2244
2245 \func{bool}{DropIndex}{\param{const char *}{idxName}}
2246
2247 Allows an index on the associated table to be dropped (deleted) if the user
2248 login has sufficient privileges to do so.
2249
2250 \wxheading{Parameters}
2251
2252 \docparam{idxName}{Name of the index to be dropped.}
2253
2254 \wxheading{Remarks}
2255
2256 If the index specified in the 'idxName' parameter does not exist, an error
2257 will be logged, and the function will return a result of FALSE.
2258
2259 It is not necessary to call \helpref{wxDb::CommitTrans}{wxdbcommittrans}
2260 after executing this function.
2261
2262
2263 \membersection{wxDbTable::DropTable}\label{wxdbtabledroptable}
2264
2265 \func{bool}{DropTable}{\void}
2266
2267 Deletes the associated table if the user has sufficient privileges to do so.
2268
2269 \wxheading{Remarks}
2270
2271 This function returns TRUE if the table does not exist, but only for
2272 supported databases (see \helpref{wxDb::Dbms}{wxdbdbms}). If a datasource
2273 is not specifically supported, and this function is called, the function
2274 will return FALSE.
2275
2276 Most datasources/ODBC drivers will delete any indexes associated with the
2277 table automatically, and others may not. Check the documentation for your
2278 database to determine the behavior.
2279
2280 It is not necessary to call \helpref{wxDb::CommitTrans}{wxdbcommittrans}
2281 after executing this function.
2282
2283
2284 \membersection{wxDbTable::From}\label{wxdbtablefrom}
2285
2286 \func{const char *}{From}{}
2287
2288 \func{void}{From}{\param{const wxString &}{From}}
2289
2290 Accessor function for the private class member wxDbTable::from. Can be used
2291 as a synonym for \helpref{wxDbTable::GetFromClause}{wxdbtablegetfromclause}
2292 (the first form of this function) or
2293 \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} (the second form
2294 of this function).
2295
2296 \wxheading{Parameters}
2297
2298 \docparam{From}{A comma separated list of table names that are to be outer
2299 joined with the base table's columns so that the joined table's columns
2300 may be returned in the result set or used as a portion of a comparison with
2301 the base table's columns. NOTE that the base tables name must NOT be included
2302 in the FROM clause, as it is automatically included by the wxDbTable class
2303 in constructing query statements.}
2304
2305 \wxheading{Return value}
2306
2307 The first form of this function returns the current value of the wxDbTable
2308 member variable ::from.
2309
2310 The second form of the function has no return value, as it will always set
2311 the from clause successfully.
2312
2313 \wxheading{See also}
2314
2315 \helpref{wxDbTable::GetFromClause}{wxdbtablegetfromclause},
2316 \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause}
2317
2318
2319 \membersection{wxDbTable::GetColDefs}\label{wxdbtablegetcoldefs}
2320
2321 \func{wxDbColDef *}{GetColDefs}{}
2322
2323 Accessor function that returns a pointer to the array of column definitions
2324 that are bound to the columns that this wxDbTable instance is associated
2325 with.
2326
2327 To determine the number of elements pointed to by the returned
2328 \helpref{wxDbColDef}{wxdbcoldef} pointer, use the
2329 \helpref{wxDbTable::GetNumberOfColumns}{wxdbtablegetnumberofcolumns} function.
2330
2331 \wxheading{Remarks}
2332
2333 These column definitions must not be manually redefined after they have been
2334 set.
2335
2336
2337 \membersection{wxDbTable::GetCursor}\label{wxdbtablegetcursor}
2338
2339 \func{HSTMT}{GetCursor}{\void}
2340
2341 Returns the HSTMT value of the current cursor for this wxDbTable object.
2342
2343 \wxheading{Remarks}
2344
2345 This function is typically used just before changing to use a different cursor
2346 so that after the program is finished using the other cursor, the current
2347 cursor can be set back to being the cursor in use.
2348
2349 \wxheading{See also}
2350
2351 \helpref{wxDbTable::SetCursor}{wxdbtablesetcursor}, \helpref{wxDbTable::GetNewCursor}{wxdbtablegetnewcursor}
2352
2353
2354 \membersection{wxDbTable::GetDb}\label{wxdbtablegetdb}
2355
2356 \func{wxDb *}{GetDb}{}
2357
2358 Accessor function for the private member variable pDb which is a pointer to
2359 the datasource connection that this wxDbTable instance uses.
2360
2361
2362 \membersection{wxDbTable::GetFirst}\label{wxdbtablegetfirst}
2363
2364 \func{bool}{GetFirst}{\void}
2365
2366 Retrieves the FIRST row in the record set as defined by the current query.
2367 Before retrieving records, a query must be performed using
2368 \helpref{wxDbTable::Query}{wxdbtablequery},
2369 \helpref{wxDbTable::QueryOnKeyFields}{wxdbtablequeryonkeyfields},
2370 \helpref{wxDbTable::QueryMatching}{wxdbtablequerymatching} or
2371 \helpref{wxDbTable::QueryBySqlStmt}{wxdbtablequerybysqlstmt}.
2372
2373 \wxheading{Remarks}
2374
2375 This function can only be used if the datasource connection used by the
2376 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2377 connection does not allow backward scrolling cursors, this function will
2378 return FALSE, and the data contained in the bound columns will be undefined.
2379
2380 \wxheading{See also}
2381
2382 \helpref{wxDb::FwdOnlyCursors}{wxdbfwdonlycursors}
2383
2384
2385 \membersection{wxDbTable::GetFromClause}\label{wxdbtablegetfromclause}
2386
2387 \func{const char *}{GetFromClause}{}
2388
2389 Accessor function that returns the current FROM setting assigned with the
2390 \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause}.
2391
2392 \wxheading{See also}
2393
2394 \helpref{wxDbTable::From}{wxdbtablefrom}
2395
2396
2397 \membersection{wxDbTable::GetLast}\label{wxdbtablegetlast}
2398
2399 \func{bool}{GetLast}{\void}
2400
2401 Retrieves the LAST row in the record set as defined by the current query.
2402 Before retrieving records, a query must be performed using
2403 \helpref{wxDbTable::Query}{wxdbtablequery},
2404 \helpref{wxDbTable::QueryOnKeyFields}{wxdbtablequeryonkeyfields},
2405 \helpref{wxDbTable::QueryMatching}{wxdbtablequerymatching} or
2406 \helpref{wxDbTable::QueryBySqlStmt}{wxdbtablequerybysqlstmt}.
2407
2408 \wxheading{Remarks}
2409
2410 This function can only be used if the datasource connection used by the
2411 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2412 connection does not allow backward scrolling cursors, this function will
2413 return FALSE, and the data contained in the bound columns will be undefined.
2414
2415 \wxheading{See also}
2416
2417 \helpref{wxDb::FwdOnlyCursors}{wxdbfwdonlycursors}
2418
2419
2420 \membersection{wxDbTable::GetNewCursor}\label{wxdbtablegetnewcursor}
2421
2422 \func{HSTMT *}{GetNewCursor}{\param{bool }{setCursor=FALSE}, \param{bool }{bindColumns=TRUE}}
2423
2424 This function will create a new cursor that can be used to access the table
2425 being referenced by this wxDbTable instance, or to execute direct SQL commands
2426 on without affecting the cursors that are already defined and possibly positioned.
2427
2428 \wxheading{Parameters}
2429
2430 \docparam{setCursor}{{\it OPTIONAL}. Should this new cursor be set to be the current cursor after successfully creating the new cursor. Default is FALSE.}
2431 \docparam{bindColumns}{{\it OPTIONAL}. Should this new cursor be bound to all the memory variables that the default cursor is bound to. Default is TRUE.}
2432
2433 \wxheading{Remarks}
2434
2435 This new cursor must be closed using \helpref{wxDbTable::DeleteCursor}{wxdbtabledeletecursor}
2436 by the calling program before the wxDbTable instance is deleted, or both memory
2437 and resource leaks will occur.
2438
2439
2440 \membersection{wxDbTable::GetNext}\label{wxdbtablegetnext}
2441
2442 \func{bool}{GetNext}{\void}
2443
2444 Retrieves the NEXT row in the record set after the current cursor position
2445 as defined by the current query. Before retrieving records, a query must be
2446 performed using \helpref{wxDbTable::Query}{wxdbtablequery},
2447 \helpref{wxDbTable::QueryOnKeyFields}{wxdbtablequeryonkeyfields},
2448 \helpref{wxDbTable::QueryMatching}{wxdbtablequerymatching} or
2449 \helpref{wxDbTable::QueryBySqlStmt}{wxdbtablequerybysqlstmt}.
2450
2451 \wxheading{Return value}
2452
2453 This function returns FALSE when the current cursor has reached the end of
2454 the result set. When FALSE is returned, data in the bound columns is
2455 undefined.
2456
2457 \wxheading{Remarks}
2458
2459 This function works with both forward and backward scrolling cursors.
2460
2461 \wxheading{See also}
2462 \helpref{wxDbTable::++}{wxdbtableplusplus}
2463
2464
2465 \membersection{wxDbTable::GetNumberOfColumns}\label{wxdbtablegetnumberofcolumns}
2466
2467 \func{bool}{GetNumberOfColumns}{}
2468
2469 Accessor function that returns the number of columns that are statically
2470 bound for access by the wxDbTable instance.
2471
2472
2473 \membersection{wxDbTable::GetOrderByClause}\label{wxdbtablegetorderbyclause}
2474
2475 \func{const char *}{GetOrderByClause}{}
2476
2477 Accessor function that returns the current ORDER BY setting assigned with
2478 the \helpref{wxDbTable::SetOrderByClause}{wxdbtablesetorderbyclause}.
2479
2480 \wxheading{See also}
2481
2482 \helpref{wxDbTable::OrderBy}{wxdbtableorderby}
2483
2484
2485 \membersection{wxDbTable::GetPrev}\label{wxdbtablegetprev}
2486
2487 \func{bool}{GetPrev}{\void}
2488
2489 Retrieves the PREVIOUS row in the record set before the current cursor
2490 position as defined by the current query. Before retrieving records, a
2491 query must be performed using \helpref{wxDbTable::Query}{wxdbtablequery},
2492 \helpref{wxDbTable::QueryOnKeyFields}{wxdbtablequeryonkeyfields},
2493 \helpref{wxDbTable::QueryMatching}{wxdbtablequerymatching} or
2494 \helpref{wxDbTable::QueryBySqlStmt}{wxdbtablequerybysqlstmt}.
2495
2496 \wxheading{Return value}
2497
2498 This function returns FALSE when the current cursor has reached the beginning
2499 of the result set and there are now other rows prior to the cursors current
2500 position. When FALSE is returned, data in the bound columns is undefined.
2501
2502 \wxheading{Remarks}
2503
2504 This function can only be used if the datasource connection used by the
2505 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2506 connection does not allow backward scrolling cursors, this function will
2507 return FALSE, and the data contained in the bound columns will be undefined.
2508
2509 \wxheading{See also}
2510
2511 \helpref{wxDb::FwdOnlyCursors}{wxdbfwdonlycursors},
2512 \helpref{wxDbTable::--}{wxdbtableminusminus}
2513
2514
2515 \membersection{wxDbTable::GetQueryTableName}\label{wxdbtablegetquerytablename}
2516
2517 \func{const char *}{GetQueryTableName}{}
2518
2519 Accessor function that returns the name of the table/view that was indicated
2520 as being the table/view to query against when this wxDbTable instance was
2521 created.
2522
2523 \wxheading{See also}
2524
2525 \helpref{wxDbTable constructor}{wxdbtableconstr}
2526
2527
2528 \membersection{wxDbTable::GetRowNum}\label{wxdbtablegetrownum}
2529
2530 \func{UWORD}{GetRowNum}{\void}
2531
2532 Returns the ODBC row number for performing positioned updates and deletes.
2533
2534 \wxheading{Remarks}
2535
2536 This function is not being used within the ODBC class library and may be a
2537 candidate for removal if no use is found for it.
2538
2539 Row nuumber with some datasources/ODBC drivers is the position in the result set,
2540 while in others it may be a physical position in the database. Check your
2541 database documentation to find out which behavior is supported.
2542
2543
2544 \membersection{wxDbTable::GetTableName}\label{wxdbtablegettablename}
2545
2546 \func{const char *}{GetTableName}{}
2547
2548 Accessor function that returns the name of the table that was indicated
2549 as being the table that this wxDbTable instance was associated with.
2550
2551
2552 \membersection{wxDbTable::GetTablePath}\label{wxdbtablegettablepath}
2553
2554 \func{const char *}{GetTablePath}{}
2555
2556 Accessor function that returns the path to the data table that was indicated
2557 during creation of this wxDbTable instance.
2558
2559 \wxheading{Remarks}
2560
2561 Currently only applicable to dBase and MS-Access datasources.
2562
2563
2564 \membersection{wxDbTable::GetWhereClause}\label{wxdbtablegetwhereclause}
2565
2566 \func{const char *}{GetWhereClause}{}
2567
2568 Accessor function that returns the current WHERE setting assigned with the
2569 \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
2570
2571 \wxheading{See also}
2572
2573 \helpref{wxDbTable::Where}{wxdbtablewhere}
2574
2575
2576 \membersection{wxDbTable::Insert}\label{wxdbtableinsert}
2577
2578 \func{int }{Insert}{\void}
2579
2580 Inserts a new record into the table being referenced by this wxDbTable
2581 instance. The values in the member variables of the wxDbTable instance are
2582 inserted into the columns of the new row in the database.
2583
2584 \wxheading{Return value}
2585
2586 \begin{verbatim}
2587 DB_SUCCESS Record inserted successfully (value = 1)
2588
2589 DB_FAILURE Insert failed (value = 0)
2590
2591 DB_ERR_INTEGRITY_CONSTRAINT_VIOL
2592 The insert failed due to an integrity
2593 constraint violation (duplicate non-unique
2594 index entry) is attempted.
2595 \end{verbatim}
2596
2597 \wxheading{Remarks}
2598
2599 A \helpref{wxDb::CommitTrans}{wxdbcommittrans} or
2600 \helpref{wxDb::RollbackTrans}{wxdbrollbacktrans} must be called after use of
2601 this function to commit or rollback the insertion.
2602
2603 \wxheading{Example}
2604
2605 \begin{verbatim}
2606 // Incomplete code snippet
2607 strcpy(parts->PartName, "10");
2608 strcpy(parts->PartDesc, "Part #10");
2609 parts->Qty = 1000;
2610 RETCODE retcode = parts.Insert();
2611 switch(retcode)
2612 {
2613 case DB_SUCCESS:
2614 parts->GetDb()->CommitTrans();
2615 return(TRUE);
2616 case DB_ERR_INTEGRITY_CONSTRAINT_VIOL:
2617 // Current data would result in a duplicate key
2618 // on one or more indexes that do not allow duplicates
2619 parts->GetDb()->RollbackTrans();
2620 return(FALSE);
2621 default:
2622 // Insert failed for some unexpected reason
2623 parts->GetDb()->RollbackTrans();
2624 return(FALSE);
2625 }
2626 \end{verbatim}
2627
2628
2629 \membersection{wxDbTable::IsColNull}\label{wxdbtableiscolnull}
2630
2631 \func{bool}{IsColNull}{\param{int }{colNo}}
2632
2633 Used primarily in the ODBC class library to determine if a column is equal
2634 to "NULL". Works for all data types supported by the ODBC class library.
2635
2636 \wxheading{Parameters}
2637
2638 \docparam{colNo}{The column number of the bound column as defined by the
2639 \helpref{wxDbTable::SetColDefs}{wxdbtablesetcoldefs}
2640 calls which defined the columns accesible to this wxDbTable instance.}
2641
2642 \wxheading{Remarks}
2643
2644 NULL column support is currently not fully implemented as of wxWindows 2.4
2645
2646
2647 \membersection{wxDbTable::IsCursorClosedOnCommit}\label{wxdbtableiscursorclosedoncommit}
2648
2649 \func{bool}{IsCursorClosedOnCommit}{\void}
2650
2651 Accessor function to return information collected during the opening of the
2652 datasource connection that is used by this wxDbTable instance. The result
2653 returned by this function indicates whether an implicit closing of the curosr is
2654 done after a commit on the database connection.
2655
2656 \wxheading{Return value}
2657
2658 Returns TRUE if the cursor associated with this wxDbTable object is closed
2659 after a commit or rollback operation. Returns FALSE otherwise.
2660
2661 \wxheading{Remarks}
2662
2663 If more than one wxDbTable instance used the same database connection, all cursors
2664 which use the database connection are closed on the commit if this function
2665 indicates TRUE.
2666
2667
2668 \membersection{wxDbTable::IsQueryOnly}\label{wxdbtableisqueryonly}
2669
2670 \func{bool}{IsQueryOnly}{}
2671
2672 Accessor function that returns a value indicating if this wxDbTable instance
2673 was created to allow only queries to be performed on the bound columns. If
2674 this function returns TRUE, then no actions may be performed using this
2675 wxDbTable instance that would modify (insert/delete/update) the table's data.
2676
2677
2678 \membersection{wxDbTable::Open}\label{wxdbtableopen}
2679
2680 \func{bool}{Open}{\param{bool }{checkPrivileges=FALSE}}
2681
2682 Every wxDbTable instance must be opened before it can be used. This function
2683 checks for the existence of the requested table, binds columns, creates required
2684 cursors, (insert/select and update if connection is not wxDB_QUERY_ONLY) and
2685 constructs the insert statement that is to be used for inserting data as a new
2686 row in the datasource.
2687
2688 \wxheading{Parameters}
2689
2690 \docparam{checkPrivileges}{Indicates whether the Open() function should check
2691 whether the current connected user has at least SELECT privileges to access the
2692 table to which they are trying to open. Default is FALSE.}
2693
2694 \wxheading{Remarks}
2695
2696 If the function returns a FALSE value due to the table not existing, a log
2697 entry is recorded for the datasource connection indicating the problem
2698 that was detected when checking for table existence. Note that it is usually
2699 best for the calling routine to check for the existence of the table and for
2700 sufficent user privileges to access the table in the mode (wxDB_QUERY_ONLY or
2701 !wxDB_QUERY_ONLY) before trying to open the table for the best possible
2702 explanation as to why a table cannot be opened.
2703
2704 Checking the user's privileges on a table can be quite time consuming during
2705 the open phase. With most applications, the programmer already knows that the
2706 user has sufficient privileges to access the table, so this check is normally
2707 not required.
2708
2709 For best performance, open the table, and then use the
2710 \helpref{wxDb::TablePrivileges}{wxdbtableprivileges} function
2711 to check the users privileges. Passing a schema to the TablePrivileges()
2712 function can significantly speed up the privileges checks.
2713
2714 \wxheading{See also}
2715
2716 \helpref{wxDb::TableExists}{wxdbtableexists},
2717 \helpref{wxDb::TablePrivileges}{wxdbtableprivileges}
2718
2719
2720 \membersection{wxDbTable::OrderBy}\label{wxdbtableorderby}
2721
2722 \func{const char *}{OrderBy}{}
2723
2724 \func{void}{OrderBy}{\param{const wxString &}{OrderBy}}
2725
2726 Accessor function for the private class member wxDbTable::orderBy. Can be
2727 used as a synonym for \helpref{wxDbTable::GetOrderByClause}{wxdbtablegetorderbyclause}
2728 (the first form of this function) or \helpref{wxDbTable::SetOrderByClause}{wxdbtablesetorderbyclause}
2729 (the second form of this function).
2730
2731 \wxheading{Parameters}
2732
2733 \docparam{OrderBy}{A comma separated list of column names that indicate the
2734 alphabetized/numeric sorting sequence that the result set is to be returned
2735 in. If a FROM clause has also been specified, each column name specified in
2736 the ORDER BY clause should be prefaced with the table name to which the column
2737 belongs using DOT notation (TABLE_NAME.COLUMN_NAME).}
2738
2739 \wxheading{Return value}
2740
2741 The first form of this function returns the current value of the wxDbTable
2742 member variable ::orderBy.
2743
2744 The second form of the function has no return value.
2745
2746 \wxheading{See also}
2747
2748 \helpref{wxDbTable::GetOrderByClause}{wxdbtablegetorderbyclause},
2749 \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause}
2750
2751
2752 \membersection{wxDbTable::Query}\label{wxdbtablequery}
2753
2754 \func{virtual bool}{Query}{\param{bool }{forUpdate=FALSE}, \param{bool }{distinct=FALSE}}
2755
2756 \wxheading{Parameters}
2757
2758 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
2759 as they are retrieved. If the RDBMS is not capable of the FOR UPDATE clause,
2760 this argument is ignored. See
2761 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
2762 additional information regarding this argument. Default is FALSE.}
2763 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
2764 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
2765 applies to all columns returned in the result set, not individual columns.
2766 Default is FALSE.}
2767
2768 \wxheading{Remarks}
2769
2770 This function queries records from the datasource based on the three
2771 wxDbTable members: "where", "orderBy", and "from". Use
2772 \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause} to filter on
2773 records to be retrieved (e.g. All users with a first name of "JOHN").
2774 Use \helpref{wxDbTable::SetOrderByClause}{wxdbtablesetorderbyclause} to
2775 change the sequence in which records are returned in the result set from
2776 the datasource (e.g. Ordered by LAST_NAME). Use
2777 \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} to allow outer
2778 joining of the base table (the one being associated with this instance of
2779 wxDbTable) with other tables which share a related field.
2780
2781 After each of these clauses are set/cleared, call wxDbTable::Query() to
2782 fetch the result set from the datasource.
2783
2784 This scheme has an advantage if you have to requery your record set
2785 frequently in that you only have to set your WHERE, ORDER BY, and FROM
2786 clauses once. Then to refresh the record set, simply call wxDbTable::Query()
2787 as frequently as needed.
2788
2789 Note that repeated calls to wxDbTable::Query() may tax the database
2790 server and make your application sluggish if done too frequently or
2791 unnecessarily.
2792
2793 The base table name is automatically prepended to the base column names in
2794 the event that the FROM clause has been set (is non-null) using
2795 \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause}.
2796
2797 The cursor for the result set is positioned {\it before} the first record in
2798 the result set after the query. To retrieve the first record, call either
2799 \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} (only if backward scrolling
2800 cursors are available) or
2801 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}. Typically, no data from the
2802 result set is returned to the client driver until a request such as
2803 \helpref{wxDbTable::GetNext}{wxdbtablegetnext} is performed, so network
2804 traffic and database load are not overwhelmed transmitting data until the
2805 data is actually requested by the client. This behavior is solely dependent
2806 on the ODBC driver though, so refer to the ODBC driver's reference material
2807 for information on its behaviors.
2808
2809 Values in the bound columns' memory variables are undefined after executing a
2810 call to this function and remain that way until a row in the result set is
2811 requested to be returned.
2812
2813 The wxDbTable::Query() function is defined as "virtual" so that it may be
2814 overridden for application specific purposes.
2815
2816 \normalbox{Be sure to set the wxDbTable's "where", "orderBy", and "from"
2817 member variables to "" if they are not to be used in the query. Otherwise,
2818 the results returned may have unexpected results (or no results) due to
2819 improper or incorrect query parameters constructed from the uninitialized
2820 clauses.}
2821
2822 \wxheading{Example}
2823
2824 \begin{verbatim}
2825 // Incomplete code sample
2826 parts->SetWhereClause("DESCRIPTION = 'FOOD'");
2827 parts->SetOrderByClause("EXPIRATION_DATE");
2828 parts->SetFromClause("");
2829 // Query the records based on the where, orderBy and from clauses
2830 // specified above
2831 parts->Query();
2832 // Display all records queried
2833 while(parts->GetNext())
2834 dispPart(parts); // user defined function
2835 \end{verbatim}
2836
2837
2838 \membersection{wxDbTable::QueryBySqlStmt}\label{wxdbtablequerybysqlstmt}
2839
2840 \func{bool}{QueryBySqlStmt}{\param{const char *}{pSqlStmt}}
2841
2842 Performs a query against the datasource by accepting and passing verbatim the
2843 SQL SELECT statement passed to the function.
2844
2845 \wxheading{Parameters}
2846
2847 \docparam{pSqlStmt}{Pointer to the SQL SELECT statement to be executed.}
2848
2849 \wxheading{Remarks}
2850
2851 This is the most powerful form of the query functions available. This member
2852 function allows a programmer to write their own custom SQL SELECT statement
2853 for requesting data from the datasource. This gives the programmer access
2854 to the full power of SQL for performing operations such as scalar functions,
2855 aggregate functions, table joins, and sub-queries, as well as datasource
2856 specific function calls.
2857
2858 The requirements of the SELECT statement are the following:
2859
2860 \begin{verbatim}
2861 1. Must return the correct number of columns. In the derived
2862 wxDbTable constructor, it is specified how many columns are in
2863 the wxDbTable object. The SELECT statement must return exactly
2864 that many columns.
2865
2866 2. The columns must be returned in the same sequence as specified
2867 when defining the bounds columns using wxDbTable::SetColDefs(),
2868 and the columns returned must be of the proper data type. For
2869 example, if column 3 is defined in the wxDbTable bound column
2870 definitions to be a float, the SELECT statement must return a
2871 float for column 3 (e.g. PRICE * 1.10 to increase the price by
2872 10%).
2873
2874 3. The ROWID can be included in your SELECT statement as the {\bf last}
2875 column selected, if the datasource supports it. Use
2876 wxDbTable::CanUpdByROWID() to determine if the ROWID can be
2877 selected from the datasource. If it can, much better
2878 performance can be achieved on updates and deletes by including
2879 the ROWID in the SELECT statement.
2880 \end{verbatim}
2881
2882 Even though data can be selected from multiple tables (joins) in your select
2883 statement, only the base table associated with this wxDbTable object
2884 is automatically updated through the ODBC class library. Data from multiple
2885 tables can be selected for display purposes however. Include columns in
2886 the wxDbTable object and mark them as non-updateable (See
2887 \helpref{wxDbColDef}{wxdbcoldef} for details). This way columns can be
2888 selected and displayed from other tables, but only the base table will be
2889 updated automatically when performed through the
2890 \helpref{wxDbTable::Update}{wxdbtableupdate} function after using this type of
2891 query. To update tables other than the base table, use the
2892 \helpref{wxDbTable::Update}{wxdbtableupdate} function passing a SQL statement.
2893
2894 After this function has been called, the cursor is positioned before the
2895 first record in the record set. To retrieve the first record, call
2896 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
2897 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
2898
2899 \wxheading{Example}
2900
2901 \begin{verbatim}
2902 // Incomplete code samples
2903 strcpy(sqlStmt, "SELECT * FROM PARTS WHERE STORAGE_DEVICE = 'SD98' \
2904 AND CONTAINER = 12");
2905 // Query the records using the SQL SELECT statement above
2906 parts->QueryBySqlStmt(sqlStmt);
2907 // Display all records queried
2908 while(parts->GetNext())
2909 dispPart(&parts);
2910
2911 Example SQL statements
2912 ----------------------
2913
2914 // Table Join returning 3 columns
2915 SELECT part_no, part_desc, sd_name
2916 from parts, storage_devices
2917 where parts.storage_device_id =
2918 storage_devices.storage_device_id
2919
2920 // Aggregate function returning total number of
2921 // parts in container 99
2922 SELECT count(*) from PARTS where container = 99
2923
2924 // Order by clause; ROWID, scalar function
2925 SELECT part_no, substring(part_desc, 1, 10), qty_on_hand + 1, ROWID
2926 from parts
2927 where warehouse = 10
2928 order by part_no desc // descending order
2929
2930 // Subquery
2931 SELECT * from parts
2932 where container in (select container
2933 from storage_devices
2934 where device_id = 12)
2935 \end{verbatim}
2936
2937
2938 \membersection{wxDbTable::QueryMatching}\label{wxdbtablequerymatching}
2939
2940 \func{virtual bool}{QueryMatching}{\param{bool }{forUpdate=FALSE}, \param{bool }{distinct=FALSE}}
2941
2942 QueryMatching allows querying of records from the table associated with
2943 the wxDbTable object by matching "columns" to values.
2944
2945 For example: To query the datasource for the row with a PART_NUMBER column
2946 value of "32", clear all column variables of the wxDbTable object, set the
2947 PartNumber variable that is bound to the PART_NUMBER column in the wxDbTable
2948 object to "32", and then call wxDbTable::QueryMatching().
2949
2950 \wxheading{Parameters}
2951
2952 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
2953 as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
2954 the FOR UPDATE clause, this argument is ignored. See
2955 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
2956 additional information regarding this argument. Default is FALSE.}
2957 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
2958 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
2959 applies to all columns returned in the result set, not individual columns.
2960 Default is FALSE.}
2961
2962 \wxheading{Remarks}
2963
2964 The SQL WHERE clause is built by the ODBC class library based on all
2965 non-zero/non-NULL columns in your wxDbTable object. Matches can be on one,
2966 many or all of the wxDbTable's columns. The base table name is prepended
2967 to the column names in the event that the wxDbTable's FROM clause is non-null.
2968
2969 This function cannot be used to perform queries which will check for
2970 columns that are 0 or NULL, as the automatically constructed WHERE clause
2971 only will contain comparisons on column member variables that are
2972 non-zero/non-NULL.
2973
2974 The primary difference between this function and \helpref{wxDbTable::QueryOnKeyFields}{wxdbtablequeryonkeyfields}
2975 is that this function can query on any column(s) in the wxDbTable object.
2976 Note however that this may not always be very efficient. Searching on
2977 non-indexed columns will always require a full table scan.
2978
2979 The cursor is positioned before the first record in the record set after
2980 the query is performed. To retrieve the first record, the program must call
2981 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
2982 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
2983
2984 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
2985 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
2986 this function.
2987
2988 \wxheading{Example}
2989
2990 \begin{verbatim}
2991 // Incomplete code sample
2992 parts->ClearMemberVars(); // Set all columns to zero
2993 strcpy(parts->PartNumber,"32"); // Set columns to query on
2994 parts->OnHold = TRUE;
2995 parts->QueryMatching(); // Query
2996 // Display all records queried
2997 while(parts->GetNext())
2998 dispPart(parts); // Some application defined function
2999 \end{verbatim}
3000
3001
3002 \membersection{wxDbTable::QueryOnKeyFields}\label{wxdbtablequeryonkeyfields}
3003
3004 \func{bool}{QueryOnKeyFields}{\param{bool }{forUpdate=FALSE}, \param{bool }{distinct=FALSE}}
3005
3006 QueryOnKeyFields provides an easy mechanism to query records in the table
3007 associated with the wxDbTable object by the primary index column(s). Simply
3008 assign the primary index column(s) values and then call this member function
3009 to retrieve the record.
3010
3011 Note that since primary indexes are always unique, this function implicitly
3012 always returns a single record from the database. The base table name is
3013 prepended to the column names in the event that the wxDbTable's FROM clause
3014 is non-null.
3015
3016 \wxheading{Parameters}
3017
3018 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
3019 as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
3020 the FOR UPDATE clause, this argument is ignored. See
3021 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
3022 additional information regarding this argument. Default is FALSE.}
3023 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
3024 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
3025 applies to all columns returned in the result set, not individual columns.
3026 Default is FALSE.}
3027
3028 \wxheading{Remarks}
3029
3030 The cursor is positioned before the first record in the record set after
3031 the query is performed. To retrieve the first record, the program must call
3032 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
3033 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
3034
3035 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
3036 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
3037 this function.
3038
3039 \wxheading{Example}
3040
3041 \begin{verbatim}
3042 // Incomplete code sample
3043 strcpy(parts->PartNumber, "32");
3044 parts->QueryOnKeyFields();
3045 // Display all records queried
3046 while(parts->GetNext())
3047 dispPart(parts); // Some application defined function
3048 \end{verbatim}
3049
3050
3051 \membersection{wxDbTable::Refresh}\label{wxdbtablerefresh}
3052
3053 \func{bool}{Refresh}{\void}
3054
3055 This function re-reads the bound columns into the memory variables, setting
3056 them to the current values stored on the disk.
3057
3058 The cursor position and result set are unaffected by calls to this function.
3059 (The one exception is in the case where the record to be refreshed has been
3060 deleted by some other user or transaction since it was originally retrieved
3061 as part of the result set. For most datasources, the default behavior in
3062 this situation is to return the value that was originally queried for the
3063 result set, even though it has been deleted from the database. But this is
3064 datasource dependent, and should be tested before relying on this behavior.)
3065
3066 \wxheading{Remarks}
3067
3068 This routine is only guaranteed to work if the table has a unique primary
3069 index defined for it. Otherwise, more than one record may be fetched and
3070 there is no guarantee that the correct record will be refreshed. The
3071 table's columns are refreshed to reflect the current data in the database.
3072
3073
3074 \membersection{wxDbTable::SetColDefs}\label{wxdbtablesetcoldefs}
3075
3076 \func{void}{SetColDefs}{\param{int }{index}, \param{const char *}{fieldName}, \param{int }{dataType}, \param{void *}{pData}, \param{int }{cType}, \param{int }{size}, \param{bool }{keyField = FALSE}, \param{bool }{upd = TRUE}, \param{bool }{insAllow = TRUE}, \param{bool }{derivedCol = FALSE}}
3077
3078 \func{wxDbColDataPtr *}{SetColDefs}{\param{wxDbColInf *}{colInfs}, \param{ULONG }{numCols}}
3079
3080 \wxheading{Parameters}
3081
3082 \docparam{index}{Column number (0 to n-1, where n is the number of columns
3083 specified as being defined for this wxDbTable instance when the
3084 wxDbTable constructor was called.}
3085 \docparam{fieldName}{Column name from the associated data table.}
3086 \docparam{dataType}{Logical data type. Valid logical types include:}
3087
3088 \begin{verbatim}
3089 DB_DATA_TYPE_VARCHAR : strings
3090 DB_DATA_TYPE_INTEGER : non-floating point numbers
3091 DB_DATA_TYPE_FLOAT : floating point numbers
3092 DB_DATA_TYPE_DATE : dates
3093 \end{verbatim}
3094
3095 \docparam{pData}{Pointer to the data object that will hold the column's
3096 value when a row of data is returned from the datasource.}
3097 \docparam{cType}{SQL C Type. This defines the data type that the SQL
3098 representation of the data is converted to to be stored in {\it pData}.
3099 Other valid types are available also, but these are the most common ones:}
3100
3101 \begin{verbatim}
3102 SQL_C_CHAR // strings
3103 SQL_C_LONG
3104 SQL_C_ULONG
3105 SQL_C_SHORT
3106 SQL_C_USHORT
3107 SQL_C_FLOAT
3108 SQL_C_DOUBLE
3109 SQL_C_NUMERIC
3110 SQL_C_TIMESTAMP
3111
3112 SQL_C_BOOLEAN // defined in db.h
3113 SQL_C_ENUM // defined in db.h
3114 \end{verbatim}
3115
3116 \docparam{size}{Maximum size in bytes of the {\it pData} object.}
3117 \docparam{keyField}{{\it OPTIONAL}. Indicates if this column is part of the
3118 primary index. Default is FALSE.}
3119 \docparam{upd}{{\it OPTIONAL}. Are updates allowed on this column?
3120 Default is TRUE.}
3121 \docparam{insAllow}{{\it OPTIONAL}. Inserts allowed on this column?
3122 Default is TRUE.}
3123 \docparam{derivedCol}{{\it OPTIONAL}. Is this a derived column (non-base
3124 table column for query only)? Default is FALSE.}
3125
3126 \docparam{colInfs}{Pointer to an array of wxDbColInf instances which contains
3127 all the information necessary to create {\it numCols} column definitions.}
3128 \docparam{numCols}{Number of elements of wxDbColInf type that are pointed
3129 to by {\it colInfs}, which are to have column definitions created from them.}
3130
3131 \wxheading{Remarks}
3132
3133 If {\it pData} is to hold a string of characters, be sure to include enough
3134 space for the NULL terminator in pData and in the byte count of {\it size}.
3135
3136 Both forms of this function provide a shortcut for defining the columns in
3137 your wxDbTable object. Use this function in any derived wxDbTable
3138 constructor when describing the column/columns in the wxDbTable object.
3139
3140 The second form of this function is primarily used when the
3141 \helpref{wxDb::GetColumns}{wxdbgetcolumns} function was used to query the
3142 datasource for the column definitions, so that the column definitions are
3143 already stored in wxDbColInf form. One example use of using
3144 \helpref{wxDb::GetColumns}{wxdbgetcolumns} then using this function is if
3145 a data table existed in one datasource, and the table's column definitions
3146 were to be copied over to another datasource or table.
3147
3148 \wxheading{Example}
3149
3150 \begin{verbatim}
3151 // Long way not using this function
3152 strcpy(colDefs[0].ColName, "PART_NO");
3153 colDefs[0].DbDataType = DB_DATA_TYPE_VARCHAR;
3154 colDefs[0].PtrDataObj = PartNumber;
3155 colDefs[0].SqlCtype = SQL_C_CHAR;
3156 colDefs[0].SzDataObj = PART_NUMBER_LEN;
3157 colDefs[0].KeyField = TRUE;
3158 colDefs[0].Updateable = FALSE;
3159 colDefs[0].InsertAllowed= TRUE;
3160 colDefs[0].DerivedCol = FALSE;
3161
3162 // Shortcut using this function
3163 SetColDefs(0, "PART_NUMBER", DB_DATA_TYPE_VARCHAR, PartNumber,
3164 SQL_C_CHAR, PART_NUMBER_LEN, TRUE, FALSE,TRUE,FALSE);
3165 \end{verbatim}
3166
3167
3168 \membersection{wxDbTable::SetCursor}\label{wxdbtablesetcursor}
3169
3170 \func{bool}{SetCursor}{\param{HSTMT *}{hstmtActivate = (void **) wxDB_DEFAULT_CURSOR}}
3171
3172 \wxheading{Parameters}
3173
3174 \docparam{hstmtActivate}{{\it OPTIONAL}. Pointer to the cursor that is to
3175 become the current cursor. Passing no cursor handle will reset the cursor
3176 back to the wxDbTable's default (original) cursor that was created when the
3177 wxDbTable instance was first created. Default is wxDB_DEFAULT_CURSOR.}
3178
3179 \wxheading{Remarks}
3180
3181 When swapping between cursors, the member variables of the wxDbTable object
3182 are automatically refreshed with the column values of the row that the
3183 current cursor is positioned at (if any). If the cursor is not positioned,
3184 then the data in member variables is undefined.
3185
3186 The only way to return back to the cursor that was in use before this
3187 function was called is to programmatically determine the current cursor's HSTMT
3188 {\bf BEFORE} calling this function using \helpref{wxDbTable::GetCursor}{wxdbtablegetcursor}
3189 and saving a pointer to that cursor.
3190
3191 \wxheading{See also}
3192
3193 \helpref{wxDbTable::GetNewCursor}{wxdbtablegetnewcursor}, \helpref{wxDbTable::GetCursor}{wxdbtablegetcursor},
3194 \helpref{wxDbTable::SetCursor}{wxdbtablesetcursor}
3195
3196
3197 \membersection{wxDbTable::SetFromClause}\label{wxdbtablesetfromclause}
3198
3199 \func{void}{SetFromClause}{\param{const wxString &}{From}}
3200
3201 Accessor function for setting the private class member wxDbTable::from
3202 that indicates what other tables should be outer joined with the wxDbTable's
3203 base table for access to the columns in those other tables.
3204
3205 Synonym to this function is one form of \helpref{wxDbTable::From}{wxdbtablefrom}
3206
3207 \wxheading{Parameters}
3208
3209 \docparam{From}{A comma separated list of table names that are to be outer
3210 joined with the base table's columns so that the joined table's columns
3211 may be returned in the result set or used as a portion of a comparison with
3212 the base table's columns. NOTE that the base tables name must NOT be included
3213 in the FROM clause, as it is automatically included by the wxDbTable class
3214 in constructing query statements.}
3215
3216 \wxheading{Remarks}
3217
3218 Used by the \helpref{wxDbTable::Query}{wxdbtablequery} and
3219 \helpref{wxDbTable::Count}{wxdbtablecount} member functions to allow outer
3220 joining of records from multiple tables.
3221
3222 Do {\bf not} include the keyword "FROM" when setting the FROM clause.
3223
3224 If using the FROM clause when performing a query, be certain to include in
3225 the corresponding WHERE clause a comparison of a column from either the base
3226 table or one of the other joined tables to each other joined table to ensure
3227 the datasource knows on which column values the tables should be joined on.
3228
3229 \wxheading{Example}
3230
3231 \begin{verbatim}
3232 ...
3233 // Base table is the "LOCATION" table, and it is being
3234 // outer joined to the "PART" table via the the field "PART_NUMBER"
3235 // that can be related between the two tables.
3236 location->SetWhereClause("LOCATION.PART_NUMBER = PART.PART_NUMBER")
3237 location->SetFromClause("PART");
3238 ...
3239 \end{verbatim}
3240
3241 \wxheading{See also}
3242
3243 \helpref{wxDbTable::From}{wxdbtablefrom},
3244 \helpref{wxDbTable::GetFromClause}{wxdbtablegetfromclause}
3245
3246
3247 \membersection{wxDbTable::SetColNull}\label{wxdbtablesetcolnull}
3248
3249 \func{bool}{SetColNull}{\param{int }{colNo}, \param{bool }{set=TRUE}}
3250
3251 \func{bool}{SetColNull}{\param{const char *}{colName}, \param{bool }{set=TRUE}}
3252
3253 Both forms of this function allow a member variable representing a column
3254 in the table associated with this wxDbTable object to be set to NULL.
3255
3256 The first form allows the column to be set by the index into the column
3257 definitions used to create the wxDbTable instance, while the second allows
3258 the actual column name to be specified.
3259
3260 \wxheading{Parameters}
3261
3262 \docparam{colNo}{Index into the column definitions used when first defining
3263 this wxDbTable object.}
3264 \docparam{colName}{Actual data table column name that is to be set to NULL.}
3265 \docparam{set}{Whether the column is set to NULL or not. Passing TRUE sets
3266 the column to NULL, passing FALSE sets the column to be non-NULL. Default is
3267 TRUE.}
3268
3269
3270 \wxheading{Remarks}
3271
3272 No database updates are done by this function. It only operates on the
3273 member variables in memory. Use and insert or update function to store this
3274 value to disk.
3275
3276
3277 \membersection{wxDbTable::SetOrderByClause}\label{wxdbtablesetorderbyclause}
3278
3279 \func{void}{SetOrderByClause}{\param{const wxString &}{OrderBy}}
3280
3281 Accessor function for setting the private class member wxDbTable::orderBy
3282 which determines sequence/ordering of the rows returned in the result set
3283 of a query.
3284
3285 A synonym to this function is one form of the function \helpref{wxDbTable::OrderBy}{wxdbtableorderby}
3286
3287 \wxheading{Parameters}
3288
3289 \docparam{OrderBy}{A comma separated list of column names that indicate the
3290 alphabetized sorting sequence that the result set is to be returned in. If
3291 a FROM clause has also been specified, each column name specified in the
3292 ORDER BY clause should be prefaced with the table name to which the column
3293 belongs using DOT notation (TABLE_NAME.COLUMN_NAME).}
3294
3295 \wxheading{Remarks}
3296
3297 Do {\bf not} include the keywords "ORDER BY" when setting the ORDER BY clause.
3298
3299 \wxheading{Example}
3300
3301 \begin{verbatim}
3302 ...
3303 parts->SetOrderByClause("PART_DESCRIP, QUANTITY");
3304 ...
3305
3306 ...
3307 location->SetOrderByClause("LOCATION.POSITION, PART.PART_NUMBER);
3308 ...
3309 \end{verbatim}
3310
3311 \wxheading{See also}
3312
3313 \helpref{wxDbTable::OrderBy}{wxdbtableorderby},
3314 \helpref{wxDbTable::GetOrderByClause}{wxdbtablegetorderbyclause}
3315
3316
3317 \membersection{wxDbTable::SetQueryTimeout}\label{wxdbtablesetquerytimeout}
3318
3319 \func{bool}{SetQueryTimeout}{\param{UDWORD }{nSeconds}}
3320
3321 Allows a time period to be set as the timeout period for queries.
3322
3323 \wxheading{Parameters}
3324
3325 \docparam{nSeconds}{The number of seconds to wait for the query to complete
3326 before timing out.}
3327
3328 \wxheading{Remarks}
3329
3330 Neither Oracle or Access support this function as of yet. Other databases
3331 should be evaluated for support before depending on this function working
3332 correctly.
3333
3334
3335 \membersection{wxDbTable::SetWhereClause}\label{wxdbtablesetwhereclause}
3336
3337 \func{void}{SetWhereClause}{\param{const wxString &}{Where}}
3338
3339 Accessor function for setting the private class member wxDbTable::where
3340 that determines which rows are returned in the result set by the datasource.
3341
3342 A synonym to this function is one form of the function \helpref{wxDbTable::Where}{wxdbtablewhere}
3343
3344 \wxheading{Parameters}
3345
3346 \docparam{Where}{SQL "where" clause. This clause can contain any SQL language
3347 that is legal in standard where clauses. If a FROM clause has also been
3348 specified, each column name specified in the ORDER BY clause should be
3349 prefaced with the table name to which the column belongs using DOT notation
3350 (TABLE_NAME.COLUMN_NAME).}
3351
3352 \wxheading{Remarks}
3353
3354 Do {\bf not} include the keywords "WHERE" when setting the WHERE clause.
3355
3356 \wxheading{Example}
3357
3358 \begin{verbatim}
3359 ...
3360 // Simple where clause
3361 parts->SetWhereClause("PART_NUMBER = '32'");
3362 ...
3363 // Any comparison operators
3364 parts->SetWhereClause("PART_DESCRIP LIKE 'HAMMER%'");
3365 ...
3366 // Multiple comparisons, including a function call
3367 parts->Where("QTY > 0 AND {fn UCASE(PART_DESCRIP)} LIKE '%DRILL%'");
3368 ...
3369 // Using parameters and multiple logical combinations
3370 parts->Where("((QTY > 10) OR (ON_ORDER > 0)) AND ON_HOLD = 0");
3371 ...
3372 // This query uses an outer join (requiring a FROM clause also)
3373 // that joins the PART and LOCATION table on he common field
3374 // PART_NUMBER.
3375 parts->Where("PART.ON_HOLD = 0 AND \
3376 PART.PART_NUMBER = LOCATION.PART_NUMBER AND \
3377 LOCATION.PART_NUMBER > 0");
3378 \end{verbatim}
3379
3380 \wxheading{See also}
3381
3382 \helpref{wxDbTable::Where}{wxdbtablewhere},
3383 \helpref{wxDbTable::GetWhereClause}{wxdbtablegetwhereclause}
3384
3385
3386 \membersection{wxDbTable::Update}\label{wxdbtableupdate}
3387
3388 \func{bool}{Update}{\void}
3389
3390 \func{bool}{Update}{\param{const char *}{pSqlStmt}}
3391
3392 The first form of this function will update the row that the current cursor
3393 is currently positioned at with the values in the memory variables that
3394 are bound to the columns. The actual SQL statement to perform the update
3395 is automatically created by the ODBC class, and then executed.
3396
3397 The second form of the function allows full access through SQL statements for
3398 updating records in the database. Write any valid SQL UPDATE statement and
3399 submit it to this function for execution. Sophisticated updates can be
3400 performed using the full power of the SQL dialect. The full SQL statement
3401 must have the exact syntax required by the driver/datasource for performing
3402 the update. This usually is in the form of:
3403
3404 \begin{verbatim}
3405 UPDATE tablename SET col1=X, col2=Y, ... where ...
3406 \end{verbatim}
3407
3408 \wxheading{Parameters}
3409
3410 \docparam{pSqlStmt}{Pointer to SQL UPDATE statement to be executed.}
3411
3412 \wxheading{Remarks}
3413
3414 A \helpref{wxDb::CommitTrans}{wxdbcommittrans} or
3415 \helpref{wxDb::RollbackTrans}{wxdbrollbacktrans} must be called after use of
3416 this function to commit or rollback the update.
3417
3418 \wxheading{Example}
3419
3420 \begin{verbatim}
3421 strcpy(sqlStmt, "update PART set QTY = 0 where PART_NUMBER = '32'");
3422 \end{verbatim}
3423
3424
3425 \membersection{wxDbTable::UpdateWhere}\label{wxdbtableupdatewhere}
3426
3427 \func{bool}{UpdateWhere}{\param{const char *}{pWhereClause}}
3428
3429 Performs updates to the base table of the wxDbTable object, updating only the
3430 rows which match the criteria specified in the {\it pWhereClause}.
3431
3432 All columns that are bound to member variables for this wxDbTable instance
3433 that were defined with the "updateable" parameter set to TRUE will be updated
3434 with the information currently held in the memory variable.
3435
3436 \wxheading{Parameters}
3437
3438 \docparam{pWhereClause}{Pointer to a valid SQL WHERE clause. Do not
3439 include the keyword 'WHERE'.}
3440
3441 \wxheading{Remarks}
3442
3443 Care should be used when updating columns that are part of indexes with
3444 this function so as not to violate an unique key constraints.
3445
3446 A \helpref{wxDb::CommitTrans}{wxdbcommittrans} or
3447 \helpref{wxDb::RollbackTrans}{wxdbrollbacktrans} must be called after use of
3448 this function to commit or rollback the update(s).
3449
3450
3451 \membersection{wxDbTable::Where}\label{wxdbtablewhere}
3452
3453 \func{const char *}{Where}{}
3454
3455 \func{void}{Where}{\param{const wxString& }{Where}}
3456
3457 Accessor function for the private class member wxDbTable::where. Can be used
3458 as a synonym for \helpref{wxDbTable::GetWhereClause}{wxdbtablegetwhereclause}
3459 (the first form of this function) to return the current where clause or
3460 \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause} (the second form
3461 of this function) to set the where clause for this table instance.
3462
3463 \wxheading{Parameters}
3464
3465 \docparam{Where}{A valid SQL WHERE clause. Do not include the keyword 'WHERE'.}
3466
3467 \wxheading{Return value}
3468
3469 The first form of this function returns the current value of the wxDbTable
3470 member variable ::where.
3471
3472 The second form of the function has no return value, as it will always set
3473 the where clause successfully.
3474
3475 \wxheading{See also}
3476
3477 \helpref{wxDbTable::GetWhereClause}{wxdbtablegetwhereclause},
3478 \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
3479
3480
3481
3482 \membersection{wxDbTable::operator $++$}\label{wxdbtableplusplus}
3483
3484 \func{bool}{operator $++$}{\void}
3485
3486 Synonym for \helpref{wxDbTable::GetNext}{wxdbtablegetnext}
3487
3488 \wxheading{See also}
3489
3490 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}
3491
3492
3493 \membersection{wxDbTable::operator $--$}\label{wxdbtableminusminus}
3494
3495 \func{bool}{operator $--$}{\void}
3496
3497 Synonym for \helpref{wxDbTable::GetPrev}{wxdbtablegetprev}
3498
3499 \wxheading{See also}
3500
3501 \helpref{wxDbTable::GetPrev}{wxdbtablegetprev}
3502
3503
3504 \section{\class{wxDbTableInf}}\label{wxdbtableinf}
3505
3506 \begin{verbatim}
3507 tableName[0] = 0;
3508 tableType[0] = 0;
3509 tableRemarks[0] = 0;
3510 numCols = 0;
3511 pColInf = NULL;
3512 \end{verbatim}
3513
3514
3515 Currently only used by \helpref{wxDb::GetCatalog}{wxdbgetcatalog} internally
3516 and \helpref{wxDbInf}{wxdbinf} class, but may be used in future releases for
3517 user functions. Contains information describing the table (Name, type, etc).
3518 A pointer to a wxDbColInf array instance is included so a program can create a
3519 \helpref{wxDbColInf}{wxdbcolinf} array instance (using \helpref{wxDb::GetColumns}{wxdbgetcolumns})
3520 to maintain all information about the columns of a table in one memory
3521 structure.
3522