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