2000-08-08 06:11:51 +00:00
\section { \class { wxDb} } \label { wxdb}
2000-07-15 19:51:35 +00:00
2000-11-23 14:39:03 +00:00
A wxDb instance is a connection to an ODBC datasource which may
2000-07-15 19:51:35 +00:00
be opened, closed, and re-opened an unlimited number of times. A
database connection allows function to be performed directly on the
2000-11-23 14:39:03 +00:00
datasource, as well as allowing access to any tables/views defined in
the datasource to which the user has sufficient privileges.
2000-07-15 19:51:35 +00:00
2002-05-06 13:46:24 +00:00
See the \helpref { database classes overview} { odbcoverview} for
an introduction to using the ODBC classes.
2000-07-15 19:51:35 +00:00
\wxheading { Include files}
<wx/db.h>
2000-08-14 11:44:26 +00:00
\wxheading { Helper classes and data structures}
The following classes and structs are defined in db.cpp/.h for use with the wxDb class.
\begin { itemize} \itemsep =0pt
\item \helpref { wxDbColFor} { wxdbcolfor}
\item \helpref { wxDbColInf} { wxdbcolinf}
\item \helpref { wxDbTableInf} { wxdbtableinf}
\item \helpref { wxDbInf} { wxdbinf}
\end { itemize}
\wxheading { Constants}
2001-04-25 15:38:00 +00:00
NOTE: In a future release, all ODBC class constants will be prefaced with 'wx'.
2000-08-14 11:44:26 +00:00
\begin { verbatim}
2000-11-23 14:39:03 +00:00
wxDB_ PATH_ MAX Maximum path length allowed to be passed to
2002-05-27 19:47:21 +00:00
the ODBC driver to indicate where the data
2000-11-23 14:39:03 +00:00
file(s) are located.
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
DB_ MAX_ COLUMN_ NAME_ LEN Maximum supported length for the name of a
2000-11-23 14:39:03 +00:00
column
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
DB_ MAX_ ERROR_ HISTORY Maximum number of error messages retained in
the queue before being overwritten by new
2000-11-23 14:39:03 +00:00
errors.
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
DB_ MAX_ ERROR_ MSG_ LEN Maximum supported length of an error message
2000-11-23 14:39:03 +00:00
returned by the ODBC classes
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
DB_ MAX_ STATEMENT_ LEN Maximum supported length for a complete SQL
2000-11-23 14:39:03 +00:00
statement to be passed to the ODBC driver
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
DB_ MAX_ TABLE_ NAME_ LEN Maximum supported length for the name of a
2000-11-23 14:39:03 +00:00
table
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
DB_ MAX_ WHERE_ CLAUSE_ LEN Maximum supported WHERE clause length that
2000-11-23 14:39:03 +00:00
can be passed to the ODBC driver
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
DB_ TYPE_ NAME_ LEN Maximum length of the name of a column's
2000-11-23 14:39:03 +00:00
data type
2000-08-14 11:44:26 +00:00
\end { verbatim}
2000-11-23 14:39:03 +00:00
\subsection { Enumerated types} \label { wxdbenumeratedtypes}
2001-04-25 15:38:00 +00:00
2000-11-29 15:29:04 +00:00
\wxheading { Enumerated types}
2000-08-08 06:11:51 +00:00
2000-08-14 11:44:26 +00:00
\docparam { enum { \bf wxDbSqlLogState} } { sqlLogOFF, sqlLogON}
2000-08-08 06:11:51 +00:00
{ \it enum { \bf wxDBMS} }
2000-08-14 11:44:26 +00:00
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.
2000-08-08 06:11:51 +00:00
\begin { verbatim}
2000-11-12 20:05:53 +00:00
dbmsUNIDENTIFIED
dbmsORACLE
dbmsSYBASE_ ASA // Adaptive Server Anywhere
dbmsSYBASE_ ASE // Adaptive Server Enterprise
dbmsMS_ SQL_ SERVER
dbmsMY_ SQL
dbmsPOSTGRES
dbmsACCESS
dbmsDBASE
2000-08-08 06:11:51 +00:00
dbmsINFORMIX
2000-11-12 20:05:53 +00:00
dbmsVIRTUOSO
dbmsDB2
2000-11-23 14:39:03 +00:00
dbmdINTERBASE
2000-08-08 06:11:51 +00:00
\end { verbatim}
2000-08-14 11:44:26 +00:00
See the remarks in \helpref { wxDb::Dbms} { wxdbdbms} for exceptions/issues with each of these database engines.
2000-08-08 06:11:51 +00:00
\wxheading { Public member variables}
2000-08-14 11:44:26 +00:00
\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.}
2000-08-08 06:11:51 +00:00
2000-11-23 14:39:03 +00:00
\docparam { int { \bf wxDb::DB\_ STATUS} } { The last ODBC error/status that occurred on this data connection. Possible codes are:}
2000-08-08 06:11:51 +00:00
\begin { verbatim}
DB_ ERR_ GENERAL_ WARNING // SqlState = '01000'
DB_ ERR_ DISCONNECT_ ERROR // SqlState = '01002'
DB_ ERR_ DATA_ TRUNCATED // SqlState = '01004'
DB_ ERR_ PRIV_ NOT_ REVOKED // SqlState = '01006'
DB_ ERR_ INVALID_ CONN_ STR_ ATTR // SqlState = '01S00'
DB_ ERR_ ERROR_ IN_ ROW // SqlState = '01S01'
DB_ ERR_ OPTION_ VALUE_ CHANGED // SqlState = '01S02'
DB_ ERR_ NO_ ROWS_ UPD_ OR_ DEL // SqlState = '01S03'
DB_ ERR_ MULTI_ ROWS_ UPD_ OR_ DEL // SqlState = '01S04'
DB_ ERR_ WRONG_ NO_ OF_ PARAMS // SqlState = '07001'
DB_ ERR_ DATA_ TYPE_ ATTR_ VIOL // SqlState = '07006'
DB_ ERR_ UNABLE_ TO_ CONNECT // SqlState = '08001'
DB_ ERR_ CONNECTION_ IN_ USE // SqlState = '08002'
DB_ ERR_ CONNECTION_ NOT_ OPEN // SqlState = '08003'
DB_ ERR_ REJECTED_ CONNECTION // SqlState = '08004'
DB_ ERR_ CONN_ FAIL_ IN_ TRANS // SqlState = '08007'
DB_ ERR_ COMM_ LINK_ FAILURE // SqlState = '08S01'
DB_ ERR_ INSERT_ VALUE_ LIST_ MISMATCH // SqlState = '21S01'
DB_ ERR_ DERIVED_ TABLE_ MISMATCH // SqlState = '21S02'
DB_ ERR_ STRING_ RIGHT_ TRUNC // SqlState = '22001'
DB_ ERR_ NUMERIC_ VALUE_ OUT_ OF_ RNG // SqlState = '22003'
DB_ ERR_ ERROR_ IN_ ASSIGNMENT // SqlState = '22005'
DB_ ERR_ DATETIME_ FLD_ OVERFLOW // SqlState = '22008'
DB_ ERR_ DIVIDE_ BY_ ZERO // SqlState = '22012'
DB_ ERR_ STR_ DATA_ LENGTH_ MISMATCH // SqlState = '22026'
DB_ ERR_ INTEGRITY_ CONSTRAINT_ VIOL // SqlState = '23000'
DB_ ERR_ INVALID_ CURSOR_ STATE // SqlState = '24000'
DB_ ERR_ INVALID_ TRANS_ STATE // SqlState = '25000'
DB_ ERR_ INVALID_ AUTH_ SPEC // SqlState = '28000'
DB_ ERR_ INVALID_ CURSOR_ NAME // SqlState = '34000'
DB_ ERR_ SYNTAX_ ERROR_ OR_ ACCESS_ VIOL // SqlState = '37000'
DB_ ERR_ DUPLICATE_ CURSOR_ NAME // SqlState = '3C000'
DB_ ERR_ SERIALIZATION_ FAILURE // SqlState = '40001'
DB_ ERR_ SYNTAX_ ERROR_ OR_ ACCESS_ VIOL2 // SqlState = '42000'
DB_ ERR_ OPERATION_ ABORTED // SqlState = '70100'
DB_ ERR_ UNSUPPORTED_ FUNCTION // SqlState = 'IM001'
DB_ ERR_ NO_ DATA_ SOURCE // SqlState = 'IM002'
DB_ ERR_ DRIVER_ LOAD_ ERROR // SqlState = 'IM003'
DB_ ERR_ SQLALLOCENV_ FAILED // SqlState = 'IM004'
DB_ ERR_ SQLALLOCCONNECT_ FAILED // SqlState = 'IM005'
DB_ ERR_ SQLSETCONNECTOPTION_ FAILED // SqlState = 'IM006'
DB_ ERR_ NO_ DATA_ SOURCE_ DLG_ PROHIB // SqlState = 'IM007'
DB_ ERR_ DIALOG_ FAILED // SqlState = 'IM008'
DB_ ERR_ UNABLE_ TO_ LOAD_ TRANSLATION_ DLL // SqlState = 'IM009'
DB_ ERR_ DATA_ SOURCE_ NAME_ TOO_ LONG // SqlState = 'IM010'
DB_ ERR_ DRIVER_ NAME_ TOO_ LONG // SqlState = 'IM011'
DB_ ERR_ DRIVER_ KEYWORD_ SYNTAX_ ERROR // SqlState = 'IM012'
DB_ ERR_ TRACE_ FILE_ ERROR // SqlState = 'IM013'
DB_ ERR_ TABLE_ OR_ VIEW_ ALREADY_ EXISTS // SqlState = 'S0001'
DB_ ERR_ TABLE_ NOT_ FOUND // SqlState = 'S0002'
DB_ ERR_ INDEX_ ALREADY_ EXISTS // SqlState = 'S0011'
DB_ ERR_ INDEX_ NOT_ FOUND // SqlState = 'S0012'
DB_ ERR_ COLUMN_ ALREADY_ EXISTS // SqlState = 'S0021'
DB_ ERR_ COLUMN_ NOT_ FOUND // SqlState = 'S0022'
DB_ ERR_ NO_ DEFAULT_ FOR_ COLUMN // SqlState = 'S0023'
DB_ ERR_ GENERAL_ ERROR // SqlState = 'S1000'
DB_ ERR_ MEMORY_ ALLOCATION_ FAILURE // SqlState = 'S1001'
DB_ ERR_ INVALID_ COLUMN_ NUMBER // SqlState = 'S1002'
DB_ ERR_ PROGRAM_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1003'
DB_ ERR_ SQL_ DATA_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1004'
DB_ ERR_ OPERATION_ CANCELLED // SqlState = 'S1008'
DB_ ERR_ INVALID_ ARGUMENT_ VALUE // SqlState = 'S1009'
DB_ ERR_ FUNCTION_ SEQUENCE_ ERROR // SqlState = 'S1010'
DB_ ERR_ OPERATION_ INVALID_ AT_ THIS_ TIME // SqlState = 'S1011'
DB_ ERR_ INVALID_ TRANS_ OPERATION_ CODE // SqlState = 'S1012'
DB_ ERR_ NO_ CURSOR_ NAME_ AVAIL // SqlState = 'S1015'
DB_ ERR_ INVALID_ STR_ OR_ BUF_ LEN // SqlState = 'S1090'
DB_ ERR_ DESCRIPTOR_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1091'
DB_ ERR_ OPTION_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1092'
DB_ ERR_ INVALID_ PARAM_ NO // SqlState = 'S1093'
DB_ ERR_ INVALID_ SCALE_ VALUE // SqlState = 'S1094'
DB_ ERR_ FUNCTION_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1095'
DB_ ERR_ INF_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1096'
DB_ ERR_ COLUMN_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1097'
DB_ ERR_ SCOPE_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1098'
DB_ ERR_ NULLABLE_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1099'
DB_ ERR_ UNIQUENESS_ OPTION_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1100'
DB_ ERR_ ACCURACY_ OPTION_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1101'
DB_ ERR_ DIRECTION_ OPTION_ OUT_ OF_ RANGE // SqlState = 'S1103'
DB_ ERR_ INVALID_ PRECISION_ VALUE // SqlState = 'S1104'
DB_ ERR_ INVALID_ PARAM_ TYPE // SqlState = 'S1105'
DB_ ERR_ FETCH_ TYPE_ OUT_ OF_ RANGE // SqlState = 'S1106'
DB_ ERR_ ROW_ VALUE_ OUT_ OF_ RANGE // SqlState = 'S1107'
DB_ ERR_ CONCURRENCY_ OPTION_ OUT_ OF_ RANGE // SqlState = 'S1108'
DB_ ERR_ INVALID_ CURSOR_ POSITION // SqlState = 'S1109'
DB_ ERR_ INVALID_ DRIVER_ COMPLETION // SqlState = 'S1110'
DB_ ERR_ INVALID_ BOOKMARK_ VALUE // SqlState = 'S1111'
DB_ ERR_ DRIVER_ NOT_ CAPABLE // SqlState = 'S1C00'
DB_ ERR_ TIMEOUT_ EXPIRED // SqlState = 'S1T00'
\end { verbatim}
2002-05-27 19:47:21 +00:00
\docparam { struct { \bf wxDb::dbInf} } { This structure is internal to the
wxDb class and contains details of the ODBC datasource that the current
instance of the wxDb is connected to in its members. When the datasource
is opened, all of the information contained in the dbInf structure is
queried from the datasource. This information is used almost exclusively
within the ODBC class library. Where there may be a need for particular
portions of this information outside of the class library, member
functions (e.g.
\helpref { wxDbTable::IsCursorClosedOnCommit} { wxdbtableiscursorclosedoncommit} )
2000-11-24 16:40:44 +00:00
have been added for ease of use.}
2000-08-08 06:11:51 +00:00
\begin { verbatim}
2001-02-04 15:52:46 +00:00
wxChar dbmsName[40] - Name of the dbms product
wxChar dbmsVer[64] - Version # of the dbms product
wxChar driverName[40] - Driver name
wxChar odbcVer[60] - ODBC version of the driver
wxChar drvMgrOdbcVer[60] - ODBC version of the driver manager
wxChar driverVer[60] - Driver version
wxChar serverName[80] - Server Name, typically a connect string
wxChar databaseName[128] - Database filename
wxChar outerJoins[2] - Does datasource support outer joins
2002-05-27 19:47:21 +00:00
wxChar procedureSupport[2] - Does datasource support stored
2000-11-23 14:39:03 +00:00
procedures
2002-05-27 19:47:21 +00:00
UWORD maxConnections - Maximum # of connections datasource
2000-11-23 14:39:03 +00:00
supports
2000-08-08 06:11:51 +00:00
UWORD maxStmts - Maximum # of HSTMTs per HDBC
UWORD apiConfLvl - ODBC API conformance level
UWORD cliConfLvl - Is datasource SAG compliant
UWORD sqlConfLvl - SQL conformance level
UWORD cursorCommitBehavior - How cursors are affected on db commit
2002-05-27 19:47:21 +00:00
UWORD cursorRollbackBehavior - How cursors are affected on db
2000-11-23 14:39:03 +00:00
rollback
2002-05-27 19:47:21 +00:00
UWORD supportNotNullClause - Does datasource support NOT NULL
2000-11-23 14:39:03 +00:00
clause
2002-05-27 19:47:21 +00:00
wxChar supportIEF[2] - Integrity Enhancement Facility (Ref.
2000-11-23 14:39:03 +00:00
Integrity)
UDWORD txnIsolation - Transaction isolation level supported by
driver
2002-05-27 19:47:21 +00:00
UDWORD txnIsolationOptions - Transaction isolation level options
2000-11-23 14:39:03 +00:00
available
2000-08-08 06:11:51 +00:00
UDWORD fetchDirections - Fetch directions supported
UDWORD lockTypes - Lock types supported in SQLSetPos
2002-05-27 19:47:21 +00:00
UDWORD posOperations - Position operations supported in
2000-11-23 14:39:03 +00:00
SQLSetPos
2000-08-08 06:11:51 +00:00
UDWORD posStmts - Position statements supported
2002-05-27 19:47:21 +00:00
UDWORD scrollConcurrency - Scrollable cursor concurrency options
2000-11-23 14:39:03 +00:00
supported
2000-08-08 06:11:51 +00:00
UDWORD scrollOptions - Scrollable cursor options supported
2002-05-27 19:47:21 +00:00
UDWORD staticSensitivity - Can additions/deletions/updates be
2000-11-23 14:39:03 +00:00
detected
2002-05-27 19:47:21 +00:00
UWORD txnCapable - Indicates if datasource supports
2000-11-23 14:39:03 +00:00
transactions
2002-05-27 19:47:21 +00:00
UDWORD loginTimeout - Number seconds to wait for a login
2000-11-23 14:39:03 +00:00
request
2000-08-08 06:11:51 +00:00
\end { verbatim}
2001-05-24 10:39:33 +00:00
\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.}
2000-08-08 06:11:51 +00:00
2001-05-24 10:39:33 +00:00
\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.}
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
\docparam { SDWORD { \bf wxDb::nativeError} } { Set by wxDb::DispAllErrors,
wxDb::GetNextError, and wxDb::DispNextError. It contains the
datasource-specific error code returned by the datasource to the ODBC driver.
2001-02-04 15:52:46 +00:00
Used for reporting ODBC errors.}
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
\docparam { wxChar { \bf wxDb::sqlState} [20]} { Set by wxDb::TranslateSqlState().
Indicates the error state after a failed ODBC operation. Used for reporting
2001-02-04 15:52:46 +00:00
ODBC errors.}
2000-08-08 06:11:51 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2000-08-08 06:11:51 +00:00
2001-05-24 10:39:33 +00:00
Default cursor scrolling is defined by wxODBC\_ FWD\_ ONLY\_ CURSORS in setup.h
2002-05-27 19:47:21 +00:00
when the wxWindows library is built. This behavior can be overridden when
an instance of a wxDb is created (see \helpref { wxDb constructor} { wxdbconstr} ).
2003-01-18 00:16:34 +00:00
Default setting of this value true, as not all databases/drivers support
2000-11-23 14:39:03 +00:00
both types of cursors.
2000-08-08 06:11:51 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { See also}
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
\helpref { wxDbColFor} { wxdbcolfor} , \helpref { wxDbColInf} { wxdbcolinf} ,
\helpref { wxDbTable} { wxdbtable} , \helpref { wxDbTableInf} { wxdbtableinf} ,
2001-02-04 15:52:46 +00:00
\helpref { wxDbInf} { wxdbinf}
2000-08-08 06:11:51 +00:00
2000-08-14 11:44:26 +00:00
\subsection { Associated non-class functions} \label { wxdbfunctions}
2000-08-08 06:11:51 +00:00
2000-08-14 11:44:26 +00:00
The following functions are used in conjunction with the wxDb class.
2000-08-08 06:11:51 +00:00
2001-11-23 00:43:41 +00:00
\func { void} { wxDbCloseConnections} { \void }
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Closes all cached connections that have been made through use of the
\helpref { wxDbGetConnection} { wxdbfunctions} function.
2001-11-23 00:43:41 +00:00
2002-05-27 19:47:21 +00:00
NOTE: These connections are closed regardless of whether they are in use
or not. This function should only be called after the program has
finished using the connections and all wxDbTable instances that use any of
2001-11-23 00:43:41 +00:00
the connections have been closed.
2002-05-27 19:47:21 +00:00
This function performs a \helpref { wxDb::CommitTrans} { wxdbcommittrans}
on the connection before closing it to commit any changes that are still
pending, as well as to avoid any function sequence errors upon closing
2001-11-23 00:43:41 +00:00
each connection.
\func { int } { wxDbConnectionsInUse} { \void }
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Returns a count of how many database connections are currently free ( not
being used) that have been cached through use of the \helpref { wxDbGetConnection} { wxdbfunctions}
2001-11-23 00:43:41 +00:00
function.
\func { bool} { wxDbFreeConnection} { \param { wxDb *} { pDb} }
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Searches the list of cached database connections connection for one matching
2001-11-23 00:43:41 +00:00
the passed in wxDb instance. If found, that cached connection is freed.
2002-05-27 19:47:21 +00:00
Freeing a connection means that it is marked as available (free) in the
cache of connections, so that a call to \helpref { wxDbGetConnection} { wxdbfunctions}
is able to return a pointer to the wxDb instance for use. Freeing a
connection does NOT close the connection, it only makes the connection
2001-11-23 00:43:41 +00:00
available again.
2002-05-27 19:47:21 +00:00
\func { wxDb *} { wxDbGetConnection} { \param { wxDbConnectInf *} { pDbConfig} ,
2001-05-24 10:39:33 +00:00
\param { bool } { FwdOnlyCursors=(bool)wxODBC\_ FWD\_ ONLY\_ CURSORS} }
2000-08-08 06:11:51 +00:00
2000-11-23 14:39:03 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function is used to request a "new" wxDb instance for use by the program.
The wxDb instance returned is also opened (see \helpref { wxDb::Open} { wxdbopen} ).
2000-11-23 14:39:03 +00:00
2002-05-27 19:47:21 +00:00
This function (along with wxDbFreeConnection() and wxDbCloseConnection())
maintain a cached of wxDb instances for user/re-use by a program. When a
program needs a wxDb instance, it may call this function to obtain a wxDb
instance. If there is a wxDb instance in the cache that is currently unused
that matches the connection requirements specified in { \it 'pDbConfig'} then
that cached connection is marked as no longer being free, and a pointer to
2000-11-23 14:39:03 +00:00
the wxDb instance is returned.
2002-05-27 19:47:21 +00:00
If there are no connections available in the cache that meet the requirements
given in { \it 'pDbConfig'} , then a new wxDb instance is created to connect
to the datasource specified in { \it 'pDbConfig'} using the userID and password
2000-11-23 14:39:03 +00:00
given in { \it 'pDbConfig'} .
2002-05-27 19:47:21 +00:00
NOTE: The caching routine also uses the \helpref { wxDb::Open} { wxdbopen}
connection datatype copying code. If the call to wxDbGetConnection()
requests a connection to a datasource, and there is not one available in the
cache, a new connection is created. But when the connection is opened,
instead of polling the datasource over again for its datatypes, if a
connection to the same datasource (using the same userID/password) has already
been done previously, the new connection skips querying the datasource for
its datatypes, and uses the same datatypes determined previously by the
other connection(s) for that same datasource. This cuts down greatly on
2000-11-23 14:39:03 +00:00
network traffic, database load, and connection creation time.
2002-05-27 19:47:21 +00:00
When the program is done using a connection created through a call to
wxDbGetConnection(), the program should call wxDbFreeConnection() to release
the wxDb instance back to the cache. DO NOT DELETE THE wxDb INSTANCE!
Deleting the wxDb instance returned can cause a crash/memory corruption
2000-11-23 14:39:03 +00:00
later in the program when the cache is cleaned up.
2002-05-27 19:47:21 +00:00
When exiting the program, call wxDbCloseConnections() to close all the
2000-11-23 14:39:03 +00:00
cached connections created by calls to wxDbGetConnection().
2001-11-23 00:43:41 +00:00
\func { const wxChar *} { wxDbLogExtendedErrorMsg} { \param { const wxChar *} { userText} , \param { wxDb *} { pDb} , \param { wxChar *} { ErrFile} , \param { int } { ErrLine} }
2000-11-23 14:39:03 +00:00
2002-05-27 19:47:21 +00:00
Writes a message to the wxLog window (stdout usually) when an internal
2001-11-23 00:43:41 +00:00
error situation occurs. This function only works in DEBUG builds
2000-11-23 14:39:03 +00:00
2002-05-05 14:24:07 +00:00
\func { bool} { wxDbSqlLog} { \param { wxDbSqlLogState } { state} , \param { const wxString \& } { filename = SQL\_ LOG\_ FILENAME} }
2000-07-15 19:51:35 +00:00
2000-11-23 14:39:03 +00:00
\wxheading { Remarks}
This function sets the sql log state for all open wxDb objects
2001-05-24 10:39:33 +00:00
\func { bool} { wxDbGetDataSource} { \param { HENV } { henv} , \param { wxChar *} { Dsn} , \param { SWORD } { DsnMax} , \param { wxChar *} { DsDesc} , \param { SWORD } { DsDescMax} , \param { UWORD } { direction = SQL\_ FETCH\_ NEXT} }
2000-07-15 19:51:35 +00:00
2000-11-23 14:39:03 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This routine queries the ODBC driver manager for a list of available
datasources. Repeatedly call this function to obtain all the datasources
2000-11-23 14:39:03 +00:00
available through the ODBC driver manager on the current workstation.
2002-05-06 13:46:24 +00:00
\begin { verbatim}
2000-11-23 14:39:03 +00:00
wxStringList strList;
2002-05-27 19:47:21 +00:00
while (wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, SQL_ MAX_ DSN_ LENGTH+1, DsDesc, 255))
2000-11-23 14:39:03 +00:00
strList.Add(Dsn);
2002-05-06 13:46:24 +00:00
\end { verbatim}
2000-11-23 14:39:03 +00:00
2000-08-14 11:44:26 +00:00
\latexignore { \rtfignore { \wxheading { Members} } }
2000-07-15 19:51:35 +00:00
2000-08-08 06:11:51 +00:00
\membersection { wxDb::wxDb} \label { wxdbconstr}
\func { } { wxDb} { \void }
2000-07-15 19:51:35 +00:00
Default constructor.
2002-05-05 14:24:07 +00:00
\func { } { wxDb} { \param { const HENV \& } { aHenv} , \param { bool } { FwdOnlyCursors=(bool)wxODBC\_ FWD\_ ONLY\_ CURSORS} }
2000-07-15 19:51:35 +00:00
2000-11-23 14:39:03 +00:00
Constructor, used to create an ODBC connection to a datasource.
2000-07-15 19:51:35 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { aHenv} { Environment handle used for this connection. See
2001-02-04 15:52:46 +00:00
\helpref { wxDConnectInf::AllocHenv} { wxdbconnectinfallochenv} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
\docparam { FwdOnlyCursors} { Will cursors created for use with this datasource
2001-02-04 15:52:46 +00:00
connection only allow forward scrolling cursors.}
2000-07-15 19:51:35 +00:00
\wxheading { Remarks}
2000-08-08 06:11:51 +00:00
This is the constructor for the wxDb class. The wxDb object must
2000-07-15 19:51:35 +00:00
be created and opened before any database activity can occur.
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-07-15 19:51:35 +00:00
\begin { verbatim}
2000-08-08 06:11:51 +00:00
wxDbConnectInf ConnectInf;
....Set values for member variables of ConnectInf here
2000-07-15 19:51:35 +00:00
2001-02-04 15:52:46 +00:00
wxDb sampleDB(ConnectInf.GetHenv());
if (!sampleDB.Open(ConnectInf.GetDsn(), ConnectInf.GetUserID(),
ConnectInf.GetPassword()))
2000-07-15 19:51:35 +00:00
{
2000-11-23 14:39:03 +00:00
// Error opening datasource
2000-07-15 19:51:35 +00:00
}
\end { verbatim}
2000-11-23 14:39:03 +00:00
\wxheading { See also}
2002-05-06 13:46:24 +00:00
\helpref { wxDbGetConnection} { wxdbfunctions}
2000-07-15 19:51:35 +00:00
2000-08-08 06:11:51 +00:00
\membersection { wxDb::Catalog} \label { wxdbcatalog}
2000-07-15 19:51:35 +00:00
2002-05-27 19:47:21 +00:00
\func { bool} { Catalog} { \param { wxChar *} { userID} , \param { const wxString \& } { fileName =
2001-05-24 10:39:33 +00:00
SQL\_ CATALOG\_ FILENAME} }
2000-07-15 19:51:35 +00:00
2002-05-27 19:47:21 +00:00
Allows a data "dictionary" of the datasource to be created, dumping pertinent
information about all data tables to which the user specified in userID has
access.
2000-08-08 06:11:51 +00:00
2000-07-15 19:51:35 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { userID} { Database user name to use in accessing the database. All
2001-02-04 15:52:46 +00:00
tables to which this user has rights will be evaluated in the catalog.}
2000-07-15 19:51:35 +00:00
2002-05-27 19:47:21 +00:00
\docparam { fileName} { { \it OPTIONAL} . Name of the text file to create and write
2001-05-24 10:39:33 +00:00
the DB catalog to. Default is SQL\_ CATALOG\_ FILENAME.}
2000-07-15 19:51:35 +00:00
2000-08-08 06:11:51 +00:00
\wxheading { Return value}
2000-07-15 19:51:35 +00:00
2003-01-18 00:16:34 +00:00
Returns true if the catalog request was successful, or false if there was some
2000-11-23 14:39:03 +00:00
reason that the catalog could not be generated.
2000-07-15 19:51:35 +00:00
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-07-15 19:51:35 +00:00
\begin { verbatim}
============== ============== ================ ========= =======
TABLE NAME COLUMN NAME DATA TYPE PRECISION LENGTH
============== ============== ================ ========= =======
EMPLOYEE RECID (0008)NUMBER 15 8
EMPLOYEE USER_ ID (0012)VARCHAR2 13 13
EMPLOYEE FULL_ NAME (0012)VARCHAR2 26 26
EMPLOYEE PASSWORD (0012)VARCHAR2 26 26
EMPLOYEE START_ DATE (0011)DATE 19 16
\end { verbatim}
2000-08-08 06:11:51 +00:00
\membersection { wxDb::Close} \label { wxdbclose}
2000-07-15 19:51:35 +00:00
\func { void} { Close} { \void }
2000-08-08 06:11:51 +00:00
Closes the database connection.
2000-07-15 19:51:35 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
At the end of your program, when you have finished all of your database work,
you must close the ODBC connection to the datasource. There are actually
four steps involved in doing this as illustrated in the example.
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Any wxDbTable instances which use this connection must be deleted before
2001-02-04 15:52:46 +00:00
closing the database connection.
2000-07-15 19:51:35 +00:00
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-07-15 19:51:35 +00:00
\begin { verbatim}
2000-11-23 14:39:03 +00:00
// Commit any open transactions on the datasource
2000-07-15 19:51:35 +00:00
sampleDB.CommitTrans();
2000-08-14 11:44:26 +00:00
// Delete any remaining wxDbTable objects allocated with new
2000-07-15 19:51:35 +00:00
delete parts;
2000-08-08 06:11:51 +00:00
// Close the wxDb connection when finished with it
2000-07-15 19:51:35 +00:00
sampleDB.Close();
\end { verbatim}
2000-08-08 06:11:51 +00:00
\membersection { wxDb::CommitTrans} \label { wxdbcommittrans}
\func { bool} { CommitTrans} { \void }
2002-05-27 19:47:21 +00:00
Permanently "commits" changes (insertions/deletions/updates) to the database.
2000-08-08 06:11:51 +00:00
\wxheading { Return value}
2003-01-18 00:16:34 +00:00
Returns true if the commit was successful, or false if the commit failed.
2000-08-08 06:11:51 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Transactions begin implicitly as soon as you make a change to the database
with an insert/update/delete, or any other direct SQL command that performs
one of these operations against the datasource.
At any time thereafter, to save the changes to disk permanently, "commit"
2000-11-23 14:39:03 +00:00
them by calling this function.
2002-05-27 19:47:21 +00:00
Calling this member function commits ALL open transactions on this ODBC
connection. For example, if three different wxDbTable instances used the
same connection to the datasource, committing changes made on one of those
wxDbTable instances commits any pending transactions on all three wxDbTable
2000-11-23 14:39:03 +00:00
instances.
2002-05-27 19:47:21 +00:00
Until a call to wxDb::CommitTrans() is made, no other user or cursor is able
2000-11-29 15:29:04 +00:00
to see any changes made to the row(s) that have been inserted/modified/deleted.
2000-11-23 14:39:03 +00:00
2000-08-08 06:11:51 +00:00
\wxheading { Special Note : { \it Cursors} }
2002-05-27 19:47:21 +00:00
\normalbox { It is important to understand that different database/ODBC driver
combinations handle transactions differently. One thing in particular that
you must pay attention to is cursors, in regard to transactions. Cursors are
what allow you to scroll through records forward and backward and to
manipulate records as you scroll through them. When you issue a query, a
cursor is created behind the scenes. The cursor keeps track of the query and
keeps track of the current record pointer. After you commit or rollback a
transaction, the cursor may be closed automatically. This is database
dependent, and with some databases this behavior can be controlled through
management functions. This means you would need to requery the datasource
before you can perform any additional work using this cursor. This is only
necessary however if the datasource closes the cursor after a commit or
rollback. Use the
\helpref { wxDbTable::IsCursorClosedOnCommit} { wxdbtableiscursorclosedoncommit}
member function to determine the datasource's transaction behavior. Note, in
many situations it is very inefficient to assume the cursor is closed and
always requery. This could put a significant, unnecessary load on datasources
2001-02-04 15:52:46 +00:00
that leave the cursors open after a transaction.}
2000-08-08 06:11:51 +00:00
\membersection { wxDb::CreateView} \label { wxdbcreateviews}
2002-05-27 19:47:21 +00:00
\func { bool} { CreateView} { \param { const wxString \& } { viewName} ,
2002-05-05 14:24:07 +00:00
\param { const wxString \& } { colList} , \param { const wxString \& } { pSqlStmt} }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Creates a SQL VIEW of one or more tables in a single datasource. Note that
this function will only work against databases which support views (currently
2000-11-23 14:39:03 +00:00
only Oracle as of November 21 2000).
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2001-05-24 10:39:33 +00:00
\docparam { viewName} { The name of the view. e.g. PARTS\_ V}
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
\docparam { colList} { { \it OPTIONAL} Pass in a comma delimited list of column
names if you wish to explicitly name each column in the result set. If not
desired, pass in an empty string and the column names from the associated
2000-11-23 14:39:03 +00:00
table(s) will be used.}
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
\docparam { pSqlStmt} { Pointer to the select statement portion of the CREATE
2001-02-04 15:52:46 +00:00
VIEW statement. Must be a complete, valid SQL SELECT statement.}
2000-08-08 06:11:51 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
A 'view' is a logical table that derives columns from one or more other
tables or views. Once the view is created, it can be queried exactly like
2001-02-04 15:52:46 +00:00
any other table in the database.
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
NOTE: Views are not available with all datasources. Oracle is one example
2001-02-04 15:52:46 +00:00
of a datasource which does support views.
2000-08-08 06:11:51 +00:00
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
// Incomplete code sample
2002-05-27 19:47:21 +00:00
db.CreateView("PARTS_ SD1", "PN, PD, QTY",
2000-08-14 11:44:26 +00:00
"SELECT PART_ NO, PART_ DESC, QTY_ ON_ HAND * 1.1 FROM PARTS \
WHERE STORAGE_ DEVICE = 1");
2000-08-08 06:11:51 +00:00
// PARTS_ SD1 can now be queried just as if it were a data table.
// e.g. SELECT PN, PD, QTY FROM PARTS_ SD1
\end { verbatim}
2000-11-12 20:05:53 +00:00
\membersection { wxDb::Dbms} \label { wxdbdbms}
\func { wxDBMS } { Dbms} { \void }
\wxheading { Remarks}
The return value will be of the enumerated type wxDBMS. This enumerated
type contains a list of all the currently tested and supported databases.
2000-11-23 14:39:03 +00:00
Additional databases may work with these classes, but the databases
2002-05-27 19:47:21 +00:00
returned by this function have been tested and confirmed to work with
2000-11-12 20:05:53 +00:00
these ODBC classes.
2002-05-27 19:47:21 +00:00
Possible values returned by this function can be viewed in the
2000-11-23 14:39:03 +00:00
\helpref { Enumerated types} { wxdbenumeratedtypes} section of wxDb.
2000-11-12 20:05:53 +00:00
There are known issues with conformance to the ODBC standards with several
2002-05-27 19:47:21 +00:00
datasources supported by the wxWindows ODBC classes. Please see the overview
2000-11-23 14:39:03 +00:00
for specific details on which datasource have which issues.
2000-11-12 20:05:53 +00:00
\wxheading { Return value}
2002-05-27 19:47:21 +00:00
The return value will indicate which of the supported datasources is
2000-11-12 20:05:53 +00:00
currently connected to by this connection. In the event that the
datasource is not recognized, a value of 'dbmsUNIDENTIFIED' is returned.
2000-08-08 06:11:51 +00:00
\membersection { wxDb::DispAllErrors} \label { wxdbdispallerrors}
2002-05-05 14:24:07 +00:00
\func { bool} { DispAllErrors} { \param { HENV} { aHenv} , \param { HDBC} { aHdbc = SQL\_ NULL\_ HDBC} , \param { HSTMT} { aHstmt = SQL\_ NULL\_ HSTMT} }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Used to log all database errors that occurred as a result of an executed
database command. This logging is automatic and also includes debug logging
when compiled in debug mode via \helpref { wxLogDebug} { wxlogdebug} . If logging
is turned on via \helpref { wxDb::SetSqlLogging} { wxdbsetsqllogging} , then an
2000-11-23 14:39:03 +00:00
entry is also logged to the defined log file.
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2000-11-23 14:39:03 +00:00
\docparam { aHenv} { Handle to the ODBC environment.}
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
\docparam { aHdbc} { Handle to the ODBC connection. Pass this in if the ODBC
2001-02-04 15:52:46 +00:00
function call that erred required a hdbc or hstmt argument.}
2000-08-14 11:44:26 +00:00
2002-07-12 23:25:14 +00:00
\docparam { aHstmt} { Handle to the ODBC statement being executed against. Pass
2002-05-29 08:28:03 +00:00
this in if the ODBC function call that failed required a hstmt argument.}
2000-08-08 06:11:51 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This member function will log all of the ODBC error messages for the last
ODBC function call that was made. This function is normally used internally
within the ODBC class library, but can be used programmatically after calling
2000-11-23 14:39:03 +00:00
ODBC functions directly (i.e. SQLFreeEnv()).
\wxheading { Return value}
2003-01-18 00:16:34 +00:00
The function always returns false, so a call to this function can be made
2002-05-27 19:47:21 +00:00
in the return statement of a code block in the event of a failure to
2000-11-23 14:39:03 +00:00
perform an action (see the example below).
2000-08-08 06:11:51 +00:00
\wxheading { See also}
2000-08-14 11:44:26 +00:00
\helpref { wxDb::SetSqlLogging} { wxdbsetsqllogging} , wxDbSqlLog
2000-08-08 06:11:51 +00:00
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_ NTS) != SQL_ SUCCESS)
// Display all ODBC errors for this stmt
return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
\end { verbatim}
\membersection { wxDb::DispNextError} \label { wxdbdispnexterror}
\func { void} { DispNextError} { \void }
\wxheading { Remarks}
This function is normally used internally within the ODBC class library.
2000-11-23 14:39:03 +00:00
It could be used programmatically after calling ODBC functions directly. This
2000-08-08 06:11:51 +00:00
function works in conjunction with \helpref { wxDb::GetNextError} { wxdbgetnexterror} when errors (or
sometimes informational messages) returned from ODBC need to be analyzed
rather than simply displaying them as an error. GetNextError() retrieves
the next ODBC error from the ODBC error queue. The wxDb member variables
"sqlState", "nativeError" and "errorMsg" could then be evaluated. To
display the error retrieved, DispNextError() could then be called.
The combination of GetNextError() and DispNextError() can be used to
iteratively step through the errors returned from ODBC evaluating each
one in context and displaying the ones you choose.
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
// Drop the table before attempting to create it
sprintf(sqlStmt, "DROP TABLE %s", tableName);
// Execute the drop table statement
if (SQLExecDirect(hstmt,(UCHAR FAR *)sqlStmt,SQL_ NTS) != SQL_ SUCCESS)
{
// Check for sqlState = S0002, "Table or view not found".
// Ignore this error, bomb out on any other error.
pDb->GetNextError(henv, hdbc, hstmt);
2001-02-04 15:52:46 +00:00
if (wxStrcmp(pDb->sqlState, "S0002"))
2000-08-08 06:11:51 +00:00
{
pDb->DispNextError(); // Displayed error retrieved
pDb->DispAllErrors(henv, hdbc, hstmt); // Display all other errors, if any
pDb->RollbackTrans(); // Rollback the transaction
CloseCursor(); // Close the cursor
2003-01-18 00:16:34 +00:00
return(false); // Return Failure
2000-08-08 06:11:51 +00:00
}
}
\end { verbatim}
\membersection { wxDb::DropView} \label { wxdbdropview}
2002-05-05 14:24:07 +00:00
\func { bool} { DropView} { \param { const wxString \& } { viewName} }
2000-08-08 06:11:51 +00:00
Drops the data table view named in 'viewName'.
\wxheading { Parameters}
\docparam { viewName} { Name of the view to be dropped.}
\wxheading { Remarks}
2003-01-18 00:16:34 +00:00
If the view does not exist, this function will return true. Note that views are not supported with all datasources.
2000-08-08 06:11:51 +00:00
\membersection { wxDb::ExecSql} \label { wxdbexecsql}
2002-05-05 14:24:07 +00:00
\func { bool} { ExecSql} { \param { const wxString \& } { pSqlStmt} }
2000-08-08 06:11:51 +00:00
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.
\wxheading { Parameters}
\docparam { pSqlStmt} { Pointer to the SQL statement to be executed.}
\wxheading { Remarks}
This member extends the wxDb class and allows you to build and execute ANY VALID
2002-05-27 19:47:21 +00:00
SQL statement against the datasource. This allows you to extend the class
2000-11-23 14:39:03 +00:00
library by being able to issue any SQL statement that the datasource is capable
2000-08-08 06:11:51 +00:00
of processing.
\wxheading { See also}
\helpref { wxDb::GetData} { wxdbgetdata} , \helpref { wxDb::GetNext} { wxdbgetnext}
2001-02-05 13:33:43 +00:00
\membersection { wxDb::FwdOnlyCursors} \label { wxdbfwdonlycursors}
\func { bool} { IsFwdOnlyCursors} { \void }
2002-05-27 19:47:21 +00:00
Older form (pre-2.3/2.4 of wxWindows) of the
\helpref { wxDb::IsFwdOnlyCursors} { wxdbisfwdonlycursors} . This method is
2002-06-07 20:15:28 +00:00
provided for backward compatibility only. The method
2002-05-27 19:47:21 +00:00
\helpref { wxDb::IsFwdOnlyCursors} { wxdbisfwdonlycursors} should be
used in place of this method.
2001-02-05 13:33:43 +00:00
\func { wxDbInf *} { GetCatalog} { \param { const wxChar *} { userID} }
2000-08-08 06:11:51 +00:00
\membersection { wxDb::GetCatalog} \label { wxdbgetcatalog}
2001-02-04 15:52:46 +00:00
\func { wxDbInf *} { GetCatalog} { \param { const wxChar *} { userID} }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Returns a \helpref { wxDbInf} { wxdbinf} pointer that points to the catalog
(datasource) name, schema, number of tables accessible to the current user,
and a wxDbTableInf pointer to all data pertaining to all tables in the users
2000-11-23 14:39:03 +00:00
catalog.
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2000-11-23 14:39:03 +00:00
\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:}
2000-08-08 06:11:51 +00:00
\begin { verbatim}
userID == NULL ... UserID is ignored (DEFAULT)
userID == "" ... UserID set equal to 'this->uid'
userID != "" ... UserID set equal to 'userID'
\end { verbatim}
\wxheading { Remarks}
2000-11-23 14:39:03 +00:00
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.
2000-08-08 06:11:51 +00:00
\membersection { wxDb::GetColumnCount} \label { wxdbgetcolumncount}
2002-05-05 14:24:07 +00:00
\func { int } { GetColumnCount} { \param { const wxString \& } { tableName} , \param { const wxChar *} { userID} }
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2000-11-23 14:39:03 +00:00
\docparam { tableName} { The table name you wish to obtain column information about.}
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
\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
2001-02-05 13:33:43 +00:00
evaluated in the following manner:}
2000-08-08 06:11:51 +00:00
\begin { verbatim}
userID == NULL ... UserID is ignored (DEFAULT)
userID == "" ... UserID set equal to 'this->uid'
userID != "" ... UserID set equal to 'userID'
\end { verbatim}
\wxheading { Return value}
2002-05-27 19:47:21 +00:00
Returns a count of how many columns are in the specified table. If an error
2000-11-23 14:39:03 +00:00
occurs retrieving the number of columns, this function will return a -1.
2000-08-08 06:11:51 +00:00
\membersection { wxDb::GetColumns} \label { wxdbgetcolumns}
2002-05-05 14:24:07 +00:00
\func { wxDbColInf *} { GetColumns} { \param { const wxString \& } { tableName} , \param { UWORD *} { numCols} , \param { const wxChar *} { userID=NULL} }
2000-08-08 06:11:51 +00:00
2001-02-04 15:52:46 +00:00
\func { wxDbColInf *} { GetColumns} { \param { wxChar *} { tableName[]} , \param { const wxChar *} { userID} }
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2000-11-23 14:39:03 +00:00
\docparam { tableName} { The table name you wish to obtain column information about.}
2001-04-11 15:02:50 +00:00
\docparam { numCols} { Pointer to a UWORD which will hold a count of the number of columns returned by this function}
2000-08-14 11:44:26 +00:00
\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.}
2000-11-23 14:39:03 +00:00
\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:}
2000-08-08 06:11:51 +00:00
\begin { verbatim}
userID == NULL ... UserID is ignored (DEFAULT)
userID == "" ... UserID set equal to 'this->uid'
userID != "" ... UserID set equal to 'userID'
\end { verbatim}
\wxheading { Return value}
2002-05-27 19:47:21 +00:00
This function returns a pointer to an array of \helpref { wxDbColInf} { wxdbcolinf}
structures, allowing you to obtain information regarding the columns of the
named table(s). If no columns were found, or an error occurred, this pointer
2000-11-23 14:39:03 +00:00
will be NULL.
2000-08-08 06:11:51 +00:00
THE CALLING FUNCTION IS RESPONSIBLE FOR DELETING THE { \it wxDbColInf} MEMORY WHEN IT IS
FINISHED WITH IT.
\normalbox { ALL column bindings associated with this wxDb instance are unbound
2002-05-27 19:47:21 +00:00
by this function, including those used by any wxDbTable instances that use
2000-11-23 14:39:03 +00:00
this wxDb instance. This function should use its own wxDb instance
2000-08-08 06:11:51 +00:00
to avoid undesired unbinding of columns.}
\wxheading { See also}
\helpref { wxDbColInf} { wxdbcolinf}
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
2001-02-04 15:52:46 +00:00
wxChar *tableList[] = { "PARTS", 0} ;
2000-08-08 06:11:51 +00:00
wxDbColInf *colInf = pDb->GetColumns(tableList);
if (colInf)
{
// Use the column inf
.......
// Destroy the memory
delete [] colInf;
}
\end { verbatim}
\membersection { wxDb::GetData} \label { wxdbgetdata}
2002-05-27 19:47:21 +00:00
\func { bool} { GetData} { \param { UWORD} { colNo} , \param { SWORD} { cType} ,
2001-02-04 15:52:46 +00:00
\param { PTR} { pData} , \param { SDWORD} { maxLen} , \param { SDWORD FAR *} { cbReturned} }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Used to retrieve result set data without binding column values to memory
2001-02-04 15:52:46 +00:00
variables (i.e. not using a wxDbTable instance to access table data).
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { colNo} { Ordinal number of the desired column in the result set to be
2001-02-04 15:52:46 +00:00
returned.}
2002-05-27 19:47:21 +00:00
\docparam { cType} { The C data type that is to be returned. See a partial list
2001-02-04 15:52:46 +00:00
in \helpref { wxDbTable::SetColDefs} { wxdbtablesetcoldefs} }
2002-05-27 19:47:21 +00:00
\docparam { pData} { Memory buffer which will hold the data returned by the call
2001-02-04 15:52:46 +00:00
to this function.}
2002-05-27 19:47:21 +00:00
\docparam { maxLen} { Maximum size of the buffer { \it 'pData'} in characters.
NOTE: Not UNICODE safe. If this is a numeric field, a value of 0 may be
passed for this parameter, as the API knows the size of the expected return
2001-02-04 15:52:46 +00:00
value.}
2002-05-27 19:47:21 +00:00
\docparam { cbReturned} { Pointer to the buffer containing the length of the
actual data returned. If this value comes back as SQL\_ NULL\_ DATA, then the
2001-02-05 13:33:43 +00:00
\helpref { wxDb::GetData} { wxdbgetdata} call has failed.}
2000-08-08 06:11:51 +00:00
\wxheading { See also}
\helpref { wxDb::GetNext} { wxdbgetnext} , \helpref { wxDb::ExecSql} { wxdbexecsql}
2002-05-27 19:47:21 +00:00
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
2000-11-12 20:05:53 +00:00
SDWORD cb;
ULONG reqQty;
wxString sqlStmt;
sqlStmt = "SELECT SUM(REQUIRED_ QTY - PICKED_ QTY) FROM ORDER_ TABLE WHERE \
2000-08-14 11:44:26 +00:00
PART_ RECID = 1450 AND REQUIRED_ QTY > PICKED_ QTY";
2000-08-08 06:11:51 +00:00
2000-11-12 20:05:53 +00:00
// Perform the query
if (!pDb->ExecSql(sqlStmt.c_ str()))
{
// ERROR
return(0);
}
// Request the first row of the result set
if (!pDb->GetNext())
{
// ERROR
return(0);
}
2002-05-27 19:47:21 +00:00
// Read column #1 of the row returned by the call to ::GetNext()
2000-11-23 14:39:03 +00:00
// and return the value in 'reqQty'
2000-11-12 20:05:53 +00:00
if (!pDb->GetData(1, SQL_ C_ ULONG, & reqQty, 0, & cb))
{
// ERROR
return(0);
}
// Check for a NULL result
if (cb == SQL_ NULL_ DATA)
return(0);
2000-08-08 06:11:51 +00:00
\end { verbatim}
\wxheading { Remarks}
When requesting multiple columns to be returned from the result set (for example, the SQL query
2000-11-12 20:05:53 +00:00
requested 3 columns be returned), the calls to this function must request the columns in ordinal
2002-05-27 19:47:21 +00:00
sequence (1,2,3 or 1,3 or 2,3).
2000-08-08 06:11:51 +00:00
\membersection { wxDb::GetDatabaseName} \label { wxdbgetdatabasename}
2001-02-04 15:52:46 +00:00
\func { const wxChar *} { GetDatabaseName} { \void }
2000-08-08 06:11:51 +00:00
Returns the name of the database engine.
2000-11-23 14:39:03 +00:00
\membersection { wxDb::GetDatasourceName} \label { wxdbgetdatasourcename}
2000-08-08 06:11:51 +00:00
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetDatasourceName} { \void }
2000-08-08 06:11:51 +00:00
Returns the ODBC datasource name.
\membersection { wxDb::GetHDBC} \label { wxdbgethdbc}
\func { HDBC} { GetHDBC} { \void }
Returns the ODBC handle to the database connection.
\membersection { wxDb::GetHENV} \label { wxdbgethenv}
\func { HENV} { GetHENV} { \void }
Returns the ODBC environment handle.
\membersection { wxDb::GetHSTMT} \label { wxdbgethstmt}
\func { HSTMT} { GetHSTMT} { \void }
Returns the ODBC statement handle associated with this database connection.
\membersection { wxDb::GetKeyFields} \label { wxdbgetkeyfields}
2002-05-05 14:24:07 +00:00
\func { int } { GetKeyFields} { \param { const wxString \& } { tableName} , \param { wxDbColInf *} { colInf} , \param { UWORD } { nocols} }
2000-08-08 06:11:51 +00:00
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.
2000-08-14 11:44:26 +00:00
This function is primarily for use by the \helpref { wxDb::GetColumns} { wxdbgetcolumns} function, but may be called if desired from the client application.
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
\docparam { tableName} { Name of the table for which the columns will be evaluated as to their inclusion in any indexes.}
2000-08-14 11:44:26 +00:00
\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.}
2000-08-08 06:11:51 +00:00
\docparam { nocols} { Number of columns defined in the instance of colInf.}
\wxheading { Return value}
2003-01-18 00:16:34 +00:00
Currently always returns true.
2000-08-08 06:11:51 +00:00
\wxheading { See also}
\helpref { wxDbColInf} { wxdbcolinf} , \helpref { wxDb::GetColumns} { wxdbgetcolumns}
\membersection { wxDb::GetNext} \label { wxdbgetnext}
2000-08-14 11:44:26 +00:00
\func { bool} { GetNext} { \void }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Called after executing a query, this function requests the next row
2000-11-23 14:39:03 +00:00
in the result set after the current position of the cursor.
2000-08-08 06:11:51 +00:00
\wxheading { See also}
\helpref { wxDb::ExecSql} { wxdbexecsql} , \helpref { wxDb::GetData} { wxdbgetdata}
\membersection { wxDb::GetNextError} \label { wxdbgetnexterror}
2002-05-27 19:47:21 +00:00
\func { bool} { GetNextError} { \param { HENV} { aHenv} ,
2001-05-24 10:39:33 +00:00
\param { HDBC} { aHdbc = SQL\_ NULL\_ HDBC} , \param { HSTMT} { aHstmt = SQL\_ NULL\_ HSTMT} }
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
\docparam { aHenv} { A handle to the ODBC environment.}
2002-07-12 23:25:14 +00:00
\docparam { aHdbc} { { \it OPTIONAL.} A handle to the ODBC connection. Pass this
2002-05-29 08:28:03 +00:00
in if the ODBC function call that failed required a hdbc or hstmt argument.}
2002-07-12 23:25:14 +00:00
\docparam { AHstmt} { { \it OPTIONAL.} A handle to the ODBC statement being executed
against. Pass this in if the ODBC function call that failed requires a
2001-02-04 15:52:46 +00:00
hstmt argument.}
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_ NTS) != SQL_ SUCCESS)
{
2002-05-29 08:28:03 +00:00
return(db.GetNextError(db.henv, db.hdbc, hstmt));
2000-08-08 06:11:51 +00:00
}
\end { verbatim}
2001-02-04 15:52:46 +00:00
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDb::DispNextError} { wxdbdispnexterror} ,
2001-02-04 15:52:46 +00:00
\helpref { wxDb::DispAllErrors} { wxdbdispallerrors}
2000-11-12 20:05:53 +00:00
2000-08-08 06:11:51 +00:00
\membersection { wxDb::GetPassword} \label { wxdbgetpassword}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetPassword} { \void }
2000-08-08 06:11:51 +00:00
2000-11-23 14:39:03 +00:00
Returns the password used to establish this connection to the datasource.
2000-08-08 06:11:51 +00:00
\membersection { wxDb::GetTableCount} \label { wxdbgettablecount}
2000-11-23 14:39:03 +00:00
\func { int } { GetTableCount} { \void }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Returns the number of wxDbTable() instances currently using this datasource
2001-02-04 15:52:46 +00:00
connection.
2000-08-08 06:11:51 +00:00
2000-11-12 20:05:53 +00:00
2000-08-08 06:11:51 +00:00
\membersection { wxDb::GetUsername} \label { wxdbgetusername}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetUsername} { \void }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Returns the user name (uid) used to establish this connection to the
2001-02-04 15:52:46 +00:00
datasource.
2000-08-08 06:11:51 +00:00
2000-11-12 20:05:53 +00:00
2000-08-08 06:11:51 +00:00
\membersection { wxDb::Grant} \label { wxdbgrant}
2002-05-27 19:47:21 +00:00
\func { bool} { Grant} { \param { int } { privileges} , \param { const wxString \& } { tableName} ,
2002-05-05 14:24:07 +00:00
\param { const wxString \& } { userList = "PUBLIC"} }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Use this member function to GRANT privileges to users for accessing tables in
2001-02-04 15:52:46 +00:00
the datasource.
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { privileges} { Use this argument to select which privileges you want to
grant. Pass DB\_ GRANT\_ ALL to grant all privileges. To grant individual
2001-02-04 15:52:46 +00:00
privileges pass one or more of the following OR'd together:}
2000-11-12 20:05:53 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
DB_ GRANT_ SELECT = 1
DB_ GRANT_ INSERT = 2
DB_ GRANT_ UPDATE = 4
DB_ GRANT_ DELETE = 8
DB_ GRANT_ ALL = DB_ GRANT_ SELECT | DB_ GRANT_ INSERT |
DB_ GRANT_ UPDATE | DB_ GRANT_ DELETE
\end { verbatim}
2000-11-12 20:05:53 +00:00
2000-08-08 06:11:51 +00:00
\docparam { tableName} { The name of the table you wish to grant privileges on.}
2000-11-23 14:39:03 +00:00
\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.}
2000-08-08 06:11:51 +00:00
\wxheading { Remarks}
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.
2002-05-27 19:47:21 +00:00
The currently logged in user must have sufficient grantor privileges for this
2000-11-23 14:39:03 +00:00
function to be able to successfully grant the indicated privileges.
2002-05-27 19:47:21 +00:00
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
db.Grant(DB_ GRANT_ SELECT | DB_ GRANT_ INSERT, "PARTS", "mary, sue");
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDb::IsFwdOnlyCursors} \label { wxdbisfwdonlycursors}
\func { bool} { IsFwdOnlyCursors} { \void }
2000-11-12 20:05:53 +00:00
This setting indicates whether this database connection was created
2002-05-27 19:47:21 +00:00
as being capable of using only forward scrolling cursors.
2000-11-23 14:39:03 +00:00
2002-05-27 19:47:21 +00:00
This function does NOT indicate if the ODBC driver or datasource supports
backward scrolling cursors. There is no standard way of detecting if the
2000-11-23 14:39:03 +00:00
driver or datasource can support backward scrolling cursors.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
If a wxDb instance was created as being capable of only forward scrolling
cursors, then even if the datasource and ODBC driver support backward
scrolling cursors, tables using this database connection would only be able
2000-11-23 14:39:03 +00:00
to use forward scrolling cursors.
2000-11-12 20:05:53 +00:00
The default setting of whether a wxDb connection to a database allows
2002-05-27 19:47:21 +00:00
forward-only or also backward scrolling cursors is defined in setup.h by the
2001-05-24 10:39:33 +00:00
value of wxODBC\_ FWD\_ ONLY\_ CURSORS. This default setting can be overridden
2002-05-27 19:47:21 +00:00
when the wxDb connection is initially created (see
2000-11-23 14:39:03 +00:00
\helpref { wxDb constructor} { wxdbconstr} and \helpref { wxDbGetConnection} { wxdbfunctions} ).
2000-11-12 20:05:53 +00:00
\wxheading { Return value}
2003-01-18 00:16:34 +00:00
Returns true if this datasource connection is defined as using only forward
scrolling cursors, or false if the connection is defined as being allowed to
2000-11-23 14:39:03 +00:00
use backward scrolling cursors and their associated functions (see note above).
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Added as of wxWindows v2.4 release, this function is a renamed version of
wxDb::FwdOnlyCursors() to match the normal wxWindows naming conventions for
2000-11-12 20:05:53 +00:00
class member functions.
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
This function is not available in versions prior to v2.4. You should
use \helpref { wxDb::FwdOnlyCursors} { wxdbfwdonlycursors} for wxWindows
2000-11-23 14:39:03 +00:00
versions prior to 2.4.
2000-08-14 11:44:26 +00:00
\wxheading { See also}
2000-11-12 20:05:53 +00:00
\helpref { wxDb constructor} { wxdbconstr} , \helpref { wxDbGetConnection} { wxdbfunctions}
2000-08-08 06:11:51 +00:00
\membersection { wxDb::IsOpen} \label { wxdbisopen}
\func { bool} { IsOpen} { \void }
2002-05-27 19:47:21 +00:00
Indicates whether the database connection to the datasource is currently
2000-11-12 20:05:53 +00:00
opened.
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function may indicate that the database connection is open, even if
the call to \helpref { wxDb::Open} { wxdbopen} may have failed to fully
initialize the connection correctly. The connection to the database
{ \it is} open and can be used via the direct SQL commands, if this
2003-01-18 00:16:34 +00:00
function returns true. Other functions which depend on the
2002-05-27 19:47:21 +00:00
\helpref { wxDb::Open} { wxdbopen} to have completed correctly may not function
as expected. The return result from \helpref { wxDb::Open} { wxdbopen} is the
only way to know if complete initialization of this wxDb connection was
successful or not. See \helpref { wxDb::Open} { wxdbopen} for more details on
2000-11-23 14:39:03 +00:00
partial failures to open a connection instance.
2000-11-12 20:05:53 +00:00
\membersection { wxDb::LogError} \label { wxdblogerror}
2002-05-05 14:24:07 +00:00
\func { void} { LogError} { \param { const wxString \& } { errMsg} \param { const wxString \& } { SQLState=""} }
2000-11-12 20:05:53 +00:00
2000-11-23 14:39:03 +00:00
\docparam { errMsg} { Free-form text to display describing the error/text to be logged.}
\docparam { SQLState} { { \it OPTIONAL.} Native SQL state error. Default is 0.}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
Calling this function will enter a log message in the error list maintained
for the database connection. This log message is free form and can be
anything the programmer wants to enter in the error list.
If SQL logging is turned on, the call to this function will also log the
text into the SQL log file.
\wxheading { See also}
\helpref { wxDb::WriteSqlLog} { wxdbwritesqllog}
2001-02-04 15:52:46 +00:00
\membersection { wxDb::ModifyColumn} \label { wxdbmodifycolumn}
2002-05-27 19:47:21 +00:00
\func { void} { ModifyColumn} { \param { const wxString \& } { tableName} \param { const wxString \& } { ColumnName}
2002-05-05 14:24:07 +00:00
\param { int } { dataType} \param { ULONG } { columnLength=0} \param { const wxString \& } { optionalParam=""} }
2001-02-04 15:52:46 +00:00
2002-05-27 19:47:21 +00:00
Used to change certain properties of a column such as the length, or whether a column
2001-02-04 15:52:46 +00:00
allows NULLs or not.
\docparam { tableName} { Name of the table that the column to be modified is in.}
2002-05-27 19:47:21 +00:00
\docparam { columnName} { Name of the column to be modified. NOTE: Name of column cannot
2001-02-04 15:52:46 +00:00
be changed with this function.}
2002-05-27 19:47:21 +00:00
\docparam { dataType} { Any one of DB\_ DATA\_ TYPE\_ VARCHAR, DB\_ DATA\_ TYPE\_ INTEGER,
2001-05-24 10:39:33 +00:00
DB\_ DATA\_ TYPE\_ FLOAT, DB\_ DATA\_ TYPE\_ DATE.}
2002-05-27 19:47:21 +00:00
\docparam { columnLength} { New size of the column. Valid only for DB\_ DATA\_ TYPE\_ VARCHAR
2001-02-04 15:52:46 +00:00
dataType fields. Default is 0.}
\docparam { optionalParam} { Default is "".}
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Cannot be used to modify the precision of a numeric column, therefore 'columnLength'
2001-05-24 10:39:33 +00:00
is ignored unless the dataType is DB\_ DATA\_ TYPE\_ VARCHAR.
2001-02-04 15:52:46 +00:00
2002-05-27 19:47:21 +00:00
Some datasources do not allow certain properties of a column to be changed if any rows
currently have data stored in that column. Those datasources that do allow columns
to be changed with data in the rows many handle truncation and/or expansion in
different ways. Please refer to the reference material for the datasource being
2001-02-04 15:52:46 +00:00
used for behavioral descriptions.
\wxheading { Example}
\begin { verbatim}
ok = pDb->ModifyColumn("CONTACTS", "ADDRESS2",
DB_ , colDefs[j].SzDataObj,
wxT("NOT NULL"));
\end { verbatim}
2000-08-08 06:11:51 +00:00
\membersection { wxDb::Open} \label { wxdbopen}
2002-05-27 19:47:21 +00:00
\func { bool} { Open} { \param { const wxString \& } { Dsn} , \param { const wxString \& } { Uid} ,
2002-05-05 14:24:07 +00:00
\param { const wxString \& } { AuthStr} }
2000-11-23 14:39:03 +00:00
2000-11-12 20:05:53 +00:00
\func { bool} { Open} { \param { wxDb *} { copyDb} }
2002-05-27 19:47:21 +00:00
Opens a connection to the datasource, sets certain behaviors of the datasource
to confirm to the accepted behaviors (e.g. cursor position maintained on
commits), and queries the datasource for its representations of the basic
datatypes to determine the form in which the data going to/from columns in
2000-11-23 14:39:03 +00:00
the data tables are to be handled.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
The second form of this function, which accepts a "wxDb *" as a parameter,
can be used to avoid the overhead (execution time, database load, network
traffic) which are needed to determine the data types and representations
of data that are necessary for cross-datasource support by these classes.
Normally the first form of the wxDb::Open() function will open the connection
and then send a series of queries to the datasource asking it for its
representation of data types, and all the features it supports. If one
connection to the datasource has already been made previously, the information
gathered when that connection was created can just be copied to any new
connections to the same datasource by passing a pointer to the first
connection in as a parameter to the wxDb::Open() function. Note that this
new connection created from the first connections information will use the
2000-11-12 20:05:53 +00:00
same Dsn/Uid/AuthStr as the first connection used.
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { Dsn} { datasource name. The name of the ODBC datasource as
assigned when the datasource is initially set up through the ODBC data
2000-08-08 06:11:51 +00:00
source manager.}
\docparam { Uid} { User ID. The name (ID) of the user you wish to connect as
2000-11-23 14:39:03 +00:00
to the datasource. The user name (ID) determines what objects you
2000-08-08 06:11:51 +00:00
have access to in the datasource and what datasource privileges you have.
Privileges include being able to create new objects, update objects, delete
objects and so on. Users and privileges are normally administered by the
database administrator.}
2000-11-12 20:05:53 +00:00
\docparam { AuthStr} { The password associated with the Uid.}
2002-05-27 19:47:21 +00:00
\docparam { copyDb} { Already completely configured and opened datasource connection
from which all Dsn, Uid, AuthStr, and data typing information is to be copied
2000-11-23 14:39:03 +00:00
from for use by this datasource connection.}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
After a wxDb instance is created, it must then be opened. When opening a
datasource, there must be three pieces of information passed. The data
source name, user name (ID) and the password for the user. No database
activity on the datasource can be performed until the connection is opened.
This is normally done at program startup and the datasource remains
open for the duration of the program/module run.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
It is possible to have connections to multiple datasources open at the same
time to support distributed database connections by having separate instances
2000-11-23 14:39:03 +00:00
of wxDb objects that use either the same or different Dsn/Uid/AuthStr settings.
2000-11-12 20:05:53 +00:00
2003-01-18 00:16:34 +00:00
If this function returns a value of false, it does not necessarily mean that
2002-05-27 19:47:21 +00:00
the connection to the datasource was not opened. It may mean that some
portion of the initialization of the connection failed (such as a datatype not
being able to be determined how the datasource represents it). To determine
if the connection to the database failed, use the \helpref { wxDb::IsOpen} { wxdbisopen}
2003-01-18 00:16:34 +00:00
function after receiving a false result back from this function to determine if
the connection was opened or not. If this function returns false, but \helpref { wxDb::IsOpen} { wxdbisopen}
returns true, then direct SQL commands may be passed to the database
2002-05-27 19:47:21 +00:00
connection and can be successfully executed, but use of the datatypes (such as
by a wxDbTable instance) that are normally determined during open will not be
2000-11-23 14:39:03 +00:00
possible.
2002-05-27 19:47:21 +00:00
\normalbox { The { \it Dsn} , { \it Uid} , and { \it AuthStr} string pointers that are passed in
are copied. NOT the strings themselves, only the pointers. The calling routine
2000-11-23 14:39:03 +00:00
must maintain the memory for these three strings for the life of the wxDb instance.}
2000-08-08 06:11:51 +00:00
\wxheading { Example}
2000-08-14 11:44:26 +00:00
2000-08-08 06:11:51 +00:00
\begin { verbatim}
2001-02-04 15:52:46 +00:00
wxDb sampleDB(DbConnectInf.GetHenv());
2000-08-08 06:11:51 +00:00
if (!sampleDB.Open("Oracle 7.1 HP/UX", "gtasker", "myPassword"))
{
2000-11-23 14:39:03 +00:00
if (sampleDb.IsOpen())
{
2002-05-27 19:47:21 +00:00
// Connection is open, but the initialization of
2000-11-23 14:39:03 +00:00
// datatypes and parameter settings failed
}
else
{
// Error opening datasource
}
2000-08-08 06:11:51 +00:00
}
\end { verbatim}
\membersection { wxDb::RollbackTrans} \label { wxdbrollbacktrans}
\func { bool} { RollbackTrans} { \void }
2000-11-23 14:39:03 +00:00
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.
2000-08-08 06:11:51 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Transactions begin implicitly as soon as you make a change to the database. The
transaction continues until either a commit or rollback is executed. Calling
wxDb::RollbackTrans() will result in ALL changes done using this database
connection that have not already been committed to be "undone" back to the last
2000-11-23 14:39:03 +00:00
commit/rollback that was successfully executed.
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
\normalbox { Calling this member function rolls back ALL open (uncommitted)
transactions on this ODBC connection, including all wxDbTable instances that
2000-11-23 14:39:03 +00:00
use this connection.}
2000-08-08 06:11:51 +00:00
\wxheading { See also}
\helpref { wxDb::CommitTrans} { wxdbcommittrans} for a special note on cursors
2000-11-12 20:05:53 +00:00
\membersection { wxDb::SetDebugErrorMessages} \label { wxdbsetdebugerrormessages}
\func { void} { SetDebugErrorMessages} { \param { bool } { state} }
2003-01-18 00:16:34 +00:00
\docparam { state} { Either true (debug messages are logged) or false (debug
2001-02-05 13:33:43 +00:00
messages are not logged).}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
Turns on/off debug error messages from the ODBC class library. When
2003-01-18 00:16:34 +00:00
this function is passed true, errors are reported to the user/logged automatically
in a text or pop-up dialog when an ODBC error occurs. When passed false,
2000-11-12 20:05:53 +00:00
errors are silently handled.
When compiled in release mode (FINAL=1), this setting has no affect.
\wxheading { See also}
\helpref { wxDb constructor} { wxdbconstr}
2000-08-08 06:11:51 +00:00
\membersection { wxDb::SetSqlLogging} \label { wxdbsetsqllogging}
2003-01-18 00:16:34 +00:00
\func { bool} { SetSqlLogging} { \param { wxDbSqlLogState} { state} , \param { const wxString \& } { filename = SQL\_ LOG\_ FILENAME} , \param { bool } { append = false} }
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2000-11-23 14:39:03 +00:00
\docparam { state} { Either sqlLogOFF or sqlLogON (see \helpref { enum wxDbSqlLogState} { wxdbcolfor} ). Turns logging of SQL commands sent to the datasource OFF or ON.}
2001-05-24 10:39:33 +00:00
\docparam { filename} { { \it OPTIONAL} . Name of the file to which the log text is to be written. Default is SQL\_ LOG\_ FILENAME.}
2003-01-18 00:16:34 +00:00
\docparam { append} { { \it OPTIONAL} . Whether the file is appended to or overwritten. Default is false.}
2000-08-08 06:11:51 +00:00
\wxheading { Remarks}
2001-02-05 13:33:43 +00:00
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.
2000-08-08 06:11:51 +00:00
2000-11-23 14:39:03 +00:00
When called with { \it sqlLogOFF} , the logging file is closed, and any calls to \helpref { wxDb::WriteSqlLog} { wxdbwritesqllog} are ignored.
2000-08-08 06:11:51 +00:00
2001-10-04 17:02:56 +00:00
\membersection { wxDb::SQLColumnName} \label { wxdbsqlcolumnname}
\func { const wxString} { SQLColumnName} { \param { const char *} { colName} }
2002-05-27 19:47:21 +00:00
Returns the column name in a form ready for use in SQL statements.
2001-10-04 17:02:56 +00:00
In most cases, the column name is returned verbatim. But some databases
2002-05-27 19:47:21 +00:00
(e.g. MS Access, SQL Server, MSDE) allow for spaces in column names, which
2001-10-04 17:02:56 +00:00
must be specially quoted. For example, if the datasource allows spaces
2002-05-27 19:47:21 +00:00
in the column name, the returned string will have the correct enclosing
marks around the name to allow it to be properly included in a SQL statement
2001-10-04 17:02:56 +00:00
for the DBMS that is currently connected to with this connection.
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { colName} { Native name of the column in the table that is to be
evaluated to determine if any special quoting marks needed to be added to it
2001-10-04 17:02:56 +00:00
before including the column name in a SQL statement}
\wxheading { See also}
\helpref { wxDb::SQLTableName} { wxdbsqltablename}
\membersection { wxDb::SQLTableName} \label { wxdbsqltablename}
\func { const wxString} { SQLTableName} { \param { const char *} { tableName} }
2002-05-27 19:47:21 +00:00
Returns the table name in a form ready for use in SQL statements.
2001-10-04 17:02:56 +00:00
In most cases, the table name is returned verbatim. But some databases
2002-05-27 19:47:21 +00:00
(e.g. MS Access, SQL Server, MSDE) allow for spaces in table names, which
2001-10-04 17:02:56 +00:00
must be specially quoted. For example, if the datasource allows spaces
2002-05-27 19:47:21 +00:00
in the table name, the returned string will have the correct enclosing
marks around the name to allow it to be properly included in a SQL statement
2001-10-04 17:02:56 +00:00
for the data source that is currently connected to with this connection.
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { tableName} { Native name of the table that is to be evaluated to
determine if any special quoting marks needed to be added to it
2001-10-04 17:02:56 +00:00
before including the table name in a SQL statement}
\wxheading { See also}
\helpref { wxDb::SQLColumnName} { wxdbsqlcolumnname}
2000-11-24 16:40:44 +00:00
\membersection { wxDb::TableExists} \label { wxdbtableexists}
2000-08-08 06:11:51 +00:00
2002-05-05 14:24:07 +00:00
\func { bool} { TableExists} { \param { const wxString \& } { tableName} , \param { const wxChar *} { userID=NULL} , \param { const wxString \& } { path=""} }
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Checks the ODBC datasource for the existence of a table. If a { \it userID}
is specified, then the table must be accessible by that user (user must have
2000-11-12 20:05:53 +00:00
at least minimal privileges to the table).
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2000-11-23 14:39:03 +00:00
\docparam { tableName} { Name of the table to check for the existence of.}
\docparam { userID} { Owner of the table (also referred to as schema). Specify a userID when the datasource you are connected
2000-08-08 06:11:51 +00:00
to allows multiple unique tables with the same name to be owned by different users. { \it userID}
is evaluated as follows:}
\begin { verbatim}
userID == NULL ... UserID is ignored (DEFAULT)
userID == "" ... UserID set equal to 'this->uid'
userID != "" ... UserID set equal to 'userID'
\end { verbatim}
\wxheading { Remarks}
{ \it tableName} may refer to a table, view, alias or synonym.
2000-11-23 14:39:03 +00:00
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.
2000-08-08 06:11:51 +00:00
2000-11-12 20:05:53 +00:00
\wxheading { See also}
\helpref { wxDb::TablePrivileges} { wxdbtableprivileges}
\membersection { wxDb::TablePrivileges} \label { wxdbtableprivileges}
2002-05-27 19:47:21 +00:00
\func { bool} { TablePrivileges} { \param { const wxString \& } { tableName} , \param { const wxString \& } { priv} ,
\param { const wxChar *} { userID=NULL} , \param { const wxChar *} { schema=NULL} ,
2002-05-05 14:24:07 +00:00
\param { const wxString \& } { path=""} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Checks the ODBC datasource for the existence of a table. If a { \it userID}
is specified, then the table must be accessible by that user (user must have
2000-11-12 20:05:53 +00:00
at least minimal privileges to the table).
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { tableName} { Name of the table on which to check privileges.
2000-11-12 20:05:53 +00:00
{ \it tableName} may refer to a table, view, alias or synonym.}
2002-05-27 19:47:21 +00:00
\docparam { priv} { The table privilege being evaluated. May be one of the
2003-06-22 22:20:40 +00:00
following (or a datasource specific privilege):}
2002-07-10 09:06:56 +00:00
2000-11-12 20:05:53 +00:00
\begin { verbatim}
2002-05-27 19:47:21 +00:00
SELECT : The connected user is permitted to retrieve data for
2000-11-23 14:39:03 +00:00
one or more columns of the table.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
INSERT : The connected user is permitted to insert new rows
containing data for one or more columns into the
2000-11-23 14:39:03 +00:00
table.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
UPDATE : The connected user is permitted to update the data in
2000-11-23 14:39:03 +00:00
one or more columns of the table.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
DELETE : The connected user is permitted to delete rows of
2000-11-23 14:39:03 +00:00
data from the table.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
REFERENCES : Is the connected user permitted to refer to one or
more columns of the table within a constraint (for
example, a unique, referential, or table check
2000-11-23 14:39:03 +00:00
constraint).
2000-11-12 20:05:53 +00:00
\end { verbatim}
2003-06-22 22:20:40 +00:00
2002-05-27 19:47:21 +00:00
\docparam { userID} { { \it OPTIONAL.} User for which to determine if the privilege
specified to be checked is granted or not. Default is "".
2003-06-22 22:20:40 +00:00
{ \it userID} is evaluated as follows:}
2002-07-10 09:06:56 +00:00
2000-11-12 20:05:53 +00:00
\begin { verbatim}
2000-11-23 14:39:03 +00:00
userID == NULL ... NOT ALLOWED!
2000-11-12 20:05:53 +00:00
userID == "" ... UserID set equal to 'this->uid'
userID != "" ... UserID set equal to 'userID'
\end { verbatim}
2003-06-22 22:20:40 +00:00
2002-05-27 19:47:21 +00:00
\docparam { schema} { { \it OPTIONAL.} Owner 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. Specifying the table owner makes determination of the
2003-06-22 22:20:40 +00:00
users privileges MUCH faster. Default is NULL. { \it userID} is
evaluated as follows:}
2002-07-10 09:06:56 +00:00
2000-11-23 14:39:03 +00:00
\begin { verbatim}
schema == NULL ... Any owner (DEFAULT)
schema == "" ... Owned by 'this->uid'
schema != "" ... Owned by userID specified in 'schema'
\end { verbatim}
2003-06-22 22:20:40 +00:00
2002-05-27 19:47:21 +00:00
\docparam { path} { { \it OPTIONAL.} Path to the table. Default is "".
2000-11-12 20:05:53 +00:00
Currently unused.}
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
The scope of privilege allowed to the connected user by a given table
privilege is datasource dependent.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
For example, the privilege UPDATE might allow the connected user to update
all columns in a table on one datasource, but only those columns for
which the grantor (the user that granted the connected user) has the UPDATE
2000-11-23 14:39:03 +00:00
privilege on another datasource.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Looking up a user's privileges to a table can be time consuming depending on the
datasource and ODBC driver. This time can be minimized by passing a { \it schema}
as a parameter. With some datasources/drivers, the difference can be several
2000-11-24 16:40:44 +00:00
seconds of time difference.
2000-11-12 20:05:53 +00:00
2000-08-08 06:11:51 +00:00
\membersection { wxDb::TranslateSqlState} \label { wxdbtranslatesqlstate}
2002-05-05 14:24:07 +00:00
\func { int } { TranslateSqlState} { \param { const wxString \& } { SQLState} }
2000-11-23 14:39:03 +00:00
Converts an ODBC sqlstate to an internal error code.
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
2000-11-23 14:39:03 +00:00
\docparam { SQLState} { State to be converted.}
2000-08-08 06:11:51 +00:00
\wxheading { Return value}
2001-05-24 10:39:33 +00:00
Returns the internal class DB\_ ERR code. See \helpref { wxDb::DB\_ STATUS} { wxdb} definition.
2000-08-08 06:11:51 +00:00
\membersection { wxDb::WriteSqlLog} \label { wxdbwritesqllog}
2002-05-05 14:24:07 +00:00
\func { bool} { WriteSqlLog} { \param { const wxString \& } { logMsg} }
2000-08-08 06:11:51 +00:00
\wxheading { Parameters}
\docparam { logMsg} { Free form string to be written to the log file.}
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Very useful debugging tool that may be turned on/off during run time (see
(see \helpref { wxDb::SetSqlLogging} { wxdbsetsqllogging} for details on
turning logging on/off). The passed in string { \it logMsg} will be written to
2000-11-23 14:39:03 +00:00
a log file if SQL logging is turned on.
2000-08-08 06:11:51 +00:00
\wxheading { Return value}
If SQL logging is off when a call to WriteSqlLog() is made, or there is a
failure to write the log message to the log file, the function returns
2003-01-18 00:16:34 +00:00
false without performing the requested log, otherwise true is returned.
2000-08-08 06:11:51 +00:00
\wxheading { See also}
\helpref { wxDb::SetSqlLogging} { wxdbsetsqllogging}
2000-11-12 20:05:53 +00:00
\section { \class { wxDbColDataPtr} } \label { wxdbcoldataptr}
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Pointer to dynamic column definitions for use with a wxDbTable instance.
2000-11-12 20:05:53 +00:00
Currently there are no member functions for this class.
2000-08-08 06:11:51 +00:00
2002-05-06 13:46:24 +00:00
See the \helpref { database classes overview} { odbcoverview} for
an introduction to using the ODBC classes.
2000-08-08 06:11:51 +00:00
\begin { verbatim}
2000-11-12 20:05:53 +00:00
void *PtrDataObj;
int SzDataObj;
2001-04-11 15:02:50 +00:00
SWORD SqlCtype;
2000-08-08 06:11:51 +00:00
\end { verbatim}
2000-11-12 20:05:53 +00:00
\section { \class { wxDbColDef} } \label { wxdbcoldef}
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
This class is used to hold information about the columns bound to an
instance of a wxDbTable object.
Each instance of this class describes one column in the wxDbTable
object. When calling the \helpref { wxDb constructor} { wxdbconstr} , a
parameter passed in indicates the number of columns that will be defined for
the wxDbTable object. The constructor uses this information to allocate
adequate memory for all of the column descriptions in your wxDbTable object.
Private member wxDbTable::colDefs is a pointer to this chunk of memory
maintained by the wxDbTable class (and can be retrieved using the
\helpref { wxDbTable::GetColDefs} { wxdbtablegetcoldefs} function).
To access the nth column definition of your wxDbTable object, just reference
2000-11-12 20:05:53 +00:00
wxDbColDefs element [n - 1].
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Typically, \helpref { wxDbTable::SetColDefs} { wxdbtablesetcoldefs} is used to
2000-11-23 14:39:03 +00:00
populate an array of these data structures for the wxDbTable instance.
2000-08-08 06:11:51 +00:00
2002-05-27 19:47:21 +00:00
Currently there are no accessor functions for this class, so all members are
2001-02-05 13:33:43 +00:00
public.
2000-11-12 20:05:53 +00:00
\begin { verbatim}
2001-02-04 15:52:46 +00:00
wxChar ColName[DB_ MAX_ COLUMN_ NAME_ LEN+1]; // Column Name
2002-05-27 19:47:21 +00:00
int DbDataType; - Logical Data Type;
2000-11-23 14:39:03 +00:00
e.g. DB_ DATA_ TYPE_ INTEGER
2001-04-11 15:02:50 +00:00
SWORD SqlCtype; - C data type; e.g. SQL_ C_ LONG
2000-11-12 20:05:53 +00:00
void *PtrDataObj; - Address of the data object
int SzDataObj; - Size, in bytes, of the data object
bool KeyField; - Is column part of the PRIMARY KEY for the
2002-05-27 19:47:21 +00:00
table? -- Date fields should NOT be
2000-11-23 14:39:03 +00:00
KeyFields
2000-11-12 20:05:53 +00:00
bool Updateable; - Column is updateable?
bool InsertAllowed; - Column included in INSERT statements?
bool DerivedCol; - Column is a derived value?
SDWORD CbValue; - !!!Internal use only!!!
bool Null; - NOT FULLY IMPLEMENTED
Allows NULL values in Inserts and Updates
\end { verbatim}
2000-08-08 06:11:51 +00:00
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { database classes overview} { odbcoverview} ,
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::GetColDefs} { wxdbtablegetcoldefs} , \helpref { wxDb constructor} { wxdbconstr}
2000-08-08 06:11:51 +00:00
2001-02-05 13:33:43 +00:00
\membersection { wxDbColDef::Initialize} \label { wxdbcoldefinitialize}
2002-05-27 19:47:21 +00:00
Simply initializes all member variables to a cleared state. Called by
2001-02-05 13:33:43 +00:00
the constructor automatically.
2002-01-14 16:40:44 +00:00
\section { \class { wxDbColFor} } \label { wxdbcolfor}
2002-05-27 19:47:21 +00:00
Beginning support for handling international formatting specifically on dates
and floats.
2002-01-14 16:40:44 +00:00
\begin { verbatim}
wxString s_ Field; // Formated String for Output
2002-05-27 19:47:21 +00:00
wxString s_ Format[7]; // Formated Objects - TIMESTAMP has
2002-01-14 16:40:44 +00:00
the biggest (7)
2002-05-27 19:47:21 +00:00
wxString s_ Amount[7]; // Formated Objects - amount of
2002-01-14 16:40:44 +00:00
things that can be formatted
2002-05-27 19:47:21 +00:00
int i_ Amount[7]; // Formated Objects -
2002-01-14 16:40:44 +00:00
TT MM YYYY HH MM SS m
int i_ Nation; // 0 = timestamp
1 = EU
2 = UK
3 = International
4 = US
int i_ dbDataType; // conversion of the 'sqlDataType'
to the generic data type used by
these classes
SWORD i_ sqlDataType;
\end { verbatim}
The constructor for this class initializes all the values to zero or NULL.
The destructor does nothing at this time.
2002-05-06 13:46:24 +00:00
Only one function is provided with this class currently.
2002-01-14 16:40:44 +00:00
2002-05-06 13:46:24 +00:00
See the \helpref { database classes overview} { odbcoverview} for
an introduction to using the ODBC classes.
2002-01-14 16:40:44 +00:00
\membersection { wxDbColFor::Format} \label { wxdbcolforformat}
2002-05-27 19:47:21 +00:00
\func { int } { Format} { \param { int } { Nation} , \param { int } { dbDataType} ,
\param { SWORD } { sqlDataType} , \param { short } { columnSize} ,
2002-01-14 16:40:44 +00:00
\param { short } { decimalDigits} } \label { wxdbcolforformat}
Work in progress, and should be inter-related with wxLocale eventually.
\membersection { wxDbColFor::Initialize} \label { wxdbcolforinitialize}
2002-05-27 19:47:21 +00:00
Simply initializes all member variables to a cleared state. Called by
2002-01-14 16:40:44 +00:00
the constructor automatically.
2000-08-14 11:44:26 +00:00
\section { \class { wxDbColInf} } \label { wxdbcolinf}
2000-11-23 14:39:03 +00:00
Used with the \helpref { wxDb::GetColumns} { wxdbgetcolumns} functions for obtaining all retrievable information about a column's definition.
\begin { verbatim}
2001-02-04 15:52:46 +00:00
wxChar catalog[128+1];
wxChar schema[128+1];
wxChar tableName[DB_ MAX_ TABLE_ NAME_ LEN+1];
wxChar colName[DB_ MAX_ COLUMN_ NAME_ LEN+1];
2000-11-23 14:39:03 +00:00
SWORD sqlDataType;
2001-02-04 15:52:46 +00:00
wxChar typeName[128+1];
2000-11-23 14:39:03 +00:00
SWORD columnSize;
SWORD bufferLength;
short decimalDigits;
short numPrecRadix;
short nullable;
2001-02-04 15:52:46 +00:00
wxChar remarks[254+1];
2002-05-27 19:47:21 +00:00
int dbDataType; // conversion of the 'sqlDataType'
// to the generic data type used by
2000-11-23 14:39:03 +00:00
// these classes
int PkCol; // Primary key column
0 = No
1 = First Key
2 = Second Key, etc...
2001-02-04 15:52:46 +00:00
wxChar PkTableName[DB_ MAX_ TABLE_ NAME_ LEN+1];
2000-11-23 14:39:03 +00:00
// Tables that use this PKey as a FKey
int FkCol; // Foreign key column
0 = No
1 = First Key
2 = Second Key, etc...
2002-05-27 19:47:21 +00:00
wxChar FkTableName[DB_ MAX_ TABLE_ NAME_ LEN+1];
2000-11-23 14:39:03 +00:00
// Foreign key table name
wxDbColFor *pColFor; // How should this column be formatted
\end { verbatim}
2001-02-04 15:52:46 +00:00
The constructor for this class initializes all the values to zero, "", or NULL.
2000-11-23 14:39:03 +00:00
2002-05-27 19:47:21 +00:00
The destructor for this class takes care of deleting the pColFor member if
2000-11-23 14:39:03 +00:00
it is non-NULL.
2000-08-14 11:44:26 +00:00
2002-05-06 13:46:24 +00:00
See the \helpref { database classes overview} { odbcoverview} for
an introduction to using the ODBC classes.
2000-11-12 20:05:53 +00:00
2001-02-05 13:33:43 +00:00
\membersection { wxDbColInf::Initialize} \label { wxdbcolinfinitialize}
2002-05-27 19:47:21 +00:00
Simply initializes all member variables to a cleared state. Called by
2001-02-05 13:33:43 +00:00
the constructor automatically.
2001-02-04 15:52:46 +00:00
\section { \class { wxDbConnectInf} } \label { wxdbconnectinf}
2002-05-27 19:47:21 +00:00
This class is used for holding the data necessary for connecting to the ODBC
datasource. That information includes: SQL environment handle, datasource
name, user ID, password and default directory path (used with dBase). Other
optional fields held in this class are and file type, both for future
2001-02-04 15:52:46 +00:00
functions planned to be added for creating/manipulating datasource definitions.
2002-05-29 08:28:03 +00:00
\membersection { wxDbConnectInf::wxDbConnectInf}
2002-05-06 13:46:24 +00:00
2001-02-04 15:52:46 +00:00
\func { } { wxDbConnectInf} { \void }
Default constructor.
2002-07-12 23:25:14 +00:00
\func { } { wxDbConnectInf} { \param { HENV } { henv} , \param { const wxString \& } { dsn} ,
\param { const wxString \& } { userID=""} , \param { const wxString \& } { password} ,
\param { const wxString \& } { defaultDir=""} , \param { const wxString \& } { description=""} ,
2002-05-05 14:24:07 +00:00
\param { const wxString \& } { fileType=""} }
2001-02-04 15:52:46 +00:00
Constructor which allows initial settings of all the classes member variables.
2002-05-27 19:47:21 +00:00
See the special note below on the henv parameter for forcing this constructor
to create a SQL environment handle automatically, rather than needing to pass
2001-02-04 15:52:46 +00:00
one in to the function.
\wxheading { Parameters}
2004-02-25 10:45:02 +00:00
\docparam { henv} { Environment handle used for this connection. See\rtfsp
2002-05-27 19:47:21 +00:00
\helpref { wxDConnectInf::AllocHenv} { wxdbconnectinfallochenv} for how to create
an SQL environment handle. NOTE: Passing in a NULL for this parameter will
inform the constructor that it should create its own SQL environment handle.
2004-02-25 10:45:02 +00:00
If NULL is passed for this parameter, the constructor will call\rtfsp
2002-05-27 19:47:21 +00:00
\helpref { wxDConnectInf::AllocHenv} { wxdbconnectinfallochenv} internally. A
flag is set internally also to indicate that the HENV was created by the
constructor so that when the default class destructor is called, the
2004-02-25 10:45:02 +00:00
destructor will call \helpref { wxDConnectInf::FreeHenv} { wxdbconnectinffreehenv} \rtfsp
2001-02-04 15:52:46 +00:00
to free the environment handle automatically.}
2002-05-27 19:47:21 +00:00
\docparam { dsn} { Name of the datasource to be used in creating wxDb instances
2001-02-04 15:52:46 +00:00
for creating connection(s) to a datasource.}
2002-05-27 19:47:21 +00:00
\docparam { userID} { { \it OPTIONAL} Many datasources allow (or even require)
use of a username to determine privileges that connecting user is allowed
2001-02-04 15:52:46 +00:00
to have when accessing the datasource or the data tables. Default is "".}
2002-05-27 19:47:21 +00:00
\docparam { password} { { \it OPTIONAL} Password to be associated with the user
2001-02-04 15:52:46 +00:00
ID specified in 'userID'. Default is "".}
2002-05-27 19:47:21 +00:00
\docparam { defaultDir} { { \it OPTIONAL} Used for datasources which require the
path to where the data file is stored to be specified. dBase is one example
2001-02-04 15:52:46 +00:00
of the type of datasource which requires this information. Default is "".}
\docparam { description} { { \it OPTIONAL} { \bf FUTURE USE} Default is "".}
\docparam { fileType} { { \it OPTIONAL} { \bf FUTURE USE} Default is "".}
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
It is strongly recommended that programs use the longer form of the
constructor and allow the constructor to create the SQL environment handle
2001-02-04 15:52:46 +00:00
automatically, and manage the destruction of the handle.
\wxheading { Example}
\begin { verbatim}
wxDbConnectInf *DbConnectInf;
DbConnectInf = new wxDbConnectInf(0,"MY_ DSN", "MY_ USER", "MY_ PASSWORD");
....the rest of the program
delete DbConnectInf;
\end { verbatim}
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDConnectInf::AllocHenv} { wxdbconnectinfallochenv} ,
2001-02-04 15:52:46 +00:00
\helpref { wxDConnectInf::FreeHenv} { wxdbconnectinffreehenv}
\membersection { wxDbConnectInf::\destruct { wxDbConnectInf} } \label { wxdbconnectinfdestr}
\func { } { \destruct { wxDbConnectInf} } { }
2002-05-27 19:47:21 +00:00
Handles the default destruction of the instance of the class. If the long form
of the \helpref { wxDConnectInf} { wxdbconnectinf} was used, then this destructor
2004-02-25 10:45:02 +00:00
also takes care of calling\rtfsp
2002-05-27 19:47:21 +00:00
\helpref { wxDConnectInf::FreeHenv} { wxdbconnectinffreehenv} to free the
2001-02-04 15:52:46 +00:00
SQL environment handle.
\membersection { wxDbConnectInf::AllocHenv} \label { wxdbconnectinfallochenv}
\func { bool } { AllocHenv} { \void }
2002-05-27 19:47:21 +00:00
Allocates a SQL environment handle that will be used to interface with
2001-02-04 15:52:46 +00:00
an ODBC datasource.
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function can be automatically called by the long from of the
2001-02-04 15:52:46 +00:00
\helpref { wxDbConnectInf} { wxdbconnectinf} constructor.
\membersection { wxDbConnectInf::FreeHenv} \label { wxdbconnectinffreehenv}
\func { void} { FreeHenv} { \void }
Frees the SQL environment handle being managed by the instance of this class.
\wxheading { Remarks}
2004-02-25 10:45:02 +00:00
If the SQL environment handle was created using the long form of the\rtfsp
2002-05-27 19:47:21 +00:00
\helpref { wxDbConnectInf} { wxdbconnectinf} constructor, then the flag indicating
that the HENV should be destroyed when the classes destructor is called
2004-02-25 10:45:02 +00:00
is reset to be false, so that any future handles created using the\rtfsp
2002-05-27 19:47:21 +00:00
\helpref { wxDbConnectInf::AllocHenv} { wxdbconnectinfallochenv} function
2001-02-04 15:52:46 +00:00
must be manually released with a call to this function.
\membersection { wxDbConnectInf::Initialize} \label { wxdbconnectinfinitialize}
2002-05-27 19:47:21 +00:00
Simply initializes all member variables to a cleared state. Called by
2001-02-04 15:52:46 +00:00
the constructor automatically.
\membersection { wxDbConnectInf::GetAuthStr} \label { wxdbconnectinfgetauthstr}
\func { const wxChar *} { GetAuthStr} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the password assigned for this class
2001-02-04 15:52:46 +00:00
instance that will be used with the user ID.
Synonymous with \helpref { wxDbConnectInf::GetPassword} { wxdbconnectinfgetpassword}
\membersection { wxDbConnectInf::GetDefaultDir} \label { wxdbconnectinfgetdefaultdir}
\func { const wxChar *} { GetDefaultDir} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the default directory in which the datasource's data
table is stored. This directory is only used for file based datasources like
dBase. MS-Access does not require this to be set, as the path is set in the
2001-02-04 15:52:46 +00:00
ODBC Administrator for MS-Access.
\membersection { wxDbConnectInf::GetDescription} \label { wxdbconnectinfgetdescription}
\func { const wxChar *} { GetDescription} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the description assigned for this class
2001-02-04 15:52:46 +00:00
instance.
NOTE: Description is a FUTURE USE item and is unused currently.
\membersection { wxDbConnectInf::GetDsn} \label { wxdbconnectinfgetdsn}
\func { const wxChar *} { GetDsn} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the datasource name assigned for this class
2001-02-04 15:52:46 +00:00
instance.
\membersection { wxDbConnectInf::GetFileType} \label { wxdbconnectinfgetfiletype}
\func { const wxChar *} { GetFileType} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the filetype of the ODBC datasource assigned for
2001-02-04 15:52:46 +00:00
this class instance.
NOTE: FileType is a FUTURE USE item and is unused currently.
\membersection { wxDbConnectInf::GetHenv} \label { wxdbconnectinfgethenv}
\func { const HENV} { GetHenv} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the SQL environment handle being managed
2001-02-04 15:52:46 +00:00
by this class instance.
\membersection { wxDbConnectInf::GetPassword} \label { wxdbconnectinfgetpassword}
\func { const wxChar *} { GetPassword} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the password assigned for this class
2001-02-04 15:52:46 +00:00
instance that will be used with the user ID.
Synonymous with \helpref { wxDbConnectInf::GetAuthStr} { wxdbconnectinfgetauthstr}
\membersection { wxDbConnectInf::GetUid} \label { wxdbconnectinfgetuid}
\func { const wxChar *} { GetUid} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the user ID assigned for this class
2001-02-04 15:52:46 +00:00
instance.
\membersection { wxDbConnectInf::GetUserID} \label { wxdbconnectinfgetuserid}
\func { const wxChar *} { GetUserID} { \void }
2002-05-27 19:47:21 +00:00
Accessor function to return the user ID assigned for this class
2001-02-04 15:52:46 +00:00
instance.
\membersection { wxDbConnectInf::SetAuthStr} \label { wxdbconnectinfsetauthstr}
2002-05-05 14:24:07 +00:00
\func { \void } { SetAuthStr} { const wxString \& authstr}
2001-02-04 15:52:46 +00:00
2002-05-27 19:47:21 +00:00
Accessor function to assign the password for this class
2001-02-04 15:52:46 +00:00
instance that will be used with the user ID.
Synonymous with \helpref { wxDbConnectInf::SetPassword} { wxdbconnectinfsetpassword}
\membersection { wxDbConnectInf::SetDefaultDir} \label { wxdbconnectinfsetdefaultdir}
2002-05-05 14:24:07 +00:00
\func { \void } { SetDefaultDir} { const wxString \& defDir}
2001-02-04 15:52:46 +00:00
2002-05-27 19:47:21 +00:00
Accessor function to assign the default directory in which the datasource's data
table is stored. This directory is only used for file based datasources like
dBase. MS-Access does not require this to be set, as the path is set in the
2001-02-04 15:52:46 +00:00
ODBC Administrator for MS-Access.
\membersection { wxDbConnectInf::SetDescription} \label { wxdbconnectinfsetdescription}
2002-05-05 14:24:07 +00:00
\func { \void } { SetDescription} { const wxString \& desc}
2001-02-04 15:52:46 +00:00
2002-05-27 19:47:21 +00:00
Accessor function to assign the description assigned for this class
2001-02-04 15:52:46 +00:00
instance.
NOTE: Description is a FUTURE USE item and is unused currently.
\membersection { wxDbConnectInf::SetDsn} \label { wxdbconnectinfsetdsn}
2002-05-05 14:24:07 +00:00
\func { \void } { SetDsn} { const wxString \& dsn}
2001-02-04 15:52:46 +00:00
Accessor function to assign the datasource name for this class instance.
\membersection { wxDbConnectInf::SetFileType} \label { wxdbconnectinfsetfiletype}
2002-05-05 14:24:07 +00:00
\func { \void } { SetFileType} { const wxString \& }
2001-02-04 15:52:46 +00:00
2002-05-27 19:47:21 +00:00
Accessor function to return the filetype of the ODBC datasource assigned for
2001-02-04 15:52:46 +00:00
this class instance.
NOTE: FileType is a FUTURE USE item and is unused currently.
\membersection { wxDbConnectInf::SetHenv} \label { wxdbconnectinfsethenv}
\func { void} { SetHenv} { \param { const HENV } { henv} }
Accessor function to set the SQL environment handle for this class instance.
\membersection { wxDbConnectInf::SetPassword} \label { wxdbconnectinfsetpassword}
2002-05-05 14:24:07 +00:00
\func { \void } { SetPassword} { const wxString \& password}
2001-02-04 15:52:46 +00:00
2002-05-27 19:47:21 +00:00
Accessor function to assign the password for this class
2001-02-04 15:52:46 +00:00
instance that will be used with the user ID.
Synonymous with \helpref { wxDbConnectInf::SetAuthStr} { wxdbconnectinfsetauthstr}
\membersection { wxDbConnectInf::SetUid} \label { wxdbconnectinfsetuid}
2002-05-05 14:24:07 +00:00
\func { \void } { SetUid} { const wxString \& uid}
2001-02-04 15:52:46 +00:00
Accessor function to set the user ID for this class instance.
\membersection { wxDbConnectInf::SetUserID} \label { wxdbconnectinfsetuserid}
2002-05-05 14:24:07 +00:00
\func { \void } { SetUserID} { const wxString \& userID}
2001-02-04 15:52:46 +00:00
Accessor function to assign the user ID for this class instance.
2001-02-05 13:33:43 +00:00
\section { \class { wxDbIdxDef} } \label { wxdbidxdef}
2002-05-27 19:47:21 +00:00
Used in creation of non-primary indexes. Currently there are no member
2001-02-05 13:33:43 +00:00
functions for this class.
\begin { verbatim}
2002-05-27 19:47:21 +00:00
wxChar ColName[DB_ MAX_ COLUMN_ NAME_ LEN+1]
2001-02-05 13:33:43 +00:00
// Name of column
2002-05-27 19:47:21 +00:00
bool Ascending // Is index maintained in
2001-02-05 13:33:43 +00:00
ASCENDING sequence?
\end { verbatim}
There are no constructors/destructors as of this time, and no member functions.
2002-05-06 13:46:24 +00:00
See the \helpref { database classes overview} { odbcoverview} for
an introduction to using the ODBC classes.
2001-02-05 13:33:43 +00:00
2000-08-14 11:44:26 +00:00
\section { \class { wxDbInf} } \label { wxdbinf}
2002-05-27 19:47:21 +00:00
Contains information regarding the database connection (datasource name,
number of tables, etc). A pointer to a wxDbTableInf is included in this
2000-08-14 11:44:26 +00:00
class so a program can create a wxDbTableInf array instance to maintain all
information about all tables in the datasource to have all the datasource's
information in one memory structure.
2000-11-23 14:39:03 +00:00
Primarily, this class is used internally by the wxWindows ODBC classes.
\begin { verbatim}
2001-02-04 15:52:46 +00:00
wxChar catalog[128+1];
wxChar schema[128+1]; // typically means owner of table(s)
2002-05-27 19:47:21 +00:00
int numTables; // How many tables does this
2000-11-23 14:39:03 +00:00
datasource have
2002-05-27 19:47:21 +00:00
wxDbTableInf *pTableInf; // Equals a new
2000-11-23 14:39:03 +00:00
wxDbTableInf[numTables];
\end { verbatim}
2001-02-04 15:52:46 +00:00
The constructor for this class initializes all the values to zero, "", or NULL.
2000-11-23 14:39:03 +00:00
2002-05-27 19:47:21 +00:00
The destructor for this class takes care of deleting the pTableInf member if
2000-11-23 14:39:03 +00:00
it is non-NULL.
2002-05-06 13:46:24 +00:00
See the \helpref { database classes overview} { odbcoverview} for
an introduction to using the ODBC classes.
2001-02-04 15:52:46 +00:00
\membersection { wxDbInf::Initialize} \label { wxdbinfinitialize}
2002-05-27 19:47:21 +00:00
Simply initializes all member variables to a cleared state. Called by
2001-02-04 15:52:46 +00:00
the constructor automatically.
2000-08-14 11:44:26 +00:00
\section { \class { wxDbTable} } \label { wxdbtable}
A wxDbTable instance provides re-usable access to rows of data in
2000-11-23 14:39:03 +00:00
a table contained within the associated ODBC datasource
2000-08-14 11:44:26 +00:00
2002-05-06 13:46:24 +00:00
See the \helpref { database classes overview} { odbcoverview} for
an introduction to using the ODBC classes.
2000-08-14 11:44:26 +00:00
\wxheading { Include files}
<wx/dbtable.h>\\
<wx/db.h>
\latexignore { \rtfignore { \wxheading { Members} } }
\wxheading { Helper classes and data structures}
2002-05-27 19:47:21 +00:00
The following classes and structs are defined in dbtable.cpp/.h for use
2001-02-04 15:52:46 +00:00
with the wxDbTable class.
2000-11-23 14:39:03 +00:00
2000-11-12 20:05:53 +00:00
\begin { itemize} \itemsep =0pt
\item \helpref { wxDbColDef} { wxdbcoldef}
\item \helpref { wxDbColDataPtr} { wxdbcoldataptr}
\item \helpref { wxDbIdxDef} { wxdbidxdef}
\end { itemize}
2000-08-14 11:44:26 +00:00
\wxheading { Constants}
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\begin { verbatim}
2000-11-23 14:39:03 +00:00
wxDB_ DEFAULT_ CURSOR Primary cursor normally used for cursor based
operations.
2000-08-08 06:11:51 +00:00
2000-11-23 14:39:03 +00:00
wxDB_ QUERY_ ONLY Used to indicate whether a table that is opened
is for query only, or if insert/update/deletes
will be performed on the table. Less overhead
2002-05-27 19:47:21 +00:00
(cursors and memory) are allocated for query
2000-11-23 14:39:03 +00:00
only tables, plus read access times are faster
with some datasources.
2000-08-08 06:11:51 +00:00
2000-11-23 14:39:03 +00:00
wxDB_ ROWID_ LEN [Oracle only] - Used when CanUpdateByRowID()
is true. Optimizes updates so they are faster
by updating on the Oracle-specific ROWID column
rather than some other index.
2000-08-08 06:11:51 +00:00
2000-11-23 14:39:03 +00:00
wxDB_ DISABLE_ VIEW Use to indicate when a database view should not
2002-05-27 19:47:21 +00:00
be if a table is normally set up to use a view.
2000-11-23 14:39:03 +00:00
[Currently unsupported.]
2000-08-14 11:44:26 +00:00
\end { verbatim}
2000-08-08 06:11:51 +00:00
2000-08-14 11:44:26 +00:00
\latexignore { \rtfignore { \wxheading { Members} } }
\membersection { wxDbTable::wxDbTable} \label { wxdbtableconstr}
2002-05-27 19:47:21 +00:00
\func { } { wxDbTable} { \param { wxDb *} { pwxDb} , \param { const wxString \& } { tblName} ,
\param { const UWORD } { numColumns} , \param { const wxString \& } { qryTblName = ""} ,
2002-05-05 14:24:07 +00:00
\param { bool } { qryOnly = !wxDB\_ QUERY\_ ONLY} , \param { const wxString \& } { tblPath = ""} }
2000-08-14 11:44:26 +00:00
Default constructor.
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { pwxDb} { Pointer to the wxDb instance to be used by this wxDbTable
2000-11-12 20:05:53 +00:00
instance.}
\docparam { tblName} { The name of the table in the RDBMS.}
2001-04-11 15:02:50 +00:00
\docparam { numColumns} { The number of columns in the table. (Do NOT include the ROWID
2000-11-12 20:05:53 +00:00
column in the count if using Oracle).}
2002-05-27 19:47:21 +00:00
\docparam { qryTblName} { { \it OPTIONAL} . The name of the table or view to base
2000-11-12 20:05:53 +00:00
your queries on. This argument allows you to specify a table/view other than
2002-05-27 19:47:21 +00:00
the base table for this object to base your queries on. This allows you to
query on a view for example, but all of the INSERT, UPDATE and DELETES will
still be performed on the base table for this wxDbTable object. Basing your
2000-11-12 20:05:53 +00:00
queries on a view can provide a substantial performance increase in cases where
2001-02-04 15:52:46 +00:00
your queries involve many tables with multiple joins. Default is "".}
2002-05-27 19:47:21 +00:00
\docparam { qryOnly} { { \it OPTIONAL} . Indicates whether the table will be
2000-11-12 20:05:53 +00:00
accessible for query purposes only, or should the table create the necessary
2002-05-27 19:47:21 +00:00
cursors to be able to insert, update, and delete data from the table.
2001-05-24 10:39:33 +00:00
Default is !wxDB\_ QUERY\_ ONLY.}
2002-05-27 19:47:21 +00:00
\docparam { tblPath} { { \it OPTIONAL} . Some datasources (such as dBase)
2001-02-04 15:52:46 +00:00
require a path to where the table is stored on the system. Default is "".}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::wxDbTable} \label { wxdbtabledestr}
\func { virtual} { \destruct { wxDbTable} } { }
Virtual default destructor.
\membersection { wxDbTable::BuildDeleteStmt} \label { wxdbtablebuilddeletestmt}
2002-05-27 19:47:21 +00:00
\func { void} { BuildDeleteStmt} { \param { wxString \& } { pSqlStmt} ,
2002-05-05 14:24:07 +00:00
\param { int } { typeOfDel} , \param { const wxString \& } { pWhereClause=""} }
2000-11-12 20:05:53 +00:00
Constructs the full SQL statement that can be used to delete all rows matching
the criteria in the pWhereClause.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2000-11-23 14:39:03 +00:00
\docparam { pSqlStmt} { Pointer to buffer for the SQL statement retrieved. To be
2000-11-12 20:05:53 +00:00
sure you have adequate space allocated for the SQL statement, allocate
2001-05-24 10:39:33 +00:00
DB\_ MAX\_ STATEMENT\_ LEN bytes.}
2000-11-12 20:05:53 +00:00
\docparam { typeOfDel} { The type of delete statement being performed. Can be one
2001-05-24 10:39:33 +00:00
of three values: DB\_ DEL\_ KEYFIELDS, DB\_ DEL\_ WHERE or DB\_ DEL\_ MATCHING}
2002-05-27 19:47:21 +00:00
\docparam { pWhereClause} { { \it OPTIONAL} . If the typeOfDel is DB\_ DEL\_ WHERE,
then you must also pass in a SQL WHERE clause in this argument. Default
2001-02-04 15:52:46 +00:00
is "".}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This member function constructs a SQL DELETE statement. This can be used for
2000-11-23 14:39:03 +00:00
debugging purposes if you are having problems executing your SQL statement.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
WHERE and FROM clauses specified using \helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
and \helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} are ignored by
2000-11-12 20:05:53 +00:00
this function.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::BuildSelectStmt} \label { wxdbtablebuildselectstmt}
2002-05-27 19:47:21 +00:00
\func { void} { BuildSelectStmt} { \param { wxString \& } { pSqlStmt} ,
2001-02-04 15:52:46 +00:00
\param { int } { typeOfSelect} , \param { bool } { distinct} }
2000-08-14 11:44:26 +00:00
2000-11-12 20:05:53 +00:00
Constructs the full SQL statement that can be used to select all rows matching
2002-05-27 19:47:21 +00:00
the criteria in the pWhereClause. This function is called internally in the
wxDbTable class whenever the function \helpref { wxDbTable::Query} { wxdbtablequery}
2000-11-12 20:05:53 +00:00
is called.
2002-05-27 19:47:21 +00:00
NOTE: Only the columns specified in \helpref { wxDbTable::SetColDefs} { wxdbtablesetcoldefs}
statements are included in the list of columns returned by the SQL statement
2000-11-12 20:05:53 +00:00
created by a call to this function.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2000-11-12 20:05:53 +00:00
\docparam { pSqlStmt} { Pointer to storage for the SQL statement retrieved. To be
sure you have adequate space allocated for the SQL statement, allocate
2001-05-24 10:39:33 +00:00
DB\_ MAX\_ STATEMENT\_ LEN bytes.}
2000-11-12 20:05:53 +00:00
\docparam { typeOfSelect} { The type of select statement being performed. Can be
2001-05-24 10:39:33 +00:00
one of four values: DB\_ SELECT\_ KEYFIELDS, DB\_ SELECT\_ WHERE, DB\_ SELECT\_ MATCHING
or DB\_ SELECT\_ STATEMENT.}
2000-11-12 20:05:53 +00:00
\docparam { distinct} { Whether to select distinct records only.}
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This member function constructs a SQL SELECT statement. This can be used for
2000-11-23 14:39:03 +00:00
debugging purposes if you are having problems executing your SQL statement.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
WHERE and FROM clauses specified using
\helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
and \helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} are ignored by
2000-11-12 20:05:53 +00:00
this function.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::BuildUpdateStmt} \label { wxdbtablebuildupdatestmt}
2002-05-27 19:47:21 +00:00
\func { void} { BuildUpdateStmt} { \param { wxString \& } { pSqlStmt} , \param { int } { typeOfUpd} ,
2002-05-05 14:24:07 +00:00
\param { const wxString \& } { pWhereClause=""} }
2000-08-14 11:44:26 +00:00
2000-11-12 20:05:53 +00:00
Constructs the full SQL statement that can be used to update all rows matching
the criteria in the pWhereClause.
2001-05-24 10:39:33 +00:00
If typeOfUpd is DB\_ UPD\_ KEYFIELDS, then the current values in the bound columns
2002-05-27 19:47:21 +00:00
are used to determine which row(s) in the table are to be updated. The
2000-11-23 14:39:03 +00:00
exception to this is when a datasource supports ROW IDs (Oracle). The ROW ID
2000-11-12 20:05:53 +00:00
column is used for efficiency purposes when available.
2002-05-27 19:47:21 +00:00
NOTE: Only the columns specified in \helpref { wxDbTable::SetColDefs} { wxdbtablesetcoldefs}
statements are included in the list of columns updated by the SQL statement
2000-11-12 20:05:53 +00:00
created by a call to this function. Any column definitions that were defined
as being non-updateable will be excluded from the SQL UPDATE statement created
by this function.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2000-11-12 20:05:53 +00:00
\docparam { pSqlStmt} { Pointer to storage for the SQL statement retrieved. To be
sure you have adequate space allocated for the SQL statement, allocate
2001-05-24 10:39:33 +00:00
DB\_ MAX\_ STATEMENT\_ LEN bytes.}
2000-11-12 20:05:53 +00:00
\docparam { typeOfUpd} { The type of update statement being performed. Can be one
2001-05-24 10:39:33 +00:00
of two values: DB\_ UPD\_ KEYFIELDS or DB\_ UPD\_ WHERE.}
2002-05-27 19:47:21 +00:00
\docparam { pWhereClause} { { \it OPTIONAL} . If the typeOfUpd is DB\_ UPD\_ WHERE,
2001-02-04 15:52:46 +00:00
then you must also pass in a SQL WHERE clause in this argument. Default is "".}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
This member function allows you to see what the SQL UPDATE statement looks like
that the ODBC class library builds. This can be used for debugging purposes if
you are having problems executing your SQL statement.
2002-05-27 19:47:21 +00:00
WHERE and FROM clauses specified using \helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
and \helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} are ignored by
2000-11-12 20:05:53 +00:00
this function.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::BuildWhereStmt} \label { wxdbtablebuildwherestmt}
2002-05-27 19:47:21 +00:00
\func { void} { BuildSelectStmt} { \param { wxString \& } { pWhereClause} ,
\param { int } { typeOfWhere} , \param { const wxString \& } { qualTableName=""} ,
2003-01-18 00:16:34 +00:00
\param { bool } { useLikeComparison=false} }
2000-08-14 11:44:26 +00:00
2000-11-12 20:05:53 +00:00
Constructs the portion of a SQL statement which would follow the word 'WHERE'
2000-11-23 14:39:03 +00:00
in a SQL statement to be passed to the datasource. The returned string
2000-11-12 20:05:53 +00:00
does NOT include the word 'WHERE'.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { pWhereClause} { Pointer to storage for the SQL statement retrieved.
2000-11-12 20:05:53 +00:00
To be sure you have adequate space allocated for the SQL statement, allocate
2001-05-24 10:39:33 +00:00
DB\_ MAX\_ STATEMENT\_ LEN bytes.}
2002-05-27 19:47:21 +00:00
\docparam { typeOfWhere} { The type of where clause to generate. Can be one of
2001-05-24 10:39:33 +00:00
two values: DB\_ WHERE\_ KEYFIELDS or DB\_ WHERE\_ MATCHING.}
2002-05-27 19:47:21 +00:00
\docparam { qualTableName} { { \it OPTIONAL} . Prepended to all base table
column names. For use when a FROM clause has been specified with the
\helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} ,
2001-02-04 15:52:46 +00:00
to clarify which table a column name reference belongs to. Default is "".}
2002-05-27 19:47:21 +00:00
\docparam { useLikeComparison} { { \it OPTIONAL} . Should the constructed WHERE
2003-01-18 00:16:34 +00:00
clause utilize the LIKE comparison operator. If false, then the '='
operator is used. Default is false.}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This member function allows you to see what the SQL WHERE clause looks like
2000-11-12 20:05:53 +00:00
that the ODBC class library builds. This can be used for debugging purposes
2000-11-23 14:39:03 +00:00
if you are having problems executing your own SQL statements.
2000-11-12 20:05:53 +00:00
2001-05-24 10:39:33 +00:00
If using 'typeOfWhere' set to DB\_ WHERE\_ MATCHING, any bound columns currently
2000-11-12 20:05:53 +00:00
containing a NULL value are not included in the WHERE clause's list of
columns to use in the comparison.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::CanSelectForUpdate} \label { wxdbtablecanselectforupdate}
\func { bool} { CanSelectForUpdate} { \void }
2000-11-23 14:39:03 +00:00
Use this function to determine if the datasource supports SELECT ... FOR UPDATE.
2000-11-12 20:05:53 +00:00
When the keywords "FOR UPDATE" are included as part of your SQL SELECT statement,
2002-05-27 19:47:21 +00:00
all records { \it retrieved} (not just queried, but actually retrieved using
\helpref { wxDbTable::GetNext} { wxdbtablegetnext} , etc) from the result set are
locked.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2000-11-23 14:39:03 +00:00
Not all datasources support the "FOR UPDATE" clause, so you must use this
member function to determine if the datasource currently connected to supports
2000-11-12 20:05:53 +00:00
this behavior or not before trying to select using "FOR UPDATE".
2002-05-27 19:47:21 +00:00
If the wxDbTable instance was created with the parameter wxDB\_ QUERY\_ ONLY, then
2003-01-18 00:16:34 +00:00
this function will return false. For all known databases which do not support
the FOR UPDATE clause, this function will return false also.
2000-11-24 16:40:44 +00:00
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::CanUpdateByROWID} \label { wxdbtablecanupdatebyrowid}
\func { bool} { CanUpdateByROWID} { \void }
2002-05-27 19:47:21 +00:00
CURRENTLY ONLY POSSIBLE IF USING ORACLE.
2000-11-12 20:05:53 +00:00
--- CURRENTLY DISABLED FOR *ALL* DATASOURCES --- NOV 1 2000 - gt
Every Oracle table has a hidden column named ROWID. This is a pointer to the
2002-05-27 19:47:21 +00:00
physical location of the record in the datasource and allows for very fast
2000-11-12 20:05:53 +00:00
updates and deletes. The key is to retrieve this ROWID during your query so
2002-05-27 19:47:21 +00:00
it is available during an update or delete operation.
Use of the ROWID feature is always handled by the class library except in the
case of \helpref { wxDbTable::QueryBySqlStmt} { wxdbtablequerybysqlstmt} . Since
you are passing in the SQL SELECT statement,
it is up to you to include the ROWID column in your query. If you do not,
the application will still work, but may not be as optimized. The ROWID is
always the last column in the column list in your SQL SELECT statement.
The ROWID is not a column in the normal sense and should not be considered
2000-11-12 20:05:53 +00:00
part of the column definitions for the wxDbTable object.
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
The decision to include the ROWID in your SQL SELECT statement must be
deferred until runtime since it depends on whether you are connected
2000-11-23 14:39:03 +00:00
to an Oracle datasource or not.
2000-11-12 20:05:53 +00:00
\wxheading { Example}
\begin { verbatim}
// Incomplete code sample
wxDbTable parts;
.....
if (parts.CanUpdByROWID())
2000-11-23 14:39:03 +00:00
{
2000-11-12 20:05:53 +00:00
// Note that the ROWID column must always be the last column selected
sqlStmt = "SELECT PART_ NO, PART_ DESC, ROWID" FROM PARTS";
2000-11-23 14:39:03 +00:00
}
2000-11-12 20:05:53 +00:00
else
2001-02-04 15:52:46 +00:00
sqlStmt = "SELECT PART_ NO, PART_ DESC FROM PARTS";
2000-11-12 20:05:53 +00:00
\end { verbatim}
2000-08-14 11:44:26 +00:00
2000-11-23 14:39:03 +00:00
\membersection { wxDbTable::ClearMemberVar} \label { wxdbtableclearmembervar}
2003-01-18 00:16:34 +00:00
\func { void} { ClearMemberVar} { \param { UWORD } { colNo} , \param { bool } { setToNull=false} }
2000-11-23 14:39:03 +00:00
Same as \helpref { wxDbTable::ClearMemberVars} { wxdbtableclearmembervars} except
2002-05-27 19:47:21 +00:00
that this function clears only the specified column of its values, and
2000-11-24 16:40:44 +00:00
optionally sets the column to be a NULL column.
2000-11-23 14:39:03 +00:00
2002-05-27 19:47:21 +00:00
\docparam { colNo} { Column number that is to be cleared. This number (between 0
and (noCols-1)) is the index of the column definition created using the
2001-02-04 15:52:46 +00:00
\helpref { wxDbTable::SetColDefs} { wxdbtablesetcoldefs} function.}
2002-05-27 19:47:21 +00:00
\docparam { setToNull} { { \it OPTIONAL} . Indicates whether the column should be
2003-01-18 00:16:34 +00:00
flagged as being a NULL value stored in the bound memory variable. If true,
2002-05-27 19:47:21 +00:00
then any value stored in the bound member variable is cleared. Default is
2003-01-18 00:16:34 +00:00
false.}
2000-11-23 14:39:03 +00:00
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::ClearMemberVars} \label { wxdbtableclearmembervars}
2003-01-18 00:16:34 +00:00
\func { void} { ClearMemberVars} { \param { bool } { setToNull=false} }
2000-11-23 14:39:03 +00:00
2002-05-27 19:47:21 +00:00
Initializes all bound columns of the wxDbTable instance to zero. In the case
of a string, zero is copied to the first byte of the string.
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
\docparam { setToNull} { { \it OPTIONAL} . Indicates whether all columns should be
2003-01-18 00:16:34 +00:00
flagged as having a NULL value stored in the bound memory variable. If true,
2002-05-27 19:47:21 +00:00
then any value stored in the bound member variable is cleared. Default is
2003-01-18 00:16:34 +00:00
false.}
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This is useful before calling functions such as
\helpref { wxDbTable::QueryMatching} { wxdbtablequerymatching} or
\helpref { wxDbTable::DeleteMatching} { wxdbtabledeletematching} since these
functions build their WHERE clauses from non-zero columns. To call either
\helpref { wxDbTable::QueryMatching} { wxdbtablequerymatching} or
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::DeleteMatching} { wxdbtabledeletematching} use this sequence:
\begin { verbatim}
1) ClearMemberVars()
2) Assign columns values you wish to match on
3) Call wxDbTable::QueryMatching() or wxDbTable::DeleteMatching()
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::CloseCursor} \label { wxdbtableclosecursor}
\func { bool} { CloseCursor} { \param { HSTMT} { cursor} }
2000-11-12 20:05:53 +00:00
Closes the specified cursor associated with the wxDbTable object.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2000-11-12 20:05:53 +00:00
\docparam { cursor} { The cursor to be closed.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Typically handled internally by the ODBC class library, but may be used by the
2000-11-12 20:05:53 +00:00
programmer if desired.
2001-05-24 10:39:33 +00:00
\normalbox { DO NOT CLOSE THE wxDB\_ DEFAULT\_ CURSOR!}
2000-11-23 14:39:03 +00:00
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::Count} \label { wxdbtablecount}
2002-05-05 14:24:07 +00:00
\func { ULONG } { Count} { \param { const wxString \& } { args="*"} }
2000-08-14 11:44:26 +00:00
2000-11-12 20:05:53 +00:00
Returns the number of records which would be in the result set using the
current query parameters specified in the WHERE and FROM clauses.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { args} { { \it OPTIONAL} . This argument allows the use of the
DISTINCT keyword against a column name to cause the returned count to
only indicate the number of rows in the result set that have a unique
value in the specified column. An example is shown below. Default is "*",
meaning a count of the total number of rows matching is returned, regardless
2001-02-04 15:52:46 +00:00
of uniqueness.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function can be called before or after an actual query to obtain the
2000-11-12 20:05:53 +00:00
count of records in the result set. Count() uses its own cursor, so result
set cursor positioning is not affected by calls to Count().
2002-05-27 19:47:21 +00:00
WHERE and FROM clauses specified using
\helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
and \helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} ARE used by
2000-11-23 14:39:03 +00:00
this function.
2000-11-12 20:05:53 +00:00
\wxheading { Example}
\begin { verbatim}
USERS TABLE
FIRST_ NAME LAST_ NAME
----------- ----------
2002-05-27 19:47:21 +00:00
John Doe
2000-11-12 20:05:53 +00:00
Richard Smith
Michael Jones
John Carpenter
// Incomplete code sample
wxDbTable users;
.....
users.SetWhereClause("");
// This Count() will return 4, as there are four users listed above
// that match the query parameters
totalNumberOfUsers = users.Count();
// This Count() will return 3, as there are only 3 unique first names
// in the table above - John, Richard, Michael.
totalNumberOfUniqueFirstNames = users.Count("DISTINCT FIRST_ NAME");
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::CreateIndex} \label { wxdbtablecreateindex}
2002-05-27 19:47:21 +00:00
\func { bool} { CreateIndex} { \param { const wxString \& } { idxName} , \param { bool } { unique} ,
\param { UWORD } { noIdxCols} , \param { wxDbIdxDef *} { pIdxDefs} ,
2003-01-18 00:16:34 +00:00
\param { bool } { attemptDrop=true} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
This member function allows you to create secondary (non primary) indexes on
your tables. You first create your table, normally specifying a primary
index, and then create any secondary indexes on the table. Indexes in
relational model are not required. You do not need indexes to look up records
in a table or to join two tables together. In the relational model, indexes,
if available, provide a quicker means to look up data in a table. To enjoy
the performance benefits of indexes, the indexes must be defined on the
appropriate columns and your SQL code must be written in such a way as to
2000-11-12 20:05:53 +00:00
take advantage of those indexes.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { idxName} { Name of the Index. Name must be unique within the table
2001-02-04 15:52:46 +00:00
space of the datasource.}
2000-11-12 20:05:53 +00:00
\docparam { unique} { Indicates if this index is unique.}
\docparam { noIdxCols} { Number of columns in the index.}
\docparam { pIdxDefs} { A pointer to an array wxDbIdxDef structures. }
2002-05-27 19:47:21 +00:00
\docparam { attemptDrop} { { \it OPTIONAL} . Indicates if the function should try
to execute a \helpref { wxDbTable::DropIndex} { wxdbtabledropindex} on the index
2003-01-18 00:16:34 +00:00
name provided before trying to create the index name. Default is true.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
The first parameter, index name, must be unique and should be given a
meaningful name. Common practice is to include the table name as a prefix
in the index name (e.g. For table PARTS, you might want to call your index
PARTS\_ IDX1). This will allow you to easily view all
2000-11-12 20:05:53 +00:00
of the indexes defined for a given table grouped together alphabetically.
2002-05-27 19:47:21 +00:00
The second parameter indicates if the index is unique or not. Uniqueness
2000-11-23 14:39:03 +00:00
is enforced at the RDBMS level preventing rows which would have duplicate
2002-05-27 19:47:21 +00:00
indexes from being inserted into the table when violating a unique index's
2000-11-23 14:39:03 +00:00
uniqueness.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
In the third parameter, specify how many columns are in your index. This
2000-11-12 20:05:53 +00:00
number must match the number of columns defined in the 'pIdxDefs' parameter.
2002-05-27 19:47:21 +00:00
The fourth parameter specifies which columns make up the index using the
wxDbIdxDef structure. For each column in the index, you must specify two
things, the column name and the sort order (ascending / descending). See
2000-11-12 20:05:53 +00:00
the example below to see how to build and pass in the wxDbIdxDef structure.
2002-05-27 19:47:21 +00:00
The fifth parameter is provided to handle the differences in datasources as
to whether they will automatically overwrite existing indexes with the same
name or not. Some datasources require that the existing index must be dropped
2000-11-23 14:39:03 +00:00
first, so this is the default behavior.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Some datasources (MySQL, and possibly others) require columns which are to be
part of an index to be defined as NOT NULL. When this function is called, if
a column is not defined to be NOT NULL, a call to this function will modify
the column definition to change any columns included in the index to be
NOT NULL. In this situation, if a NULL value already exists in one of the
2000-11-23 14:39:03 +00:00
columns that is being modified, creation of the index will fail.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
PostGres is unable to handle index definitions which specify whether the index
is ascending or descending, and defaults to the system default when the index
2000-11-12 20:05:53 +00:00
is created.
2002-05-27 19:47:21 +00:00
It is not necessary to call \helpref { wxDb::CommitTrans} { wxdbcommittrans}
2000-11-12 20:05:53 +00:00
after executing this function.
\wxheading { Example}
\begin { verbatim}
// Create a secondary index on the PARTS table
wxDbIdxDef idxDef[2]; // 2 columns make up the index
2001-02-04 15:52:46 +00:00
wxStrcpy(idxDef[0].ColName, "PART_ DESC"); // Column 1
2003-01-18 00:16:34 +00:00
idxDef[0].Ascending = true;
2000-11-12 20:05:53 +00:00
2001-02-04 15:52:46 +00:00
wxStrcpy(idxDef[1].ColName, "SERIAL_ NO"); // Column 2
2003-01-18 00:16:34 +00:00
idxDef[1].Ascending = false;
2000-11-12 20:05:53 +00:00
// Create a name for the index based on the table's name
wxString indexName;
2001-02-04 15:52:46 +00:00
indexName.Printf("%s_IDX1",parts->GetTableName());
2003-01-18 00:16:34 +00:00
parts->CreateIndex(indexName, true, 2, idxDef);
2000-11-12 20:05:53 +00:00
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::CreateTable} \label { wxdbtablecreatetable}
2003-01-18 00:16:34 +00:00
\func { bool} { CreateTable} { \param { bool } { attemptDrop=true} }
2000-08-14 11:44:26 +00:00
2000-11-12 20:05:53 +00:00
Creates a table based on the definitions previously defined for this
wxDbTable instance.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { attemptDrop} { { \it OPTIONAL} . Indicates whether the driver should
attempt to drop the table before trying to create it. Some datasources will
not allow creation of a table if the table already exists in the table space
2003-01-18 00:16:34 +00:00
being used. Default is true.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function creates the table and primary index (if any) in the table space
associated with the connected datasource. The owner of these objects will
be the user id that was given when \helpref { wxDb::Open} { wxdbopen} was called.
2001-02-04 15:52:46 +00:00
The objects will be created in the default schema/table space for that user.
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
In your derived wxDbTable object constructor, the columns and primary index
of the table are described through the \helpref { wxDbColDef} { wxdbcoldef} structure.
\helpref { wxDbTable::CreateTable} { wxdbtablecreatetable} uses this information
to create the table and to add the primary index. See
\helpref { wxDbTable} { wxdbtable} ctor and wxDbColDef description for additional
2001-02-04 15:52:46 +00:00
information on describing the columns of the table.
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
It is not necessary to call \helpref { wxDb::CommitTrans} { wxdbcommittrans}
2000-11-12 20:05:53 +00:00
after executing this function.
2000-08-14 11:44:26 +00:00
2001-05-24 10:39:33 +00:00
\membersection { wxDbTable::DB\_ STATUS} \label { wxdbtabledbstatus}
2000-08-14 11:44:26 +00:00
2001-05-24 10:39:33 +00:00
\func { bool} { DB\_ STATUS} { \void }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns the wxDb private member variable DB\_ STATUS for
2000-11-12 20:05:53 +00:00
the database connection used by this instance of wxDbTable.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::Delete} \label { wxdbtabledelete}
\func { bool} { Delete} { \void }
2000-11-23 14:39:03 +00:00
Deletes the row from the table indicated by the current cursor.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Use \helpref { wxDbTable::GetFirst} { wxdbtablegetfirst} ,
\helpref { wxDbTable::GetLast} { wxdbtablegetlast} ,
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::GetNext} { wxdbtablegetnext} or
2002-05-27 19:47:21 +00:00
\helpref { wxDbTable::GetPrev} { wxdbtablegetprev} to position the cursor to
a valid record. Once positioned on a record, call this function to delete
2000-11-12 20:05:53 +00:00
the row from the table.
2002-05-27 19:47:21 +00:00
A \helpref { wxDb::CommitTrans} { wxdbcommittrans} or
\helpref { wxDb::RollbackTrans} { wxdbrollbacktrans} must be called after use of
2000-11-12 20:05:53 +00:00
this function to commit or rollback the deletion.
2002-05-27 19:47:21 +00:00
NOTE: Most datasources have a limited size "rollback" segment. This means
that it is only possible to insert/update/delete a finite number of rows
without performing a \helpref { wxDb::CommitTrans} { wxdbcommittrans} or
\helpref { wxDb::RollbackTrans} { wxdbrollbacktrans} . Size of the rollback
segment varies from database to database, and is user configurable in
most databases. Therefore it is usually best to try to perform a commit
or rollback at relatively small intervals when processing a larger number
2000-11-12 20:05:53 +00:00
of actions that insert/update/delete rows in a table.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::DeleteCursor} \label { wxdbtabledeletecursor}
2000-11-12 20:05:53 +00:00
\func { bool} { DeleteCursor} { \param { HSTMT *} { hstmtDel} }
Allows a program to delete a cursor.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2000-11-12 20:05:53 +00:00
\docparam { hstmtDel} { Handle of the cursor to delete.}
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
For default cursors associated with the instance of wxDbTable, it is not
necessary to specifically delete the cursors. This is automatically done
2000-11-12 20:05:53 +00:00
in the wxDbTable destructor.
2002-05-27 19:47:21 +00:00
NOTE: If the cursor could not be deleted for some reason, an error is logged
indicating the reason. Even if the cursor could not be deleted, the HSTMT
2000-11-12 20:05:53 +00:00
that is passed in is deleted, and the pointer is set to NULL.
2001-05-24 10:39:33 +00:00
\normalbox { DO NOT DELETE THE wxDB\_ DEFAULT\_ CURSOR!}
2000-11-23 14:39:03 +00:00
2000-11-12 20:05:53 +00:00
\membersection { wxDbTable::DeleteMatching} \label { wxdbtabledeletematching}
\func { bool} { DeleteMatching} { \void }
2002-05-27 19:47:21 +00:00
This member function allows you to delete records from your wxDbTable object
by specifying the data in the columns to match on.
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2000-11-12 20:05:53 +00:00
To delete all users with a first name of "JOHN", do the following:
2002-07-10 09:06:56 +00:00
\begin { enumerate} \itemsep =0pt
\item Clear all "columns" using wxDbTable::ClearMemberVars().
2002-07-12 23:25:14 +00:00
\item Set the FIRST\_ NAME column equal to "JOHN".
2002-07-10 09:06:56 +00:00
\item Call wxDbTable::DeleteMatching().
\end { enumerate}
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
The WHERE clause is built by the ODBC class library based on all non-NULL
columns. This allows deletion of records by matching on any column(s) in
2001-02-04 15:52:46 +00:00
your wxDbTable instance, without having to write the SQL WHERE clause.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
A \helpref { wxDb::CommitTrans} { wxdbcommittrans} or
\helpref { wxDb::RollbackTrans} { wxdbrollbacktrans} must be called after use of
2000-11-12 20:05:53 +00:00
this function to commit or rollback the deletion.
2002-05-27 19:47:21 +00:00
NOTE: Row(s) should be locked before deleting them to make sure they are
not already in use. This can be achieved by calling
\helpref { wxDbTable::QueryMatching} { wxdbtablequerymatching} ,
and then retrieving the records, locking each as you go (assuming FOR UPDATE
is allowed on the datasource). After the row(s) have been successfully locked,
2000-11-23 14:39:03 +00:00
call this function.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
NOTE: Most datasources have a limited "rollback" segment. This means
that it is only possible to insert/update/delete a finite number of rows
without performing a \helpref { wxDb::CommitTrans} { wxdbcommittrans} or
\helpref { wxDb::RollbackTrans} { wxdbrollbacktrans} . Size of the rollback
segment varies from database to database, and is user configurable in
most databases. Therefore it is usually best to try to perform a commit
or rollback at relatively small intervals when processing a larger number
2000-11-12 20:05:53 +00:00
of actions that insert/update/delete rows in a table.
\wxheading { Example}
\begin { verbatim}
// Incomplete code sample to delete all users with a first name
// of "JOHN"
users.ClearMemberVars();
2001-02-04 15:52:46 +00:00
wxStrcpy(users.FirstName,"JOHN");
2000-11-12 20:05:53 +00:00
users.DeleteMatching();
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::DeleteWhere} \label { wxdbtabledeletewhere}
2002-05-05 14:24:07 +00:00
\func { bool} { DeleteWhere} { \param { const wxString \& } { pWhereClause} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Deletes all rows from the table which match the criteria specified in the
2000-11-24 16:40:44 +00:00
WHERE clause that is passed in.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { pWhereClause} { SQL WHERE clause. This WHERE clause determines which
records will be deleted from the table interfaced through the wxDbTable
instance. The WHERE clause passed in must be compliant with the SQL 92
2000-11-12 20:05:53 +00:00
grammar. Do not include the keyword 'WHERE'
}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This is the most powerful form of the wxDbTable delete functions. This
function gives access to the full power of SQL. This function can be used
to delete records by passing a valid SQL WHERE clause. Sophisticated
deletions can be performed based on multiple criteria using the full
functionality of the SQL language.
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
A \helpref { wxDb::CommitTrans} { wxdbcommittrans} must be called after use of
2000-11-12 20:05:53 +00:00
this function to commit the deletions.
2002-05-27 19:47:21 +00:00
Note: This function is limited to deleting records from the table associated
2000-11-12 20:05:53 +00:00
with this wxDbTable object only. Deletions on joined tables is not possible.
2002-05-27 19:47:21 +00:00
NOTE: Most datasources have a limited size "rollback" segment. This means
that it is only possible to insert/update/delete a finite number of rows
without performing a \helpref { wxDb::CommitTrans} { wxdbcommittrans} or
\helpref { wxDb::RollbackTrans} { wxdbrollbacktrans} . Size of the rollback
segment varies from database to database, and is user configurable in
most databases. Therefore it is usually best to try to perform a commit
or rollback at relatively small intervals when processing a larger number
2000-11-12 20:05:53 +00:00
of actions that insert/update/delete rows in a table.
2002-05-27 19:47:21 +00:00
WHERE and FROM clauses specified using \helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
and \helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} are ignored by
2000-11-24 16:40:44 +00:00
this function.
2000-11-12 20:05:53 +00:00
\wxheading { Example}
\begin { verbatim}
2002-05-27 19:47:21 +00:00
// Delete parts 1 thru 10 from containers 'X', 'Y' and 'Z' that
2000-11-12 20:05:53 +00:00
// are magenta in color
parts.DeleteWhere("(PART_ NUMBER BETWEEN 1 AND 10) AND \
CONTAINER IN ('X', 'Y', 'Z') AND \
UPPER(COLOR) = 'MAGENTA'");
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::DropIndex} \label { wxdbtabledropindex}
2002-05-05 14:24:07 +00:00
\func { bool} { DropIndex} { \param { const wxString \& } { idxName} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Allows an index on the associated table to be dropped (deleted) if the user
2000-11-12 20:05:53 +00:00
login has sufficient privileges to do so.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2000-11-12 20:05:53 +00:00
\docparam { idxName} { Name of the index to be dropped.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
If the index specified in the 'idxName' parameter does not exist, an error
2003-01-18 00:16:34 +00:00
will be logged, and the function will return a result of false.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
It is not necessary to call \helpref { wxDb::CommitTrans} { wxdbcommittrans}
2000-11-12 20:05:53 +00:00
after executing this function.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::DropTable} \label { wxdbtabledroptable}
\func { bool} { DropTable} { \void }
2000-11-12 20:05:53 +00:00
Deletes the associated table if the user has sufficient privileges to do so.
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2003-01-18 00:16:34 +00:00
This function returns true if the table does not exist, but only for
2002-05-27 19:47:21 +00:00
supported databases (see \helpref { wxDb::Dbms} { wxdbdbms} ). If a datasource
is not specifically supported, and this function is called, the function
2003-01-18 00:16:34 +00:00
will return false.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Most datasources/ODBC drivers will delete any indexes associated with the
table automatically, and others may not. Check the documentation for your
2000-11-12 20:05:53 +00:00
database to determine the behavior.
2002-05-27 19:47:21 +00:00
It is not necessary to call \helpref { wxDb::CommitTrans} { wxdbcommittrans}
2000-11-12 20:05:53 +00:00
after executing this function.
\membersection { wxDbTable::From} \label { wxdbtablefrom}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { From} { }
2000-11-24 16:40:44 +00:00
2002-05-05 14:24:07 +00:00
\func { void} { From} { \param { const wxString \& } { From} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Accessor function for the private class member wxDbTable::from. Can be used
as a synonym for \helpref { wxDbTable::GetFromClause} { wxdbtablegetfromclause}
(the first form of this function) or
\helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} (the second form
2000-11-12 20:05:53 +00:00
of this function).
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { From} { A comma separated list of table names that are to be outer
joined with the base table's columns so that the joined table's columns
may be returned in the result set or used as a portion of a comparison with
the base table's columns. NOTE that the base tables name must NOT be included
in the FROM clause, as it is automatically included by the wxDbTable class
2000-11-12 20:05:53 +00:00
in constructing query statements.}
\wxheading { Return value}
2002-05-27 19:47:21 +00:00
The first form of this function returns the current value of the wxDbTable
member variable ::from.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
The second form of the function has no return value, as it will always set
the from clause successfully.
2000-11-12 20:05:53 +00:00
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDbTable::GetFromClause} { wxdbtablegetfromclause} ,
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetColDefs} \label { wxdbtablegetcoldefs}
\func { wxDbColDef *} { GetColDefs} { }
2002-05-27 19:47:21 +00:00
Accessor function that returns a pointer to the array of column definitions
that are bound to the columns that this wxDbTable instance is associated
2000-11-12 20:05:53 +00:00
with.
2002-05-27 19:47:21 +00:00
To determine the number of elements pointed to by the returned
\helpref { wxDbColDef} { wxdbcoldef} pointer, use the
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::GetNumberOfColumns} { wxdbtablegetnumberofcolumns} function.
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
These column definitions must not be manually redefined after they have been
2000-11-12 20:05:53 +00:00
set.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetCursor} \label { wxdbtablegetcursor}
\func { HSTMT} { GetCursor} { \void }
2002-05-27 19:47:21 +00:00
Returns the HSTMT value of the current cursor for this wxDbTable object.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function is typically used just before changing to use a different cursor
so that after the program is finished using the other cursor, the current
2000-11-12 20:05:53 +00:00
cursor can be set back to being the cursor in use.
\wxheading { See also}
\helpref { wxDbTable::SetCursor} { wxdbtablesetcursor} , \helpref { wxDbTable::GetNewCursor} { wxdbtablegetnewcursor}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetDb} \label { wxdbtablegetdb}
\func { wxDb *} { GetDb} { }
2002-05-27 19:47:21 +00:00
Accessor function for the private member variable pDb which is a pointer to
2000-11-12 20:05:53 +00:00
the datasource connection that this wxDbTable instance uses.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetFirst} \label { wxdbtablegetfirst}
\func { bool} { GetFirst} { \void }
2002-05-27 19:47:21 +00:00
Retrieves the FIRST row in the record set as defined by the current query.
Before retrieving records, a query must be performed using
\helpref { wxDbTable::Query} { wxdbtablequery} ,
\helpref { wxDbTable::QueryOnKeyFields} { wxdbtablequeryonkeyfields} ,
\helpref { wxDbTable::QueryMatching} { wxdbtablequerymatching} or
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::QueryBySqlStmt} { wxdbtablequerybysqlstmt} .
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function can only be used if the datasource connection used by the
2003-01-18 00:16:34 +00:00
wxDbTable instance was created with FwdOnlyCursors set to false. If the
2002-05-27 19:47:21 +00:00
connection does not allow backward scrolling cursors, this function will
2003-01-18 00:16:34 +00:00
return false, and the data contained in the bound columns will be undefined.
2000-08-14 11:44:26 +00:00
\wxheading { See also}
2001-02-05 13:33:43 +00:00
\helpref { wxDb::IsFwdOnlyCursors} { wxdbisfwdonlycursors}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetFromClause} \label { wxdbtablegetfromclause}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetFromClause} { }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns the current FROM setting assigned with the
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} .
\wxheading { See also}
\helpref { wxDbTable::From} { wxdbtablefrom}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetLast} \label { wxdbtablegetlast}
\func { bool} { GetLast} { \void }
2002-05-27 19:47:21 +00:00
Retrieves the LAST row in the record set as defined by the current query.
Before retrieving records, a query must be performed using
\helpref { wxDbTable::Query} { wxdbtablequery} ,
\helpref { wxDbTable::QueryOnKeyFields} { wxdbtablequeryonkeyfields} ,
\helpref { wxDbTable::QueryMatching} { wxdbtablequerymatching} or
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::QueryBySqlStmt} { wxdbtablequerybysqlstmt} .
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function can only be used if the datasource connection used by the
2003-01-18 00:16:34 +00:00
wxDbTable instance was created with FwdOnlyCursors set to false. If the
2002-05-27 19:47:21 +00:00
connection does not allow backward scrolling cursors, this function will
2003-01-18 00:16:34 +00:00
return false, and the data contained in the bound columns will be undefined.
2000-08-14 11:44:26 +00:00
\wxheading { See also}
2001-02-05 13:33:43 +00:00
\helpref { wxDb::IsFwdOnlyCursors} { wxdbisfwdonlycursors}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetNewCursor} \label { wxdbtablegetnewcursor}
2003-01-18 00:16:34 +00:00
\func { HSTMT *} { GetNewCursor} { \param { bool } { setCursor=false} ,
\param { bool } { bindColumns=true} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
This function will create a new cursor that can be used to access the table
being referenced by this wxDbTable instance, or to execute direct SQL commands
on without affecting the cursors that are already defined and possibly
2001-02-04 15:52:46 +00:00
positioned.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { setCursor} { { \it OPTIONAL} . Should this new cursor be set to be the
2003-01-18 00:16:34 +00:00
current cursor after successfully creating the new cursor. Default is false.}
2002-05-27 19:47:21 +00:00
\docparam { bindColumns} { { \it OPTIONAL} . Should this new cursor be bound to all
2003-01-18 00:16:34 +00:00
the memory variables that the default cursor is bound to. Default is true.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This new cursor must be closed using
\helpref { wxDbTable::DeleteCursor} { wxdbtabledeletecursor}
by the calling program before the wxDbTable instance is deleted, or both
2001-02-04 15:52:46 +00:00
memory and resource leaks will occur.
2000-11-24 16:40:44 +00:00
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetNext} \label { wxdbtablegetnext}
\func { bool} { GetNext} { \void }
2002-05-27 19:47:21 +00:00
Retrieves the NEXT row in the record set after the current cursor position
as defined by the current query. Before retrieving records, a query must be
performed using \helpref { wxDbTable::Query} { wxdbtablequery} ,
\helpref { wxDbTable::QueryOnKeyFields} { wxdbtablequeryonkeyfields} ,
\helpref { wxDbTable::QueryMatching} { wxdbtablequerymatching} or
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::QueryBySqlStmt} { wxdbtablequerybysqlstmt} .
\wxheading { Return value}
2003-01-18 00:16:34 +00:00
This function returns false when the current cursor has reached the end of
the result set. When false is returned, data in the bound columns is
2000-11-12 20:05:53 +00:00
undefined.
2000-11-24 16:40:44 +00:00
\wxheading { Remarks}
This function works with both forward and backward scrolling cursors.
2000-11-12 20:05:53 +00:00
\wxheading { See also}
\helpref { wxDbTable::++} { wxdbtableplusplus}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetNumberOfColumns} \label { wxdbtablegetnumberofcolumns}
2001-04-11 15:02:50 +00:00
\func { UWORD } { GetNumberOfColumns} { }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns the number of columns that are statically
2000-11-12 20:05:53 +00:00
bound for access by the wxDbTable instance.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetOrderByClause} \label { wxdbtablegetorderbyclause}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetOrderByClause} { }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns the current ORDER BY setting assigned with
2000-11-12 20:05:53 +00:00
the \helpref { wxDbTable::SetOrderByClause} { wxdbtablesetorderbyclause} .
\wxheading { See also}
\helpref { wxDbTable::OrderBy} { wxdbtableorderby}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetPrev} \label { wxdbtablegetprev}
\func { bool} { GetPrev} { \void }
2002-05-27 19:47:21 +00:00
Retrieves the PREVIOUS row in the record set before the current cursor
position as defined by the current query. Before retrieving records, a
query must be performed using \helpref { wxDbTable::Query} { wxdbtablequery} ,
\helpref { wxDbTable::QueryOnKeyFields} { wxdbtablequeryonkeyfields} ,
\helpref { wxDbTable::QueryMatching} { wxdbtablequerymatching} or
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::QueryBySqlStmt} { wxdbtablequerybysqlstmt} .
\wxheading { Return value}
2003-01-18 00:16:34 +00:00
This function returns false when the current cursor has reached the beginning
2002-05-27 19:47:21 +00:00
of the result set and there are now other rows prior to the cursors current
2003-01-18 00:16:34 +00:00
position. When false is returned, data in the bound columns is undefined.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function can only be used if the datasource connection used by the
2003-01-18 00:16:34 +00:00
wxDbTable instance was created with FwdOnlyCursors set to false. If the
2002-05-27 19:47:21 +00:00
connection does not allow backward scrolling cursors, this function will
2003-01-18 00:16:34 +00:00
return false, and the data contained in the bound columns will be undefined.
2000-08-14 11:44:26 +00:00
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDb::IsFwdOnlyCursors} { wxdbisfwdonlycursors} ,
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::--} { wxdbtableminusminus}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetQueryTableName} \label { wxdbtablegetquerytablename}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetQueryTableName} { }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns the name of the table/view that was indicated
as being the table/view to query against when this wxDbTable instance was
2000-11-12 20:05:53 +00:00
created.
\wxheading { See also}
\helpref { wxDbTable constructor} { wxdbtableconstr}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetRowNum} \label { wxdbtablegetrownum}
\func { UWORD} { GetRowNum} { \void }
2002-05-27 19:47:21 +00:00
Returns the ODBC row number for performing positioned updates and deletes.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function is not being used within the ODBC class library and may be a
2000-11-12 20:05:53 +00:00
candidate for removal if no use is found for it.
2002-05-27 19:47:21 +00:00
Row number with some datasources/ODBC drivers is the position in the result set,
while in others it may be a physical position in the database. Check your
2000-11-24 16:40:44 +00:00
database documentation to find out which behavior is supported.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetTableName} \label { wxdbtablegettablename}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetTableName} { }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns the name of the table that was indicated
2000-11-12 20:05:53 +00:00
as being the table that this wxDbTable instance was associated with.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetTablePath} \label { wxdbtablegettablepath}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetTablePath} { }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns the path to the data table that was indicated
2000-11-12 20:05:53 +00:00
during creation of this wxDbTable instance.
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2000-11-12 20:05:53 +00:00
Currently only applicable to dBase and MS-Access datasources.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::GetWhereClause} \label { wxdbtablegetwhereclause}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { GetWhereClause} { }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns the current WHERE setting assigned with the
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
\wxheading { See also}
\helpref { wxDbTable::Where} { wxdbtablewhere}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::Insert} \label { wxdbtableinsert}
2000-11-23 14:39:03 +00:00
\func { int } { Insert} { \void }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Inserts a new record into the table being referenced by this wxDbTable
instance. The values in the member variables of the wxDbTable instance are
2000-11-24 16:40:44 +00:00
inserted into the columns of the new row in the database.
2002-05-27 19:47:21 +00:00
2000-11-12 20:05:53 +00:00
\wxheading { Return value}
\begin { verbatim}
DB_ SUCCESS Record inserted successfully (value = 1)
DB_ FAILURE Insert failed (value = 0)
2002-05-27 19:47:21 +00:00
DB_ ERR_ INTEGRITY_ CONSTRAINT_ VIOL
2000-11-12 20:05:53 +00:00
The insert failed due to an integrity
constraint violation (duplicate non-unique
index entry) is attempted.
\end { verbatim}
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
A \helpref { wxDb::CommitTrans} { wxdbcommittrans} or
\helpref { wxDb::RollbackTrans} { wxdbrollbacktrans} must be called after use of
2000-11-12 20:05:53 +00:00
this function to commit or rollback the insertion.
\wxheading { Example}
\begin { verbatim}
// Incomplete code snippet
2001-02-04 15:52:46 +00:00
wxStrcpy(parts->PartName, "10");
wxStrcpy(parts->PartDesc, "Part #10");
2000-11-12 20:05:53 +00:00
parts->Qty = 1000;
2001-12-20 16:30:31 +00:00
RETCODE retcode = parts->Insert();
2000-11-12 20:05:53 +00:00
switch(retcode)
{
case DB_ SUCCESS:
parts->GetDb()->CommitTrans();
2003-01-18 00:16:34 +00:00
return(true);
2000-11-12 20:05:53 +00:00
case DB_ ERR_ INTEGRITY_ CONSTRAINT_ VIOL:
// Current data would result in a duplicate key
// on one or more indexes that do not allow duplicates
parts->GetDb()->RollbackTrans();
2003-01-18 00:16:34 +00:00
return(false);
2000-11-12 20:05:53 +00:00
default:
// Insert failed for some unexpected reason
parts->GetDb()->RollbackTrans();
2003-01-18 00:16:34 +00:00
return(false);
2000-11-12 20:05:53 +00:00
}
\end { verbatim}
\membersection { wxDbTable::IsColNull} \label { wxdbtableiscolnull}
2001-07-02 10:08:23 +00:00
\func { bool } { IsColNull} { \param { UWORD } { colNo} } const
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Used primarily in the ODBC class library to determine if a column value is
2001-02-04 15:52:46 +00:00
set to "NULL". Works for all data types supported by the ODBC class library.
2000-11-12 20:05:53 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { colNo} { The column number of the bound column as defined by the
\helpref { wxDbTable::SetColDefs} { wxdbtablesetcoldefs}
2001-02-05 13:33:43 +00:00
calls which defined the columns accessible to this wxDbTable instance.}
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-06 13:46:24 +00:00
NULL column support is currently not fully implemented as of wxWindows 2.4.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::IsCursorClosedOnCommit} \label { wxdbtableiscursorclosedoncommit}
2001-02-04 15:52:46 +00:00
\func { bool } { IsCursorClosedOnCommit} { \void }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function to return information collected during the opening of the
datasource connection that is used by this wxDbTable instance. The result
returned by this function indicates whether an implicit closing of the cursor is
2000-11-24 16:40:44 +00:00
done after a commit on the database connection.
2000-11-12 20:05:53 +00:00
\wxheading { Return value}
2003-01-18 00:16:34 +00:00
Returns true if the cursor associated with this wxDbTable object is closed
after a commit or rollback operation. Returns false otherwise.
2000-11-12 20:05:53 +00:00
2000-11-24 16:40:44 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
If more than one wxDbTable instance used the same database connection, all cursors
which use the database connection are closed on the commit if this function
2003-01-18 00:16:34 +00:00
indicates true.
2000-11-24 16:40:44 +00:00
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::IsQueryOnly} \label { wxdbtableisqueryonly}
2001-02-04 15:52:46 +00:00
\func { bool } { IsQueryOnly} { }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Accessor function that returns a value indicating if this wxDbTable instance
was created to allow only queries to be performed on the bound columns. If
2003-01-18 00:16:34 +00:00
this function returns true, then no actions may be performed using this
2000-11-12 20:05:53 +00:00
wxDbTable instance that would modify (insert/delete/update) the table's data.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::Open} \label { wxdbtableopen}
2003-01-18 00:16:34 +00:00
\func { bool } { Open} { \param { bool } { checkPrivileges=false} , \param { bool } { checkTableExists=true} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Every wxDbTable instance must be opened before it can be used. This function
checks for the existence of the requested table, binds columns, creates required
cursors, (insert/select and update if connection is not wxDB\_ QUERY\_ ONLY) and
constructs the insert statement that is to be used for inserting data as a new
2000-11-24 16:40:44 +00:00
row in the datasource.
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { checkPrivileges} { Indicates whether the Open() function should check
whether the current connected user has at least SELECT privileges to access the
2003-01-18 00:16:34 +00:00
table to which they are trying to open. Default is false.}
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
\docparam { checkTableExists} { Indicates whether the Open() function should check
2003-01-18 00:16:34 +00:00
whether the table exists in the database or not before opening it. Default is true.}
2001-04-10 10:43:51 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2003-01-18 00:16:34 +00:00
If the function returns a false value due to the table not existing, a log
2002-05-27 19:47:21 +00:00
entry is recorded for the datasource connection indicating the problem
that was detected when checking for table existence. Note that it is usually
best for the calling routine to check for the existence of the table and for
2002-06-07 20:15:28 +00:00
sufficient user privileges to access the table in the mode (wxDB\_ QUERY\_ ONLY or
2002-05-27 19:47:21 +00:00
!wxDB\_ QUERY\_ ONLY) before trying to open the table for the best possible
2000-11-24 16:40:44 +00:00
explanation as to why a table cannot be opened.
2002-05-27 19:47:21 +00:00
Checking the user's privileges on a table can be quite time consuming during
the open phase. With most applications, the programmer already knows that the
user has sufficient privileges to access the table, so this check is normally
2000-11-24 16:40:44 +00:00
not required.
2002-05-27 19:47:21 +00:00
For best performance, open the table, and then use the
\helpref { wxDb::TablePrivileges} { wxdbtableprivileges} function
to check the users privileges. Passing a schema to the TablePrivileges()
2000-11-24 16:40:44 +00:00
function can significantly speed up the privileges checks.
2000-11-12 20:05:53 +00:00
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDb::TableExists} { wxdbtableexists} ,
2000-11-24 16:40:44 +00:00
\helpref { wxDb::TablePrivileges} { wxdbtableprivileges}
2000-11-12 20:05:53 +00:00
\membersection { wxDbTable::OrderBy} \label { wxdbtableorderby}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { OrderBy} { }
2000-11-24 16:40:44 +00:00
2002-05-05 14:24:07 +00:00
\func { void} { OrderBy} { \param { const wxString \& } { OrderBy} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Accessor function for the private class member wxDbTable::orderBy. Can be
used as a synonym for
\helpref { wxDbTable::GetOrderByClause} { wxdbtablegetorderbyclause}
(the first form of this function) or
\helpref { wxDbTable::SetOrderByClause} { wxdbtablesetorderbyclause}
2000-11-12 20:05:53 +00:00
(the second form of this function).
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { OrderBy} { A comma separated list of column names that indicate the
alphabetized/numeric sorting sequence that the result set is to be returned
in. If a FROM clause has also been specified, each column name specified in
the ORDER BY clause should be prefaced with the table name to which the column
2001-05-24 10:39:33 +00:00
belongs using DOT notation (TABLE\_ NAME.COLUMN\_ NAME).}
2000-11-12 20:05:53 +00:00
\wxheading { Return value}
2002-05-27 19:47:21 +00:00
The first form of this function returns the current value of the wxDbTable
member variable ::orderBy.
2000-11-12 20:05:53 +00:00
The second form of the function has no return value.
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDbTable::GetOrderByClause} { wxdbtablegetorderbyclause} ,
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::Query} \label { wxdbtablequery}
2003-01-18 00:16:34 +00:00
\func { virtual bool } { Query} { \param { bool } { forUpdate=false} , \param { bool } { distinct=false} }
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { forUpdate} { { \it OPTIONAL} . Gives you the option of locking records
as they are retrieved. If the RDBMS is not capable of the FOR UPDATE clause,
this argument is ignored. See
\helpref { wxDbTable::CanSelectForUpdate} { wxdbtablecanselectforupdate} for
2003-01-18 00:16:34 +00:00
additional information regarding this argument. Default is false.}
2002-05-27 19:47:21 +00:00
\docparam { distinct} { { \it OPTIONAL} . Allows selection of only distinct values
from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
applies to all columns returned in the result set, not individual columns.
2003-01-18 00:16:34 +00:00
Default is false.}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This function queries records from the datasource based on the three
wxDbTable members: "where", "orderBy", and "from". Use
\helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause} to filter on
records to be retrieved (e.g. All users with a first name of "JOHN").
Use \helpref { wxDbTable::SetOrderByClause} { wxdbtablesetorderbyclause} to
change the sequence in which records are returned in the result set from
the datasource (e.g. Ordered by LAST\_ NAME). Use
\helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} to allow outer
joining of the base table (the one being associated with this instance of
wxDbTable) with other tables which share a related field.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
After each of these clauses are set/cleared, call wxDbTable::Query() to
fetch the result set from the datasource.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
This scheme has an advantage if you have to requery your record set
frequently in that you only have to set your WHERE, ORDER BY, and FROM
clauses once. Then to refresh the record set, simply call wxDbTable::Query()
as frequently as needed.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Note that repeated calls to wxDbTable::Query() may tax the database
server and make your application sluggish if done too frequently or
unnecessarily.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
The base table name is automatically prepended to the base column names in
the event that the FROM clause has been set (is non-null) using
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} .
2002-05-27 19:47:21 +00:00
The cursor for the result set is positioned { \it before} the first record in
the result set after the query. To retrieve the first record, call either
\helpref { wxDbTable::GetFirst} { wxdbtablegetfirst} (only if backward scrolling
cursors are available) or
\helpref { wxDbTable::GetNext} { wxdbtablegetnext} . Typically, no data from the
result set is returned to the client driver until a request such as
\helpref { wxDbTable::GetNext} { wxdbtablegetnext} is performed, so network
traffic and database load are not overwhelmed transmitting data until the
data is actually requested by the client. This behavior is solely dependent
on the ODBC driver though, so refer to the ODBC driver's reference material
2000-11-12 20:05:53 +00:00
for information on its behaviors.
2002-05-27 19:47:21 +00:00
Values in the bound columns' memory variables are undefined after executing a
call to this function and remain that way until a row in the result set is
2000-11-24 16:40:44 +00:00
requested to be returned.
2002-05-27 19:47:21 +00:00
The wxDbTable::Query() function is defined as "virtual" so that it may be
2000-11-12 20:05:53 +00:00
overridden for application specific purposes.
2002-05-27 19:47:21 +00:00
\normalbox { Be sure to set the wxDbTable's "where", "orderBy", and "from"
member variables to "" if they are not to be used in the query. Otherwise,
the results returned may have unexpected results (or no results) due to
improper or incorrect query parameters constructed from the uninitialized
2000-11-12 20:05:53 +00:00
clauses.}
\wxheading { Example}
\begin { verbatim}
// Incomplete code sample
parts->SetWhereClause("DESCRIPTION = 'FOOD'");
parts->SetOrderByClause("EXPIRATION_ DATE");
parts->SetFromClause("");
2002-05-27 19:47:21 +00:00
// Query the records based on the where, orderBy and from clauses
2000-11-12 20:05:53 +00:00
// specified above
parts->Query();
// Display all records queried
while(parts->GetNext())
dispPart(parts); // user defined function
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::QueryBySqlStmt} \label { wxdbtablequerybysqlstmt}
2002-05-05 14:24:07 +00:00
\func { bool} { QueryBySqlStmt} { \param { const wxString \& } { pSqlStmt} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Performs a query against the datasource by accepting and passing verbatim the
2000-11-12 20:05:53 +00:00
SQL SELECT statement passed to the function.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2000-11-24 16:40:44 +00:00
\docparam { pSqlStmt} { Pointer to the SQL SELECT statement to be executed.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This is the most powerful form of the query functions available. This member
function allows a programmer to write their own custom SQL SELECT statement
for requesting data from the datasource. This gives the programmer access
to the full power of SQL for performing operations such as scalar functions,
aggregate functions, table joins, and sub-queries, as well as datasource
specific function calls.
2000-11-12 20:05:53 +00:00
The requirements of the SELECT statement are the following:
2002-07-10 09:06:56 +00:00
\begin { enumerate}
\item Must return the correct number of columns. In the derived
wxDbTable constructor, it is specified how many columns are in
the wxDbTable object. The SELECT statement must return exactly
that many columns.
\item The columns must be returned in the same sequence as specified
when defining the bounds columns using wxDbTable::SetColDefs(),
and the columns returned must be of the proper data type. For
example, if column 3 is defined in the wxDbTable bound column
definitions to be a float, the SELECT statement must return a
float for column 3 (e.g. PRICE * 1.10 to increase the price by
10%).
2002-07-12 23:25:14 +00:00
\item The ROWID can be included in your SELECT statement as the { \bf last}
2002-07-10 09:06:56 +00:00
column selected, if the datasource supports it. Use
wxDbTable::CanUpdByROWID() to determine if the ROWID can be
selected from the datasource. If it can, much better
performance can be achieved on updates and deletes by including
the ROWID in the SELECT statement.
\end { enumerate}
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Even though data can be selected from multiple tables (joins) in your select
2000-11-24 16:40:44 +00:00
statement, only the base table associated with this wxDbTable object
2002-05-27 19:47:21 +00:00
is automatically updated through the ODBC class library. Data from multiple
tables can be selected for display purposes however. Include columns in
the wxDbTable object and mark them as non-updateable (See
\helpref { wxDbColDef} { wxdbcoldef} for details). This way columns can be
selected and displayed from other tables, but only the base table will be
updated automatically when performed through the
\helpref { wxDbTable::Update} { wxdbtableupdate} function after using this type of
query. To update tables other than the base table, use the
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::Update} { wxdbtableupdate} function passing a SQL statement.
2002-05-27 19:47:21 +00:00
After this function has been called, the cursor is positioned before the
first record in the record set. To retrieve the first record, call
either \helpref { wxDbTable::GetFirst} { wxdbtablegetfirst} or
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::GetNext} { wxdbtablegetnext} .
\wxheading { Example}
\begin { verbatim}
// Incomplete code samples
2001-02-04 15:52:46 +00:00
wxString sqlStmt;
sqlStmt = "SELECT * FROM PARTS WHERE STORAGE_ DEVICE = 'SD98' \
AND CONTAINER = 12";
2000-11-12 20:05:53 +00:00
// Query the records using the SQL SELECT statement above
parts->QueryBySqlStmt(sqlStmt);
// Display all records queried
while(parts->GetNext())
dispPart(& parts);
Example SQL statements
----------------------
// Table Join returning 3 columns
SELECT part_ no, part_ desc, sd_ name
from parts, storage_ devices
2002-05-27 19:47:21 +00:00
where parts.storage_ device_ id =
2000-11-24 16:40:44 +00:00
storage_ devices.storage_ device_ id
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
// Aggregate function returning total number of
2000-11-24 16:40:44 +00:00
// parts in container 99
2000-11-12 20:05:53 +00:00
SELECT count(*) from PARTS where container = 99
// Order by clause; ROWID, scalar function
SELECT part_ no, substring(part_ desc, 1, 10), qty_ on_ hand + 1, ROWID
from parts
where warehouse = 10
order by part_ no desc // descending order
// Subquery
SELECT * from parts
where container in (select container
from storage_ devices
where device_ id = 12)
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::QueryMatching} \label { wxdbtablequerymatching}
2003-01-18 00:16:34 +00:00
\func { virtual bool } { QueryMatching} { \param { bool } { forUpdate=false} ,
\param { bool } { distinct=false} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
QueryMatching allows querying of records from the table associated with
the wxDbTable object by matching "columns" to values.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
For example: To query the datasource for the row with a PART\_ NUMBER column
value of "32", clear all column variables of the wxDbTable object, set the
PartNumber variable that is bound to the PART\_ NUMBER column in the wxDbTable
2000-11-12 20:05:53 +00:00
object to "32", and then call wxDbTable::QueryMatching().
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { forUpdate} { { \it OPTIONAL} . Gives you the option of locking records
as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
the FOR UPDATE clause, this argument is ignored. See
\helpref { wxDbTable::CanSelectForUpdate} { wxdbtablecanselectforupdate} for
2003-01-18 00:16:34 +00:00
additional information regarding this argument. Default is false.}
2002-05-27 19:47:21 +00:00
\docparam { distinct} { { \it OPTIONAL} . Allows selection of only distinct values
from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
applies to all columns returned in the result set, not individual columns.
2003-01-18 00:16:34 +00:00
Default is false.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
The SQL WHERE clause is built by the ODBC class library based on all
non-zero/non-NULL columns in your wxDbTable object. Matches can be on one,
many or all of the wxDbTable's columns. The base table name is prepended
2000-11-12 20:05:53 +00:00
to the column names in the event that the wxDbTable's FROM clause is non-null.
2002-05-27 19:47:21 +00:00
This function cannot be used to perform queries which will check for
columns that are 0 or NULL, as the automatically constructed WHERE clause
only will contain comparisons on column member variables that are
2000-11-12 20:05:53 +00:00
non-zero/non-NULL.
2002-05-27 19:47:21 +00:00
The primary difference between this function and \helpref { wxDbTable::QueryOnKeyFields} { wxdbtablequeryonkeyfields}
is that this function can query on any column(s) in the wxDbTable object.
Note however that this may not always be very efficient. Searching on
2000-11-12 20:05:53 +00:00
non-indexed columns will always require a full table scan.
2002-05-27 19:47:21 +00:00
The cursor is positioned before the first record in the record set after
the query is performed. To retrieve the first record, the program must call
either \helpref { wxDbTable::GetFirst} { wxdbtablegetfirst} or
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::GetNext} { wxdbtablegetnext} .
2002-05-27 19:47:21 +00:00
WHERE and FROM clauses specified using \helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
and \helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} are ignored by
2000-11-24 16:40:44 +00:00
this function.
2000-11-12 20:05:53 +00:00
\wxheading { Example}
\begin { verbatim}
// Incomplete code sample
parts->ClearMemberVars(); // Set all columns to zero
2001-02-04 15:52:46 +00:00
wxStrcpy(parts->PartNumber,"32"); // Set columns to query on
2003-01-18 00:16:34 +00:00
parts->OnHold = true;
2000-11-12 20:05:53 +00:00
parts->QueryMatching(); // Query
// Display all records queried
while(parts->GetNext())
dispPart(parts); // Some application defined function
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::QueryOnKeyFields} \label { wxdbtablequeryonkeyfields}
2003-01-18 00:16:34 +00:00
\func { bool } { QueryOnKeyFields} { \param { bool } { forUpdate=false} ,
\param { bool } { distinct=false} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
QueryOnKeyFields provides an easy mechanism to query records in the table
associated with the wxDbTable object by the primary index column(s). Simply
assign the primary index column(s) values and then call this member function
to retrieve the record.
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Note that since primary indexes are always unique, this function implicitly
always returns a single record from the database. The base table name is
prepended to the column names in the event that the wxDbTable's FROM clause
2000-11-12 20:05:53 +00:00
is non-null.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { forUpdate} { { \it OPTIONAL} . Gives you the option of locking records
as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
the FOR UPDATE clause, this argument is ignored. See
\helpref { wxDbTable::CanSelectForUpdate} { wxdbtablecanselectforupdate} for
2003-01-18 00:16:34 +00:00
additional information regarding this argument. Default is false.}
2002-05-27 19:47:21 +00:00
\docparam { distinct} { { \it OPTIONAL} . Allows selection of only distinct values
from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
applies to all columns returned in the result set, not individual columns.
2003-01-18 00:16:34 +00:00
Default is false.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
The cursor is positioned before the first record in the record set after
the query is performed. To retrieve the first record, the program must call
either \helpref { wxDbTable::GetFirst} { wxdbtablegetfirst} or
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::GetNext} { wxdbtablegetnext} .
2002-05-27 19:47:21 +00:00
WHERE and FROM clauses specified using \helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
and \helpref { wxDbTable::SetFromClause} { wxdbtablesetfromclause} are ignored by
2000-11-24 16:40:44 +00:00
this function.
2000-11-12 20:05:53 +00:00
\wxheading { Example}
\begin { verbatim}
// Incomplete code sample
2001-02-04 15:52:46 +00:00
wxStrcpy(parts->PartNumber, "32");
2000-11-12 20:05:53 +00:00
parts->QueryOnKeyFields();
// Display all records queried
while(parts->GetNext())
dispPart(parts); // Some application defined function
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::Refresh} \label { wxdbtablerefresh}
\func { bool} { Refresh} { \void }
2002-05-27 19:47:21 +00:00
This function re-reads the bound columns into the memory variables, setting
2000-11-24 16:40:44 +00:00
them to the current values stored on the disk.
2000-11-12 20:05:53 +00:00
The cursor position and result set are unaffected by calls to this function.
2002-05-27 19:47:21 +00:00
(The one exception is in the case where the record to be refreshed has been
deleted by some other user or transaction since it was originally retrieved
as part of the result set. For most datasources, the default behavior in
this situation is to return the value that was originally queried for the
result set, even though it has been deleted from the database. But this is
2000-11-12 20:05:53 +00:00
datasource dependent, and should be tested before relying on this behavior.)
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
This routine is only guaranteed to work if the table has a unique primary
index defined for it. Otherwise, more than one record may be fetched and
there is no guarantee that the correct record will be refreshed. The
2000-11-12 20:05:53 +00:00
table's columns are refreshed to reflect the current data in the database.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::SetColDefs} \label { wxdbtablesetcoldefs}
2002-05-27 19:47:21 +00:00
\func { void} { SetColDefs} { \param { UWORD } { index} , \param { const wxString \& } { fieldName} ,
\param { int } { dataType} , \param { void *} { pData} , \param { SWORD } { cType} ,
2003-01-18 00:16:34 +00:00
\param { int } { size} , \param { bool } { keyField = false} , \param { bool } { upd = true} ,
\param { bool } { insAllow = true} , \param { bool } { derivedCol = false} }
2000-08-14 11:44:26 +00:00
2001-04-11 15:02:50 +00:00
\func { wxDbColDataPtr *} { SetColDefs} { \param { wxDbColInf *} { colInfs} , \param { UWORD } { numCols} }
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { index} { Column number (0 to n-1, where n is the number of columns
specified as being defined for this wxDbTable instance when the
2000-11-12 20:05:53 +00:00
wxDbTable constructor was called.}
\docparam { fieldName} { Column name from the associated data table.}
\docparam { dataType} { Logical data type. Valid logical types include:}
2000-08-14 11:44:26 +00:00
2000-11-12 20:05:53 +00:00
\begin { verbatim}
DB_ DATA_ TYPE_ VARCHAR : strings
DB_ DATA_ TYPE_ INTEGER : non-floating point numbers
DB_ DATA_ TYPE_ FLOAT : floating point numbers
DB_ DATA_ TYPE_ DATE : dates
\end { verbatim}
2002-05-27 19:47:21 +00:00
\docparam { pData} { Pointer to the data object that will hold the column's
2000-11-12 20:05:53 +00:00
value when a row of data is returned from the datasource.}
2002-05-27 19:47:21 +00:00
\docparam { cType} { SQL C Type. This defines the data type that the SQL
2000-11-12 20:05:53 +00:00
representation of the data is converted to to be stored in { \it pData} .
Other valid types are available also, but these are the most common ones:}
\begin { verbatim}
SQL_ C_ CHAR // strings
SQL_ C_ LONG
SQL_ C_ ULONG
SQL_ C_ SHORT
SQL_ C_ USHORT
SQL_ C_ FLOAT
SQL_ C_ DOUBLE
2002-05-27 19:47:21 +00:00
SQL_ C_ NUMERIC
2000-11-12 20:05:53 +00:00
SQL_ C_ TIMESTAMP
SQL_ C_ BOOLEAN // defined in db.h
SQL_ C_ ENUM // defined in db.h
\end { verbatim}
\docparam { size} { Maximum size in bytes of the { \it pData} object.}
2002-05-27 19:47:21 +00:00
\docparam { keyField} { { \it OPTIONAL} . Indicates if this column is part of the
2003-01-18 00:16:34 +00:00
primary index. Default is false.}
2002-05-27 19:47:21 +00:00
\docparam { upd} { { \it OPTIONAL} . Are updates allowed on this column?
2003-01-18 00:16:34 +00:00
Default is true.}
2002-05-27 19:47:21 +00:00
\docparam { insAllow} { { \it OPTIONAL} . Inserts allowed on this column?
2003-01-18 00:16:34 +00:00
Default is true.}
2002-05-27 19:47:21 +00:00
\docparam { derivedCol} { { \it OPTIONAL} . Is this a derived column (non-base
2003-01-18 00:16:34 +00:00
table column for query only)? Default is false.}
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
\docparam { colInfs} { Pointer to an array of wxDbColInf instances which contains
2000-11-12 20:05:53 +00:00
all the information necessary to create { \it numCols} column definitions.}
2002-05-27 19:47:21 +00:00
\docparam { numCols} { Number of elements of wxDbColInf type that are pointed
2000-11-12 20:05:53 +00:00
to by { \it colInfs} , which are to have column definitions created from them.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
If { \it pData} is to hold a string of characters, be sure to include enough
2000-11-12 20:05:53 +00:00
space for the NULL terminator in pData and in the byte count of { \it size} .
2002-05-27 19:47:21 +00:00
Both forms of this function provide a shortcut for defining the columns in
your wxDbTable object. Use this function in any derived wxDbTable
2000-11-12 20:05:53 +00:00
constructor when describing the column/columns in the wxDbTable object.
2002-05-27 19:47:21 +00:00
The second form of this function is primarily used when the
\helpref { wxDb::GetColumns} { wxdbgetcolumns} function was used to query the
datasource for the column definitions, so that the column definitions are
already stored in wxDbColInf form. One example use of using
\helpref { wxDb::GetColumns} { wxdbgetcolumns} then using this function is if
a data table existed in one datasource, and the table's column definitions
2000-11-12 20:05:53 +00:00
were to be copied over to another datasource or table.
\wxheading { Example}
\begin { verbatim}
// Long way not using this function
2001-02-04 15:52:46 +00:00
wxStrcpy(colDefs[0].ColName, "PART_ NO");
2000-11-12 20:05:53 +00:00
colDefs[0].DbDataType = DB_ DATA_ TYPE_ VARCHAR;
colDefs[0].PtrDataObj = PartNumber;
colDefs[0].SqlCtype = SQL_ C_ CHAR;
colDefs[0].SzDataObj = PART_ NUMBER_ LEN;
2003-01-18 00:16:34 +00:00
colDefs[0].KeyField = true;
colDefs[0].Updateable = false;
colDefs[0].InsertAllowed= true;
colDefs[0].DerivedCol = false;
2000-11-12 20:05:53 +00:00
// Shortcut using this function
SetColDefs(0, "PART_ NUMBER", DB_ DATA_ TYPE_ VARCHAR, PartNumber,
2003-01-18 00:16:34 +00:00
SQL_ C_ CHAR, PART_ NUMBER_ LEN, true, false,true,false);
2000-11-12 20:05:53 +00:00
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::SetCursor} \label { wxdbtablesetcursor}
2001-05-24 10:39:33 +00:00
\func { bool} { SetCursor} { \param { HSTMT *} { hstmtActivate = (void **) wxDB\_ DEFAULT\_ CURSOR} }
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { hstmtActivate} { { \it OPTIONAL} . Pointer to the cursor that is to
become the current cursor. Passing no cursor handle will reset the cursor
back to the wxDbTable's default (original) cursor that was created when the
2001-05-24 10:39:33 +00:00
wxDbTable instance was first created. Default is wxDB\_ DEFAULT\_ CURSOR.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
When swapping between cursors, the member variables of the wxDbTable object
are automatically refreshed with the column values of the row that the
current cursor is positioned at (if any). If the cursor is not positioned,
2000-11-12 20:05:53 +00:00
then the data in member variables is undefined.
2002-05-27 19:47:21 +00:00
The only way to return back to the cursor that was in use before this
function was called is to programmatically determine the current cursor's HSTMT
{ \bf BEFORE} calling this function using \helpref { wxDbTable::GetCursor} { wxdbtablegetcursor}
2000-11-12 20:05:53 +00:00
and saving a pointer to that cursor.
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDbTable::GetNewCursor} { wxdbtablegetnewcursor} ,
\helpref { wxDbTable::GetCursor} { wxdbtablegetcursor} ,
2000-11-12 20:05:53 +00:00
\helpref { wxDbTable::SetCursor} { wxdbtablesetcursor}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::SetFromClause} \label { wxdbtablesetfromclause}
2002-05-05 14:24:07 +00:00
\func { void} { SetFromClause} { \param { const wxString \& } { From} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Accessor function for setting the private class member wxDbTable::from
2000-11-12 20:05:53 +00:00
that indicates what other tables should be outer joined with the wxDbTable's
2002-05-27 19:47:21 +00:00
base table for access to the columns in those other tables.
2000-11-12 20:05:53 +00:00
Synonym to this function is one form of \helpref { wxDbTable::From} { wxdbtablefrom}
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { From} { A comma separated list of table names that are to be outer
joined with the base table's columns so that the joined table's columns
may be returned in the result set or used as a portion of a comparison with
the base table's columns. NOTE that the base tables name must NOT be included
in the FROM clause, as it is automatically included by the wxDbTable class
2000-11-12 20:05:53 +00:00
in constructing query statements.}
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Used by the \helpref { wxDbTable::Query} { wxdbtablequery} and
\helpref { wxDbTable::Count} { wxdbtablecount} member functions to allow outer
joining of records from multiple tables.
2000-11-12 20:05:53 +00:00
Do { \bf not} include the keyword "FROM" when setting the FROM clause.
2002-05-27 19:47:21 +00:00
If using the FROM clause when performing a query, be certain to include in
the corresponding WHERE clause a comparison of a column from either the base
table or one of the other joined tables to each other joined table to ensure
2000-11-12 20:05:53 +00:00
the datasource knows on which column values the tables should be joined on.
\wxheading { Example}
\begin { verbatim}
...
// Base table is the "LOCATION" table, and it is being
// outer joined to the "PART" table via the the field "PART_ NUMBER"
// that can be related between the two tables.
location->SetWhereClause("LOCATION.PART_ NUMBER = PART.PART_ NUMBER")
location->SetFromClause("PART");
...
\end { verbatim}
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDbTable::From} { wxdbtablefrom} ,
2000-11-24 16:40:44 +00:00
\helpref { wxDbTable::GetFromClause} { wxdbtablegetfromclause}
2000-11-12 20:05:53 +00:00
2000-11-24 16:40:44 +00:00
\membersection { wxDbTable::SetColNull} \label { wxdbtablesetcolnull}
2000-08-14 11:44:26 +00:00
2003-01-18 00:16:34 +00:00
\func { bool} { SetColNull} { \param { UWORD } { colNo} , \param { bool } { set=true} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
\func { bool} { SetColNull} { \param { const wxString \& } { colName} ,
2003-01-18 00:16:34 +00:00
\param { bool } { set=true} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Both forms of this function allow a member variable representing a column
2000-11-12 20:05:53 +00:00
in the table associated with this wxDbTable object to be set to NULL.
2002-05-27 19:47:21 +00:00
The first form allows the column to be set by the index into the column
definitions used to create the wxDbTable instance, while the second allows
2000-11-12 20:05:53 +00:00
the actual column name to be specified.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { colNo} { Index into the column definitions used when first defining
2000-11-12 20:05:53 +00:00
this wxDbTable object.}
\docparam { colName} { Actual data table column name that is to be set to NULL.}
2003-01-18 00:16:34 +00:00
\docparam { set} { Whether the column is set to NULL or not. Passing true sets
the column to NULL, passing false sets the column to be non-NULL. Default is
true.}
2000-11-24 16:40:44 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
No database updates are done by this function. It only operates on the
member variables in memory. Use and insert or update function to store this
2000-11-12 20:05:53 +00:00
value to disk.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::SetOrderByClause} \label { wxdbtablesetorderbyclause}
2002-05-05 14:24:07 +00:00
\func { void} { SetOrderByClause} { \param { const wxString \& } { OrderBy} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Accessor function for setting the private class member wxDbTable::orderBy
which determines sequence/ordering of the rows returned in the result set
2000-11-12 20:05:53 +00:00
of a query.
2000-11-24 16:40:44 +00:00
A synonym to this function is one form of the function \helpref { wxDbTable::OrderBy} { wxdbtableorderby}
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { OrderBy} { A comma separated list of column names that indicate the
alphabetized sorting sequence that the result set is to be returned in. If
a FROM clause has also been specified, each column name specified in the
ORDER BY clause should be prefaced with the table name to which the column
2001-05-24 10:39:33 +00:00
belongs using DOT notation (TABLE\_ NAME.COLUMN\_ NAME).}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
Do { \bf not} include the keywords "ORDER BY" when setting the ORDER BY clause.
\wxheading { Example}
\begin { verbatim}
...
parts->SetOrderByClause("PART_ DESCRIP, QUANTITY");
...
...
location->SetOrderByClause("LOCATION.POSITION, PART.PART_ NUMBER);
...
\end { verbatim}
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDbTable::OrderBy} { wxdbtableorderby} ,
2000-11-24 16:40:44 +00:00
\helpref { wxDbTable::GetOrderByClause} { wxdbtablegetorderbyclause}
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::SetQueryTimeout} \label { wxdbtablesetquerytimeout}
\func { bool} { SetQueryTimeout} { \param { UDWORD } { nSeconds} }
2000-11-12 20:05:53 +00:00
Allows a time period to be set as the timeout period for queries.
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { nSeconds} { The number of seconds to wait for the query to complete
2000-11-12 20:05:53 +00:00
before timing out.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Neither Oracle or Access support this function as of yet. Other databases
should be evaluated for support before depending on this function working
2000-11-12 20:05:53 +00:00
correctly.
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::SetWhereClause} \label { wxdbtablesetwhereclause}
2002-05-05 14:24:07 +00:00
\func { void} { SetWhereClause} { \param { const wxString \& } { Where} }
2000-11-12 20:05:53 +00:00
2002-05-27 19:47:21 +00:00
Accessor function for setting the private class member wxDbTable::where
2000-11-12 20:05:53 +00:00
that determines which rows are returned in the result set by the datasource.
2000-11-24 16:40:44 +00:00
A synonym to this function is one form of the function \helpref { wxDbTable::Where} { wxdbtablewhere}
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { Where} { SQL "where" clause. This clause can contain any SQL language
that is legal in standard where clauses. If a FROM clause has also been
specified, each column name specified in the ORDER BY clause should be
prefaced with the table name to which the column belongs using DOT notation
2001-05-24 10:39:33 +00:00
(TABLE\_ NAME.COLUMN\_ NAME).}
2000-11-12 20:05:53 +00:00
\wxheading { Remarks}
Do { \bf not} include the keywords "WHERE" when setting the WHERE clause.
\wxheading { Example}
\begin { verbatim}
...
// Simple where clause
parts->SetWhereClause("PART_ NUMBER = '32'");
...
// Any comparison operators
parts->SetWhereClause("PART_ DESCRIP LIKE 'HAMMER%'");
...
// Multiple comparisons, including a function call
parts->Where("QTY > 0 AND { fn UCASE(PART_ DESCRIP)} LIKE '%DRILL%'");
...
// Using parameters and multiple logical combinations
parts->Where("((QTY > 10) OR (ON_ ORDER > 0)) AND ON_ HOLD = 0");
...
// This query uses an outer join (requiring a FROM clause also)
// that joins the PART and LOCATION table on he common field
// PART_ NUMBER.
parts->Where("PART.ON_ HOLD = 0 AND \
PART.PART_ NUMBER = LOCATION.PART_ NUMBER AND \
LOCATION.PART_ NUMBER > 0");
\end { verbatim}
2000-11-24 16:40:44 +00:00
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDbTable::Where} { wxdbtablewhere} ,
2000-11-24 16:40:44 +00:00
\helpref { wxDbTable::GetWhereClause} { wxdbtablegetwhereclause}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::Update} \label { wxdbtableupdate}
2001-02-04 15:52:46 +00:00
\func { bool } { Update} { \void }
2000-08-14 11:44:26 +00:00
2002-05-05 14:24:07 +00:00
\func { bool } { Update} { \param { const wxString \& } { pSqlStmt} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
The first form of this function will update the row that the current cursor
is currently positioned at with the values in the memory variables that
are bound to the columns. The actual SQL statement to perform the update
2000-11-12 20:05:53 +00:00
is automatically created by the ODBC class, and then executed.
2002-05-27 19:47:21 +00:00
The second form of the function allows full access through SQL statements for
updating records in the database. Write any valid SQL UPDATE statement and
submit it to this function for execution. Sophisticated updates can be
performed using the full power of the SQL dialect. The full SQL statement
must have the exact syntax required by the driver/datasource for performing
2000-11-12 20:05:53 +00:00
the update. This usually is in the form of:
\begin { verbatim}
UPDATE tablename SET col1=X, col2=Y, ... where ...
\end { verbatim}
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2000-11-12 20:05:53 +00:00
\docparam { pSqlStmt} { Pointer to SQL UPDATE statement to be executed.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
A \helpref { wxDb::CommitTrans} { wxdbcommittrans} or
\helpref { wxDb::RollbackTrans} { wxdbrollbacktrans} must be called after use of
2000-11-12 20:05:53 +00:00
this function to commit or rollback the update.
\wxheading { Example}
\begin { verbatim}
2001-02-04 15:52:46 +00:00
wxString sqlStmt;
sqlStmt = "update PART set QTY = 0 where PART_ NUMBER = '32'";
2000-11-12 20:05:53 +00:00
\end { verbatim}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::UpdateWhere} \label { wxdbtableupdatewhere}
2002-05-05 14:24:07 +00:00
\func { bool} { UpdateWhere} { \param { const wxString \& } { pWhereClause} }
2000-08-14 11:44:26 +00:00
2002-05-27 19:47:21 +00:00
Performs updates to the base table of the wxDbTable object, updating only the
2000-11-12 20:05:53 +00:00
rows which match the criteria specified in the { \it pWhereClause} .
2002-05-27 19:47:21 +00:00
All columns that are bound to member variables for this wxDbTable instance
2003-01-18 00:16:34 +00:00
that were defined with the "updateable" parameter set to true will be updated
2002-05-27 19:47:21 +00:00
with the information currently held in the memory variable.
2000-11-12 20:05:53 +00:00
2000-08-14 11:44:26 +00:00
\wxheading { Parameters}
2002-05-27 19:47:21 +00:00
\docparam { pWhereClause} { Pointer to a valid SQL WHERE clause. Do not
2000-11-12 20:05:53 +00:00
include the keyword 'WHERE'.}
2000-08-14 11:44:26 +00:00
\wxheading { Remarks}
2002-05-27 19:47:21 +00:00
Care should be used when updating columns that are part of indexes with
2000-11-12 20:05:53 +00:00
this function so as not to violate an unique key constraints.
2002-05-27 19:47:21 +00:00
A \helpref { wxDb::CommitTrans} { wxdbcommittrans} or
\helpref { wxDb::RollbackTrans} { wxdbrollbacktrans} must be called after use of
2000-11-12 20:05:53 +00:00
this function to commit or rollback the update(s).
2000-11-24 16:40:44 +00:00
\membersection { wxDbTable::Where} \label { wxdbtablewhere}
2002-05-05 14:24:07 +00:00
\func { const wxString \& } { Where} { }
2000-11-24 16:40:44 +00:00
2002-05-05 14:24:07 +00:00
\func { void} { Where} { \param { const wxString\& } { Where} }
2000-11-24 16:40:44 +00:00
2002-05-27 19:47:21 +00:00
Accessor function for the private class member wxDbTable::where. Can be used
as a synonym for \helpref { wxDbTable::GetWhereClause} { wxdbtablegetwhereclause}
(the first form of this function) to return the current where clause or
\helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause} (the second form
2000-11-24 16:40:44 +00:00
of this function) to set the where clause for this table instance.
\wxheading { Parameters}
\docparam { Where} { A valid SQL WHERE clause. Do not include the keyword 'WHERE'.}
\wxheading { Return value}
2002-05-27 19:47:21 +00:00
The first form of this function returns the current value of the wxDbTable
member variable ::where.
2000-11-24 16:40:44 +00:00
2002-05-27 19:47:21 +00:00
The second form of the function has no return value, as it will always set
the where clause successfully.
2000-11-24 16:40:44 +00:00
\wxheading { See also}
2002-05-27 19:47:21 +00:00
\helpref { wxDbTable::GetWhereClause} { wxdbtablegetwhereclause} ,
2000-11-24 16:40:44 +00:00
\helpref { wxDbTable::SetWhereClause} { wxdbtablesetwhereclause}
2000-08-14 11:44:26 +00:00
\membersection { wxDbTable::operator $ + + $ } \label { wxdbtableplusplus}
\func { bool} { operator $ + + $ } { \void }
2000-11-12 20:05:53 +00:00
Synonym for \helpref { wxDbTable::GetNext} { wxdbtablegetnext}
2000-08-14 11:44:26 +00:00
\wxheading { See also}
\helpref { wxDbTable::GetNext} { wxdbtablegetnext}
\membersection { wxDbTable::operator $ - - $ } \label { wxdbtableminusminus}
\func { bool} { operator $ - - $ } { \void }
2000-11-12 20:05:53 +00:00
Synonym for \helpref { wxDbTable::GetPrev} { wxdbtablegetprev}
2000-08-14 11:44:26 +00:00
\wxheading { See also}
\helpref { wxDbTable::GetPrev} { wxdbtablegetprev}
\section { \class { wxDbTableInf} } \label { wxdbtableinf}
2000-11-24 16:40:44 +00:00
\begin { verbatim}
tableName[0] = 0;
tableType[0] = 0;
tableRemarks[0] = 0;
numCols = 0;
pColInf = NULL;
\end { verbatim}
2002-05-27 19:47:21 +00:00
Currently only used by \helpref { wxDb::GetCatalog} { wxdbgetcatalog} internally
and \helpref { wxDbInf} { wxdbinf} class, but may be used in future releases for
user functions. Contains information describing the table (Name, type, etc).
A pointer to a wxDbColInf array instance is included so a program can create a
\helpref { wxDbColInf} { wxdbcolinf} array instance (using
\helpref { wxDb::GetColumns} { wxdbgetcolumns} )
to maintain all information about the columns of a table in one memory
2000-11-24 16:40:44 +00:00
structure.
2000-08-08 06:11:51 +00:00
2001-02-05 13:33:43 +00:00
Eventually, accessor functions will be added for this class
2002-05-06 13:46:24 +00:00
See the \helpref { database classes overview} { odbcoverview} for
an introduction to using the ODBC classes.
2001-02-05 13:33:43 +00:00
\membersection { wxDbTableInf::Initialize} \label { wxdbtableinfinitialize}
2002-05-27 19:47:21 +00:00
Simply initializes all member variables to a cleared state. Called by
2001-02-05 13:33:43 +00:00
the constructor automatically.
2001-04-25 15:38:00 +00:00
2002-12-08 16:10:50 +00:00
\section { \class { wxDbGridColInfo} } \label { wxdbgridcolinfo}
This class is used to define columns to be shown, names of the columns,
order and type of data, when using \helpref { wxdbGridTableBase} { wxdbgridtablebase} to display
a Table or query in a \helpref { wxGrid} { wxgrid}
See the database grid example in \helpref { wxDbGridTableBase} { wxdbgridtablebase} for
an introduction to using the wxDbGrid classes.
\wxheading { Include files}
<wx/dbgrid.h>
\latexignore { \rtfignore { \wxheading { Members} } }
2003-08-15 16:17:40 +00:00
\membersection { wxDbGridColInfo::wxDbGridColInfo} \label { wxdbgridcolinfoctor}
2002-12-08 16:10:50 +00:00
\func { } { wxDbGridColInfo} { \param { int } { colNo} , \param { wxString } { type} ,
\param { wxString } { title} , \param { wxDbGridColInfo *} { next} }
Default constructor. See the database grid example in \helpref { wxDbGridTableBase} { wxdbgridtablebase} to
see two different ways for adding columns.
\wxheading { Parameters}
\docparam { colNo} { Column number in the \helpref { wxDbTable} { wxdbtable} instance to be used (first column is 0).}
\docparam { type} { Column type ,wxString specifying the grid name for the datatype in this column, or
2003-01-07 15:15:41 +00:00
use wxGRID\_ VALUE\_ DBAUTO to determine the type automatically from the \helpref { wxDbColDef} { wxdbcoldef} definition}
2002-12-08 16:10:50 +00:00
\docparam { title} { The column label to be used in the grid display}
\docparam { next} { A pointer to the next wxDbGridColInfo structure if using one-step
construction, NULL terminates the list. Use Null also if using two step construction.}
See the database grid example in \helpref { wxDbGridTableBase} { wxdbgridtablebase} to
see two different ways for adding columns.
\membersection { wxDbGridColInfo::\destruct { wxDbGridColInfo} }
\func { } { \destruct { wxDbGridColInfo} } { }
Destructor.
\membersection { wxDbGridColInfo::AddColInfo} \label { wxdbgridcolinfoaddcolinfo}
\func { void} { AddColInfo} { \param { int } { colNo} ,
\param { wxString } { type} , \param { wxString } { title} }
Use this member function for adding columns. See the database
grid example in \helpref { wxDbGridTableBase} { wxdbgridtablebase} to
see two different ways for adding columns.
It is important to note that this class is merely a specifier to the \helpref { wxDbGridTableBase} { wxdbgridtablebase}
constructor. Changes made to this datatype after the \helpref { wxDbGridTableBase} { wxdbgridtablebase} is called will
not have any effect.
\wxheading { Parameters}
\docparam { colNo} { Column number in the \helpref { wxDbTable} { wxdbtable} instance to be used (first column is 0).}
\docparam { type} { Column type ,wxString specifying the grid name for the datatype in this column, or
2003-01-07 15:15:41 +00:00
use wxGRID\_ VALUE\_ DBAUTO to determine the type automatically from the \helpref { wxDbColDef} { wxdbcoldef} definition}
2002-12-08 16:10:50 +00:00
\docparam { title} { The column label to be used in the grid display}
\wxheading { Remarks}
As wxDbTable must be defined with to have columns which match those to by a wxDbGridColInfo
info structure as this is the structure which informs the grid of how you want to display your
\helpref { wxDbTable} { wxdbtable} . If no datatype conversion or the referenced column number does not exist the
the behavior is undefined.
2003-08-15 16:17:40 +00:00
See the example at \helpref { wxDbGridColInfo::wxDbGridColInfo} { wxdbgridcolinfoctor} .
2002-12-08 16:10:50 +00:00
\section { \class { wxDbGridTableBase} } \label { wxdbgridtablebase}
You can view a database table in a grid using this class.
If you are deriving your own wxDbTable subclass for your table , then you may consider
overriding GetCol() and SetCol() to provide calculated fields. This does work but care should
be taken when using wxDbGridTableBase in this way.
The constructor and AssignDbTable() call allows you to specify the ownership if the wxDbTable
object pointer. If you tell wxGridTableBase to take ownership , it will delete the passed wxDbTable
when an new on is assigned or wxGridTableBase's destructor is called.
However no checks for aliasing are done so Assign(table,..,true); Assign(table,..,true);
is an error. If you need to requery an table object the preferred way is
that the client keeps ownership.
\wxheading { Derived From}
\helpref { wxGridTableBase} { wxgridtablebase}
\wxheading { Include files}
<wx/dbgrid.h>
\wxheading { Example}
\begin { verbatim}
// First step, let's define wxDbTable
int numColumns = 2;
wxDbTable *table = new wxDbTable (db, tblName, numColumns);
int int_ var;
wxChar string_ name[255];
table->SetColDef (0, "column 0", DB_ DATA_ TYPE_ INTEGER, & int_ var,
2003-01-18 00:16:34 +00:00
SQL_ C_ LONG, sizeof(int_ var), true);
2002-12-08 16:10:50 +00:00
table->SetColDef (1, "column 1", DB_ DATA_ TYPE_ VARCHAR, & string_ name,
2003-01-18 00:16:34 +00:00
SQL_ C_ LONG, sizeof(string_ name), false);
2002-12-08 16:10:50 +00:00
// now let's define columns in the grid
// first way to do it
wxDbGridColInfo *columns;
columns = new wxDbGridColInfo(0, wxGRID_ VALUE_ LONG, "first column",
new wxDbGridColInfo(1, wxGRID_ VALUE_ STRING, "second column",
NULL);
// second way to do it
wxDbGridColInfo *columns;
// first column is special
columns = new wxDbGridColInfo(0, wxGRID_ VALUE_ LONG, "first column", NULL);
// all the rest
columns->AddColInfo (1, wxGRID_ VALUE_ STRING, "second column");
// second way may be better when columns are not known at compile time
// now, let's open the table and make a Query()
table->Open();
// this step is very important
table->SetRowMode (wxDbTable::WX_ ROW_ MODE_ QUERY);
// in the grid we will see only the rows of the result query
m_ dbTable->Query();
2003-01-18 00:16:34 +00:00
wxDbGridTableBase *dbgrid = new wxDbGridTableBase(table, columns, wxUSE_ QUERY, true);
2002-12-08 16:10:50 +00:00
delete columns; // not needed anymore
wxGrid *grid = new wxGrid ( ... );
2003-01-18 00:16:34 +00:00
grid->SetTable(dbgrid, true);
2002-12-08 16:10:50 +00:00
grid->Fit();
\end { verbatim}
\wxheading { Include files}
<wx/dbgrid.h>
\wxheading { Helper classes and data structures}
\membersection { wxDbGridTableBase::wxDbGridTableBase} \label { wxdbgridtablebaseconstr}
\func { } { wxDbGridTableBase} { \param { wxDbTable *} { tab} , \param { wxDbGridColInfo *} { ColInfo} ,
2003-01-18 00:16:34 +00:00
\param { int } { count = wxUSE\_ QUERY} , \param { bool } { takeOwnership = true} }
2002-12-08 16:10:50 +00:00
Constructor.
\wxheading { Parameters}
\docparam { tab} { The database table you want to display. Must be opened and queried before display the grid.
See the example \helpref { above} { wxdbgridtablebase} .}
\docparam { ColInfo} { Columns titles, and other values. See \helpref { wxDbGridColInfo} { wxdbgridcolinfo} .}
2003-01-07 15:15:41 +00:00
\docparam { count} { You can use a query result set (wxUSE\_ QUERY, to use wxDbTable::Count(wxDbTable::Count()
2002-12-08 16:10:50 +00:00
or you can fix the total number of rows (count >= 0) to display, or specify it if you already know the size in avoid calling }
2003-01-18 00:16:34 +00:00
\docparam { takeOwnership} { If true, this class deletes wxDbTable when it stops
referring to it, if false application must
2002-12-08 16:10:50 +00:00
take care of deleting it. }
\membersection { wxDbGridTableBase::ValidateRow} \label { wxdbgridtablebasevalidate}
\func { void} { ValidateRow} { \param { int } { row} }
It ensures that the row data is fetched from the database, and it the wxDbTable local buffer,
the row number passed should be the grid row.
\wxheading { Parameters}
\docparam { row} { Row where validation must be done. }
\membersection { wxDbGridTableBase::UpdateRow} \label { wxdbgridtablebaseupdaterow}
\func { bool} { UpdateRow} { \param { int } { row} }
If row has changed it forces that row to be written back to the database, however support
for detecting whether insert/update is required is currently not in wxDbTable, so this
function is currently unsupported.
\wxheading { Parameters}
\docparam { row} { Row you want to update. }
\membersection { wxDbGridTableBase::AssignDbTable} \label { wxdbgridtablebaseassigndbtable}
2003-01-07 15:15:41 +00:00
\func { bool} { AssignDbTable} { \param { wxDbTable *} { tab} ,\param { int } { count = wxUSE\_ QUERY} ,
2003-01-18 00:16:34 +00:00
\param { bool } { takeOwnership = true} }
2002-12-08 16:10:50 +00:00
Resets the grid for using with a new database table, but using the same columns definition.
This can be useful when re-querying the database and want to see the changes.
\wxheading { Parameters}
\docparam { tab} { Database table you want to assign to the grid. }
2003-01-07 15:15:41 +00:00
\docparam { count} { Number of rows you want to show or wxUSE\_ QUERY for using a query. }
2003-01-18 00:16:34 +00:00
\docparam { takeOwnership} { If false, user must take care of deleting tab after deleting
the wxDbGridTableBase. If true, deletion is made by destructor class. }
2002-12-08 16:10:50 +00:00