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