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