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