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