📄 db.tex
字号:
\wxheading{Parameters}\docparam{aHenv}{Handle to the ODBC environment.}\docparam{aHdbc}{Handle to the ODBC connection. Pass this in if the ODBCfunction call that erred required a hdbc or hstmt argument.}\docparam{aHstmt}{Handle to the ODBC statement being executed against. Passthis in if the ODBC function call that failed required a hstmt argument.}\wxheading{Remarks}This member function will log all of the ODBC error messages for the lastODBC function call that was made. This function is normally used internallywithin the ODBC class library, but can be used programmatically after callingODBC functions directly (i.e. SQLFreeEnv()).\wxheading{Return value}The function always returns false, so a call to this function can be madein the return statement of a code block in the event of a failure toperform an action (see the example below).\wxheading{See also}\helpref{wxDb::SetSqlLogging}{wxdbsetsqllogging}, wxDbSqlLog\wxheading{Example}\begin{verbatim} if (SQLExecDirect(hstmt, (UCHAR FAR *) pSqlStmt, SQL_NTS) != SQL_SUCCESS) // Display all ODBC errors for this stmt return(db.DispAllErrors(db.henv, db.hdbc, hstmt));\end{verbatim}\membersection{wxDb::DispNextError}\label{wxdbdispnexterror}\func{void}{DispNextError}{\void}\wxheading{Remarks}This function is normally used internally within the ODBC class library.It could be used programmatically after calling ODBC functions directly. Thisfunction works in conjunction with \helpref{wxDb::GetNextError}{wxdbgetnexterror} when errors (orsometimes informational messages) returned from ODBC need to be analyzedrather than simply displaying them as an error. GetNextError() retrievesthe next ODBC error from the ODBC error queue. The wxDb member variables"sqlState", "nativeError" and "errorMsg" could then be evaluated. Todisplay the error retrieved, DispNextError() could then be called.The combination of GetNextError() and DispNextError() can be used toiteratively step through the errors returned from ODBC evaluating eachone in context and displaying the ones you choose.\wxheading{Example}\begin{verbatim} // Drop the table before attempting to create it sprintf(sqlStmt, "DROP TABLE %s", tableName); // Execute the drop table statement if (SQLExecDirect(hstmt,(UCHAR FAR *)sqlStmt,SQL_NTS) != SQL_SUCCESS) { // Check for sqlState = S0002, "Table or view not found". // Ignore this error, bomb out on any other error. pDb->GetNextError(henv, hdbc, hstmt); if (wxStrcmp(pDb->sqlState, "S0002")) { pDb->DispNextError(); // Displayed error retrieved pDb->DispAllErrors(henv, hdbc, hstmt); // Display all other errors, if any pDb->RollbackTrans(); // Rollback the transaction CloseCursor(); // Close the cursor return(false); // Return Failure } }\end{verbatim}\membersection{wxDb::DropView}\label{wxdbdropview}\func{bool}{DropView}{\param{const wxString \&}{viewName}}Drops the data table view named in 'viewName'.\wxheading{Parameters}\docparam{viewName}{Name of the view to be dropped.}\wxheading{Remarks}If the view does not exist, this function will return true. Note that views are not supported with all datasources.\membersection{wxDb::EscapeSqlChars}\label{wxdbescapesqlchars}\func{wxString}{EscapeSqlChars}{\param{const wxString\& }{value}}This function is used internally by wxWidgets while building SQL statements.It has been provided to help users who wish to explicity construct SQLstatements to be sent to the server. The function takes the value passed andreturns it with any special characters escaped. Which characters areconsidered special depends on what type of datasource the object is connectedto. For example, most database servers use a backslash as the escapecharacter; if the value passed contains a backlash it will be replaced with adouble backslash before it is passed to the server. This function can be usedto avoid passing statements with syntax errors to the server as well as preventSQL injection attacks.\wxheading{Parameters}\docparam{value}{The value to be escaped.}\membersection{wxDb::ExecSql}\label{wxdbexecsql}\func{bool}{ExecSql}{\param{const wxString \&}{pSqlStmt}}\func{bool}{ExecSql}{\param{const wxString \&}{pSqlStmt}, \param{wxDbColInf **}{columns}, \param{short \&}{numcols}}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.To get column amount and column names or other information about returned columns, pass {\it 'columns'} and {\it 'numcols'} parameters to the function also.\wxheading{Parameters}\docparam{pSqlStmt}{Pointer to the SQL statement to be executed.}\docparam{columns}{On success, this function will set this pointer to point to array of \helpref{wxDbColInf}{wxdbcolinf} objects, holding information about columns returned by the query. You need to call delete[] for the pointer you pass here after you don't use it anymore to prevent memory leak.}\docparam{numcols}{Reference to variable where amount of objects in {\it 'columns'}-parameter will be set.}\wxheading{Remarks}This member extends the wxDb class and allows you to build and execute ANY VALIDSQL statement against the datasource. This allows you to extend the classlibrary by being able to issue any SQL statement that the datasource is capableof processing.\wxheading{See also}\helpref{wxDb::GetData}{wxdbgetdata}, \helpref{wxDb::GetNext}{wxdbgetnext}\membersection{wxDb::FwdOnlyCursors}\label{wxdbfwdonlycursors}\func{bool}{IsFwdOnlyCursors}{\void}Older form (pre-2.3/2.4 of wxWidgets) of the\helpref{wxDb::IsFwdOnlyCursors}{wxdbisfwdonlycursors}. This method isprovided for backward compatibility only. The method\helpref{wxDb::IsFwdOnlyCursors}{wxdbisfwdonlycursors} should beused in place of this method.\func{wxDbInf *}{GetCatalog}{\param{const wxChar *}{userID}}\membersection{wxDb::GetCatalog}\label{wxdbgetcatalog}\func{wxDbInf *}{GetCatalog}{\param{const wxChar *}{userID}}Returns a \helpref{wxDbInf}{wxdbinf} pointer that points to the catalog(datasource) name, schema, number of tables accessible to the current user,and a wxDbTableInf pointer to all data pertaining to all tables in the userscatalog.\wxheading{Parameters}\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:}\begin{verbatim} userID == NULL ... UserID is ignored (DEFAULT) userID == "" ... UserID set equal to 'this->uid' userID != "" ... UserID set equal to 'userID'\end{verbatim}\wxheading{Remarks}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.\membersection{wxDb::GetColumnCount}\label{wxdbgetcolumncount}\func{int }{GetColumnCount}{\param{const wxString \&}{tableName}, \param{const wxChar *}{userID}}\wxheading{Parameters}\docparam{tableName}{The table name you wish to obtain column information about.}\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 thesame name in the datasource, but owned by different users. {\it userID } isevaluated in the following manner:}\begin{verbatim} userID == NULL ... UserID is ignored (DEFAULT) userID == "" ... UserID set equal to 'this->uid' userID != "" ... UserID set equal to 'userID'\end{verbatim}\wxheading{Return value}Returns a count of how many columns are in the specified table. If an erroroccurs retrieving the number of columns, this function will return a -1.\membersection{wxDb::GetColumns}\label{wxdbgetcolumns}\func{wxDbColInf *}{GetColumns}{\param{const wxString \&}{tableName}, \param{UWORD *}{numCols}, \param{const wxChar *}{userID=NULL}}\func{wxDbColInf *}{GetColumns}{\param{wxChar *}{tableName[]}, \param{const wxChar *}{userID}}\wxheading{Parameters}\docparam{tableName}{The table name you wish to obtain column information about.}\docparam{numCols}{Pointer to a UWORD which will hold a count of the number of columns returned by this function}\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.}\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:}\begin{verbatim} userID == NULL ... UserID is ignored (DEFAULT) userID == "" ... UserID set equal to 'this->uid' userID != "" ... UserID set equal to 'userID'\end{verbatim}\wxheading{Return value}This function returns a pointer to an array of \helpref{wxDbColInf}{wxdbcolinf}structures, allowing you to obtain information regarding the columns of thenamed table(s). If no columns were found, or an error occurred, this pointerwill be NULL.THE CALLING FUNCTION IS RESPONSIBLE FOR DELETING THE {\it wxDbColInf} MEMORY WHEN IT ISFINISHED WITH IT.\normalbox{ALL column bindings associated with this wxDb instance are unboundby this function, including those used by any wxDbTable instances that usethis wxDb instance. This function should use its own wxDb instanceto avoid undesired unbinding of columns.}\wxheading{See also}\helpref{wxDbColInf}{wxdbcolinf}\wxheading{Example}\begin{verbatim} wxChar *tableList[] = {"PARTS", 0}; wxDbColInf *colInf = pDb->GetColumns(tableList); if (colInf) { // Use the column inf ....... // Destroy the memory delete [] colInf; }\end{verbatim}\membersection{wxDb::GetData}\label{wxdbgetdata}\func{bool}{GetData}{\param{UWORD}{ colNumber}, \param{SWORD}{ cType},\param{PTR}{ pData}, \param{SDWORD}{ maxLen}, \param{SDWORD FAR *}{ cbReturned} }Used to retrieve result set data without binding column values to memoryvariables (i.e. not using a wxDbTable instance to access table data).\wxheading{Parameters}\docparam{colNumber}{Ordinal number of the desired column in the result set to bereturned.}\docparam{cType}{The C data type that is to be returned. See a partial listin \helpref{wxDbTable::SetColDefs}{wxdbtablesetcoldefs}}\docparam{pData}{Memory buffer which will hold the data returned by the callto this function.}\docparam{maxLen}{Maximum size of the buffer {\it 'pData'} in characters.NOTE: Not UNICODE safe. If this is a numeric field, a value of 0 may bepassed for this parameter, as the API knows the size of the expected returnvalue.}\docparam{cbReturned}{Pointer to the buffer containing the length of theactual data returned. If this value comes back as SQL\_NULL\_DATA, then the\helpref{wxDb::GetData}{wxdbgetdata} call has failed.}\wxheading{See also}\helpref{wxDb::GetNext}{wxdbgetnext}, \helpref{wxDb::ExecSql}{wxdbexecsql}\wxheading{Example}\begin{verbatim} SDWORD cb; ULONG reqQty; wxString sqlStmt; sqlStmt = "SELECT SUM(REQUIRED_QTY - PICKED_QTY) FROM ORDER_TABLE WHERE \ PART_RECID = 1450 AND REQUIRED_QTY > PICKED_QTY"; // Perform the query if (!pDb->ExecSql(sqlStmt.c_str())) { // ERROR return(0); } // Request the first row of the result set if (!pDb->GetNext()) { // ERROR return(0); } // Read column #1 of the row returned by the call to ::GetNext() // and return the value in 'reqQty' if (!pDb->GetData(1, SQL_C_ULONG, &reqQty, 0, &cb)) { // ERROR return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -