1 \section{\class{wxDb
}}\label{wxdb
}
3 A wxDb instance is a connection to an ODBC data source 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 data source, as well as allowing access to any tables/views defined in
7 the data source to which the user has sufficient privileges.
9 \wxheading{Include files
}
16 \latexignore{\rtfignore{\wxheading{Members
}}}
17 \wxheading{Enumerated types
}
19 \label{wxdbenumsqllogstate
}\docparam{enum
{\bf wxDbSqlLogState
}}{sqlLogOFF, sqlLogON
}
21 {\it enum
{\bf wxDBMS
}}
23 These are the databases currently tested and working with these ODBC classes.
24 A call to
\helpref{wxDb::Dbms
}{wxdbdbms
} will return one of these enumerated values listed below.
29 dbmsSYBASE_ASA, // Adaptive Server Anywhere
30 dbmsSYBASE_ASE, // Adaptive Server Enterprise
39 See the remarks in
\helpref{wxDb::Dbms
}{wxdbdbms
} for exceptions/issues with
40 each of these database engines.
43 \wxheading{Public member variables
}
45 \docparam{SWORD
{\bf wxDb::cbErrorMsg
}}{This member variable is populated as a result of
46 calling
\helpref{wxDb::GetNextError
}{wxdbgetnexterror
}. Contains the count of bytes in the wxDb::errorMsg string.
}
48 \label{wxdbdbstatus
}\docparam{int
{\bf wxDb::DB_STATUS
}}{The last ODBC error that occured on this data connection. Possible codes are:
}
51 DB_ERR_GENERAL_WARNING // SqlState = '
01000'
52 DB_ERR_DISCONNECT_ERROR // SqlState = '
01002'
53 DB_ERR_DATA_TRUNCATED // SqlState = '
01004'
54 DB_ERR_PRIV_NOT_REVOKED // SqlState = '
01006'
55 DB_ERR_INVALID_CONN_STR_ATTR // SqlState = '
01S00'
56 DB_ERR_ERROR_IN_ROW // SqlState = '
01S01'
57 DB_ERR_OPTION_VALUE_CHANGED // SqlState = '
01S02'
58 DB_ERR_NO_ROWS_UPD_OR_DEL // SqlState = '
01S03'
59 DB_ERR_MULTI_ROWS_UPD_OR_DEL // SqlState = '
01S04'
60 DB_ERR_WRONG_NO_OF_PARAMS // SqlState = '
07001'
61 DB_ERR_DATA_TYPE_ATTR_VIOL // SqlState = '
07006'
62 DB_ERR_UNABLE_TO_CONNECT // SqlState = '
08001'
63 DB_ERR_CONNECTION_IN_USE // SqlState = '
08002'
64 DB_ERR_CONNECTION_NOT_OPEN // SqlState = '
08003'
65 DB_ERR_REJECTED_CONNECTION // SqlState = '
08004'
66 DB_ERR_CONN_FAIL_IN_TRANS // SqlState = '
08007'
67 DB_ERR_COMM_LINK_FAILURE // SqlState = '
08S01'
68 DB_ERR_INSERT_VALUE_LIST_MISMATCH // SqlState = '
21S01'
69 DB_ERR_DERIVED_TABLE_MISMATCH // SqlState = '
21S02'
70 DB_ERR_STRING_RIGHT_TRUNC // SqlState = '
22001'
71 DB_ERR_NUMERIC_VALUE_OUT_OF_RNG // SqlState = '
22003'
72 DB_ERR_ERROR_IN_ASSIGNMENT // SqlState = '
22005'
73 DB_ERR_DATETIME_FLD_OVERFLOW // SqlState = '
22008'
74 DB_ERR_DIVIDE_BY_ZERO // SqlState = '
22012'
75 DB_ERR_STR_DATA_LENGTH_MISMATCH // SqlState = '
22026'
76 DB_ERR_INTEGRITY_CONSTRAINT_VIOL // SqlState = '
23000'
77 DB_ERR_INVALID_CURSOR_STATE // SqlState = '
24000'
78 DB_ERR_INVALID_TRANS_STATE // SqlState = '
25000'
79 DB_ERR_INVALID_AUTH_SPEC // SqlState = '
28000'
80 DB_ERR_INVALID_CURSOR_NAME // SqlState = '
34000'
81 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL // SqlState = '
37000'
82 DB_ERR_DUPLICATE_CURSOR_NAME // SqlState = '
3C000'
83 DB_ERR_SERIALIZATION_FAILURE // SqlState = '
40001'
84 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2 // SqlState = '
42000'
85 DB_ERR_OPERATION_ABORTED // SqlState = '
70100'
86 DB_ERR_UNSUPPORTED_FUNCTION // SqlState = 'IM001'
87 DB_ERR_NO_DATA_SOURCE // SqlState = 'IM002'
88 DB_ERR_DRIVER_LOAD_ERROR // SqlState = 'IM003'
89 DB_ERR_SQLALLOCENV_FAILED // SqlState = 'IM004'
90 DB_ERR_SQLALLOCCONNECT_FAILED // SqlState = 'IM005'
91 DB_ERR_SQLSETCONNECTOPTION_FAILED // SqlState = 'IM006'
92 DB_ERR_NO_DATA_SOURCE_DLG_PROHIB // SqlState = 'IM007'
93 DB_ERR_DIALOG_FAILED // SqlState = 'IM008'
94 DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL // SqlState = 'IM009'
95 DB_ERR_DATA_SOURCE_NAME_TOO_LONG // SqlState = 'IM010'
96 DB_ERR_DRIVER_NAME_TOO_LONG // SqlState = 'IM011'
97 DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR // SqlState = 'IM012'
98 DB_ERR_TRACE_FILE_ERROR // SqlState = 'IM013'
99 DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS // SqlState = 'S0001'
100 DB_ERR_TABLE_NOT_FOUND // SqlState = 'S0002'
101 DB_ERR_INDEX_ALREADY_EXISTS // SqlState = 'S0011'
102 DB_ERR_INDEX_NOT_FOUND // SqlState = 'S0012'
103 DB_ERR_COLUMN_ALREADY_EXISTS // SqlState = 'S0021'
104 DB_ERR_COLUMN_NOT_FOUND // SqlState = 'S0022'
105 DB_ERR_NO_DEFAULT_FOR_COLUMN // SqlState = 'S0023'
106 DB_ERR_GENERAL_ERROR // SqlState = 'S1000'
107 DB_ERR_MEMORY_ALLOCATION_FAILURE // SqlState = 'S1001'
108 DB_ERR_INVALID_COLUMN_NUMBER // SqlState = 'S1002'
109 DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE // SqlState = 'S1003'
110 DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE // SqlState = 'S1004'
111 DB_ERR_OPERATION_CANCELLED // SqlState = 'S1008'
112 DB_ERR_INVALID_ARGUMENT_VALUE // SqlState = 'S1009'
113 DB_ERR_FUNCTION_SEQUENCE_ERROR // SqlState = 'S1010'
114 DB_ERR_OPERATION_INVALID_AT_THIS_TIME // SqlState = 'S1011'
115 DB_ERR_INVALID_TRANS_OPERATION_CODE // SqlState = 'S1012'
116 DB_ERR_NO_CURSOR_NAME_AVAIL // SqlState = 'S1015'
117 DB_ERR_INVALID_STR_OR_BUF_LEN // SqlState = 'S1090'
118 DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE // SqlState = 'S1091'
119 DB_ERR_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1092'
120 DB_ERR_INVALID_PARAM_NO // SqlState = 'S1093'
121 DB_ERR_INVALID_SCALE_VALUE // SqlState = 'S1094'
122 DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE // SqlState = 'S1095'
123 DB_ERR_INF_TYPE_OUT_OF_RANGE // SqlState = 'S1096'
124 DB_ERR_COLUMN_TYPE_OUT_OF_RANGE // SqlState = 'S1097'
125 DB_ERR_SCOPE_TYPE_OUT_OF_RANGE // SqlState = 'S1098'
126 DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE // SqlState = 'S1099'
127 DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1100'
128 DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE // SqlState = 'S1101'
129 DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE // SqlState = 'S1103'
130 DB_ERR_INVALID_PRECISION_VALUE // SqlState = 'S1104'
131 DB_ERR_INVALID_PARAM_TYPE // SqlState = 'S1105'
132 DB_ERR_FETCH_TYPE_OUT_OF_RANGE // SqlState = 'S1106'
133 DB_ERR_ROW_VALUE_OUT_OF_RANGE // SqlState = 'S1107'
134 DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE // SqlState = 'S1108'
135 DB_ERR_INVALID_CURSOR_POSITION // SqlState = 'S1109'
136 DB_ERR_INVALID_DRIVER_COMPLETION // SqlState = 'S1110'
137 DB_ERR_INVALID_BOOKMARK_VALUE // SqlState = 'S1111'
138 DB_ERR_DRIVER_NOT_CAPABLE // SqlState = 'S1C00'
139 DB_ERR_TIMEOUT_EXPIRED // SqlState = 'S1T00'
143 \docparam{struct
{\bf wxDb::dbInf
}}{This structure is internal to the wxDb class and contains
144 details of the ODBC datasource that the current instance of the wxDb is connected to
145 in its members. When the data source is opened, all of the information contained in
146 the dbInf structure is queried from the data source. This information is used almost
147 exclusively within the ODBC class library. Where there is a need for this information
148 outside of the class library a member function such as wxTable::IsCursorClosedOnCommit()
149 has been added for ease of use.
}
152 char dbmsName
[40] - Name of the dbms product
153 char dbmsVer
[64] - Version # of the dbms product
154 char driverName
[40] - Driver name
155 char odbcVer
[60] - ODBC version of the driver
156 char drvMgrOdbcVer
[60] - ODBC version of the driver manager
157 char driverVer
[60] - Driver version
158 char serverName
[80] - Server Name, typically a connect string
159 char databaseName
[128] - Database filename
160 char outerJoins
[2] - Does datasource support outer joins
161 char procedureSupport
[2] - Does datasource support stored procedures
162 UWORD maxConnections - Maximum # of connections datasource supports
163 UWORD maxStmts - Maximum # of HSTMTs per HDBC
164 UWORD apiConfLvl - ODBC API conformance level
165 UWORD cliConfLvl - Is datasource SAG compliant
166 UWORD sqlConfLvl - SQL conformance level
167 UWORD cursorCommitBehavior - How cursors are affected on db commit
168 UWORD cursorRollbackBehavior - How cursors are affected on db rollback
169 UWORD supportNotNullClause - Does datasource support NOT NULL clause
170 char supportIEF
[2] - Integrity Enhancement Facility (Ref. Integrity)
171 UDWORD txnIsolation - Transaction isolation level supported by driver
172 UDWORD txnIsolationOptions - Transaction isolation level options available
173 UDWORD fetchDirections - Fetch directions supported
174 UDWORD lockTypes - Lock types supported in SQLSetPos
175 UDWORD posOperations - Position operations supported in SQLSetPos
176 UDWORD posStmts - Position statements supported
177 UDWORD scrollConcurrency - Scrollable cursor concurrency options supported
178 UDWORD scrollOptions - Scrollable cursor options supported
179 UDWORD staticSensitivity - Can additions/deletions/updates be detected
180 UWORD txnCapable - Indicates if datasource supports transactions
181 UDWORD loginTimeout - Number seconds to wait for a login request
184 \docparam{char
{\bf wxDb::errorList
}[DB_MAX_ERROR_HISTORY
][DB_MAX_ERROR_MSG_LEN
]}{The last n ODBC errors that have occured on this database connection.
}
186 \docparam{char
{\bf wxDb::errorMsg
}[SQL_MAX_MESSAGE_LENGTH
]}{This member variable is populated as a result of calling
\helpref{wxDb::GetNextError
}{wxdbgetnexterror
}. It contains the ODBC error message text.
}
188 \docparam{SDWORD
{\bf wxDb::nativeError
}}{Set by wxDb::DispAllErrors, wxDb::GetNextError, and wxDb::DispNextError. It contains the datasource-specific error code returned by the datasource to the ODBC driver. Used for reporting ODBC errors.
}
190 \docparam{wxChar
{\bf wxDb::sqlState
}[20]}{Set by wxDb::TranslateSqlState(). Indicates the error state after a failed ODBC operation. Used for reporting ODBC errors.
}
192 \docparam{unsigned int
{\bf nTables
}}{Number of wxDbTable objects connected to this wxDb instance.
{\bf FOR INTERNAL USE ONLY
} by wxDbTable!!!
}
194 {\it wxDbSqlTypeInfo
{\bf typeInfVarchar
}}
196 {\it wxDbSqlTypeInfo
{\bf typeInfInteger
}}
198 {\it wxDbSqlTypeInfo
{\bf typeInfFloat
}}
200 {\it wxDbSqlTypeInfo
{\bf typeInfDate
}}
202 \begin{indented
}{1cm
}
203 The four wxDbSqlTypeInfo member variables listed above contain information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
205 This information is obtained from the ODBC driver by use of the ::SQLGetTypeInfo() function. The key piece of information is the type name the datasource uses for each logical data type. e.g. VARCHAR; Oracle calls it VARCHAR2.
210 Default cursor scrolling is defined by wxODBC_FWD_ONLY_CURSORS in setup.h
211 when the wxWindows library is built. This behavior can be overridden when
212 an instance of a wxDb is created (see
\helpref{wxDb constructor
}{wxdbconstr
}
216 \helpref{wxDbColFor
}{wxdbcolfor
},
\helpref{wxDbColInf
}{wxdbcolinf
},
\helpref{wxDbTable
}{wxdbtable
},
\helpref{wxDbTableInf
}{wxdbtableinf
},
\helpref{wxDbInf
}{wxdbinf
}
220 \membersection{wxDb::wxDb
}\label{wxdbconstr
}
226 \func{}{wxDb
}{\param{HENV\&
}{aHenv
}}
228 Constructor, used to create an ODBC connection to a data source.
230 \wxheading{Parameters
}
232 \docparam{aHenv
}{Environment handle defined in iODBC
}
236 This is the constructor for the wxDb class. The wxDb object must
237 be created and opened before any database activity can occur.
241 wxDbConnectInf ConnectInf;
242 ....Set values for member variables of ConnectInf here
244 wxDb sampleDB(ConnectInf.Henv);
245 if (!sampleDB.Open(ConnectInf.Dsn, ConnectInf.Uid, ConnectInf.AuthStr))
247 // Error opening data source
252 \membersection{wxDb::Catalog
}\label{wxdbcatalog
}
254 \func{bool
}{Catalog
}{\param{char *
}{ userID
},
\param{char *
}{fileName = SQL_CATALOG_FILENAME
}}
256 Allows a data "dictionary" of the data source to be created, dumping pertinent information about all data tables to which the user specified in userID has access.
258 \wxheading{Parameters
}
260 \docparam{userID
}{Database user name to use in accessing the database. All tables to which this user has rights will be evaluated in the catalog.
}
262 \docparam{fileName
}{OPTIONAL argument. Name of the text file to create and write the DB catalog to.
}
264 \wxheading{Return value
}
266 Returns TRUE if the catalog request was successful, of FALSE if there was some reason the catalog could not be generated
270 ============== ============== ================ ========= =======
271 TABLE NAME COLUMN NAME DATA TYPE PRECISION LENGTH
272 ============== ============== ================ ========= =======
273 EMPLOYEE RECID (
0008)NUMBER
15 8
274 EMPLOYEE USER_ID (
0012)VARCHAR2
13 13
275 EMPLOYEE FULL_NAME (
0012)VARCHAR2
26 26
276 EMPLOYEE PASSWORD (
0012)VARCHAR2
26 26
277 EMPLOYEE START_DATE (
0011)DATE
19 16
281 \membersection{wxDb::Close
}\label{wxdbclose
}
283 \func{void
}{Close
}{\void}
285 Closes the database connection.
289 At the end of your program, when you have finished all of your database work, you must close the ODBC connection to the data source. There are actually four steps involved in doing this as illustrated in the example.
291 Any wxTable instances which use this connection must be deleted before closing the database connection.
295 // Commit any open transactions on the data source
296 sampleDB.CommitTrans();
298 // Delete any remaining wxTable objects allocated with new
301 // Close the wxDb connection when finished with it
304 // Free Environment Handle that ODBC uses
305 if (SQLFreeEnv(Db.Henv) != SQL_SUCCESS)
307 // Error freeing environment handle
312 \membersection{wxDb::CommitTrans
}\label{wxdbcommittrans
}
314 \func{bool
}{CommitTrans
}{\void}
316 Permanently "commits" changes (insertions/deletions/updates) to the database.
318 \wxheading{Return value
}
320 Returns TRUE if the commit was successful, or FALSE if the commit failed.
324 Transactions begin implicitly as soon as you make a change to the database. At any time thereafter, you can save your work to the database ("Commit") or roll back all of your changes ("Rollback"). Calling this member function commits all open transactions on this ODBC connection.
326 \wxheading{Special Note :
{\it Cursors
} }
328 \normalbox{It is important to understand that different database/ODBC driver combinations handle
329 transactions differently. One thing in particular that you must pay attention to is
330 cursors, in regard to transactions. Cursors are what allow you to scroll through
331 records forward and backward and to manipulate records as you scroll through them.
332 When you issue a query, a cursor is created behind the scenes. The cursor keeps track
333 of the query and keeps track of the current record pointer. After you commit or
334 rollback a transaction, the cursor may be closed automatically. This means you must
335 requery the data source before you can perform any additional work against the wxTable
336 object. This is only necessary however if the data source closes the cursor after a
337 commit or rollback. Use the wxTable::IsCursorClosedOnCommit() member function to
338 determine the data source's transaction behavior. Note, it would be very inefficient
339 to just assume the data source closes the cursor and always requery. This could put
340 a significant, unnecessary load on data sources that leave the cursors open after a
344 \membersection{wxDb::CreateView
}\label{wxdbcreateviews
}
346 \func{bool
}{CreateView
}{\param{char *
}{ viewName
},
\param{char *
}{ colList
},
\param{char *
}{pSqlStmt
}}
350 \wxheading{Parameters
}
352 \docparam{viewName
}{The name of the view. e.g. PARTS_V
}
353 \docparam{colList
}{{\it OPTIONAL
} Pass in a comma delimited list of column names if you
354 wish to explicitly name each column in the result set. If not desired, pass in an
356 \docparam{pSqlStmt
}{Pointer to the select statement portion of the CREATE VIEW statement.
357 Must be a complete, valid SQL SELECT statement.
}
361 A 'view' is a logical table that derives columns from one or more other tables or views. Once the view is created, it can be queried exactly like any other table in the database.
363 NOTE: Views are not available with all datasources. Oracle is one example of a datasouce which does support views.
367 // Incomplete code sample
368 db.CreateView("PARTS_SD1", "PN, PD, QTY",
369 "SELECT PART_NO, PART_DESC, QTY_ON_HAND *
1.1 FROM PARTS WHERE STORAGE_DEVICE =
1");
371 // PARTS_SD1 can now be queried just as if it were a data table.
372 // e.g. SELECT PN, PD, QTY FROM PARTS_SD1
376 \membersection{wxDb::DispAllErrors
}\label{wxdbdispallerrors
}
378 \func{bool
}{DispAllErrors
}{\param{HENV
}{ aHenv
},
{\param}{HDBC
}{ aHdbc = SQL_NULL_HDBC
},
{\param}{HSTMT
}{ aHstmt = SQL_NULL_HSTMT
}}
380 Logs all database errors that occurred as a result of the last executed database command. This logging also includes debug logging when compiled in debug mode via
\helpref{wxLogDebug
}{wxlogdebug
}. If logging is turned on via
\helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}, then an entry is also logged to the defined log file.
382 \wxheading{Parameters
}
384 \docparam{aHenv
}{A handle to the ODBC environment.
}
385 \docparam{aHdbc
}{A handle to the ODBC connection. Pass this in if the ODBC function call that
386 erred out required a hdbc or hstmt argument.
}
387 \docparam{AHstmt
}{A handle to the ODBC statement being executed against. Pass this in if the
388 ODBC function call that erred out required a hstmt argument.
}
392 This member function will display all of the ODBC error messages for the last ODBC function call that was made. Normally used internally within the ODBC class library. Would be used externally if calling ODBC functions directly (i.e. SQLFreeEnv()).
396 \helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
},
\helpref{wxDbSqlLog
}{wxdbsqllog
}
400 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
401 // Display all ODBC errors for this stmt
402 return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
406 \membersection{wxDb::DispNextError
}\label{wxdbdispnexterror
}
408 \func{void
}{DispNextError
}{\void}
412 This function is normally used internally within the ODBC class library.
413 It could be used externally if calling ODBC functions directly. This
414 function works in conjunction with
\helpref{wxDb::GetNextError
}{wxdbgetnexterror
} when errors (or
415 sometimes informational messages) returned from ODBC need to be analyzed
416 rather than simply displaying them as an error. GetNextError() retrieves
417 the next ODBC error from the ODBC error queue. The wxDb member variables
418 "sqlState", "nativeError" and "errorMsg" could then be evaluated. To
419 display the error retrieved, DispNextError() could then be called.
420 The combination of GetNextError() and DispNextError() can be used to
421 iteratively step through the errors returned from ODBC evaluating each
422 one in context and displaying the ones you choose.
426 // Drop the table before attempting to create it
427 sprintf(sqlStmt, "DROP TABLE
%s", tableName);
428 // Execute the drop table statement
429 if (SQLExecDirect(hstmt,(UCHAR FAR *)sqlStmt,SQL_NTS) != SQL_SUCCESS)
431 // Check for sqlState = S0002, "Table or view not found".
432 // Ignore this error, bomb out on any other error.
433 pDb->GetNextError(henv, hdbc, hstmt);
434 if (strcmp(pDb->sqlState, "S0002"))
436 pDb->DispNextError(); // Displayed error retrieved
437 pDb->DispAllErrors(henv, hdbc, hstmt); // Display all other errors, if any
438 pDb->RollbackTrans(); // Rollback the transaction
439 CloseCursor(); // Close the cursor
440 return(FALSE); // Return Failure
446 \membersection{wxDb::DropView
}\label{wxdbdropview
}
448 \func{bool
}{DropView
}{\param{const char *
}{viewName
}}
450 Drops the data table view named in 'viewName'.
452 \wxheading{Parameters
}
454 \docparam{viewName
}{Name of the view to be dropped.
}
458 If the view does not exist, this function will return TRUE. Note that views are not supported with all data soruces.
461 \membersection{wxDb::ExecSql
}\label{wxdbexecsql
}
463 \func{bool
}{ExecSql
}{\param{char *
}{pSqlStmt
}}
465 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.
467 \wxheading{Parameters
}
469 \docparam{pSqlStmt
}{Pointer to the SQL statement to be executed.
}
473 This member extends the wxDb class and allows you to build and execute ANY VALID
474 SQL statement against the data source. This allows you to extend the class
475 library by being able to issue any SQL statement that the data source is capable
480 \helpref{wxDb::GetData
}{wxdbgetdata
},
\helpref{wxDb::GetNext
}{wxdbgetnext
}
483 \membersection{wxDb::FwdOnlyCursors
}\label{wxdbfwdonlycursors
}
485 \func{bool
}{FwdOnlyCursors
}{\void}
487 Indicates whether this connection to the datasource only allows forward scrolling cursors or not. This state is set at connection creation time.
491 \helpref{wxDb::wxDb
}{wxdbconstruct
},
\helpref{wxDbGetConnection
}{wxdbgetconnection
}
494 \membersection{wxDb::GetCatalog
}\label{wxdbgetcatalog
}
496 \func{wxDbInf *
}{GetCatalog
}{\param{char *
}{userID
}}
498 Returns a wxDbInf pointer that points to the catalog(data source) name, schema, number of tables accessible to the current user, and a wxDbTableInf pointer to all data pertaining to all tables in the users catalog.
500 \wxheading{Parameters
}
502 \docparam{userID
}{Owner of the table. Specify a userID when the datasource you are connected
503 to allows multiple unique tables with the same name to be owned by different users.
{\it userID
}
504 is evaluated as follows:
}
507 userID == NULL ... UserID is ignored (DEFAULT)
508 userID == "" ... UserID set equal to 'this->uid'
509 userID != "" ... UserID set equal to 'userID'
514 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 via this connection will be returned.
517 \membersection{wxDb::GetColumnCount
}\label{wxdbgetcolumncount
}
519 \func{int
}{GetColumnCount
}{\param{char *
}{tableName
},
\param{const char *
}{userID
}}
521 \wxheading{Parameters
}
523 \docparam{tableName
}{A table name you wish to obtain column information about.
}
524 \docparam{userID
}{Name of the user that owns the table(s). Required for some datasources for
525 situations where there may be multiple tables with the same name in the datasource, but owned
526 by different users.
{\it userID
} is evaluated in the following manner:
}
529 userID == NULL ... UserID is ignored (DEFAULT)
530 userID == "" ... UserID set equal to 'this->uid'
531 userID != "" ... UserID set equal to 'userID'
534 \wxheading{Return value
}
536 Returns a count of how many columns are in the specified table. If an error occurs retrieving the number of columns the function will return a -
1.
539 \membersection{wxDb::GetColumns
}\label{wxdbgetcolumns
}
541 \func{wxDbColInf *
}{GetColumns
}{\param{char *
}{tableName
},
\param{int *
}{numCols
},
\param{const char *
}{userID=NULL
}}
543 \func{wxDbColInf *
}{GetColumns
}{\param{char *
}{tableName
[]},
\param{const char *
}{userID
}}
545 \wxheading{Parameters
}
547 \docparam{tableName
}{A table name you wish to obtain column information about.
}
548 \docparam{tableName
[]}{An array of pointers to table names you wish to obtain column information about.
549 The last element of this array must be a NULL string.
}
550 \docparam{numCols
}{A pointer to a integer which will hold a count of the number
551 of columns returned by this function
}
552 \docparam{userID
}{Name of the user that owns the table(s). Required for some datasources for
553 situations where there may be multiple tables with the same name in the datasource, but owned
554 by different users.
{\it userID
} is evaluated in the following manner:
}
557 userID == NULL ... UserID is ignored (DEFAULT)
558 userID == "" ... UserID set equal to 'this->uid'
559 userID != "" ... UserID set equal to 'userID'
562 \wxheading{Return value
}
564 This function returns an array of wxDbColInf structures. This allows you to obtain
565 information regarding the columns of your table(s). If no columns were found, or
566 an error occured, this pointer will be zero (null).
568 THE CALLING FUNCTION IS RESPONSIBLE FOR DELETING THE
{\it wxDbColInf
} MEMORY WHEN IT IS
571 \normalbox{ALL column bindings associated with this wxDb instance are unbound
572 by this function. This function should use its own wxDb instance
573 to avoid undesired unbinding of columns.
}
577 \helpref{wxDbColInf
}{wxdbcolinf
}
581 char *tableList
[] =
{"PARTS",
0};
582 wxDbColInf *colInf = pDb->GetColumns(tableList);
585 // Use the column inf
587 // Destroy the memory
593 \membersection{wxDb::GetData
}\label{wxdbgetdata
}
595 \func{bool
}{GetData
}{\param{UWORD
}{ colNo
},
\param{SWORD
}{ cType
},
\param{PTR
}{ pData
},
\param{SDWORD
}{ maxLen
},
\param{SDWORD FAR *
}{ cbReturned
} }
597 Used to retrieve result set data without binding column values to memory variables (i.e. not using a wxDbTable instance to access table data).
599 \wxheading{Parameters
}
601 \docparam{colNo
}{Ordinal number of column in the result set to be returned.
}
602 \docparam{cType
}{The C data type that is to be returned.
}
603 \docparam{pData
}{Memory buffer which will hold the data returned by the call to this function.
}
604 \docparam{maxLen
}{Maximum size of the buffer that will hold the returned value.
}
605 \docparam{cbReturned
}{Pointer to the buffer containing the length of the actual data returned. If this value comes back as SQL_NULL_DATA, then the GetData() call has failed.
}
609 \helpref{wxDb::GetNext
}{wxdbgetnext
},
\helpref{wxDb::ExecSql
}{wxdbexecsql
}
616 sqlStmt = "SELECT SUM(REQUIRED_QTY - PICKED_QTY) FROM ORDER_TABLE WHERE PART_RECID =
1450 AND REQUIRED_QTY > PICKED_QTY";
619 if (!pDb->ExecSql(sqlStmt.c_str()))
625 // Request the first row of the result set
632 Read column
#1 of this row of the result set and store the value in 'reqQty'
633 if (!pDb->GetData(
1, SQL_C_ULONG, &reqQty,
0, &cb))
639 // Check for a NULL result
640 if (cb == SQL_NULL_DATA)
646 When requesting multiple columns to be returned from the result set (for example, the SQL query
647 requested
3 columns be returned), the calls to GetData must request the columns in ordinal
648 sequence (
1,
2,
3 or
1,
3 or
2,
3).
651 \membersection{wxDb::GetDatabaseName
}\label{wxdbgetdatabasename
}
653 \func{char *
}{GetDatabaseName
}{\void}
655 Returns the name of the database engine.
658 \membersection{wxDb::GetDataSource
}\label{wxdbgetdatasource
}
660 \func{char *
}{GetDataSource
}{\void}
662 Returns the ODBC datasource name.
665 \membersection{wxDb::GetHDBC
}\label{wxdbgethdbc
}
667 \func{HDBC
}{GetHDBC
}{\void}
669 Returns the ODBC handle to the database connection.
672 \membersection{wxDb::GetHENV
}\label{wxdbgethenv
}
674 \func{HENV
}{GetHENV
}{\void}
676 Returns the ODBC environment handle.
679 \membersection{wxDb::GetHSTMT
}\label{wxdbgethstmt
}
681 \func{HSTMT
}{GetHSTMT
}{\void}
683 Returns the ODBC statement handle associated with this database connection.
686 \membersection{wxDb::GetKeyFields
}\label{wxdbgetkeyfields
}
688 \func{int
}{GetKeyFields
}{\param{char *
}{tableName
},
\param{wxDbColInf *
}{colInf
},
\param{int
}{nocols
}}
690 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.
692 This function is primarily for use by the wxDb::GetColumns() function, but may be called if desired from the client application.
694 \wxheading{Parameters
}
696 \docparam{tableName
}{Name of the table for which the columns will be evaluated as to their inclusion in any indexes.
}
697 \docparam{colInf
}{Data structure containing the column definitions (obtained with wxDb::GetColumns()). This function populates the PkCol, PkTableName, and FkTableName members of the colInf structure.
}
698 \docparam{nocols
}{Number of columns defined in the instance of colInf.
}
700 \wxheading{Return value
}
702 Currently always returns TRUE.
706 \helpref{wxDbColInf
}{wxdbcolinf
},
\helpref{wxDb::GetColumns
}{wxdbgetcolumns
}
709 \membersection{wxDb::GetNext
}\label{wxdbgetnext
}
711 \func{HSTMT
}{GetNext
}{\void}
713 Requests the next row in the result set obtained by issueing a query through a direct request using wxDb::ExecSql().
717 \helpref{wxDb::ExecSql
}{wxdbexecsql
},
\helpref{wxDb::GetData
}{wxdbgetdata
}
720 \membersection{wxDb::GetNextError
}\label{wxdbgetnexterror
}
722 \func{bool
}{GetNextError
}{\param{HENV
}{ aHenv
},
\param{HDBC
}{ aHdbc = SQL_NULL_HDBC
},
\param{HSTMT
}{ aHstmt = SQL_NULL_HSTMT
}}
724 \wxheading{Parameters
}
726 \docparam{aHenv
}{A handle to the ODBC environment.
}
727 \docparam{aHdbc
}{A handle to the ODBC connection. Pass this in if the ODBC function call that
728 erred out required a hdbc or hstmt argument.
}
729 \docparam{AHstmt
}{A handle to the ODBC statement being executed against. Pass this in if the
730 ODBC function call that erred out requires a hstmt argument.
}
734 \helpref{wxDb::DispNextError
}{wxdbdispnexterror
},
\helpref{wxDb::DispAllErrors
}{wxdbdispallerrors
}
738 if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS)
740 // Display all ODBC errors for this stmt
741 return(db.DispAllErrors(db.henv, db.hdbc, hstmt));
746 \membersection{wxDb::GetPassword
}\label{wxdbgetpassword
}
748 \func{char *
}{GetPassword
}{\void}
750 Returns the password used to connect to the datasource.
753 \membersection{wxDb::GetTableCount
}\label{wxdbgettablecount
}
755 \func{int
}{GetTableCount
}{\void}
757 Returns the number of wxDbTable() instances currently using this data source connection.
760 \membersection{wxDb::GetUsername
}\label{wxdbgetusername
}
762 \func{char *
}{GetUsername
}{\void}
764 Returns the user name used to access the datasource.
767 \membersection{wxDb::Grant
}\label{wxdbgrant
}
769 \func{bool
}{Grant
}{\param{int
}{ privileges
},
\param{char *
}{tableName
},
\param{char *
}{userList = "PUBLIC"
}}
771 Use this member function to GRANT privileges to users for accessing tables in the datasource.
773 \wxheading{Parameters
}
775 \docparam{privileges
}{Use this argument to select which privileges you want to grant. Pass
776 DB_GRANT_ALL to grant all privileges. To grant individual privileges pass
777 one or more of the following OR'd together:
}
783 DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT |
784 DB_GRANT_UPDATE | DB_GRANT_DELETE
786 \docparam{tableName
}{The name of the table you wish to grant privileges on.
}
787 \docparam{userList
}{A comma delimited list of users to grant the privileges to. If this argument is not
788 passed in, the privileges will be given to the general PUBLIC.
}
792 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.
796 db.Grant(DB_GRANT_SELECT | DB_GRANT_INSERT, "PARTS", "mary, sue");
800 \membersection{wxDb::IsOpen
}\label{wxdbisopen
}
802 \func{bool
}{IsOpen
}{\void}
804 Indicates whether the database connection to the datasource is currently opened.
807 \membersection{wxDb::Open
}\label{wxdbopen
}
809 \func{bool
}{Open
}{\param{char *
}{Dsn
},
\param{char *
}{Uid
},
\param{char *
}{AuthStr
}}
811 \wxheading{Parameters
}
813 \docparam{Dsn
}{Data source name. The name of the ODBC data source as
814 assigned when the data source is initially set up through the ODBC data
816 \docparam{Uid
}{User ID. The name (ID) of the user you wish to connect as
817 to the data source. The user name (ID) determines what objects you
818 have access to in the datasource and what datasource privileges you have.
819 Privileges include being able to create new objects, update objects, delete
820 objects and so on. Users and privileges are normally administered by the
821 database administrator.
}
822 \docparam{AuthStr
}{The password associated witht the Uid.
}
826 After a wxDb instance is created, it must then be opened. When opening a data source, there must be hree pieces of information passed. The data source name, user name (ID) and the password for the user. No database activity on the data source can be performed until it is opened. This would normally be done at program startup and the data source would remain open for the duration of the program run. Note: It is possible to have multiple data sources open at the same time to support distributed database connections.
830 wxDb sampleDB(Db.Henv);
831 if (!sampleDB.Open("Oracle
7.1 HP/UX", "gtasker", "myPassword"))
833 // Error opening data source
838 \membersection{wxDb::RollbackTrans
}\label{wxdbrollbacktrans
}
840 \func{bool
}{RollbackTrans
}{\void}
842 Function to "rollback" 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.
846 Transactions begin implicitly as soon as you make a change to the database. At any time thereafter, you can save your work to the database (using
\helpref{wxDb::CommitTrans
}{wxdbcommittrans
}) or undo all of your changes using this function.
848 \normalbox{Calling this member function rolls back ALL open (uncommitted) transactions on this ODBC connection.
}
852 \helpref{wxDb::CommitTrans
}{wxdbcommittrans
} for a special note on cursors
855 \membersection{wxDb::SetSqlLogging
}\label{wxdbsetsqllogging
}
857 \func{bool
}{SetSqlLogging
}{\param{wxDbSqlLogState
}{ state
},
\param{const wxChar *
}{filename = SQL_LOG_FILENAME
},
\param{bool
}{ append = FALSE
}}
859 \wxheading{Parameters
}
861 \docparam{state
}{Either sqlLogOFF or sqlLogON (see
\helpref{enum wxDbSqlLogState
}{wxdbenumsqllogstate
}). Turns logging of SQL commands sent to the data
863 \docparam{filename
}{{\it OPTIONAL
}. Name of the file to which the log text is to be written.
}
864 \docparam{append
}{{\it OPTIONAL
}. Whether the file is appended to or overwritten.
}
868 When called with
{\it sqlLogON
}, all commands sent to the data source engine are logged to the file specified by
{\it filename
}. Logging is done by embedded WriteSqlLog() calls in the database member functions, or may be manually logged by adding calls to WriteSqlLog() in your own source code.
870 When called with
{\it sqlLogOFF
}, the logging file is closed, and any calls to WriteSqlLog() are ignored.
873 \membersection{wxDb::TableExists
}\label{wxdbtablexists
}
875 \func{bool
}{TableExists
}{\param{const char *
}{tableName
},
\param{const char *
}{userID=NULL
},
\param{const char *
}{path=NULL
}}
877 Checks the ODBC data source for the existence of a table. If a
{\it userID
} is specified, then the table must be accessible by that user (user must have at least minimal privileges to the table).
879 \wxheading{Parameters
}
881 \docparam{tableName
}{Name of the table to check for the existence of
}
882 \docparam{userID
}{Owner of the table. Specify a userID when the datasource you are connected
883 to allows multiple unique tables with the same name to be owned by different users.
{\it userID
}
884 is evaluated as follows:
}
887 userID == NULL ... UserID is ignored (DEFAULT)
888 userID == "" ... UserID set equal to 'this->uid'
889 userID != "" ... UserID set equal to 'userID'
894 {\it tableName
} may refer to a table, view, alias or synonym.
896 This function does not indicate whether or not the user has privleges to query or perform other functions on the table.
899 \membersection{wxDb::TranslateSqlState
}\label{wxdbtranslatesqlstate
}
901 \func{int
}{TranslateSqlState
}{\param{const wxChar *
}{SQLState
}}
903 \wxheading{Parameters
}
905 \docparam{SQLState
}{Converts an ODBC sqlstate to an internal error code.
}
907 \wxheading{Return value
}
909 Returns the internal class DB_ERR code. See
\helpref{wxDb::DB_STATUS
}{wxdbdbstatus
} definition.
912 \membersection{wxDb::WriteSqlLog
}\label{wxdbwritesqllog
}
914 \func{bool
}{WriteSqlLog
}{\param{const wxChar *
}{logMsg
}}
916 \wxheading{Parameters
}
918 \docparam{logMsg
}{Free form string to be written to the log file.
}
922 Very useful debugging tool that may be turned on/off during run time. The
923 passed in string
{\it logMsg
} will be written to a log file if SQL logging
924 is turned on (see
\helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
} for details on turning logging on/off).
926 \wxheading{Return value
}
928 If SQL logging is off when a call to WriteSqlLog() is made, or there is a
929 failure to write the log message to the log file, the function returns
930 FALSE without performing the requested log, otherwise TRUE is returned.
934 \helpref{wxDb::SetSqlLogging
}{wxdbsetsqllogging
}
937 \membersection{wxDb::IsFwdOnlyCursors
}\label{wxdbisfwdonlycursors
}
939 \func{bool
}{IsFwdOnlyCursors
}{\void}
943 This setting indicates whether this database connection was created
944 as being capable of using only forward scrolling cursors. This function
945 does NOT indicate if the ODBC driver or datasource supports backward
946 scrolling cursors. There is no standard way of detecting if the driver
947 or datasource can support backward scrolling cursors.
949 If a wxDb instance was created as being forward only cursors, then even if
950 the datasource and ODBC driver support backward scrolling cursors, then
951 tables using this database connection can only use forward scrolling
954 The default setting of whether a wxDb connection to a database allows
955 forward-only or also backward scrolling cursors is defined in setup.h by
956 the wxODBC_FWD_ONLY_CURSORS value. This default setting can be overridden
957 when the wxDb connection is initially created (see
\helpref{wxDb constructor
}{wxdbconstr
}).
959 \wxheading{Return value
}
961 Returns TRUE if this datasource connection is defined as using only forward
962 scrolling cursors, or FALSE if the connection is defined as being capable
963 of supporting backward scrolling cursors (see note above).
967 \helpref{wxDb constructor
}{wxdbconstr
}
970 \membersection{wxDb::Dbms
}\label{wxdbdbms
}
972 \func{wxDBMS
}{Dbms
}{\void}
976 The return value will be of the enumerated type wxDBMS. This enumerated
977 type contains a list of all the currently tested and supported databases.
979 Additional databases may be work with these classes, but these databases
980 returned by this function have been tested and confirmed to work with
983 enum wxDBMS includes:
997 There are known issues with conformance to the ODBC standards with several
998 datasources listed above. Please see the overview for specific details on
999 on which datasource have which issues.
1001 \wxheading{Return value
}
1003 The return value will indicate which of the supported datasources is
1004 currently connected to by this connection. In the event that the
1005 datasource is not recognized, a value of 'dbmsUNIDENTIFIED' is returned.
1008 \membersection{wxDb::SetDebugErrorMessages
}\label{wxdbsetdebugerrormessages
}
1010 \func{void
}{SetDebugErrorMessages
}{\param{bool
}{state
}}
1012 \docparam{state
}{Either TRUE (debug messages are displayed) or FALSE (debug
1013 messages are not displayed.
}
1017 Turns on/off debug error messages from the ODBC class library. When
1018 this function is passed TRUE, errors are reported to the user automatically
1019 in a text or pop-up dialog when an ODBC error occurs. When passed FALSE,
1020 errors are silently handled.
1022 When compiled in release mode (FINAL=
1), this setting has no affect.
1024 \wxheading{See also
}
1026 \helpref{wxDb constructor
}{wxdbconstr
}
1031 \membersection{wxDb::LogError
}\label{wxdblogerror
}
1033 \func{void
}{LogError
}{\param{const char *
}{errMsg
} \param{const char *
}{SQLState=
0}}
1035 \docparam{errMsg
}{Free-form text to display describing the error to be logged.
}
1036 \docparam{SQLState
}{Native SQL state error
}
1039 Calling this function will enter a log message in the error list maintained
1040 for the database connection. This log message is free form and can be
1041 anything the programmer wants to enter in the error list.
1043 If SQL logging is turned on, the call to this function will also log the
1044 text into the SQL log file.
1046 \wxheading{See also
}
1048 \helpref{wxDb::WriteSqlLog
}{wxdbwritesqllog
}
1053 \membersection{wxDb::GetTypeInfXxxxx
}\label{wxdbgettypeinf
}
1055 \func{wxDbSqlTypeInfo
}{GetTypeInfDate
}{\void}
1056 \func{wxDbSqlTypeInfo
}{GetTypeInfFloat
}{\void}
1057 \func{wxDbSqlTypeInfo
}{GetTypeInfInteger
}{\void}
1058 \func{wxDbSqlTypeInfo
}{GetTypeInfVarchar
}{\void}
1064 \wxheading{Return value
}