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