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.
10 \wxheading{Include files
}
15 \wxheading{Helper classes and data structures
}
17 The following classes and structs are defined in db.cpp/.h for use with the wxDb class.
19 \begin{itemize
}\itemsep=
0pt
20 \item \helpref{wxDbColFor
}{wxdbcolfor
}
21 \item \helpref{wxDbColInf
}{wxdbcolinf
}
22 \item \helpref{wxDbTableInf
}{wxdbtableinf
}
23 \item \helpref{wxDbInf
}{wxdbinf
}
29 NOTE: In a future release, all ODBC class constants will be prefaced with 'wx'
33 wxDB_PATH_MAX Maximum path length allowed to be passed to
34 the ODBC driver to indicate where the data
37 DB_MAX_COLUMN_NAME_LEN Maximum supported length for the name of a
40 DB_MAX_ERROR_HISTORY Maximum number of error messages retained in
41 the queue before being overwritten by new
44 DB_MAX_ERROR_MSG_LEN Maximum supported length of an error message
45 returned by the ODBC classes
47 DB_MAX_STATEMENT_LEN Maximum supported length for a complete SQL
48 statement to be passed to the ODBC driver
50 DB_MAX_TABLE_NAME_LEN Maximum supported length for the name of a
53 DB_MAX_WHERE_CLAUSE_LEN Maximum supported WHERE clause length that
54 can be passed to the ODBC driver
56 DB_TYPE_NAME_LEN Maximum length of the name of a column's
61 \subsection{Enumerated types
}\label{wxdbenumeratedtypes
}
62 \wxheading{Enumerated types
}
64 \docparam{enum
{\bf wxDbSqlLogState
}}{sqlLogOFF, sqlLogON
}
66 {\it enum
{\bf wxDBMS
}}
68 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.
73 dbmsSYBASE_ASA // Adaptive Server Anywhere
74 dbmsSYBASE_ASE // Adaptive Server Enterprise
86 See the remarks in
\helpref{wxDb::Dbms
}{wxdbdbms
} for exceptions/issues with each of these database engines.
89 \wxheading{Public member variables
}
91 \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.
}
93 \docparam{int
{\bf wxDb::DB
\_STATUS}}{The last ODBC error/status that occurred on this data connection. Possible codes are:
}
96 DB_ERR_GENERAL_WARNING // SqlState = '
01000'
97 DB_ERR_DISCONNECT_ERROR // SqlState = '
01002'
98 DB_ERR_DATA_TRUNCATED // SqlState = '
01004'
99 DB_ERR_PRIV_NOT_REVOKED // SqlState = '
01006'
100 DB_ERR_INVALID_CONN_STR_ATTR // SqlState = '
01S00'
101 DB_ERR_ERROR_IN_ROW // SqlState = '
01S01'
102 DB_ERR_OPTION_VALUE_CHANGED // SqlState = '
01S02'
103 DB_ERR_NO_ROWS_UPD_OR_DEL // SqlState = '
01S03'
104 DB_ERR_MULTI_ROWS_UPD_OR_DEL // SqlState = '
01S04'
105 DB_ERR_WRONG_NO_OF_PARAMS // SqlState = '
07001'
106 DB_ERR_DATA_TYPE_ATTR_VIOL // SqlState = '
07006'
107 DB_ERR_UNABLE_TO_CONNECT // SqlState = '
08001'
108 DB_ERR_CONNECTION_IN_USE // SqlState = '
08002'
109 DB_ERR_CONNECTION_NOT_OPEN // SqlState = '
08003'
110 DB_ERR_REJECTED_CONNECTION // SqlState = '
08004'
111 DB_ERR_CONN_FAIL_IN_TRANS // SqlState = '
08007'
112 DB_ERR_COMM_LINK_FAILURE // SqlState = '
08S01'
113 DB_ERR_INSERT_VALUE_LIST_MISMATCH // SqlState = '
21S01'
114 DB_ERR_DERIVED_TABLE_MISMATCH // SqlState = '
21S02'
115 DB_ERR_STRING_RIGHT_TRUNC // SqlState = '
22001'
116 DB_ERR_NUMERIC_VALUE_OUT_OF_RNG // SqlState = '
22003'
117 DB_ERR_ERROR_IN_ASSIGNMENT // SqlState = '
22005'
118 DB_ERR_DATETIME_FLD_OVERFLOW // SqlState = '
22008'
119 DB_ERR_DIVIDE_BY_ZERO // SqlState = '
22012'
120 DB_ERR_STR_DATA_LENGTH_MISMATCH // SqlState = '
22026'
121 DB_ERR_INTEGRITY_CONSTRAINT_VIOL // SqlState = '
23000'
122 DB_ERR_INVALID_CURSOR_STATE // SqlState = '
24000'
123 DB_ERR_INVALID_TRANS_STATE // SqlState = '
25000'
124 DB_ERR_INVALID_AUTH_SPEC // SqlState = '
28000'
125 DB_ERR_INVALID_CURSOR_NAME // SqlState = '
34000'
126 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL // SqlState = '
37000'
127 DB_ERR_DUPLICATE_CURSOR_NAME // SqlState = '
3C000'
128 DB_ERR_SERIALIZATION_FAILURE // SqlState = '
40001'
129 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2 // SqlState = '
42000'
130 DB_ERR_OPERATION_ABORTED // SqlState = '
70100'
131 DB_ERR_UNSUPPORTED_FUNCTION // SqlState = 'IM001'
132 DB_ERR_NO_DATA_SOURCE // SqlState = 'IM002'
133 DB_ERR_DRIVER_LOAD_ERROR // SqlState = 'IM003'
134 DB_ERR_SQLALLOCENV_FAILED // SqlState = 'IM004'
135 DB_ERR_SQLALLOCCONNECT_FAILED // SqlState = 'IM005'
136 DB_ERR_SQLSETCONNECTOPTION_FAILED // SqlState = 'IM006'
137 DB_ERR_NO_DATA_SOURCE_DLG_PROHIB // SqlState = 'IM007'
138 DB_ERR_DIALOG_FAILED // SqlState = 'IM008'
139 DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL // SqlState = 'IM009'
140 DB_ERR_DATA_SOURCE_NAME_TOO_LONG // SqlState = 'IM010'
141 DB_ERR_DRIVER_NAME_TOO_LONG // SqlState = 'IM011'
142 DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR // SqlState = 'IM012'
143 DB_ERR_TRACE_FILE_ERROR // SqlState = 'IM013'
144 DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS // SqlState = 'S0001'
145 DB_ERR_TABLE_NOT_FOUND // SqlState = 'S0002'
146 DB_ERR_INDEX_ALREADY_EXISTS // SqlState = 'S0011'
147 DB_ERR_INDEX_NOT_FOUND // SqlState = 'S0012'
148 DB_ERR_COLUMN_ALREADY_EXISTS // SqlState = 'S0021'
149 DB_ERR_COLUMN_NOT_FOUND // SqlState = 'S0022'
150 DB_ERR_NO_DEFAULT_FOR_COLUMN // SqlState = 'S0023'
151 DB_ERR_GENERAL_ERROR // SqlState = 'S1000'
152 DB_ERR_MEMORY_ALLOCATION_FAILURE // SqlState = 'S1001'
153 DB_ERR_INVALID_COLUMN_NUMBER // SqlState = 'S1002'
154 DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE // SqlState = 'S1003'
155 DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE // SqlState = 'S1004'
156 DB_ERR_OPERATION_CANCELLED // SqlState = 'S1008'
157 DB_ERR_INVALID_ARGUMENT_VALUE // SqlState = 'S1009'
158 DB_ERR_FUNCTION_SEQUENCE_ERROR // SqlState = 'S1010'
159 DB_ERR_OPERATION_INVALID_AT_THIS_TIME // SqlState = 'S1011'
160 DB_ERR_INVALID_TRANS_OPERATION_CODE // SqlState = 'S1012'
161 DB_ERR_NO_CURSOR_NAME_AVAIL // SqlState = 'S1015'
162 DB_ERR_INVALID_STR_OR_BUF_LEN // SqlState = 'S1090'
163 DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE // SqlState = 'S1091'
164 DB_ERR_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1092'
165 DB_ERR_INVALID_PARAM_NO // SqlState = 'S1093'
166 DB_ERR_INVALID_SCALE_VALUE // SqlState = 'S1094'
167 DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE // SqlState = 'S1095'
168 DB_ERR_INF_TYPE_OUT_OF_RANGE // SqlState = 'S1096'
169 DB_ERR_COLUMN_TYPE_OUT_OF_RANGE // SqlState = 'S1097'
170 DB_ERR_SCOPE_TYPE_OUT_OF_RANGE // SqlState = 'S1098'
171 DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE // SqlState = 'S1099'
172 DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1100'
173 DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1101'
174 DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE // SqlState = 'S1103'
175 DB_ERR_INVALID_PRECISION_VALUE // SqlState = 'S1104'
176 DB_ERR_INVALID_PARAM_TYPE // SqlState = 'S1105'
177 DB_ERR_FETCH_TYPE_OUT_OF_RANGE // SqlState = 'S1106'
178 DB_ERR_ROW_VALUE_OUT_OF_RANGE // SqlState = 'S1107'
179 DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE // SqlState = 'S1108'
180 DB_ERR_INVALID_CURSOR_POSITION // SqlState = 'S1109'
181 DB_ERR_INVALID_DRIVER_COMPLETION // SqlState = 'S1110'
182 DB_ERR_INVALID_BOOKMARK_VALUE // SqlState = 'S1111'
183 DB_ERR_DRIVER_NOT_CAPABLE // SqlState = 'S1C00'
184 DB_ERR_TIMEOUT_EXPIRED // SqlState = 'S1T00'
187 \docparam{struct
{\bf wxDb::dbInf
}}{This structure is internal to the
188 wxDb class and contains details of the ODBC datasource that the current
189 instance of the wxDb is connected to in its members. When the datasource
190 is opened, all of the information contained in the dbInf structure is
191 queried from the datasource. This information is used almost exclusively
192 within the ODBC class library. Where there may be a need for particular
193 portions of this information outside of the class library, member
195 \helpref{wxDbTable::IsCursorClosedOnCommit
}{wxdbtableiscursorclosedoncommit
})
196 have been added for ease of use.
}
199 wxChar dbmsName
[40] - Name of the dbms product
200 wxChar dbmsVer
[64] - Version # of the dbms product
201 wxChar driverName
[40] - Driver name
202 wxChar odbcVer
[60] - ODBC version of the driver
203 wxChar drvMgrOdbcVer
[60] - ODBC version of the driver manager
204 wxChar driverVer
[60] - Driver version
205 wxChar serverName
[80] - Server Name, typically a connect string
206 wxChar databaseName
[128] - Database filename
207 wxChar outerJoins
[2] - Does datasource support outer joins
208 wxChar procedureSupport
[2] - Does datasource support stored
210 UWORD maxConnections - Maximum # of connections datasource
212 UWORD maxStmts - Maximum # of HSTMTs per HDBC
213 UWORD apiConfLvl - ODBC API conformance level
214 UWORD cliConfLvl - Is datasource SAG compliant
215 UWORD sqlConfLvl - SQL conformance level
216 UWORD cursorCommitBehavior - How cursors are affected on db commit
217 UWORD cursorRollbackBehavior - How cursors are affected on db
219 UWORD supportNotNullClause - Does datasource support NOT NULL
221 wxChar supportIEF
[2] - Integrity Enhancement Facility (Ref.
223 UDWORD txnIsolation - Transaction isolation level supported by
225 UDWORD txnIsolationOptions - Transaction isolation level options
227 UDWORD fetchDirections - Fetch directions supported
228 UDWORD lockTypes - Lock types supported in SQLSetPos
229 UDWORD posOperations - Position operations supported in
231 UDWORD posStmts - Position statements supported
232 UDWORD scrollConcurrency - Scrollable cursor concurrency options
234 UDWORD scrollOptions - Scrollable cursor options supported
235 UDWORD staticSensitivity - Can additions/deletions/updates be
237 UWORD txnCapable - Indicates if datasource supports
239 UDWORD loginTimeout - Number seconds to wait for a login
243 \docparam{wxChar
{\bf wxDb::errorList
}[DB_MAX_ERROR_HISTORY
][DB_MAX_ERROR_MSG_LEN
]}{The last n ODBC errors that have occurred on this database connection.
}
245 \docparam{wxChar
{\bf wxDb::errorMsg
}[SQL_MAX_MESSAGE_LENGTH
]}{This member variable is populated as a result of calling
\helpref{wxDb::GetNextError
}{wxdbgetnexterror
}. It contains the ODBC error message text.
}
247 \docparam{SDWORD
{\bf wxDb::nativeError
}}{Set by wxDb::DispAllErrors,
248 wxDb::GetNextError, and wxDb::DispNextError. It contains the
249 datasource-specific error code returned by the datasource to the ODBC driver.
250 Used for reporting ODBC errors.
}
252 \docparam{wxChar
{\bf wxDb::sqlState
}[20]}{Set by wxDb::TranslateSqlState().
253 Indicates the error state after a failed ODBC operation. Used for reporting
258 Default cursor scrolling is defined by wxODBC_FWD_ONLY_CURSORS in setup.h
259 when the wxWindows library is built. This behavior can be overridden when
260 an instance of a wxDb is created (see
\helpref{wxDb constructor
}{wxdbconstr
}).
261 Default setting of this value TRUE, as not all databases/drivers support
262 both types of cursors.
266 \helpref{wxDbColFor
}{wxdbcolfor
},
\helpref{wxDbColInf
}{wxdbcolinf
},
267 \helpref{wxDbTable
}{wxdbtable
},
\helpref{wxDbTableInf
}{wxdbtableinf
},
268 \helpref{wxDbInf
}{wxdbinf
}
270 \subsection{Associated non-class functions
}\label{wxdbfunctions
}
272 The following functions are used in conjunction with the wxDb class.
275 \func{wxDb *
}{wxDbGetConnection
}{\param{wxDbConnectInf *
}{pDbConfig
},
276 \param{bool
}{FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS
}}
280 This function is used to request a "new" wxDb instance for use by the program.
281 The wxDb instance returned is also opened (see
\helpref{wxDb::Open
}{wxdbopen
}).
283 This function (along with wxDbFreeConnection() and wxDbCloseConnection())
284 maintain a cached of wxDb instances for user/re-use by a program. When a
285 program needs a wxDb instance, it may call this function to obtain a wxDb
286 instance. If there is a wxDb instance in the cache that is currently unused
287 that matches the connection requirements specified in
{\it'pDbConfig'
} then
288 that cached connection is marked as no longer being free, and a pointer to
289 the wxDb instance is returned.
291 If there are no connections available in the cache that meet the requirements
292 given in
{\it'pDbConfig'
}, then a new wxDb instance is created to connect
293 to the datasource specified in
{\it'pDbConfig'
} using the userID and password
294 given in
{\it'pDbConfig'
}.
296 NOTE: The caching routine also uses the
\helpref{wxDb::Open
}{wxdbopen
}
297 connection datatype copying code. If the call to wxDbGetConnection()
298 requests a connection to a datasource, and there is not one available in the
299 cache, a new connection is created. But when the connection is opened,
300 instead of polling the datasource over again for its datatypes, if a
301 connection to the same datasource (using the same userID/password) has already
302 been done previously, the new connection skips querying the datasource for
303 its datatypes, and uses the same datatypes determined previously by the
304 other connection(s) for that same datasource. This cuts down greatly on
305 network traffic, database load, and connection creation time.
307 When the program is done using a connection created through a call to
308 wxDbGetConnection(), the program should call wxDbFreeConnection() to release
309 the wxDb instance back to the cache. DO NOT DELETE THE wxDb INSTANCE!
310 Deleting the wxDb instance returned can cause a crash/memory corruption
311 later in the program when the cache is cleaned up.
313 When exiting the program, call wxDbCloseConnections() to close all the
314 cached connections created by calls to wxDbGetConnection().
317 \func{bool
}{wxDbFreeConnection
}{\param{wxDb *
}{pDb
}}
321 Searches the list of cached database connections connection for one matching
322 the passed in wxDb instance. If found, that cached connection is freed.
324 Freeing a connection means that it is marked as available (free) in the
325 cache of connections, so that a call to
\helpref{wxDbGetConnection
}{wxdbfunctions
}
326 is able to return a pointer to the wxDb instance for use. Freeing a
327 connection does NOT close the connection, it only makes the connection
331 \func{void
}{wxDbCloseConnections
}{\void}
335 Closes all cached connections that have been made through use of the
336 \helpref{wxDbGetConnection
}{wxdbfunctions
} function.
338 NOTE: These connections are closed regardless of whether they are in use
339 or not. This function should only be called after the program has
340 finished using the connections and all wxDbTable instances that use any of
341 the connections have been closed.
343 This function performs a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
344 on the connection before closing it to commit any changes that are still
345 pending, as well as to avoid any function sequence errors upon closing
349 \func{int
}{wxDbConnectionsInUse
}{\void}
353 Returns a count of how many database connections are currently free ( not
354 being used) that have been cached through use of the
\helpref{wxDbGetConnection
}{wxdbfunctions
}
358 \func{bool
}{wxDbSqlLog
}{\param{wxDbSqlLogState
}{state
},
\param{const wxString &
}{filename = SQL_LOG_FILENAME
}}
362 This function sets the sql log state for all open wxDb objects
365 \func{bool
}{wxDbGetDataSource
}{\param{HENV
}{henv
},
\param{wxChar *
}{Dsn
},
\param{SWORD
}{DsnMax
},
\param{wxChar *
}{DsDesc
},
\param{SWORD
}{DsDescMax
},
\param{UWORD
}{direction = SQL_FETCH_NEXT
}}
369 This routine queries the ODBC driver manager for a list of available
370 datasources. Repeatedly call this function to obtain all the datasources
371 available through the ODBC driver manager on the current workstation.
373 wxStringList strList;
375 while (wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, SQL_MAX_DSN_LENGTH+
1, DsDesc,
255))
379 \latexignore{\rtfignore{\wxheading{Members
}}}
381 \membersection{wxDb::wxDb
}\label{wxdbconstr
}
387 \func{}{wxDb
}{\param{const HENV &
}{aHenv
},
\param{bool
}{FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS
}}
389 Constructor, used to create an ODBC connection to a datasource.
391 \wxheading{Parameters
}
393 \docparam{aHenv
}{Environment handle used for this connection. See
394 \helpref{wxDConnectInf::AllocHenv
}{wxdbconnectinfallochenv
}}
396 \docparam{FwdOnlyCursors
}{Will cursors created for use with this datasource
397 connection only allow forward scrolling cursors.
}
401 This is the constructor for the wxDb class. The wxDb object must
402 be created and opened before any database activity can occur.
407 wxDbConnectInf ConnectInf;
408 ....Set values for member variables of ConnectInf here
410 wxDb sampleDB(ConnectInf.GetHenv());
411 if (!sampleDB.Open(ConnectInf.GetDsn(), ConnectInf.GetUserID(),
412 ConnectInf.GetPassword()))
414 // Error opening datasource
420 \helpref{wxDbGetConnection
}{wxdbfunctions
},
423 \membersection{wxDb::Catalog
}\label{wxdbcatalog
}
425 \func{bool
}{Catalog
}{\param{wxChar *
}{ userID
},
\param{const wxString &
}{fileName =
426 SQL_CATALOG_FILENAME
}}
428 Allows a data "dictionary" of the datasource to be created, dumping pertinent
429 information about all data tables to which the user specified in userID has
432 \wxheading{Parameters
}
434 \docparam{userID
}{Database user name to use in accessing the database. All
435 tables to which this user has rights will be evaluated in the catalog.
}
437 \docparam{fileName
}{{\it OPTIONAL
}. Name of the text file to create and write
438 the DB catalog to. Default is SQL_CATALOG_FILENAME.
}
440 \wxheading{Return value
}
442 Returns TRUE if the catalog request was successful, or FALSE if there was some
443 reason that the catalog could not be generated.
448 ============== ============== ================ ========= =======
449 TABLE NAME COLUMN NAME DATA TYPE PRECISION LENGTH
450 ============== ============== ================ ========= =======
451 EMPLOYEE RECID (
0008)NUMBER
15 8
452 EMPLOYEE USER_ID (
0012)VARCHAR2
13 13
453 EMPLOYEE FULL_NAME (
0012)VARCHAR2
26 26
454 EMPLOYEE PASSWORD (
0012)VARCHAR2
26 26
455 EMPLOYEE START_DATE (
0011)DATE
19 16
459 \membersection{wxDb::Close
}\label{wxdbclose
}
461 \func{void
}{Close
}{\void}
463 Closes the database connection.
467 At the end of your program, when you have finished all of your database work,
468 you must close the ODBC connection to the datasource. There are actually
469 four steps involved in doing this as illustrated in the example.
471 Any wxDbTable instances which use this connection must be deleted before
472 closing the database connection.
477 // Commit any open transactions on the datasource
478 sampleDB.CommitTrans();
480 // Delete any remaining wxDbTable objects allocated with new
483 // Close the wxDb connection when finished with it
488 \membersection{wxDb::CommitTrans
}\label{wxdbcommittrans
}
490 \func{bool
}{CommitTrans
}{\void}
492 Permanently "commits" changes (insertions/deletions/updates) to the database.
494 \wxheading{Return value
}
496 Returns TRUE if the commit was successful, or FALSE if the commit failed.
500 Transactions begin implicitly as soon as you make a change to the database
501 with an insert/update/delete, or any other direct SQL command that performs
502 one of these operations against the datasource.
503 At any time thereafter, to save the changes to disk permanently, "commit"
504 them by calling this function.
506 Calling this member function commits ALL open transactions on this ODBC
507 connection. For example, if three different wxDbTable instances used the
508 same connection to the datasource, committing changes made on one of those
509 wxDbTable instances commits any pending transactions on all three wxDbTable
512 Until a call to wxDb::CommitTrans() is made, no other user or cursor is able
513 to see any changes made to the row(s) that have been inserted/modified/deleted.
516 \wxheading{Special Note :
{\it Cursors
} }
518 \normalbox{It is important to understand that different database/ODBC driver
519 combinations handle transactions differently. One thing in particular that
520 you must pay attention to is cursors, in regard to transactions. Cursors are
521 what allow you to scroll through records forward and backward and to
522 manipulate records as you scroll through them. When you issue a query, a
523 cursor is created behind the scenes. The cursor keeps track of the query and
524 keeps track of the current record pointer. After you commit or rollback a
525 transaction, the cursor may be closed automatically. This is database
526 dependent, and with some databases this behavior can be controlled through
527 management functions. This means you would need to requery the datasource
528 before you can perform any additional work using this cursor. This is only
529 necessary however if the datasource closes the cursor after a commit or
531 \helpref{wxDbTable::IsCursorClosedOnCommit
}{wxdbtableiscursorclosedoncommit
}
532 member function to determine the datasource's transaction behavior. Note, in
533 many situations it is very inefficient to assume the cursor is closed and
534 always requery. This could put a significant, unnecessary load on datasources
535 that leave the cursors open after a transaction.
}
538 \membersection{wxDb::CreateView
}\label{wxdbcreateviews
}
540 \func{bool
}{CreateView
}{\param{const wxString &
}{ viewName
},
541 \param{const wxString &
}{ colList
},
\param{const wxString &
}{pSqlStmt
}}
543 Creates a SQL VIEW of one or more tables in a single datasource. Note that
544 this function will only work against databases which support views (currently
545 only Oracle as of November
21 2000).
547 \wxheading{Parameters
}
549 \docparam{viewName
}{The name of the view. e.g. PARTS_V
}
551 \docparam{colList
}{{\it OPTIONAL
} Pass in a comma delimited list of column
552 names if you wish to explicitly name each column in the result set. If not
553 desired, pass in an empty string and the column names from the associated
554 table(s) will be used.
}
556 \docparam{pSqlStmt
}{Pointer to the select statement portion of the CREATE
557 VIEW statement. Must be a complete, valid SQL SELECT statement.
}
561 A 'view' is a logical table that derives columns from one or more other
562 tables or views. Once the view is created, it can be queried exactly like
563 any other table in the database.
565 NOTE: Views are not available with all datasources. Oracle is one example
566 of a datasource which does support views.
571 // Incomplete code sample
572 db.CreateView("PARTS_SD1", "PN, PD, QTY",
573 "SELECT PART_NO, PART_DESC, QTY_ON_HAND *
1.1 FROM PARTS \
574 WHERE STORAGE_DEVICE =
1");
576 // PARTS_SD1 can now be queried just as if it were a data table.
577 // e.g. SELECT PN, PD, QTY FROM PARTS_SD1
581 \membersection{wxDb::Dbms
}\label{wxdbdbms
}
583 \func{wxDBMS
}{Dbms
}{\void}
587 The return value will be of the enumerated type wxDBMS. This enumerated
588 type contains a list of all the currently tested and supported databases.
590 Additional databases may work with these classes, but the databases
591 returned by this function have been tested and confirmed to work with
594 Possible values returned by this function can be viewed in the
595 \helpref{Enumerated types
}{wxdbenumeratedtypes
} section of wxDb.
597 There are known issues with conformance to the ODBC standards with several
598 datasources supported by the wxWindows ODBC classes. Please see the overview
599 for specific details on which datasource have which issues.
601 \wxheading{Return value
}
603 The return value will indicate which of the supported datasources is
604 currently connected to by this connection. In the event that the
605 datasource is not recognized, a value of 'dbmsUNIDENTIFIED' is returned.
608 \membersection{wxDb::DispAllErrors
}\label{wxdbdispallerrors
}
610 \func{bool
}{DispAllErrors
}{\param{HENV
}{ aHenv
},
{\param}{HDBC
}
611 { aHdbc = SQL_NULL_HDBC
},
{\param}{HSTMT
}{ aHstmt = SQL_NULL_HSTMT
}}
613 Used to log all database errors that occurred as a result of an executed
614 database command. This logging is automatic and also includes debug logging
615 when compiled in debug mode via
\helpref{wxLogDebug
}{wxlogdebug
}. If logging
616 is turned on via
\helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}, then an
617 entry is also logged to the defined log file.
619 \wxheading{Parameters
}
621 \docparam{aHenv
}{Handle to the ODBC environment.
}
623 \docparam{aHdbc
}{Handle to the ODBC connection. Pass this in if the ODBC
624 function call that erred required a hdbc or hstmt argument.
}
626 \docparam{aHstmt
}{Handle to the ODBC statement being executed against. Pass
627 this in if the ODBC function call that erred out required a hstmt argument.
}
631 This member function will log all of the ODBC error messages for the last
632 ODBC function call that was made. This function is normally used internally
633 within the ODBC class library, but can be used programmatically after calling
634 ODBC functions directly (i.e. SQLFreeEnv()).
636 \wxheading{Return value
}
638 The function always returns FALSE, so a call to this function can be made
639 in the return statement of a code block in the event of a failure to
640 perform an action (see the example below).
644 \helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}, wxDbSqlLog
649 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
650 // Display all ODBC errors for this stmt
651 return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
655 \membersection{wxDb::DispNextError
}\label{wxdbdispnexterror
}
657 \func{void
}{DispNextError
}{\void}
661 This function is normally used internally within the ODBC class library.
662 It could be used programmatically after calling ODBC functions directly. This
663 function works in conjunction with
\helpref{wxDb::GetNextError
}{wxdbgetnexterror
} when errors (or
664 sometimes informational messages) returned from ODBC need to be analyzed
665 rather than simply displaying them as an error. GetNextError() retrieves
666 the next ODBC error from the ODBC error queue. The wxDb member variables
667 "sqlState", "nativeError" and "errorMsg" could then be evaluated. To
668 display the error retrieved, DispNextError() could then be called.
669 The combination of GetNextError() and DispNextError() can be used to
670 iteratively step through the errors returned from ODBC evaluating each
671 one in context and displaying the ones you choose.
676 // Drop the table before attempting to create it
677 sprintf(sqlStmt, "DROP TABLE
%s", tableName);
678 // Execute the drop table statement
679 if (SQLExecDirect(hstmt,(UCHAR FAR *)sqlStmt,SQL_NTS) != SQL_SUCCESS)
681 // Check for sqlState = S0002, "Table or view not found".
682 // Ignore this error, bomb out on any other error.
683 pDb->GetNextError(henv, hdbc, hstmt);
684 if (wxStrcmp(pDb->sqlState, "S0002"))
686 pDb->DispNextError(); // Displayed error retrieved
687 pDb->DispAllErrors(henv, hdbc, hstmt); // Display all other errors, if any
688 pDb->RollbackTrans(); // Rollback the transaction
689 CloseCursor(); // Close the cursor
690 return(FALSE); // Return Failure
696 \membersection{wxDb::DropView
}\label{wxdbdropview
}
698 \func{bool
}{DropView
}{\param{const wxString &
}{viewName
}}
700 Drops the data table view named in 'viewName'.
702 \wxheading{Parameters
}
704 \docparam{viewName
}{Name of the view to be dropped.
}
708 If the view does not exist, this function will return TRUE. Note that views are not supported with all datasources.
710 \membersection{wxDb::ExecSql
}\label{wxdbexecsql
}
713 \func{bool
}{ExecSql
}{\param{const wxString &
}{pSqlStmt
}}
715 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.
717 \wxheading{Parameters
}
719 \docparam{pSqlStmt
}{Pointer to the SQL statement to be executed.
}
723 This member extends the wxDb class and allows you to build and execute ANY VALID
724 SQL statement against the datasource. This allows you to extend the class
725 library by being able to issue any SQL statement that the datasource is capable
730 \helpref{wxDb::GetData
}{wxdbgetdata
},
\helpref{wxDb::GetNext
}{wxdbgetnext
}
733 \membersection{wxDb::FwdOnlyCursors
}\label{wxdbfwdonlycursors
}
735 \func{bool
}{IsFwdOnlyCursors
}{\void}
737 Older form (pre-
2.3/
2.4 of wxWindows) of the
738 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
}. This method is
739 provided for backward compatability only. The method
740 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
} should be
741 used in place of this method.
744 \func{wxDbInf *
}{GetCatalog
}{\param{const wxChar *
}{userID
}}
746 \membersection{wxDb::GetCatalog
}\label{wxdbgetcatalog
}
748 \func{wxDbInf *
}{GetCatalog
}{\param{const wxChar *
}{userID
}}
750 Returns a
\helpref{wxDbInf
}{wxdbinf
} pointer that points to the catalog
751 (datasource) name, schema, number of tables accessible to the current user,
752 and a wxDbTableInf pointer to all data pertaining to all tables in the users
755 \wxheading{Parameters
}
757 \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:
}
760 userID == NULL ... UserID is ignored (DEFAULT)
761 userID == "" ... UserID set equal to 'this->uid'
762 userID != "" ... UserID set equal to 'userID'
767 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.
769 \membersection{wxDb::GetColumnCount
}\label{wxdbgetcolumncount
}
771 \func{int
}{GetColumnCount
}{\param{const wxString &
}{tableName
},
\param{const wxChar *
}{userID
}}
773 \wxheading{Parameters
}
775 \docparam{tableName
}{The table name you wish to obtain column information about.
}
777 \docparam{userID
}{Name of the user that owns the table(s) (also referred to as schema).
778 Required for some datasources for situations where there may be multiple tables with the
779 same name in the datasource, but owned by different users.
{\it userID
} is
780 evaluated in the following manner:
}
783 userID == NULL ... UserID is ignored (DEFAULT)
784 userID == "" ... UserID set equal to 'this->uid'
785 userID != "" ... UserID set equal to 'userID'
788 \wxheading{Return value
}
790 Returns a count of how many columns are in the specified table. If an error
791 occurs retrieving the number of columns, this function will return a -
1.
793 \membersection{wxDb::GetColumns
}\label{wxdbgetcolumns
}
795 \func{wxDbColInf *
}{GetColumns
}{\param{const wxString &
}{tableName
},
\param{UWORD *
}{numCols
},
\param{const wxChar *
}{userID=NULL
}}
797 \func{wxDbColInf *
}{GetColumns
}{\param{wxChar *
}{tableName
[]},
\param{const wxChar *
}{userID
}}
799 \wxheading{Parameters
}
801 \docparam{tableName
}{The table name you wish to obtain column information about.
}
802 \docparam{numCols
}{Pointer to a UWORD which will hold a count of the number of columns returned by this function
}
803 \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.
}
804 \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:
}
807 userID == NULL ... UserID is ignored (DEFAULT)
808 userID == "" ... UserID set equal to 'this->uid'
809 userID != "" ... UserID set equal to 'userID'
812 \wxheading{Return value
}
814 This function returns a pointer to an array of
\helpref{wxDbColInf
}{wxdbcolinf
}
815 structures, allowing you to obtain information regarding the columns of the
816 named table(s). If no columns were found, or an error occurred, this pointer
819 THE CALLING FUNCTION IS RESPONSIBLE FOR DELETING THE
{\it wxDbColInf
} MEMORY WHEN IT IS
822 \normalbox{ALL column bindings associated with this wxDb instance are unbound
823 by this function, including those used by any wxDbTable instances that use
824 this wxDb instance. This function should use its own wxDb instance
825 to avoid undesired unbinding of columns.
}
829 \helpref{wxDbColInf
}{wxdbcolinf
}
834 wxChar *tableList
[] =
{"PARTS",
0};
835 wxDbColInf *colInf = pDb->GetColumns(tableList);
838 // Use the column inf
840 // Destroy the memory
846 \membersection{wxDb::GetData
}\label{wxdbgetdata
}
848 \func{bool
}{GetData
}{\param{UWORD
}{ colNo
},
\param{SWORD
}{ cType
},
849 \param{PTR
}{ pData
},
\param{SDWORD
}{ maxLen
},
\param{SDWORD FAR *
}{ cbReturned
} }
851 Used to retrieve result set data without binding column values to memory
852 variables (i.e. not using a wxDbTable instance to access table data).
854 \wxheading{Parameters
}
856 \docparam{colNo
}{Ordinal number of the desired column in the result set to be
858 \docparam{cType
}{The C data type that is to be returned. See a partial list
859 in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}}
860 \docparam{pData
}{Memory buffer which will hold the data returned by the call
862 \docparam{maxLen
}{Maximum size of the buffer
{\it 'pData'
} in characters.
863 NOTE: Not UNICODE safe. If this is a numeric field, a value of
0 may be
864 passed for this parameter, as the API knows the size of the expected return
866 \docparam{cbReturned
}{Pointer to the buffer containing the length of the
867 actual data returned. If this value comes back as SQL_NULL_DATA, then the
868 \helpref{wxDb::GetData
}{wxdbgetdata
} call has failed.
}
872 \helpref{wxDb::GetNext
}{wxdbgetnext
},
\helpref{wxDb::ExecSql
}{wxdbexecsql
}
880 sqlStmt = "SELECT SUM(REQUIRED_QTY - PICKED_QTY) FROM ORDER_TABLE WHERE \
881 PART_RECID =
1450 AND REQUIRED_QTY > PICKED_QTY";
884 if (!pDb->ExecSql(sqlStmt.c_str()))
890 // Request the first row of the result set
897 // Read column
#1 of the row returned by the call to ::GetNext()
898 // and return the value in 'reqQty'
899 if (!pDb->GetData(
1, SQL_C_ULONG, &reqQty,
0, &cb))
905 // Check for a NULL result
906 if (cb == SQL_NULL_DATA)
912 When requesting multiple columns to be returned from the result set (for example, the SQL query
913 requested
3 columns be returned), the calls to this function must request the columns in ordinal
914 sequence (
1,
2,
3 or
1,
3 or
2,
3).
916 \membersection{wxDb::GetDatabaseName
}\label{wxdbgetdatabasename
}
918 \func{const wxChar *
}{GetDatabaseName
}{\void}
920 Returns the name of the database engine.
922 \membersection{wxDb::GetDatasourceName
}\label{wxdbgetdatasourcename
}
924 \func{const wxString &
}{GetDatasourceName
}{\void}
926 Returns the ODBC datasource name.
928 \membersection{wxDb::GetHDBC
}\label{wxdbgethdbc
}
930 \func{HDBC
}{GetHDBC
}{\void}
932 Returns the ODBC handle to the database connection.
934 \membersection{wxDb::GetHENV
}\label{wxdbgethenv
}
936 \func{HENV
}{GetHENV
}{\void}
938 Returns the ODBC environment handle.
940 \membersection{wxDb::GetHSTMT
}\label{wxdbgethstmt
}
942 \func{HSTMT
}{GetHSTMT
}{\void}
944 Returns the ODBC statement handle associated with this database connection.
946 \membersection{wxDb::GetKeyFields
}\label{wxdbgetkeyfields
}
948 \func{int
}{GetKeyFields
}{\param{const wxString &
}{tableName
},
\param{wxDbColInf *
}{colInf
},
\param{UWORD
}{nocols
}}
950 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.
952 This function is primarily for use by the
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
} function, but may be called if desired from the client application.
954 \wxheading{Parameters
}
956 \docparam{tableName
}{Name of the table for which the columns will be evaluated as to their inclusion in any indexes.
}
957 \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.
}
958 \docparam{nocols
}{Number of columns defined in the instance of colInf.
}
960 \wxheading{Return value
}
962 Currently always returns TRUE.
966 \helpref{wxDbColInf
}{wxdbcolinf
},
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
}
968 \membersection{wxDb::GetNext
}\label{wxdbgetnext
}
970 \func{bool
}{GetNext
}{\void}
972 Called after executing a query, this function requests the next row
973 in the result set after the current position of the cursor.
977 \helpref{wxDb::ExecSql
}{wxdbexecsql
},
\helpref{wxDb::GetData
}{wxdbgetdata
}
979 \membersection{wxDb::GetNextError
}\label{wxdbgetnexterror
}
981 \func{bool
}{GetNextError
}{\param{HENV
}{ aHenv
},
982 \param{HDBC
}{ aHdbc = SQL_NULL_HDBC
},
\param{HSTMT
}{ aHstmt = SQL_NULL_HSTMT
}}
984 \wxheading{Parameters
}
986 \docparam{aHenv
}{A handle to the ODBC environment.
}
987 \docparam{aHdbc
}{{\it OPTIONAL.
} A handle to the ODBC connection. Pass this
988 in if the ODBC function call that erred out required a hdbc or hstmt argument.
}
989 \docparam{AHstmt
}{{\it OPTIONAL.
}A handle to the ODBC statement being executed
990 against. Pass this in if the ODBC function call that erred out requires a
996 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
998 // Display all ODBC errors for this stmt
999 return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
1003 \wxheading{See also
}
1005 \helpref{wxDb::DispNextError
}{wxdbdispnexterror
},
1006 \helpref{wxDb::DispAllErrors
}{wxdbdispallerrors
}
1009 \membersection{wxDb::GetPassword
}\label{wxdbgetpassword
}
1011 \func{const wxString &
}{GetPassword
}{\void}
1013 Returns the password used to establish this connection to the datasource.
1016 \membersection{wxDb::GetTableCount
}\label{wxdbgettablecount
}
1018 \func{int
}{GetTableCount
}{\void}
1020 Returns the number of wxDbTable() instances currently using this datasource
1024 \membersection{wxDb::GetUsername
}\label{wxdbgetusername
}
1026 \func{const wxString &
}{GetUsername
}{\void}
1028 Returns the user name (uid) used to establish this connection to the
1032 \membersection{wxDb::Grant
}\label{wxdbgrant
}
1034 \func{bool
}{Grant
}{\param{int
}{privileges
},
\param{const wxString &
}{tableName
},
1035 \param{const wxString &
}{userList = "PUBLIC"
}}
1037 Use this member function to GRANT privileges to users for accessing tables in
1040 \wxheading{Parameters
}
1042 \docparam{privileges
}{Use this argument to select which privileges you want to
1043 grant. Pass DB_GRANT_ALL to grant all privileges. To grant individual
1044 privileges pass one or more of the following OR'd together:
}
1051 DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT |
1052 DB_GRANT_UPDATE | DB_GRANT_DELETE
1055 \docparam{tableName
}{The name of the table you wish to grant privileges on.
}
1056 \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.
}
1060 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.
1062 The currently logged in user must have sufficient grantor privileges for this
1063 function to be able to successfully grant the indicated privileges.
1068 db.Grant(DB_GRANT_SELECT | DB_GRANT_INSERT, "PARTS", "mary, sue");
1072 \membersection{wxDb::IsFwdOnlyCursors
}\label{wxdbisfwdonlycursors
}
1074 \func{bool
}{IsFwdOnlyCursors
}{\void}
1076 This setting indicates whether this database connection was created
1077 as being capable of using only forward scrolling cursors.
1079 This function does NOT indicate if the ODBC driver or datasource supports
1080 backward scrolling cursors. There is no standard way of detecting if the
1081 driver or datasource can support backward scrolling cursors.
1083 If a wxDb instance was created as being capable of only forward scrolling
1084 cursors, then even if the datasource and ODBC driver support backward
1085 scrolling cursors, tables using this database connection would only be able
1086 to use forward scrolling cursors.
1088 The default setting of whether a wxDb connection to a database allows
1089 forward-only or also backward scrolling cursors is defined in setup.h by the
1090 value of wxODBC_FWD_ONLY_CURSORS. This default setting can be overridden
1091 when the wxDb connection is initially created (see
1092 \helpref{wxDb constructor
}{wxdbconstr
} and
\helpref{wxDbGetConnection
}{wxdbfunctions
}).
1094 \wxheading{Return value
}
1096 Returns TRUE if this datasource connection is defined as using only forward
1097 scrolling cursors, or FALSE if the connection is defined as being allowed to
1098 use backward scrolling cursors and their associated functions (see note above).
1102 Added as of wxWindows v2.4 release, this function is a renamed version of
1103 wxDb::FwdOnlyCursors() to match the normal wxWindows naming conventions for
1104 class member functions.
1106 This function is not available in versions prior to v2.4. You should
1107 use
\helpref{wxDb::FwdOnlyCursors
}{wxdbfwdonlycursors
} for wxWindows
1108 versions prior to
2.4.
1110 \wxheading{See also
}
1112 \helpref{wxDb constructor
}{wxdbconstr
},
\helpref{wxDbGetConnection
}{wxdbfunctions
}
1115 \membersection{wxDb::IsOpen
}\label{wxdbisopen
}
1117 \func{bool
}{IsOpen
}{\void}
1119 Indicates whether the database connection to the datasource is currently
1124 This function may indicate that the database connection is open, even if
1125 the call to
\helpref{wxDb::Open
}{wxdbopen
} may have failed to fully
1126 initialize the connection correctly. The connection to the database
1127 {\it is
} open and can be used via the direct SQL commands, if this
1128 function returns TRUE. Other functions which depend on the
1129 \helpref{wxDb::Open
}{wxdbopen
} to have completed correctly may not function
1130 as expected. The return result from
\helpref{wxDb::Open
}{wxdbopen
} is the
1131 only way to know if complete initialization of this wxDb connection was
1132 successful or not. See
\helpref{wxDb::Open
}{wxdbopen
} for more details on
1133 partial failures to open a connection instance.
1136 \membersection{wxDb::LogError
}\label{wxdblogerror
}
1138 \func{void
}{LogError
}{\param{const wxString &
}{errMsg
} \param{const wxString &
}{SQLState=""
}}
1140 \docparam{errMsg
}{Free-form text to display describing the error/text to be logged.
}
1141 \docparam{SQLState
}{{\it OPTIONAL.
} Native SQL state error. Default is
0.
}
1145 Calling this function will enter a log message in the error list maintained
1146 for the database connection. This log message is free form and can be
1147 anything the programmer wants to enter in the error list.
1149 If SQL logging is turned on, the call to this function will also log the
1150 text into the SQL log file.
1152 \wxheading{See also
}
1154 \helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
}
1157 \membersection{wxDb::ModifyColumn
}\label{wxdbmodifycolumn
}
1159 \func{void
}{ModifyColumn
}{\param{const wxString &
}{tableName
} \param{const wxString &
}{ColumnName
}
1160 \param{int
}{dataType
} \param{ULONG
}{columnLength=
0} \param{const wxString &
}{optionalParam=""
}}
1162 Used to change certain properties of a column such as the length, or whether a column
1163 allows NULLs or not.
1165 \docparam{tableName
}{Name of the table that the column to be modified is in.
}
1166 \docparam{columnName
}{Name of the column to be modified. NOTE: Name of column cannot
1167 be changed with this function.
}
1168 \docparam{dataType
}{Any one of DB_DATA_TYPE_VARCHAR, DB_DATA_TYPE_INTEGER,
1169 DB_DATA_TYPE_FLOAT, DB_DATA_TYPE_DATE.
}
1170 \docparam{columnLength
}{New size of the column. Valid only for DB_DATA_TYPE_VARCHAR
1171 dataType fields. Default is
0.
}
1172 \docparam{optionalParam
}{Default is "".
}
1176 Cannot be used to modify the precision of a numeric column, therefore 'columnLength'
1177 is ignored unless the dataType is DB_DATA_TYPE_VARCHAR.
1179 Some datasources do not allow certain properties of a column to be changed if any rows
1180 currently have data stored in that column. Those datasources that do allow columns
1181 to be changed with data in the rows many handle truncation and/or expansion in
1182 different ways. Please refer to the reference material for the datasource being
1183 used for behavioral descriptions.
1188 ok = pDb->ModifyColumn("CONTACTS", "ADDRESS2",
1189 DB_, colDefs
[j
].SzDataObj,
1194 \membersection{wxDb::Open
}\label{wxdbopen
}
1196 \func{bool
}{Open
}{\param{const wxString &
}{Dsn
},
\param{const wxString &
}{Uid
},
1197 \param{const wxString &
}{AuthStr
}}
1199 \func{bool
}{Open
}{\param{wxDb *
}{copyDb
}}
1201 Opens a connection to the datasource, sets certain behaviors of the datasource
1202 to confirm to the accepted behaviors (e.g. cursor position maintained on
1203 commits), and queries the datasource for its representations of the basic
1204 datatypes to determine the form in which the data going to/from columns in
1205 the data tables are to be handled.
1207 The second form of this function, which accepts a "wxDb *" as a parameter,
1208 can be used to avoid the overhead (execution time, database load, network
1209 traffic) which are needed to determine the data types and representations
1210 of data that are necessary for cross-datasource support by these classes.
1212 Normally the first form of the wxDb::Open() function will open the connection
1213 and then send a series of queries to the datasource asking it for its
1214 representation of data types, and all the features it supports. If one
1215 connection to the datasource has already been made previously, the information
1216 gathered when that connection was created can just be copied to any new
1217 connections to the same datasource by passing a pointer to the first
1218 connection in as a parameter to the wxDb::Open() function. Note that this
1219 new connection created from the first connections information will use the
1220 same Dsn/Uid/AuthStr as the first connection used.
1222 \wxheading{Parameters
}
1224 \docparam{Dsn
}{datasource name. The name of the ODBC datasource as
1225 assigned when the datasource is initially set up through the ODBC data
1227 \docparam{Uid
}{User ID. The name (ID) of the user you wish to connect as
1228 to the datasource. The user name (ID) determines what objects you
1229 have access to in the datasource and what datasource privileges you have.
1230 Privileges include being able to create new objects, update objects, delete
1231 objects and so on. Users and privileges are normally administered by the
1232 database administrator.
}
1233 \docparam{AuthStr
}{The password associated with the Uid.
}
1234 \docparam{copyDb
}{Already completely configured and opened datasource connection
1235 from which all Dsn, Uid, AuthStr, and data typing information is to be copied
1236 from for use by this datasource connection.
}
1240 After a wxDb instance is created, it must then be opened. When opening a
1241 datasource, there must be three pieces of information passed. The data
1242 source name, user name (ID) and the password for the user. No database
1243 activity on the datasource can be performed until the connection is opened.
1244 This is normally done at program startup and the datasource remains
1245 open for the duration of the program/module run.
1247 It is possible to have connections to multiple datasources open at the same
1248 time to support distributed database connections by having separate instances
1249 of wxDb objects that use either the same or different Dsn/Uid/AuthStr settings.
1251 If this function returns a value of FALSE, it does not necessarily mean that
1252 the connection to the datasource was not opened. It may mean that some
1253 portion of the initialization of the connection failed (such as a datatype not
1254 being able to be determined how the datasource represents it). To determine
1255 if the connection to the database failed, use the
\helpref{wxDb::IsOpen
}{wxdbisopen
}
1256 function after receiving a FALSE result back from this function to determine if
1257 the connection was opened or not. If this function returns FALSE, but
\helpref{wxDb::IsOpen
}{wxdbisopen
}
1258 returns TRUE, then direct SQL commands may be passed to the database
1259 connection and can be successfully executed, but use of the datatypes (such as
1260 by a wxDbTable instance) that are normally determined during open will not be
1263 \normalbox{The
{\it Dsn
},
{\it Uid
}, and
{\it AuthStr
} string pointers that are passed in
1264 are copied. NOT the strings themselves, only the pointers. The calling routine
1265 must maintain the memory for these three strings for the life of the wxDb instance.
}
1270 wxDb sampleDB(DbConnectInf.GetHenv());
1271 if (!sampleDB.Open("Oracle
7.1 HP/UX", "gtasker", "myPassword"))
1273 if (sampleDb.IsOpen())
1275 // Connection is open, but the initialization of
1276 // datatypes and parameter settings failed
1280 // Error opening datasource
1286 \membersection{wxDb::RollbackTrans
}\label{wxdbrollbacktrans
}
1288 \func{bool
}{RollbackTrans
}{\void}
1290 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.
1294 Transactions begin implicitly as soon as you make a change to the database. The
1295 transaction continues until either a commit or rollback is executed. Calling
1296 wxDb::RollbackTrans() will result in ALL changes done using this database
1297 connection that have not already been committed to be "undone" back to the last
1298 commit/rollback that was successfully executed.
1300 \normalbox{Calling this member function rolls back ALL open (uncommitted)
1301 transactions on this ODBC connection, including all wxDbTable instances that
1302 use this connection.
}
1304 \wxheading{See also
}
1306 \helpref{wxDb::CommitTrans
}{wxdbcommittrans
} for a special note on cursors
1309 \membersection{wxDb::SetDebugErrorMessages
}\label{wxdbsetdebugerrormessages
}
1311 \func{void
}{SetDebugErrorMessages
}{\param{bool
}{state
}}
1313 \docparam{state
}{Either TRUE (debug messages are logged) or FALSE (debug
1314 messages are not logged).
}
1318 Turns on/off debug error messages from the ODBC class library. When
1319 this function is passed TRUE, errors are reported to the user/logged automatically
1320 in a text or pop-up dialog when an ODBC error occurs. When passed FALSE,
1321 errors are silently handled.
1323 When compiled in release mode (FINAL=
1), this setting has no affect.
1325 \wxheading{See also
}
1327 \helpref{wxDb constructor
}{wxdbconstr
}
1330 \membersection{wxDb::SetSqlLogging
}\label{wxdbsetsqllogging
}
1332 \func{bool
}{SetSqlLogging
}{\param{wxDbSqlLogState
}{ state
},
\param{const wxString &
}{filename = SQL_LOG_FILENAME
},
\param{bool
}{ append = FALSE
}}
1334 \wxheading{Parameters
}
1336 \docparam{state
}{Either sqlLogOFF or sqlLogON (see
\helpref{enum wxDbSqlLogState
}{wxdbcolfor
}). Turns logging of SQL commands sent to the datasource OFF or ON.
}
1337 \docparam{filename
}{{\it OPTIONAL
}. Name of the file to which the log text is to be written. Default is SQL_LOG_FILENAME.
}
1338 \docparam{append
}{{\it OPTIONAL
}. Whether the file is appended to or overwritten. Default is FALSE.
}
1342 When called with
{\it sqlLogON
}, all commands sent to the datasource engine are logged to the file specified by
{\it filename
}. Logging is done by embedded
\helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
} calls in the database member functions, or may be manually logged by adding calls to
\helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
} in your own source code.
1344 When called with
{\it sqlLogOFF
}, the logging file is closed, and any calls to
\helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
} are ignored.
1347 \membersection{wxDb::TableExists
}\label{wxdbtableexists
}
1349 \func{bool
}{TableExists
}{\param{const wxString &
}{tableName
},
\param{const wxChar *
}{userID=NULL
},
\param{const wxString &
}{path=""
}}
1351 Checks the ODBC datasource for the existence of a table. If a
{\it userID
}
1352 is specified, then the table must be accessible by that user (user must have
1353 at least minimal privileges to the table).
1355 \wxheading{Parameters
}
1357 \docparam{tableName
}{Name of the table to check for the existence of.
}
1358 \docparam{userID
}{Owner of the table (also referred to as schema). Specify a userID when the datasource you are connected
1359 to allows multiple unique tables with the same name to be owned by different users.
{\it userID
}
1360 is evaluated as follows:
}
1363 userID == NULL ... UserID is ignored (DEFAULT)
1364 userID == "" ... UserID set equal to 'this->uid'
1365 userID != "" ... UserID set equal to 'userID'
1370 {\it tableName
} may refer to a table, view, alias or synonym.
1372 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.
1374 \wxheading{See also
}
1376 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
}
1379 \membersection{wxDb::TablePrivileges
}\label{wxdbtableprivileges
}
1381 \func{bool
}{TablePrivileges
}{\param{const wxString &
}{tableName
},
\param{const wxString &
}{priv
},
1382 \param{const wxChar *
}{userID=NULL
},
\param{const wxChar *
}{schema=NULL
},
1383 \param{const wxString &
}{path=""
}}
1385 Checks the ODBC datasource for the existence of a table. If a
{\it userID
}
1386 is specified, then the table must be accessible by that user (user must have
1387 at least minimal privileges to the table).
1389 \wxheading{Parameters
}
1391 \docparam{tableName
}{Name of the table on which to check privileges.
1392 {\it tableName
} may refer to a table, view, alias or synonym.
}
1393 \docparam{priv
}{The table privilege being evaluated. May be one of the
1394 following (or a datasource specific privilege):
}
1397 SELECT : The connected user is permitted to retrieve data for
1398 one or more columns of the table.
1400 INSERT : The connected user is permitted to insert new rows
1401 containing data for one or more columns into the
1404 UPDATE : The connected user is permitted to update the data in
1405 one or more columns of the table.
1407 DELETE : The connected user is permitted to delete rows of
1408 data from the table.
1410 REFERENCES : Is the connected user permitted to refer to one or
1411 more columns of the table within a constraint (for
1412 example, a unique, referential, or table check
1415 \docparam{userID
}{{\it OPTIONAL.
} User for which to determine if the privilege
1416 specified to be checked is granted or not. Default is "".
1417 {\it userID
} is evaluated as follows:
1420 userID == NULL ... NOT ALLOWED!
1421 userID == "" ... UserID set equal to 'this->uid'
1422 userID != "" ... UserID set equal to 'userID'
1425 \docparam{schema
}{{\it OPTIONAL.
} Owner of the table. Specify a userID when the datasource
1426 you are connected to allows multiple unique tables with the same name to be
1427 owned by different users. Specifying the table owner makes determination of the
1428 users privileges MUCH faster. Default is NULL.
{\it userID
} is evaluated as follows:
1431 schema == NULL ... Any owner (DEFAULT)
1432 schema == "" ... Owned by 'this->uid'
1433 schema != "" ... Owned by userID specified in 'schema'
1436 \docparam{path
}{{\it OPTIONAL.
} Path to the table. Default is "".
1441 The scope of privilege allowed to the connected user by a given table
1442 privilege is datasource dependent.
1444 For example, the privilege UPDATE might allow the connected user to update
1445 all columns in a table on one datasource, but only those columns for
1446 which the grantor (the user that granted the connected user) has the UPDATE
1447 privilege on another datasource.
1449 Looking up a user's privileges to a table can be time consuming depending on the
1450 datasource and ODBC driver. This time can be minimized by passing a
{\it schema
}
1451 as a parameter. With some datasources/drivers, the difference can be several
1452 seconds of time difference.
1455 \membersection{wxDb::TranslateSqlState
}\label{wxdbtranslatesqlstate
}
1457 \func{int
}{TranslateSqlState
}{\param{const wxString &
}{SQLState
}}
1459 Converts an ODBC sqlstate to an internal error code.
1461 \wxheading{Parameters
}
1463 \docparam{SQLState
}{State to be converted.
}
1465 \wxheading{Return value
}
1467 Returns the internal class DB_ERR code. See
\helpref{wxDb::DB_STATUS
}{wxdb
} definition.
1470 \membersection{wxDb::WriteSqlLog
}\label{wxdbwritesqllog
}
1472 \func{bool
}{WriteSqlLog
}{\param{const wxString &
}{logMsg
}}
1474 \wxheading{Parameters
}
1476 \docparam{logMsg
}{Free form string to be written to the log file.
}
1480 Very useful debugging tool that may be turned on/off during run time (see
1481 (see
\helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
} for details on
1482 turning logging on/off). The passed in string
{\it logMsg
} will be written to
1483 a log file if SQL logging is turned on.
1485 \wxheading{Return value
}
1487 If SQL logging is off when a call to WriteSqlLog() is made, or there is a
1488 failure to write the log message to the log file, the function returns
1489 FALSE without performing the requested log, otherwise TRUE is returned.
1491 \wxheading{See also
}
1493 \helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}
1496 \section{\class{wxDbColDataPtr
}}\label{wxdbcoldataptr
}
1498 Pointer to dynamic column definitions for use with a wxDbTable instance.
1499 Currently there are no member functions for this class.
1508 \section{\class{wxDbColDef
}}\label{wxdbcoldef
}
1510 This class is used to hold information about the columns bound to an
1511 instance of a wxDbTable object.
1513 Each instance of this class describes one column in the wxDbTable
1514 object. When calling the
\helpref{wxDb constructor
}{wxdbconstr
}, a
1515 parameter passed in indicates the number of columns that will be defined for
1516 the wxDbTable object. The constructor uses this information to allocate
1517 adequate memory for all of the column descriptions in your wxDbTable object.
1518 Private member wxDbTable::colDefs is a pointer to this chunk of memory
1519 maintained by the wxDbTable class (and can be retrieved using the
1520 \helpref{wxDbTable::GetColDefs
}{wxdbtablegetcoldefs
} function).
1521 To access the nth column definition of your wxDbTable object, just reference
1522 wxDbColDefs element
[n -
1].
1524 Typically,
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
} is used to
1525 populate an array of these data structures for the wxDbTable instance.
1527 Currently there are no accessor functions for this class, so all members are
1531 wxChar ColName
[DB_MAX_COLUMN_NAME_LEN+
1]; // Column Name
1532 int DbDataType; - Logical Data Type;
1533 e.g. DB_DATA_TYPE_INTEGER
1534 SWORD SqlCtype; - C data type; e.g. SQL_C_LONG
1535 void *PtrDataObj; - Address of the data object
1536 int SzDataObj; - Size, in bytes, of the data object
1537 bool KeyField; - Is column part of the PRIMARY KEY for the
1538 table? -- Date fields should NOT be
1540 bool Updateable; - Column is updateable?
1541 bool InsertAllowed; - Column included in INSERT statements?
1542 bool DerivedCol; - Column is a derived value?
1543 SDWORD CbValue; - !!!Internal use only!!!
1544 bool Null; - NOT FULLY IMPLEMENTED
1545 Allows NULL values in Inserts and Updates
1548 \wxheading{See also
}
1550 \helpref{wxDbTable::GetColDefs
}{wxdbtablegetcoldefs
},
\helpref{wxDb constructor
}{wxdbconstr
}
1553 \membersection{wxDbColDef::Initialize
}\label{wxdbcoldefinitialize
}
1555 Simply initializes all member variables to a cleared state. Called by
1556 the constructor automatically.
1559 \section{\class{wxDbColInf
}}\label{wxdbcolinf
}
1561 Used with the
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
} functions for obtaining all retrievable information about a column's definition.
1564 wxChar catalog
[128+
1];
1565 wxChar schema
[128+
1];
1566 wxChar tableName
[DB_MAX_TABLE_NAME_LEN+
1];
1567 wxChar colName
[DB_MAX_COLUMN_NAME_LEN+
1];
1569 wxChar typeName
[128+
1];
1572 short decimalDigits;
1575 wxChar remarks
[254+
1];
1576 int dbDataType; // conversion of the 'sqlDataType'
1577 // to the generic data type used by
1579 int PkCol; // Primary key column
1582 2 = Second Key, etc...
1583 wxChar PkTableName
[DB_MAX_TABLE_NAME_LEN+
1];
1584 // Tables that use this PKey as a FKey
1585 int FkCol; // Foreign key column
1588 2 = Second Key, etc...
1589 wxChar FkTableName
[DB_MAX_TABLE_NAME_LEN+
1];
1590 // Foreign key table name
1591 wxDbColFor *pColFor; // How should this column be formatted
1594 The constructor for this class initializes all the values to zero, "", or NULL.
1596 The destructor for this class takes care of deleting the pColFor member if
1600 \membersection{wxDbColInf::Initialize
}\label{wxdbcolinfinitialize
}
1602 Simply initializes all member variables to a cleared state. Called by
1603 the constructor automatically.
1607 \section{\class{wxDbColFor
}}\label{wxdbcolfor
}
1609 Beginning support for handling international formatting specifically on dates
1613 wxString s_Field; // Formated String for Output
1614 wxString s_Format
[7]; // Formated Objects - TIMESTAMP has
1616 wxString s_Amount
[7]; // Formated Objects - amount of
1617 things that can be formatted
1618 int i_Amount
[7]; // Formated Objects -
1619 TT MM YYYY HH MM SS m
1620 int i_Nation; //
0 = timestamp
1625 int i_dbDataType; // conversion of the 'sqlDataType'
1626 to the generic data type used by
1628 SWORD i_sqlDataType;
1631 The constructor for this class initializes all the values to zero or NULL.
1633 The destructor does nothing at this time.
1635 Only one function is provided with this class currently:
1638 \membersection{wxDbColFor::Format
}\label{wxdbcolforformat
}
1640 \func{int
}{Format
}{\param{int
}{Nation
},
\param{int
}{dbDataType
},
1641 \param{SWORD
}{sqlDataType
},
\param{short
}{columnSize
},
1642 \param{short
}{decimalDigits
}}\label{wxdbcolforformat
}
1644 Work in progress, and should be inter-related with wxLocale eventually.
1647 \membersection{wxDbColFor::Initialize
}\label{wxdbcolforinitialize
}
1649 Simply initializes all member variables to a cleared state. Called by
1650 the constructor automatically.
1653 \section{\class{wxDbConnectInf
}}\label{wxdbconnectinf
}
1655 This class is used for holding the data necessary for connecting to the ODBC
1656 datasource. That information includes: SQL environment handle, datasource
1657 name, user ID, password and default directory path (used with dBase). Other
1658 optional fields held in this class are and file type, both for future
1659 functions planned to be added for creating/manipulating datasource definitions.
1661 \func{}{wxDbConnectInf
}{\void}
1663 Default constructor.
1665 \func{}{wxDb
}{\param{HENV
}{henv
},
\param{const wxString &
}{dsn
},
1666 \param{const wxString &
}{userID=""
},
\param{const wxString &
}{password
},
1667 \param{const wxString &
}{defaultDir=""
},
\param{const wxString &
}{description=""
},
1668 \param{const wxString &
}{fileType=""
}}
1670 Constructor which allows initial settings of all the classes member variables.
1672 See the special not below on the henv parameter for forcing this constructor
1673 to create a SQL environment handle automatically, rather than needing to pass
1674 one in to the function.
1676 \wxheading{Parameters
}
1678 \docparam{henv
}{Environment handle used for this connection. See
1679 \helpref{wxDConnectInf::AllocHenv
}{wxdbconnectinfallochenv
} for how to create
1680 an SQL environment handle. NOTE: Passing in a NULL for this parameter will
1681 inform the constructor that it should create its own SQL environment handle.
1682 If NULL is passed for this parameter, the constructor will call
1683 \helpref{wxDConnectInf::AllocHenv
}{wxdbconnectinfallochenv
} internally. A
1684 flag is set internally also to indicate that the HENV was created by the
1685 constructor so that when the default class destructor is called, the
1686 destructor will call
\helpref{wxDConnectInf::FreeHenv
}{wxdbconnectinffreehenv
}
1687 to free the environment handle automatically.
}
1688 \docparam{dsn
}{Name of the datasource to be used in creating wxDb instances
1689 for creating connection(s) to a datasource.
}
1690 \docparam{userID
}{{\it OPTIONAL
} Many datasources allow (or even require)
1691 use of a username to determine privileges that connecting user is allowed
1692 to have when accessing the datasource or the data tables. Default is "".
}
1693 \docparam{password
}{{\it OPTIONAL
} Password to be associated with the user
1694 ID specified in 'userID'. Default is "".
}
1695 \docparam{defaultDir
}{{\it OPTIONAL
} Used for datasources which require the
1696 path to where the data file is stored to be specified. dBase is one example
1697 of the type of datasource which requires this information. Default is "".
}
1698 \docparam{description
}{{\it OPTIONAL
} {\bf FUTURE USE
} Default is "".
}
1699 \docparam{fileType
}{{\it OPTIONAL
} {\bf FUTURE USE
} Default is "".
}
1703 It is strongly recommended that programs use the longer form of the
1704 constructor and allow the constructor to create the SQL environment handle
1705 automatically, and manage the destruction of the handle.
1710 wxDbConnectInf *DbConnectInf;
1712 DbConnectInf = new wxDbConnectInf(
0,"MY_DSN", "MY_USER", "MY_PASSWORD");
1714 ....the rest of the program
1716 delete DbConnectInf;
1719 \wxheading{See also
}
1721 \helpref{wxDConnectInf::AllocHenv
}{wxdbconnectinfallochenv
},
1722 \helpref{wxDConnectInf::FreeHenv
}{wxdbconnectinffreehenv
}
1725 \membersection{wxDbConnectInf::
\destruct{wxDbConnectInf
}}\label{wxdbconnectinfdestr
}
1727 \func{}{\destruct{wxDbConnectInf
}}{}
1729 Handles the default destruction of the instance of the class. If the long form
1730 of the
\helpref{wxDConnectInf
}{wxdbconnectinf
} was used, then this destructor
1731 also takes care of calling
1732 \helpref{wxDConnectInf::FreeHenv
}{wxdbconnectinffreehenv
} to free the
1733 SQL environment handle.
1736 \membersection{wxDbConnectInf::AllocHenv
}\label{wxdbconnectinfallochenv
}
1738 \func{bool
}{AllocHenv
}{\void}
1740 Allocates a SQL environment handle that will be used to interface with
1745 This function can be automatically called by the long from of the
1746 \helpref{wxDbConnectInf
}{wxdbconnectinf
} constructor.
1749 \membersection{wxDbConnectInf::FreeHenv
}\label{wxdbconnectinffreehenv
}
1751 \func{void
}{FreeHenv
}{\void}
1753 Frees the SQL environment handle being managed by the instance of this class.
1757 If the SQL environment handle was created using the long form of the
1758 \helpref{wxDbConnectInf
}{wxdbconnectinf
} constructor, then the flag indicating
1759 that the HENV should be destroyed when the classes destructor is called
1760 is reset to be FALSE, so that any future handles created using the
1761 \helpref{wxDbConnectInf::AllocHenv
}{wxdbconnectinfallochenv
} function
1762 must be manually released with a call to this function.
1765 \membersection{wxDbConnectInf::Initialize
}\label{wxdbconnectinfinitialize
}
1767 Simply initializes all member variables to a cleared state. Called by
1768 the constructor automatically.
1771 \membersection{wxDbConnectInf::GetAuthStr
}\label{wxdbconnectinfgetauthstr
}
1773 \func{const wxChar *
}{GetAuthStr
}{\void}
1775 Accessor function to return the password assigned for this class
1776 instance that will be used with the user ID.
1778 Synonymous with
\helpref{wxDbConnectInf::GetPassword
}{wxdbconnectinfgetpassword
}
1781 \membersection{wxDbConnectInf::GetDefaultDir
}\label{wxdbconnectinfgetdefaultdir
}
1783 \func{const wxChar *
}{GetDefaultDir
}{\void}
1785 Accessor function to return the default directory in which the datasource's data
1786 table is stored. This directory is only used for file based datasources like
1787 dBase. MS-Access does not require this to be set, as the path is set in the
1788 ODBC Administrator for MS-Access.
1791 \membersection{wxDbConnectInf::GetDescription
}\label{wxdbconnectinfgetdescription
}
1793 \func{const wxChar *
}{GetDescription
}{\void}
1795 Accessor function to return the description assigned for this class
1798 NOTE: Description is a FUTURE USE item and is unused currently.
1801 \membersection{wxDbConnectInf::GetDsn
}\label{wxdbconnectinfgetdsn
}
1803 \func{const wxChar *
}{GetDsn
}{\void}
1805 Accessor function to return the datasource name assigned for this class
1809 \membersection{wxDbConnectInf::GetFileType
}\label{wxdbconnectinfgetfiletype
}
1811 \func{const wxChar *
}{GetFileType
}{\void}
1813 Accessor function to return the filetype of the ODBC datasource assigned for
1814 this class instance.
1816 NOTE: FileType is a FUTURE USE item and is unused currently.
1819 \membersection{wxDbConnectInf::GetHenv
}\label{wxdbconnectinfgethenv
}
1821 \func{const HENV
}{GetHenv
}{\void}
1823 Accessor function to return the SQL environment handle being managed
1824 by this class instance.
1827 \membersection{wxDbConnectInf::GetPassword
}\label{wxdbconnectinfgetpassword
}
1829 \func{const wxChar *
}{GetPassword
}{\void}
1831 Accessor function to return the password assigned for this class
1832 instance that will be used with the user ID.
1834 Synonymous with
\helpref{wxDbConnectInf::GetAuthStr
}{wxdbconnectinfgetauthstr
}
1837 \membersection{wxDbConnectInf::GetUid
}\label{wxdbconnectinfgetuid
}
1839 \func{const wxChar *
}{GetUid
}{\void}
1841 Accessor function to return the user ID assigned for this class
1845 \membersection{wxDbConnectInf::GetUserID
}\label{wxdbconnectinfgetuserid
}
1847 \func{const wxChar *
}{GetUserID
}{\void}
1849 Accessor function to return the user ID assigned for this class
1853 \membersection{wxDbConnectInf::SetAuthStr
}\label{wxdbconnectinfsetauthstr
}
1855 \func{\void}{SetAuthStr
}{const wxString &authstr
}
1857 Accessor function to assign the password for this class
1858 instance that will be used with the user ID.
1860 Synonymous with
\helpref{wxDbConnectInf::SetPassword
}{wxdbconnectinfsetpassword
}
1863 \membersection{wxDbConnectInf::SetDefaultDir
}\label{wxdbconnectinfsetdefaultdir
}
1865 \func{\void}{SetDefaultDir
}{const wxString &defDir
}
1867 Accessor function to assign the default directory in which the datasource's data
1868 table is stored. This directory is only used for file based datasources like
1869 dBase. MS-Access does not require this to be set, as the path is set in the
1870 ODBC Administrator for MS-Access.
1873 \membersection{wxDbConnectInf::SetDescription
}\label{wxdbconnectinfsetdescription
}
1875 \func{\void}{SetDescription
}{const wxString &desc
}
1877 Accessor function to assign the description assigned for this class
1880 NOTE: Description is a FUTURE USE item and is unused currently.
1883 \membersection{wxDbConnectInf::SetDsn
}\label{wxdbconnectinfsetdsn
}
1885 \func{\void}{SetDsn
}{const wxString &dsn
}
1887 Accessor function to assign the datasource name for this class instance.
1890 \membersection{wxDbConnectInf::SetFileType
}\label{wxdbconnectinfsetfiletype
}
1892 \func{\void}{SetFileType
}{const wxString &
}
1894 Accessor function to return the filetype of the ODBC datasource assigned for
1895 this class instance.
1897 NOTE: FileType is a FUTURE USE item and is unused currently.
1900 \membersection{wxDbConnectInf::SetHenv
}\label{wxdbconnectinfsethenv
}
1902 \func{void
}{SetHenv
}{\param{const HENV
}{henv
}}
1904 Accessor function to set the SQL environment handle for this class instance.
1907 \membersection{wxDbConnectInf::SetPassword
}\label{wxdbconnectinfsetpassword
}
1909 \func{\void}{SetPassword
}{const wxString &password
}
1911 Accessor function to assign the password for this class
1912 instance that will be used with the user ID.
1914 Synonymous with
\helpref{wxDbConnectInf::SetAuthStr
}{wxdbconnectinfsetauthstr
}
1917 \membersection{wxDbConnectInf::SetUid
}\label{wxdbconnectinfsetuid
}
1919 \func{\void}{SetUid
}{const wxString &uid
}
1921 Accessor function to set the user ID for this class instance.
1924 \membersection{wxDbConnectInf::SetUserID
}\label{wxdbconnectinfsetuserid
}
1926 \func{\void}{SetUserID
}{const wxString &userID
}
1928 Accessor function to assign the user ID for this class instance.
1932 \section{\class{wxDbIdxDef
}}\label{wxdbidxdef
}
1934 Used in creation of non-primary indexes. Currently there are no member
1935 functions for this class.
1938 wxChar ColName
[DB_MAX_COLUMN_NAME_LEN+
1]
1940 bool Ascending // Is index maintained in
1944 There are no constructors/destructors as of this time, and no member functions.
1947 \section{\class{wxDbInf
}}\label{wxdbinf
}
1949 Contains information regarding the database connection (datasource name,
1950 number of tables, etc). A pointer to a wxDbTableInf is included in this
1951 class so a program can create a wxDbTableInf array instance to maintain all
1952 information about all tables in the datasource to have all the datasource's
1953 information in one memory structure.
1955 Primarily, this class is used internally by the wxWindows ODBC classes.
1958 wxChar catalog
[128+
1];
1959 wxChar schema
[128+
1]; // typically means owner of table(s)
1960 int numTables; // How many tables does this
1962 wxDbTableInf *pTableInf; // Equals a new
1963 wxDbTableInf
[numTables
];
1966 The constructor for this class initializes all the values to zero, "", or NULL.
1968 The destructor for this class takes care of deleting the pTableInf member if
1971 \membersection{wxDbInf::Initialize
}\label{wxdbinfinitialize
}
1973 Simply initializes all member variables to a cleared state. Called by
1974 the constructor automatically.
1977 \section{\class{wxDbTable
}}\label{wxdbtable
}
1979 A wxDbTable instance provides re-usable access to rows of data in
1980 a table contained within the associated ODBC datasource
1982 \wxheading{Include files
}
1987 \latexignore{\rtfignore{\wxheading{Members
}}}
1988 \wxheading{Helper classes and data structures
}
1990 The following classes and structs are defined in dbtable.cpp/.h for use
1991 with the wxDbTable class.
1993 \begin{itemize
}\itemsep=
0pt
1994 \item \helpref{wxDbColDef
}{wxdbcoldef
}
1995 \item \helpref{wxDbColDataPtr
}{wxdbcoldataptr
}
1996 \item \helpref{wxDbIdxDef
}{wxdbidxdef
}
1999 \wxheading{Constants
}
2002 wxDB_DEFAULT_CURSOR Primary cursor normally used for cursor based
2005 wxDB_QUERY_ONLY Used to indicate whether a table that is opened
2006 is for query only, or if insert/update/deletes
2007 will be performed on the table. Less overhead
2008 (cursors and memory) are allocated for query
2009 only tables, plus read access times are faster
2010 with some datasources.
2012 wxDB_ROWID_LEN
[Oracle only
] - Used when CanUpdateByRowID()
2013 is true. Optimizes updates so they are faster
2014 by updating on the Oracle-specific ROWID column
2015 rather than some other index.
2018 wxDB_DISABLE_VIEW Use to indicate when a database view should not
2019 be if a table is normally set up to use a view.
2020 [Currently unsupported.
]
2025 \latexignore{\rtfignore{\wxheading{Members
}}}
2027 \membersection{wxDbTable::wxDbTable
}\label{wxdbtableconstr
}
2029 \func{}{wxDbTable
}{\param{wxDb *
}{pwxDb
},
\param{const wxString &
}{tblName
},
2030 \param{const UWORD
}{numColumns
},
\param{const wxString &
}{qryTblName = ""
},
2031 \param{bool
}{qryOnly = !wxDB_QUERY_ONLY
},
\param{const wxString &
}{tblPath = ""
}}
2033 Default constructor.
2035 \wxheading{Parameters
}
2037 \docparam{pwxDb
}{Pointer to the wxDb instance to be used by this wxDbTable
2039 \docparam{tblName
}{The name of the table in the RDBMS.
}
2040 \docparam{numColumns
}{The number of columns in the table. (Do NOT include the ROWID
2041 column in the count if using Oracle).
}
2042 \docparam{qryTblName
}{{\it OPTIONAL
}. The name of the table or view to base
2043 your queries on. This argument allows you to specify a table/view other than
2044 the base table for this object to base your queries on. This allows you to
2045 query on a view for example, but all of the INSERT, UPDATE and DELETES will
2046 still be performed on the base table for this wxDbTable object. Basing your
2047 queries on a view can provide a substantial performance increase in cases where
2048 your queries involve many tables with multiple joins. Default is "".
}
2049 \docparam{qryOnly
}{{\it OPTIONAL
}. Indicates whether the table will be
2050 accessible for query purposes only, or should the table create the necessary
2051 cursors to be able to insert, update, and delete data from the table.
2052 Default is !wxDB_QUERY_ONLY.
}
2053 \docparam{tblPath
}{{\it OPTIONAL
}. Some datasources (such as dBase)
2054 require a path to where the table is stored on the system. Default is "".
}
2056 \membersection{wxDbTable::wxDbTable
}\label{wxdbtabledestr
}
2058 \func{virtual
}{\destruct{wxDbTable
}}{}
2060 Virtual default destructor.
2063 \membersection{wxDbTable::BuildDeleteStmt
}\label{wxdbtablebuilddeletestmt
}
2065 \func{void
}{BuildDeleteStmt
}{\param{wxString &
}{pSqlStmt
},
2066 \param{int
}{typeOfDel
},
\param{const wxString &
}{pWhereClause=""
}}
2068 Constructs the full SQL statement that can be used to delete all rows matching
2069 the criteria in the pWhereClause.
2071 \wxheading{Parameters
}
2073 \docparam{pSqlStmt
}{Pointer to buffer for the SQL statement retrieved. To be
2074 sure you have adequate space allocated for the SQL statement, allocate
2075 DB_MAX_STATEMENT_LEN bytes.
}
2076 \docparam{typeOfDel
}{The type of delete statement being performed. Can be one
2077 of three values: DB_DEL_KEYFIELDS, DB_DEL_WHERE or DB_DEL_MATCHING
}
2078 \docparam{pWhereClause
}{{\it OPTIONAL
}. If the typeOfDel is DB_DEL_WHERE,
2079 then you must also pass in a SQL WHERE clause in this argument. Default
2084 This member function constructs a SQL DELETE statement. This can be used for
2085 debugging purposes if you are having problems executing your SQL statement.
2087 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2088 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2092 \membersection{wxDbTable::BuildSelectStmt
}\label{wxdbtablebuildselectstmt
}
2094 \func{void
}{BuildSelectStmt
}{\param{wxString &
}{pSqlStmt
},
2095 \param{int
}{typeOfSelect
},
\param{bool
}{distinct
}}
2097 Constructs the full SQL statement that can be used to select all rows matching
2098 the criteria in the pWhereClause. This function is called internally in the
2099 wxDbTable class whenever the function
\helpref{wxDbTable::Query
}{wxdbtablequery
}
2102 NOTE: Only the columns specified in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
2103 statements are included in the list of columns returned by the SQL statement
2104 created by a call to this function.
2106 \wxheading{Parameters
}
2108 \docparam{pSqlStmt
}{Pointer to storage for the SQL statement retrieved. To be
2109 sure you have adequate space allocated for the SQL statement, allocate
2110 DB_MAX_STATEMENT_LEN bytes.
}
2111 \docparam{typeOfSelect
}{The type of select statement being performed. Can be
2112 one of four values: DB_SELECT_KEYFIELDS, DB_SELECT_WHERE, DB_SELECT_MATCHING
2113 or DB_SELECT_STATEMENT.
}
2114 \docparam{distinct
}{Whether to select distinct records only.
}
2118 This member function constructs a SQL SELECT statement. This can be used for
2119 debugging purposes if you are having problems executing your SQL statement.
2121 WHERE and FROM clauses specified using
2122 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2123 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2127 \membersection{wxDbTable::BuildUpdateStmt
}\label{wxdbtablebuildupdatestmt
}
2129 \func{void
}{BuildUpdateStmt
}{\param{wxString &
}{pSqlStmt
},
\param{int
}{typeOfUpd
},
2130 \param{const wxString &
}{pWhereClause=""
}}
2132 Constructs the full SQL statement that can be used to update all rows matching
2133 the criteria in the pWhereClause.
2135 If typeOfUpd is DB_UPD_KEYFIELDS, then the current values in the bound columns
2136 are used to determine which row(s) in the table are to be updated. The
2137 exception to this is when a datasource supports ROW IDs (Oracle). The ROW ID
2138 column is used for efficiency purposes when available.
2140 NOTE: Only the columns specified in
\helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
2141 statements are included in the list of columns updated by the SQL statement
2142 created by a call to this function. Any column definitions that were defined
2143 as being non-updateable will be excluded from the SQL UPDATE statement created
2146 \wxheading{Parameters
}
2148 \docparam{pSqlStmt
}{Pointer to storage for the SQL statement retrieved. To be
2149 sure you have adequate space allocated for the SQL statement, allocate
2150 DB_MAX_STATEMENT_LEN bytes.
}
2151 \docparam{typeOfUpd
}{The type of update statement being performed. Can be one
2152 of two values: DB_UPD_KEYFIELDS or DB_UPD_WHERE.
}
2153 \docparam{pWhereClause
}{{\it OPTIONAL
}. If the typeOfUpd is DB_UPD_WHERE,
2154 then you must also pass in a SQL WHERE clause in this argument. Default is "".
}
2158 This member function allows you to see what the SQL UPDATE statement looks like
2159 that the ODBC class library builds. This can be used for debugging purposes if
2160 you are having problems executing your SQL statement.
2162 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2163 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2167 \membersection{wxDbTable::BuildWhereStmt
}\label{wxdbtablebuildwherestmt
}
2169 \func{void
}{BuildSelectStmt
}{\param{wxString &
}{pWhereClause
},
2170 \param{int
}{typeOfWhere
},
\param{const wxString &
}{qualTableName=""
},
2171 \param{bool
}{useLikeComparison=FALSE
}}
2173 Constructs the portion of a SQL statement which would follow the word 'WHERE'
2174 in a SQL statement to be passed to the datasource. The returned string
2175 does NOT include the word 'WHERE'.
2177 \wxheading{Parameters
}
2179 \docparam{pWhereClause
}{Pointer to storage for the SQL statement retrieved.
2180 To be sure you have adequate space allocated for the SQL statement, allocate
2181 DB_MAX_STATEMENT_LEN bytes.
}
2182 \docparam{typeOfWhere
}{The type of where clause to generate. Can be one of
2183 two values: DB_WHERE_KEYFIELDS or DB_WHERE_MATCHING.
}
2184 \docparam{qualTableName
}{{\it OPTIONAL
}. Prepended to all base table
2185 column names. For use when a FROM clause has been specified with the
2186 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
},
2187 to clarify which table a column name reference belongs to. Default is "".
}
2188 \docparam{useLikeComparison
}{{\it OPTIONAL
}. Should the constructed WHERE
2189 clause utilize the LIKE comparison operator. If FALSE, then the '='
2190 operator is used. Default is FALSE.
}
2194 This member function allows you to see what the SQL WHERE clause looks like
2195 that the ODBC class library builds. This can be used for debugging purposes
2196 if you are having problems executing your own SQL statements.
2198 If using 'typeOfWhere' set to DB_WHERE_MATCHING, any bound columns currently
2199 containing a NULL value are not included in the WHERE clause's list of
2200 columns to use in the comparison.
2203 \membersection{wxDbTable::CanSelectForUpdate
}\label{wxdbtablecanselectforupdate
}
2205 \func{bool
}{CanSelectForUpdate
}{\void}
2207 Use this function to determine if the datasource supports SELECT ... FOR UPDATE.
2208 When the keywords "FOR UPDATE" are included as part of your SQL SELECT statement,
2209 all records
{\it retrieved
} (not just queried, but actually retrieved using
2210 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}, etc) from the result set are
2215 Not all datasources support the "FOR UPDATE" clause, so you must use this
2216 member function to determine if the datasource currently connected to supports
2217 this behavior or not before trying to select using "FOR UPDATE".
2219 If the wxDbTable instance was created with the parameter wxDB_QUERY_ONLY, then
2220 this function will return FALSE. For all known databases which do not support
2221 the FOR UPDATE clause, this function will return FALSE also.
2224 \membersection{wxDbTable::CanUpdateByROWID
}\label{wxdbtablecanupdatebyrowid
}
2226 \func{bool
}{CanUpdateByROWID
}{\void}
2228 CURRENTLY ONLY POSSIBLE IF USING ORACLE.
2230 --- CURRENTLY DISABLED FOR *ALL* DATASOURCES --- NOV
1 2000 - gt
2232 Every Oracle table has a hidden column named ROWID. This is a pointer to the
2233 physical location of the record in the datasource and allows for very fast
2234 updates and deletes. The key is to retrieve this ROWID during your query so
2235 it is available during an update or delete operation.
2237 Use of the ROWID feature is always handled by the class library except in the
2238 case of
\helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}. Since
2239 you are passing in the SQL SELECT statement,
2240 it is up to you to include the ROWID column in your query. If you do not,
2241 the application will still work, but may not be as optimized. The ROWID is
2242 always the last column in the column list in your SQL SELECT statement.
2243 The ROWID is not a column in the normal sense and should not be considered
2244 part of the column definitions for the wxDbTable object.
2248 The decision to include the ROWID in your SQL SELECT statement must be
2249 deferred until runtime since it depends on whether you are connected
2250 to an Oracle datasource or not.
2255 // Incomplete code sample
2258 if (parts.CanUpdByROWID())
2260 // Note that the ROWID column must always be the last column selected
2261 sqlStmt = "SELECT PART_NO, PART_DESC, ROWID" FROM PARTS";
2264 sqlStmt = "SELECT PART_NO, PART_DESC FROM PARTS";
2268 \membersection{wxDbTable::ClearMemberVar
}\label{wxdbtableclearmembervar
}
2270 \func{void
}{ClearMemberVar
}{\param{UWORD
}{colNo
},
\param{bool
}{setToNull=FALSE
}}
2272 Same as
\helpref{wxDbTable::ClearMemberVars
}{wxdbtableclearmembervars
} except
2273 that this function clears only the specified column of its values, and
2274 optionally sets the column to be a NULL column.
2276 \docparam{colNo
}{Column number that is to be cleared. This number (between
0
2277 and (noCols-
1)) is the index of the column definition created using the
2278 \helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
} function.
}
2279 \docparam{setToNull
}{{\it OPTIONAL
}. Indicates whether the column should be
2280 flagged as being a NULL value stored in the bound memory variable. If TRUE,
2281 then any value stored in the bound member variable is cleared. Default is
2285 \membersection{wxDbTable::ClearMemberVars
}\label{wxdbtableclearmembervars
}
2287 \func{void
}{ClearMemberVars
}{\param{bool
}{setToNull=FALSE
}}
2289 Initializes all bound columns of the wxDbTable instance to zero. In the case
2290 of a string, zero is copied to the first byte of the string.
2292 \docparam{setToNull
}{{\it OPTIONAL
}. Indicates whether all columns should be
2293 flagged as having a NULL value stored in the bound memory variable. If TRUE,
2294 then any value stored in the bound member variable is cleared. Default is
2299 This is useful before calling functions such as
2300 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2301 \helpref{wxDbTable::DeleteMatching
}{wxdbtabledeletematching
} since these
2302 functions build their WHERE clauses from non-zero columns. To call either
2303 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2304 \helpref{wxDbTable::DeleteMatching
}{wxdbtabledeletematching
} use this sequence:
2307 1) ClearMemberVars()
2308 2) Assign columns values you wish to match on
2309 3) Call wxDbTable::QueryMatching() or wxDbTable::DeleteMatching()
2313 \membersection{wxDbTable::CloseCursor
}\label{wxdbtableclosecursor
}
2315 \func{bool
}{CloseCursor
}{\param{HSTMT
}{cursor
}}
2317 Closes the specified cursor associated with the wxDbTable object.
2319 \wxheading{Parameters
}
2321 \docparam{cursor
}{The cursor to be closed.
}
2325 Typically handled internally by the ODBC class library, but may be used by the
2326 programmer if desired.
2329 \normalbox{DO NOT CLOSE THE wxDB_DEFAULT_CURSOR!
}
2332 \membersection{wxDbTable::Count
}\label{wxdbtablecount
}
2334 \func{ULONG
}{Count
}{\param{const wxString &
}{args="*"
}}
2336 Returns the number of records which would be in the result set using the
2337 current query parameters specified in the WHERE and FROM clauses.
2339 \wxheading{Parameters
}
2341 \docparam{args
}{{\it OPTIONAL
}. This argument allows the use of the
2342 DISTINCT keyword against a column name to cause the returned count to
2343 only indicate the number of rows in the result set that have a unique
2344 value in the specified column. An example is shown below. Default is "*",
2345 meaning a count of the total number of rows matching is returned, regardless
2350 This function can be called before or after an actual query to obtain the
2351 count of records in the result set. Count() uses its own cursor, so result
2352 set cursor positioning is not affected by calls to Count().
2354 WHERE and FROM clauses specified using
2355 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2356 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} ARE used by
2365 FIRST_NAME LAST_NAME
2366 ----------- ----------
2372 // Incomplete code sample
2375 users.SetWhereClause("");
2377 // This Count() will return
4, as there are four users listed above
2378 // that match the query parameters
2379 totalNumberOfUsers = users.Count();
2381 // This Count() will return
3, as there are only
3 unique first names
2382 // in the table above - John, Richard, Michael.
2383 totalNumberOfUniqueFirstNames = users.Count("DISTINCT FIRST_NAME");
2387 \membersection{wxDbTable::CreateIndex
}\label{wxdbtablecreateindex
}
2389 \func{bool
}{CreateIndex
}{\param{const wxString &
}{idxName
},
\param{bool
}{unique
},
2390 \param{UWORD
}{noIdxCols
},
\param{wxDbIdxDef *
}{pIdxDefs
},
2391 \param{bool
}{attemptDrop=TRUE
}}
2393 This member function allows you to create secondary (non primary) indexes on
2394 your tables. You first create your table, normally specifying a primary
2395 index, and then create any secondary indexes on the table. Indexes in
2396 relational model are not required. You do not need indexes to look up records
2397 in a table or to join two tables together. In the relational model, indexes,
2398 if available, provide a quicker means to look up data in a table. To enjoy
2399 the performance benefits of indexes, the indexes must be defined on the
2400 appropriate columns and your SQL code must be written in such a way as to
2401 take advantage of those indexes.
2403 \wxheading{Parameters
}
2405 \docparam{idxName
}{Name of the Index. Name must be unique within the table
2406 space of the datasource.
}
2407 \docparam{unique
}{Indicates if this index is unique.
}
2408 \docparam{noIdxCols
}{Number of columns in the index.
}
2409 \docparam{pIdxDefs
}{A pointer to an array wxDbIdxDef structures.
}
2410 \docparam{attemptDrop
}{{\it OPTIONAL
}. Indicates if the function should try
2411 to execute a
\helpref{wxDbTable::DropIndex
}{wxdbtabledropindex
} on the index
2412 name provided before trying to create the index name. Default is TRUE.
}
2416 The first parameter, index name, must be unique and should be given a
2417 meaningful name. Common practice is to include the table name as a prefix
2418 in the index name (e.g. For table PARTS, you might want to call your index
2419 PARTS_IDX1). This will allow you to easily view all
2420 of the indexes defined for a given table grouped together alphabetically.
2422 The second parameter indicates if the index is unique or not. Uniqueness
2423 is enforced at the RDBMS level preventing rows which would have duplicate
2424 indexes from being inserted into the table when violating a unique index's
2427 In the third parameter, specify how many columns are in your index. This
2428 number must match the number of columns defined in the 'pIdxDefs' parameter.
2430 The fourth parameter specifies which columns make up the index using the
2431 wxDbIdxDef structure. For each column in the index, you must specify two
2432 things, the column name and the sort order (ascending / descending). See
2433 the example below to see how to build and pass in the wxDbIdxDef structure.
2435 The fifth parameter is provided to handle the differences in datasources as
2436 to whether they will automatically overwrite existing indexes with the same
2437 name or not. Some datasources require that the existing index must be dropped
2438 first, so this is the default behavior.
2440 Some datasources (MySQL, and possibly others) require columns which are to be
2441 part of an index to be defined as NOT NULL. When this function is called, if
2442 a column is not defined to be NOT NULL, a call to this function will modify
2443 the column definition to change any columns included in the index to be
2444 NOT NULL. In this situation, if a NULL value already exists in one of the
2445 columns that is being modified, creation of the index will fail.
2447 PostGres is unable to handle index definitions which specify whether the index
2448 is ascending or descending, and defaults to the system default when the index
2451 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2452 after executing this function.
2457 // Create a secondary index on the PARTS table
2458 wxDbIdxDef idxDef
[2]; //
2 columns make up the index
2460 wxStrcpy(idxDef
[0].ColName, "PART_DESC"); // Column
1
2461 idxDef
[0].Ascending = TRUE;
2463 wxStrcpy(idxDef
[1].ColName, "SERIAL_NO"); // Column
2
2464 idxDef
[1].Ascending = FALSE;
2466 // Create a name for the index based on the table's name
2468 indexName.Printf("
%s_IDX1",parts->GetTableName());
2469 parts->CreateIndex(indexName, TRUE,
2, idxDef);
2473 \membersection{wxDbTable::CreateTable
}\label{wxdbtablecreatetable
}
2475 \func{bool
}{CreateTable
}{\param{bool
}{attemptDrop=TRUE
}}
2477 Creates a table based on the definitions previously defined for this
2480 \wxheading{Parameters
}
2482 \docparam{attemptDrop
}{{\it OPTIONAL
}. Indicates whether the driver should
2483 attempt to drop the table before trying to create it. Some datasources will
2484 not allow creation of a table if the table already exists in the table space
2485 being used. Default is TRUE.
}
2489 This function creates the table and primary index (if any) in the table space
2490 associated with the connected datasource. The owner of these objects will
2491 be the user id that was given when
\helpref{wxDb::Open
}{wxdbopen
} was called.
2492 The objects will be created in the default schema/table space for that user.
2494 In your derived wxDbTable object constructor, the columns and primary index
2495 of the table are described through the
\helpref{wxDbColDef
}{wxdbcoldef
} structure.
2496 \helpref{wxDbTable::CreateTable
}{wxdbtablecreatetable
} uses this information
2497 to create the table and to add the primary index. See
2498 \helpref{wxDbTable
}{wxdbtable
} ctor and wxDbColDef description for additional
2499 information on describing the columns of the table.
2501 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2502 after executing this function.
2505 \membersection{wxDbTable::DB_STATUS
}\label{wxdbtabledbstatus
}
2507 \func{bool
}{DB_STATUS
}{\void}
2509 Accessor function that returns the wxDb private member variable DB_STATUS for
2510 the database connection used by this instance of wxDbTable.
2513 \membersection{wxDbTable::Delete
}\label{wxdbtabledelete
}
2515 \func{bool
}{Delete
}{\void}
2517 Deletes the row from the table indicated by the current cursor.
2521 Use
\helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
},
2522 \helpref{wxDbTable::GetLast
}{wxdbtablegetlast
},
2523 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
} or
2524 \helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
} to position the cursor to
2525 a valid record. Once positioned on a record, call this function to delete
2526 the row from the table.
2528 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2529 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
2530 this function to commit or rollback the deletion.
2532 NOTE: Most datasources have a limited size "rollback" segment. This means
2533 that it is only possible to insert/update/delete a finite number of rows
2534 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2535 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2536 segment varies from database to database, and is user configurable in
2537 most databases. Therefore it is usually best to try to perform a commit
2538 or rollback at relatively small intervals when processing a larger number
2539 of actions that insert/update/delete rows in a table.
2542 \membersection{wxDbTable::DeleteCursor
}\label{wxdbtabledeletecursor
}
2544 \func{bool
}{DeleteCursor
}{\param{HSTMT *
}{hstmtDel
}}
2546 Allows a program to delete a cursor.
2548 \wxheading{Parameters
}
2550 \docparam{hstmtDel
}{Handle of the cursor to delete.
}
2554 For default cursors associated with the instance of wxDbTable, it is not
2555 necessary to specifically delete the cursors. This is automatically done
2556 in the wxDbTable destructor.
2558 NOTE: If the cursor could not be deleted for some reason, an error is logged
2559 indicating the reason. Even if the cursor could not be deleted, the HSTMT
2560 that is passed in is deleted, and the pointer is set to NULL.
2562 \normalbox{DO NOT DELETE THE wxDB_DEFAULT_CURSOR!
}
2565 \membersection{wxDbTable::DeleteMatching
}\label{wxdbtabledeletematching
}
2567 \func{bool
}{DeleteMatching
}{\void}
2569 This member function allows you to delete records from your wxDbTable object
2570 by specifying the data in the columns to match on.
2574 To delete all users with a first name of "JOHN", do the following:
2577 1) Clear all "columns" using wxDbTable::ClearMemberVars().
2578 2) Set the FIRST_NAME column equal to "JOHN".
2579 3) Call wxDbTable::DeleteMatching().
2582 The WHERE clause is built by the ODBC class library based on all non-NULL
2583 columns. This allows deletion of records by matching on any column(s) in
2584 your wxDbTable instance, without having to write the SQL WHERE clause.
2586 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2587 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
2588 this function to commit or rollback the deletion.
2590 NOTE: Row(s) should be locked before deleting them to make sure they are
2591 not already in use. This can be achieved by calling
2592 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
},
2593 and then retrieving the records, locking each as you go (assuming FOR UPDATE
2594 is allowed on the datasource). After the row(s) have been successfully locked,
2597 NOTE: Most datasources have a limited "rollback" segment. This means
2598 that it is only possible to insert/update/delete a finite number of rows
2599 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2600 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2601 segment varies from database to database, and is user configurable in
2602 most databases. Therefore it is usually best to try to perform a commit
2603 or rollback at relatively small intervals when processing a larger number
2604 of actions that insert/update/delete rows in a table.
2610 // Incomplete code sample to delete all users with a first name
2612 users.ClearMemberVars();
2613 wxStrcpy(users.FirstName,"JOHN");
2614 users.DeleteMatching();
2618 \membersection{wxDbTable::DeleteWhere
}\label{wxdbtabledeletewhere
}
2620 \func{bool
}{DeleteWhere
}{\param{const wxString &
}{pWhereClause
}}
2622 Deletes all rows from the table which match the criteria specified in the
2623 WHERE clause that is passed in.
2625 \wxheading{Parameters
}
2627 \docparam{pWhereClause
}{SQL WHERE clause. This WHERE clause determines which
2628 records will be deleted from the table interfaced through the wxDbTable
2629 instance. The WHERE clause passed in must be compliant with the SQL
92
2630 grammar. Do not include the keyword 'WHERE'
2635 This is the most powerful form of the wxDbTable delete functions. This
2636 function gives access to the full power of SQL. This function can be used
2637 to delete records by passing a valid SQL WHERE clause. Sophisticated
2638 deletions can be performed based on multiple criteria using the full
2639 functionality of the SQL language.
2641 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} must be called after use of
2642 this function to commit the deletions.
2644 Note: This function is limited to deleting records from the table associated
2645 with this wxDbTable object only. Deletions on joined tables is not possible.
2647 NOTE: Most datasources have a limited size "rollback" segment. This means
2648 that it is only possible to insert/update/delete a finite number of rows
2649 without performing a
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
2650 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
}. Size of the rollback
2651 segment varies from database to database, and is user configurable in
2652 most databases. Therefore it is usually best to try to perform a commit
2653 or rollback at relatively small intervals when processing a larger number
2654 of actions that insert/update/delete rows in a table.
2656 WHERE and FROM clauses specified using
\helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
2657 and
\helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} are ignored by
2663 // Delete parts
1 thru
10 from containers 'X', 'Y' and 'Z' that
2664 // are magenta in
color
2665 parts.DeleteWhere("(PART_NUMBER BETWEEN
1 AND
10) AND \
2666 CONTAINER IN ('X', 'Y', 'Z') AND \
2667 UPPER(COLOR) = 'MAGENTA'");
2671 \membersection{wxDbTable::DropIndex
}\label{wxdbtabledropindex
}
2673 \func{bool
}{DropIndex
}{\param{const wxString &
}{idxName
}}
2675 Allows an index on the associated table to be dropped (deleted) if the user
2676 login has sufficient privileges to do so.
2678 \wxheading{Parameters
}
2680 \docparam{idxName
}{Name of the index to be dropped.
}
2684 If the index specified in the 'idxName' parameter does not exist, an error
2685 will be logged, and the function will return a result of FALSE.
2687 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2688 after executing this function.
2691 \membersection{wxDbTable::DropTable
}\label{wxdbtabledroptable
}
2693 \func{bool
}{DropTable
}{\void}
2695 Deletes the associated table if the user has sufficient privileges to do so.
2699 This function returns TRUE if the table does not exist, but only for
2700 supported databases (see
\helpref{wxDb::Dbms
}{wxdbdbms
}). If a datasource
2701 is not specifically supported, and this function is called, the function
2704 Most datasources/ODBC drivers will delete any indexes associated with the
2705 table automatically, and others may not. Check the documentation for your
2706 database to determine the behavior.
2708 It is not necessary to call
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}
2709 after executing this function.
2712 \membersection{wxDbTable::From
}\label{wxdbtablefrom
}
2714 \func{const wxString &
}{From
}{}
2716 \func{void
}{From
}{\param{const wxString &
}{From
}}
2718 Accessor function for the private class member wxDbTable::from. Can be used
2719 as a synonym for
\helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
}
2720 (the first form of this function) or
2721 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} (the second form
2724 \wxheading{Parameters
}
2726 \docparam{From
}{A comma separated list of table names that are to be outer
2727 joined with the base table's columns so that the joined table's columns
2728 may be returned in the result set or used as a portion of a comparison with
2729 the base table's columns. NOTE that the base tables name must NOT be included
2730 in the FROM clause, as it is automatically included by the wxDbTable class
2731 in constructing query statements.
}
2733 \wxheading{Return value
}
2735 The first form of this function returns the current value of the wxDbTable
2736 member variable ::from.
2738 The second form of the function has no return value, as it will always set
2739 the from clause successfully.
2741 \wxheading{See also
}
2743 \helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
},
2744 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}
2747 \membersection{wxDbTable::GetColDefs
}\label{wxdbtablegetcoldefs
}
2749 \func{wxDbColDef *
}{GetColDefs
}{}
2751 Accessor function that returns a pointer to the array of column definitions
2752 that are bound to the columns that this wxDbTable instance is associated
2755 To determine the number of elements pointed to by the returned
2756 \helpref{wxDbColDef
}{wxdbcoldef
} pointer, use the
2757 \helpref{wxDbTable::GetNumberOfColumns
}{wxdbtablegetnumberofcolumns
} function.
2761 These column definitions must not be manually redefined after they have been
2765 \membersection{wxDbTable::GetCursor
}\label{wxdbtablegetcursor
}
2767 \func{HSTMT
}{GetCursor
}{\void}
2769 Returns the HSTMT value of the current cursor for this wxDbTable object.
2773 This function is typically used just before changing to use a different cursor
2774 so that after the program is finished using the other cursor, the current
2775 cursor can be set back to being the cursor in use.
2777 \wxheading{See also
}
2779 \helpref{wxDbTable::SetCursor
}{wxdbtablesetcursor
},
\helpref{wxDbTable::GetNewCursor
}{wxdbtablegetnewcursor
}
2782 \membersection{wxDbTable::GetDb
}\label{wxdbtablegetdb
}
2784 \func{wxDb *
}{GetDb
}{}
2786 Accessor function for the private member variable pDb which is a pointer to
2787 the datasource connection that this wxDbTable instance uses.
2790 \membersection{wxDbTable::GetFirst
}\label{wxdbtablegetfirst
}
2792 \func{bool
}{GetFirst
}{\void}
2794 Retrieves the FIRST row in the record set as defined by the current query.
2795 Before retrieving records, a query must be performed using
2796 \helpref{wxDbTable::Query
}{wxdbtablequery
},
2797 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2798 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2799 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2803 This function can only be used if the datasource connection used by the
2804 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2805 connection does not allow backward scrolling cursors, this function will
2806 return FALSE, and the data contained in the bound columns will be undefined.
2808 \wxheading{See also
}
2810 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
}
2813 \membersection{wxDbTable::GetFromClause
}\label{wxdbtablegetfromclause
}
2815 \func{const wxString &
}{GetFromClause
}{}
2817 Accessor function that returns the current FROM setting assigned with the
2818 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}.
2820 \wxheading{See also
}
2822 \helpref{wxDbTable::From
}{wxdbtablefrom
}
2825 \membersection{wxDbTable::GetLast
}\label{wxdbtablegetlast
}
2827 \func{bool
}{GetLast
}{\void}
2829 Retrieves the LAST row in the record set as defined by the current query.
2830 Before retrieving records, a query must be performed using
2831 \helpref{wxDbTable::Query
}{wxdbtablequery
},
2832 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2833 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2834 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2838 This function can only be used if the datasource connection used by the
2839 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2840 connection does not allow backward scrolling cursors, this function will
2841 return FALSE, and the data contained in the bound columns will be undefined.
2843 \wxheading{See also
}
2845 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
}
2848 \membersection{wxDbTable::GetNewCursor
}\label{wxdbtablegetnewcursor
}
2850 \func{HSTMT *
}{GetNewCursor
}{\param{bool
}{setCursor=FALSE
},
2851 \param{bool
}{bindColumns=TRUE
}}
2853 This function will create a new cursor that can be used to access the table
2854 being referenced by this wxDbTable instance, or to execute direct SQL commands
2855 on without affecting the cursors that are already defined and possibly
2858 \wxheading{Parameters
}
2860 \docparam{setCursor
}{{\it OPTIONAL
}. Should this new cursor be set to be the
2861 current cursor after successfully creating the new cursor. Default is FALSE.
}
2862 \docparam{bindColumns
}{{\it OPTIONAL
}. Should this new cursor be bound to all
2863 the memory variables that the default cursor is bound to. Default is TRUE.
}
2867 This new cursor must be closed using
2868 \helpref{wxDbTable::DeleteCursor
}{wxdbtabledeletecursor
}
2869 by the calling program before the wxDbTable instance is deleted, or both
2870 memory and resource leaks will occur.
2873 \membersection{wxDbTable::GetNext
}\label{wxdbtablegetnext
}
2875 \func{bool
}{GetNext
}{\void}
2877 Retrieves the NEXT row in the record set after the current cursor position
2878 as defined by the current query. Before retrieving records, a query must be
2879 performed using
\helpref{wxDbTable::Query
}{wxdbtablequery
},
2880 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2881 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2882 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2884 \wxheading{Return value
}
2886 This function returns FALSE when the current cursor has reached the end of
2887 the result set. When FALSE is returned, data in the bound columns is
2892 This function works with both forward and backward scrolling cursors.
2894 \wxheading{See also
}
2895 \helpref{wxDbTable::++
}{wxdbtableplusplus
}
2898 \membersection{wxDbTable::GetNumberOfColumns
}\label{wxdbtablegetnumberofcolumns
}
2900 \func{UWORD
}{GetNumberOfColumns
}{}
2902 Accessor function that returns the number of columns that are statically
2903 bound for access by the wxDbTable instance.
2906 \membersection{wxDbTable::GetOrderByClause
}\label{wxdbtablegetorderbyclause
}
2908 \func{const wxString &
}{GetOrderByClause
}{}
2910 Accessor function that returns the current ORDER BY setting assigned with
2911 the
\helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
}.
2913 \wxheading{See also
}
2915 \helpref{wxDbTable::OrderBy
}{wxdbtableorderby
}
2918 \membersection{wxDbTable::GetPrev
}\label{wxdbtablegetprev
}
2920 \func{bool
}{GetPrev
}{\void}
2922 Retrieves the PREVIOUS row in the record set before the current cursor
2923 position as defined by the current query. Before retrieving records, a
2924 query must be performed using
\helpref{wxDbTable::Query
}{wxdbtablequery
},
2925 \helpref{wxDbTable::QueryOnKeyFields
}{wxdbtablequeryonkeyfields
},
2926 \helpref{wxDbTable::QueryMatching
}{wxdbtablequerymatching
} or
2927 \helpref{wxDbTable::QueryBySqlStmt
}{wxdbtablequerybysqlstmt
}.
2929 \wxheading{Return value
}
2931 This function returns FALSE when the current cursor has reached the beginning
2932 of the result set and there are now other rows prior to the cursors current
2933 position. When FALSE is returned, data in the bound columns is undefined.
2937 This function can only be used if the datasource connection used by the
2938 wxDbTable instance was created with FwdOnlyCursors set to FALSE. If the
2939 connection does not allow backward scrolling cursors, this function will
2940 return FALSE, and the data contained in the bound columns will be undefined.
2942 \wxheading{See also
}
2944 \helpref{wxDb::IsFwdOnlyCursors
}{wxdbisfwdonlycursors
},
2945 \helpref{wxDbTable::--
}{wxdbtableminusminus
}
2948 \membersection{wxDbTable::GetQueryTableName
}\label{wxdbtablegetquerytablename
}
2950 \func{const wxString &
}{GetQueryTableName
}{}
2952 Accessor function that returns the name of the table/view that was indicated
2953 as being the table/view to query against when this wxDbTable instance was
2956 \wxheading{See also
}
2958 \helpref{wxDbTable constructor
}{wxdbtableconstr
}
2961 \membersection{wxDbTable::GetRowNum
}\label{wxdbtablegetrownum
}
2963 \func{UWORD
}{GetRowNum
}{\void}
2965 Returns the ODBC row number for performing positioned updates and deletes.
2969 This function is not being used within the ODBC class library and may be a
2970 candidate for removal if no use is found for it.
2972 Row number with some datasources/ODBC drivers is the position in the result set,
2973 while in others it may be a physical position in the database. Check your
2974 database documentation to find out which behavior is supported.
2977 \membersection{wxDbTable::GetTableName
}\label{wxdbtablegettablename
}
2979 \func{const wxString &
}{GetTableName
}{}
2981 Accessor function that returns the name of the table that was indicated
2982 as being the table that this wxDbTable instance was associated with.
2985 \membersection{wxDbTable::GetTablePath
}\label{wxdbtablegettablepath
}
2987 \func{const wxString &
}{GetTablePath
}{}
2989 Accessor function that returns the path to the data table that was indicated
2990 during creation of this wxDbTable instance.
2994 Currently only applicable to dBase and MS-Access datasources.
2997 \membersection{wxDbTable::GetWhereClause
}\label{wxdbtablegetwhereclause
}
2999 \func{const wxString &
}{GetWhereClause
}{}
3001 Accessor function that returns the current WHERE setting assigned with the
3002 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
3004 \wxheading{See also
}
3006 \helpref{wxDbTable::Where
}{wxdbtablewhere
}
3009 \membersection{wxDbTable::Insert
}\label{wxdbtableinsert
}
3011 \func{int
}{Insert
}{\void}
3013 Inserts a new record into the table being referenced by this wxDbTable
3014 instance. The values in the member variables of the wxDbTable instance are
3015 inserted into the columns of the new row in the database.
3017 \wxheading{Return value
}
3020 DB_SUCCESS Record inserted successfully (value =
1)
3022 DB_FAILURE Insert failed (value =
0)
3024 DB_ERR_INTEGRITY_CONSTRAINT_VIOL
3025 The insert failed due to an integrity
3026 constraint violation (duplicate non-unique
3027 index entry) is attempted.
3032 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
3033 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
3034 this function to commit or rollback the insertion.
3039 // Incomplete code snippet
3040 wxStrcpy(parts->PartName, "
10");
3041 wxStrcpy(parts->PartDesc, "Part
#10");
3043 RETCODE retcode = parts.Insert();
3047 parts->GetDb()->CommitTrans();
3049 case DB_ERR_INTEGRITY_CONSTRAINT_VIOL:
3050 // Current data would result in a duplicate key
3051 // on one or more indexes that do not allow duplicates
3052 parts->GetDb()->RollbackTrans();
3055 // Insert failed for some unexpected reason
3056 parts->GetDb()->RollbackTrans();
3062 \membersection{wxDbTable::IsColNull
}\label{wxdbtableiscolnull
}
3064 \func{bool
}{IsColNull
}{\param{UWORD
}{colNo
}}
3066 Used primarily in the ODBC class library to determine if a column value is
3067 set to "NULL". Works for all data types supported by the ODBC class library.
3069 \wxheading{Parameters
}
3071 \docparam{colNo
}{The column number of the bound column as defined by the
3072 \helpref{wxDbTable::SetColDefs
}{wxdbtablesetcoldefs
}
3073 calls which defined the columns accessible to this wxDbTable instance.
}
3077 NULL column support is currently not fully implemented as of wxWindows
2.4
3080 \membersection{wxDbTable::IsCursorClosedOnCommit
}\label{wxdbtableiscursorclosedoncommit
}
3082 \func{bool
}{IsCursorClosedOnCommit
}{\void}
3084 Accessor function to return information collected during the opening of the
3085 datasource connection that is used by this wxDbTable instance. The result
3086 returned by this function indicates whether an implicit closing of the cursor is
3087 done after a commit on the database connection.
3089 \wxheading{Return value
}
3091 Returns TRUE if the cursor associated with this wxDbTable object is closed
3092 after a commit or rollback operation. Returns FALSE otherwise.
3096 If more than one wxDbTable instance used the same database connection, all cursors
3097 which use the database connection are closed on the commit if this function
3101 \membersection{wxDbTable::IsQueryOnly
}\label{wxdbtableisqueryonly
}
3103 \func{bool
}{IsQueryOnly
}{}
3105 Accessor function that returns a value indicating if this wxDbTable instance
3106 was created to allow only queries to be performed on the bound columns. If
3107 this function returns TRUE, then no actions may be performed using this
3108 wxDbTable instance that would modify (insert/delete/update) the table's data.
3111 \membersection{wxDbTable::Open
}\label{wxdbtableopen
}
3113 \func{bool
}{Open
}{\param{bool
}{checkPrivileges=FALSE
},
\param{bool
}{checkTableExists=TRUE
}}
3115 Every wxDbTable instance must be opened before it can be used. This function
3116 checks for the existence of the requested table, binds columns, creates required
3117 cursors, (insert/select and update if connection is not wxDB_QUERY_ONLY) and
3118 constructs the insert statement that is to be used for inserting data as a new
3119 row in the datasource.
3121 \wxheading{Parameters
}
3123 \docparam{checkPrivileges
}{Indicates whether the Open() function should check
3124 whether the current connected user has at least SELECT privileges to access the
3125 table to which they are trying to open. Default is FALSE.
}
3127 \docparam{checkTableExists
}{Indicates whether the Open() function should check
3128 whether the table exists in the database or not before opening it. Default is TRUE.
}
3132 If the function returns a FALSE value due to the table not existing, a log
3133 entry is recorded for the datasource connection indicating the problem
3134 that was detected when checking for table existence. Note that it is usually
3135 best for the calling routine to check for the existence of the table and for
3136 sufficent user privileges to access the table in the mode (wxDB_QUERY_ONLY or
3137 !wxDB_QUERY_ONLY) before trying to open the table for the best possible
3138 explanation as to why a table cannot be opened.
3140 Checking the user's privileges on a table can be quite time consuming during
3141 the open phase. With most applications, the programmer already knows that the
3142 user has sufficient privileges to access the table, so this check is normally
3145 For best performance, open the table, and then use the
3146 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
} function
3147 to check the users privileges. Passing a schema to the TablePrivileges()
3148 function can significantly speed up the privileges checks.
3150 \wxheading{See also
}
3152 \helpref{wxDb::TableExists
}{wxdbtableexists
},
3153 \helpref{wxDb::TablePrivileges
}{wxdbtableprivileges
}
3156 \membersection{wxDbTable::OrderBy
}\label{wxdbtableorderby
}
3158 \func{const wxString &
}{OrderBy
}{}
3160 \func{void
}{OrderBy
}{\param{const wxString &
}{OrderBy
}}
3162 Accessor function for the private class member wxDbTable::orderBy. Can be
3163 used as a synonym for
3164 \helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
}
3165 (the first form of this function) or
3166 \helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
}
3167 (the second form of this function).
3169 \wxheading{Parameters
}
3171 \docparam{OrderBy
}{A comma separated list of column names that indicate the
3172 alphabetized/numeric sorting sequence that the result set is to be returned
3173 in. If a FROM clause has also been specified, each column name specified in
3174 the ORDER BY clause should be prefaced with the table name to which the column
3175 belongs using DOT notation (TABLE_NAME.COLUMN_NAME).
}
3177 \wxheading{Return value
}
3179 The first form of this function returns the current value of the wxDbTable
3180 member variable ::orderBy.
3182 The second form of the function has no return value.
3184 \wxheading{See also
}
3186 \helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
},
3187 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}
3190 \membersection{wxDbTable::Query
}\label{wxdbtablequery
}
3192 \func{virtual bool
}{Query
}{\param{bool
}{forUpdate=FALSE
},
\param{bool
}{distinct=FALSE
}}
3194 \wxheading{Parameters
}
3196 \docparam{forUpdate
}{{\it OPTIONAL
}. Gives you the option of locking records
3197 as they are retrieved. If the RDBMS is not capable of the FOR UPDATE clause,
3198 this argument is ignored. See
3199 \helpref{wxDbTable::CanSelectForUpdate
}{wxdbtablecanselectforupdate
} for
3200 additional information regarding this argument. Default is FALSE.
}
3201 \docparam{distinct
}{{\it OPTIONAL
}. Allows selection of only distinct values
3202 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
3203 applies to all columns returned in the result set, not individual columns.
3208 This function queries records from the datasource based on the three
3209 wxDbTable members: "where", "orderBy", and "from". Use
3210 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
} to filter on
3211 records to be retrieved (e.g. All users with a first name of "JOHN").
3212 Use
\helpref{wxDbTable::SetOrderByClause
}{wxdbtablesetorderbyclause
} to
3213 change the sequence in which records are returned in the result set from
3214 the datasource (e.g. Ordered by LAST_NAME). Use
3215 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
} to allow outer
3216 joining of the base table (the one being associated with this instance of
3217 wxDbTable) with other tables which share a related field.
3219 After each of these clauses are set/cleared, call wxDbTable::Query() to
3220 fetch the result set from the datasource.
3222 This scheme has an advantage if you have to requery your record set
3223 frequently in that you only have to set your WHERE, ORDER BY, and FROM
3224 clauses once. Then to refresh the record set, simply call wxDbTable::Query()
3225 as frequently as needed.
3227 Note that repeated calls to wxDbTable::Query() may tax the database
3228 server and make your application sluggish if done too frequently or
3231 The base table name is automatically prepended to the base column names in
3232 the event that the FROM clause has been set (is non-null) using
3233 \helpref{wxDbTable::SetFromClause
}{wxdbtablesetfromclause
}.
3235 The cursor for the result set is positioned
{\it before
} the first record in
3236 the result set after the query. To retrieve the first record, call either
3237 \helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
} (only if backward scrolling
3238 cursors are available) or
3239 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}. Typically, no data from the
3240 result set is returned to the client driver until a request such as
3241 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
} is performed, so network
3242 traffic and database load are not overwhelmed transmitting data until the
3243 data is actually requested by the client. This behavior is solely dependent
3244 on the ODBC driver though, so refer to the ODBC driver's reference material
3245 for information on its behaviors.
3247 Values in the bound columns' memory variables are undefined after executing a
3248 call to this function and remain that way until a row in the result set is
3249 requested to be returned.
3251 The wxDbTable::Query() function is defined as "virtual" so that it may be
3252 overridden for application specific purposes.
3254 \normalbox{Be sure to set the wxDbTable's "where", "orderBy", and "from"
3255 member variables to "" if they are not to be used in the query. Otherwise,
3256 the results returned may have unexpected results (or no results) due to
3257 improper or incorrect query parameters constructed from the uninitialized
3263 // Incomplete code sample
3264 parts->SetWhereClause("DESCRIPTION = 'FOOD'");
3265 parts->SetOrderByClause("EXPIRATION_DATE");
3266 parts->SetFromClause("");
3267 // Query the records based on the where, orderBy and from clauses
3270 // Display all records queried
3271 while(parts->GetNext())
3272 dispPart(parts); // user defined function
3276 \membersection{wxDbTable::QueryBySqlStmt
}\label{wxdbtablequerybysqlstmt
}
3278 \func{bool
}{QueryBySqlStmt
}{\param{const wxString &
}{pSqlStmt
}}
3280 Performs a query against the datasource by accepting and passing verbatim the
3281 SQL SELECT statement passed to the function.
3283 \wxheading{Parameters
}
3285 \docparam{pSqlStmt
}{Pointer to the SQL SELECT statement to be executed.
}
3289 This is the most powerful form of the query functions available. This member
3290 function allows a programmer to write their own custom SQL SELECT statement
3291 for requesting data from the datasource. This gives the programmer access
3292 to the full power of SQL for performing operations such as scalar functions,
3293 aggregate functions, table joins, and sub-queries, as well as datasource
3294 specific function calls.
3296 The requirements of the SELECT statement are the following:
3299 1. Must return the correct number of columns. In the derived
3300 wxDbTable constructor, it is specified how many columns are in
3301 the wxDbTable object. The SELECT statement must return exactly
3304 2. The columns must be returned in the same sequence as specified
3305 when defining the bounds columns using wxDbTable::SetColDefs(),
3306 and the columns returned must be of the proper data type. For
3307 example, if column
3 is defined in the wxDbTable bound column
3308 definitions to be a float, the SELECT statement must return a
3309 float for column
3 (e.g. PRICE *
1.10 to increase the price by
3312 3. The ROWID can be included in your SELECT statement as the
{\bf last
}
3313 column selected, if the datasource supports it. Use
3314 wxDbTable::CanUpdByROWID() to determine if the ROWID can be
3315 selected from the datasource. If it can, much better
3316 performance can be achieved on updates and deletes by including
3317 the ROWID in the SELECT statement.
3320 Even though data can be selected from multiple tables (joins) in your select
3321 statement, only the base table associated with this wxDbTable object
3322 is automatically updated through the ODBC class library. Data from multiple
3323 tables can be selected for display purposes however. Include columns in
3324 the wxDbTable object and mark them as non-updateable (See
3325 \helpref{wxDbColDef
}{wxdbcoldef
} for details). This way columns can be
3326 selected and displayed from other tables, but only the base table will be
3327 updated automatically when performed through the
3328 \helpref{wxDbTable::Update
}{wxdbtableupdate
} function after using this type of
3329 query. To update tables other than the base table, use the
3330 \helpref{wxDbTable::Update
}{wxdbtableupdate
} function passing a SQL statement.
3332 After this function has been called, the cursor is positioned before the
3333 first record in the record set. To retrieve the first record, call
3334 either
\helpref{wxDbTable::GetFirst
}{wxdbtablegetfirst
} or
3335 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}.
3340 // Incomplete code samples
3342 sqlStmt = "SELECT * FROM PARTS WHERE STORAGE_DEVICE = 'SD98' \
3343 AND CONTAINER =
12";
3344 // Query the records using the SQL SELECT statement above
3345 parts->QueryBySqlStmt(sqlStmt);
3346 // Display all records queried
3347 while(parts->GetNext())
3350 Example SQL statements
3351 ----------------------
3353 // Table Join returning
3 columns
3354 SELECT part_no, part_desc, sd_name
3355 from parts, storage_devices
3356 where parts.storage_device_id =
3357 storage_devices.storage_device_id
3359 // Aggregate function returning total number of
3360 // parts in container
99
3361 SELECT count
(*) from PARTS where container = 99
3363 // Order by clause; ROWID, scalar function
3364 SELECT part_no, substring(part_desc, 1, 10), qty_on_hand + 1, ROWID
3366 where warehouse = 10
3367 order by part_no desc // descending order
3371 where container in (select container
3372 from storage_devices
3373 where device_id = 12)
3377 \membersection{wxDbTable::QueryMatching}\label{wxdbtablequerymatching}
3379 \func{virtual bool }{QueryMatching}{\param{bool }{forUpdate=FALSE},
3380 \param{bool }{distinct=FALSE}}
3382 QueryMatching allows querying of records from the table associated with
3383 the wxDbTable object by matching "columns" to values.
3385 For example: To query the datasource for the row with a PART_NUMBER column
3386 value of "32", clear all column variables of the wxDbTable object, set the
3387 PartNumber variable that is bound to the PART_NUMBER column in the wxDbTable
3388 object to "32", and then call wxDbTable::QueryMatching().
3390 \wxheading{Parameters}
3392 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
3393 as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
3394 the FOR UPDATE clause, this argument is ignored. See
3395 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
3396 additional information regarding this argument. Default is FALSE.}
3397 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
3398 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
3399 applies to all columns returned in the result set, not individual columns.
3404 The SQL WHERE clause is built by the ODBC class library based on all
3405 non-zero/non-NULL columns in your wxDbTable object. Matches can be on one,
3406 many or all of the wxDbTable's columns. The base table name is prepended
3407 to the column names in the event that the wxDbTable's FROM clause is non-null.
3409 This function cannot be used to perform queries which will check for
3410 columns that are 0 or NULL, as the automatically constructed WHERE clause
3411 only will contain comparisons on column member variables that are
3414 The primary difference between this function and \helpref{wxDbTable::QueryOnKeyFields}{wxdbtablequeryonkeyfields}
3415 is that this function can query on any column(s) in the wxDbTable object.
3416 Note however that this may not always be very efficient. Searching on
3417 non-indexed columns will always require a full table scan.
3419 The cursor is positioned before the first record in the record set after
3420 the query is performed. To retrieve the first record, the program must call
3421 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
3422 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
3424 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
3425 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
3431 // Incomplete code sample
3432 parts->ClearMemberVars(); // Set all columns to zero
3433 wxStrcpy(parts->PartNumber,"32"); // Set columns to query on
3434 parts->OnHold = TRUE;
3435 parts->QueryMatching(); // Query
3436 // Display all records queried
3437 while(parts->GetNext())
3438 dispPart(parts); // Some application defined function
3442 \membersection{wxDbTable::QueryOnKeyFields}\label{wxdbtablequeryonkeyfields}
3444 \func{bool }{QueryOnKeyFields}{\param{bool }{forUpdate=FALSE},
3445 \param{bool }{distinct=FALSE}}
3447 QueryOnKeyFields provides an easy mechanism to query records in the table
3448 associated with the wxDbTable object by the primary index column(s). Simply
3449 assign the primary index column(s) values and then call this member function
3450 to retrieve the record.
3452 Note that since primary indexes are always unique, this function implicitly
3453 always returns a single record from the database. The base table name is
3454 prepended to the column names in the event that the wxDbTable's FROM clause
3457 \wxheading{Parameters}
3459 \docparam{forUpdate}{{\it OPTIONAL}. Gives you the option of locking records
3460 as they are queried (SELECT ... FOR UPDATE). If the RDBMS is not capable of
3461 the FOR UPDATE clause, this argument is ignored. See
3462 \helpref{wxDbTable::CanSelectForUpdate}{wxdbtablecanselectforupdate} for
3463 additional information regarding this argument. Default is FALSE.}
3464 \docparam{distinct}{{\it OPTIONAL}. Allows selection of only distinct values
3465 from the query (SELECT DISTINCT ... FROM ...). The notion of DISTINCT
3466 applies to all columns returned in the result set, not individual columns.
3471 The cursor is positioned before the first record in the record set after
3472 the query is performed. To retrieve the first record, the program must call
3473 either \helpref{wxDbTable::GetFirst}{wxdbtablegetfirst} or
3474 \helpref{wxDbTable::GetNext}{wxdbtablegetnext}.
3476 WHERE and FROM clauses specified using \helpref{wxDbTable::SetWhereClause}{wxdbtablesetwhereclause}
3477 and \helpref{wxDbTable::SetFromClause}{wxdbtablesetfromclause} are ignored by
3483 // Incomplete code sample
3484 wxStrcpy(parts->PartNumber, "32");
3485 parts->QueryOnKeyFields();
3486 // Display all records queried
3487 while(parts->GetNext())
3488 dispPart(parts); // Some application defined function
3492 \membersection{wxDbTable::Refresh}\label{wxdbtablerefresh}
3494 \func{bool}{Refresh}{\void}
3496 This function re-reads the bound columns into the memory variables, setting
3497 them to the current values stored on the disk.
3499 The cursor position and result set are unaffected by calls to this function.
3500 (The one exception is in the case where the record to be refreshed has been
3501 deleted by some other user or transaction since it was originally retrieved
3502 as part of the result set. For most datasources, the default behavior in
3503 this situation is to return the value that was originally queried for the
3504 result set, even though it has been deleted from the database. But this is
3505 datasource dependent, and should be tested before relying on this behavior.)
3509 This routine is only guaranteed to work if the table has a unique primary
3510 index defined for it. Otherwise, more than one record may be fetched and
3511 there is no guarantee that the correct record will be refreshed. The
3512 table's columns are refreshed to reflect the current data in the database.
3515 \membersection{wxDbTable::SetColDefs}\label{wxdbtablesetcoldefs}
3517 \func{void}{SetColDefs}{\param{UWORD }{index}, \param{const wxString &}{fieldName},
3518 \param{int }{dataType}, \param{void *}{pData}, \param{SWORD }{cType},
3519 \param{int }{size}, \param{bool }{keyField = FALSE}, \param{bool }{upd = TRUE},
3520 \param{bool }{insAllow = TRUE}, \param{bool }{derivedCol = FALSE}}
3522 \func{wxDbColDataPtr *}{SetColDefs}{\param{wxDbColInf *}{colInfs}, \param{UWORD }{numCols}}
3524 \wxheading{Parameters}
3526 \docparam{index}{Column number (0 to n-1, where n is the number of columns
3527 specified as being defined for this wxDbTable instance when the
3528 wxDbTable constructor was called.}
3529 \docparam{fieldName}{Column name from the associated data table.}
3530 \docparam{dataType}{Logical data type. Valid logical types include:}
3533 DB_DATA_TYPE_VARCHAR : strings
3534 DB_DATA_TYPE_INTEGER : non-floating point numbers
3535 DB_DATA_TYPE_FLOAT : floating point numbers
3536 DB_DATA_TYPE_DATE : dates
3539 \docparam{pData}{Pointer to the data object that will hold the column's
3540 value when a row of data is returned from the datasource.}
3541 \docparam{cType}{SQL C Type. This defines the data type that the SQL
3542 representation of the data is converted to to be stored in {\it pData}.
3543 Other valid types are available also, but these are the most common ones:}
3546 SQL_C_CHAR // strings
3556 SQL_C_BOOLEAN // defined in db.h
3557 SQL_C_ENUM // defined in db.h
3560 \docparam{size}{Maximum size in bytes of the {\it pData} object.}
3561 \docparam{keyField}{{\it OPTIONAL}. Indicates if this column is part of the
3562 primary index. Default is FALSE.}
3563 \docparam{upd}{{\it OPTIONAL}. Are updates allowed on this column?
3565 \docparam{insAllow}{{\it OPTIONAL}. Inserts allowed on this column?
3567 \docparam{derivedCol}{{\it OPTIONAL}. Is this a derived column (non-base
3568 table column for query only)? Default is FALSE.}
3570 \docparam{colInfs}{Pointer to an array of wxDbColInf instances which contains
3571 all the information necessary to create {\it numCols} column definitions.}
3572 \docparam{numCols}{Number of elements of wxDbColInf type that are pointed
3573 to by {\it colInfs}, which are to have column definitions created from them.}
3577 If {\it pData} is to hold a string of characters, be sure to include enough
3578 space for the NULL terminator in pData and in the byte count of {\it size}.
3580 Both forms of this function provide a shortcut for defining the columns in
3581 your wxDbTable object. Use this function in any derived wxDbTable
3582 constructor when describing the column/columns in the wxDbTable object.
3584 The second form of this function is primarily used when the
3585 \helpref{wxDb::GetColumns}{wxdbgetcolumns} function was used to query the
3586 datasource for the column definitions, so that the column definitions are
3587 already stored in wxDbColInf form. One example use of using
3588 \helpref{wxDb::GetColumns}{wxdbgetcolumns} then using this function is if
3589 a data table existed in one datasource, and the table's column definitions
3590 were to be copied over to another datasource or table.
3595 // Long way not using this function
3596 wxStrcpy(colDefs[0].ColName, "PART_NO");
3597 colDefs[0].DbDataType = DB_DATA_TYPE_VARCHAR;
3598 colDefs[0].PtrDataObj = PartNumber;
3599 colDefs[0].SqlCtype = SQL_C_CHAR;
3600 colDefs[0].SzDataObj = PART_NUMBER_LEN;
3601 colDefs[0].KeyField = TRUE;
3602 colDefs[0].Updateable = FALSE;
3603 colDefs[0].InsertAllowed= TRUE;
3604 colDefs[0].DerivedCol = FALSE;
3606 // Shortcut using this function
3607 SetColDefs(0, "PART_NUMBER", DB_DATA_TYPE_VARCHAR, PartNumber,
3608 SQL_C_CHAR, PART_NUMBER_LEN, TRUE, FALSE,TRUE,FALSE);
3612 \membersection{wxDbTable::SetCursor}\label{wxdbtablesetcursor}
3614 \func{bool}{SetCursor}{\param{HSTMT *}{hstmtActivate = (void **) wxDB_DEFAULT_CURSOR
}}
3616 \wxheading{Parameters
}
3618 \docparam{hstmtActivate
}{{\it OPTIONAL
}. Pointer to the cursor that is to
3619 become the current cursor. Passing no cursor handle will reset the cursor
3620 back to the wxDbTable's default (original) cursor that was created when the
3621 wxDbTable instance was first created. Default is wxDB_DEFAULT_CURSOR.
}
3625 When swapping between cursors, the member variables of the wxDbTable object
3626 are automatically refreshed with the column values of the row that the
3627 current cursor is positioned at (if any). If the cursor is not positioned,
3628 then the data in member variables is undefined.
3630 The only way to return back to the cursor that was in use before this
3631 function was called is to programmatically determine the current cursor's HSTMT
3632 {\bf BEFORE
} calling this function using
\helpref{wxDbTable::GetCursor
}{wxdbtablegetcursor
}
3633 and saving a pointer to that cursor.
3635 \wxheading{See also
}
3637 \helpref{wxDbTable::GetNewCursor
}{wxdbtablegetnewcursor
},
3638 \helpref{wxDbTable::GetCursor
}{wxdbtablegetcursor
},
3639 \helpref{wxDbTable::SetCursor
}{wxdbtablesetcursor
}
3642 \membersection{wxDbTable::SetFromClause
}\label{wxdbtablesetfromclause
}
3644 \func{void
}{SetFromClause
}{\param{const wxString &
}{From
}}
3646 Accessor function for setting the private class member wxDbTable::from
3647 that indicates what other tables should be outer joined with the wxDbTable's
3648 base table for access to the columns in those other tables.
3650 Synonym to this function is one form of
\helpref{wxDbTable::From
}{wxdbtablefrom
}
3652 \wxheading{Parameters
}
3654 \docparam{From
}{A comma separated list of table names that are to be outer
3655 joined with the base table's columns so that the joined table's columns
3656 may be returned in the result set or used as a portion of a comparison with
3657 the base table's columns. NOTE that the base tables name must NOT be included
3658 in the FROM clause, as it is automatically included by the wxDbTable class
3659 in constructing query statements.
}
3663 Used by the
\helpref{wxDbTable::Query
}{wxdbtablequery
} and
3664 \helpref{wxDbTable::Count
}{wxdbtablecount
} member functions to allow outer
3665 joining of records from multiple tables.
3667 Do
{\bf not
} include the keyword "FROM" when setting the FROM clause.
3669 If using the FROM clause when performing a query, be certain to include in
3670 the corresponding WHERE clause a comparison of a column from either the base
3671 table or one of the other joined tables to each other joined table to ensure
3672 the datasource knows on which column values the tables should be joined on.
3678 // Base table is the "LOCATION" table, and it is being
3679 // outer joined to the "PART" table via the the field "PART_NUMBER"
3680 // that can be related between the two tables.
3681 location->SetWhereClause("LOCATION.PART_NUMBER = PART.PART_NUMBER")
3682 location->SetFromClause("PART");
3686 \wxheading{See also
}
3688 \helpref{wxDbTable::From
}{wxdbtablefrom
},
3689 \helpref{wxDbTable::GetFromClause
}{wxdbtablegetfromclause
}
3692 \membersection{wxDbTable::SetColNull
}\label{wxdbtablesetcolnull
}
3694 \func{bool
}{SetColNull
}{\param{UWORD
}{colNo
},
\param{bool
}{set=TRUE
}}
3696 \func{bool
}{SetColNull
}{\param{const wxString &
}{colName
},
3697 \param{bool
}{set=TRUE
}}
3699 Both forms of this function allow a member variable representing a column
3700 in the table associated with this wxDbTable object to be set to NULL.
3702 The first form allows the column to be set by the index into the column
3703 definitions used to create the wxDbTable instance, while the second allows
3704 the actual column name to be specified.
3706 \wxheading{Parameters
}
3708 \docparam{colNo
}{Index into the column definitions used when first defining
3709 this wxDbTable object.
}
3710 \docparam{colName
}{Actual data table column name that is to be set to NULL.
}
3711 \docparam{set
}{Whether the column is set to NULL or not. Passing TRUE sets
3712 the column to NULL, passing FALSE sets the column to be non-NULL. Default is
3718 No database updates are done by this function. It only operates on the
3719 member variables in memory. Use and insert or update function to store this
3723 \membersection{wxDbTable::SetOrderByClause
}\label{wxdbtablesetorderbyclause
}
3725 \func{void
}{SetOrderByClause
}{\param{const wxString &
}{OrderBy
}}
3727 Accessor function for setting the private class member wxDbTable::orderBy
3728 which determines sequence/ordering of the rows returned in the result set
3731 A synonym to this function is one form of the function
\helpref{wxDbTable::OrderBy
}{wxdbtableorderby
}
3733 \wxheading{Parameters
}
3735 \docparam{OrderBy
}{A comma separated list of column names that indicate the
3736 alphabetized sorting sequence that the result set is to be returned in. If
3737 a FROM clause has also been specified, each column name specified in the
3738 ORDER BY clause should be prefaced with the table name to which the column
3739 belongs using DOT notation (TABLE_NAME.COLUMN_NAME).
}
3743 Do
{\bf not
} include the keywords "ORDER BY" when setting the ORDER BY clause.
3749 parts->SetOrderByClause("PART_DESCRIP, QUANTITY");
3753 location->SetOrderByClause("LOCATION.POSITION, PART.PART_NUMBER);
3757 \wxheading{See also
}
3759 \helpref{wxDbTable::OrderBy
}{wxdbtableorderby
},
3760 \helpref{wxDbTable::GetOrderByClause
}{wxdbtablegetorderbyclause
}
3763 \membersection{wxDbTable::SetQueryTimeout
}\label{wxdbtablesetquerytimeout
}
3765 \func{bool
}{SetQueryTimeout
}{\param{UDWORD
}{nSeconds
}}
3767 Allows a time period to be set as the timeout period for queries.
3769 \wxheading{Parameters
}
3771 \docparam{nSeconds
}{The number of seconds to wait for the query to complete
3776 Neither Oracle or Access support this function as of yet. Other databases
3777 should be evaluated for support before depending on this function working
3781 \membersection{wxDbTable::SetWhereClause
}\label{wxdbtablesetwhereclause
}
3783 \func{void
}{SetWhereClause
}{\param{const wxString &
}{Where
}}
3785 Accessor function for setting the private class member wxDbTable::where
3786 that determines which rows are returned in the result set by the datasource.
3788 A synonym to this function is one form of the function
\helpref{wxDbTable::Where
}{wxdbtablewhere
}
3790 \wxheading{Parameters
}
3792 \docparam{Where
}{SQL "where" clause. This clause can contain any SQL language
3793 that is legal in standard where clauses. If a FROM clause has also been
3794 specified, each column name specified in the ORDER BY clause should be
3795 prefaced with the table name to which the column belongs using DOT notation
3796 (TABLE_NAME.COLUMN_NAME).
}
3800 Do
{\bf not
} include the keywords "WHERE" when setting the WHERE clause.
3806 // Simple where clause
3807 parts->SetWhereClause("PART_NUMBER = '
32'");
3809 // Any comparison operators
3810 parts->SetWhereClause("PART_DESCRIP LIKE 'HAMMER
%'");
3812 // Multiple comparisons, including a function call
3813 parts->Where("QTY >
0 AND
{fn UCASE(PART_DESCRIP)
} LIKE '
%DRILL%'");
3815 // Using parameters and multiple logical combinations
3816 parts->Where("((QTY >
10) OR (ON_ORDER >
0)) AND ON_HOLD =
0");
3818 // This query uses an outer join (requiring a FROM clause also)
3819 // that joins the PART and LOCATION table on he common field
3821 parts->Where("PART.ON_HOLD =
0 AND \
3822 PART.PART_NUMBER = LOCATION.PART_NUMBER AND \
3823 LOCATION.PART_NUMBER >
0");
3826 \wxheading{See also
}
3828 \helpref{wxDbTable::Where
}{wxdbtablewhere
},
3829 \helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
}
3832 \membersection{wxDbTable::Update
}\label{wxdbtableupdate
}
3834 \func{bool
}{Update
}{\void}
3836 \func{bool
}{Update
}{\param{const wxString &
}{pSqlStmt
}}
3838 The first form of this function will update the row that the current cursor
3839 is currently positioned at with the values in the memory variables that
3840 are bound to the columns. The actual SQL statement to perform the update
3841 is automatically created by the ODBC class, and then executed.
3843 The second form of the function allows full access through SQL statements for
3844 updating records in the database. Write any valid SQL UPDATE statement and
3845 submit it to this function for execution. Sophisticated updates can be
3846 performed using the full power of the SQL dialect. The full SQL statement
3847 must have the exact syntax required by the driver/datasource for performing
3848 the update. This usually is in the form of:
3851 UPDATE tablename SET col1=X, col2=Y, ... where ...
3854 \wxheading{Parameters
}
3856 \docparam{pSqlStmt
}{Pointer to SQL UPDATE statement to be executed.
}
3860 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
3861 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
3862 this function to commit or rollback the update.
3868 sqlStmt = "update PART set QTY =
0 where PART_NUMBER = '
32'";
3872 \membersection{wxDbTable::UpdateWhere
}\label{wxdbtableupdatewhere
}
3874 \func{bool
}{UpdateWhere
}{\param{const wxString &
}{pWhereClause
}}
3876 Performs updates to the base table of the wxDbTable object, updating only the
3877 rows which match the criteria specified in the
{\it pWhereClause
}.
3879 All columns that are bound to member variables for this wxDbTable instance
3880 that were defined with the "updateable" parameter set to TRUE will be updated
3881 with the information currently held in the memory variable.
3883 \wxheading{Parameters
}
3885 \docparam{pWhereClause
}{Pointer to a valid SQL WHERE clause. Do not
3886 include the keyword 'WHERE'.
}
3890 Care should be used when updating columns that are part of indexes with
3891 this function so as not to violate an unique key constraints.
3893 A
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
} or
3894 \helpref{wxDb::RollbackTrans
}{wxdbrollbacktrans
} must be called after use of
3895 this function to commit or rollback the update(s).
3898 \membersection{wxDbTable::Where
}\label{wxdbtablewhere
}
3900 \func{const wxString &
}{Where
}{}
3902 \func{void
}{Where
}{\param{const wxString&
}{Where
}}
3904 Accessor function for the private class member wxDbTable::where. Can be used
3905 as a synonym for
\helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
}
3906 (the first form of this function) to return the current where clause or
3907 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
} (the second form
3908 of this function) to set the where clause for this table instance.
3910 \wxheading{Parameters
}
3912 \docparam{Where
}{A valid SQL WHERE clause. Do not include the keyword 'WHERE'.
}
3914 \wxheading{Return value
}
3916 The first form of this function returns the current value of the wxDbTable
3917 member variable ::where.
3919 The second form of the function has no return value, as it will always set
3920 the where clause successfully.
3922 \wxheading{See also
}
3924 \helpref{wxDbTable::GetWhereClause
}{wxdbtablegetwhereclause
},
3925 \helpref{wxDbTable::SetWhereClause
}{wxdbtablesetwhereclause
}
3929 \membersection{wxDbTable::operator $++$
}\label{wxdbtableplusplus
}
3931 \func{bool
}{operator $++$
}{\void}
3933 Synonym for
\helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}
3935 \wxheading{See also
}
3937 \helpref{wxDbTable::GetNext
}{wxdbtablegetnext
}
3940 \membersection{wxDbTable::operator $--$
}\label{wxdbtableminusminus
}
3942 \func{bool
}{operator $--$
}{\void}
3944 Synonym for
\helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
}
3946 \wxheading{See also
}
3948 \helpref{wxDbTable::GetPrev
}{wxdbtablegetprev
}
3951 \section{\class{wxDbTableInf
}}\label{wxdbtableinf
}
3956 tableRemarks
[0] =
0;
3962 Currently only used by
\helpref{wxDb::GetCatalog
}{wxdbgetcatalog
} internally
3963 and
\helpref{wxDbInf
}{wxdbinf
} class, but may be used in future releases for
3964 user functions. Contains information describing the table (Name, type, etc).
3965 A pointer to a wxDbColInf array instance is included so a program can create a
3966 \helpref{wxDbColInf
}{wxdbcolinf
} array instance (using
3967 \helpref{wxDb::GetColumns
}{wxdbgetcolumns
})
3968 to maintain all information about the columns of a table in one memory
3971 Eventually, accessor functions will be added for this class
3974 \membersection{wxDbTableInf::Initialize
}\label{wxdbtableinfinitialize
}
3976 Simply initializes all member variables to a cleared state. Called by
3977 the constructor automatically.