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