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