SQLFreeEnv (ODBC 1.0, Core)
SQLFreeEnv frees the environment handle and releases all memory associated with the environment handle.
Syntax
RETCODE SQLFreeEnv(henv)
The SQLFreeEnv function accepts the following argument.
Type
|
Argument
|
Use
|
Description |
HENV
|
henv
|
Input
|
Environment handle. |
Returns
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.
Diagnostics
When SQLFreeEnv returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLFreeEnv and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
SQLSTATE
|
Error
|
Description |
01000
|
General warning
|
Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
S1000
|
General error
|
An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause. |
S1010
|
Function sequence error
|
(DM) There was at least one hdbc in an allocated or connected state. Call SQLDisconnect and SQLFreeConnect for each hdbc before calling SQLFreeEnv. |
Comments
Prior to calling SQLFreeEnv, an application must call SQLFreeConnect for any hdbc allocated under the henv. Otherwise, SQLFreeEnv returns SQL_ERROR and the henv and any active hdbc remains valid.
When the Driver Manager processes the SQLFreeEnv function, it checks the TraceAutoStop keyword in the [ODBC] section of the ODBC.INI file or the ODBC subkey of the registry. If it is set to 1, the Driver Manager disables tracing for all applications and sets the Trace keyword in the [ODBC] section of the ODBC.INI file or the ODBC subkey of the registry to 0.
Code Example
See SQLBrowseConnect and SQLConnect.
Related Functions
For information about
|
See |
Allocating an environment handle
|
SQLAllocEnv |
Freeing a connection handle
|
SQLFreeConnect |
SQLFreeStmt (ODBC 1.0, Core)
SQLFreeStmt stops processing associated with a specific hstmt, closes any open cursors associated with the hstmt, discards pending results, and, optionally, frees all resources associated with the statement handle.
Syntax
RETCODE SQLFreeStmt(hstmt, fOption)
The SQLFreeStmt function accepts the following arguments.
Type
|
Argument
|
Use
|
Description |
HSTMT
|
hstmt
|
Input
|
Statement handle |
UWORD
|
fOption
|
Input
|
One of the following options:
SQL_ CLOSE: Close the cursor associated with hstmt (if one was defined) and discard all pending results. The application can reopen this cursor later by executing a SELECT statement again with the same or different parameter values. If no cursor is open, this option has no effect for the application.
SQL_DROP: Release the hstmt, free all resources associated with it, close the cursor (if one is open), and discard all pending rows. This option terminates all access to the hstmt. The hstmt must be reallocated to be reused.
SQL_UNBIND: Release all column buffers bound by SQLBindCol for the given hstmt.
SQL_RESET_PARAMS: Release all parameter buffers set by SQLBindParameter for the given hstmt. |
Returns
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.
Diagnostics
When SQLFreeStmt returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLFreeStmt and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
SQLSTATE
|
Error
|
Description |
01000
|
General warning
|
Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
IM001
|
Driver does not support this function
|
(DM) The driver associated with the hstmt does not support the function. |
S1000
|
General error
|
An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause. |
S1001
|
Memory allocation failure
|
The driver was unable to allocate memory required to support execution or completion of the function. |
S1010
|
Function sequence error
|
(DM) An asynchronously executing function was called for the hstmt and was still executing when this function was called.
(DM) SQLExecute, SQLExecDirect, or SQLSetPos was called for the hstmt and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns. |
S1092
|
Option type out of range
|
(DM) The value specified for the argument fOption was not:
SQL_CLOSE
SQL_DROP
SQL_UNBIND
SQL_RESET_PARAMS |
Comments
An application can call SQLFreeStmt to terminate processing of a SELECT statement with or without canceling the statement handle.
The SQL_DROP option frees all resources that were allocated by the SQLAllocStmt function.
Code Example
See SQLBrowseConnect and SQLConnect.
Related Functions
For information about
|
See |
Allocating a statement handle
|
SQLAllocStmt |
Canceling statement processing
|
SQLCancel |
Setting a cursor name
|
SQLSetCursorName |
SQLGetConnectOption (ODBC 1.0, Level 1)
SQLGetConnectOption returns the current setting of a connection option.
Syntax
RETCODE SQLGetConnectOption(hdbc, fOption, pvParam)
The SQLGetConnectOption function accepts the following arguments:
Type
|
Argument
|
Use
|
Description |
HDBC
|
hdbc
|
Input
|
Connection handle. |
UWORD
|
fOption
|
Input
|
Option to retrieve. |
PTR
|
pvParam
|
Output
|
Value associated with fOption. Depending on the value of fOption, a 32-bit integer value or a pointer to a null-terminated character string will be returned in pvParam. |
Returns
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NO_DATA_FOUND, SQL_ERROR, or SQL_INVALID_HANDLE.
Diagnostics
When SQLGetConnectOption returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLGetConnectOption and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
SQLSTATE
|
Error
|
Description |
01000
|
General warning
|
Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
08003
|
Connection not open
|
(DM) An fOption value was specified that required an open connection. |
IM001
|
Driver does not support this function
|
(DM) The driver corresponding to the hdbc does not support the function. |
S1000
|
General error
|
An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause. |
S1001
|
Memory allocation failure
|
The driver was unable to allocate memory required to support execution or completion of the function. |
S1010
|
Function sequence error
|
(DM) SQLBrowseConnect was called for the hdbc and returned SQL_NEED_DATA. This function was called before SQLBrowseConnect returned SQL_SUCCESS_WITH_INFO or SQL_SUCCESS. |
S1092
|
Option type out of range
|
(DM) The value specified for the argument fOption was in the block of numbers reserved for ODBC connection and statement options, but was not valid for the version of ODBC supported by the driver. |
S1C00
|
Driver not capable
|
The value specified for the argument fOption was a valid ODBC connection option for the version of ODBC supported by the driver, but was not supported by the driver.
The value specified for the argument fOption was in the block of numbers reserved for driver-specific connection and statement options, but was not supported by the driver. |
Comments
For a list of options, see SQLSetConnectOption. Note that if fOption specifies an option that returns a string, pvParam must be a pointer to storage for the string. The maximum length of the string will be SQL_MAX_OPTION_STRING_LENGTH bytes (excluding the null termination byte).
Depending on the option, an application does not need to establish a connection prior to calling SQLGetConnectOption. However, if SQLGetConnectOption is called and the specified option does not have a default and has not been set by a prior call to SQLSetConnectOption, SQLGetConnnectOption will return SQL_NO_DATA_FOUND.
While an application can set statement options using SQLSetConnectOption, an application cannot use SQLGetConnectOption to retrieve statement option values; it must call SQLGetStmtOption to retrieve the setting of statement options.
Related Functions
For information about
|
See |
Returning the setting of a statement option
|
SQLGetStmtOption (extension) |
Setting a connection option
|
SQLSetConnectOption (extension) |
Setting a statement option
|
SQLSetStmtOption (extension) |
SQLGetCursorName (ODBC 1.0, Core)
SQLGetCursorName returns the cursor name associated with a specified hstmt.
Syntax
RETCODE SQLGetCursorName(hstmt, szCursor, cbCursorMax, pcbCursor)
The SQLGetCursorName function accepts the following arguments.
Type
|
Argument
|
Use
|
Description |
HSTMT
|
hstmt
|
Input
|
Statement handle. |
UCHAR FAR *
|
szCursor
|
Output
|
Pointer to storage for the cursor name. |
SWORD
|
cbCursorMax
|
Input
|
Length of szCursor. |
SWORD FAR *
|
pcbCursor
|
Output
|
Total number of bytes (excluding the null termination byte) available to return in szCursor. If the number of bytes available to return is greater than or equal to cbCursorMax, the cursor name in szCursor is truncated to cbCursorMax 1 bytes. |
Returns
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.
Diagnostics
When SQLGetCursorName returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLGetCursorName and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
SQLSTATE
|
Error
|
Description |
01000
|
General warning
|
Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
01004
|
Data truncated
|
The buffer szCursor was not large enough to return the entire cursor name, so the cursor name was truncated. The argument pcbCursor contains the length of the untruncated cursor name. (Function returns SQL_SUCCESS_WITH_INFO.) |
IM001
|
Driver does not support this function
|
(DM) The driver associated with the hstmt does not support the function. |
S1000
|
General error
|
An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause. |
S1001
|
Memory allocation failure
|
The driver was unable to allocate memory required to support execution or completion of the function. |
S1010
|
Function sequence error
|
(DM) An asynchronously executing function was called for the hstmt and was still executing when this function was called.
(DM) SQLExecute, SQLExecDirect, or SQLSetPos was called for the hstmt and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns. |
S1015
|
No cursor name available
|
(DM) There was no open cursor on the hstmt and no cursor name had been set with SQLSetCursorName. |
S1090
|
Invalid string or buffer length
|
(DM) The value specified in the argument cbCursorMax was less than 0. |
Comments
The only ODBC SQL statements that use a cursor name are positioned update and delete (for example, UPDATE table-name ...WHERE CURRENT OF cursor-name). If the application does not call SQLSetCursorName to define a cursor name, on execution of a SELECT statement the driver generates a name that begins with the letters SQL_CUR and does not exceed 18 characters in length.
SQLGetCursorName returns the name of a cursor regardless of whether the name was created explicitly or implicitly.
A cursor name that is set either explicitly or implicitly remains set until the hstmt with which it is associated is dropped, using SQLFreeStmt with the SQL_DROP option.
Related Functions
For information about
|
See |
Executing an SQL statement
|
SQLExecDirect |
Executing a prepared SQL statement
|
SQLExecute |
Preparing a statement for execution
|
SQLPrepare |
Setting a cursor name
|
SQLSetCursorName |
Setting cursor scrolling options
|
SQLSetScrollOptions (extension) |
SQLGetData (ODBC 1.0, Level 1)
SQLGetData returns result data for a single unbound column in the current row. The application must call SQLFetch, or SQLExtendedFetch and (optionally) SQLSetPos to position the cursor on a row of data before it calls SQLGetData. It is possible to use SQLBindCol for some columns and use SQLGetData for others within the same row. This function can be used to retrieve character or binary data values in parts from a column with a character, binary, or data sourcespecific data type (for example, data from SQL_LONGVARBINARY or SQL_LONGVARCHAR columns).
Syntax
RETCODE SQLGetData(hstmt, icol, fCType, rgbValue, cbValueMax, pcbValue)
The SQLGetData function accepts the following arguments:
Type
|
Argument
|
Use
|
Description |
HSTMT
|
hstmt
|
Input
|
Statement handle. |
UWORD
|
icol
|
Input
|
Column number of result data, ordered sequentially left to right, starting at 1. A column number of 0 is used to retrieve a bookmark for the row; bookmarks are not supported by ODBC 1.0 drivers or SQLFetch. |
SWORD
|
fCType
|
Input
|
The C data type of the result data. This must be one of the following values:
SQL_C_BINARY
SQL_C_BIT
SQL_C_BOOKMARK
SQL_C_CHAR
SQL_C_DATE
SQL_C_DEFAULT
SQL_C_DOUBLE
SQL_C_FLOAT
SQL_C_SLONG
SQL_C_SSHORT
SQL_C_STINYINT
SQL_C_TIME
SQL_C_TIMESTAMP
SQL_C_ULONG
SQL_C_USHORT
SQL_C_UTINYINT
SQL_C_DEFAULT specifies that data be converted to its default C data type.
Note Drivers must also support the following values of fCType from ODBC 1.0. Applications must use these values, rather than the ODBC 2.0 values, when calling an ODBC 1.0 driver:
SQL_C_LONG
SQL_C_SHORT
SQL_C_TINYINT
For information about how data is converted, see "Converting Data from SQL to C Data Types" in Appendix D, "Data Types." |
PTR
|
rgbValue
|
Output
|
Pointer to storage for the data. |
SDWORD
|
cbValueMax
|
Input
|
Maximum length of the rgbValue buffer. For character data, rgbValue must also include space for the null-termination byte.
For character and binary C data, cbValueMax determines the amount of data that can be received in a single call to SQLGetData. For all other types of C data, cbValueMax is ignored; the driver assumes that the size of rgbValue is the size of the C data type specified with fCType and returns the entire data value. For more information about length, see "Precision, Scale, Length, and Display Size" in Appendix D, "Data Types." |
SDWORD FAR *
|
pcbValue
|
Output
|
SQL_NULL_DATA, the total number of bytes (excluding the null termination byte for character data) available to return in rgbValue prior to the current call to SQLGetData, or SQL_NO_TOTAL if the number of available bytes cannot be determined.
For character data, if pcbValue is SQL_NO_TOTAL or is greater than or equal to cbValueMax, the data in rgbValue is truncated to cbValueMax 1 bytes and is null-terminated by the driver.
For binary data, if pcbValue is SQL_NO_TOTAL or is greater than cbValueMax, the data in rgbValue is truncated to cbValueMax bytes.
For all other data types, the value of cbValueMax is ignored and the driver assumes the size of rgbValue is the size of the C data type specified with fCType. |
Returns
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NO_DATA_FOUND, SQL_STILL_EXECUTING, SQL_ERROR, or SQL_INVALID_HANDLE.
Diagnostics
When SQLGetData returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLGetData and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
SQLSTATE
|
Error
|
Description |
01000
|
General warning
|
Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
01004
|
Data truncated
|
All of the data for the specified column, icol, could not be retrieved in a single call to the function. The argument pcbValue contains the length of the data remaining in the specified column prior to the current call to SQLGetData. (Function returns SQL_SUCCESS_WITH_INFO.) For more information on using multiple calls to SQLGetData for a single column, see "Comments." |
07006
|
Restricted data type attribute violation
|
The data value cannot be converted to the C data type specified by the argument fCType. |
08S01
|
Communication link failure
|
The communication link between the driver and the data source to which the driver was connected failed before the function completed processing. |
22002
|
Indicator variable required but not supplied
|
NULL data is retrieved and pcbValue is a null pointer. |
22003
|
Numeric value out of range
|
Returning the numeric value (as numeric or string) for the column would have caused the whole (as opposed to fractional) part of the number to be truncated.
Returning the binary value for the column would have caused a loss of binary significance.
For more information, see Appendix D, "Data Types." |
22005
|
Error in assignment
|
The data for the column was incompatible with the data type into which it was to be converted. For more information, see Appendix D, "Data Types." |
22008
|
Datetime field overflow
|
The data for the column was not a valid date, time, or timestamp value. For more information, see Appendix D, "Data Types." |
24000
|
Invalid cursor state
|
(DM) The hstmt was in an executed state but no result set was associated with the hstmt.
(DM) A cursor was open on the hstmt but SQLFetch or SQLExtendedFetch had not been called.
A cursor was open on the hstmt and SQLFetch or SQLExtendedFetch had been called, but the cursor was positioned before the start of the result set or after the end of the result set. |
IM001
|
Driver does not support this function
|
(DM) The driver corresponding to the hstmt does not support the function. |
S1000
|
General error
|
An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause. |
S1001
|
Memory allocation failure
|
The driver was unable to allocate memory required to support execution or completion of the function. |
S1002
|
Invalid column number
|
The value specified for the argument icol was 0 and the driver was an ODBC 1.0 driver.
The value specified for the argument icol was 0 and SQLFetch was used to fetch the data.
The value specified for the argument icol was 0 and the SQL_USE_BOOKMARKS statement option was set to SQL_UB_OFF.
The specified column was greater than the number of result columns.
The specified column was bound through a call to SQLBindCol. This description does not apply to drivers that return the SQL_GD_BOUND bitmask for the SQL_GETDATA_EXTENSIONS option in SQLGetInfo. |
|
|
The specified column was at or before the last bound column specified through SQLBindCol. This description does not apply to drivers that return the SQL_GD_ANY_COLUMN bitmask for the SQL_GETDATA_EXTENSIONS option in SQLGetInfo. |
|
|
The application has already called SQLGetData for the current row. The column specified in the current call was before the column specified in the preceding call. This description does not apply to drivers that return the SQL_GD_ANY_ORDER bitmask for the SQL_GETDATA_EXTENSIONS option in SQLGetInfo. |
S1003
|
Program type out of range
|
(DM) The argument fCType was not a valid data type or SQL_C_DEFAULT.
The argument icol was 0 and the argument fCType was not SQL_C_BOOKMARK. |
S1008
|
Operation canceled
|
Asynchronous processing was enabled for the hstmt. The function was called and before it completed execution, SQLCancel was called on the hstmt. Then the function was called again on the hstmt.
The function was called and, before it completed execution, SQLCancel was called on the hstmt from a different thread in a multithreaded application. |
S1009
|
Invalid argument value
|
(DM) The argument rgbValue was a null pointer. |
S1010
|
Function sequence error
|
(DM) The specified hstmt was not in an executed state. The function was called without first calling SQLExecDirect, SQLExecute, or a catalog function.
(DM) An asynchronously executing function (not this one) was called for the hstmt and was still executing when this function was called.
(DM) SQLExecute, SQLExecDirect, or SQLSetPos was called for the hstmt and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns. |
S1090
|
Invalid string or buffer length
|
(DM) The value specified for argument cbValueMax was less than 0. |
S1109
|
Invalid cursor position
|
The cursor was positioned (by SQLSetPos or SQLExtendedFetch) on a row for which the value in the rgfRowStatus array in SQLExtendedFetch was SQL_ROW_DELETED or SQL_ROW_ERROR. |
S1C00
|
Driver not capable
|
The driver or data source does not support use of SQLGetData with multiple rows in SQLExtendedFetch. This description does not apply to drivers that return the SQL_GD_BLOCK bitmask for the SQL_GETDATA_EXTENSIONS option in SQLGetInfo.
The driver or data source does not support the conversion specified by the combination of the fCType argument and the SQL data type of the corresponding column. This error only applies when the SQL data type of the column was mapped to a driver-specific SQL data type.
The argument icol was 0 and the driver does not support bookmarks.
The driver only supports ODBC 1.0 and the argument fCType was one of the following:
SQL_C_STINYINT
SQL_C_UTINYINT
SQL_C_SSHORT
SQL_C_USHORT
SQL_C_SLONG
SQL_C_ULONG |
S1T00
|
Timeout expired
|
The timeout period expired before the data source returned the result set. The timeout period is set through SQLSetStmtOption, SQL_QUERY_TIMEOUT. |
Comments
With each call, the driver sets pcbValue to the number of bytes that were available in the result column prior to the current call to SQLGetData. (If SQL_MAX_LENGTH has been set with SQLSetStmtOption, and the total number of bytes available on the first call is greater than SQL_MAX_LENGTH, the available number of bytes is set to SQL_MAX_LENGTH. Note that the SQL_MAX_LENGTH statement option is intended to reduce network traffic and may not be supported by all drivers. To guarantee that data is truncated, an application should allocate a buffer of the desired size and specify this size in the cbValueMax argument.) If the total number of bytes in the result column cannot be determined in advance, the driver sets pcbValue to SQL_NO_TOTAL. If the data value for the column is NULL, the driver stores SQL_NULL_DATA in pcbValue.
SQLGetData can convert data to a different data type. The result and success of the conversion is determined by the rules for assignment specified in "Converting Data from SQL to C Data Types" in Appendix D, "Data Types."
If more than one call to SQLGetData is required to retrieve data from a single column with a character, binary, or data sourcespecific data type, the driver returns SQL_SUCCESS_WITH_INFO. A subsequent call to SQLError returns SQLSTATE 01004 (Data truncated). The application can then use the same column number to retrieve subsequent parts of the data until SQLGetData returns SQL_SUCCESS, indicating that all data for the column has been retrieved. SQLGetData will return SQL_NO_DATA_FOUND when it is called for a column after all of the data has been retrieved and before data is retrieved for a subsequent column. The application can ignore excess data by proceeding to the next result column.
Note An application can use SQLGetData to retrieve data from a column in parts only when retrieving character C data from a column with a character,binary, or data sourcespecific data type or when retrieving binary C data from a column with a character, binary, or data sourcespecific data type. If SQLGetData is called more than one time in a row for a column under any other conditions, it returns SQL_NO_DATA_FOUND for all calls after the first.
For maximum interoperability, applications should call SQLGetData only for unbound columns with numbers greater than the number of the last bound column. Within a single row of data, the column number in each call to SQLGetData should be greater than or equal to the column number in the previous call (that is, data should be retrieved in increasing order of column number). As extended functionality, drivers can return data through SQLGetData from bound columns, from columns before the last bound column, or from columns in any order. To determine whether a driver supports these extensions, an application calls SQLGetInfo with the SQL_GETDATA_EXTENSIONS option.
Furthermore, applications that use SQLExtendedFetch to retrieve data should call SQLGetData only when the rowset size is 1. As extended functionality, drivers can return data through SQLGetData when the rowset size is greater than 1. The application calls SQLSetPos to position the cursor on a row and calls SQLGetData to retrieve data from an unbound column. To determine whether a driver supports this extension, an application calls SQLGetInfo with the SQL_GETDATA_EXTENSIONS option.
Code Example
In the following example, an application executes a SELECT statement to return a result set of the employee names, ages, and birthdays sorted by birthday, age, and name. For each row of data, it calls SQLFetch to position the cursor to the next row. It calls SQLGetData to retrieve the fetched data; the storage locations for the data and the returned number of bytes are specified in the call to SQLGetData. Finally, it prints each employees name, age, and birthday.
#define NAME_LEN 30
#define BDAY_LEN 11
UCHAR szName[NAME_LEN], szBirthday[BDAY_LEN];
SWORD sAge;
SDWORD cbName, cbAge, cbBirthday;
retcode = SQLExecDirect(hstmt,
"SELECT NAME, AGE, BIRTHDAY FROM EMPLOYEE ORDER BY 3, 2, 1",
SQL_NTS);
if (retcode == SQL_SUCCESS) {
while (TRUE) {
retcode = SQLFetch(hstmt);
if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
show_error();
}
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
/* Get data for columns 1, 2, and 3 */
/* Print the row of data */
SQLGetData(hstmt, 1, SQL_C_CHAR, szName, NAME_LEN, &cbName);
SQLGetData(hstmt, 2, SQL_C_SSHORT, &sAge, 0, &cbAge);
SQLGetData(hstmt, 3, SQL_C_CHAR, szBirthday, BDAY_LEN,
&cbBirthday);
fprintf(out, "%-*s %-2d %*s", NAME_LEN-1, szName, sAge,
BDAY_LEN-1, szBirthday);
} else {
break;
}
}
}
Related Functions
For information about
|
See |
Assigning storage for a column in a result set
|
SQLBindCol |
Canceling statement processing
|
SQLCancel |
Executing an SQL statement
|
SQLExecDirect |
Executing a prepared SQL statement
|
SQLExecute |
Fetching a block of data or scrolling through a result set
|
SQLExtendedFetch (extension) |
Fetching a row of data
|
SQLFetch |
Sending parameter data at execution time
|
SQLPutData (extension) |
Copyright © 1992-1997 Solid Information Technology Ltd All rights reserved.