1 \section{\class{wxDb
}}\label{wxdb
}
3 A wxDb instance is a connection to an ODBC datasource which may
4 be opened, closed, and re-opened an unlimited number of times. A
5 database connection allows function to be performed directly on the
6 datasource, as well as allowing access to any tables/views defined in
7 the datasource to which the user has sufficient privileges.
9 \wxheading{Include files
}
13 \wxheading{Helper classes and data structures
}
15 The following classes and structs are defined in db.cpp/.h for use with the wxDb class.
17 \begin{itemize
}\itemsep=
0pt
18 \item \helpref{wxDbColFor
}{wxdbcolfor
}
19 \item \helpref{wxDbColInf
}{wxdbcolinf
}
20 \item \helpref{wxDbTableInf
}{wxdbtableinf
}
21 \item \helpref{wxDbInf
}{wxdbinf
}
26 NOTE: In a future release, all ODBC class constants will be prefaced with 'wx'
30 wxDB_PATH_MAX Maximum path length allowed to be passed to
31 the ODBC driver to indicate where the data
34 DB_MAX_COLUMN_NAME_LEN Maximum supported length for the name of a
37 DB_MAX_ERROR_HISTORY Maximum number of error messages retained in
38 the queue before being overwritten by new
41 DB_MAX_ERROR_MSG_LEN Maximum supported length of an error message
42 returned by the ODBC classes
44 DB_MAX_STATEMENT_LEN Maximum supported length for a complete SQL
45 statement to be passed to the ODBC driver
47 DB_MAX_TABLE_NAME_LEN Maximum supported length for the name of a
50 DB_MAX_WHERE_CLAUSE_LEN Maximum supported WHERE clause length that
51 can be passed to the ODBC driver
53 DB_TYPE_NAME_LEN Maximum length of the name of a column's
58 \subsection{Enumerated types
}\label{wxdbenumeratedtypes
}
60 \docparam{enum
{\bf wxDbSqlLogState
}}{sqlLogOFF, sqlLogON
}
62 {\it enum
{\bf wxDBMS
}}
64 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.
69 dbmsSYBASE_ASA // Adaptive Server Anywhere
70 dbmsSYBASE_ASE // Adaptive Server Enterprise
82 See the remarks in
\helpref{wxDb::Dbms
}{wxdbdbms
} for exceptions/issues with each of these database engines.
84 \wxheading{Public member variables
}
86 \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.
}
88 \docparam{int
{\bf wxDb::DB
\_STATUS}}{The last ODBC error/status that occurred on this data connection. Possible codes are:
}
91 DB_ERR_GENERAL_WARNING // SqlState = '
01000'
92 DB_ERR_DISCONNECT_ERROR // SqlState = '
01002'
93 DB_ERR_DATA_TRUNCATED // SqlState = '
01004'
94 DB_ERR_PRIV_NOT_REVOKED // SqlState = '
01006'
95 DB_ERR_INVALID_CONN_STR_ATTR // SqlState = '
01S00'
96 DB_ERR_ERROR_IN_ROW // SqlState = '
01S01'
97 DB_ERR_OPTION_VALUE_CHANGED // SqlState = '
01S02'
98 DB_ERR_NO_ROWS_UPD_OR_DEL // SqlState = '
01S03'
99 DB_ERR_MULTI_ROWS_UPD_OR_DEL // SqlState = '
01S04'
100 DB_ERR_WRONG_NO_OF_PARAMS // SqlState = '
07001'
101 DB_ERR_DATA_TYPE_ATTR_VIOL // SqlState = '
07006'
102 DB_ERR_UNABLE_TO_CONNECT // SqlState = '
08001'
103 DB_ERR_CONNECTION_IN_USE // SqlState = '
08002'
104 DB_ERR_CONNECTION_NOT_OPEN // SqlState = '
08003'
105 DB_ERR_REJECTED_CONNECTION // SqlState = '
08004'
106 DB_ERR_CONN_FAIL_IN_TRANS // SqlState = '
08007'
107 DB_ERR_COMM_LINK_FAILURE // SqlState = '
08S01'
108 DB_ERR_INSERT_VALUE_LIST_MISMATCH // SqlState = '
21S01'
109 DB_ERR_DERIVED_TABLE_MISMATCH // SqlState = '
21S02'
110 DB_ERR_STRING_RIGHT_TRUNC // SqlState = '
22001'
111 DB_ERR_NUMERIC_VALUE_OUT_OF_RNG // SqlState = '
22003'
112 DB_ERR_ERROR_IN_ASSIGNMENT // SqlState = '
22005'
113 DB_ERR_DATETIME_FLD_OVERFLOW // SqlState = '
22008'
114 DB_ERR_DIVIDE_BY_ZERO // SqlState = '
22012'
115 DB_ERR_STR_DATA_LENGTH_MISMATCH // SqlState = '
22026'
116 DB_ERR_INTEGRITY_CONSTRAINT_VIOL // SqlState = '
23000'
117 DB_ERR_INVALID_CURSOR_STATE // SqlState = '
24000'
118 DB_ERR_INVALID_TRANS_STATE // SqlState = '
25000'
119 DB_ERR_INVALID_AUTH_SPEC // SqlState = '
28000'
120 DB_ERR_INVALID_CURSOR_NAME // SqlState = '
34000'
121 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL // SqlState = '
37000'
122 DB_ERR_DUPLICATE_CURSOR_NAME // SqlState = '
3C000'
123 DB_ERR_SERIALIZATION_FAILURE // SqlState = '
40001'
124 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2 // SqlState = '
42000'
125 DB_ERR_OPERATION_ABORTED // SqlState = '
70100'
126 DB_ERR_UNSUPPORTED_FUNCTION // SqlState = 'IM001'
127 DB_ERR_NO_DATA_SOURCE // SqlState = 'IM002'
128 DB_ERR_DRIVER_LOAD_ERROR // SqlState = 'IM003'
129 DB_ERR_SQLALLOCENV_FAILED // SqlState = 'IM004'
130 DB_ERR_SQLALLOCCONNECT_FAILED // SqlState = 'IM005'
131 DB_ERR_SQLSETCONNECTOPTION_FAILED // SqlState = 'IM006'
132 DB_ERR_NO_DATA_SOURCE_DLG_PROHIB // SqlState = 'IM007'
133 DB_ERR_DIALOG_FAILED // SqlState = 'IM008'
134 DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL // SqlState = 'IM009'
135 DB_ERR_DATA_SOURCE_NAME_TOO_LONG // SqlState = 'IM010'
136 DB_ERR_DRIVER_NAME_TOO_LONG // SqlState = 'IM011'
137 DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR // SqlState = 'IM012'
138 DB_ERR_TRACE_FILE_ERROR // SqlState = 'IM013'
139 DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS // SqlState = 'S0001'
140 DB_ERR_TABLE_NOT_FOUND // SqlState = 'S0002'
141 DB_ERR_INDEX_ALREADY_EXISTS // SqlState = 'S0011'
142 DB_ERR_INDEX_NOT_FOUND // SqlState = 'S0012'
143 DB_ERR_COLUMN_ALREADY_EXISTS // SqlState = 'S0021'
144 DB_ERR_COLUMN_NOT_FOUND // SqlState = 'S0022'
145 DB_ERR_NO_DEFAULT_FOR_COLUMN // SqlState = 'S0023'
146 DB_ERR_GENERAL_ERROR // SqlState = 'S1000'
147 DB_ERR_MEMORY_ALLOCATION_FAILURE // SqlState = 'S1001'
148 DB_ERR_INVALID_COLUMN_NUMBER // SqlState = 'S1002'
149 DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE // SqlState = 'S1003'
150 DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE // SqlState = 'S1004'
151 DB_ERR_OPERATION_CANCELLED // SqlState = 'S1008'
152 DB_ERR_INVALID_ARGUMENT_VALUE // SqlState = 'S1009'
153 DB_ERR_FUNCTION_SEQUENCE_ERROR // SqlState = 'S1010'
154 DB_ERR_OPERATION_INVALID_AT_THIS_TIME // SqlState = 'S1011'
155 DB_ERR_INVALID_TRANS_OPERATION_CODE // SqlState = 'S1012'
156 DB_ERR_NO_CURSOR_NAME_AVAIL // SqlState = 'S1015'
157 DB_ERR_INVALID_STR_OR_BUF_LEN // SqlState = 'S1090'
158 DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE // SqlState = 'S1091'
159 DB_ERR_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1092'
160 DB_ERR_INVALID_PARAM_NO // SqlState = 'S1093'
161 DB_ERR_INVALID_SCALE_VALUE // SqlState = 'S1094'
162 DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE // SqlState = 'S1095'
163 DB_ERR_INF_TYPE_OUT_OF_RANGE // SqlState = 'S1096'
164 DB_ERR_COLUMN_TYPE_OUT_OF_RANGE // SqlState = 'S1097'
165 DB_ERR_SCOPE_TYPE_OUT_OF_RANGE // SqlState = 'S1098'
166 DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE // SqlState = 'S1099'
167 DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1100'
168 DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1101'
169 DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE // SqlState = 'S1103'
170 DB_ERR_INVALID_PRECISION_VALUE // SqlState = 'S1104'
171 DB_ERR_INVALID_PARAM_TYPE // SqlState = 'S1105'
172 DB_ERR_FETCH_TYPE_OUT_OF_RANGE // SqlState = 'S1106'
173 DB_ERR_ROW_VALUE_OUT_OF_RANGE // SqlState = 'S1107'
174 DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE // SqlState = 'S1108'
175 DB_ERR_INVALID_CURSOR_POSITION // SqlState = 'S1109'
176 DB_ERR_INVALID_DRIVER_COMPLETION // SqlState = 'S1110'
177 DB_ERR_INVALID_BOOKMARK_VALUE // SqlState = 'S1111'
178 DB_ERR_DRIVER_NOT_CAPABLE // SqlState = 'S1C00'
179 DB_ERR_TIMEOUT_EXPIRED // SqlState = 'S1T00'
182 \docparam{struct
{\bf wxDb::dbInf
}}{This structure is internal to the
183 wxDb class and contains details of the ODBC datasource that the current
184 instance of the wxDb is connected to in its members. When the datasource
185 is opened, all of the information contained in the dbInf structure is
186 queried from the datasource. This information is used almost exclusively
187 within the ODBC class library. Where there may be a need for particular
188 portions of this information outside of the class library, member
190 \helpref{wxDbTable::IsCursorClosedOnCommit
}{wxdbtableiscursorclosedoncommit
})
191 have been added for ease of use.
}
194 char dbmsName
[40] - Name of the dbms product
195 char dbmsVer
[64] - Version # of the dbms product
196 char driverName
[40] - Driver name
197 char odbcVer
[60] - ODBC version of the driver
198 char drvMgrOdbcVer
[60] - ODBC version of the driver manager
199 char driverVer
[60] - Driver version
200 char serverName
[80] - Server Name, typically a connect string
201 char databaseName
[128] - Database filename
202 char outerJoins
[2] - Does datasource support outer joins
203 char procedureSupport
[2] - Does datasource support stored
205 UWORD maxConnections - Maximum # of connections datasource
207 UWORD maxStmts - Maximum # of HSTMTs per HDBC
208 UWORD apiConfLvl - ODBC API conformance level
209 UWORD cliConfLvl - Is datasource SAG compliant
210 UWORD sqlConfLvl - SQL conformance level
211 UWORD cursorCommitBehavior - How cursors are affected on db commit
212 UWORD cursorRollbackBehavior - How cursors are affected on db
214 UWORD supportNotNullClause - Does datasource support NOT NULL
216 char supportIEF
[2] - Integrity Enhancement Facility (Ref.
218 UDWORD txnIsolation - Transaction isolation level supported by
220 UDWORD txnIsolationOptions - Transaction isolation level options
222 UDWORD fetchDirections - Fetch directions supported
223 UDWORD lockTypes - Lock types supported in SQLSetPos
224 UDWORD posOperations - Position operations supported in
226 UDWORD posStmts - Position statements supported
227 UDWORD scrollConcurrency - Scrollable cursor concurrency options
229 UDWORD scrollOptions - Scrollable cursor options supported
230 UDWORD staticSensitivity - Can additions/deletions/updates be
232 UWORD txnCapable - Indicates if datasource supports
234 UDWORD loginTimeout - Number seconds to wait for a login
238 \docparam{char
{\bf wxDb::errorList
}[DB_MAX_ERROR_HISTORY
][DB_MAX_ERROR_MSG_LEN
]}{The last n ODBC errors that have occurred on this database connection.
}
240 \docparam{char
{\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.
}
242 \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. Used for reporting ODBC errors.
}
244 \docparam{wxChar
{\bf wxDb::sqlState
}[20]}{Set by wxDb::TranslateSqlState(). Indicates the error state after a failed ODBC operation. Used for reporting ODBC errors.
}
248 Default cursor scrolling is defined by wxODBC_FWD_ONLY_CURSORS in setup.h
249 when the wxWindows library is built. This behavior can be overridden when
250 an instance of a wxDb is created (see
\helpref{wxDb constructor
}{wxdbconstr
}).
251 Default setting of this value TRUE, as not all databases/drivers support
252 both types of cursors.
256 \helpref{wxDbColFor
}{wxdbcolfor
},
\helpref{wxDbColInf
}{wxdbcolinf
},
\helpref{wxDbTable
}{wxdbtable
},
\helpref{wxDbTableInf
}{wxdbtableinf
},
\helpref{wxDbInf
}{wxdbinf
}
258 \subsection{Associated non-class functions
}\label{wxdbfunctions
}
260 The following functions are used in conjunction with the wxDb class.
262 \func{wxDb *
}{wxDbGetConnection
}{\param{wxDbConnectInf *
}{pDbConfig
},
\param{bool
}{FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS
}}
266 This function is used to request a "new" wxDb instance for use by the program.
267 The wxDb instance returned is also opened (see
\helpref{wxDb::Open
}{wxdbopen
}).
269 This function (along with wxDbFreeConnection() and wxDbCloseConnection())
270 maintain a cached of wxDb instances for user/re-use by a program. When a
271 program needs a wxDb instance, it may call this function to obtain a wxDb
272 instance. If there is a wxDb instance in the cache that is currently unused
273 that matches the connection requirements specified in
{\it'pDbConfig'
} then
274 that cached connection is marked as no longer being free, and a pointer to
275 the wxDb instance is returned.
277 If there are no connections available in the cache that meet the requirements
278 given in
{\it'pDbConfig'
}, then a new wxDb instance is created to connect
279 to the datasource specified in
{\it'pDbConfig'
} using the userID and password
280 given in
{\it'pDbConfig'
}.
282 NOTE: The caching routine also uses the
\helpref{wxDb::Open
}{wxdbopen
}
283 connection datatype copying code. If the call to wxDbGetConnection()
284 requests a connection to a datasource, and there is not one available in the
285 cache, a new connection is created. But when the connection is opened,
286 instead of polling the datasource over again for its datatypes, if a
287 connection to the same datasource (using the same userID/password) has already
288 been done previously, the new connection skips querying the datasource for
289 its datatypes, and uses the same datatypes determined previously by the
290 other connection(s) for that same datasource. This cuts down greatly on
291 network traffic, database load, and connection creation time.
293 When the program is done using a connection created through a call to
294 wxDbGetConnection(), the program shoudl call wxDbFreeConnection() to release
295 the wxDb instance back to the cache. DO NOT DELETE THE wxDb INSTANCE!
296 Deleting the wxDb instance returned can cause a crash/memory corruption
297 later in the program when the cache is cleaned up.
299 When exiting the program, call wxDbCloseConnections() to close all the
300 cached connections created by calls to wxDbGetConnection().
303 \func{bool
}{wxDbFreeConnection
}{\param{wxDb *
}{pDb
}}
307 Searches the list of cached database connections connection for one matching
308 the passed in wxDb instance. If found, that cached connection is freed.
310 Freeing a connection means that it is marked as available (free) in the
311 cache of connections, so that a call to
\helpref{wxDbGetConnection
}{wxdbfunctions
}
312 is able to return a pointer to the wxDb instance for use. Freeing a
313 connection does NOT close the connection, it only makes the connection
317 \func{void
}{wxDbCloseConnections
}{\void}
321 Closes all cached connections that have been made through use of the
322 \helpref{wxDbGetConnection
}{wxdbfunctions
} function.
324 NOTE: These connections are closed regardless of whether they are in use
325 or not. This function should only be called after the program has
326 finished using the connections and all wxDbTable instances that use any of
327 the connections have been closed.
329 This function performs a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
330 on the connection before closing it to commit any changes tht are still
331 pending, as well as to avoid any function sequence errors upon closing
335 \func{int
}{wxDbConnectionsInUse
}{\void}
339 Returns a count of how many database connections are currently free ( not
340 being used) that have been cached through use of the
\helpref{wxDbGetConnection
}{wxdbfunctions
}
344 \func{bool
}{wxDbSqlLog
}{\param{wxDbSqlLogState
}{state
},
\param{const wxChar *
}{filename = SQL_LOG_FILENAME
}}
348 This function sets the sql log state for all open wxDb objects
351 \func{bool
}{wxDbGetDataSource
}{\param{HENV
}{henv
},
\param{char *
}{Dsn
},
\param{SWORD
}{DsnMax
},
\param{char *
}{DsDesc
},
\param{SWORD
}{DsDescMax
},
\param{UWORD
}{direction = SQL_FETCH_NEXT
}}
355 This routine queries the ODBC driver manager for a list of available
356 datasources. Repeatedly call this function to obtain all the datasources
357 available through the ODBC driver manager on the current workstation.
359 wxStringList strList;
361 while (wxDbGetDataSource(DbConnectInf.Henv, Dsn, SQL_MAX_DSN_LENGTH+
1, DsDesc,
255))
365 \latexignore{\rtfignore{\wxheading{Members
}}}
367 \membersection{wxDb::wxDb
}\label{wxdbconstr
}
373 \func{}{wxDb
}{\param{HENV &
}{aHenv
},
\param{bool
}{FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS
}}
375 Constructor, used to create an ODBC connection to a datasource.
377 \wxheading{Parameters
}
379 \docparam{aHenv
}{Environment handle used for this connection.
}
381 \docparam{FwdOnlyCursors
}{Will cursors created for use with this datasource connection only allow forward scrolling cursors.
}
385 This is the constructor for the wxDb class. The wxDb object must
386 be created and opened before any database activity can occur.
391 wxDbConnectInf ConnectInf;
392 ....Set values for member variables of ConnectInf here
394 wxDb sampleDB(ConnectInf.Henv);
395 if (!sampleDB.Open(ConnectInf.Dsn, ConnectInf.Uid, ConnectInf.AuthStr))
397 // Error opening datasource
403 \helpref{wxDbGetConnection
}{wxdbfunctions
},
406 \membersection{wxDb::Catalog
}\label{wxdbcatalog
}
408 \func{bool
}{Catalog
}{\param{char *
}{ userID
},
\param{char *
}{fileName = SQL_CATALOG_FILENAME
}}
410 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.
412 \wxheading{Parameters
}
414 \docparam{userID
}{Database user name to use in accessing the database. All tables to which this user has rights will be evaluated in the catalog.
}
416 \docparam{fileName
}{{\it OPTIONAL
}. Name of the text file to create and write
417 the DB catalog to. Default is SQL_CATALOG_FILENAME.
}
419 \wxheading{Return value
}
421 Returns TRUE if the catalog request was successful, or FALSE if there was some
422 reason that the catalog could not be generated.
427 ============== ============== ================ ========= =======
428 TABLE NAME COLUMN NAME DATA TYPE PRECISION LENGTH
429 ============== ============== ================ ========= =======
430 EMPLOYEE RECID (
0008)NUMBER
15 8
431 EMPLOYEE USER_ID (
0012)VARCHAR2
13 13
432 EMPLOYEE FULL_NAME (
0012)VARCHAR2
26 26
433 EMPLOYEE PASSWORD (
0012)VARCHAR2
26 26
434 EMPLOYEE START_DATE (
0011)DATE
19 16
438 \membersection{wxDb::Close
}\label{wxdbclose
}
440 \func{void
}{Close
}{\void}
442 Closes the database connection.
446 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.
448 Any wxDbTable instances which use this connection must be deleted before closing the database connection.
453 // Commit any open transactions on the datasource
454 sampleDB.CommitTrans();
456 // Delete any remaining wxDbTable objects allocated with new
459 // Close the wxDb connection when finished with it
462 // Free Environment Handle that ODBC uses
464 // Be certain that no wxDb instances still exist
465 // that were created using this handle! If you
466 // use wxDbGetConnection() to get all the wxDb
467 // instances, you can use wxDbConnectionsInUse()
468 // to find out if any connections have not been
469 // closed before calling this
470 if (SQLFreeEnv(Db.Henv) != SQL_SUCCESS)
472 // Error freeing environment handle
477 \membersection{wxDb::CommitTrans
}\label{wxdbcommittrans
}
479 \func{bool
}{CommitTrans
}{\void}
481 Permanently "commits" changes (insertions/deletions/updates) to the database.
483 \wxheading{Return value
}
485 Returns TRUE if the commit was successful, or FALSE if the commit failed.
489 Transactions begin implicitly as soon as you make a change to the database
490 with an insert/update/delete, or any other direct SQL command that performs
491 one of these operations against the datasource.
492 At any time thereafter, to save the changes to disk permanently, "commit"
493 them by calling this function.
495 Calling this member function commits ALL open transactions on this ODBC
496 connection. For example, if three different wxDbTable instances used the
497 same connection to the datasource, commiting changes made on one of those
498 wxDbTable instances commits any pending transactions on all three wxDbTable
501 Until a call to wxDb::CommitTrans() is made, no other user or cursor is able
502 to see any changes made to the row(s) that have been inserted/modifed/deleted.
505 \wxheading{Special Note :
{\it Cursors
} }
507 \normalbox{It is important to understand that different database/ODBC driver combinations handle
508 transactions differently. One thing in particular that you must pay attention to is
509 cursors, in regard to transactions. Cursors are what allow you to scroll through
510 records forward and backward and to manipulate records as you scroll through them.
511 When you issue a query, a cursor is created behind the scenes. The cursor keeps track
512 of the query and keeps track of the current record pointer. After you commit or
513 rollback a transaction, the cursor may be closed automatically. This is database
514 dependent, and with some databases this behavior can be controlled through
515 management functions. This means you would need to
516 requery the datasource before you can perform any additional work using this
517 cursor. This is only necessary however if the datasource closes the cursor after a
518 commit or rollback. Use the
\helpref{wxDbTable::IsCursorClosedOnCommit
}{wxdbtableiscursorclosedoncommit
} member function to
519 determine the datasource's transaction behavior. Note, in many situations
520 it is very inefficient to assume the cursor is closed and always requery. This could put
521 a significant, unnecessary load on datasources that leave the cursors open after a
525 \membersection{wxDb::CreateView
}\label{wxdbcreateviews
}
527 \func{bool
}{CreateView
}{\param{char *
}{ viewName
},
\param{char *
}{ colList
},
\param{char *
}{pSqlStmt
}}
529 Creates a SQL VIEW of one or more tables in a single datasource. Note that
530 this function will only work against databases which support views (currently
531 only Oracle as of November
21 2000).
533 \wxheading{Parameters
}
535 \docparam{viewName
}{The name of the view. e.g. PARTS_V
}
537 \docparam{colList
}{{\it OPTIONAL
} Pass in a comma delimited list of column
538 names if you wish to explicitly name each column in the result set. If not
539 desired, pass in an empty string and the column names from the associated
540 table(s) will be used.
}
542 \docparam{pSqlStmt
}{Pointer to the select statement portion of the CREATE VIEW statement. Must be a complete, valid SQL SELECT statement.
}
546 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 any other table in the database.
548 NOTE: Views are not available with all datasources. Oracle is one example of a datasouce which does support views.
553 // Incomplete code sample
554 db.CreateView("PARTS_SD1", "PN, PD, QTY",
555 "SELECT PART_NO, PART_DESC, QTY_ON_HAND *
1.1 FROM PARTS \
556 WHERE STORAGE_DEVICE =
1");
558 // PARTS_SD1 can now be queried just as if it were a data table.
559 // e.g. SELECT PN, PD, QTY FROM PARTS_SD1
563 \membersection{wxDb::Dbms
}\label{wxdbdbms
}
565 \func{wxDBMS
}{Dbms
}{\void}
569 The return value will be of the enumerated type wxDBMS. This enumerated
570 type contains a list of all the currently tested and supported databases.
572 Additional databases may work with these classes, but the databases
573 returned by this function have been tested and confirmed to work with
576 Possible values returned by this function can be viewed in the
577 \helpref{Enumerated types
}{wxdbenumeratedtypes
} section of wxDb.
579 There are known issues with conformance to the ODBC standards with several
580 datasources supported by the wxWindows ODBC classes. Please see the overview
581 for specific details on which datasource have which issues.
583 \wxheading{Return value
}
585 The return value will indicate which of the supported datasources is
586 currently connected to by this connection. In the event that the
587 datasource is not recognized, a value of 'dbmsUNIDENTIFIED' is returned.
590 \membersection{wxDb::DispAllErrors
}\label{wxdbdispallerrors
}
592 \func{bool
}{DispAllErrors
}{\param{HENV
}{ aHenv
},
{\param}{HDBC
}{ aHdbc = SQL_NULL_HDBC
},
{\param}{HSTMT
}{ aHstmt = SQL_NULL_HSTMT
}}
594 Used to log all database errors that occurred as a result of an executed
595 database command. This logging is automatic and also includes debug logging
596 when compiled in debug mode via
\helpref{wxLogDebug
}{wxlogdebug
}. If logging
597 is turned on via
\helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}, then an
598 entry is also logged to the defined log file.
600 \wxheading{Parameters
}
602 \docparam{aHenv
}{Handle to the ODBC environment.
}
604 \docparam{aHdbc
}{Handle to the ODBC connection. Pass this in if the ODBC function call that erred required a hdbc or hstmt argument.
}
606 \docparam{AHstmt
}{Handle to the ODBC statement being executed against. Pass this in if the ODBC function call that erred out required a hstmt argument.
}
610 This member function will log all of the ODBC error messages for the last
611 ODBC function call that was made. This function is normally used internally
612 within the ODBC class library, but can be used programmatically after calling
613 ODBC functions directly (i.e. SQLFreeEnv()).
615 \wxheading{Return value
}
617 The function always returns FALSE, so a call to this function can be made
618 in the return statement of a code block in the event of a failure to
619 perform an action (see the example below).
623 \helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}, wxDbSqlLog
628 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
629 // Display all ODBC errors for this stmt
630 return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
634 \membersection{wxDb::DispNextError
}\label{wxdbdispnexterror
}
636 \func{void
}{DispNextError
}{\void}
640 This function is normally used internally within the ODBC class library.
641 It could be used programmatically after calling ODBC functions directly. This
642 function works in conjunction with
\helpref{wxDb::GetNextError
}{wxdbgetnexterror
} when errors (or
643 sometimes informational messages) returned from ODBC need to be analyzed
644 rather than simply displaying them as an error. GetNextError() retrieves
645 the next ODBC error from the ODBC error queue. The wxDb member variables
646 "sqlState", "nativeError" and "errorMsg" could then be evaluated. To
647 display the error retrieved, DispNextError() could then be called.
648 The combination of GetNextError() and DispNextError() can be used to
649 iteratively step through the errors returned from ODBC evaluating each
650 one in context and displaying the ones you choose.
655 // Drop the table before attempting to create it
656 sprintf(sqlStmt, "DROP TABLE
%s", tableName);
657 // Execute the drop table statement
658 if (SQLExecDirect(hstmt,(UCHAR FAR *)sqlStmt,SQL_NTS) != SQL_SUCCESS)
660 // Check for sqlState = S0002, "Table or view not found".
661 // Ignore this error, bomb out on any other error.
662 pDb->GetNextError(henv, hdbc, hstmt);
663 if (strcmp(pDb->sqlState, "S0002"))
665 pDb->DispNextError(); // Displayed error retrieved
666 pDb->DispAllErrors(henv, hdbc, hstmt); // Display all other errors, if any
667 pDb->RollbackTrans(); // Rollback the transaction
668 CloseCursor(); // Close the cursor
669 return(FALSE); // Return Failure
675 \membersection{wxDb::DropView
}\label{wxdbdropview
}
677 \func{bool
}{DropView
}{\param{const char *
}{viewName
}}
679 Drops the data table view named in 'viewName'.
681 \wxheading{Parameters
}
683 \docparam{viewName
}{Name of the view to be dropped.
}
687 If the view does not exist, this function will return TRUE. Note that views are not supported with all datasources.
689 \membersection{wxDb::ExecSql
}\label{wxdbexecsql
}
691 \func{bool
}{ExecSql
}{\param{char *
}{pSqlStmt
}}
693 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.
695 \wxheading{Parameters
}
697 \docparam{pSqlStmt
}{Pointer to the SQL statement to be executed.
}
701 This member extends the wxDb class and allows you to build and execute ANY VALID
702 SQL statement against the datasource. This allows you to extend the class
703 library by being able to issue any SQL statement that the datasource is capable
708 \helpref{wxDb::GetData
}{wxdbgetdata
},
\helpref{wxDb::GetNext
}{wxdbgetnext
}
711 \membersection{wxDb::GetCatalog
}\label{wxdbgetcatalog
}
713 \func{wxDbInf *
}{GetCatalog
}{\param{char *
}{userID
}}
715 Returns a
\helpref{wxDbInf
}{wxdbinf
} pointer that points to the catalog
716 (datasource) name, schema, number of tables accessible to the current user,
717 and a wxDbTableInf pointer to all data pertaining to all tables in the users
720 \wxheading{Parameters
}
722 \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:
}
725 userID == NULL ... UserID is ignored (DEFAULT)
726 userID == "" ... UserID set equal to 'this->uid'
727 userID != "" ... UserID set equal to 'userID'
732 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.
734 \membersection{wxDb::GetColumnCount
}\label{wxdbgetcolumncount
}
736 \func{int
}{GetColumnCount
}{\param{char *
}{tableName
},
\param{const char *
}{userID
}}
738 \wxheading{Parameters
}
740 \docparam{tableName
}{The table name you wish to obtain column information about.
}
742 \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:
}
745 userID == NULL ... UserID is ignored (DEFAULT)
746 userID == "" ... UserID set equal to 'this->uid'
747 userID != "" ... UserID set equal to 'userID'
750 \wxheading{Return value
}
752 Returns a count of how many columns are in the specified table. If an error
753 occurs retrieving the number of columns, this function will return a -
1.
755 \membersection{wxDb::GetColumns
}\label{wxdbgetcolumns
}
757 \func{wxDbColInf *
}{GetColumns
}{\param{char *
}{tableName
},
\param{int *
}{numCols
},
\param{const char *
}{userID=NULL
}}
759 \func{wxDbColInf *
}{GetColumns
}{\param{char *
}{tableName
[]},
\param{const char *
}{userID
}}
761 \wxheading{Parameters
}
763 \docparam{tableName
}{The table name you wish to obtain column information about.
}
764 \docparam{numCols
}{Pointer to an integer which will hold a count of the number of columns returned by this function
}
765 \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.
}
766 \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:
}
769 userID == NULL ... UserID is ignored (DEFAULT)
770 userID == "" ... UserID set equal to 'this->uid'
771 userID != "" ... UserID set equal to 'userID'
774 \wxheading{Return value
}
776 This function returns a pointer to an array of
\helpref{wxDbColInf
}{wxdbcolinf
}
777 structures, allowing you to obtain information regarding the columns of the
778 named table(s). If no columns were found, or an error occurred, this pointer
781 THE CALLING FUNCTION IS RESPONSIBLE FOR DELETING THE
{\it wxDbColInf
} MEMORY WHEN IT IS
784 \normalbox{ALL column bindings associated with this wxDb instance are unbound
785 by this function, including those used by any wxDbTable instances that use
786 this wxDb instance. This function should use its own wxDb instance
787 to avoid undesired unbinding of columns.
}
791 \helpref{wxDbColInf
}{wxdbcolinf
}
796 char *tableList
[] =
{"PARTS",
0};
797 wxDbColInf *colInf = pDb->GetColumns(tableList);
800 // Use the column inf
802 // Destroy the memory
808 \membersection{wxDb::GetData
}\label{wxdbgetdata
}
810 \func{bool
}{GetData
}{\param{UWORD
}{ colNo
},
\param{SWORD
}{ cType
},
\param{PTR
}{ pData
},
\param{SDWORD
}{ maxLen
},
\param{SDWORD FAR *
}{ cbReturned
} }
812 Used to retrieve result set data without binding column values to memory variables (i.e. not using a wxDbTable instance to access table data).
814 \wxheading{Parameters
}
816 \docparam{colNo
}{Ordinal number of the desired column in the result set to be returned.
}
817 \docparam{cType
}{The C data type that is to be returned. See a partial list in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}}
818 \docparam{pData
}{Memory buffer which will hold the data returned by the call to this function.
}
819 \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 value.
}
820 \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 wxDb::GetData() call has failed.
}
824 \helpref{wxDb::GetNext
}{wxdbgetnext
},
\helpref{wxDb::ExecSql
}{wxdbexecsql
}
832 sqlStmt = "SELECT SUM(REQUIRED_QTY - PICKED_QTY) FROM ORDER_TABLE WHERE \
833 PART_RECID =
1450 AND REQUIRED_QTY > PICKED_QTY";
836 if (!pDb->ExecSql(sqlStmt.c_str()))
842 // Request the first row of the result set
849 // Read column
#1 of the row returned by the call to ::GetNext()
850 // and return the value in 'reqQty'
851 if (!pDb->GetData(
1, SQL_C_ULONG, &reqQty,
0, &cb))
857 // Check for a NULL result
858 if (cb == SQL_NULL_DATA)
864 When requesting multiple columns to be returned from the result set (for example, the SQL query
865 requested
3 columns be returned), the calls to this function must request the columns in ordinal
866 sequence (
1,
2,
3 or
1,
3 or
2,
3).
868 \membersection{wxDb::GetDatabaseName
}\label{wxdbgetdatabasename
}
870 \func{const char *
}{GetDatabaseName
}{\void}
872 Returns the name of the database engine.
874 \membersection{wxDb::GetDatasourceName
}\label{wxdbgetdatasourcename
}
876 \func{const char *
}{GetDatasourceName
}{\void}
878 Returns the ODBC datasource name.
880 \membersection{wxDb::GetHDBC
}\label{wxdbgethdbc
}
882 \func{HDBC
}{GetHDBC
}{\void}
884 Returns the ODBC handle to the database connection.
886 \membersection{wxDb::GetHENV
}\label{wxdbgethenv
}
888 \func{HENV
}{GetHENV
}{\void}
890 Returns the ODBC environment handle.
892 \membersection{wxDb::GetHSTMT
}\label{wxdbgethstmt
}
894 \func{HSTMT
}{GetHSTMT
}{\void}
896 Returns the ODBC statement handle associated with this database connection.
898 \membersection{wxDb::GetKeyFields
}\label{wxdbgetkeyfields
}
900 \func{int
}{GetKeyFields
}{\param{char *
}{tableName
},
\param{wxDbColInf *
}{colInf
},
\param{int
}{nocols
}}
902 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.
904 This function is primarily for use by the
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
} function, but may be called if desired from the client application.
906 \wxheading{Parameters
}
908 \docparam{tableName
}{Name of the table for which the columns will be evaluated as to their inclusion in any indexes.
}
909 \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.
}
910 \docparam{nocols
}{Number of columns defined in the instance of colInf.
}
912 \wxheading{Return value
}
914 Currently always returns TRUE.
918 \helpref{wxDbColInf
}{wxdbcolinf
},
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
}
920 \membersection{wxDb::GetNext
}\label{wxdbgetnext
}
922 \func{bool
}{GetNext
}{\void}
924 Called after executing a query, this function requests the next row
925 in the result set after the current position of the cursor.
929 \helpref{wxDb::ExecSql
}{wxdbexecsql
},
\helpref{wxDb::GetData
}{wxdbgetdata
}
931 \membersection{wxDb::GetNextError
}\label{wxdbgetnexterror
}
933 \func{bool
}{GetNextError
}{\param{HENV
}{ aHenv
},
\param{HDBC
}{ aHdbc = SQL_NULL_HDBC
},
\param{HSTMT
}{ aHstmt = SQL_NULL_HSTMT
}}
935 \wxheading{Parameters
}
937 \docparam{aHenv
}{A handle to the ODBC environment.
}
938 \docparam{aHdbc
}{{\it OPTIONAL.
} A handle to the ODBC connection. Pass this in if the ODBC function call that
939 erred out required a hdbc or hstmt argument.
}
940 \docparam{AHstmt
}{{\it OPTIONAL.
}A handle to the ODBC statement being executed against. Pass this in if the
941 ODBC function call that erred out requires a hstmt argument.
}
945 \helpref{wxDb::DispNextError
}{wxdbdispnexterror
},
\helpref{wxDb::DispAllErrors
}{wxdbdispallerrors
}
950 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
952 // Display all ODBC errors for this stmt
953 return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
958 \membersection{wxDb::GetPassword
}\label{wxdbgetpassword
}
960 \func{const char *
}{GetPassword
}{\void}
962 Returns the password used to establish this connection to the datasource.
965 \membersection{wxDb::GetTableCount
}\label{wxdbgettablecount
}
967 \func{int
}{GetTableCount
}{\void}
969 Returns the number of wxDbTable() instances currently using this datasource connection.
972 \membersection{wxDb::GetUsername
}\label{wxdbgetusername
}
974 \func{const char *
}{GetUsername
}{\void}
976 Returns the user name (uid) used to establish this connection to the datasource.
979 \membersection{wxDb::Grant
}\label{wxdbgrant
}
981 \func{bool
}{Grant
}{\param{int
}{privileges
},
\param{char *
}{tableName
},
\param{char *
}{userList = "PUBLIC"
}}
983 Use this member function to GRANT privileges to users for accessing tables in the datasource.
985 \wxheading{Parameters
}
987 \docparam{privileges
}{Use this argument to select which privileges you want to grant. Pass DB_GRANT_ALL to grant all privileges. To grant individual privileges pass one or more of the following OR'd together:
}
994 DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT |
995 DB_GRANT_UPDATE | DB_GRANT_DELETE
998 \docparam{tableName
}{The name of the table you wish to grant privileges on.
}
999 \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.
}
1003 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.
1005 The currently logged in user must have sufficient grantor privileges for this
1006 function to be able to successfully grant the indicated privileges.
1011 db.Grant(DB_GRANT_SELECT | DB_GRANT_INSERT, "PARTS", "mary, sue");
1015 \membersection{wxDb::IsFwdOnlyCursors
}\label{wxdbisfwdonlycursors
}
1017 \func{bool
}{IsFwdOnlyCursors
}{\void}
1019 This setting indicates whether this database connection was created
1020 as being capable of using only forward scrolling cursors.
1022 This function does NOT indicate if the ODBC driver or datasource supports
1023 backward scrolling cursors. There is no standard way of detecting if the
1024 driver or datasource can support backward scrolling cursors.
1026 If a wxDb instance was created as being capable of only forward scrolling
1027 cursors, then even if the datasource and ODBC driver support backward
1028 scrolling cursors, tables using this database connection would only be able
1029 to use forward scrolling cursors.
1031 The default setting of whether a wxDb connection to a database allows
1032 forward-only or also backward scrolling cursors is defined in setup.h by the
1033 value of wxODBC_FWD_ONLY_CURSORS. This default setting can be overridden
1034 when the wxDb connection is initially created (see
1035 \helpref{wxDb constructor
}{wxdbconstr
} and
\helpref{wxDbGetConnection
}{wxdbfunctions
}).
1037 \wxheading{Return value
}
1039 Returns TRUE if this datasource connection is defined as using only forward
1040 scrolling cursors, or FALSE if the connection is defined as being allowed to
1041 use backward scrolling cursors and their associated functions (see note above).
1045 Added as of wxWindows v2.4 release, this function is a renamed version of
1046 wxDb::FwdOnlyCursors() to match the normal wxWindows naming conventions for
1047 class member functions.
1049 This function is not available in versions prior to v2.4. You should
1050 use
\helpref{wxDb::FwdOnlyCursors
}{wxdbfwdonlycursors
} for wxWindows
1051 versions prior to
2.4.
1053 \wxheading{See also
}
1055 \helpref{wxDb constructor
}{wxdbconstr
},
\helpref{wxDbGetConnection
}{wxdbfunctions
}
1058 \membersection{wxDb::IsOpen
}\label{wxdbisopen
}
1060 \func{bool
}{IsOpen
}{\void}
1062 Indicates whether the database connection to the datasource is currently
1067 This function may indicate that the database connection is open, even if
1068 the call to
\helpref{wxDb::Open
}{wxdbopen
} may have failed to fully
1069 initialize the connection correctly. The connection to the database
1070 {\it is
} open and can be used via the direct SQL commands, if this
1071 function returns TRUE. Other functions which depend on the
1072 \helpref{wxDb::Open
}{wxdbopen
} to have completed correctly may not function
1073 as expected. The return result from
\helpref{wxDb::Open
}{wxdbopen
} is the
1074 only way to know if complete initialization of this wxDb connection was
1075 successful or not. See
\helpref{wxDb::Open
}{wxdbopen
} for more details on
1076 partial failures to open a connection instance.
1079 \membersection{wxDb::LogError
}\label{wxdblogerror
}
1081 \func{void
}{LogError
}{\param{const char *
}{errMsg
} \param{const char *
}{SQLState=NULL
}}
1083 \docparam{errMsg
}{Free-form text to display describing the error/text to be logged.
}
1084 \docparam{SQLState
}{{\it OPTIONAL.
} Native SQL state error. Default is
0.
}
1088 Calling this function will enter a log message in the error list maintained
1089 for the database connection. This log message is free form and can be
1090 anything the programmer wants to enter in the error list.
1092 If SQL logging is turned on, the call to this function will also log the
1093 text into the SQL log file.
1095 \wxheading{See also
}
1097 \helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
}
1100 \membersection{wxDb::Open
}\label{wxdbopen
}
1102 \func{bool
}{Open
}{\param{char *
}{Dsn
},
\param{char *
}{Uid
},
\param{char *
}{AuthStr
}}
1104 \func{bool
}{Open
}{\param{wxDb *
}{copyDb
}}
1106 Opens a connection to the datasource, sets certain behaviors of the datasource
1107 to confirm to the accepted behaviors (e.g. cursor position maintained on
1108 commits), and queries the datasource for its representations of the basic
1109 datatypes to determine the form in which the data going to/from columns in
1110 the data tables are to be handled.
1112 The second form of this function, which accepts a "wxDb *" as a parameter,
1113 can be used to avoid the overhead (execution time, database load, network
1114 traffic) which are needed to determine the data types and representations
1115 of data that are necessary for cross-datasource support by these classes.
1117 Normally the first form of the wxDb::Open() function will open the connection
1118 and then send a series of queries to the datasource asking it for its
1119 representation of data types, and all the features it supports. If one
1120 connection to the datasource has already been made previously, the information
1121 gathered when that connection was created can just be copied to any new
1122 connections to the same datasource by passing a pointer to the first
1123 connection in as a parameter to the wxDb::Open() function. Note that this
1124 new connection created from the first connections information will use the
1125 same Dsn/Uid/AuthStr as the first connection used.
1127 \wxheading{Parameters
}
1129 \docparam{Dsn
}{datasource name. The name of the ODBC datasource as
1130 assigned when the datasource is initially set up through the ODBC data
1132 \docparam{Uid
}{User ID. The name (ID) of the user you wish to connect as
1133 to the datasource. The user name (ID) determines what objects you
1134 have access to in the datasource and what datasource privileges you have.
1135 Privileges include being able to create new objects, update objects, delete
1136 objects and so on. Users and privileges are normally administered by the
1137 database administrator.
}
1138 \docparam{AuthStr
}{The password associated with the Uid.
}
1139 \docparam{copyDb
}{Already completely configured and opened datasource connection
1140 from which all Dsn, Uid, AuthStr, and data typing information is to be copied
1141 from for use by this datasource connection.
}
1145 After a wxDb instance is created, it must then be opened. When opening a
1146 datasource, there must be three pieces of information passed. The data
1147 source name, user name (ID) and the password for the user. No database
1148 activity on the datasource can be performed until the connection is opened.
1149 This is normally done at program startup and the datasource remains
1150 open for the duration of the program/module run.
1152 It is possible to have connections to multiple datasources open at the same
1153 time to support distributed database connections by having separate instances
1154 of wxDb objects that use either the same or different Dsn/Uid/AuthStr settings.
1156 If this function returns a value of FALSE, it does not necessarily mean that
1157 the connection to the datasource was not opened. It may mean that some
1158 portion of the initialization of the connection failed (such as a datatype not
1159 being able to be determined how the datasource represents it). To determine
1160 if the connection to the database failed, use the
\helpref{wxDb::IsOpen
}{wxdbisopen
}
1161 function after receiving a FALSE result back from this function to determine if
1162 the connection was opened or not. If this function returns FALSE, but
\helpref{wxDb::IsOpen
}{wxdbisopen
}
1163 returns TRUE, then direct SQL commands may be passed to the database
1164 connection and can be successfully executed, but use of the datatypes (such as
1165 by a wxDbTable instance) that are normally determined during open will not be
1168 \normalbox{The
{\it Dsn
},
{\it Uid
}, and
{\it AuthStr
} string pointers that are passed in
1169 are copied. NOT the strings themselves, only the pointers. The calling routine
1170 must maintain the memory for these three strings for the life of the wxDb instance.
}
1175 wxDb sampleDB(Db.Henv);
1176 if (!sampleDB.Open("Oracle
7.1 HP/UX", "gtasker", "myPassword"))
1178 if (sampleDb.IsOpen())
1180 // Connection is open, but the initialization of
1181 // datatypes and parameter settings failed
1185 // Error opening datasource
1191 \membersection{wxDb::RollbackTrans
}\label{wxdbrollbacktrans
}
1193 \func{bool
}{RollbackTrans
}{\void}
1195 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.
1199 Transactions begin implicitly as soon as you make a change to the database. The
1200 transaction continues until either a commit or rollback is executed. Calling
1201 wxDb::RollbackTrans() will result in ALL changes done using this database
1202 connection that have not already been committed to be "undone" back to the last
1203 commit/rollback that was successfully executed.
1205 \normalbox{Calling this member function rolls back ALL open (uncommitted)
1206 transactions on this ODBC connection, including all wxDbTable instances that
1207 use this connection.
}
1209 \wxheading{See also
}
1211 \helpref{wxDb::CommitTrans
}{wxdbcommittrans
} for a special note on cursors
1214 \membersection{wxDb::SetDebugErrorMessages
}\label{wxdbsetdebugerrormessages
}
1216 \func{void
}{SetDebugErrorMessages
}{\param{bool
}{state
}}
1218 \docparam{state
}{Either TRUE (debug messages are logged) or FALSE (debug
1219 messages are not logged.
}
1223 Turns on/off debug error messages from the ODBC class library. When
1224 this function is passed TRUE, errors are reported to the user/logged automatically
1225 in a text or pop-up dialog when an ODBC error occurs. When passed FALSE,
1226 errors are silently handled.
1228 When compiled in release mode (FINAL=
1), this setting has no affect.
1230 \wxheading{See also
}
1232 \helpref{wxDb constructor
}{wxdbconstr
}
1235 \membersection{wxDb::SetSqlLogging
}\label{wxdbsetsqllogging
}
1237 \func{bool
}{SetSqlLogging
}{\param{wxDbSqlLogState
}{ state
},
\param{const wxChar *
}{filename = SQL_LOG_FILENAME
},
\param{bool
}{ append = FALSE
}}
1239 \wxheading{Parameters
}
1241 \docparam{state
}{Either sqlLogOFF or sqlLogON (see
\helpref{enum wxDbSqlLogState
}{wxdbcolfor
}). Turns logging of SQL commands sent to the datasource OFF or ON.
}
1242 \docparam{filename
}{{\it OPTIONAL
}. Name of the file to which the log text is to be written. Default is SQL_LOG_FILENAME.
}
1243 \docparam{append
}{{\it OPTIONAL
}. Whether the file is appended to or overwritten. Default is FALSE.
}
1247 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 riteSqlLog() calls in the database member functions, or may be manually logged by adding calls to
\helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
} in your own source code.
1249 When called with
{\it sqlLogOFF
}, the logging file is closed, and any calls to
\helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
} are ignored.
1252 \membersection{wxDb::TableExists
}\label{wxdbtableexists
}
1254 \func{bool
}{TableExists
}{\param{const char *
}{tableName
},
\param{const char *
}{userID=NULL
},
\param{const char *
}{path=NULL
}}
1256 Checks the ODBC datasource for the existence of a table. If a
{\it userID
}
1257 is specified, then the table must be accessible by that user (user must have
1258 at least minimal privileges to the table).
1260 \wxheading{Parameters
}
1262 \docparam{tableName
}{Name of the table to check for the existence of.
}
1263 \docparam{userID
}{Owner of the table (also referred to as schema). Specify a userID when the datasource you are connected
1264 to allows multiple unique tables with the same name to be owned by different users.
{\it userID
}
1265 is evaluated as follows:
}
1268 userID == NULL ... UserID is ignored (DEFAULT)
1269 userID == "" ... UserID set equal to 'this->uid'
1270 userID != "" ... UserID set equal to 'userID'
1275 {\it tableName
} may refer to a table, view, alias or synonym.
1277 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.
1279 \wxheading{See also
}
1281 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
}
1284 \membersection{wxDb::TablePrivileges
}\label{wxdbtableprivileges
}
1286 \func{bool
}{TablePrivileges
}{\param{const char *
}{tableName
},
\param{const char *
}{priv
},
\param{const char *
}{userID=""
},
\param{const char *
}{schema=NULL
},
\param{const char *
}{path=""
}}
1288 Checks the ODBC datasource for the existence of a table. If a
{\it userID
}
1289 is specified, then the table must be accessible by that user (user must have
1290 at least minimal privileges to the table).
1292 \wxheading{Parameters
}
1294 \docparam{tableName
}{Name of the table on which to check privileges.
1295 {\it tableName
} may refer to a table, view, alias or synonym.
}
1296 \docparam{priv
}{The table privilege being evaluated. May be one of the
1297 following (or a datasource specific privilege):
}
1300 SELECT : The connected user is permitted to retrieve data for
1301 one or more columns of the table.
1303 INSERT : The connected user is permitted to insert new rows
1304 containing data for one or more columns into the
1307 UPDATE : The connected user is permitted to update the data in
1308 one or more columns of the table.
1310 DELETE : The connected user is permitted to delete rows of
1311 data from the table.
1313 REFERENCES : Is the connected user permitted to refer to one or
1314 more columns of the table within a constraint (for
1315 example, a unique, referential, or table check
1318 \docparam{userID
}{{\it OPTIONAL.
} User for which to determine if the privilege
1319 specified to be checked is granted or not. Default is "".
1320 {\it userID
} is evaluated as follows:
1323 userID == NULL ... NOT ALLOWED!
1324 userID == "" ... UserID set equal to 'this->uid'
1325 userID != "" ... UserID set equal to 'userID'
1328 \docparam{schema
}{{\it OPTIONAL.
} Owner of the table. Specify a userID when the datasource
1329 you are connected to allows multiple unique tables with the same name to be
1330 owned by different users. Specifying the table owner makes determination of the
1331 users privileges MUCH faster. Default is NULL.
{\it userID
} is evaluated as follows:
1334 schema == NULL ... Any owner (DEFAULT)
1335 schema == "" ... Owned by 'this->uid'
1336 schema != "" ... Owned by userID specified in 'schema'
1339 \docparam{path
}{{\it OPTIONAL.
} Path to the table. Default is "".
1344 The scope of privilege allowed to the connected user by a given table
1345 privilege is datasource dependent.
1347 For example, the privilege UPDATE might allow the connected user to update
1348 all columns in a table on one datasource, but only those columns for
1349 which the grantor (the user that granted the connected user) has the UPDATE
1350 privilege on another datasource.
1352 Looking up a user's privileges to a table can be time consuming depending on the
1353 datasource and ODBC driver. This time can be minimized by passing a
{\it schema
}
1354 as a parameter. With some datasources/drivers, the difference can be several
1355 seconds of time difference.
1358 \membersection{wxDb::TranslateSqlState
}\label{wxdbtranslatesqlstate
}
1360 \func{int
}{TranslateSqlState
}{\param{const wxChar *
}{SQLState
}}
1362 Converts an ODBC sqlstate to an internal error code.
1364 \wxheading{Parameters
}
1366 \docparam{SQLState
}{State to be converted.
}
1368 \wxheading{Return value
}
1370 Returns the internal class DB_ERR code. See
\helpref{wxDb::DB_STATUS
}{wxdb
} definition.
1373 \membersection{wxDb::WriteSqlLog
}\label{wxdbwritesqllog
}
1375 \func{bool
}{WriteSqlLog
}{\param{const wxChar *
}{logMsg
}}
1377 \wxheading{Parameters
}
1379 \docparam{logMsg
}{Free form string to be written to the log file.
}
1383 Very useful debugging tool that may be turned on/off during run time (see
1384 (see
\helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
} for details on
1385 turning logging on/off). The passed in string
{\it logMsg
} will be written to
1386 a log file if SQL logging is turned on.
1388 \wxheading{Return value
}
1390 If SQL logging is off when a call to WriteSqlLog() is made, or there is a
1391 failure to write the log message to the log file, the function returns
1392 FALSE without performing the requested log, otherwise TRUE is returned.
1394 \wxheading{See also
}
1396 \helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}
1399 \section{\class{wxDbColDataPtr
}}\label{wxdbcoldataptr
}
1401 Pointer to dynamic column definitions for use with a wxDbTable instance.
1402 Currently there are no member functions for this class.
1411 \section{\class{wxDbColDef
}}\label{wxdbcoldef
}
1413 This class is used to hold information about the columns bound to an
1414 instance of a wxDbTable object.
1416 Each instance of this class describes one column in the wxDbTable
1417 object. When calling the
\helpref{wxDb constructor
}{wxdbconstr
}, a
1418 parameter passed in indicates the number of columns that will be defined for
1419 the wxDbTable object. The constructor uses this information to allocate
1420 adequate memory for all of the column descriptions in your wxDbTable object.
1421 Private member wxDbTable::colDefs is a pointer to this chunk of memory
1422 maintained by the wxDbTable class (and can be retrieved using the
1423 \helpref{wxDbTable::GetColDefs
}{wxdbtablegetcoldefs
} function).
1424 To access the nth column definition of your wxDbTable object, just reference
1425 wxDbColDefs element
[n -
1].
1427 Currently there are no member functions for this class.
1429 Typically,
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
} is used to
1430 populate an array of these data structures for the wxDbTable instance.
1433 char ColName
[DB_MAX_COLUMN_NAME_LEN+
1]; // Column Name
1434 int DbDataType; - Logical Data Type;
1435 e.g. DB_DATA_TYPE_INTEGER
1436 int SqlCtype; - C data type; e.g. SQL_C_LONG
1437 void *PtrDataObj; - Address of the data object
1438 int SzDataObj; - Size, in bytes, of the data object
1439 bool KeyField; - Is column part of the PRIMARY KEY for the
1440 table? -- Date fields should NOT be
1442 bool Updateable; - Column is updateable?
1443 bool InsertAllowed; - Column included in INSERT statements?
1444 bool DerivedCol; - Column is a derived value?
1445 SDWORD CbValue; - !!!Internal use only!!!
1446 bool Null; - NOT FULLY IMPLEMENTED
1447 Allows NULL values in Inserts and Updates
1450 \wxheading{See also
}
1452 \helpref{wxDbTable::GetColDefs
}{wxdbtablegetcoldefs
},
\helpref{wxDb constructor
}{wxdbconstr
}
1455 \section{\class{wxDbColInf
}}\label{wxdbcolinf
}
1457 Used with the
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
} functions for obtaining all retrievable information about a column's definition.
1460 char catalog
[128+
1];
1462 char tableName
[DB_MAX_TABLE_NAME_LEN+
1];
1463 char colName
[DB_MAX_COLUMN_NAME_LEN+
1];
1465 char typeName
[128+
1];
1468 short decimalDigits;
1471 char remarks
[254+
1];
1472 int dbDataType; // conversion of the 'sqlDataType'
1473 // to the generic data type used by
1475 int PkCol; // Primary key column
1478 2 = Second Key, etc...
1479 char PkTableName
[DB_MAX_TABLE_NAME_LEN+
1];
1480 // Tables that use this PKey as a FKey
1481 int FkCol; // Foreign key column
1484 2 = Second Key, etc...
1485 char FkTableName
[DB_MAX_TABLE_NAME_LEN+
1];
1486 // Foreign key table name
1487 wxDbColFor *pColFor; // How should this column be formatted
1490 The constructor for this class initializes all the values to zero or NULL.
1492 The destructor for this class takes care of deleting the pColFor member if
1496 \section{\class{wxDbColFor
}}\label{wxdbcolfor
}
1498 Beginning support for handling international formatting specifically on dates and floats.
1501 wxString s_Field; // Formated String for Output
1502 wxString s_Format
[7]; // Formated Objects - TIMESTAMP has
1504 wxString s_Amount
[7]; // Formated Objects - amount of
1505 things that can be formatted
1506 int i_Amount
[7]; // Formated Objects -
1507 TT MM YYYY HH MM SS m
1508 int i_Nation; //
0 = timestamp
1513 int i_dbDataType; // conversion of the 'sqlDataType'
1514 to the generic data type used by
1516 SWORD i_sqlDataType;
1519 The constructor for this class initializes all the values to zero or NULL.
1521 The destructor does nothing at this time.
1523 Only one function is provided with this class currently:
1525 \membersection{wxDbColFor::Format
}\label{wxdbcolforformat
}
1527 \func{int
}{Format
}{\param{int
}{Nation
},
\param{int
}{dbDataType
},
\param{SWORD
}{sqlDataType
},
\param{short
}{columnSize
},
\param{short
}{decimalDigits
}}\label{wxdbcolforformat
}
1529 Work in progress, and should be inter-related with wxLocale eventually.
1532 \section{\class{wxDbIdxDef
}}\label{wxdbidxdef
}
1534 Used in creation of non-primary indexes. Currently there are no member
1535 functions for this class.
1538 char ColName
[DB_MAX_COLUMN_NAME_LEN+
1]
1540 bool Ascending // Is index maintained in
1544 There are no constructors/destructors as of this time, and no member functions.
1547 \section{\class{wxDbInf
}}\label{wxdbinf
}
1549 Contains information regarding the database connection (datasource name,
1550 number of tables, etc). A pointer to a wxDbTableInf is included in this
1551 class so a program can create a wxDbTableInf array instance to maintain all
1552 information about all tables in the datasource to have all the datasource's
1553 information in one memory structure.
1555 Primarily, this class is used internally by the wxWindows ODBC classes.
1558 char catalog
[128+
1];
1559 char schema
[128+
1]; // typically means owner of table(s)
1560 int numTables; // How many tables does this
1562 wxDbTableInf *pTableInf; // Equals a new
1563 wxDbTableInf
[numTables
];
1566 The constructor for this class initializes all the values to zero or NULL.
1568 The destructor for this class takes care of deleting the pTableInf member if
1572 \section{\class{wxDbTable
}}\label{wxdbtable
}
1574 A wxDbTable instance provides re-usable access to rows of data in
1575 a table contained within the associated ODBC datasource
1577 \wxheading{Include files
}
1582 \latexignore{\rtfignore{\wxheading{Members
}}}
1583 \wxheading{Helper classes and data structures
}
1585 The following classes and structs are defined in dbtable.cpp/.h for use with the wxDbTable class.
1587 \begin{itemize
}\itemsep=
0pt
1588 \item \helpref{wxDbColDef
}{wxdbcoldef
}
1589 \item \helpref{wxDbColDataPtr
}{wxdbcoldataptr
}
1590 \item \helpref{wxDbIdxDef
}{wxdbidxdef
}
1593 \wxheading{Constants
}
1596 wxDB_DEFAULT_CURSOR Primary cursor normally used for cursor based
1599 wxDB_QUERY_ONLY Used to indicate whether a table that is opened
1600 is for query only, or if insert/update/deletes
1601 will be performed on the table. Less overhead
1602 (cursors and memory) are allocated for query
1603 only tables, plus read access times are faster
1604 with some datasources.
1606 wxDB_ROWID_LEN
[Oracle only
] - Used when CanUpdateByRowID()
1607 is true. Optimizes updates so they are faster
1608 by updating on the Oracle-specific ROWID column
1609 rather than some other index.
1612 wxDB_DISABLE_VIEW Use to indicate when a database view should not
1613 be if a table is normally set up to use a view.
1614 [Currently unsupported.
]
1619 \latexignore{\rtfignore{\wxheading{Members
}}}
1621 \membersection{wxDbTable::wxDbTable
}\label{wxdbtableconstr
}
1623 \func{}{wxDbTable
}{\param{wxDb *
}{pwxDb
},
\param{const char *
}{tblName
},
\param{const int
}{nCols
},
\param{const char *
}{qryTblName = NULL
},
\param{bool
}{qryOnly = !wxDB_QUERY_ONLY
},
\param{const char *
}{tblPath=NULL
}}
1625 Default constructor.
1627 \wxheading{Parameters
}
1629 \docparam{pwxDb
}{Pointer to the wxDb instance to be used by this wxDbTable
1631 \docparam{tblName
}{The name of the table in the RDBMS.
}
1632 \docparam{nCols
}{The number of columns in the table. (Do NOT include the ROWID
1633 column in the count if using Oracle).
}
1634 \docparam{qryTblName
}{{\it OPTIONAL
}. The name of the table or view to base
1635 your queries on. This argument allows you to specify a table/view other than
1636 the base table for this object to base your queries on. This allows you to
1637 query on a view for example, but all of the INSERT, UPDATE and DELETES will
1638 still be performed on the base table for this wxDbTable object. Basing your
1639 queries on a view can provide a substantial performance increase in cases where
1640 your queries involve many tables with multiple joins. Default is NULL.
}
1641 \docparam{qryOnly
}{{\it OPTIONAL
}. Indicates whether the table will be
1642 accessible for query purposes only, or should the table create the necessary
1643 cursors to be able to insert, update, and delete data from the table.
1644 Default is !wxDB_QUERY_ONLY.
}
1645 \docparam{tblPath
}{{\it OPTIONAL
}. Some datasources (such as dBase)
1646 require a path to where the table is stored on the system. Default is NULL.
}
1648 \membersection{wxDbTable::wxDbTable
}\label{wxdbtabledestr
}
1650 \func{virtual
}{\destruct{wxDbTable
}}{}
1652 Virtual default destructor.
1655 \membersection{wxDbTable::BuildDeleteStmt
}\label{wxdbtablebuilddeletestmt
}
1657 \func{void
}{BuildDeleteStmt
}{\param{char *
}{pSqlStmt
},
\param{int
}{typeOfDel
},
\param{const char *
}{pWhereClause=NULL
}}
1659 Constructs the full SQL statement that can be used to delete all rows matching
1660 the criteria in the pWhereClause.
1662 \wxheading{Parameters
}
1664 \docparam{pSqlStmt
}{Pointer to buffer for the SQL statement retrieved. To be
1665 sure you have adequate space allocated for the SQL statement, allocate
1666 DB_MAX_STATEMENT_LEN bytes.
}
1667 \docparam{typeOfDel
}{The type of delete statement being performed. Can be one
1668 of three values: DB_DEL_KEYFIELDS, DB_DEL_WHERE or DB_DEL_MATCHING
}
1669 \docparam{pWhereClause
}{{\it OPTIONAL
}. If the typeOfDel is DB_DEL_WHERE,
1670 then you must also pass in a SQL WHERE clause in this argument. Default
1675 This member function constructs a SQL DELETE statement. This can be used for
1676 debugging purposes if you are having problems executing your SQL statement.
1678 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
1679 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
1683 \membersection{wxDbTable::BuildSelectStmt
}\label{wxdbtablebuildselectstmt
}
1685 \func{void
}{BuildSelectStmt
}{\param{char *
}{pSqlStmt
},
\param{int
}{typeOfSelect
},
\param{bool
}{distinct
}}
1687 Constructs the full SQL statement that can be used to select all rows matching
1688 the criteria in the pWhereClause. This function is called internally in the
1689 wxDbTable class whenever the function
\helpref{wxDbTable::Query
}{wxdbtablequery
}
1692 NOTE: Only the columns specified in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
1693 statements are included in the list of columns returned by the SQL statement
1694 created by a call to this function.
1696 \wxheading{Parameters
}
1698 \docparam{pSqlStmt
}{Pointer to storage for the SQL statement retrieved. To be
1699 sure you have adequate space allocated for the SQL statement, allocate
1700 DB_MAX_STATEMENT_LEN bytes.
}
1701 \docparam{typeOfSelect
}{The type of select statement being performed. Can be
1702 one of four values: DB_SELECT_KEYFIELDS, DB_SELECT_WHERE, DB_SELECT_MATCHING
1703 or DB_SELECT_STATEMENT.
}
1704 \docparam{distinct
}{Whether to select distinct records only.
}
1708 This member function constructs a SQL SELECT statement. This can be used for
1709 debugging purposes if you are having problems executing your SQL statement.
1711 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
1712 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
1716 \membersection{wxDbTable::BuildUpdateStmt
}\label{wxdbtablebuildupdatestmt
}
1718 \func{void
}{BuildSelectStmt
}{\param{char *
}{pSqlStmt
},
\param{int
}{typeOfUpd
},
\param{const char *
}{pWhereClause=NULL
}}
1720 Constructs the full SQL statement that can be used to update all rows matching
1721 the criteria in the pWhereClause.
1723 If typeOfUpd is DB_UPD_KEYFIELDS, then the current values in the bound columns
1724 are used to determine which row(s) in the table are to be updated. The
1725 exception to this is when a datasource supports ROW IDs (Oracle). The ROW ID
1726 column is used for efficiency purposes when available.
1728 NOTE: Only the columns specified in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
1729 statements are included in the list of columns updated by the SQL statement
1730 created by a call to this function. Any column definitions that were defined
1731 as being non-updateable will be excluded from the SQL UPDATE statement created
1734 \wxheading{Parameters
}
1736 \docparam{pSqlStmt
}{Pointer to storage for the SQL statement retrieved. To be
1737 sure you have adequate space allocated for the SQL statement, allocate
1738 DB_MAX_STATEMENT_LEN bytes.
}
1739 \docparam{typeOfUpd
}{The type of update statement being performed. Can be one
1740 of two values: DB_UPD_KEYFIELDS or DB_UPD_WHERE.
}
1741 \docparam{pWhereClause
}{{\it OPTIONAL
}. If the typeOfUpd is DB_UPD_WHERE,
1742 then you must also pass in a SQL WHERE clause in this argument. Default
1747 This member function allows you to see what the SQL UPDATE statement looks like
1748 that the ODBC class library builds. This can be used for debugging purposes if
1749 you are having problems executing your SQL statement.
1751 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
1752 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
1756 \membersection{wxDbTable::BuildWhereStmt
}\label{wxdbtablebuildwherestmt
}
1758 \func{void
}{BuildSelectStmt
}{\param{char *
}{pWhereClause
},
\param{int
}{typeOfWhere
},
\param{const char *
}{qualTableName=NULL
},
\param{const char *
}{useLikeComparison=FALSE
}}
1760 Constructs the portion of a SQL statement which would follow the word 'WHERE'
1761 in a SQL statement to be passed to the datasource. The returned string
1762 does NOT include the word 'WHERE'.
1764 \wxheading{Parameters
}
1766 \docparam{pWhereClause
}{Pointer to storage for the SQL statement retrieved.
1767 To be sure you have adequate space allocated for the SQL statement, allocate
1768 DB_MAX_STATEMENT_LEN bytes.
}
1769 \docparam{typeOfWhere
}{The type of where clause to generate. Can be one of
1770 two values: DB_WHERE_KEYFIELDS or DB_WHERE_MATCHING.
}
1771 \docparam{qualTableName
}{{\it OPTIONAL
}. Prepended to all base table
1772 column names. For use when a FROM clause has been specified with the
1773 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
},
1774 to clarify which table a column name reference belongs to. Default is NULL.
}
1775 \docparam{useLikeComparison
}{{\it OPTIONAL
}. Should the constructed WHERE
1776 clause utilize the LIKE comparison operator. If FALSE, then the '='
1777 operator is used. Default is FALSE.
}
1781 This member function allows you to see what the SQL WHERE clause looks like
1782 that the ODBC class library builds. This can be used for debugging purposes
1783 if you are having problems executing your own SQL statements.
1785 If using 'typeOfWhere' set to DB_WHERE_MATCHING, any bound columns currently
1786 containing a NULL value are not included in the WHERE clause's list of
1787 columns to use in the comparison.
1790 \membersection{wxDbTable::CanSelectForUpdate
}\label{wxdbtablecanselectforupdate
}
1792 \func{bool
}{CanSelectForUpdate
}{\void}
1794 Use this function to determine if the datasource supports SELECT ... FOR UPDATE.
1795 When the keywords "FOR UPDATE" are included as part of your SQL SELECT statement,
1796 all records
{\it retrieved
} (not just queried, but actually retrieved using
1797 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}, etc) from the result set are
1802 Not all datasources support the "FOR UPDATE" clause, so you must use this
1803 member function to determine if the datasource currently connected to supports
1804 this behavior or not before trying to select using "FOR UPDATE".
1806 If the wxDbTable instance was created with the parameter wxDB_QUERY_ONLY, then
1807 this function will return FALSE. For all known databases which do not support
1808 the FOR UPDATE clause, this function will return FALSE also.
1811 \membersection{wxDbTable::CanUpdateByROWID
}\label{wxdbtablecanupdatebyrowid
}
1813 \func{bool
}{CanUpdateByROWID
}{\void}
1815 CURRENTLY ONLY POSSIBLE IF USING ORACLE.
1817 --- CURRENTLY DISABLED FOR *ALL* DATASOURCES --- NOV
1 2000 - gt
1819 Every Oracle table has a hidden column named ROWID. This is a pointer to the
1820 physical location of the record in the datasource and allows for very fast
1821 updates and deletes. The key is to retrieve this ROWID during your query so
1822 it is available during an update or delete operation.
1824 Use of the ROWID feature is always handled by the class library except in the
1825 case of
\helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}. Since
1826 you are passing in the SQL SELECT statement,
1827 it is up to you to include the ROWID column in your query. If you do not,
1828 the application will still work, but may not be as optimized. The ROWID is
1829 always the last column in the column list in your SQL SELECT statement.
1830 The ROWID is not a column in the normal sense and should not be considered
1831 part of the column definitions for the wxDbTable object.
1835 The decision to include the ROWID in your SQL SELECT statement must be
1836 deferred until runtime since it depends on whether you are connected
1837 to an Oracle datasource or not.
1842 // Incomplete code sample
1845 if (parts.CanUpdByROWID())
1847 // Note that the ROWID column must always be the last column selected
1848 sqlStmt = "SELECT PART_NO, PART_DESC, ROWID" FROM PARTS";
1851 sqlStmt = "SELECT PART_NO, PART_DESC" FROM PARTS";
1855 \membersection{wxDbTable::ClearMemberVar
}\label{wxdbtableclearmembervar
}
1857 \func{void
}{ClearMemberVar
}{\param{int
}{colNo
},
\param{bool
}{setToNull=FALSE
}}
1859 Same as
\helpref{wxDbTable::ClearMemberVars
}{wxdbtableclearmembervars
} except
1860 that this function clears only the specified column of its values, and
1861 optionally sets the column to be a NULL column.
1863 \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
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
} function.
}
1864 \docparam{setToNull
}{{\it OPTIONAL
}. Indicates whether the column should be flagged as being a NULL value stored in the bound memory variable. If TRUE, then any value stored in the bound member variable is cleared. Default is FALSE.
}
1867 \membersection{wxDbTable::ClearMemberVars
}\label{wxdbtableclearmembervars
}
1869 \func{void
}{ClearMemberVars
}{\param{bool
}{setToNull=FALSE
}}
1871 Initializes all bound columns of the wxDbTable instance to zero. In the case
1872 of a string, zero is copied to the first byte of the string.
1874 \docparam{setToNull
}{{\it OPTIONAL
}. Indicates whether all columns should be flagged as having a NULL value stored in the bound memory variable. If TRUE, then any value stored in the bound member variable is cleared. Default is FALSE.
}
1878 This is useful before calling functions such as
\helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
1879 \helpref{wxDbTable::DeleteMatching
}{wxdbtabledeletematching
} since these
1880 functions build their WHERE clauses from non-zero columns. To call either
1881 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
1882 \helpref{wxDbTable::DeleteMatching
}{wxdbtabledeletematching
} use this sequence:
1885 1) ClearMemberVars()
1886 2) Assign columns values you wish to match on
1887 3) Call wxDbTable::QueryMatching() or wxDbTable::DeleteMatching()
1891 \membersection{wxDbTable::CloseCursor
}\label{wxdbtableclosecursor
}
1893 \func{bool
}{CloseCursor
}{\param{HSTMT
}{cursor
}}
1895 Closes the specified cursor associated with the wxDbTable object.
1897 \wxheading{Parameters
}
1899 \docparam{cursor
}{The cursor to be closed.
}
1903 Typically handled internally by the ODBC class library, but may be used by the
1904 programmer if desired.
1907 \normalbox{DO NOT CLOSE THE wxDB_DEFAULT_CURSOR!
}
1910 \membersection{wxDbTable::Count
}\label{wxdbtablecount
}
1912 \func{ULONG
}{Count
}{\param{const char *
}{args="*"
}}
1914 Returns the number of records which would be in the result set using the
1915 current query parameters specified in the WHERE and FROM clauses.
1917 \wxheading{Parameters
}
1919 \docparam{args
}{{\it OPTIONAL
}. This arguement allows the use of the
1920 DISTINCT keyword against a column name to cause the returned count to
1921 only indicate the number of rows in the result set that have a unique
1922 value in the specified column. An example is shown below. Default is "*",
1923 meaning a count of the total number of rows matching is returned, regardless of
1928 This function can be called before or after an actual query to obtain the
1929 count of records in the result set. Count() uses its own cursor, so result
1930 set cursor positioning is not affected by calls to Count().
1932 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
1933 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} ARE used by
1942 FIRST_NAME LAST_NAME
1943 ----------- ----------
1949 // Incomplete code sample
1952 users.SetWhereClause("");
1954 // This Count() will return
4, as there are four users listed above
1955 // that match the query parameters
1956 totalNumberOfUsers = users.Count();
1958 // This Count() will return
3, as there are only
3 unique first names
1959 // in the table above - John, Richard, Michael.
1960 totalNumberOfUniqueFirstNames = users.Count("DISTINCT FIRST_NAME");
1964 \membersection{wxDbTable::CreateIndex
}\label{wxdbtablecreateindex
}
1966 \func{bool
}{CreateIndex
}{\param{const char *
}{idxName
},
\param{bool
}{unique
},
\param{int
}{noIdxCols
},
\param{wxDbIdxDef *
}{pIdxDefs
},
\param{bool
}{attemptDrop=TRUE
}}
1968 This member function allows you to create secondary (non primary) indexes on
1969 your tables. You first create your table, normally specifying a primary
1970 index, and then create any secondary indexes on the table. Indexes in
1971 relational model are not required. You do not need indexes to look up records
1972 in a table or to join two tables together. In the relational model, indexes,
1973 if available, provide a quicker means to look up data in a table. To enjoy
1974 the performance benefits of indexes, the indexes must be defined on the
1975 appropriate columns and your SQL code must be written in such a way as to
1976 take advantage of those indexes.
1978 \wxheading{Parameters
}
1980 \docparam{idxName
}{Name of the Index. Name must be unique within the table space of the datasource.
}
1981 \docparam{unique
}{Indicates if this index is unique.
}
1982 \docparam{noIdxCols
}{Number of columns in the index.
}
1983 \docparam{pIdxDefs
}{A pointer to an array wxDbIdxDef structures.
}
1984 \docparam{attemptDrop
}{{\it OPTIONAL
}. Indicates if the function should try
1985 to execute a
\helpref{wxDbTable::DropIndex
}{wxdbtabledropindex
} on the index
1986 name provided before trying to create the index name. Default is TRUE.
}
1990 The first parameter, index name, must be unique and should be given a
1991 meaningful name. Common practice is to include the table name as a prefix
1992 in the index name (e.g. For table PARTS, you might want to call your index
1993 PARTS_IDX1). This will allow you to easily view all
1994 of the indexes defined for a given table grouped together alphabetically.
1996 The second parameter indicates if the index is unique or not. Uniqueness
1997 is enforced at the RDBMS level preventing rows which would have duplicate
1998 indexes from being inserted into the table when violating a unique index's
2001 In the third parameter, specify how many columns are in your index. This
2002 number must match the number of columns defined in the 'pIdxDefs' parameter.
2004 The fourth parameter specifies which columns make up the index using the
2005 wxDbIdxDef structure. For each column in the index, you must specify two
2006 things, the column name and the sort order (ascending / descending). See
2007 the example below to see how to build and pass in the wxDbIdxDef structure.
2009 The fifth parameter is provided to handle the differences in datasources as
2010 to whether they will automatically overwrite existing indexes with the same
2011 name or not. Some datasources require that the existing index must be dropped
2012 first, so this is the default behavior.
2014 Some datasources (MySQL, and possibly others) require columns which are to be
2015 part of an index to be defined as NOT NULL. When this function is called, if
2016 a column is not defined to be NOT NULL, a call to this function will modify
2017 the column definition to change any columns included in the index to be
2018 NOT NULL. In this situation, if a NULL value already exists in one of the
2019 columns that is being modified, creation of the index will fail.
2021 PostGres is unable to handle index definitions which specify whether the index
2022 is ascending or descending, and defaults to the system default when the index
2025 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2026 after executing this function.
2031 // Create a secondary index on the PARTS table
2032 wxDbIdxDef idxDef
[2]; //
2 columns make up the index
2034 strcpy(idxDef
[0].ColName, "PART_DESC"); // Column
1
2035 idxDef
[0].Ascending = TRUE;
2037 strcpy(idxDef
[1].ColName, "SERIAL_NO"); // Column
2
2038 idxDef
[1].Ascending = FALSE;
2040 // Create a name for the index based on the table's name
2042 indexName.sprintf("
%s_IDX1",parts->GetTableName());
2043 parts->CreateIndex(indexName.c_str(), TRUE,
2, idxDef);
2047 \membersection{wxDbTable::CreateTable
}\label{wxdbtablecreatetable
}
2049 \func{bool
}{CreateTable
}{\param{bool
}{attemptDrop=TRUE
}}
2051 Creates a table based on the definitions previously defined for this
2054 \wxheading{Parameters
}
2056 \docparam{attemptDrop
}{{\it OPTIONAL
}. Indicates whether the driver should
2057 attempt to drop the table before trying to create it. Some datasources will
2058 not allow creation of a table if the table already exists in the table space
2059 being used. Default is TRUE.
}
2063 This function creates the table and primary index (if any) in the table space
2064 associated with the connected datasource. The owner of these objects will
2065 be the user id that was given when
\helpref{wxDb::Open
}{wxdbopen
} was called. The objects will
2066 be created in the default schema/table space for that user.
2068 In your derived wxDbTable object constructor, the columns and primary index
2069 of the table are described through the
\helpref{wxDbColDef
}{wxdbcoldef
} structure.
2070 \helpref{wxDbTable::CreateTable
}{wxdbtablecreatetable
} uses this information to create the table and to add
2071 the primary index. See
\helpref{wxDbTable
}{wxdbtable
} ctor and wxDbColDef
2072 description for additional information on describing the columns of the table.
2074 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2075 after executing this function.
2078 \membersection{wxDbTable::DB_STATUS
}\label{wxdbtabledbstatus
}
2080 \func{bool
}{DB_STATUS
}{\void}
2082 Accessor function that returns the wxDb private member variable DB_STATUS for
2083 the database connection used by this instance of wxDbTable.
2086 \membersection{wxDbTable::Delete
}\label{wxdbtabledelete
}
2088 \func{bool
}{Delete
}{\void}
2090 Deletes the row from the table indicated by the current cursor.
2094 Use
\helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
},
\helpref{wxDbTable::GetLast
}{wxdbtablegetlast
},
2095 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
} or
2096 \helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
} to position the cursor to
2097 a valid record. Once positioned on a record, call this function to delete
2098 the row from the table.
2100 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2101 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
2102 this function to commit or rollback the deletion.
2104 NOTE: Most datasources have a limited size "rollback" segment. This means
2105 that it is only possible to insert/update/delete a finite number of rows
2106 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2107 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2108 segment varies from database to database, and is user configurable in
2109 most databases. Therefore it is usually best to try to perform a commit
2110 or rollback at relatively small intervals when processing a larger number
2111 of actions that insert/update/delete rows in a table.
2114 \membersection{wxDbTable::DeleteCursor
}\label{wxdbtabledeletecursor
}
2116 \func{bool
}{DeleteCursor
}{\param{HSTMT *
}{hstmtDel
}}
2118 Allows a program to delete a cursor.
2120 \wxheading{Parameters
}
2122 \docparam{hstmtDel
}{Handle of the cursor to delete.
}
2126 For default cursors associated with the instance of wxDbTable, it is not
2127 necessary to specifically delete the cursors. This is automatically done
2128 in the wxDbTable destructor.
2130 NOTE: If the cursor could not be deleted for some reason, an error is logged
2131 indicating the reason. Even if the cursor could not be deleted, the HSTMT
2132 that is passed in is deleted, and the pointer is set to NULL.
2134 \normalbox{DO NOT DELETE THE wxDB_DEFAULT_CURSOR!
}
2137 \membersection{wxDbTable::DeleteMatching
}\label{wxdbtabledeletematching
}
2139 \func{bool
}{DeleteMatching
}{\void}
2141 This member function allows you to delete records from your wxDbTable object
2142 by specifying the data in the columns to match on.
2146 To delete all users with a first name of "JOHN", do the following:
2149 1) Clear all "columns" using wxDbTable::ClearMemberVars().
2150 2) Set the FIRST_NAME column equal to "JOHN".
2151 3) Call wxDbTable::DeleteMatching().
2154 The WHERE clause is built by the ODBC class library based on all non-NULL
2155 columns. This allows deletion of records
2156 by matching on any column(s) in your wxDbTable instance, without having to
2157 write the SQL WHERE clause.
2159 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2160 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
2161 this function to commit or rollback the deletion.
2163 NOTE: Row(s) should be locked before deleting them to make sure they are
2164 not already in use. This can be achieved by calling
\helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
},
2165 and then retrieving the records, locking each as you go (assuming FOR UPDATE
2166 is allowed on the datasource). After the row(s) have been successfully locked,
2169 NOTE: Most datasources have a limited "rollback" segment. This means
2170 that it is only possible to insert/update/delete a finite number of rows
2171 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2172 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2173 segment varies from database to database, and is user configurable in
2174 most databases. Therefore it is usually best to try to perform a commit
2175 or rollback at relatively small intervals when processing a larger number
2176 of actions that insert/update/delete rows in a table.
2182 // Incomplete code sample to delete all users with a first name
2184 users.ClearMemberVars();
2185 strcpy(users.FirstName,"JOHN");
2186 users.DeleteMatching();
2190 \membersection{wxDbTable::DeleteWhere
}\label{wxdbtabledeletewhere
}
2192 \func{bool
}{DeleteWhere
}{\param{const char *
}{pWhereClause
}}
2194 Deletes all rows from the table which match the criteria specified in the
2195 WHERE clause that is passed in.
2197 \wxheading{Parameters
}
2199 \docparam{pWhereClause
}{SQL WHERE clause. This WHERE clause determines which
2200 records will be deleted from the table interfaced through the wxDbTable
2201 instance. The WHERE clause passed in must be compliant with the SQL
92
2202 grammar. Do not include the keyword 'WHERE'
2207 This is the most powerful form of the wxDbTable delete functions. This
2208 function gives access to the full power of SQL. This function can be used
2209 to delete records by passing a valid SQL WHERE clause. Sophisticated
2210 deletions can be performed based on multiple criteria using the full
2211 functionality of the SQL language.
2213 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} must be called after use of
2214 this function to commit the deletions.
2216 Note: This function is limited to deleting records from the table associated
2217 with this wxDbTable object only. Deletions on joined tables is not possible.
2219 NOTE: Most datasources have a limited size "rollback" segment. This means
2220 that it is only possible to insert/update/delete a finite number of rows
2221 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2222 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2223 segment varies from database to database, and is user configurable in
2224 most databases. Therefore it is usually best to try to perform a commit
2225 or rollback at relatively small intervals when processing a larger number
2226 of actions that insert/update/delete rows in a table.
2228 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2229 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2235 // Delete parts
1 thru
10 from containers 'X', 'Y' and 'Z' that
2236 // are magenta in
color
2237 parts.DeleteWhere("(PART_NUMBER BETWEEN
1 AND
10) AND \
2238 CONTAINER IN ('X', 'Y', 'Z') AND \
2239 UPPER(COLOR) = 'MAGENTA'");
2243 \membersection{wxDbTable::DropIndex
}\label{wxdbtabledropindex
}
2245 \func{bool
}{DropIndex
}{\param{const char *
}{idxName
}}
2247 Allows an index on the associated table to be dropped (deleted) if the user
2248 login has sufficient privileges to do so.
2250 \wxheading{Parameters
}
2252 \docparam{idxName
}{Name of the index to be dropped.
}
2256 If the index specified in the 'idxName' parameter does not exist, an error
2257 will be logged, and the function will return a result of FALSE.
2259 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2260 after executing this function.
2263 \membersection{wxDbTable::DropTable
}\label{wxdbtabledroptable
}
2265 \func{bool
}{DropTable
}{\void}
2267 Deletes the associated table if the user has sufficient privileges to do so.
2271 This function returns TRUE if the table does not exist, but only for
2272 supported databases (see
\helpref{wxDb::Dbms
}{wxdbdbms
}). If a datasource
2273 is not specifically supported, and this function is called, the function
2276 Most datasources/ODBC drivers will delete any indexes associated with the
2277 table automatically, and others may not. Check the documentation for your
2278 database to determine the behavior.
2280 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2281 after executing this function.
2284 \membersection{wxDbTable::From
}\label{wxdbtablefrom
}
2286 \func{const char *
}{From
}{}
2288 \func{void
}{From
}{\param{const wxString &
}{From
}}
2290 Accessor function for the private class member wxDbTable::from. Can be used
2291 as a synonym for
\helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
}
2292 (the first form of this function) or
2293 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} (the second form
2296 \wxheading{Parameters
}
2298 \docparam{From
}{A comma separated list of table names that are to be outer
2299 joined with the base table's columns so that the joined table's columns
2300 may be returned in the result set or used as a portion of a comparison with
2301 the base table's columns. NOTE that the base tables name must NOT be included
2302 in the FROM clause, as it is automatically included by the wxDbTable class
2303 in constructing query statements.
}
2305 \wxheading{Return value
}
2307 The first form of this function returns the current value of the wxDbTable
2308 member variable ::from.
2310 The second form of the function has no return value, as it will always set
2311 the from clause successfully.
2313 \wxheading{See also
}
2315 \helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
},
2316 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}
2319 \membersection{wxDbTable::GetColDefs
}\label{wxdbtablegetcoldefs
}
2321 \func{wxDbColDef *
}{GetColDefs
}{}
2323 Accessor function that returns a pointer to the array of column definitions
2324 that are bound to the columns that this wxDbTable instance is associated
2327 To determine the number of elements pointed to by the returned
2328 \helpref{wxDbColDef
}{wxdbcoldef
} pointer, use the
2329 \helpref{wxDbTable::GetNumberOfColumns
}{wxdbtablegetnumberofcolumns
} function.
2333 These column definitions must not be manually redefined after they have been
2337 \membersection{wxDbTable::GetCursor
}\label{wxdbtablegetcursor
}
2339 \func{HSTMT
}{GetCursor
}{\void}
2341 Returns the HSTMT value of the current cursor for this wxDbTable object.
2345 This function is typically used just before changing to use a different cursor
2346 so that after the program is finished using the other cursor, the current
2347 cursor can be set back to being the cursor in use.
2349 \wxheading{See also
}
2351 \helpref{wxDbTable::SetCursor
}{wxdbtablesetcursor
},
\helpref{wxDbTable::GetNewCursor
}{wxdbtablegetnewcursor
}
2354 \membersection{wxDbTable::GetDb
}\label{wxdbtablegetdb
}
2356 \func{wxDb *
}{GetDb
}{}
2358 Accessor function for the private member variable pDb which is a pointer to
2359 the datasource connection that this wxDbTable instance uses.
2362 \membersection{wxDbTable::GetFirst
}\label{wxdbtablegetfirst
}
2364 \func{bool
}{GetFirst
}{\void}
2366 Retrieves the FIRST row in the record set as defined by the current query.
2367 Before retrieving records, a query must be performed using
2368 \helpref{wxDbTable::Query
}{wxdbtablequery
},
2369 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2370 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2371 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2375 This function can only be used if the datasource connection used by the
2376 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2377 connection does not allow backward scrolling cursors, this function will
2378 return FALSE, and the data contained in the bound columns will be undefined.
2380 \wxheading{See also
}
2382 \helpref{wxDb::FwdOnlyCursors
}{wxdbfwdonlycursors
}
2385 \membersection{wxDbTable::GetFromClause
}\label{wxdbtablegetfromclause
}
2387 \func{const char *
}{GetFromClause
}{}
2389 Accessor function that returns the current FROM setting assigned with the
2390 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}.
2392 \wxheading{See also
}
2394 \helpref{wxDbTable::From
}{wxdbtablefrom
}
2397 \membersection{wxDbTable::GetLast
}\label{wxdbtablegetlast
}
2399 \func{bool
}{GetLast
}{\void}
2401 Retrieves the LAST row in the record set as defined by the current query.
2402 Before retrieving records, a query must be performed using
2403 \helpref{wxDbTable::Query
}{wxdbtablequery
},
2404 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2405 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2406 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2410 This function can only be used if the datasource connection used by the
2411 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2412 connection does not allow backward scrolling cursors, this function will
2413 return FALSE, and the data contained in the bound columns will be undefined.
2415 \wxheading{See also
}
2417 \helpref{wxDb::FwdOnlyCursors
}{wxdbfwdonlycursors
}
2420 \membersection{wxDbTable::GetNewCursor
}\label{wxdbtablegetnewcursor
}
2422 \func{HSTMT *
}{GetNewCursor
}{\param{bool
}{setCursor=FALSE
},
\param{bool
}{bindColumns=TRUE
}}
2424 This function will create a new cursor that can be used to access the table
2425 being referenced by this wxDbTable instance, or to execute direct SQL commands
2426 on without affecting the cursors that are already defined and possibly positioned.
2428 \wxheading{Parameters
}
2430 \docparam{setCursor
}{{\it OPTIONAL
}. Should this new cursor be set to be the current cursor after successfully creating the new cursor. Default is FALSE.
}
2431 \docparam{bindColumns
}{{\it OPTIONAL
}. Should this new cursor be bound to all the memory variables that the default cursor is bound to. Default is TRUE.
}
2435 This new cursor must be closed using
\helpref{wxDbTable::DeleteCursor
}{wxdbtabledeletecursor
}
2436 by the calling program before the wxDbTable instance is deleted, or both memory
2437 and resource leaks will occur.
2440 \membersection{wxDbTable::GetNext
}\label{wxdbtablegetnext
}
2442 \func{bool
}{GetNext
}{\void}
2444 Retrieves the NEXT row in the record set after the current cursor position
2445 as defined by the current query. Before retrieving records, a query must be
2446 performed using
\helpref{wxDbTable::Query
}{wxdbtablequery
},
2447 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2448 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2449 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2451 \wxheading{Return value
}
2453 This function returns FALSE when the current cursor has reached the end of
2454 the result set. When FALSE is returned, data in the bound columns is
2459 This function works with both forward and backward scrolling cursors.
2461 \wxheading{See also
}
2462 \helpref{wxDbTable::++
}{wxdbtableplusplus
}
2465 \membersection{wxDbTable::GetNumberOfColumns
}\label{wxdbtablegetnumberofcolumns
}
2467 \func{bool
}{GetNumberOfColumns
}{}
2469 Accessor function that returns the number of columns that are statically
2470 bound for access by the wxDbTable instance.
2473 \membersection{wxDbTable::GetOrderByClause
}\label{wxdbtablegetorderbyclause
}
2475 \func{const char *
}{GetOrderByClause
}{}
2477 Accessor function that returns the current ORDER BY setting assigned with
2478 the
\helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
}.
2480 \wxheading{See also
}
2482 \helpref{wxDbTable::OrderBy
}{wxdbtableorderby
}
2485 \membersection{wxDbTable::GetPrev
}\label{wxdbtablegetprev
}
2487 \func{bool
}{GetPrev
}{\void}
2489 Retrieves the PREVIOUS row in the record set before the current cursor
2490 position as defined by the current query. Before retrieving records, a
2491 query must be performed using
\helpref{wxDbTable::Query
}{wxdbtablequery
},
2492 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2493 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2494 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2496 \wxheading{Return value
}
2498 This function returns FALSE when the current cursor has reached the beginning
2499 of the result set and there are now other rows prior to the cursors current
2500 position. When FALSE is returned, data in the bound columns is undefined.
2504 This function can only be used if the datasource connection used by the
2505 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2506 connection does not allow backward scrolling cursors, this function will
2507 return FALSE, and the data contained in the bound columns will be undefined.
2509 \wxheading{See also
}
2511 \helpref{wxDb::FwdOnlyCursors
}{wxdbfwdonlycursors
},
2512 \helpref{wxDbTable::--
}{wxdbtableminusminus
}
2515 \membersection{wxDbTable::GetQueryTableName
}\label{wxdbtablegetquerytablename
}
2517 \func{const char *
}{GetQueryTableName
}{}
2519 Accessor function that returns the name of the table/view that was indicated
2520 as being the table/view to query against when this wxDbTable instance was
2523 \wxheading{See also
}
2525 \helpref{wxDbTable constructor
}{wxdbtableconstr
}
2528 \membersection{wxDbTable::GetRowNum
}\label{wxdbtablegetrownum
}
2530 \func{UWORD
}{GetRowNum
}{\void}
2532 Returns the ODBC row number for performing positioned updates and deletes.
2536 This function is not being used within the ODBC class library and may be a
2537 candidate for removal if no use is found for it.
2539 Row nuumber with some datasources/ODBC drivers is the position in the result set,
2540 while in others it may be a physical position in the database. Check your
2541 database documentation to find out which behavior is supported.
2544 \membersection{wxDbTable::GetTableName
}\label{wxdbtablegettablename
}
2546 \func{const char *
}{GetTableName
}{}
2548 Accessor function that returns the name of the table that was indicated
2549 as being the table that this wxDbTable instance was associated with.
2552 \membersection{wxDbTable::GetTablePath
}\label{wxdbtablegettablepath
}
2554 \func{const char *
}{GetTablePath
}{}
2556 Accessor function that returns the path to the data table that was indicated
2557 during creation of this wxDbTable instance.
2561 Currently only applicable to dBase and MS-Access datasources.
2564 \membersection{wxDbTable::GetWhereClause
}\label{wxdbtablegetwhereclause
}
2566 \func{const char *
}{GetWhereClause
}{}
2568 Accessor function that returns the current WHERE setting assigned with the
2569 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2571 \wxheading{See also
}
2573 \helpref{wxDbTable::Where
}{wxdbtablewhere
}
2576 \membersection{wxDbTable::Insert
}\label{wxdbtableinsert
}
2578 \func{int
}{Insert
}{\void}
2580 Inserts a new record into the table being referenced by this wxDbTable
2581 instance. The values in the member variables of the wxDbTable instance are
2582 inserted into the columns of the new row in the database.
2584 \wxheading{Return value
}
2587 DB_SUCCESS Record inserted successfully (value =
1)
2589 DB_FAILURE Insert failed (value =
0)
2591 DB_ERR_INTEGRITY_CONSTRAINT_VIOL
2592 The insert failed due to an integrity
2593 constraint violation (duplicate non-unique
2594 index entry) is attempted.
2599 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2600 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
2601 this function to commit or rollback the insertion.
2606 // Incomplete code snippet
2607 strcpy(parts->PartName, "
10");
2608 strcpy(parts->PartDesc, "Part
#10");
2610 RETCODE retcode = parts.Insert();
2614 parts->GetDb()->CommitTrans();
2616 case DB_ERR_INTEGRITY_CONSTRAINT_VIOL:
2617 // Current data would result in a duplicate key
2618 // on one or more indexes that do not allow duplicates
2619 parts->GetDb()->RollbackTrans();
2622 // Insert failed for some unexpected reason
2623 parts->GetDb()->RollbackTrans();
2629 \membersection{wxDbTable::IsColNull
}\label{wxdbtableiscolnull
}
2631 \func{bool
}{IsColNull
}{\param{int
}{colNo
}}
2633 Used primarily in the ODBC class library to determine if a column is equal
2634 to "NULL". Works for all data types supported by the ODBC class library.
2636 \wxheading{Parameters
}
2638 \docparam{colNo
}{The column number of the bound column as defined by the
2639 \helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
2640 calls which defined the columns accesible to this wxDbTable instance.
}
2644 NULL column support is currently not fully implemented as of wxWindows
2.4
2647 \membersection{wxDbTable::IsCursorClosedOnCommit
}\label{wxdbtableiscursorclosedoncommit
}
2649 \func{bool
}{IsCursorClosedOnCommit
}{\void}
2651 Accessor function to return information collected during the opening of the
2652 datasource connection that is used by this wxDbTable instance. The result
2653 returned by this function indicates whether an implicit closing of the curosr is
2654 done after a commit on the database connection.
2656 \wxheading{Return value
}
2658 Returns TRUE if the cursor associated with this wxDbTable object is closed
2659 after a commit or rollback operation. Returns FALSE otherwise.
2663 If more than one wxDbTable instance used the same database connection, all cursors
2664 which use the database connection are closed on the commit if this function
2668 \membersection{wxDbTable::IsQueryOnly
}\label{wxdbtableisqueryonly
}
2670 \func{bool
}{IsQueryOnly
}{}
2672 Accessor function that returns a value indicating if this wxDbTable instance
2673 was created to allow only queries to be performed on the bound columns. If
2674 this function returns TRUE, then no actions may be performed using this
2675 wxDbTable instance that would modify (insert/delete/update) the table's data.
2678 \membersection{wxDbTable::Open
}\label{wxdbtableopen
}
2680 \func{bool
}{Open
}{\param{bool
}{checkPrivileges=FALSE
}}
2682 Every wxDbTable instance must be opened before it can be used. This function
2683 checks for the existence of the requested table, binds columns, creates required
2684 cursors, (insert/select and update if connection is not wxDB_QUERY_ONLY) and
2685 constructs the insert statement that is to be used for inserting data as a new
2686 row in the datasource.
2688 \wxheading{Parameters
}
2690 \docparam{checkPrivileges
}{Indicates whether the Open() function should check
2691 whether the current connected user has at least SELECT privileges to access the
2692 table to which they are trying to open. Default is FALSE.
}
2696 If the function returns a FALSE value due to the table not existing, a log
2697 entry is recorded for the datasource connection indicating the problem
2698 that was detected when checking for table existence. Note that it is usually
2699 best for the calling routine to check for the existence of the table and for
2700 sufficent user privileges to access the table in the mode (wxDB_QUERY_ONLY or
2701 !wxDB_QUERY_ONLY) before trying to open the table for the best possible
2702 explanation as to why a table cannot be opened.
2704 Checking the user's privileges on a table can be quite time consuming during
2705 the open phase. With most applications, the programmer already knows that the
2706 user has sufficient privileges to access the table, so this check is normally
2709 For best performance, open the table, and then use the
2710 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
} function
2711 to check the users privileges. Passing a schema to the TablePrivileges()
2712 function can significantly speed up the privileges checks.
2714 \wxheading{See also
}
2716 \helpref{wxDb::TableExists
}{wxdbtableexists
},
2717 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
}
2720 \membersection{wxDbTable::OrderBy
}\label{wxdbtableorderby
}
2722 \func{const char *
}{OrderBy
}{}
2724 \func{void
}{OrderBy
}{\param{const wxString &
}{OrderBy
}}
2726 Accessor function for the private class member wxDbTable::orderBy. Can be
2727 used as a synonym for
\helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
}
2728 (the first form of this function) or
\helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
}
2729 (the second form of this function).
2731 \wxheading{Parameters
}
2733 \docparam{OrderBy
}{A comma separated list of column names that indicate the
2734 alphabetized/numeric sorting sequence that the result set is to be returned
2735 in. If a FROM clause has also been specified, each column name specified in
2736 the ORDER BY clause should be prefaced with the table name to which the column
2737 belongs using DOT notation (TABLE_NAME.COLUMN_NAME).
}
2739 \wxheading{Return value
}
2741 The first form of this function returns the current value of the wxDbTable
2742 member variable ::orderBy.
2744 The second form of the function has no return value.
2746 \wxheading{See also
}
2748 \helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
},
2749 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}
2752 \membersection{wxDbTable::Query
}\label{wxdbtablequery
}
2754 \func{virtual bool
}{Query
}{\param{bool
}{forUpdate=FALSE
},
\param{bool
}{distinct=FALSE
}}
2756 \wxheading{Parameters
}
2758 \docparam{forUpdate
}{{\it OPTIONAL
}. Gives you the option of locking records
2759 as they are retrieved. If the RDBMS is not capable of the FOR UPDATE clause,
2760 this argument is ignored. See
2761 \helpref{wxDbTable::CanSelectForUpdate
}{wxdbtablecanselectforupdate
} for
2762 additional information regarding this argument. Default is FALSE.
}
2763 \docparam{distinct
}{{\it OPTIONAL
}. Allows selection of only distinct values
2764 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
2765 applies to all columns returned in the result set, not individual columns.
2770 This function queries records from the datasource based on the three
2771 wxDbTable members: "where", "orderBy", and "from". Use
2772 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
} to filter on
2773 records to be retrieved (e.g. All users with a first name of "JOHN").
2774 Use
\helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
} to
2775 change the sequence in which records are returned in the result set from
2776 the datasource (e.g. Ordered by LAST_NAME). Use
2777 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} to allow outer
2778 joining of the base table (the one being associated with this instance of
2779 wxDbTable) with other tables which share a related field.
2781 After each of these clauses are set/cleared, call wxDbTable::Query() to
2782 fetch the result set from the datasource.
2784 This scheme has an advantage if you have to requery your record set
2785 frequently in that you only have to set your WHERE, ORDER BY, and FROM
2786 clauses once. Then to refresh the record set, simply call wxDbTable::Query()
2787 as frequently as needed.
2789 Note that repeated calls to wxDbTable::Query() may tax the database
2790 server and make your application sluggish if done too frequently or
2793 The base table name is automatically prepended to the base column names in
2794 the event that the FROM clause has been set (is non-null) using
2795 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}.
2797 The cursor for the result set is positioned
{\it before
} the first record in
2798 the result set after the query. To retrieve the first record, call either
2799 \helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
} (only if backward scrolling
2800 cursors are available) or
2801 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}. Typically, no data from the
2802 result set is returned to the client driver until a request such as
2803 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
} is performed, so network
2804 traffic and database load are not overwhelmed transmitting data until the
2805 data is actually requested by the client. This behavior is solely dependent
2806 on the ODBC driver though, so refer to the ODBC driver's reference material
2807 for information on its behaviors.
2809 Values in the bound columns' memory variables are undefined after executing a
2810 call to this function and remain that way until a row in the result set is
2811 requested to be returned.
2813 The wxDbTable::Query() function is defined as "virtual" so that it may be
2814 overridden for application specific purposes.
2816 \normalbox{Be sure to set the wxDbTable's "where", "orderBy", and "from"
2817 member variables to "" if they are not to be used in the query. Otherwise,
2818 the results returned may have unexpected results (or no results) due to
2819 improper or incorrect query parameters constructed from the uninitialized
2825 // Incomplete code sample
2826 parts->SetWhereClause("DESCRIPTION = 'FOOD'");
2827 parts->SetOrderByClause("EXPIRATION_DATE");
2828 parts->SetFromClause("");
2829 // Query the records based on the where, orderBy and from clauses
2832 // Display all records queried
2833 while(parts->GetNext())
2834 dispPart(parts); // user defined function
2838 \membersection{wxDbTable::QueryBySqlStmt
}\label{wxdbtablequerybysqlstmt
}
2840 \func{bool
}{QueryBySqlStmt
}{\param{const char *
}{pSqlStmt
}}
2842 Performs a query against the datasource by accepting and passing verbatim the
2843 SQL SELECT statement passed to the function.
2845 \wxheading{Parameters
}
2847 \docparam{pSqlStmt
}{Pointer to the SQL SELECT statement to be executed.
}
2851 This is the most powerful form of the query functions available. This member
2852 function allows a programmer to write their own custom SQL SELECT statement
2853 for requesting data from the datasource. This gives the programmer access
2854 to the full power of SQL for performing operations such as scalar functions,
2855 aggregate functions, table joins, and sub-queries, as well as datasource
2856 specific function calls.
2858 The requirements of the SELECT statement are the following:
2861 1. Must return the correct number of columns. In the derived
2862 wxDbTable constructor, it is specified how many columns are in
2863 the wxDbTable object. The SELECT statement must return exactly
2866 2. The columns must be returned in the same sequence as specified
2867 when defining the bounds columns using wxDbTable::SetColDefs(),
2868 and the columns returned must be of the proper data type. For
2869 example, if column
3 is defined in the wxDbTable bound column
2870 definitions to be a float, the SELECT statement must return a
2871 float for column
3 (e.g. PRICE *
1.10 to increase the price by
2874 3. The ROWID can be included in your SELECT statement as the
{\bf last
}
2875 column selected, if the datasource supports it. Use
2876 wxDbTable::CanUpdByROWID() to determine if the ROWID can be
2877 selected from the datasource. If it can, much better
2878 performance can be achieved on updates and deletes by including
2879 the ROWID in the SELECT statement.
2882 Even though data can be selected from multiple tables (joins) in your select
2883 statement, only the base table associated with this wxDbTable object
2884 is automatically updated through the ODBC class library. Data from multiple
2885 tables can be selected for display purposes however. Include columns in
2886 the wxDbTable object and mark them as non-updateable (See
2887 \helpref{wxDbColDef
}{wxdbcoldef
} for details). This way columns can be
2888 selected and displayed from other tables, but only the base table will be
2889 updated automatically when performed through the
2890 \helpref{wxDbTable::Update
}{wxdbtableupdate
} function after using this type of
2891 query. To update tables other than the base table, use the
2892 \helpref{wxDbTable::Update
}{wxdbtableupdate
} function passing a SQL statement.
2894 After this function has been called, the cursor is positioned before the
2895 first record in the record set. To retrieve the first record, call
2896 either
\helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
} or
2897 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}.
2902 // Incomplete code samples
2903 strcpy(sqlStmt, "SELECT * FROM PARTS WHERE STORAGE_DEVICE = 'SD98' \
2904 AND CONTAINER =
12");
2905 // Query the records using the SQL SELECT statement above
2906 parts->QueryBySqlStmt(sqlStmt);
2907 // Display all records queried
2908 while(parts->GetNext())
2911 Example SQL statements
2912 ----------------------
2914 // Table Join returning
3 columns
2915 SELECT part_no, part_desc, sd_name
2916 from parts, storage_devices
2917 where parts.storage_device_id =
2918 storage_devices.storage_device_id
2920 // Aggregate function returning total number of
2921 // parts in container
99
2922 SELECT count
(*) from PARTS where container = 99
2924 // Order by clause; ROWID, scalar function
2925 SELECT part_no, substring(part_desc, 1, 10), qty_on_hand + 1, ROWID
2927 where warehouse = 10
2928 order by part_no desc // descending order
2932 where container in (select container
2933 from storage_devices
2934 where device_id = 12)
2938 \membersection{wxDbTable::QueryMatching}\label{wxdbtablequerymatching}
2940 \func{virtual bool}{QueryMatching}{\param{bool }{forUpdate=FALSE}, \param{bool }{distinct=FALSE}}
2942 QueryMatching allows querying of records from the table associated with
2943 the wxDbTable object by matching "columns" to values.
2945 For example: To query the datasource for the row with a PART_NUMBER column
2946 value of "32", clear all column variables of the wxDbTable object, set the
2947 PartNumber variable that is bound to the PART_NUMBER column in the wxDbTable
2948 object to "32", and then call wxDbTable::QueryMatching().
2950 \wxheading{Parameters}
2952 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
2953 as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
2954 the FOR UPDATE clause, this argument is ignored. See
2955 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
2956 additional information regarding this argument. Default is FALSE.}
2957 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
2958 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
2959 applies to all columns returned in the result set, not individual columns.
2964 The SQL WHERE clause is built by the ODBC class library based on all
2965 non-zero/non-NULL columns in your wxDbTable object. Matches can be on one,
2966 many or all of the wxDbTable's columns. The base table name is prepended
2967 to the column names in the event that the wxDbTable's FROM clause is non-null.
2969 This function cannot be used to perform queries which will check for
2970 columns that are 0 or NULL, as the automatically constructed WHERE clause
2971 only will contain comparisons on column member variables that are
2974 The primary difference between this function and \helpref{wxDbTable::QueryOnKeyFields}{wxdbtablequeryonkeyfields}
2975 is that this function can query on any column(s) in the wxDbTable object.
2976 Note however that this may not always be very efficient. Searching on
2977 non-indexed columns will always require a full table scan.
2979 The cursor is positioned before the first record in the record set after
2980 the query is performed. To retrieve the first record, the program must call
2981 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
2982 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
2984 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
2985 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
2991 // Incomplete code sample
2992 parts->ClearMemberVars(); // Set all columns to zero
2993 strcpy(parts->PartNumber,"32"); // Set columns to query on
2994 parts->OnHold = TRUE;
2995 parts->QueryMatching(); // Query
2996 // Display all records queried
2997 while(parts->GetNext())
2998 dispPart(parts); // Some application defined function
3002 \membersection{wxDbTable::QueryOnKeyFields}\label{wxdbtablequeryonkeyfields}
3004 \func{bool}{QueryOnKeyFields}{\param{bool }{forUpdate=FALSE}, \param{bool }{distinct=FALSE}}
3006 QueryOnKeyFields provides an easy mechanism to query records in the table
3007 associated with the wxDbTable object by the primary index column(s). Simply
3008 assign the primary index column(s) values and then call this member function
3009 to retrieve the record.
3011 Note that since primary indexes are always unique, this function implicitly
3012 always returns a single record from the database. The base table name is
3013 prepended to the column names in the event that the wxDbTable's FROM clause
3016 \wxheading{Parameters}
3018 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
3019 as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
3020 the FOR UPDATE clause, this argument is ignored. See
3021 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
3022 additional information regarding this argument. Default is FALSE.}
3023 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
3024 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
3025 applies to all columns returned in the result set, not individual columns.
3030 The cursor is positioned before the first record in the record set after
3031 the query is performed. To retrieve the first record, the program must call
3032 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
3033 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
3035 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
3036 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
3042 // Incomplete code sample
3043 strcpy(parts->PartNumber, "32");
3044 parts->QueryOnKeyFields();
3045 // Display all records queried
3046 while(parts->GetNext())
3047 dispPart(parts); // Some application defined function
3051 \membersection{wxDbTable::Refresh}\label{wxdbtablerefresh}
3053 \func{bool}{Refresh}{\void}
3055 This function re-reads the bound columns into the memory variables, setting
3056 them to the current values stored on the disk.
3058 The cursor position and result set are unaffected by calls to this function.
3059 (The one exception is in the case where the record to be refreshed has been
3060 deleted by some other user or transaction since it was originally retrieved
3061 as part of the result set. For most datasources, the default behavior in
3062 this situation is to return the value that was originally queried for the
3063 result set, even though it has been deleted from the database. But this is
3064 datasource dependent, and should be tested before relying on this behavior.)
3068 This routine is only guaranteed to work if the table has a unique primary
3069 index defined for it. Otherwise, more than one record may be fetched and
3070 there is no guarantee that the correct record will be refreshed. The
3071 table's columns are refreshed to reflect the current data in the database.
3074 \membersection{wxDbTable::SetColDefs}\label{wxdbtablesetcoldefs}
3076 \func{void}{SetColDefs}{\param{int }{index}, \param{const char *}{fieldName}, \param{int }{dataType}, \param{void *}{pData}, \param{int }{cType}, \param{int }{size}, \param{bool }{keyField = FALSE}, \param{bool }{upd = TRUE}, \param{bool }{insAllow = TRUE}, \param{bool }{derivedCol = FALSE}}
3078 \func{wxDbColDataPtr *}{SetColDefs}{\param{wxDbColInf *}{colInfs}, \param{ULONG }{numCols}}
3080 \wxheading{Parameters}
3082 \docparam{index}{Column number (0 to n-1, where n is the number of columns
3083 specified as being defined for this wxDbTable instance when the
3084 wxDbTable constructor was called.}
3085 \docparam{fieldName}{Column name from the associated data table.}
3086 \docparam{dataType}{Logical data type. Valid logical types include:}
3089 DB_DATA_TYPE_VARCHAR : strings
3090 DB_DATA_TYPE_INTEGER : non-floating point numbers
3091 DB_DATA_TYPE_FLOAT : floating point numbers
3092 DB_DATA_TYPE_DATE : dates
3095 \docparam{pData}{Pointer to the data object that will hold the column's
3096 value when a row of data is returned from the datasource.}
3097 \docparam{cType}{SQL C Type. This defines the data type that the SQL
3098 representation of the data is converted to to be stored in {\it pData}.
3099 Other valid types are available also, but these are the most common ones:}
3102 SQL_C_CHAR // strings
3112 SQL_C_BOOLEAN // defined in db.h
3113 SQL_C_ENUM // defined in db.h
3116 \docparam{size}{Maximum size in bytes of the {\it pData} object.}
3117 \docparam{keyField}{{\it OPTIONAL}. Indicates if this column is part of the
3118 primary index. Default is FALSE.}
3119 \docparam{upd}{{\it OPTIONAL}. Are updates allowed on this column?
3121 \docparam{insAllow}{{\it OPTIONAL}. Inserts allowed on this column?
3123 \docparam{derivedCol}{{\it OPTIONAL}. Is this a derived column (non-base
3124 table column for query only)? Default is FALSE.}
3126 \docparam{colInfs}{Pointer to an array of wxDbColInf instances which contains
3127 all the information necessary to create {\it numCols} column definitions.}
3128 \docparam{numCols}{Number of elements of wxDbColInf type that are pointed
3129 to by {\it colInfs}, which are to have column definitions created from them.}
3133 If {\it pData} is to hold a string of characters, be sure to include enough
3134 space for the NULL terminator in pData and in the byte count of {\it size}.
3136 Both forms of this function provide a shortcut for defining the columns in
3137 your wxDbTable object. Use this function in any derived wxDbTable
3138 constructor when describing the column/columns in the wxDbTable object.
3140 The second form of this function is primarily used when the
3141 \helpref{wxDb::GetColumns}{wxdbgetcolumns} function was used to query the
3142 datasource for the column definitions, so that the column definitions are
3143 already stored in wxDbColInf form. One example use of using
3144 \helpref{wxDb::GetColumns}{wxdbgetcolumns} then using this function is if
3145 a data table existed in one datasource, and the table's column definitions
3146 were to be copied over to another datasource or table.
3151 // Long way not using this function
3152 strcpy(colDefs[0].ColName, "PART_NO");
3153 colDefs[0].DbDataType = DB_DATA_TYPE_VARCHAR;
3154 colDefs[0].PtrDataObj = PartNumber;
3155 colDefs[0].SqlCtype = SQL_C_CHAR;
3156 colDefs[0].SzDataObj = PART_NUMBER_LEN;
3157 colDefs[0].KeyField = TRUE;
3158 colDefs[0].Updateable = FALSE;
3159 colDefs[0].InsertAllowed= TRUE;
3160 colDefs[0].DerivedCol = FALSE;
3162 // Shortcut using this function
3163 SetColDefs(0, "PART_NUMBER", DB_DATA_TYPE_VARCHAR, PartNumber,
3164 SQL_C_CHAR, PART_NUMBER_LEN, TRUE, FALSE,TRUE,FALSE);
3168 \membersection{wxDbTable::SetCursor}\label{wxdbtablesetcursor}
3170 \func{bool}{SetCursor}{\param{HSTMT *}{hstmtActivate = (void **) wxDB_DEFAULT_CURSOR
}}
3172 \wxheading{Parameters
}
3174 \docparam{hstmtActivate
}{{\it OPTIONAL
}. Pointer to the cursor that is to
3175 become the current cursor. Passing no cursor handle will reset the cursor
3176 back to the wxDbTable's default (original) cursor that was created when the
3177 wxDbTable instance was first created. Default is wxDB_DEFAULT_CURSOR.
}
3181 When swapping between cursors, the member variables of the wxDbTable object
3182 are automatically refreshed with the column values of the row that the
3183 current cursor is positioned at (if any). If the cursor is not positioned,
3184 then the data in member variables is undefined.
3186 The only way to return back to the cursor that was in use before this
3187 function was called is to programmatically determine the current cursor's HSTMT
3188 {\bf BEFORE
} calling this function using
\helpref{wxDbTable::GetCursor
}{wxdbtablegetcursor
}
3189 and saving a pointer to that cursor.
3191 \wxheading{See also
}
3193 \helpref{wxDbTable::GetNewCursor
}{wxdbtablegetnewcursor
},
\helpref{wxDbTable::GetCursor
}{wxdbtablegetcursor
},
3194 \helpref{wxDbTable::SetCursor
}{wxdbtablesetcursor
}
3197 \membersection{wxDbTable::SetFromClause
}\label{wxdbtablesetfromclause
}
3199 \func{void
}{SetFromClause
}{\param{const wxString &
}{From
}}
3201 Accessor function for setting the private class member wxDbTable::from
3202 that indicates what other tables should be outer joined with the wxDbTable's
3203 base table for access to the columns in those other tables.
3205 Synonym to this function is one form of
\helpref{wxDbTable::From
}{wxdbtablefrom
}
3207 \wxheading{Parameters
}
3209 \docparam{From
}{A comma separated list of table names that are to be outer
3210 joined with the base table's columns so that the joined table's columns
3211 may be returned in the result set or used as a portion of a comparison with
3212 the base table's columns. NOTE that the base tables name must NOT be included
3213 in the FROM clause, as it is automatically included by the wxDbTable class
3214 in constructing query statements.
}
3218 Used by the
\helpref{wxDbTable::Query
}{wxdbtablequery
} and
3219 \helpref{wxDbTable::Count
}{wxdbtablecount
} member functions to allow outer
3220 joining of records from multiple tables.
3222 Do
{\bf not
} include the keyword "FROM" when setting the FROM clause.
3224 If using the FROM clause when performing a query, be certain to include in
3225 the corresponding WHERE clause a comparison of a column from either the base
3226 table or one of the other joined tables to each other joined table to ensure
3227 the datasource knows on which column values the tables should be joined on.
3233 // Base table is the "LOCATION" table, and it is being
3234 // outer joined to the "PART" table via the the field "PART_NUMBER"
3235 // that can be related between the two tables.
3236 location->SetWhereClause("LOCATION.PART_NUMBER = PART.PART_NUMBER")
3237 location->SetFromClause("PART");
3241 \wxheading{See also
}
3243 \helpref{wxDbTable::From
}{wxdbtablefrom
},
3244 \helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
}
3247 \membersection{wxDbTable::SetColNull
}\label{wxdbtablesetcolnull
}
3249 \func{bool
}{SetColNull
}{\param{int
}{colNo
},
\param{bool
}{set=TRUE
}}
3251 \func{bool
}{SetColNull
}{\param{const char *
}{colName
},
\param{bool
}{set=TRUE
}}
3253 Both forms of this function allow a member variable representing a column
3254 in the table associated with this wxDbTable object to be set to NULL.
3256 The first form allows the column to be set by the index into the column
3257 definitions used to create the wxDbTable instance, while the second allows
3258 the actual column name to be specified.
3260 \wxheading{Parameters
}
3262 \docparam{colNo
}{Index into the column definitions used when first defining
3263 this wxDbTable object.
}
3264 \docparam{colName
}{Actual data table column name that is to be set to NULL.
}
3265 \docparam{set
}{Whether the column is set to NULL or not. Passing TRUE sets
3266 the column to NULL, passing FALSE sets the column to be non-NULL. Default is
3272 No database updates are done by this function. It only operates on the
3273 member variables in memory. Use and insert or update function to store this
3277 \membersection{wxDbTable::SetOrderByClause
}\label{wxdbtablesetorderbyclause
}
3279 \func{void
}{SetOrderByClause
}{\param{const wxString &
}{OrderBy
}}
3281 Accessor function for setting the private class member wxDbTable::orderBy
3282 which determines sequence/ordering of the rows returned in the result set
3285 A synonym to this function is one form of the function
\helpref{wxDbTable::OrderBy
}{wxdbtableorderby
}
3287 \wxheading{Parameters
}
3289 \docparam{OrderBy
}{A comma separated list of column names that indicate the
3290 alphabetized sorting sequence that the result set is to be returned in. If
3291 a FROM clause has also been specified, each column name specified in the
3292 ORDER BY clause should be prefaced with the table name to which the column
3293 belongs using DOT notation (TABLE_NAME.COLUMN_NAME).
}
3297 Do
{\bf not
} include the keywords "ORDER BY" when setting the ORDER BY clause.
3303 parts->SetOrderByClause("PART_DESCRIP, QUANTITY");
3307 location->SetOrderByClause("LOCATION.POSITION, PART.PART_NUMBER);
3311 \wxheading{See also
}
3313 \helpref{wxDbTable::OrderBy
}{wxdbtableorderby
},
3314 \helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
}
3317 \membersection{wxDbTable::SetQueryTimeout
}\label{wxdbtablesetquerytimeout
}
3319 \func{bool
}{SetQueryTimeout
}{\param{UDWORD
}{nSeconds
}}
3321 Allows a time period to be set as the timeout period for queries.
3323 \wxheading{Parameters
}
3325 \docparam{nSeconds
}{The number of seconds to wait for the query to complete
3330 Neither Oracle or Access support this function as of yet. Other databases
3331 should be evaluated for support before depending on this function working
3335 \membersection{wxDbTable::SetWhereClause
}\label{wxdbtablesetwhereclause
}
3337 \func{void
}{SetWhereClause
}{\param{const wxString &
}{Where
}}
3339 Accessor function for setting the private class member wxDbTable::where
3340 that determines which rows are returned in the result set by the datasource.
3342 A synonym to this function is one form of the function
\helpref{wxDbTable::Where
}{wxdbtablewhere
}
3344 \wxheading{Parameters
}
3346 \docparam{Where
}{SQL "where" clause. This clause can contain any SQL language
3347 that is legal in standard where clauses. If a FROM clause has also been
3348 specified, each column name specified in the ORDER BY clause should be
3349 prefaced with the table name to which the column belongs using DOT notation
3350 (TABLE_NAME.COLUMN_NAME).
}
3354 Do
{\bf not
} include the keywords "WHERE" when setting the WHERE clause.
3360 // Simple where clause
3361 parts->SetWhereClause("PART_NUMBER = '
32'");
3363 // Any comparison operators
3364 parts->SetWhereClause("PART_DESCRIP LIKE 'HAMMER
%'");
3366 // Multiple comparisons, including a function call
3367 parts->Where("QTY >
0 AND
{fn UCASE(PART_DESCRIP)
} LIKE '
%DRILL%'");
3369 // Using parameters and multiple logical combinations
3370 parts->Where("((QTY >
10) OR (ON_ORDER >
0)) AND ON_HOLD =
0");
3372 // This query uses an outer join (requiring a FROM clause also)
3373 // that joins the PART and LOCATION table on he common field
3375 parts->Where("PART.ON_HOLD =
0 AND \
3376 PART.PART_NUMBER = LOCATION.PART_NUMBER AND \
3377 LOCATION.PART_NUMBER >
0");
3380 \wxheading{See also
}
3382 \helpref{wxDbTable::Where
}{wxdbtablewhere
},
3383 \helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
}
3386 \membersection{wxDbTable::Update
}\label{wxdbtableupdate
}
3388 \func{bool
}{Update
}{\void}
3390 \func{bool
}{Update
}{\param{const char *
}{pSqlStmt
}}
3392 The first form of this function will update the row that the current cursor
3393 is currently positioned at with the values in the memory variables that
3394 are bound to the columns. The actual SQL statement to perform the update
3395 is automatically created by the ODBC class, and then executed.
3397 The second form of the function allows full access through SQL statements for
3398 updating records in the database. Write any valid SQL UPDATE statement and
3399 submit it to this function for execution. Sophisticated updates can be
3400 performed using the full power of the SQL dialect. The full SQL statement
3401 must have the exact syntax required by the driver/datasource for performing
3402 the update. This usually is in the form of:
3405 UPDATE tablename SET col1=X, col2=Y, ... where ...
3408 \wxheading{Parameters
}
3410 \docparam{pSqlStmt
}{Pointer to SQL UPDATE statement to be executed.
}
3414 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
3415 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
3416 this function to commit or rollback the update.
3421 strcpy(sqlStmt, "update PART set QTY =
0 where PART_NUMBER = '
32'");
3425 \membersection{wxDbTable::UpdateWhere
}\label{wxdbtableupdatewhere
}
3427 \func{bool
}{UpdateWhere
}{\param{const char *
}{pWhereClause
}}
3429 Performs updates to the base table of the wxDbTable object, updating only the
3430 rows which match the criteria specified in the
{\it pWhereClause
}.
3432 All columns that are bound to member variables for this wxDbTable instance
3433 that were defined with the "updateable" parameter set to TRUE will be updated
3434 with the information currently held in the memory variable.
3436 \wxheading{Parameters
}
3438 \docparam{pWhereClause
}{Pointer to a valid SQL WHERE clause. Do not
3439 include the keyword 'WHERE'.
}
3443 Care should be used when updating columns that are part of indexes with
3444 this function so as not to violate an unique key constraints.
3446 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
3447 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
3448 this function to commit or rollback the update(s).
3451 \membersection{wxDbTable::Where
}\label{wxdbtablewhere
}
3453 \func{const char *
}{Where
}{}
3455 \func{void
}{Where
}{\param{const wxString&
}{Where
}}
3457 Accessor function for the private class member wxDbTable::where. Can be used
3458 as a synonym for
\helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
}
3459 (the first form of this function) to return the current where clause or
3460 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
} (the second form
3461 of this function) to set the where clause for this table instance.
3463 \wxheading{Parameters
}
3465 \docparam{Where
}{A valid SQL WHERE clause. Do not include the keyword 'WHERE'.
}
3467 \wxheading{Return value
}
3469 The first form of this function returns the current value of the wxDbTable
3470 member variable ::where.
3472 The second form of the function has no return value, as it will always set
3473 the where clause successfully.
3475 \wxheading{See also
}
3477 \helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
},
3478 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
3482 \membersection{wxDbTable::operator $++$
}\label{wxdbtableplusplus
}
3484 \func{bool
}{operator $++$
}{\void}
3486 Synonym for
\helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}
3488 \wxheading{See also
}
3490 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}
3493 \membersection{wxDbTable::operator $--$
}\label{wxdbtableminusminus
}
3495 \func{bool
}{operator $--$
}{\void}
3497 Synonym for
\helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
}
3499 \wxheading{See also
}
3501 \helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
}
3504 \section{\class{wxDbTableInf
}}\label{wxdbtableinf
}
3509 tableRemarks
[0] =
0;
3515 Currently only used by
\helpref{wxDb::GetCatalog
}{wxdbgetcatalog
} internally
3516 and
\helpref{wxDbInf
}{wxdbinf
} class, but may be used in future releases for
3517 user functions. Contains information describing the table (Name, type, etc).
3518 A pointer to a wxDbColInf array instance is included so a program can create a
3519 \helpref{wxDbColInf
}{wxdbcolinf
} array instance (using
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
})
3520 to maintain all information about the columns of a table in one memory