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