1 \section{\class{wxDb
}}\label{wxdb
}
3 A wxDb instance is a connection to an ODBC datasource which may
4 be opened, closed, and re-opened an unlimited number of times. A
5 database connection allows function to be performed directly on the
6 datasource, as well as allowing access to any tables/views defined in
7 the datasource to which the user has sufficient privileges.
9 See the
\helpref{database classes overview
}{odbcoverview
} for
10 an introduction to using the ODBC classes.
12 \wxheading{Include files
}
16 \wxheading{Helper classes and data structures
}
18 The following classes and structs are defined in db.cpp/.h for use with the wxDb class.
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
}
29 NOTE: In a future release, all ODBC class constants will be prefaced with 'wx'.
32 wxDB_PATH_MAX Maximum path length allowed to be passed to
33 the ODBC driver to indicate where the data
36 DB_MAX_COLUMN_NAME_LEN Maximum supported length for the name of a
39 DB_MAX_ERROR_HISTORY Maximum number of error messages retained in
40 the queue before being overwritten by new
43 DB_MAX_ERROR_MSG_LEN Maximum supported length of an error message
44 returned by the ODBC classes
46 DB_MAX_STATEMENT_LEN Maximum supported length for a complete SQL
47 statement to be passed to the ODBC driver
49 DB_MAX_TABLE_NAME_LEN Maximum supported length for the name of a
52 DB_MAX_WHERE_CLAUSE_LEN Maximum supported WHERE clause length that
53 can be passed to the ODBC driver
55 DB_TYPE_NAME_LEN Maximum length of the name of a column's
59 \subsection{Enumerated types
}\label{wxdbenumeratedtypes
}
61 \wxheading{Enumerated types
}
63 \docparam{enum
{\bf wxDbSqlLogState
}}{sqlLogOFF, sqlLogON
}
65 {\it enum
{\bf wxDBMS
}}
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.
72 dbmsSYBASE_ASA // Adaptive Server Anywhere
73 dbmsSYBASE_ASE // Adaptive Server Enterprise
85 See the remarks in
\helpref{wxDb::Dbms
}{wxdbdbms
} for exceptions/issues with each of these database engines.
87 \wxheading{Public member variables
}
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.
}
91 \docparam{int
{\bf wxDb::DB
\_STATUS}}{The last ODBC error/status that occurred on this data connection. Possible codes are:
}
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'
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
193 \helpref{wxDbTable::IsCursorClosedOnCommit
}{wxdbtableiscursorclosedoncommit
})
194 have been added for ease of use.
}
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
206 wxChar procedureSupport
[2] - Does datasource support stored
208 UWORD maxConnections - Maximum # of connections datasource
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
215 UWORD cursorRollbackBehavior - How cursors are affected on db
217 UWORD supportNotNullClause - Does datasource support NOT NULL
219 wxChar supportIEF
[2] - Integrity Enhancement Facility (Ref.
221 UDWORD txnIsolation - Transaction isolation level supported by
223 UDWORD txnIsolationOptions - Transaction isolation level options
225 UDWORD fetchDirections - Fetch directions supported
226 UDWORD lockTypes - Lock types supported in SQLSetPos
227 UDWORD posOperations - Position operations supported in
229 UDWORD posStmts - Position statements supported
230 UDWORD scrollConcurrency - Scrollable cursor concurrency options
232 UDWORD scrollOptions - Scrollable cursor options supported
233 UDWORD staticSensitivity - Can additions/deletions/updates be
235 UWORD txnCapable - Indicates if datasource supports
237 UDWORD loginTimeout - Number seconds to wait for a login
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.
}
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.
}
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.
248 Used for reporting ODBC errors.
}
250 \docparam{wxChar
{\bf wxDb::sqlState
}[20]}{Set by wxDb::TranslateSqlState().
251 Indicates the error state after a failed ODBC operation. Used for reporting
256 Default cursor scrolling is defined by wxODBC
\_FWD\_ONLY\_CURSORS in setup.h
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
}).
259 Default setting of this value TRUE, as not all databases/drivers support
260 both types of cursors.
264 \helpref{wxDbColFor
}{wxdbcolfor
},
\helpref{wxDbColInf
}{wxdbcolinf
},
265 \helpref{wxDbTable
}{wxdbtable
},
\helpref{wxDbTableInf
}{wxdbtableinf
},
266 \helpref{wxDbInf
}{wxdbinf
}
268 \subsection{Associated non-class functions
}\label{wxdbfunctions
}
270 The following functions are used in conjunction with the wxDb class.
272 \func{void
}{wxDbCloseConnections
}{\void}
276 Closes all cached connections that have been made through use of the
277 \helpref{wxDbGetConnection
}{wxdbfunctions
} function.
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
282 the connections have been closed.
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
290 \func{int
}{wxDbConnectionsInUse
}{\void}
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
}
299 \func{bool
}{wxDbFreeConnection
}{\param{wxDb *
}{pDb
}}
303 Searches the list of cached database connections connection for one matching
304 the passed in wxDb instance. If found, that cached connection is freed.
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
313 \func{wxDb *
}{wxDbGetConnection
}{\param{wxDbConnectInf *
}{pDbConfig
},
314 \param{bool
}{FwdOnlyCursors=(bool)wxODBC
\_FWD\_ONLY\_CURSORS}}
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
}).
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
327 the wxDb instance is returned.
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
332 given in
{\it'pDbConfig'
}.
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
343 network traffic, database load, and connection creation time.
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
349 later in the program when the cache is cleaned up.
351 When exiting the program, call wxDbCloseConnections() to close all the
352 cached connections created by calls to wxDbGetConnection().
355 \func{const wxChar *
}{wxDbLogExtendedErrorMsg
}{\param{const wxChar *
}{userText
},
\param{wxDb *
}{pDb
},
\param{wxChar *
}{ErrFile
},
\param{int
}{ErrLine
}}
357 Writes a message to the wxLog window (stdout usually) when an internal
358 error situation occurs. This function only works in DEBUG builds
360 \func{bool
}{wxDbSqlLog
}{\param{wxDbSqlLogState
}{state
},
\param{const wxString \&
}{filename = SQL
\_LOG\_FILENAME}}
364 This function sets the sql log state for all open wxDb objects
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}}
370 This routine queries the ODBC driver manager for a list of available
371 datasources. Repeatedly call this function to obtain all the datasources
372 available through the ODBC driver manager on the current workstation.
375 wxStringList strList;
377 while (wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, SQL_MAX_DSN_LENGTH+
1, DsDesc,
255))
381 \latexignore{\rtfignore{\wxheading{Members
}}}
383 \membersection{wxDb::wxDb
}\label{wxdbconstr
}
389 \func{}{wxDb
}{\param{const HENV \&
}{aHenv
},
\param{bool
}{FwdOnlyCursors=(bool)wxODBC
\_FWD\_ONLY\_CURSORS}}
391 Constructor, used to create an ODBC connection to a datasource.
393 \wxheading{Parameters
}
395 \docparam{aHenv
}{Environment handle used for this connection. See
396 \helpref{wxDConnectInf::AllocHenv
}{wxdbconnectinfallochenv
}}
398 \docparam{FwdOnlyCursors
}{Will cursors created for use with this datasource
399 connection only allow forward scrolling cursors.
}
403 This is the constructor for the wxDb class. The wxDb object must
404 be created and opened before any database activity can occur.
409 wxDbConnectInf ConnectInf;
410 ....Set values for member variables of ConnectInf here
412 wxDb sampleDB(ConnectInf.GetHenv());
413 if (!sampleDB.Open(ConnectInf.GetDsn(), ConnectInf.GetUserID(),
414 ConnectInf.GetPassword()))
416 // Error opening datasource
422 \helpref{wxDbGetConnection
}{wxdbfunctions
}
424 \membersection{wxDb::Catalog
}\label{wxdbcatalog
}
426 \func{bool
}{Catalog
}{\param{wxChar *
}{ userID
},
\param{const wxString \&
}{fileName =
427 SQL
\_CATALOG\_FILENAME}}
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
433 \wxheading{Parameters
}
435 \docparam{userID
}{Database user name to use in accessing the database. All
436 tables to which this user has rights will be evaluated in the catalog.
}
438 \docparam{fileName
}{{\it OPTIONAL
}. Name of the text file to create and write
439 the DB catalog to. Default is SQL
\_CATALOG\_FILENAME.
}
441 \wxheading{Return value
}
443 Returns TRUE if the catalog request was successful, or FALSE if there was some
444 reason that the catalog could not be generated.
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
460 \membersection{wxDb::Close
}\label{wxdbclose
}
462 \func{void
}{Close
}{\void}
464 Closes the database connection.
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.
472 Any wxDbTable instances which use this connection must be deleted before
473 closing the database connection.
478 // Commit any open transactions on the datasource
479 sampleDB.CommitTrans();
481 // Delete any remaining wxDbTable objects allocated with new
484 // Close the wxDb connection when finished with it
489 \membersection{wxDb::CommitTrans
}\label{wxdbcommittrans
}
491 \func{bool
}{CommitTrans
}{\void}
493 Permanently "commits" changes (insertions/deletions/updates) to the database.
495 \wxheading{Return value
}
497 Returns TRUE if the commit was successful, or FALSE if the commit failed.
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"
505 them by calling this function.
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
513 Until a call to wxDb::CommitTrans() is made, no other user or cursor is able
514 to see any changes made to the row(s) that have been inserted/modified/deleted.
517 \wxheading{Special Note :
{\it Cursors
} }
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
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
536 that leave the cursors open after a transaction.
}
539 \membersection{wxDb::CreateView
}\label{wxdbcreateviews
}
541 \func{bool
}{CreateView
}{\param{const wxString \&
}{ viewName
},
542 \param{const wxString \&
}{ colList
},
\param{const wxString \&
}{pSqlStmt
}}
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
546 only Oracle as of November
21 2000).
548 \wxheading{Parameters
}
550 \docparam{viewName
}{The name of the view. e.g. PARTS
\_V}
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
555 table(s) will be used.
}
557 \docparam{pSqlStmt
}{Pointer to the select statement portion of the CREATE
558 VIEW statement. Must be a complete, valid SQL SELECT statement.
}
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
564 any other table in the database.
566 NOTE: Views are not available with all datasources. Oracle is one example
567 of a datasource which does support views.
572 // Incomplete code sample
573 db.CreateView("PARTS_SD1", "PN, PD, QTY",
574 "SELECT PART_NO, PART_DESC, QTY_ON_HAND *
1.1 FROM PARTS \
575 WHERE STORAGE_DEVICE =
1");
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
582 \membersection{wxDb::Dbms
}\label{wxdbdbms
}
584 \func{wxDBMS
}{Dbms
}{\void}
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.
591 Additional databases may work with these classes, but the databases
592 returned by this function have been tested and confirmed to work with
595 Possible values returned by this function can be viewed in the
596 \helpref{Enumerated types
}{wxdbenumeratedtypes
} section of wxDb.
598 There are known issues with conformance to the ODBC standards with several
599 datasources supported by the wxWindows ODBC classes. Please see the overview
600 for specific details on which datasource have which issues.
602 \wxheading{Return value
}
604 The return value will indicate which of the supported datasources is
605 currently connected to by this connection. In the event that the
606 datasource is not recognized, a value of 'dbmsUNIDENTIFIED' is returned.
609 \membersection{wxDb::DispAllErrors
}\label{wxdbdispallerrors
}
611 \func{bool
}{DispAllErrors
}{\param{HENV
}{ aHenv
},
\param{HDBC
}{ aHdbc = SQL
\_NULL\_HDBC},
\param{HSTMT
}{ aHstmt = SQL
\_NULL\_HSTMT}}
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
617 entry is also logged to the defined log file.
619 \wxheading{Parameters
}
621 \docparam{aHenv
}{Handle to the ODBC environment.
}
623 \docparam{aHdbc
}{Handle to the ODBC connection. Pass this in if the ODBC
624 function call that erred required a hdbc or hstmt argument.
}
626 \docparam{aHstmt
}{Handle to the ODBC statement being executed against. Pass
627 this in if the ODBC function call that failed required a hstmt argument.
}
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
634 ODBC functions directly (i.e. SQLFreeEnv()).
636 \wxheading{Return value
}
638 The function always returns FALSE, so a call to this function can be made
639 in the return statement of a code block in the event of a failure to
640 perform an action (see the example below).
644 \helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}, wxDbSqlLog
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));
654 \membersection{wxDb::DispNextError
}\label{wxdbdispnexterror
}
656 \func{void
}{DispNextError
}{\void}
660 This function is normally used internally within the ODBC class library.
661 It could be used programmatically after calling ODBC functions directly. This
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.
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)
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);
683 if (wxStrcmp(pDb->sqlState, "S0002"))
685 pDb->DispNextError(); // Displayed error retrieved
686 pDb->DispAllErrors(henv, hdbc, hstmt); // Display all other errors, if any
687 pDb->RollbackTrans(); // Rollback the transaction
688 CloseCursor(); // Close the cursor
689 return(FALSE); // Return Failure
695 \membersection{wxDb::DropView
}\label{wxdbdropview
}
697 \func{bool
}{DropView
}{\param{const wxString \&
}{viewName
}}
699 Drops the data table view named in 'viewName'.
701 \wxheading{Parameters
}
703 \docparam{viewName
}{Name of the view to be dropped.
}
707 If the view does not exist, this function will return TRUE. Note that views are not supported with all datasources.
709 \membersection{wxDb::ExecSql
}\label{wxdbexecsql
}
711 \func{bool
}{ExecSql
}{\param{const wxString \&
}{pSqlStmt
}}
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.
715 \wxheading{Parameters
}
717 \docparam{pSqlStmt
}{Pointer to the SQL statement to be executed.
}
721 This member extends the wxDb class and allows you to build and execute ANY VALID
722 SQL statement against the datasource. This allows you to extend the class
723 library by being able to issue any SQL statement that the datasource is capable
728 \helpref{wxDb::GetData
}{wxdbgetdata
},
\helpref{wxDb::GetNext
}{wxdbgetnext
}
730 \membersection{wxDb::FwdOnlyCursors
}\label{wxdbfwdonlycursors
}
732 \func{bool
}{IsFwdOnlyCursors
}{\void}
734 Older form (pre-
2.3/
2.4 of wxWindows) of the
735 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
}. This method is
736 provided for backward compatibility only. The method
737 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
} should be
738 used in place of this method.
741 \func{wxDbInf *
}{GetCatalog
}{\param{const wxChar *
}{userID
}}
743 \membersection{wxDb::GetCatalog
}\label{wxdbgetcatalog
}
745 \func{wxDbInf *
}{GetCatalog
}{\param{const wxChar *
}{userID
}}
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
752 \wxheading{Parameters
}
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:
}
757 userID == NULL ... UserID is ignored (DEFAULT)
758 userID == "" ... UserID set equal to 'this->uid'
759 userID != "" ... UserID set equal to 'userID'
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.
766 \membersection{wxDb::GetColumnCount
}\label{wxdbgetcolumncount
}
768 \func{int
}{GetColumnCount
}{\param{const wxString \&
}{tableName
},
\param{const wxChar *
}{userID
}}
770 \wxheading{Parameters
}
772 \docparam{tableName
}{The table name you wish to obtain column information about.
}
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
777 evaluated in the following manner:
}
780 userID == NULL ... UserID is ignored (DEFAULT)
781 userID == "" ... UserID set equal to 'this->uid'
782 userID != "" ... UserID set equal to 'userID'
785 \wxheading{Return value
}
787 Returns a count of how many columns are in the specified table. If an error
788 occurs retrieving the number of columns, this function will return a -
1.
790 \membersection{wxDb::GetColumns
}\label{wxdbgetcolumns
}
792 \func{wxDbColInf *
}{GetColumns
}{\param{const wxString \&
}{tableName
},
\param{UWORD *
}{numCols
},
\param{const wxChar *
}{userID=NULL
}}
794 \func{wxDbColInf *
}{GetColumns
}{\param{wxChar *
}{tableName
[]},
\param{const wxChar *
}{userID
}}
796 \wxheading{Parameters
}
798 \docparam{tableName
}{The table name you wish to obtain column information about.
}
799 \docparam{numCols
}{Pointer to a UWORD which will hold a count of the number of columns returned by this function
}
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.
}
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:
}
804 userID == NULL ... UserID is ignored (DEFAULT)
805 userID == "" ... UserID set equal to 'this->uid'
806 userID != "" ... UserID set equal to 'userID'
809 \wxheading{Return value
}
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
816 THE CALLING FUNCTION IS RESPONSIBLE FOR DELETING THE
{\it wxDbColInf
} MEMORY WHEN IT IS
819 \normalbox{ALL column bindings associated with this wxDb instance are unbound
820 by this function, including those used by any wxDbTable instances that use
821 this wxDb instance. This function should use its own wxDb instance
822 to avoid undesired unbinding of columns.
}
826 \helpref{wxDbColInf
}{wxdbcolinf
}
831 wxChar *tableList
[] =
{"PARTS",
0};
832 wxDbColInf *colInf = pDb->GetColumns(tableList);
835 // Use the column inf
837 // Destroy the memory
842 \membersection{wxDb::GetData
}\label{wxdbgetdata
}
844 \func{bool
}{GetData
}{\param{UWORD
}{ colNo
},
\param{SWORD
}{ cType
},
845 \param{PTR
}{ pData
},
\param{SDWORD
}{ maxLen
},
\param{SDWORD FAR *
}{ cbReturned
} }
847 Used to retrieve result set data without binding column values to memory
848 variables (i.e. not using a wxDbTable instance to access table data).
850 \wxheading{Parameters
}
852 \docparam{colNo
}{Ordinal number of the desired column in the result set to be
854 \docparam{cType
}{The C data type that is to be returned. See a partial list
855 in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}}
856 \docparam{pData
}{Memory buffer which will hold the data returned by the call
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
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
864 \helpref{wxDb::GetData
}{wxdbgetdata
} call has failed.
}
868 \helpref{wxDb::GetNext
}{wxdbgetnext
},
\helpref{wxDb::ExecSql
}{wxdbexecsql
}
876 sqlStmt = "SELECT SUM(REQUIRED_QTY - PICKED_QTY) FROM ORDER_TABLE WHERE \
877 PART_RECID =
1450 AND REQUIRED_QTY > PICKED_QTY";
880 if (!pDb->ExecSql(sqlStmt.c_str()))
886 // Request the first row of the result set
893 // Read column
#1 of the row returned by the call to ::GetNext()
894 // and return the value in 'reqQty'
895 if (!pDb->GetData(
1, SQL_C_ULONG, &reqQty,
0, &cb))
901 // Check for a NULL result
902 if (cb == SQL_NULL_DATA)
908 When requesting multiple columns to be returned from the result set (for example, the SQL query
909 requested
3 columns be returned), the calls to this function must request the columns in ordinal
910 sequence (
1,
2,
3 or
1,
3 or
2,
3).
912 \membersection{wxDb::GetDatabaseName
}\label{wxdbgetdatabasename
}
914 \func{const wxChar *
}{GetDatabaseName
}{\void}
916 Returns the name of the database engine.
918 \membersection{wxDb::GetDatasourceName
}\label{wxdbgetdatasourcename
}
920 \func{const wxString \&
}{GetDatasourceName
}{\void}
922 Returns the ODBC datasource name.
924 \membersection{wxDb::GetHDBC
}\label{wxdbgethdbc
}
926 \func{HDBC
}{GetHDBC
}{\void}
928 Returns the ODBC handle to the database connection.
930 \membersection{wxDb::GetHENV
}\label{wxdbgethenv
}
932 \func{HENV
}{GetHENV
}{\void}
934 Returns the ODBC environment handle.
936 \membersection{wxDb::GetHSTMT
}\label{wxdbgethstmt
}
938 \func{HSTMT
}{GetHSTMT
}{\void}
940 Returns the ODBC statement handle associated with this database connection.
942 \membersection{wxDb::GetKeyFields
}\label{wxdbgetkeyfields
}
944 \func{int
}{GetKeyFields
}{\param{const wxString \&
}{tableName
},
\param{wxDbColInf *
}{colInf
},
\param{UWORD
}{nocols
}}
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.
948 This function is primarily for use by the
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
} function, but may be called if desired from the client application.
950 \wxheading{Parameters
}
952 \docparam{tableName
}{Name of the table for which the columns will be evaluated as to their inclusion in any indexes.
}
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.
}
954 \docparam{nocols
}{Number of columns defined in the instance of colInf.
}
956 \wxheading{Return value
}
958 Currently always returns TRUE.
962 \helpref{wxDbColInf
}{wxdbcolinf
},
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
}
964 \membersection{wxDb::GetNext
}\label{wxdbgetnext
}
966 \func{bool
}{GetNext
}{\void}
968 Called after executing a query, this function requests the next row
969 in the result set after the current position of the cursor.
973 \helpref{wxDb::ExecSql
}{wxdbexecsql
},
\helpref{wxDb::GetData
}{wxdbgetdata
}
975 \membersection{wxDb::GetNextError
}\label{wxdbgetnexterror
}
977 \func{bool
}{GetNextError
}{\param{HENV
}{ aHenv
},
978 \param{HDBC
}{ aHdbc = SQL
\_NULL\_HDBC},
\param{HSTMT
}{ aHstmt = SQL
\_NULL\_HSTMT}}
980 \wxheading{Parameters
}
982 \docparam{aHenv
}{A handle to the ODBC environment.
}
983 \docparam{aHdbc
}{{\it OPTIONAL.
} A handle to the ODBC connection. Pass this
984 in if the ODBC function call that failed required a hdbc or hstmt argument.
}
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
992 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
994 return(db.GetNextError(db.henv, db.hdbc, hstmt));
1000 \helpref{wxDb::DispNextError
}{wxdbdispnexterror
},
1001 \helpref{wxDb::DispAllErrors
}{wxdbdispallerrors
}
1004 \membersection{wxDb::GetPassword
}\label{wxdbgetpassword
}
1006 \func{const wxString \&
}{GetPassword
}{\void}
1008 Returns the password used to establish this connection to the datasource.
1011 \membersection{wxDb::GetTableCount
}\label{wxdbgettablecount
}
1013 \func{int
}{GetTableCount
}{\void}
1015 Returns the number of wxDbTable() instances currently using this datasource
1019 \membersection{wxDb::GetUsername
}\label{wxdbgetusername
}
1021 \func{const wxString \&
}{GetUsername
}{\void}
1023 Returns the user name (uid) used to establish this connection to the
1027 \membersection{wxDb::Grant
}\label{wxdbgrant
}
1029 \func{bool
}{Grant
}{\param{int
}{privileges
},
\param{const wxString \&
}{tableName
},
1030 \param{const wxString \&
}{userList = "PUBLIC"
}}
1032 Use this member function to GRANT privileges to users for accessing tables in
1035 \wxheading{Parameters
}
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
1039 privileges pass one or more of the following OR'd together:
}
1046 DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT |
1047 DB_GRANT_UPDATE | DB_GRANT_DELETE
1050 \docparam{tableName
}{The name of the table you wish to grant privileges on.
}
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.
}
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.
1057 The currently logged in user must have sufficient grantor privileges for this
1058 function to be able to successfully grant the indicated privileges.
1063 db.Grant(DB_GRANT_SELECT | DB_GRANT_INSERT, "PARTS", "mary, sue");
1066 \membersection{wxDb::IsFwdOnlyCursors
}\label{wxdbisfwdonlycursors
}
1068 \func{bool
}{IsFwdOnlyCursors
}{\void}
1070 This setting indicates whether this database connection was created
1071 as being capable of using only forward scrolling cursors.
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
1075 driver or datasource can support backward scrolling cursors.
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
1080 to use forward scrolling cursors.
1082 The default setting of whether a wxDb connection to a database allows
1083 forward-only or also backward scrolling cursors is defined in setup.h by the
1084 value of wxODBC
\_FWD\_ONLY\_CURSORS. This default setting can be overridden
1085 when the wxDb connection is initially created (see
1086 \helpref{wxDb constructor
}{wxdbconstr
} and
\helpref{wxDbGetConnection
}{wxdbfunctions
}).
1088 \wxheading{Return value
}
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
1092 use backward scrolling cursors and their associated functions (see note above).
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
1098 class member functions.
1100 This function is not available in versions prior to v2.4. You should
1101 use
\helpref{wxDb::FwdOnlyCursors
}{wxdbfwdonlycursors
} for wxWindows
1102 versions prior to
2.4.
1104 \wxheading{See also
}
1106 \helpref{wxDb constructor
}{wxdbconstr
},
\helpref{wxDbGetConnection
}{wxdbfunctions
}
1108 \membersection{wxDb::IsOpen
}\label{wxdbisopen
}
1110 \func{bool
}{IsOpen
}{\void}
1112 Indicates whether the database connection to the datasource is currently
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
1121 function returns TRUE. Other functions which depend on the
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
1126 partial failures to open a connection instance.
1128 \membersection{wxDb::LogError
}\label{wxdblogerror
}
1130 \func{void
}{LogError
}{\param{const wxString \&
}{errMsg
} \param{const wxString \&
}{SQLState=""
}}
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.
}
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.
1141 If SQL logging is turned on, the call to this function will also log the
1142 text into the SQL log file.
1144 \wxheading{See also
}
1146 \helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
}
1148 \membersection{wxDb::ModifyColumn
}\label{wxdbmodifycolumn
}
1150 \func{void
}{ModifyColumn
}{\param{const wxString \&
}{tableName
} \param{const wxString \&
}{ColumnName
}
1151 \param{int
}{dataType
} \param{ULONG
}{columnLength=
0} \param{const wxString \&
}{optionalParam=""
}}
1153 Used to change certain properties of a column such as the length, or whether a column
1154 allows NULLs or not.
1156 \docparam{tableName
}{Name of the table that the column to be modified is in.
}
1157 \docparam{columnName
}{Name of the column to be modified. NOTE: Name of column cannot
1158 be changed with this function.
}
1159 \docparam{dataType
}{Any one of DB
\_DATA\_TYPE\_VARCHAR, DB
\_DATA\_TYPE\_INTEGER,
1160 DB
\_DATA\_TYPE\_FLOAT, DB
\_DATA\_TYPE\_DATE.
}
1161 \docparam{columnLength
}{New size of the column. Valid only for DB
\_DATA\_TYPE\_VARCHAR
1162 dataType fields. Default is
0.
}
1163 \docparam{optionalParam
}{Default is "".
}
1167 Cannot be used to modify the precision of a numeric column, therefore 'columnLength'
1168 is ignored unless the dataType is DB
\_DATA\_TYPE\_VARCHAR.
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
1174 used for behavioral descriptions.
1179 ok = pDb->ModifyColumn("CONTACTS", "ADDRESS2",
1180 DB_, colDefs
[j
].SzDataObj,
1185 \membersection{wxDb::Open
}\label{wxdbopen
}
1187 \func{bool
}{Open
}{\param{const wxString \&
}{Dsn
},
\param{const wxString \&
}{Uid
},
1188 \param{const wxString \&
}{AuthStr
}}
1190 \func{bool
}{Open
}{\param{wxDb *
}{copyDb
}}
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
1196 the data tables are to be handled.
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.
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
1211 same Dsn/Uid/AuthStr as the first connection used.
1213 \wxheading{Parameters
}
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
1218 \docparam{Uid
}{User ID. The name (ID) of the user you wish to connect as
1219 to the datasource. The user name (ID) determines what objects you
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.
}
1224 \docparam{AuthStr
}{The password associated with the Uid.
}
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
1227 from for use by this datasource connection.
}
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.
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
1240 of wxDb objects that use either the same or different Dsn/Uid/AuthStr settings.
1242 If this function returns a value of FALSE, it does not necessarily mean that
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
}
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
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
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
1256 must maintain the memory for these three strings for the life of the wxDb instance.
}
1261 wxDb sampleDB(DbConnectInf.GetHenv());
1262 if (!sampleDB.Open("Oracle
7.1 HP/UX", "gtasker", "myPassword"))
1264 if (sampleDb.IsOpen())
1266 // Connection is open, but the initialization of
1267 // datatypes and parameter settings failed
1271 // Error opening datasource
1276 \membersection{wxDb::RollbackTrans
}\label{wxdbrollbacktrans
}
1278 \func{bool
}{RollbackTrans
}{\void}
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.
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
1288 commit/rollback that was successfully executed.
1290 \normalbox{Calling this member function rolls back ALL open (uncommitted)
1291 transactions on this ODBC connection, including all wxDbTable instances that
1292 use this connection.
}
1294 \wxheading{See also
}
1296 \helpref{wxDb::CommitTrans
}{wxdbcommittrans
} for a special note on cursors
1298 \membersection{wxDb::SetDebugErrorMessages
}\label{wxdbsetdebugerrormessages
}
1300 \func{void
}{SetDebugErrorMessages
}{\param{bool
}{state
}}
1302 \docparam{state
}{Either TRUE (debug messages are logged) or FALSE (debug
1303 messages are not logged).
}
1307 Turns on/off debug error messages from the ODBC class library. When
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,
1310 errors are silently handled.
1312 When compiled in release mode (FINAL=
1), this setting has no affect.
1314 \wxheading{See also
}
1316 \helpref{wxDb constructor
}{wxdbconstr
}
1318 \membersection{wxDb::SetSqlLogging
}\label{wxdbsetsqllogging
}
1320 \func{bool
}{SetSqlLogging
}{\param{wxDbSqlLogState
}{ state
},
\param{const wxString \&
}{filename = SQL
\_LOG\_FILENAME},
\param{bool
}{ append = FALSE
}}
1322 \wxheading{Parameters
}
1324 \docparam{state
}{Either sqlLogOFF or sqlLogON (see
\helpref{enum wxDbSqlLogState
}{wxdbcolfor
}). Turns logging of SQL commands sent to the datasource OFF or ON.
}
1325 \docparam{filename
}{{\it OPTIONAL
}. Name of the file to which the log text is to be written. Default is SQL
\_LOG\_FILENAME.
}
1326 \docparam{append
}{{\it OPTIONAL
}. Whether the file is appended to or overwritten. Default is FALSE.
}
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.
1332 When called with
{\it sqlLogOFF
}, the logging file is closed, and any calls to
\helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
} are ignored.
1334 \membersection{wxDb::SQLColumnName
}\label{wxdbsqlcolumnname
}
1336 \func{const wxString
}{SQLColumnName
}{\param{const char *
}{ colName
}}
1338 Returns the column name in a form ready for use in SQL statements.
1339 In most cases, the column name is returned verbatim. But some databases
1340 (e.g. MS Access, SQL Server, MSDE) allow for spaces in column names, which
1341 must be specially quoted. For example, if the datasource allows spaces
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
1344 for the DBMS that is currently connected to with this connection.
1346 \wxheading{Parameters
}
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
1350 before including the column name in a SQL statement
}
1352 \wxheading{See also
}
1354 \helpref{wxDb::SQLTableName
}{wxdbsqltablename
}
1356 \membersection{wxDb::SQLTableName
}\label{wxdbsqltablename
}
1358 \func{const wxString
}{SQLTableName
}{\param{const char *
}{ tableName
}}
1360 Returns the table name in a form ready for use in SQL statements.
1361 In most cases, the table name is returned verbatim. But some databases
1362 (e.g. MS Access, SQL Server, MSDE) allow for spaces in table names, which
1363 must be specially quoted. For example, if the datasource allows spaces
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
1366 for the data source that is currently connected to with this connection.
1368 \wxheading{Parameters
}
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
1372 before including the table name in a SQL statement
}
1374 \wxheading{See also
}
1376 \helpref{wxDb::SQLColumnName
}{wxdbsqlcolumnname
}
1378 \membersection{wxDb::TableExists
}\label{wxdbtableexists
}
1380 \func{bool
}{TableExists
}{\param{const wxString \&
}{tableName
},
\param{const wxChar *
}{userID=NULL
},
\param{const wxString \&
}{path=""
}}
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
1384 at least minimal privileges to the table).
1386 \wxheading{Parameters
}
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
1390 to allows multiple unique tables with the same name to be owned by different users.
{\it userID
}
1391 is evaluated as follows:
}
1394 userID == NULL ... UserID is ignored (DEFAULT)
1395 userID == "" ... UserID set equal to 'this->uid'
1396 userID != "" ... UserID set equal to 'userID'
1401 {\it tableName
} may refer to a table, view, alias or synonym.
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.
1405 \wxheading{See also
}
1407 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
}
1409 \membersection{wxDb::TablePrivileges
}\label{wxdbtableprivileges
}
1411 \func{bool
}{TablePrivileges
}{\param{const wxString \&
}{tableName
},
\param{const wxString \&
}{priv
},
1412 \param{const wxChar *
}{userID=NULL
},
\param{const wxChar *
}{schema=NULL
},
1413 \param{const wxString \&
}{path=""
}}
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
1417 at least minimal privileges to the table).
1419 \wxheading{Parameters
}
1421 \docparam{tableName
}{Name of the table on which to check privileges.
1422 {\it tableName
} may refer to a table, view, alias or synonym.
}
1423 \docparam{priv
}{The table privilege being evaluated. May be one of the
1424 following (or a datasource specific privilege):
}
1426 SELECT : The connected user is permitted to retrieve data for
1427 one or more columns of the table.
1429 INSERT : The connected user is permitted to insert new rows
1430 containing data for one or more columns into the
1433 UPDATE : The connected user is permitted to update the data in
1434 one or more columns of the table.
1436 DELETE : The connected user is permitted to delete rows of
1437 data from the table.
1439 REFERENCES : Is the connected user permitted to refer to one or
1440 more columns of the table within a constraint (for
1441 example, a unique, referential, or table check
1444 \docparam{userID
}{{\it OPTIONAL.
} User for which to determine if the privilege
1445 specified to be checked is granted or not. Default is "".
1446 {\it userID
} is evaluated as follows:
}
1448 userID == NULL ... NOT ALLOWED!
1449 userID == "" ... UserID set equal to 'this->uid'
1450 userID != "" ... UserID set equal to 'userID'
1453 \docparam{schema
}{{\it OPTIONAL.
} Owner of the table. Specify a userID when the datasource
1454 you are connected to allows multiple unique tables with the same name to be
1455 owned by different users. Specifying the table owner makes determination of the
1456 users privileges MUCH faster. Default is NULL.
{\it userID
} is evaluated as follows:
}
1458 schema == NULL ... Any owner (DEFAULT)
1459 schema == "" ... Owned by 'this->uid'
1460 schema != "" ... Owned by userID specified in 'schema'
1463 \docparam{path
}{{\it OPTIONAL.
} Path to the table. Default is "".
1468 The scope of privilege allowed to the connected user by a given table
1469 privilege is datasource dependent.
1471 For example, the privilege UPDATE might allow the connected user to update
1472 all columns in a table on one datasource, but only those columns for
1473 which the grantor (the user that granted the connected user) has the UPDATE
1474 privilege on another datasource.
1476 Looking up a user's privileges to a table can be time consuming depending on the
1477 datasource and ODBC driver. This time can be minimized by passing a
{\it schema
}
1478 as a parameter. With some datasources/drivers, the difference can be several
1479 seconds of time difference.
1482 \membersection{wxDb::TranslateSqlState
}\label{wxdbtranslatesqlstate
}
1484 \func{int
}{TranslateSqlState
}{\param{const wxString \&
}{SQLState
}}
1486 Converts an ODBC sqlstate to an internal error code.
1488 \wxheading{Parameters
}
1490 \docparam{SQLState
}{State to be converted.
}
1492 \wxheading{Return value
}
1494 Returns the internal class DB
\_ERR code. See
\helpref{wxDb::DB
\_STATUS}{wxdb
} definition.
1496 \membersection{wxDb::WriteSqlLog
}\label{wxdbwritesqllog
}
1498 \func{bool
}{WriteSqlLog
}{\param{const wxString \&
}{logMsg
}}
1500 \wxheading{Parameters
}
1502 \docparam{logMsg
}{Free form string to be written to the log file.
}
1506 Very useful debugging tool that may be turned on/off during run time (see
1507 (see
\helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
} for details on
1508 turning logging on/off). The passed in string
{\it logMsg
} will be written to
1509 a log file if SQL logging is turned on.
1511 \wxheading{Return value
}
1513 If SQL logging is off when a call to WriteSqlLog() is made, or there is a
1514 failure to write the log message to the log file, the function returns
1515 FALSE without performing the requested log, otherwise TRUE is returned.
1517 \wxheading{See also
}
1519 \helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}
1521 \section{\class{wxDbColDataPtr
}}\label{wxdbcoldataptr
}
1523 Pointer to dynamic column definitions for use with a wxDbTable instance.
1524 Currently there are no member functions for this class.
1526 See the
\helpref{database classes overview
}{odbcoverview
} for
1527 an introduction to using the ODBC classes.
1535 \section{\class{wxDbColDef
}}\label{wxdbcoldef
}
1537 This class is used to hold information about the columns bound to an
1538 instance of a wxDbTable object.
1540 Each instance of this class describes one column in the wxDbTable
1541 object. When calling the
\helpref{wxDb constructor
}{wxdbconstr
}, a
1542 parameter passed in indicates the number of columns that will be defined for
1543 the wxDbTable object. The constructor uses this information to allocate
1544 adequate memory for all of the column descriptions in your wxDbTable object.
1545 Private member wxDbTable::colDefs is a pointer to this chunk of memory
1546 maintained by the wxDbTable class (and can be retrieved using the
1547 \helpref{wxDbTable::GetColDefs
}{wxdbtablegetcoldefs
} function).
1548 To access the nth column definition of your wxDbTable object, just reference
1549 wxDbColDefs element
[n -
1].
1551 Typically,
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
} is used to
1552 populate an array of these data structures for the wxDbTable instance.
1554 Currently there are no accessor functions for this class, so all members are
1558 wxChar ColName
[DB_MAX_COLUMN_NAME_LEN+
1]; // Column Name
1559 int DbDataType; - Logical Data Type;
1560 e.g. DB_DATA_TYPE_INTEGER
1561 SWORD SqlCtype; - C data type; e.g. SQL_C_LONG
1562 void *PtrDataObj; - Address of the data object
1563 int SzDataObj; - Size, in bytes, of the data object
1564 bool KeyField; - Is column part of the PRIMARY KEY for the
1565 table? -- Date fields should NOT be
1567 bool Updateable; - Column is updateable?
1568 bool InsertAllowed; - Column included in INSERT statements?
1569 bool DerivedCol; - Column is a derived value?
1570 SDWORD CbValue; - !!!Internal use only!!!
1571 bool Null; - NOT FULLY IMPLEMENTED
1572 Allows NULL values in Inserts and Updates
1575 \wxheading{See also
}
1577 \helpref{database classes overview
}{odbcoverview
},
1578 \helpref{wxDbTable::GetColDefs
}{wxdbtablegetcoldefs
},
\helpref{wxDb constructor
}{wxdbconstr
}
1580 \membersection{wxDbColDef::Initialize
}\label{wxdbcoldefinitialize
}
1582 Simply initializes all member variables to a cleared state. Called by
1583 the constructor automatically.
1585 \section{\class{wxDbColFor
}}\label{wxdbcolfor
}
1587 Beginning support for handling international formatting specifically on dates
1591 wxString s_Field; // Formated String for Output
1592 wxString s_Format
[7]; // Formated Objects - TIMESTAMP has
1594 wxString s_Amount
[7]; // Formated Objects - amount of
1595 things that can be formatted
1596 int i_Amount
[7]; // Formated Objects -
1597 TT MM YYYY HH MM SS m
1598 int i_Nation; //
0 = timestamp
1603 int i_dbDataType; // conversion of the 'sqlDataType'
1604 to the generic data type used by
1606 SWORD i_sqlDataType;
1609 The constructor for this class initializes all the values to zero or NULL.
1611 The destructor does nothing at this time.
1613 Only one function is provided with this class currently.
1615 See the
\helpref{database classes overview
}{odbcoverview
} for
1616 an introduction to using the ODBC classes.
1618 \membersection{wxDbColFor::Format
}\label{wxdbcolforformat
}
1620 \func{int
}{Format
}{\param{int
}{Nation
},
\param{int
}{dbDataType
},
1621 \param{SWORD
}{sqlDataType
},
\param{short
}{columnSize
},
1622 \param{short
}{decimalDigits
}}\label{wxdbcolforformat
}
1624 Work in progress, and should be inter-related with wxLocale eventually.
1626 \membersection{wxDbColFor::Initialize
}\label{wxdbcolforinitialize
}
1628 Simply initializes all member variables to a cleared state. Called by
1629 the constructor automatically.
1631 \section{\class{wxDbColInf
}}\label{wxdbcolinf
}
1633 Used with the
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
} functions for obtaining all retrievable information about a column's definition.
1636 wxChar catalog
[128+
1];
1637 wxChar schema
[128+
1];
1638 wxChar tableName
[DB_MAX_TABLE_NAME_LEN+
1];
1639 wxChar colName
[DB_MAX_COLUMN_NAME_LEN+
1];
1641 wxChar typeName
[128+
1];
1644 short decimalDigits;
1647 wxChar remarks
[254+
1];
1648 int dbDataType; // conversion of the 'sqlDataType'
1649 // to the generic data type used by
1651 int PkCol; // Primary key column
1654 2 = Second Key, etc...
1655 wxChar PkTableName
[DB_MAX_TABLE_NAME_LEN+
1];
1656 // Tables that use this PKey as a FKey
1657 int FkCol; // Foreign key column
1660 2 = Second Key, etc...
1661 wxChar FkTableName
[DB_MAX_TABLE_NAME_LEN+
1];
1662 // Foreign key table name
1663 wxDbColFor *pColFor; // How should this column be formatted
1666 The constructor for this class initializes all the values to zero, "", or NULL.
1668 The destructor for this class takes care of deleting the pColFor member if
1671 See the
\helpref{database classes overview
}{odbcoverview
} for
1672 an introduction to using the ODBC classes.
1674 \membersection{wxDbColInf::Initialize
}\label{wxdbcolinfinitialize
}
1676 Simply initializes all member variables to a cleared state. Called by
1677 the constructor automatically.
1679 \section{\class{wxDbConnectInf
}}\label{wxdbconnectinf
}
1681 This class is used for holding the data necessary for connecting to the ODBC
1682 datasource. That information includes: SQL environment handle, datasource
1683 name, user ID, password and default directory path (used with dBase). Other
1684 optional fields held in this class are and file type, both for future
1685 functions planned to be added for creating/manipulating datasource definitions.
1687 \membersection{wxDbConnectInf::wxDbConnectInf
}
1689 \func{}{wxDbConnectInf
}{\void}
1691 Default constructor.
1693 \func{}{wxDbConnectInf
}{\param{HENV
}{henv
},
\param{const wxString \&
}{dsn
},
1694 \param{const wxString \&
}{userID=""
},
\param{const wxString \&
}{password
},
1695 \param{const wxString \&
}{defaultDir=""
},
\param{const wxString \&
}{description=""
},
1696 \param{const wxString \&
}{fileType=""
}}
1698 Constructor which allows initial settings of all the classes member variables.
1700 See the special note below on the henv parameter for forcing this constructor
1701 to create a SQL environment handle automatically, rather than needing to pass
1702 one in to the function.
1704 \wxheading{Parameters
}
1706 \docparam{henv
}{Environment handle used for this connection. See
1707 \helpref{wxDConnectInf::AllocHenv
}{wxdbconnectinfallochenv
} for how to create
1708 an SQL environment handle. NOTE: Passing in a NULL for this parameter will
1709 inform the constructor that it should create its own SQL environment handle.
1710 If NULL is passed for this parameter, the constructor will call
1711 \helpref{wxDConnectInf::AllocHenv
}{wxdbconnectinfallochenv
} internally. A
1712 flag is set internally also to indicate that the HENV was created by the
1713 constructor so that when the default class destructor is called, the
1714 destructor will call
\helpref{wxDConnectInf::FreeHenv
}{wxdbconnectinffreehenv
}
1715 to free the environment handle automatically.
}
1716 \docparam{dsn
}{Name of the datasource to be used in creating wxDb instances
1717 for creating connection(s) to a datasource.
}
1718 \docparam{userID
}{{\it OPTIONAL
} Many datasources allow (or even require)
1719 use of a username to determine privileges that connecting user is allowed
1720 to have when accessing the datasource or the data tables. Default is "".
}
1721 \docparam{password
}{{\it OPTIONAL
} Password to be associated with the user
1722 ID specified in 'userID'. Default is "".
}
1723 \docparam{defaultDir
}{{\it OPTIONAL
} Used for datasources which require the
1724 path to where the data file is stored to be specified. dBase is one example
1725 of the type of datasource which requires this information. Default is "".
}
1726 \docparam{description
}{{\it OPTIONAL
} {\bf FUTURE USE
} Default is "".
}
1727 \docparam{fileType
}{{\it OPTIONAL
} {\bf FUTURE USE
} Default is "".
}
1731 It is strongly recommended that programs use the longer form of the
1732 constructor and allow the constructor to create the SQL environment handle
1733 automatically, and manage the destruction of the handle.
1738 wxDbConnectInf *DbConnectInf;
1740 DbConnectInf = new wxDbConnectInf(
0,"MY_DSN", "MY_USER", "MY_PASSWORD");
1742 ....the rest of the program
1744 delete DbConnectInf;
1747 \wxheading{See also
}
1749 \helpref{wxDConnectInf::AllocHenv
}{wxdbconnectinfallochenv
},
1750 \helpref{wxDConnectInf::FreeHenv
}{wxdbconnectinffreehenv
}
1752 \membersection{wxDbConnectInf::
\destruct{wxDbConnectInf
}}\label{wxdbconnectinfdestr
}
1754 \func{}{\destruct{wxDbConnectInf
}}{}
1756 Handles the default destruction of the instance of the class. If the long form
1757 of the
\helpref{wxDConnectInf
}{wxdbconnectinf
} was used, then this destructor
1758 also takes care of calling
1759 \helpref{wxDConnectInf::FreeHenv
}{wxdbconnectinffreehenv
} to free the
1760 SQL environment handle.
1762 \membersection{wxDbConnectInf::AllocHenv
}\label{wxdbconnectinfallochenv
}
1764 \func{bool
}{AllocHenv
}{\void}
1766 Allocates a SQL environment handle that will be used to interface with
1771 This function can be automatically called by the long from of the
1772 \helpref{wxDbConnectInf
}{wxdbconnectinf
} constructor.
1774 \membersection{wxDbConnectInf::FreeHenv
}\label{wxdbconnectinffreehenv
}
1776 \func{void
}{FreeHenv
}{\void}
1778 Frees the SQL environment handle being managed by the instance of this class.
1782 If the SQL environment handle was created using the long form of the
1783 \helpref{wxDbConnectInf
}{wxdbconnectinf
} constructor, then the flag indicating
1784 that the HENV should be destroyed when the classes destructor is called
1785 is reset to be FALSE, so that any future handles created using the
1786 \helpref{wxDbConnectInf::AllocHenv
}{wxdbconnectinfallochenv
} function
1787 must be manually released with a call to this function.
1789 \membersection{wxDbConnectInf::Initialize
}\label{wxdbconnectinfinitialize
}
1791 Simply initializes all member variables to a cleared state. Called by
1792 the constructor automatically.
1794 \membersection{wxDbConnectInf::GetAuthStr
}\label{wxdbconnectinfgetauthstr
}
1796 \func{const wxChar *
}{GetAuthStr
}{\void}
1798 Accessor function to return the password assigned for this class
1799 instance that will be used with the user ID.
1801 Synonymous with
\helpref{wxDbConnectInf::GetPassword
}{wxdbconnectinfgetpassword
}
1803 \membersection{wxDbConnectInf::GetDefaultDir
}\label{wxdbconnectinfgetdefaultdir
}
1805 \func{const wxChar *
}{GetDefaultDir
}{\void}
1807 Accessor function to return the default directory in which the datasource's data
1808 table is stored. This directory is only used for file based datasources like
1809 dBase. MS-Access does not require this to be set, as the path is set in the
1810 ODBC Administrator for MS-Access.
1812 \membersection{wxDbConnectInf::GetDescription
}\label{wxdbconnectinfgetdescription
}
1814 \func{const wxChar *
}{GetDescription
}{\void}
1816 Accessor function to return the description assigned for this class
1819 NOTE: Description is a FUTURE USE item and is unused currently.
1821 \membersection{wxDbConnectInf::GetDsn
}\label{wxdbconnectinfgetdsn
}
1823 \func{const wxChar *
}{GetDsn
}{\void}
1825 Accessor function to return the datasource name assigned for this class
1828 \membersection{wxDbConnectInf::GetFileType
}\label{wxdbconnectinfgetfiletype
}
1830 \func{const wxChar *
}{GetFileType
}{\void}
1832 Accessor function to return the filetype of the ODBC datasource assigned for
1833 this class instance.
1835 NOTE: FileType is a FUTURE USE item and is unused currently.
1837 \membersection{wxDbConnectInf::GetHenv
}\label{wxdbconnectinfgethenv
}
1839 \func{const HENV
}{GetHenv
}{\void}
1841 Accessor function to return the SQL environment handle being managed
1842 by this class instance.
1844 \membersection{wxDbConnectInf::GetPassword
}\label{wxdbconnectinfgetpassword
}
1846 \func{const wxChar *
}{GetPassword
}{\void}
1848 Accessor function to return the password assigned for this class
1849 instance that will be used with the user ID.
1851 Synonymous with
\helpref{wxDbConnectInf::GetAuthStr
}{wxdbconnectinfgetauthstr
}
1853 \membersection{wxDbConnectInf::GetUid
}\label{wxdbconnectinfgetuid
}
1855 \func{const wxChar *
}{GetUid
}{\void}
1857 Accessor function to return the user ID assigned for this class
1860 \membersection{wxDbConnectInf::GetUserID
}\label{wxdbconnectinfgetuserid
}
1862 \func{const wxChar *
}{GetUserID
}{\void}
1864 Accessor function to return the user ID assigned for this class
1867 \membersection{wxDbConnectInf::SetAuthStr
}\label{wxdbconnectinfsetauthstr
}
1869 \func{\void}{SetAuthStr
}{const wxString \&authstr
}
1871 Accessor function to assign the password for this class
1872 instance that will be used with the user ID.
1874 Synonymous with
\helpref{wxDbConnectInf::SetPassword
}{wxdbconnectinfsetpassword
}
1876 \membersection{wxDbConnectInf::SetDefaultDir
}\label{wxdbconnectinfsetdefaultdir
}
1878 \func{\void}{SetDefaultDir
}{const wxString \&defDir
}
1880 Accessor function to assign the default directory in which the datasource's data
1881 table is stored. This directory is only used for file based datasources like
1882 dBase. MS-Access does not require this to be set, as the path is set in the
1883 ODBC Administrator for MS-Access.
1885 \membersection{wxDbConnectInf::SetDescription
}\label{wxdbconnectinfsetdescription
}
1887 \func{\void}{SetDescription
}{const wxString \&desc
}
1889 Accessor function to assign the description assigned for this class
1892 NOTE: Description is a FUTURE USE item and is unused currently.
1894 \membersection{wxDbConnectInf::SetDsn
}\label{wxdbconnectinfsetdsn
}
1896 \func{\void}{SetDsn
}{const wxString \&dsn
}
1898 Accessor function to assign the datasource name for this class instance.
1900 \membersection{wxDbConnectInf::SetFileType
}\label{wxdbconnectinfsetfiletype
}
1902 \func{\void}{SetFileType
}{const wxString \&
}
1904 Accessor function to return the filetype of the ODBC datasource assigned for
1905 this class instance.
1907 NOTE: FileType is a FUTURE USE item and is unused currently.
1909 \membersection{wxDbConnectInf::SetHenv
}\label{wxdbconnectinfsethenv
}
1911 \func{void
}{SetHenv
}{\param{const HENV
}{henv
}}
1913 Accessor function to set the SQL environment handle for this class instance.
1915 \membersection{wxDbConnectInf::SetPassword
}\label{wxdbconnectinfsetpassword
}
1917 \func{\void}{SetPassword
}{const wxString \&password
}
1919 Accessor function to assign the password for this class
1920 instance that will be used with the user ID.
1922 Synonymous with
\helpref{wxDbConnectInf::SetAuthStr
}{wxdbconnectinfsetauthstr
}
1924 \membersection{wxDbConnectInf::SetUid
}\label{wxdbconnectinfsetuid
}
1926 \func{\void}{SetUid
}{const wxString \&uid
}
1928 Accessor function to set the user ID for this class instance.
1930 \membersection{wxDbConnectInf::SetUserID
}\label{wxdbconnectinfsetuserid
}
1932 \func{\void}{SetUserID
}{const wxString \&userID
}
1934 Accessor function to assign the user ID for this class instance.
1936 \section{\class{wxDbIdxDef
}}\label{wxdbidxdef
}
1938 Used in creation of non-primary indexes. Currently there are no member
1939 functions for this class.
1942 wxChar ColName
[DB_MAX_COLUMN_NAME_LEN+
1]
1944 bool Ascending // Is index maintained in
1948 There are no constructors/destructors as of this time, and no member functions.
1950 See the
\helpref{database classes overview
}{odbcoverview
} for
1951 an introduction to using the ODBC classes.
1953 \section{\class{wxDbInf
}}\label{wxdbinf
}
1955 Contains information regarding the database connection (datasource name,
1956 number of tables, etc). A pointer to a wxDbTableInf is included in this
1957 class so a program can create a wxDbTableInf array instance to maintain all
1958 information about all tables in the datasource to have all the datasource's
1959 information in one memory structure.
1961 Primarily, this class is used internally by the wxWindows ODBC classes.
1964 wxChar catalog
[128+
1];
1965 wxChar schema
[128+
1]; // typically means owner of table(s)
1966 int numTables; // How many tables does this
1968 wxDbTableInf *pTableInf; // Equals a new
1969 wxDbTableInf
[numTables
];
1972 The constructor for this class initializes all the values to zero, "", or NULL.
1974 The destructor for this class takes care of deleting the pTableInf member if
1977 See the
\helpref{database classes overview
}{odbcoverview
} for
1978 an introduction to using the ODBC classes.
1980 \membersection{wxDbInf::Initialize
}\label{wxdbinfinitialize
}
1982 Simply initializes all member variables to a cleared state. Called by
1983 the constructor automatically.
1985 \section{\class{wxDbTable
}}\label{wxdbtable
}
1987 A wxDbTable instance provides re-usable access to rows of data in
1988 a table contained within the associated ODBC datasource
1990 See the
\helpref{database classes overview
}{odbcoverview
} for
1991 an introduction to using the ODBC classes.
1993 \wxheading{Include files
}
1998 \latexignore{\rtfignore{\wxheading{Members
}}}
1999 \wxheading{Helper classes and data structures
}
2001 The following classes and structs are defined in dbtable.cpp/.h for use
2002 with the wxDbTable class.
2004 \begin{itemize
}\itemsep=
0pt
2005 \item \helpref{wxDbColDef
}{wxdbcoldef
}
2006 \item \helpref{wxDbColDataPtr
}{wxdbcoldataptr
}
2007 \item \helpref{wxDbIdxDef
}{wxdbidxdef
}
2010 \wxheading{Constants
}
2013 wxDB_DEFAULT_CURSOR Primary cursor normally used for cursor based
2016 wxDB_QUERY_ONLY Used to indicate whether a table that is opened
2017 is for query only, or if insert/update/deletes
2018 will be performed on the table. Less overhead
2019 (cursors and memory) are allocated for query
2020 only tables, plus read access times are faster
2021 with some datasources.
2023 wxDB_ROWID_LEN
[Oracle only
] - Used when CanUpdateByRowID()
2024 is true. Optimizes updates so they are faster
2025 by updating on the Oracle-specific ROWID column
2026 rather than some other index.
2029 wxDB_DISABLE_VIEW Use to indicate when a database view should not
2030 be if a table is normally set up to use a view.
2031 [Currently unsupported.
]
2036 \latexignore{\rtfignore{\wxheading{Members
}}}
2038 \membersection{wxDbTable::wxDbTable
}\label{wxdbtableconstr
}
2040 \func{}{wxDbTable
}{\param{wxDb *
}{pwxDb
},
\param{const wxString \&
}{tblName
},
2041 \param{const UWORD
}{numColumns
},
\param{const wxString \&
}{qryTblName = ""
},
2042 \param{bool
}{qryOnly = !wxDB
\_QUERY\_ONLY},
\param{const wxString \&
}{tblPath = ""
}}
2044 Default constructor.
2046 \wxheading{Parameters
}
2048 \docparam{pwxDb
}{Pointer to the wxDb instance to be used by this wxDbTable
2050 \docparam{tblName
}{The name of the table in the RDBMS.
}
2051 \docparam{numColumns
}{The number of columns in the table. (Do NOT include the ROWID
2052 column in the count if using Oracle).
}
2053 \docparam{qryTblName
}{{\it OPTIONAL
}. The name of the table or view to base
2054 your queries on. This argument allows you to specify a table/view other than
2055 the base table for this object to base your queries on. This allows you to
2056 query on a view for example, but all of the INSERT, UPDATE and DELETES will
2057 still be performed on the base table for this wxDbTable object. Basing your
2058 queries on a view can provide a substantial performance increase in cases where
2059 your queries involve many tables with multiple joins. Default is "".
}
2060 \docparam{qryOnly
}{{\it OPTIONAL
}. Indicates whether the table will be
2061 accessible for query purposes only, or should the table create the necessary
2062 cursors to be able to insert, update, and delete data from the table.
2063 Default is !wxDB
\_QUERY\_ONLY.
}
2064 \docparam{tblPath
}{{\it OPTIONAL
}. Some datasources (such as dBase)
2065 require a path to where the table is stored on the system. Default is "".
}
2067 \membersection{wxDbTable::wxDbTable
}\label{wxdbtabledestr
}
2069 \func{virtual
}{\destruct{wxDbTable
}}{}
2071 Virtual default destructor.
2073 \membersection{wxDbTable::BuildDeleteStmt
}\label{wxdbtablebuilddeletestmt
}
2075 \func{void
}{BuildDeleteStmt
}{\param{wxString \&
}{pSqlStmt
},
2076 \param{int
}{typeOfDel
},
\param{const wxString \&
}{pWhereClause=""
}}
2078 Constructs the full SQL statement that can be used to delete all rows matching
2079 the criteria in the pWhereClause.
2081 \wxheading{Parameters
}
2083 \docparam{pSqlStmt
}{Pointer to buffer for the SQL statement retrieved. To be
2084 sure you have adequate space allocated for the SQL statement, allocate
2085 DB
\_MAX\_STATEMENT\_LEN bytes.
}
2086 \docparam{typeOfDel
}{The type of delete statement being performed. Can be one
2087 of three values: DB
\_DEL\_KEYFIELDS, DB
\_DEL\_WHERE or DB
\_DEL\_MATCHING}
2088 \docparam{pWhereClause
}{{\it OPTIONAL
}. If the typeOfDel is DB
\_DEL\_WHERE,
2089 then you must also pass in a SQL WHERE clause in this argument. Default
2094 This member function constructs a SQL DELETE statement. This can be used for
2095 debugging purposes if you are having problems executing your SQL statement.
2097 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2098 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2101 \membersection{wxDbTable::BuildSelectStmt
}\label{wxdbtablebuildselectstmt
}
2103 \func{void
}{BuildSelectStmt
}{\param{wxString \&
}{pSqlStmt
},
2104 \param{int
}{typeOfSelect
},
\param{bool
}{distinct
}}
2106 Constructs the full SQL statement that can be used to select all rows matching
2107 the criteria in the pWhereClause. This function is called internally in the
2108 wxDbTable class whenever the function
\helpref{wxDbTable::Query
}{wxdbtablequery
}
2111 NOTE: Only the columns specified in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
2112 statements are included in the list of columns returned by the SQL statement
2113 created by a call to this function.
2115 \wxheading{Parameters
}
2117 \docparam{pSqlStmt
}{Pointer to storage for the SQL statement retrieved. To be
2118 sure you have adequate space allocated for the SQL statement, allocate
2119 DB
\_MAX\_STATEMENT\_LEN bytes.
}
2120 \docparam{typeOfSelect
}{The type of select statement being performed. Can be
2121 one of four values: DB
\_SELECT\_KEYFIELDS, DB
\_SELECT\_WHERE, DB
\_SELECT\_MATCHING
2122 or DB
\_SELECT\_STATEMENT.
}
2123 \docparam{distinct
}{Whether to select distinct records only.
}
2127 This member function constructs a SQL SELECT statement. This can be used for
2128 debugging purposes if you are having problems executing your SQL statement.
2130 WHERE and FROM clauses specified using
2131 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2132 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2135 \membersection{wxDbTable::BuildUpdateStmt
}\label{wxdbtablebuildupdatestmt
}
2137 \func{void
}{BuildUpdateStmt
}{\param{wxString \&
}{pSqlStmt
},
\param{int
}{typeOfUpd
},
2138 \param{const wxString \&
}{pWhereClause=""
}}
2140 Constructs the full SQL statement that can be used to update all rows matching
2141 the criteria in the pWhereClause.
2143 If typeOfUpd is DB
\_UPD\_KEYFIELDS, then the current values in the bound columns
2144 are used to determine which row(s) in the table are to be updated. The
2145 exception to this is when a datasource supports ROW IDs (Oracle). The ROW ID
2146 column is used for efficiency purposes when available.
2148 NOTE: Only the columns specified in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
2149 statements are included in the list of columns updated by the SQL statement
2150 created by a call to this function. Any column definitions that were defined
2151 as being non-updateable will be excluded from the SQL UPDATE statement created
2154 \wxheading{Parameters
}
2156 \docparam{pSqlStmt
}{Pointer to storage for the SQL statement retrieved. To be
2157 sure you have adequate space allocated for the SQL statement, allocate
2158 DB
\_MAX\_STATEMENT\_LEN bytes.
}
2159 \docparam{typeOfUpd
}{The type of update statement being performed. Can be one
2160 of two values: DB
\_UPD\_KEYFIELDS or DB
\_UPD\_WHERE.
}
2161 \docparam{pWhereClause
}{{\it OPTIONAL
}. If the typeOfUpd is DB
\_UPD\_WHERE,
2162 then you must also pass in a SQL WHERE clause in this argument. Default is "".
}
2166 This member function allows you to see what the SQL UPDATE statement looks like
2167 that the ODBC class library builds. This can be used for debugging purposes if
2168 you are having problems executing your SQL statement.
2170 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2171 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2174 \membersection{wxDbTable::BuildWhereStmt
}\label{wxdbtablebuildwherestmt
}
2176 \func{void
}{BuildSelectStmt
}{\param{wxString \&
}{pWhereClause
},
2177 \param{int
}{typeOfWhere
},
\param{const wxString \&
}{qualTableName=""
},
2178 \param{bool
}{useLikeComparison=FALSE
}}
2180 Constructs the portion of a SQL statement which would follow the word 'WHERE'
2181 in a SQL statement to be passed to the datasource. The returned string
2182 does NOT include the word 'WHERE'.
2184 \wxheading{Parameters
}
2186 \docparam{pWhereClause
}{Pointer to storage for the SQL statement retrieved.
2187 To be sure you have adequate space allocated for the SQL statement, allocate
2188 DB
\_MAX\_STATEMENT\_LEN bytes.
}
2189 \docparam{typeOfWhere
}{The type of where clause to generate. Can be one of
2190 two values: DB
\_WHERE\_KEYFIELDS or DB
\_WHERE\_MATCHING.
}
2191 \docparam{qualTableName
}{{\it OPTIONAL
}. Prepended to all base table
2192 column names. For use when a FROM clause has been specified with the
2193 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
},
2194 to clarify which table a column name reference belongs to. Default is "".
}
2195 \docparam{useLikeComparison
}{{\it OPTIONAL
}. Should the constructed WHERE
2196 clause utilize the LIKE comparison operator. If FALSE, then the '='
2197 operator is used. Default is FALSE.
}
2201 This member function allows you to see what the SQL WHERE clause looks like
2202 that the ODBC class library builds. This can be used for debugging purposes
2203 if you are having problems executing your own SQL statements.
2205 If using 'typeOfWhere' set to DB
\_WHERE\_MATCHING, any bound columns currently
2206 containing a NULL value are not included in the WHERE clause's list of
2207 columns to use in the comparison.
2209 \membersection{wxDbTable::CanSelectForUpdate
}\label{wxdbtablecanselectforupdate
}
2211 \func{bool
}{CanSelectForUpdate
}{\void}
2213 Use this function to determine if the datasource supports SELECT ... FOR UPDATE.
2214 When the keywords "FOR UPDATE" are included as part of your SQL SELECT statement,
2215 all records
{\it retrieved
} (not just queried, but actually retrieved using
2216 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}, etc) from the result set are
2221 Not all datasources support the "FOR UPDATE" clause, so you must use this
2222 member function to determine if the datasource currently connected to supports
2223 this behavior or not before trying to select using "FOR UPDATE".
2225 If the wxDbTable instance was created with the parameter wxDB
\_QUERY\_ONLY, then
2226 this function will return FALSE. For all known databases which do not support
2227 the FOR UPDATE clause, this function will return FALSE also.
2229 \membersection{wxDbTable::CanUpdateByROWID
}\label{wxdbtablecanupdatebyrowid
}
2231 \func{bool
}{CanUpdateByROWID
}{\void}
2233 CURRENTLY ONLY POSSIBLE IF USING ORACLE.
2235 --- CURRENTLY DISABLED FOR *ALL* DATASOURCES --- NOV
1 2000 - gt
2237 Every Oracle table has a hidden column named ROWID. This is a pointer to the
2238 physical location of the record in the datasource and allows for very fast
2239 updates and deletes. The key is to retrieve this ROWID during your query so
2240 it is available during an update or delete operation.
2242 Use of the ROWID feature is always handled by the class library except in the
2243 case of
\helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}. Since
2244 you are passing in the SQL SELECT statement,
2245 it is up to you to include the ROWID column in your query. If you do not,
2246 the application will still work, but may not be as optimized. The ROWID is
2247 always the last column in the column list in your SQL SELECT statement.
2248 The ROWID is not a column in the normal sense and should not be considered
2249 part of the column definitions for the wxDbTable object.
2253 The decision to include the ROWID in your SQL SELECT statement must be
2254 deferred until runtime since it depends on whether you are connected
2255 to an Oracle datasource or not.
2260 // Incomplete code sample
2263 if (parts.CanUpdByROWID())
2265 // Note that the ROWID column must always be the last column selected
2266 sqlStmt = "SELECT PART_NO, PART_DESC, ROWID" FROM PARTS";
2269 sqlStmt = "SELECT PART_NO, PART_DESC FROM PARTS";
2273 \membersection{wxDbTable::ClearMemberVar
}\label{wxdbtableclearmembervar
}
2275 \func{void
}{ClearMemberVar
}{\param{UWORD
}{colNo
},
\param{bool
}{setToNull=FALSE
}}
2277 Same as
\helpref{wxDbTable::ClearMemberVars
}{wxdbtableclearmembervars
} except
2278 that this function clears only the specified column of its values, and
2279 optionally sets the column to be a NULL column.
2281 \docparam{colNo
}{Column number that is to be cleared. This number (between
0
2282 and (noCols-
1)) is the index of the column definition created using the
2283 \helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
} function.
}
2284 \docparam{setToNull
}{{\it OPTIONAL
}. Indicates whether the column should be
2285 flagged as being a NULL value stored in the bound memory variable. If TRUE,
2286 then any value stored in the bound member variable is cleared. Default is
2289 \membersection{wxDbTable::ClearMemberVars
}\label{wxdbtableclearmembervars
}
2291 \func{void
}{ClearMemberVars
}{\param{bool
}{setToNull=FALSE
}}
2293 Initializes all bound columns of the wxDbTable instance to zero. In the case
2294 of a string, zero is copied to the first byte of the string.
2296 \docparam{setToNull
}{{\it OPTIONAL
}. Indicates whether all columns should be
2297 flagged as having a NULL value stored in the bound memory variable. If TRUE,
2298 then any value stored in the bound member variable is cleared. Default is
2303 This is useful before calling functions such as
2304 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2305 \helpref{wxDbTable::DeleteMatching
}{wxdbtabledeletematching
} since these
2306 functions build their WHERE clauses from non-zero columns. To call either
2307 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2308 \helpref{wxDbTable::DeleteMatching
}{wxdbtabledeletematching
} use this sequence:
2311 1) ClearMemberVars()
2312 2) Assign columns values you wish to match on
2313 3) Call wxDbTable::QueryMatching() or wxDbTable::DeleteMatching()
2316 \membersection{wxDbTable::CloseCursor
}\label{wxdbtableclosecursor
}
2318 \func{bool
}{CloseCursor
}{\param{HSTMT
}{cursor
}}
2320 Closes the specified cursor associated with the wxDbTable object.
2322 \wxheading{Parameters
}
2324 \docparam{cursor
}{The cursor to be closed.
}
2328 Typically handled internally by the ODBC class library, but may be used by the
2329 programmer if desired.
2331 \normalbox{DO NOT CLOSE THE wxDB
\_DEFAULT\_CURSOR!
}
2333 \membersection{wxDbTable::Count
}\label{wxdbtablecount
}
2335 \func{ULONG
}{Count
}{\param{const wxString \&
}{args="*"
}}
2337 Returns the number of records which would be in the result set using the
2338 current query parameters specified in the WHERE and FROM clauses.
2340 \wxheading{Parameters
}
2342 \docparam{args
}{{\it OPTIONAL
}. This argument allows the use of the
2343 DISTINCT keyword against a column name to cause the returned count to
2344 only indicate the number of rows in the result set that have a unique
2345 value in the specified column. An example is shown below. Default is "*",
2346 meaning a count of the total number of rows matching is returned, regardless
2351 This function can be called before or after an actual query to obtain the
2352 count of records in the result set. Count() uses its own cursor, so result
2353 set cursor positioning is not affected by calls to Count().
2355 WHERE and FROM clauses specified using
2356 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2357 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} ARE used by
2366 FIRST_NAME LAST_NAME
2367 ----------- ----------
2373 // Incomplete code sample
2376 users.SetWhereClause("");
2378 // This Count() will return
4, as there are four users listed above
2379 // that match the query parameters
2380 totalNumberOfUsers = users.Count();
2382 // This Count() will return
3, as there are only
3 unique first names
2383 // in the table above - John, Richard, Michael.
2384 totalNumberOfUniqueFirstNames = users.Count("DISTINCT FIRST_NAME");
2387 \membersection{wxDbTable::CreateIndex
}\label{wxdbtablecreateindex
}
2389 \func{bool
}{CreateIndex
}{\param{const wxString \&
}{idxName
},
\param{bool
}{unique
},
2390 \param{UWORD
}{noIdxCols
},
\param{wxDbIdxDef *
}{pIdxDefs
},
2391 \param{bool
}{attemptDrop=TRUE
}}
2393 This member function allows you to create secondary (non primary) indexes on
2394 your tables. You first create your table, normally specifying a primary
2395 index, and then create any secondary indexes on the table. Indexes in
2396 relational model are not required. You do not need indexes to look up records
2397 in a table or to join two tables together. In the relational model, indexes,
2398 if available, provide a quicker means to look up data in a table. To enjoy
2399 the performance benefits of indexes, the indexes must be defined on the
2400 appropriate columns and your SQL code must be written in such a way as to
2401 take advantage of those indexes.
2403 \wxheading{Parameters
}
2405 \docparam{idxName
}{Name of the Index. Name must be unique within the table
2406 space of the datasource.
}
2407 \docparam{unique
}{Indicates if this index is unique.
}
2408 \docparam{noIdxCols
}{Number of columns in the index.
}
2409 \docparam{pIdxDefs
}{A pointer to an array wxDbIdxDef structures.
}
2410 \docparam{attemptDrop
}{{\it OPTIONAL
}. Indicates if the function should try
2411 to execute a
\helpref{wxDbTable::DropIndex
}{wxdbtabledropindex
} on the index
2412 name provided before trying to create the index name. Default is TRUE.
}
2416 The first parameter, index name, must be unique and should be given a
2417 meaningful name. Common practice is to include the table name as a prefix
2418 in the index name (e.g. For table PARTS, you might want to call your index
2419 PARTS
\_IDX1). This will allow you to easily view all
2420 of the indexes defined for a given table grouped together alphabetically.
2422 The second parameter indicates if the index is unique or not. Uniqueness
2423 is enforced at the RDBMS level preventing rows which would have duplicate
2424 indexes from being inserted into the table when violating a unique index's
2427 In the third parameter, specify how many columns are in your index. This
2428 number must match the number of columns defined in the 'pIdxDefs' parameter.
2430 The fourth parameter specifies which columns make up the index using the
2431 wxDbIdxDef structure. For each column in the index, you must specify two
2432 things, the column name and the sort order (ascending / descending). See
2433 the example below to see how to build and pass in the wxDbIdxDef structure.
2435 The fifth parameter is provided to handle the differences in datasources as
2436 to whether they will automatically overwrite existing indexes with the same
2437 name or not. Some datasources require that the existing index must be dropped
2438 first, so this is the default behavior.
2440 Some datasources (MySQL, and possibly others) require columns which are to be
2441 part of an index to be defined as NOT NULL. When this function is called, if
2442 a column is not defined to be NOT NULL, a call to this function will modify
2443 the column definition to change any columns included in the index to be
2444 NOT NULL. In this situation, if a NULL value already exists in one of the
2445 columns that is being modified, creation of the index will fail.
2447 PostGres is unable to handle index definitions which specify whether the index
2448 is ascending or descending, and defaults to the system default when the index
2451 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2452 after executing this function.
2457 // Create a secondary index on the PARTS table
2458 wxDbIdxDef idxDef
[2]; //
2 columns make up the index
2460 wxStrcpy(idxDef
[0].ColName, "PART_DESC"); // Column
1
2461 idxDef
[0].Ascending = TRUE;
2463 wxStrcpy(idxDef
[1].ColName, "SERIAL_NO"); // Column
2
2464 idxDef
[1].Ascending = FALSE;
2466 // Create a name for the index based on the table's name
2468 indexName.Printf("
%s_IDX1",parts->GetTableName());
2469 parts->CreateIndex(indexName, TRUE,
2, idxDef);
2472 \membersection{wxDbTable::CreateTable
}\label{wxdbtablecreatetable
}
2474 \func{bool
}{CreateTable
}{\param{bool
}{attemptDrop=TRUE
}}
2476 Creates a table based on the definitions previously defined for this
2479 \wxheading{Parameters
}
2481 \docparam{attemptDrop
}{{\it OPTIONAL
}. Indicates whether the driver should
2482 attempt to drop the table before trying to create it. Some datasources will
2483 not allow creation of a table if the table already exists in the table space
2484 being used. Default is TRUE.
}
2488 This function creates the table and primary index (if any) in the table space
2489 associated with the connected datasource. The owner of these objects will
2490 be the user id that was given when
\helpref{wxDb::Open
}{wxdbopen
} was called.
2491 The objects will be created in the default schema/table space for that user.
2493 In your derived wxDbTable object constructor, the columns and primary index
2494 of the table are described through the
\helpref{wxDbColDef
}{wxdbcoldef
} structure.
2495 \helpref{wxDbTable::CreateTable
}{wxdbtablecreatetable
} uses this information
2496 to create the table and to add the primary index. See
2497 \helpref{wxDbTable
}{wxdbtable
} ctor and wxDbColDef description for additional
2498 information on describing the columns of the table.
2500 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2501 after executing this function.
2503 \membersection{wxDbTable::DB
\_STATUS}\label{wxdbtabledbstatus
}
2505 \func{bool
}{DB
\_STATUS}{\void}
2507 Accessor function that returns the wxDb private member variable DB
\_STATUS for
2508 the database connection used by this instance of wxDbTable.
2510 \membersection{wxDbTable::Delete
}\label{wxdbtabledelete
}
2512 \func{bool
}{Delete
}{\void}
2514 Deletes the row from the table indicated by the current cursor.
2518 Use
\helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
},
2519 \helpref{wxDbTable::GetLast
}{wxdbtablegetlast
},
2520 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
} or
2521 \helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
} to position the cursor to
2522 a valid record. Once positioned on a record, call this function to delete
2523 the row from the table.
2525 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2526 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
2527 this function to commit or rollback the deletion.
2529 NOTE: Most datasources have a limited size "rollback" segment. This means
2530 that it is only possible to insert/update/delete a finite number of rows
2531 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2532 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2533 segment varies from database to database, and is user configurable in
2534 most databases. Therefore it is usually best to try to perform a commit
2535 or rollback at relatively small intervals when processing a larger number
2536 of actions that insert/update/delete rows in a table.
2538 \membersection{wxDbTable::DeleteCursor
}\label{wxdbtabledeletecursor
}
2540 \func{bool
}{DeleteCursor
}{\param{HSTMT *
}{hstmtDel
}}
2542 Allows a program to delete a cursor.
2544 \wxheading{Parameters
}
2546 \docparam{hstmtDel
}{Handle of the cursor to delete.
}
2550 For default cursors associated with the instance of wxDbTable, it is not
2551 necessary to specifically delete the cursors. This is automatically done
2552 in the wxDbTable destructor.
2554 NOTE: If the cursor could not be deleted for some reason, an error is logged
2555 indicating the reason. Even if the cursor could not be deleted, the HSTMT
2556 that is passed in is deleted, and the pointer is set to NULL.
2558 \normalbox{DO NOT DELETE THE wxDB
\_DEFAULT\_CURSOR!
}
2560 \membersection{wxDbTable::DeleteMatching
}\label{wxdbtabledeletematching
}
2562 \func{bool
}{DeleteMatching
}{\void}
2564 This member function allows you to delete records from your wxDbTable object
2565 by specifying the data in the columns to match on.
2569 To delete all users with a first name of "JOHN", do the following:
2572 1) Clear all "columns" using wxDbTable::ClearMemberVars().
2573 2) Set the FIRST_NAME column equal to "JOHN".
2574 3) Call wxDbTable::DeleteMatching().
2577 The WHERE clause is built by the ODBC class library based on all non-NULL
2578 columns. This allows deletion of records by matching on any column(s) in
2579 your wxDbTable instance, without having to write the SQL WHERE clause.
2581 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2582 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
2583 this function to commit or rollback the deletion.
2585 NOTE: Row(s) should be locked before deleting them to make sure they are
2586 not already in use. This can be achieved by calling
2587 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
},
2588 and then retrieving the records, locking each as you go (assuming FOR UPDATE
2589 is allowed on the datasource). After the row(s) have been successfully locked,
2592 NOTE: Most datasources have a limited "rollback" segment. This means
2593 that it is only possible to insert/update/delete a finite number of rows
2594 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2595 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2596 segment varies from database to database, and is user configurable in
2597 most databases. Therefore it is usually best to try to perform a commit
2598 or rollback at relatively small intervals when processing a larger number
2599 of actions that insert/update/delete rows in a table.
2604 // Incomplete code sample to delete all users with a first name
2606 users.ClearMemberVars();
2607 wxStrcpy(users.FirstName,"JOHN");
2608 users.DeleteMatching();
2612 \membersection{wxDbTable::DeleteWhere
}\label{wxdbtabledeletewhere
}
2614 \func{bool
}{DeleteWhere
}{\param{const wxString \&
}{pWhereClause
}}
2616 Deletes all rows from the table which match the criteria specified in the
2617 WHERE clause that is passed in.
2619 \wxheading{Parameters
}
2621 \docparam{pWhereClause
}{SQL WHERE clause. This WHERE clause determines which
2622 records will be deleted from the table interfaced through the wxDbTable
2623 instance. The WHERE clause passed in must be compliant with the SQL
92
2624 grammar. Do not include the keyword 'WHERE'
2629 This is the most powerful form of the wxDbTable delete functions. This
2630 function gives access to the full power of SQL. This function can be used
2631 to delete records by passing a valid SQL WHERE clause. Sophisticated
2632 deletions can be performed based on multiple criteria using the full
2633 functionality of the SQL language.
2635 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} must be called after use of
2636 this function to commit the deletions.
2638 Note: This function is limited to deleting records from the table associated
2639 with this wxDbTable object only. Deletions on joined tables is not possible.
2641 NOTE: Most datasources have a limited size "rollback" segment. This means
2642 that it is only possible to insert/update/delete a finite number of rows
2643 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2644 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2645 segment varies from database to database, and is user configurable in
2646 most databases. Therefore it is usually best to try to perform a commit
2647 or rollback at relatively small intervals when processing a larger number
2648 of actions that insert/update/delete rows in a table.
2650 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2651 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2657 // Delete parts
1 thru
10 from containers 'X', 'Y' and 'Z' that
2658 // are magenta in
color
2659 parts.DeleteWhere("(PART_NUMBER BETWEEN
1 AND
10) AND \
2660 CONTAINER IN ('X', 'Y', 'Z') AND \
2661 UPPER(COLOR) = 'MAGENTA'");
2665 \membersection{wxDbTable::DropIndex
}\label{wxdbtabledropindex
}
2667 \func{bool
}{DropIndex
}{\param{const wxString \&
}{idxName
}}
2669 Allows an index on the associated table to be dropped (deleted) if the user
2670 login has sufficient privileges to do so.
2672 \wxheading{Parameters
}
2674 \docparam{idxName
}{Name of the index to be dropped.
}
2678 If the index specified in the 'idxName' parameter does not exist, an error
2679 will be logged, and the function will return a result of FALSE.
2681 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2682 after executing this function.
2684 \membersection{wxDbTable::DropTable
}\label{wxdbtabledroptable
}
2686 \func{bool
}{DropTable
}{\void}
2688 Deletes the associated table if the user has sufficient privileges to do so.
2692 This function returns TRUE if the table does not exist, but only for
2693 supported databases (see
\helpref{wxDb::Dbms
}{wxdbdbms
}). If a datasource
2694 is not specifically supported, and this function is called, the function
2697 Most datasources/ODBC drivers will delete any indexes associated with the
2698 table automatically, and others may not. Check the documentation for your
2699 database to determine the behavior.
2701 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2702 after executing this function.
2704 \membersection{wxDbTable::From
}\label{wxdbtablefrom
}
2706 \func{const wxString \&
}{From
}{}
2708 \func{void
}{From
}{\param{const wxString \&
}{From
}}
2710 Accessor function for the private class member wxDbTable::from. Can be used
2711 as a synonym for
\helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
}
2712 (the first form of this function) or
2713 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} (the second form
2716 \wxheading{Parameters
}
2718 \docparam{From
}{A comma separated list of table names that are to be outer
2719 joined with the base table's columns so that the joined table's columns
2720 may be returned in the result set or used as a portion of a comparison with
2721 the base table's columns. NOTE that the base tables name must NOT be included
2722 in the FROM clause, as it is automatically included by the wxDbTable class
2723 in constructing query statements.
}
2725 \wxheading{Return value
}
2727 The first form of this function returns the current value of the wxDbTable
2728 member variable ::from.
2730 The second form of the function has no return value, as it will always set
2731 the from clause successfully.
2733 \wxheading{See also
}
2735 \helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
},
2736 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}
2739 \membersection{wxDbTable::GetColDefs
}\label{wxdbtablegetcoldefs
}
2741 \func{wxDbColDef *
}{GetColDefs
}{}
2743 Accessor function that returns a pointer to the array of column definitions
2744 that are bound to the columns that this wxDbTable instance is associated
2747 To determine the number of elements pointed to by the returned
2748 \helpref{wxDbColDef
}{wxdbcoldef
} pointer, use the
2749 \helpref{wxDbTable::GetNumberOfColumns
}{wxdbtablegetnumberofcolumns
} function.
2753 These column definitions must not be manually redefined after they have been
2756 \membersection{wxDbTable::GetCursor
}\label{wxdbtablegetcursor
}
2758 \func{HSTMT
}{GetCursor
}{\void}
2760 Returns the HSTMT value of the current cursor for this wxDbTable object.
2764 This function is typically used just before changing to use a different cursor
2765 so that after the program is finished using the other cursor, the current
2766 cursor can be set back to being the cursor in use.
2768 \wxheading{See also
}
2770 \helpref{wxDbTable::SetCursor
}{wxdbtablesetcursor
},
\helpref{wxDbTable::GetNewCursor
}{wxdbtablegetnewcursor
}
2772 \membersection{wxDbTable::GetDb
}\label{wxdbtablegetdb
}
2774 \func{wxDb *
}{GetDb
}{}
2776 Accessor function for the private member variable pDb which is a pointer to
2777 the datasource connection that this wxDbTable instance uses.
2779 \membersection{wxDbTable::GetFirst
}\label{wxdbtablegetfirst
}
2781 \func{bool
}{GetFirst
}{\void}
2783 Retrieves the FIRST row in the record set as defined by the current query.
2784 Before retrieving records, a query must be performed using
2785 \helpref{wxDbTable::Query
}{wxdbtablequery
},
2786 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2787 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2788 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2792 This function can only be used if the datasource connection used by the
2793 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2794 connection does not allow backward scrolling cursors, this function will
2795 return FALSE, and the data contained in the bound columns will be undefined.
2797 \wxheading{See also
}
2799 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
}
2801 \membersection{wxDbTable::GetFromClause
}\label{wxdbtablegetfromclause
}
2803 \func{const wxString \&
}{GetFromClause
}{}
2805 Accessor function that returns the current FROM setting assigned with the
2806 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}.
2808 \wxheading{See also
}
2810 \helpref{wxDbTable::From
}{wxdbtablefrom
}
2812 \membersection{wxDbTable::GetLast
}\label{wxdbtablegetlast
}
2814 \func{bool
}{GetLast
}{\void}
2816 Retrieves the LAST row in the record set as defined by the current query.
2817 Before retrieving records, a query must be performed using
2818 \helpref{wxDbTable::Query
}{wxdbtablequery
},
2819 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2820 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2821 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2825 This function can only be used if the datasource connection used by the
2826 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2827 connection does not allow backward scrolling cursors, this function will
2828 return FALSE, and the data contained in the bound columns will be undefined.
2830 \wxheading{See also
}
2832 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
}
2834 \membersection{wxDbTable::GetNewCursor
}\label{wxdbtablegetnewcursor
}
2836 \func{HSTMT *
}{GetNewCursor
}{\param{bool
}{setCursor=FALSE
},
2837 \param{bool
}{bindColumns=TRUE
}}
2839 This function will create a new cursor that can be used to access the table
2840 being referenced by this wxDbTable instance, or to execute direct SQL commands
2841 on without affecting the cursors that are already defined and possibly
2844 \wxheading{Parameters
}
2846 \docparam{setCursor
}{{\it OPTIONAL
}. Should this new cursor be set to be the
2847 current cursor after successfully creating the new cursor. Default is FALSE.
}
2848 \docparam{bindColumns
}{{\it OPTIONAL
}. Should this new cursor be bound to all
2849 the memory variables that the default cursor is bound to. Default is TRUE.
}
2853 This new cursor must be closed using
2854 \helpref{wxDbTable::DeleteCursor
}{wxdbtabledeletecursor
}
2855 by the calling program before the wxDbTable instance is deleted, or both
2856 memory and resource leaks will occur.
2858 \membersection{wxDbTable::GetNext
}\label{wxdbtablegetnext
}
2860 \func{bool
}{GetNext
}{\void}
2862 Retrieves the NEXT row in the record set after the current cursor position
2863 as defined by the current query. Before retrieving records, a query must be
2864 performed using
\helpref{wxDbTable::Query
}{wxdbtablequery
},
2865 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2866 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2867 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2869 \wxheading{Return value
}
2871 This function returns FALSE when the current cursor has reached the end of
2872 the result set. When FALSE is returned, data in the bound columns is
2877 This function works with both forward and backward scrolling cursors.
2879 \wxheading{See also
}
2880 \helpref{wxDbTable::++
}{wxdbtableplusplus
}
2882 \membersection{wxDbTable::GetNumberOfColumns
}\label{wxdbtablegetnumberofcolumns
}
2884 \func{UWORD
}{GetNumberOfColumns
}{}
2886 Accessor function that returns the number of columns that are statically
2887 bound for access by the wxDbTable instance.
2889 \membersection{wxDbTable::GetOrderByClause
}\label{wxdbtablegetorderbyclause
}
2891 \func{const wxString \&
}{GetOrderByClause
}{}
2893 Accessor function that returns the current ORDER BY setting assigned with
2894 the
\helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
}.
2896 \wxheading{See also
}
2898 \helpref{wxDbTable::OrderBy
}{wxdbtableorderby
}
2900 \membersection{wxDbTable::GetPrev
}\label{wxdbtablegetprev
}
2902 \func{bool
}{GetPrev
}{\void}
2904 Retrieves the PREVIOUS row in the record set before the current cursor
2905 position as defined by the current query. Before retrieving records, a
2906 query must be performed using
\helpref{wxDbTable::Query
}{wxdbtablequery
},
2907 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2908 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2909 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2911 \wxheading{Return value
}
2913 This function returns FALSE when the current cursor has reached the beginning
2914 of the result set and there are now other rows prior to the cursors current
2915 position. When FALSE is returned, data in the bound columns is undefined.
2919 This function can only be used if the datasource connection used by the
2920 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2921 connection does not allow backward scrolling cursors, this function will
2922 return FALSE, and the data contained in the bound columns will be undefined.
2924 \wxheading{See also
}
2926 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
},
2927 \helpref{wxDbTable::--
}{wxdbtableminusminus
}
2929 \membersection{wxDbTable::GetQueryTableName
}\label{wxdbtablegetquerytablename
}
2931 \func{const wxString \&
}{GetQueryTableName
}{}
2933 Accessor function that returns the name of the table/view that was indicated
2934 as being the table/view to query against when this wxDbTable instance was
2937 \wxheading{See also
}
2939 \helpref{wxDbTable constructor
}{wxdbtableconstr
}
2941 \membersection{wxDbTable::GetRowNum
}\label{wxdbtablegetrownum
}
2943 \func{UWORD
}{GetRowNum
}{\void}
2945 Returns the ODBC row number for performing positioned updates and deletes.
2949 This function is not being used within the ODBC class library and may be a
2950 candidate for removal if no use is found for it.
2952 Row number with some datasources/ODBC drivers is the position in the result set,
2953 while in others it may be a physical position in the database. Check your
2954 database documentation to find out which behavior is supported.
2956 \membersection{wxDbTable::GetTableName
}\label{wxdbtablegettablename
}
2958 \func{const wxString \&
}{GetTableName
}{}
2960 Accessor function that returns the name of the table that was indicated
2961 as being the table that this wxDbTable instance was associated with.
2963 \membersection{wxDbTable::GetTablePath
}\label{wxdbtablegettablepath
}
2965 \func{const wxString \&
}{GetTablePath
}{}
2967 Accessor function that returns the path to the data table that was indicated
2968 during creation of this wxDbTable instance.
2972 Currently only applicable to dBase and MS-Access datasources.
2974 \membersection{wxDbTable::GetWhereClause
}\label{wxdbtablegetwhereclause
}
2976 \func{const wxString \&
}{GetWhereClause
}{}
2978 Accessor function that returns the current WHERE setting assigned with the
2979 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2981 \wxheading{See also
}
2983 \helpref{wxDbTable::Where
}{wxdbtablewhere
}
2985 \membersection{wxDbTable::Insert
}\label{wxdbtableinsert
}
2987 \func{int
}{Insert
}{\void}
2989 Inserts a new record into the table being referenced by this wxDbTable
2990 instance. The values in the member variables of the wxDbTable instance are
2991 inserted into the columns of the new row in the database.
2993 \wxheading{Return value
}
2996 DB_SUCCESS Record inserted successfully (value =
1)
2998 DB_FAILURE Insert failed (value =
0)
3000 DB_ERR_INTEGRITY_CONSTRAINT_VIOL
3001 The insert failed due to an integrity
3002 constraint violation (duplicate non-unique
3003 index entry) is attempted.
3008 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
3009 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
3010 this function to commit or rollback the insertion.
3015 // Incomplete code snippet
3016 wxStrcpy(parts->PartName, "
10");
3017 wxStrcpy(parts->PartDesc, "Part
#10");
3019 RETCODE retcode = parts->Insert();
3023 parts->GetDb()->CommitTrans();
3025 case DB_ERR_INTEGRITY_CONSTRAINT_VIOL:
3026 // Current data would result in a duplicate key
3027 // on one or more indexes that do not allow duplicates
3028 parts->GetDb()->RollbackTrans();
3031 // Insert failed for some unexpected reason
3032 parts->GetDb()->RollbackTrans();
3037 \membersection{wxDbTable::IsColNull
}\label{wxdbtableiscolnull
}
3039 \func{bool
}{IsColNull
}{\param{UWORD
}{colNo
}} const
3041 Used primarily in the ODBC class library to determine if a column value is
3042 set to "NULL". Works for all data types supported by the ODBC class library.
3044 \wxheading{Parameters
}
3046 \docparam{colNo
}{The column number of the bound column as defined by the
3047 \helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
3048 calls which defined the columns accessible to this wxDbTable instance.
}
3052 NULL column support is currently not fully implemented as of wxWindows
2.4.
3054 \membersection{wxDbTable::IsCursorClosedOnCommit
}\label{wxdbtableiscursorclosedoncommit
}
3056 \func{bool
}{IsCursorClosedOnCommit
}{\void}
3058 Accessor function to return information collected during the opening of the
3059 datasource connection that is used by this wxDbTable instance. The result
3060 returned by this function indicates whether an implicit closing of the cursor is
3061 done after a commit on the database connection.
3063 \wxheading{Return value
}
3065 Returns TRUE if the cursor associated with this wxDbTable object is closed
3066 after a commit or rollback operation. Returns FALSE otherwise.
3070 If more than one wxDbTable instance used the same database connection, all cursors
3071 which use the database connection are closed on the commit if this function
3074 \membersection{wxDbTable::IsQueryOnly
}\label{wxdbtableisqueryonly
}
3076 \func{bool
}{IsQueryOnly
}{}
3078 Accessor function that returns a value indicating if this wxDbTable instance
3079 was created to allow only queries to be performed on the bound columns. If
3080 this function returns TRUE, then no actions may be performed using this
3081 wxDbTable instance that would modify (insert/delete/update) the table's data.
3083 \membersection{wxDbTable::Open
}\label{wxdbtableopen
}
3085 \func{bool
}{Open
}{\param{bool
}{checkPrivileges=FALSE
},
\param{bool
}{checkTableExists=TRUE
}}
3087 Every wxDbTable instance must be opened before it can be used. This function
3088 checks for the existence of the requested table, binds columns, creates required
3089 cursors, (insert/select and update if connection is not wxDB
\_QUERY\_ONLY) and
3090 constructs the insert statement that is to be used for inserting data as a new
3091 row in the datasource.
3093 \wxheading{Parameters
}
3095 \docparam{checkPrivileges
}{Indicates whether the Open() function should check
3096 whether the current connected user has at least SELECT privileges to access the
3097 table to which they are trying to open. Default is FALSE.
}
3099 \docparam{checkTableExists
}{Indicates whether the Open() function should check
3100 whether the table exists in the database or not before opening it. Default is TRUE.
}
3104 If the function returns a FALSE value due to the table not existing, a log
3105 entry is recorded for the datasource connection indicating the problem
3106 that was detected when checking for table existence. Note that it is usually
3107 best for the calling routine to check for the existence of the table and for
3108 sufficient user privileges to access the table in the mode (wxDB
\_QUERY\_ONLY or
3109 !wxDB
\_QUERY\_ONLY) before trying to open the table for the best possible
3110 explanation as to why a table cannot be opened.
3112 Checking the user's privileges on a table can be quite time consuming during
3113 the open phase. With most applications, the programmer already knows that the
3114 user has sufficient privileges to access the table, so this check is normally
3117 For best performance, open the table, and then use the
3118 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
} function
3119 to check the users privileges. Passing a schema to the TablePrivileges()
3120 function can significantly speed up the privileges checks.
3122 \wxheading{See also
}
3124 \helpref{wxDb::TableExists
}{wxdbtableexists
},
3125 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
}
3127 \membersection{wxDbTable::OrderBy
}\label{wxdbtableorderby
}
3129 \func{const wxString \&
}{OrderBy
}{}
3131 \func{void
}{OrderBy
}{\param{const wxString \&
}{OrderBy
}}
3133 Accessor function for the private class member wxDbTable::orderBy. Can be
3134 used as a synonym for
3135 \helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
}
3136 (the first form of this function) or
3137 \helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
}
3138 (the second form of this function).
3140 \wxheading{Parameters
}
3142 \docparam{OrderBy
}{A comma separated list of column names that indicate the
3143 alphabetized/numeric sorting sequence that the result set is to be returned
3144 in. If a FROM clause has also been specified, each column name specified in
3145 the ORDER BY clause should be prefaced with the table name to which the column
3146 belongs using DOT notation (TABLE
\_NAME.COLUMN
\_NAME).
}
3148 \wxheading{Return value
}
3150 The first form of this function returns the current value of the wxDbTable
3151 member variable ::orderBy.
3153 The second form of the function has no return value.
3155 \wxheading{See also
}
3157 \helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
},
3158 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}
3160 \membersection{wxDbTable::Query
}\label{wxdbtablequery
}
3162 \func{virtual bool
}{Query
}{\param{bool
}{forUpdate=FALSE
},
\param{bool
}{distinct=FALSE
}}
3164 \wxheading{Parameters
}
3166 \docparam{forUpdate
}{{\it OPTIONAL
}. Gives you the option of locking records
3167 as they are retrieved. If the RDBMS is not capable of the FOR UPDATE clause,
3168 this argument is ignored. See
3169 \helpref{wxDbTable::CanSelectForUpdate
}{wxdbtablecanselectforupdate
} for
3170 additional information regarding this argument. Default is FALSE.
}
3171 \docparam{distinct
}{{\it OPTIONAL
}. Allows selection of only distinct values
3172 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
3173 applies to all columns returned in the result set, not individual columns.
3178 This function queries records from the datasource based on the three
3179 wxDbTable members: "where", "orderBy", and "from". Use
3180 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
} to filter on
3181 records to be retrieved (e.g. All users with a first name of "JOHN").
3182 Use
\helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
} to
3183 change the sequence in which records are returned in the result set from
3184 the datasource (e.g. Ordered by LAST
\_NAME). Use
3185 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} to allow outer
3186 joining of the base table (the one being associated with this instance of
3187 wxDbTable) with other tables which share a related field.
3189 After each of these clauses are set/cleared, call wxDbTable::Query() to
3190 fetch the result set from the datasource.
3192 This scheme has an advantage if you have to requery your record set
3193 frequently in that you only have to set your WHERE, ORDER BY, and FROM
3194 clauses once. Then to refresh the record set, simply call wxDbTable::Query()
3195 as frequently as needed.
3197 Note that repeated calls to wxDbTable::Query() may tax the database
3198 server and make your application sluggish if done too frequently or
3201 The base table name is automatically prepended to the base column names in
3202 the event that the FROM clause has been set (is non-null) using
3203 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}.
3205 The cursor for the result set is positioned
{\it before
} the first record in
3206 the result set after the query. To retrieve the first record, call either
3207 \helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
} (only if backward scrolling
3208 cursors are available) or
3209 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}. Typically, no data from the
3210 result set is returned to the client driver until a request such as
3211 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
} is performed, so network
3212 traffic and database load are not overwhelmed transmitting data until the
3213 data is actually requested by the client. This behavior is solely dependent
3214 on the ODBC driver though, so refer to the ODBC driver's reference material
3215 for information on its behaviors.
3217 Values in the bound columns' memory variables are undefined after executing a
3218 call to this function and remain that way until a row in the result set is
3219 requested to be returned.
3221 The wxDbTable::Query() function is defined as "virtual" so that it may be
3222 overridden for application specific purposes.
3224 \normalbox{Be sure to set the wxDbTable's "where", "orderBy", and "from"
3225 member variables to "" if they are not to be used in the query. Otherwise,
3226 the results returned may have unexpected results (or no results) due to
3227 improper or incorrect query parameters constructed from the uninitialized
3233 // Incomplete code sample
3234 parts->SetWhereClause("DESCRIPTION = 'FOOD'");
3235 parts->SetOrderByClause("EXPIRATION_DATE");
3236 parts->SetFromClause("");
3237 // Query the records based on the where, orderBy and from clauses
3240 // Display all records queried
3241 while(parts->GetNext())
3242 dispPart(parts); // user defined function
3245 \membersection{wxDbTable::QueryBySqlStmt
}\label{wxdbtablequerybysqlstmt
}
3247 \func{bool
}{QueryBySqlStmt
}{\param{const wxString \&
}{pSqlStmt
}}
3249 Performs a query against the datasource by accepting and passing verbatim the
3250 SQL SELECT statement passed to the function.
3252 \wxheading{Parameters
}
3254 \docparam{pSqlStmt
}{Pointer to the SQL SELECT statement to be executed.
}
3258 This is the most powerful form of the query functions available. This member
3259 function allows a programmer to write their own custom SQL SELECT statement
3260 for requesting data from the datasource. This gives the programmer access
3261 to the full power of SQL for performing operations such as scalar functions,
3262 aggregate functions, table joins, and sub-queries, as well as datasource
3263 specific function calls.
3265 The requirements of the SELECT statement are the following:
3268 1. Must return the correct number of columns. In the derived
3269 wxDbTable constructor, it is specified how many columns are in
3270 the wxDbTable object. The SELECT statement must return exactly
3273 2. The columns must be returned in the same sequence as specified
3274 when defining the bounds columns using wxDbTable::SetColDefs(),
3275 and the columns returned must be of the proper data type. For
3276 example, if column
3 is defined in the wxDbTable bound column
3277 definitions to be a float, the SELECT statement must return a
3278 float for column
3 (e.g. PRICE *
1.10 to increase the price by
3281 3. The ROWID can be included in your SELECT statement as the
{\bf last
}
3282 column selected, if the datasource supports it. Use
3283 wxDbTable::CanUpdByROWID() to determine if the ROWID can be
3284 selected from the datasource. If it can, much better
3285 performance can be achieved on updates and deletes by including
3286 the ROWID in the SELECT statement.
3289 Even though data can be selected from multiple tables (joins) in your select
3290 statement, only the base table associated with this wxDbTable object
3291 is automatically updated through the ODBC class library. Data from multiple
3292 tables can be selected for display purposes however. Include columns in
3293 the wxDbTable object and mark them as non-updateable (See
3294 \helpref{wxDbColDef
}{wxdbcoldef
} for details). This way columns can be
3295 selected and displayed from other tables, but only the base table will be
3296 updated automatically when performed through the
3297 \helpref{wxDbTable::Update
}{wxdbtableupdate
} function after using this type of
3298 query. To update tables other than the base table, use the
3299 \helpref{wxDbTable::Update
}{wxdbtableupdate
} function passing a SQL statement.
3301 After this function has been called, the cursor is positioned before the
3302 first record in the record set. To retrieve the first record, call
3303 either
\helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
} or
3304 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}.
3309 // Incomplete code samples
3311 sqlStmt = "SELECT * FROM PARTS WHERE STORAGE_DEVICE = 'SD98' \
3312 AND CONTAINER =
12";
3313 // Query the records using the SQL SELECT statement above
3314 parts->QueryBySqlStmt(sqlStmt);
3315 // Display all records queried
3316 while(parts->GetNext())
3319 Example SQL statements
3320 ----------------------
3322 // Table Join returning
3 columns
3323 SELECT part_no, part_desc, sd_name
3324 from parts, storage_devices
3325 where parts.storage_device_id =
3326 storage_devices.storage_device_id
3328 // Aggregate function returning total number of
3329 // parts in container
99
3330 SELECT count
(*) from PARTS where container = 99
3332 // Order by clause; ROWID, scalar function
3333 SELECT part_no, substring(part_desc, 1, 10), qty_on_hand + 1, ROWID
3335 where warehouse = 10
3336 order by part_no desc // descending order
3340 where container in (select container
3341 from storage_devices
3342 where device_id = 12)
3345 \membersection{wxDbTable::QueryMatching}\label{wxdbtablequerymatching}
3347 \func{virtual bool }{QueryMatching}{\param{bool }{forUpdate=FALSE},
3348 \param{bool }{distinct=FALSE}}
3350 QueryMatching allows querying of records from the table associated with
3351 the wxDbTable object by matching "columns" to values.
3353 For example: To query the datasource for the row with a PART\_NUMBER column
3354 value of "32", clear all column variables of the wxDbTable object, set the
3355 PartNumber variable that is bound to the PART\_NUMBER column in the wxDbTable
3356 object to "32", and then call wxDbTable::QueryMatching().
3358 \wxheading{Parameters}
3360 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
3361 as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
3362 the FOR UPDATE clause, this argument is ignored. See
3363 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
3364 additional information regarding this argument. Default is FALSE.}
3365 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
3366 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
3367 applies to all columns returned in the result set, not individual columns.
3372 The SQL WHERE clause is built by the ODBC class library based on all
3373 non-zero/non-NULL columns in your wxDbTable object. Matches can be on one,
3374 many or all of the wxDbTable's columns. The base table name is prepended
3375 to the column names in the event that the wxDbTable's FROM clause is non-null.
3377 This function cannot be used to perform queries which will check for
3378 columns that are 0 or NULL, as the automatically constructed WHERE clause
3379 only will contain comparisons on column member variables that are
3382 The primary difference between this function and \helpref{wxDbTable::QueryOnKeyFields}{wxdbtablequeryonkeyfields}
3383 is that this function can query on any column(s) in the wxDbTable object.
3384 Note however that this may not always be very efficient. Searching on
3385 non-indexed columns will always require a full table scan.
3387 The cursor is positioned before the first record in the record set after
3388 the query is performed. To retrieve the first record, the program must call
3389 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
3390 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
3392 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
3393 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
3399 // Incomplete code sample
3400 parts->ClearMemberVars(); // Set all columns to zero
3401 wxStrcpy(parts->PartNumber,"32"); // Set columns to query on
3402 parts->OnHold = TRUE;
3403 parts->QueryMatching(); // Query
3404 // Display all records queried
3405 while(parts->GetNext())
3406 dispPart(parts); // Some application defined function
3409 \membersection{wxDbTable::QueryOnKeyFields}\label{wxdbtablequeryonkeyfields}
3411 \func{bool }{QueryOnKeyFields}{\param{bool }{forUpdate=FALSE},
3412 \param{bool }{distinct=FALSE}}
3414 QueryOnKeyFields provides an easy mechanism to query records in the table
3415 associated with the wxDbTable object by the primary index column(s). Simply
3416 assign the primary index column(s) values and then call this member function
3417 to retrieve the record.
3419 Note that since primary indexes are always unique, this function implicitly
3420 always returns a single record from the database. The base table name is
3421 prepended to the column names in the event that the wxDbTable's FROM clause
3424 \wxheading{Parameters}
3426 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
3427 as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
3428 the FOR UPDATE clause, this argument is ignored. See
3429 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
3430 additional information regarding this argument. Default is FALSE.}
3431 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
3432 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
3433 applies to all columns returned in the result set, not individual columns.
3438 The cursor is positioned before the first record in the record set after
3439 the query is performed. To retrieve the first record, the program must call
3440 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
3441 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
3443 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
3444 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
3450 // Incomplete code sample
3451 wxStrcpy(parts->PartNumber, "32");
3452 parts->QueryOnKeyFields();
3453 // Display all records queried
3454 while(parts->GetNext())
3455 dispPart(parts); // Some application defined function
3458 \membersection{wxDbTable::Refresh}\label{wxdbtablerefresh}
3460 \func{bool}{Refresh}{\void}
3462 This function re-reads the bound columns into the memory variables, setting
3463 them to the current values stored on the disk.
3465 The cursor position and result set are unaffected by calls to this function.
3466 (The one exception is in the case where the record to be refreshed has been
3467 deleted by some other user or transaction since it was originally retrieved
3468 as part of the result set. For most datasources, the default behavior in
3469 this situation is to return the value that was originally queried for the
3470 result set, even though it has been deleted from the database. But this is
3471 datasource dependent, and should be tested before relying on this behavior.)
3475 This routine is only guaranteed to work if the table has a unique primary
3476 index defined for it. Otherwise, more than one record may be fetched and
3477 there is no guarantee that the correct record will be refreshed. The
3478 table's columns are refreshed to reflect the current data in the database.
3480 \membersection{wxDbTable::SetColDefs}\label{wxdbtablesetcoldefs}
3482 \func{void}{SetColDefs}{\param{UWORD }{index}, \param{const wxString \&}{fieldName},
3483 \param{int }{dataType}, \param{void *}{pData}, \param{SWORD }{cType},
3484 \param{int }{size}, \param{bool }{keyField = FALSE}, \param{bool }{upd = TRUE},
3485 \param{bool }{insAllow = TRUE}, \param{bool }{derivedCol = FALSE}}
3487 \func{wxDbColDataPtr *}{SetColDefs}{\param{wxDbColInf *}{colInfs}, \param{UWORD }{numCols}}
3489 \wxheading{Parameters}
3491 \docparam{index}{Column number (0 to n-1, where n is the number of columns
3492 specified as being defined for this wxDbTable instance when the
3493 wxDbTable constructor was called.}
3494 \docparam{fieldName}{Column name from the associated data table.}
3495 \docparam{dataType}{Logical data type. Valid logical types include:}
3498 DB_DATA_TYPE_VARCHAR : strings
3499 DB_DATA_TYPE_INTEGER : non-floating point numbers
3500 DB_DATA_TYPE_FLOAT : floating point numbers
3501 DB_DATA_TYPE_DATE : dates
3504 \docparam{pData}{Pointer to the data object that will hold the column's
3505 value when a row of data is returned from the datasource.}
3506 \docparam{cType}{SQL C Type. This defines the data type that the SQL
3507 representation of the data is converted to to be stored in {\it pData}.
3508 Other valid types are available also, but these are the most common ones:}
3511 SQL_C_CHAR // strings
3521 SQL_C_BOOLEAN // defined in db.h
3522 SQL_C_ENUM // defined in db.h
3525 \docparam{size}{Maximum size in bytes of the {\it pData} object.}
3526 \docparam{keyField}{{\it OPTIONAL}. Indicates if this column is part of the
3527 primary index. Default is FALSE.}
3528 \docparam{upd}{{\it OPTIONAL}. Are updates allowed on this column?
3530 \docparam{insAllow}{{\it OPTIONAL}. Inserts allowed on this column?
3532 \docparam{derivedCol}{{\it OPTIONAL}. Is this a derived column (non-base
3533 table column for query only)? Default is FALSE.}
3535 \docparam{colInfs}{Pointer to an array of wxDbColInf instances which contains
3536 all the information necessary to create {\it numCols} column definitions.}
3537 \docparam{numCols}{Number of elements of wxDbColInf type that are pointed
3538 to by {\it colInfs}, which are to have column definitions created from them.}
3542 If {\it pData} is to hold a string of characters, be sure to include enough
3543 space for the NULL terminator in pData and in the byte count of {\it size}.
3545 Both forms of this function provide a shortcut for defining the columns in
3546 your wxDbTable object. Use this function in any derived wxDbTable
3547 constructor when describing the column/columns in the wxDbTable object.
3549 The second form of this function is primarily used when the
3550 \helpref{wxDb::GetColumns}{wxdbgetcolumns} function was used to query the
3551 datasource for the column definitions, so that the column definitions are
3552 already stored in wxDbColInf form. One example use of using
3553 \helpref{wxDb::GetColumns}{wxdbgetcolumns} then using this function is if
3554 a data table existed in one datasource, and the table's column definitions
3555 were to be copied over to another datasource or table.
3560 // Long way not using this function
3561 wxStrcpy(colDefs[0].ColName, "PART_NO");
3562 colDefs[0].DbDataType = DB_DATA_TYPE_VARCHAR;
3563 colDefs[0].PtrDataObj = PartNumber;
3564 colDefs[0].SqlCtype = SQL_C_CHAR;
3565 colDefs[0].SzDataObj = PART_NUMBER_LEN;
3566 colDefs[0].KeyField = TRUE;
3567 colDefs[0].Updateable = FALSE;
3568 colDefs[0].InsertAllowed= TRUE;
3569 colDefs[0].DerivedCol = FALSE;
3571 // Shortcut using this function
3572 SetColDefs(0, "PART_NUMBER", DB_DATA_TYPE_VARCHAR, PartNumber,
3573 SQL_C_CHAR, PART_NUMBER_LEN, TRUE, FALSE,TRUE,FALSE);
3576 \membersection{wxDbTable::SetCursor}\label{wxdbtablesetcursor}
3578 \func{bool}{SetCursor}{\param{HSTMT *}{hstmtActivate = (void **) wxDB
\_DEFAULT\_CURSOR}}
3580 \wxheading{Parameters
}
3582 \docparam{hstmtActivate
}{{\it OPTIONAL
}. Pointer to the cursor that is to
3583 become the current cursor. Passing no cursor handle will reset the cursor
3584 back to the wxDbTable's default (original) cursor that was created when the
3585 wxDbTable instance was first created. Default is wxDB
\_DEFAULT\_CURSOR.
}
3589 When swapping between cursors, the member variables of the wxDbTable object
3590 are automatically refreshed with the column values of the row that the
3591 current cursor is positioned at (if any). If the cursor is not positioned,
3592 then the data in member variables is undefined.
3594 The only way to return back to the cursor that was in use before this
3595 function was called is to programmatically determine the current cursor's HSTMT
3596 {\bf BEFORE
} calling this function using
\helpref{wxDbTable::GetCursor
}{wxdbtablegetcursor
}
3597 and saving a pointer to that cursor.
3599 \wxheading{See also
}
3601 \helpref{wxDbTable::GetNewCursor
}{wxdbtablegetnewcursor
},
3602 \helpref{wxDbTable::GetCursor
}{wxdbtablegetcursor
},
3603 \helpref{wxDbTable::SetCursor
}{wxdbtablesetcursor
}
3605 \membersection{wxDbTable::SetFromClause
}\label{wxdbtablesetfromclause
}
3607 \func{void
}{SetFromClause
}{\param{const wxString \&
}{From
}}
3609 Accessor function for setting the private class member wxDbTable::from
3610 that indicates what other tables should be outer joined with the wxDbTable's
3611 base table for access to the columns in those other tables.
3613 Synonym to this function is one form of
\helpref{wxDbTable::From
}{wxdbtablefrom
}
3615 \wxheading{Parameters
}
3617 \docparam{From
}{A comma separated list of table names that are to be outer
3618 joined with the base table's columns so that the joined table's columns
3619 may be returned in the result set or used as a portion of a comparison with
3620 the base table's columns. NOTE that the base tables name must NOT be included
3621 in the FROM clause, as it is automatically included by the wxDbTable class
3622 in constructing query statements.
}
3626 Used by the
\helpref{wxDbTable::Query
}{wxdbtablequery
} and
3627 \helpref{wxDbTable::Count
}{wxdbtablecount
} member functions to allow outer
3628 joining of records from multiple tables.
3630 Do
{\bf not
} include the keyword "FROM" when setting the FROM clause.
3632 If using the FROM clause when performing a query, be certain to include in
3633 the corresponding WHERE clause a comparison of a column from either the base
3634 table or one of the other joined tables to each other joined table to ensure
3635 the datasource knows on which column values the tables should be joined on.
3641 // Base table is the "LOCATION" table, and it is being
3642 // outer joined to the "PART" table via the the field "PART_NUMBER"
3643 // that can be related between the two tables.
3644 location->SetWhereClause("LOCATION.PART_NUMBER = PART.PART_NUMBER")
3645 location->SetFromClause("PART");
3649 \wxheading{See also
}
3651 \helpref{wxDbTable::From
}{wxdbtablefrom
},
3652 \helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
}
3654 \membersection{wxDbTable::SetColNull
}\label{wxdbtablesetcolnull
}
3656 \func{bool
}{SetColNull
}{\param{UWORD
}{colNo
},
\param{bool
}{set=TRUE
}}
3658 \func{bool
}{SetColNull
}{\param{const wxString \&
}{colName
},
3659 \param{bool
}{set=TRUE
}}
3661 Both forms of this function allow a member variable representing a column
3662 in the table associated with this wxDbTable object to be set to NULL.
3664 The first form allows the column to be set by the index into the column
3665 definitions used to create the wxDbTable instance, while the second allows
3666 the actual column name to be specified.
3668 \wxheading{Parameters
}
3670 \docparam{colNo
}{Index into the column definitions used when first defining
3671 this wxDbTable object.
}
3672 \docparam{colName
}{Actual data table column name that is to be set to NULL.
}
3673 \docparam{set
}{Whether the column is set to NULL or not. Passing TRUE sets
3674 the column to NULL, passing FALSE sets the column to be non-NULL. Default is
3679 No database updates are done by this function. It only operates on the
3680 member variables in memory. Use and insert or update function to store this
3683 \membersection{wxDbTable::SetOrderByClause
}\label{wxdbtablesetorderbyclause
}
3685 \func{void
}{SetOrderByClause
}{\param{const wxString \&
}{OrderBy
}}
3687 Accessor function for setting the private class member wxDbTable::orderBy
3688 which determines sequence/ordering of the rows returned in the result set
3691 A synonym to this function is one form of the function
\helpref{wxDbTable::OrderBy
}{wxdbtableorderby
}
3693 \wxheading{Parameters
}
3695 \docparam{OrderBy
}{A comma separated list of column names that indicate the
3696 alphabetized sorting sequence that the result set is to be returned in. If
3697 a FROM clause has also been specified, each column name specified in the
3698 ORDER BY clause should be prefaced with the table name to which the column
3699 belongs using DOT notation (TABLE
\_NAME.COLUMN
\_NAME).
}
3703 Do
{\bf not
} include the keywords "ORDER BY" when setting the ORDER BY clause.
3709 parts->SetOrderByClause("PART_DESCRIP, QUANTITY");
3713 location->SetOrderByClause("LOCATION.POSITION, PART.PART_NUMBER);
3717 \wxheading{See also
}
3719 \helpref{wxDbTable::OrderBy
}{wxdbtableorderby
},
3720 \helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
}
3722 \membersection{wxDbTable::SetQueryTimeout
}\label{wxdbtablesetquerytimeout
}
3724 \func{bool
}{SetQueryTimeout
}{\param{UDWORD
}{nSeconds
}}
3726 Allows a time period to be set as the timeout period for queries.
3728 \wxheading{Parameters
}
3730 \docparam{nSeconds
}{The number of seconds to wait for the query to complete
3735 Neither Oracle or Access support this function as of yet. Other databases
3736 should be evaluated for support before depending on this function working
3739 \membersection{wxDbTable::SetWhereClause
}\label{wxdbtablesetwhereclause
}
3741 \func{void
}{SetWhereClause
}{\param{const wxString \&
}{Where
}}
3743 Accessor function for setting the private class member wxDbTable::where
3744 that determines which rows are returned in the result set by the datasource.
3746 A synonym to this function is one form of the function
\helpref{wxDbTable::Where
}{wxdbtablewhere
}
3748 \wxheading{Parameters
}
3750 \docparam{Where
}{SQL "where" clause. This clause can contain any SQL language
3751 that is legal in standard where clauses. If a FROM clause has also been
3752 specified, each column name specified in the ORDER BY clause should be
3753 prefaced with the table name to which the column belongs using DOT notation
3754 (TABLE
\_NAME.COLUMN
\_NAME).
}
3758 Do
{\bf not
} include the keywords "WHERE" when setting the WHERE clause.
3764 // Simple where clause
3765 parts->SetWhereClause("PART_NUMBER = '
32'");
3767 // Any comparison operators
3768 parts->SetWhereClause("PART_DESCRIP LIKE 'HAMMER
%'");
3770 // Multiple comparisons, including a function call
3771 parts->Where("QTY >
0 AND
{fn UCASE(PART_DESCRIP)
} LIKE '
%DRILL%'");
3773 // Using parameters and multiple logical combinations
3774 parts->Where("((QTY >
10) OR (ON_ORDER >
0)) AND ON_HOLD =
0");
3776 // This query uses an outer join (requiring a FROM clause also)
3777 // that joins the PART and LOCATION table on he common field
3779 parts->Where("PART.ON_HOLD =
0 AND \
3780 PART.PART_NUMBER = LOCATION.PART_NUMBER AND \
3781 LOCATION.PART_NUMBER >
0");
3784 \wxheading{See also
}
3786 \helpref{wxDbTable::Where
}{wxdbtablewhere
},
3787 \helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
}
3789 \membersection{wxDbTable::Update
}\label{wxdbtableupdate
}
3791 \func{bool
}{Update
}{\void}
3793 \func{bool
}{Update
}{\param{const wxString \&
}{pSqlStmt
}}
3795 The first form of this function will update the row that the current cursor
3796 is currently positioned at with the values in the memory variables that
3797 are bound to the columns. The actual SQL statement to perform the update
3798 is automatically created by the ODBC class, and then executed.
3800 The second form of the function allows full access through SQL statements for
3801 updating records in the database. Write any valid SQL UPDATE statement and
3802 submit it to this function for execution. Sophisticated updates can be
3803 performed using the full power of the SQL dialect. The full SQL statement
3804 must have the exact syntax required by the driver/datasource for performing
3805 the update. This usually is in the form of:
3808 UPDATE tablename SET col1=X, col2=Y, ... where ...
3811 \wxheading{Parameters
}
3813 \docparam{pSqlStmt
}{Pointer to SQL UPDATE statement to be executed.
}
3817 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
3818 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
3819 this function to commit or rollback the update.
3825 sqlStmt = "update PART set QTY =
0 where PART_NUMBER = '
32'";
3828 \membersection{wxDbTable::UpdateWhere
}\label{wxdbtableupdatewhere
}
3830 \func{bool
}{UpdateWhere
}{\param{const wxString \&
}{pWhereClause
}}
3832 Performs updates to the base table of the wxDbTable object, updating only the
3833 rows which match the criteria specified in the
{\it pWhereClause
}.
3835 All columns that are bound to member variables for this wxDbTable instance
3836 that were defined with the "updateable" parameter set to TRUE will be updated
3837 with the information currently held in the memory variable.
3839 \wxheading{Parameters
}
3841 \docparam{pWhereClause
}{Pointer to a valid SQL WHERE clause. Do not
3842 include the keyword 'WHERE'.
}
3846 Care should be used when updating columns that are part of indexes with
3847 this function so as not to violate an unique key constraints.
3849 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
3850 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
3851 this function to commit or rollback the update(s).
3853 \membersection{wxDbTable::Where
}\label{wxdbtablewhere
}
3855 \func{const wxString \&
}{Where
}{}
3857 \func{void
}{Where
}{\param{const wxString\&
}{Where
}}
3859 Accessor function for the private class member wxDbTable::where. Can be used
3860 as a synonym for
\helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
}
3861 (the first form of this function) to return the current where clause or
3862 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
} (the second form
3863 of this function) to set the where clause for this table instance.
3865 \wxheading{Parameters
}
3867 \docparam{Where
}{A valid SQL WHERE clause. Do not include the keyword 'WHERE'.
}
3869 \wxheading{Return value
}
3871 The first form of this function returns the current value of the wxDbTable
3872 member variable ::where.
3874 The second form of the function has no return value, as it will always set
3875 the where clause successfully.
3877 \wxheading{See also
}
3879 \helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
},
3880 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
3882 \membersection{wxDbTable::operator $++$
}\label{wxdbtableplusplus
}
3884 \func{bool
}{operator $++$
}{\void}
3886 Synonym for
\helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}
3888 \wxheading{See also
}
3890 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}
3892 \membersection{wxDbTable::operator $--$
}\label{wxdbtableminusminus
}
3894 \func{bool
}{operator $--$
}{\void}
3896 Synonym for
\helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
}
3898 \wxheading{See also
}
3900 \helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
}
3902 \section{\class{wxDbTableInf
}}\label{wxdbtableinf
}
3907 tableRemarks
[0] =
0;
3912 Currently only used by
\helpref{wxDb::GetCatalog
}{wxdbgetcatalog
} internally
3913 and
\helpref{wxDbInf
}{wxdbinf
} class, but may be used in future releases for
3914 user functions. Contains information describing the table (Name, type, etc).
3915 A pointer to a wxDbColInf array instance is included so a program can create a
3916 \helpref{wxDbColInf
}{wxdbcolinf
} array instance (using
3917 \helpref{wxDb::GetColumns
}{wxdbgetcolumns
})
3918 to maintain all information about the columns of a table in one memory
3921 Eventually, accessor functions will be added for this class
3923 See the
\helpref{database classes overview
}{odbcoverview
} for
3924 an introduction to using the ODBC classes.
3926 \membersection{wxDbTableInf::Initialize
}\label{wxdbtableinfinitialize
}
3928 Simply initializes all member variables to a cleared state. Called by
3929 the constructor automatically.