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