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