Rzadppdf
Rzadppdf
Version 7.2
Database
SQL call level interface
IBM
Note
Before using this information and the product it supports, read the information in “Notices” on page
297.
This document may contain references to Licensed Internal Code. Licensed Internal Code is Machine Code and is
licensed to you under the terms of the IBM License Agreement for Machine Code.
© Copyright International Business Machines Corporation 1999, 2013.
US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
Contents
iii
SQLConnect - Connect to a data source.............................................................................................. 73
SQLCopyDesc - Copy description statement.......................................................................................75
SQLDataSources - Get list of data sources..........................................................................................76
SQLDescribeCol - Describe column attributes.................................................................................... 79
SQLDescribeParam - Return description of a parameter marker....................................................... 83
SQLDisconnect - Disconnect from a data source................................................................................ 85
SQLDriverConnect - Connect to a data source.................................................................................... 86
SQLEndTran - Commit or roll back a transaction................................................................................ 90
SQLError - Retrieve error information..................................................................................................91
SQLExecDirect - Execute a statement directly....................................................................................94
SQLExecute - Execute a statement..................................................................................................... 96
SQLExtendedFetch - Fetch array of rows............................................................................................ 98
SQLFetch - Fetch next row.................................................................................................................100
SQLFetchScroll - Fetch from a scrollable cursor...............................................................................105
SQLForeignKeys - Get the list of foreign key columns......................................................................107
SQLFreeConnect - Free connection handle.......................................................................................112
SQLFreeEnv - Free environment handle............................................................................................113
SQLFreeHandle - Free a handle.........................................................................................................114
SQLFreeStmt - Free (or reset) a statement handle...........................................................................115
SQLGetCol - Retrieve one column of a row of the result set............................................................ 117
SQLGetConnectAttr - Get the value of a connection attribute......................................................... 122
SQLGetConnectOption - Return current setting of a connect option............................................... 123
SQLGetCursorName - Get cursor name............................................................................................ 125
SQLGetData - Get data from a column.............................................................................................. 128
SQLGetDescField - Get descriptor field............................................................................................ 129
SQLGetDescRec - Get descriptor record........................................................................................... 131
SQLGetDiagField - Return diagnostic information (extensible)........................................................133
SQLGetDiagRec - Return diagnostic information (concise).............................................................. 136
SQLGetEnvAttr - Return current setting of an environment attribute.............................................. 138
SQLGetFunctions - Get functions...................................................................................................... 139
SQLGetInfo - Get general information...............................................................................................142
SQLGetLength - Retrieve length of a string value............................................................................. 156
SQLGetPosition - Return starting position of string.......................................................................... 158
SQLGetStmtAttr - Get the value of a statement attribute................................................................ 161
SQLGetStmtOption - Return current setting of a statement option................................................. 163
SQLGetSubString - Retrieve portion of a string value....................................................................... 164
SQLGetTypeInfo - Get data type information................................................................................... 167
SQLLanguages - Get SQL dialect or conformance information........................................................ 173
SQLMoreResults - Determine whether there are more result sets.................................................. 174
SQLNativeSql - Get native SQL text................................................................................................... 175
SQLNextResult - Process the next result set.................................................................................... 178
SQLNumParams - Get number of parameters in an SQL statement................................................ 179
SQLNumResultCols - Get number of result columns........................................................................180
SQLParamData - Get next parameter for which a data value is needed.......................................... 181
SQLParamOptions - Specify an input array for a parameter.............................................................183
SQLPrepare - Prepare a statement....................................................................................................184
SQLPrimaryKeys - Get primary key columns of a table.................................................................... 188
SQLProcedureColumns - Get input/output parameter information for a procedure....................... 190
SQLProcedures - Get list of procedure names..................................................................................196
SQLPutData - Pass data value for a parameter................................................................................. 200
SQLReleaseEnv - Release all environment resources...................................................................... 201
SQLRowCount - Get row count.......................................................................................................... 202
SQLSetConnectAttr - Set a connection attribute.............................................................................. 204
SQLSetConnectOption - Set connection option................................................................................ 218
SQLSetCursorName - Set cursor name............................................................................................. 219
SQLSetDescField - Set a descriptor field...........................................................................................221
SQLSetDescRec - Set a descriptor record......................................................................................... 223
SQLSetEnvAttr - Set environment attribute...................................................................................... 224
iv
SQLSetParam - Set parameter...........................................................................................................230
SQLSetStmtAttr - Set a statement attribute..................................................................................... 230
SQLSetStmtOption - Set statement option....................................................................................... 237
SQLSpecialColumns - Get special (row identifier) columns............................................................. 239
SQLStatistics - Get index and statistics information for a base table.............................................. 242
SQLTablePrivileges - Get privileges associated with a table............................................................246
SQLTables - Get table information.................................................................................................... 249
SQLTransact - Commit or roll back a transaction............................................................................. 251
Db2 for i CLI include file.......................................................................................................................... 253
Running Db2 for i CLI in server mode..................................................................................................... 282
Starting Db2 for i CLI in SQL server mode......................................................................................... 282
Restrictions for running Db2 for i CLI in server mode.......................................................................282
Unicode in Db2 for i CLI...........................................................................................................................283
Examples: Db2 for i CLI applications...................................................................................................... 285
Example: Embedded SQL and the equivalent Db2 for i CLI function calls.......................................285
Example: Using the CLI XA transaction connection attributes.........................................................288
Example: Interactive SQL and the equivalent Db2 for i CLI function calls.......................................290
Notices..............................................................................................................297
Programming interface information........................................................................................................298
Trademarks..............................................................................................................................................298
Terms and conditions.............................................................................................................................. 299
Index................................................................................................................ 301
v
vi
SQL call level interface
Db2® for i call level interface (CLI) is a callable Structured Query Language (SQL) programming interface
that is supported in all DB2® environments.
A callable SQL interface is a programming interface (API) for database access that uses function calls to
run dynamic SQL statements.
Db2 for i CLI is an alternative to embedded dynamic SQL. The important difference between embedded
dynamic SQL and Db2 for i CLI is how the SQL statements are run. On the IBM® i operating system, this
interface is available to any of the Integrated Language Environment® (ILE) languages.
Db2 for i CLI also provides full Level 1 Microsoft Open Database Connectivity (ODBC) support, plus many
Level 2 functions. For the most part, ODBC is a superset of the American National Standards Institute
(ANSI) and ISO SQL CLI standard.
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
ISO standard 9075:1999 – Database Language SQL Part 3: Call-Level Interface provides the standard
definition of CLI. The goal of this interface is to increase the portability of applications by enabling them to
become independent of any one database server.
ODBC provides a Driver Manager for Windows, which offers a central point of control for each ODBC driver
(a dynamic link library (DLL) that implements ODBC function calls and interacts with a specific Database
Management System (DBMS)).
EXECUTE SQLExecute()
EXECUTE IMMEDIATE SQLExecDirect()
FETCH SQLFetch()
FREE LOCATOR X SQLSetConnectAttr()
GET DESCRIPTOR
GET DIAGNOSTICS
GRANT X X
HOLD LOCATOR X
INCLUDE b
INSERT X X
LABEL X
LOCK TABLE X X
MERGE X X
OPEN SQLExecute(), SQLExecDirect()
Notes:
1
Dyn stands for dynamic. All statements in this list can be coded as static SQL, but only those marked
with X can be coded as dynamic SQL.
2
Each DBMS might have additional statements that can be dynamically prepared, in which case Db2 for i
CLI passes them to the DBMS. There is one exception, COMMIT and ROLLBACK can be dynamically
Deciding between Db2 for i CLI, dynamic SQL, and static SQL
Which interfaces you choose depends on your application.
Db2 for i CLI is ideally suited for query-based applications that require portability but not require the APIs
or utilities offered by a particular Database Management System (DBMS) (for example, catalog database,
backup, restore). This does not mean that using Db2 for i CLI calls DBMS-specific APIs from an
application. It means that the application is no longer portable.
Another important consideration is the performance comparison between dynamic and static SQL.
Dynamic SQL is prepared at run time, while static SQL is prepared at the precompile stage. Because
preparing statements requires additional processing time, static SQL might be more efficient. If you
choose static over dynamic SQL, then Db2 for i CLI is not an option.
In most cases the choice between either interface is open to personal preference. Your previous
experience might make one alternative seem more intuitive than the other.
/*******************************************************
** file = basiccon.c
** - demonstrate basic connection to two datasources.
** - error handling ignored for simplicity
**
** Functions used:
**
** SQLAllocConnect SQLDisconnect
** SQLAllocEnv SQLFreeConnect
** SQLConnect SQLFreeEnv
**
**
********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "sqlcli.h"
int
connect(SQLHENV henv,
SQLHDBC * hdbc);
#define MAX_DSN_LENGTH 18
#define MAX_UID_LENGTH 10
#define MAX_PWD_LENGTH 10
#define MAX_CONNECTIONS 5
int
main()
{
SQLHENV henv;
SQLHDBC hdbc[MAX_CONNECTIONS];
printf("\nDisconnecting .....\n");
SQLDisconnect(hdbc[0]); /* disconnect first connection */
SQLDisconnect(hdbc[1]); /* disconnect second connection */
SQLFreeConnect(hdbc[0]); /* free first connection handle */
SQLFreeConnect(hdbc[1]); /* free second connection handle */
SQLFreeEnv(henv); /* free environment handle */
return (SQL_SUCCESS);
}
/********************************************************************
** connect - Prompt for connect options and connect **
********************************************************************/
int
connect(SQLHENV henv,
SQLHDBC * hdbc)
{
SQLRETURN rc;
SQLCHAR server[MAX_DSN_LENGTH + 1], uid[MAX_UID_LENGTH + 1],
pwd[MAX_PWD_LENGTH
+ 1];
SQLCHAR buffer[255];
SQLSMALLINT outlen;
Processing UPDATE, DELETE, MERGE, and INSERT statements in a Db2 for i CLI application
If the statement modifies data (UPDATE, DELETE, MERGE, or INSERT), no action is required other than
the normal check for diagnostic messages. In this case, SQLRowCount() can be used to obtain the
number of rows affected by the SQL statement.
If the SQL statement is a Positioned UPDATE or DELETE, it is necessary to use a cursor. A cursor is a
moveable pointer to a row in the result table of a SELECT statement. In embedded SQL, cursors are used
to retrieve, update or delete rows. When using Db2 for i CLI, it is not necessary to define a cursor, because
one is generated automatically.
In the case of Positioned UPDATE or DELETE statements, you need to specify the name of the cursor
within the SQL statement. You can either define your own cursor name using SQLSetCursorName(), or
query the name of the generated cursor using SQLGetCursorName(). It is best to use the generated
name, because all error messages refer to this name, and not the one defined by SQLSetCursorName().
Related reference
SQLNumResultCols - Get number of result columns
SQLNumResultCols() returns the number of columns in the result set associated with the input
statement handle.
SQL_SUCCESS_WITH_INFO 1 The function is completed successfully, with a warning or other information. Call
SQLError() to receive the SQLSTATE and any other error information. The
SQLSTATE has a class of 01.
SQL_NO_DATA_FOUND 100 The function returned successfully, but no relevant data is found.
SQL_ERROR -1 The function fails. Call SQLError() to receive the SQLSTATE and any other error
information.
SQL_INVALID_HANDLE -2 The function fails because an input handle is not valid (environment, connection or
statement handle).
SQL_NEED_DATA 99 The application tries to run an SQL statement, but Db2 for i CLI lacks parameter data
that the application indicates will be passed at run time.
Note that there is no DECFLOAT(7) data type. However, DB2 will accept this data type from applications.
char xmlBuffer[10240];
integer length;
// Assume a table named dept has been created with the following statement:
// CREATE TABLE dept (id CHAR(8), deptdoc XML)
char xmlBuffer[10240];
// xmlBuffer is used to hold the retrieved XML document
integer length;
// Assume a table named dept has been created with the following statement:
// CREATE TABLE dept (id CHAR(8), deptdoc XML)
:
char *ts = "1970-01-01 12:34:56.123456";
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP, 0, 6, ts,
0, &ind);
SQLExecute(hstmt);
:
// If a timestamp that is bound as shown above is then passed on the SQLExecute call, it will
fail with
// SQLCODE -303 "Variable *N not compatible or value too long", because of the ColumnSize
parameter being 0.
// To correct this problem, bind the parameter as follows, with a ColumnSize parameter of 26 :
:
char *ts = "1970-01-01 12:34:56.123456";
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP,26, 6, ts,
0, &ind);
SQLExecute(hstmt);
:
Perhaps instead, the timestamp was stored in a large buffer and the size of the buffer was passed in:
:
char buffer[50] = "1970-01-01 12:34:56.123456";
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP,
sizeof(buffer), 6, buffer, 0, &ind);
SQLExecute(hstmt);
:
// If a timestamp that is bound as shown above is then passed on the SQLExecute call, it will
fail with
// SQLCODE -180 ""Syntax of date, time, or timestamp value not valid.", because of the
ColumnSize parameter being
// sizeof(buffer), or 50.
// To correct this problem, bind the parameter as follows, with a ColumnSize parameter of 26 :
:
Note that the same problem occurs when binding timestamp types on Db2 for i CLI SQLBindParam and
SQLBindCol functions.
To fix the problems described in the examples above, use either the corrective action shown in the
example or something similar to insure the ColumnSize parameter is set properly. Here are the details on
the changes for the parameters for the SQLBindParameter, SQLBindParam, and the SQLBindCol
functions:
• SQLBindParameter, ColumnSize must be between 19 and 32 and DecimalDigits must be between 0 and
12.
• SQLBindParam, cbParamDef must be between 19 and 32 and ibScale must be between 0 and 12.
• SQLBindCol, cbValueMax must be greater than or equal to 19.
The easiest way to always ensure these values are correct is to use the information retrieved using
SQLDescribeParam for parameter markers and SQLDescribeCol or SQLColAttribute for columns.
Type Description
Purpose This section gives a brief overview of what the function does. It also indicates if
any functions should be called before and after calling the function being
described.
Syntax This section contains the C language prototype for the IBM i environment.
Arguments This section lists each function argument, along with its data type, a description
and whether it is an input or output argument.
Each Db2 for i CLI argument is either an input or output argument. With the
exception of SQLGetInfo(), Db2 for i CLI only modifies arguments that are
indicated as output.
Some functions contain input or output arguments which are known as deferred
or bound arguments. These arguments are pointers to buffers allocated by the
application. These arguments are associated with (or bound to) either a
parameter in an SQL statement, or a column in a result set. The data areas
specified by the function are accessed by Db2 for i CLI at a later time. It is
important that these deferred data areas are still valid at the time Db2 for i CLI
accesses them.
Usage This section provides information about how to use the function, and any special
considerations. Possible error conditions are not discussed here, but are listed
in the diagnostics section instead.
Return codes This section lists all the possible function return codes. When SQL_ERROR or
SQL_SUCCESS_WITH_INFO is returned, error information can be obtained by
calling SQLError().
Refer to “Diagnostics in a Db2 for i CLI application” on page 15 for more
information about return codes.
Restrictions This section indicates any differences or limitations between Db2 for i CLI and
ODBC that might affect an application.
Example This section is a code fragment demonstrating the use of the function. The
complete source used for all code fragments is listed in “Examples: Db2 for i CLI
applications” on page 285.
References This section lists related Db2 for i CLI functions.
Syntax
Function arguments
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
If SQL_ERROR is returned, the phdbc argument is set to SQL_NULL_HDBC. The application should call
SQLError() with the environment handle (henv), with hdbc set to SQL_NULL_HDBC, and with hstmt set
to SQL_NULL_HSTMT.
Diagnostics
Example
The following example shows how to obtain diagnostic information for the connection and the
environment. For more examples of using SQLError(), refer to “Example: Interactive SQL and the
equivalent Db2 for i CLI function calls” on page 290 for a complete listing of typical.c.
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*******************************************************************
** initialize
** - allocate environment handle
** - allocate connection handle
** - prompt for server, user id, & password
** - connect to server
*******************************************************************/
if (uid[0] == '\0')
{ rc = SQLConnect (*hdbc, server, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS);
if (rc != SQL_SUCCESS )
check_error (*henv, *hdbc, SQL_NULL_HSTMT, rc);
}
else
{ rc = SQLConnect (*hdbc, server, SQL_NTS, uid, SQL_NTS, pwd, SQL_NTS);
if (rc != SQL_SUCCESS )
check_error (*henv, *hdbc, SQL_NULL_HSTMT, rc);
}
}/* end initialize */
/*******************************************************************/
int check_error (SQLHENV henv,
SQLHDBC hdbc,
SQLHSTMT hstmt,
SQLRETURN frc)
{
SQLRETURN rc;
switch (frc){
case SQL_SUCCESS : break;
case SQL_ERROR :
case SQL_INVALID_HANDLE:
printf("\n ** FATAL ERROR, Attempting to rollback transaction **\n");
rc = SQLTransact(henv, hdbc, SQL_ROLLBACK);
if (rc != SQL_SUCCESS)
printf("Rollback Failed, Exiting application\n");
else
printf("Rollback Successful, Exiting application\n");
terminate(henv, hdbc);
exit(frc);
break;
case SQL_SUCCESS_WITH_INFO :
printf("\n ** Warning Message, application continuing\n");
break;
case SQL_NO_DATA_FOUND :
printf("\n ** No Data Found ** \n");
break;
default :
printf("\n ** Invalid Return Code ** \n");
printf(" ** Attempting to rollback transaction **\n");
SQLTransact(henv, hdbc, SQL_ROLLBACK);
terminate(henv, hdbc);
exit(frc);
break;
}
return(SQL_SUCCESS);
References
• “SQLAllocEnv - Allocate environment handle” on page 27
• “SQLConnect - Connect to a data source” on page 73
• “SQLDisconnect - Disconnect from a data source” on page 85
• “SQLFreeConnect - Free connection handle” on page 112
• “SQLGetConnectAttr - Get the value of a connection attribute” on page 122
• “SQLSetConnectOption - Set connection option” on page 218
Syntax
Function arguments
Usage
There can be only one active environment at any one time per application. Any later call to
SQLAllocEnv() returns the existing environment handle.
By default, the first successful call to SQLFreeEnv() releases the resources associated with the handle.
This occurs no matter how many times SQLAllocEnv() is successfully called. If the environment
attribute SQL_ATTR_ENVHNDL_COUNTER is set to SQL_TRUE, SQLFreeEnv() must be called once for
each successful SQLAllocEnv() call before the resources associated with the handle are released.
To ensure that all Db2 for i CLI resources are kept active, the program that calls SQLAllocEnv() should
not stop or leave the stack. Otherwise, the application loses open cursors, statement handles, and other
resources it has allocated.
Return codes
• SQL_SUCCESS
• SQL_ERROR
If SQL_ERROR is returned and phenv is equal to SQL_NULL_HENV, then SQLError() cannot be called
because there is no handle with which to associate additional diagnostic information.
If the return code is SQL_ERROR and the pointer to the environment handle is not equal to
SQL_NULL_HENV, then the handle is a restricted handle. This means the handle can only be used in a call
to SQLError() to obtain more error information, or to SQLFreeEnv().
Diagnostics
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*******************************************************
** file = basiccon.c
** - demonstrate basic connection to two datasources.
** - error handling ignored for simplicity
**
** Functions used:
**
** SQLAllocConnect SQLDisconnect
#include <stdio.h>
#include <stdlib.h>
#include "sqlcli.h"
int
connect(SQLHENV henv,
SQLHDBC * hdbc);
#define MAX_DSN_LENGTH 18
#define MAX_UID_LENGTH 10
#define MAX_PWD_LENGTH 10
#define MAX_CONNECTIONS 5
int
main()
{
SQLHENV henv;
SQLHDBC hdbc[MAX_CONNECTIONS];
printf("\nDisconnecting .....\n");
SQLFreeConnect(hdbc[0]); /* free first connection handle */
SQLFreeConnect(hdbc[1]); /* free second connection handle */
SQLFreeEnv(henv); /* free environment handle */
return (SQL_SUCCESS);
}
/********************************************************************
** connect - Prompt for connect options and connect **
********************************************************************/
int
connect(SQLHENV henv,
SQLHDBC * hdbc)
{
SQLRETURN rc;
SQLCHAR server[MAX_DSN_LENGTH + 1], uid[MAX_UID_LENGTH + 1],
pwd[MAX_PWD_LENGTH
+ 1];
SQLCHAR buffer[255];
SQLSMALLINT outlen;
Syntax
Function arguments
Usage
This function is an alternative to the functions SQLAllocEnv(), SQLAllocConnect(), and
SQLAllocStmt(). In addition, it can be used to allocate a descriptor handle.
If htype is SQL_HANDLE_ENV, ihandle must be SQL_NULL_HANDLE. If htype is SQL_HANDLE_DBC,
ihandle must be a valid environment handle. If htype is either SQL_HANDLE_DESC or
SQL_HANDLE_STMT, ihandle must be a valid connection handle.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
SQL_ERROR is returned if the argument handle is a null pointer.
References
• “SQLAllocConnect - Allocate connection handle” on page 25
• “SQLAllocEnv - Allocate environment handle” on page 27
• “SQLAllocStmt - Allocate a statement handle” on page 31
Syntax
Function arguments
Usage
Db2 for i CLI uses each statement handle to relate all the descriptors, result values, cursor information,
and status information to the SQL statement processed. Although each SQL statement must have a
statement handle, you can reuse the handles for different statements.
A call to this function requires that hdbc references an active database connection.
To process a positioned UPDATE or DELETE statement, the application must use different statement
handles for the SELECT statement and the UPDATE or DELETE statement.
If the input pointer to the statement handle (phstmt) points to a valid statement handle allocated by a
previous call to SQLAllocStmt(), then the original value is overwritten as a result of this call. This is an
application programming error and is not detected by Db2 for i CLI.
Return codes
• SQL_SUCCESS
Diagnostics
Example
Refer to the example in “SQLFetch - Fetch next row” on page 100.
References
• “SQLConnect - Connect to a data source” on page 73
• “SQLFreeStmt - Free (or reset) a statement handle” on page 115
• “SQLGetStmtOption - Return current setting of a statement option” on page 163
• “SQLSetStmtOption - Set statement option” on page 237
This function is also used to specify any data conversion that is required. It is called once for each column
in the result set that the application needs to retrieve.
SQLPrepare() or SQLExecDirect() is typically called before this function. It might also be necessary
to call SQLDescribeCol() or SQLColAttribute() to get the attributes of the corresponding result set
column.
Syntax
Function arguments
Note:
For this function, both rgbValue and pcbValue are deferred outputs, meaning that the storage locations
these pointers point to are not updated until SQLFetch() is called. The locations referred to by these
pointers must remain valid until SQLFetch() is called.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Example
Refer to the example in “SQLFetch - Fetch next row” on page 100.
The LOB file reference arguments (file name, file name length, file reference options) refer to a file within
the application's environment (on the client). Before fetching each row, the application must make sure
that these variables contain the name of a file, the length of the file name, and a file option (new/
overwrite/append). These values can be changed between each fetch.
Syntax
Function arguments
SQLSMALLINT MaxFileNameLength Input This specifies the length of the FileName buffer.
SQLINTEGER * StringLength Output Pointer to the location that contains the length in
(deferred) bytes of the LOB data that is returned. If this
pointer is NULL, nothing is returned.
SQLINTEGER * IndicatorValue Output Pointer to the location that contains an indicator
(deferred) value.
Usage
The application calls SQLBindFileToCol() once for each column that should be transferred directly to
a file when a row is fetched. LOB data is written directly to the file without any data conversion, and
without appending null-terminators.
FileName, FileNameLength, and FileOptions must be set before each fetch. When SQLFetch() or
SQLFetchScroll() is called, the data for any column which has been bound to a LOB file reference is
written to the file or files pointed to by that file reference. Errors associated with the deferred input
argument values of SQLBindFileToCol() are reported at fetch time. The LOB file reference, and the
deferred StringLength and IndicatorValue output arguments are updated between fetch operations.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
HY009 Argument value that is not FileName, StringLength, or FileOptions is a null pointer.
valid
HY010 Function sequence error The function is called while in a data-at-processing
(SQLParamData(), SQLPutData()) operation.
The function is called while within a BEGIN
COMPOUND and END COMPOUND SQL operation.
Restrictions
This function is not available when connected to DB2 servers that do not support Large Object data types.
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLFetch - Fetch next row” on page 100
• “SQLBindFileToParam - Bind LOB file reference to LOB parameter” on page 40
The LOB file reference arguments (file name, file name length, file reference options) refer to a file within
the application's environment (on the client). Before calling SQLExecute() or SQLExecDirect(), the
application must make sure that this information is available in the deferred input buffers. These values
can be changed between SQLExecute() calls.
Syntax
SQLCHAR * FileName Input Pointer to the location that contains the file name
(deferred) or an array of file names when the statement
(StatementHandle) is processed. This is either the
complete path name of the file or a relative file
name. If a relative file name is provided, it is
appended to the current path of the client process.
This argument cannot be NULL.
SQLSMALLINT * FileNameLength Input Pointer to the location that contains the length of
(deferred) the file name (or an array of lengths) at the time the
next SQLExecute() or SQLExecDirect()
function is run using the StatementHandle.
If this pointer is NULL, then a length of SQL_NTS is
assumed.
The maximum value of the file name length is 255.
SQLINTEGER * FileOptions Input Pointer to the location that contains the file option
(deferred) (or an array of file options) to be used when reading
the file. The location is accessed when the
statement (StatementHandle) is processed. Only
one option is supported (and it must be specified):
SQL_FILE_READ
A regular file that can be opened, read and
closed. (The length is computed when the file is
opened)
This pointer cannot be NULL.
SQLSMALLINT MaxFileNameLength Input This specifies the length of the FileName buffer. If
the application calls SQLParamOptions() to
specify multiple values for each parameter, this is
the length of each element in the FileName array.
SQLINTEGER * IndicatorValue Input Pointer to the location that contains an indicator
(deferred), value (or array of values), which is set to
output SQL_NULL_DATA if the data value of the parameter
(deferred) is to be null. It must be set to 0 (or the pointer can
be set to null) when the data value is not null.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
HY021 Internal descriptor that is not The internal descriptor cannot be addressed or allocated, or it
valid contains a value that is not valid.
HY090 String or buffer length that is The value specified for the input argument MaxFileNameLength
not valid is less than 0.
HY093 Parameter number that is not The value specified for ParameterNumber is either less than 1
valid or greater than the maximum number of parameters supported.
HYC00 Driver not capable The data source does not support large object data types.
Restrictions
This function is not available when the application is connected to DB2 servers that do not support large
object data types.
References
• “SQLBindParam - Bind a buffer to a parameter marker” on page 43
• “SQLExecute - Execute a statement” on page 96
• “SQLParamOptions - Specify an input array for a parameter” on page 183
SQLBindParam() binds an application variable to a parameter marker in an SQL statement. This function
can also be used to bind an application variable to a parameter of a stored procedure CALL statement
where the parameter can be input or output.
Syntax
Function arguments
Usage
When SQLBindParam() is used to bind an application variable to an output parameter for a stored
procedure, Db2 for i CLI provides some performance enhancement if the rgbValue buffer is placed
consecutively in memory after the pcbValue buffer.
For decimal floating point data types, a precision of 32, 64, or 128 can be specified by using the default
symbolic C data type constants. For example, to specify a decimal floating point data type with a precision
of 128 bytes, fCType can be set to SQL_C_DECIMAL128.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
References
“SQLBindParameter - Bind a parameter marker to a buffer” on page 48
This function must also be used to bind application storage to a parameter of a stored procedure where
the parameter can be input, output, or both.
Syntax
Usage
A parameter marker is represented by a "?" character in an SQL statement and is used to indicate a
position in the statement where an application supplied value is to be substituted when the statement is
processed. This value is obtained from an application variable.
For decimal floating point data types, a precision of 32, 64, or 128 can be specified by using the default
symbolic C data type constants. For example, to specify a decimal floating point data type with a precision
of 128 bytes, ValueType can be set to SQL_C_DECIMAL128.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
HY104 Precision value not valid The value specified for ParameterType is either SQL_DECIMAL
or SQL_NUMERIC and the value specified for ParamDef is less
than 1.
HY105 Parameter type not valid InputOutputType is not one of SQL_PARAM_INPUT,
SQL_PARAM_OUTPUT, or SQL_PARAM_INPUT_OUTPUT.
HYC00 Driver not capable Db2 for i CLI or data source does not support the conversion
specified by the combination of the value specified for the
argument ValueType and the value specified for the argument
ParameterType.
The value specified for the argument ParameterType is not
supported by either Db2 for i CLI or the data source.
References
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLExecute - Execute a statement” on page 96
• “SQLParamData - Get next parameter for which a data value is needed” on page 181
• “SQLPutData - Pass data value for a parameter” on page 200
Syntax
Usage
A successful return code indicates that the implementation has accepted the cancel request; it does not
ensure that the processing is canceled.
Return codes
• SQL_SUCCESS
• SQL_INVALID_HANDLE
• SQL_ERROR
Diagnostics
Restrictions
Db2 for i CLI does not support asynchronous statement processing.
Syntax
Function arguments
Usage
Calling SQLCloseCursor() closes any cursor associated with the statement handle and discards any
pending results. If no open cursor is associated with the statement handle, the function has no effect.
If the statement handle references a stored procedure that has multiple result sets, the
SQLCloseCursor() closes only the current result set. Any additional result sets remain open and
usable.
Diagnostics
Syntax
Function arguments
SQL_ATTR_READONLY
SQL_ATTR_WRITE
SQL_ATTR_READWRITE_UNKNOWN
Usage
Instead of returning a specific set of arguments like SQLDescribeCol(), SQLColAttribute() can be
used to specify which attribute you want to receive for a specific column. If the required information is a
string, it is returned in CharacterAttributePtr. If the required information is a number, it is returned in
NumericAttributePtr.
Although SQLColAttribute() allows for future extensions, it requires more calls to receive the same
information than SQLDescribeCol() for each column.
If a FieldIdentifier descriptor type does not apply to the database server, an empty string is returned in
CharacterAttributePtr or zero is returned in NumericAttributePtr, depending on the expected result of the
descriptor.
Columns are identified by a number (numbered sequentially from left to right starting with 1) and can be
described in any order.
Calling SQLColAttribute() with FieldIdentifier set to SQL_DESC_COUNT is an alternative to calling
SQLNumResultCols() to determine whether any columns can be returned.
Call SQLNumResultCols() before calling SQLColAttribute() to determine whether a result set
exists.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLDescribeCol - Describe column attributes” on page 79
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLExecute - Execute a statement” on page 96
• “SQLPrepare - Prepare a statement” on page 184
Although this release version of DB2 CLI continues to support SQLColAttributes(), it is recommended that
you begin using SQLColAttribute() in your DB2 CLI programs so that they conform to the latest
standards.”
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLColAttributesW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Note: Refer to “SQLColAttribute - Return a column attribute” on page 59 for a description of the
applicable sections.
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLColumnPrivilegesW(). Refer to “Unicode in Db2 for i CLI”
on page 283 for more information about Unicode support forDb2 for i CLI.
Syntax
SQLRETURN SQLColumnPrivileges (
SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName
SQLSMALLINT NameLength3,
SQLCHAR *ColumnName,
SQLSMALLINT NameLength4);
Function arguments
Usage
The results are returned as a standard result set containing the columns listed in Table 31 on page 67.
The result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, and PRIVILEGE.
If multiple privileges are associated with any given column, each privilege is returned as a separate row. A
Note: The column names used by Db2 for i CLI follow the X/Open CLI CAE specification style. The column
types, contents and order are identical to those defined for the SQLColumnPrivileges() result set in
ODBC.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Restrictions
None.
Example
/* call SQLColumnPrivileges */
printf("\n Call SQLColumnPrivileges for:\n");
printf(" tbSchema = %s\n", tbSchema);
printf(" tbName = %s\n", tbName);
sqlrc = SQLColumnPrivileges( hstmt, NULL, 0,
tbSchema, SQL_NTS,
tbName, SQL_NTS,
colNamePattern, SQL_NTS);
References
• “SQLColumns - Get column information for a table” on page 69
• “SQLTables - Get table information” on page 249
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLColumnsW(). Refer to “Unicode in Db2 for i CLI” on page 283
for more information about Unicode support for Db2 for i CLI.
Syntax
Function arguments
Usage
This function retrieves information about the columns of a table or a list of tables.
SQLColumns() returns a standard result set. Table 34 on page 70 lists the columns in the result set.
The szCatalogName, szSchemaName, szTableName, and szColumnName arguments accept search
patterns. An escape character can be specified in conjunction with a wildcard character to allow that
14 SQL_DATA_TYPE SMALLINT not NULL DATA_TYPE identifies the SQL data type of
the column.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Syntax
Function arguments
Usage
You can define various connection characteristics (options) in the application using
SQLSetConnectOption().
The input length arguments to SQLConnect() (cbDSN, cbUID, cbAuthStr) can be set to the actual length
of their associated data - this does not include any null-terminating character - or to SQL_NTS to indicate
that the associated data is null-terminated.
Leading and trailing blanks in the szDSN and szUID argument values are stripped before processing unless
they are enclosed in quotation marks.
Input arguments szUID and szAuthStr are treated as case sensitive.
When running in server mode, both szUID and szAuthStr must be passed in order for the connection to run
on behalf of a user ID other than the current user. If either parameter is NULL or both are NULL, the
connection is started using the user ID that is in effect for the current job running the CLI program.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Restrictions
The implicit connection (or default database) option for IBM DBMSs is not supported. SQLConnect()
must be called before any SQL statements can be processed. Db2 for i does not support multiple
simultaneous connections to the same data source in a single job.
When you are using Db2 for i CLI on a newer release, SQLConnect() can encounter an SQL0144
message. This indicates that the data source (the server) has obsolete SQL packages that must be
deleted. To delete these packages, run the following command on the data source:
DLTSQLPKG SQLPKG(QGPL/QSQCLI*)
Example
Refer to the example in “SQLAllocEnv - Allocate environment handle” on page 27.
References
• “SQLAllocConnect - Allocate connection handle” on page 25
• “SQLAllocStmt - Allocate a statement handle” on page 31
Any existing data in the data structure associated with the target handle is overwritten, except that the
ALLOC_TYPE field is not changed.
Syntax
Function arguments
Return codes
• SQL_SUCCESS
• SQL_INVALID_HANDLE
• SQL_ERROR
For more information about cataloging, refer to the usage notes for SQLConnect() or see the online help
for the Work with Relational Database (RDB) Directory Entries (WRKRDBDIRE) command.
SQLDataSources() is typically called before a connection is made, to determine the databases that are
available to connect to.
If you are running Db2 for i CLI in SQL server mode, some restrictions apply when you use
SQLDataSources().
For more information about running in server mode refer to the “Restrictions for running Db2 for i CLI in
server mode” on page 282.
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLDataSourcesW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
SQLCHAR * ServerName Output Pointer to buffer to hold the data source name
retrieved.
Usage
The application can call this function any time by setting Direction to either SQL_FETCH_FIRST or
SQL_FETCH_NEXT.
If SQL_FETCH_FIRST is specified, the first database in the list is always returned.
If SQL_FETCH_NEXT is specified:
• Directly following the SQL_FETCH_FIRST call, the second database in the list is returned
• Before any other SQLDataSources() call, the first database in the list is returned
• When there are no more databases in the list, SQL_NO_DATA_FOUND is returned. If the function is
called again, the first database is returned.
• Any other time, the next database in the list is returned.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
HY013 Unexpected memory handling Db2 for i CLI is unable to access memory required to support
error the processing or completion of the function.
HY103 Direction option out of range The value specified for the argument Direction is not equal to
SQL_FETCH_FIRST or SQL_FETCH_NEXT.
Authorization
None.
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
#include <stdio.h>
#include <stdlib.h>
#include <sqlcli1.h>
#include "samputil.h" /* Header file for CLI sample code */
/* ... */
/*******************************************************************
** main
** - initialize
** - terminate
*******************************************************************/
int main() {
SQLHANDLE henv ;
SQLRETURN rc ;
SQLCHAR source[SQL_MAX_DSN_LENGTH + 1], description[255] ;
/* ... */
return( SQL_SUCCESS ) ;
If the application needs only one attribute of the descriptor information, the SQLColAttribute()
function can be used in place of SQLDescribeCol().
Either SQLPrepare() or SQLExecDirect() must be called before calling this function.
This function (or SQLColAttribute()) is typically called before SQLBindCol().
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLDescribeColW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
Columns are identified by a number and are numbered sequentially from left to right starting with 1, and
can be described in any order.
A valid pointer and buffer space must be made available for the szColName argument. If a null pointer is
specified for any of the remaining pointer arguments, Db2 for i CLI assumes that the information is not
needed by the application and nothing is returned.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
If SQLDescribeCol() returns either SQL_ERROR, or SQL_SUCCESS_WITH_INFO, one of the following
SQLSTATEs can be obtained by calling the SQLError() function.
40003 * Statement completion The communication link between the CLI and the
unknown data source fails before the function completes
processing.
58004 System error Unrecoverable system error.
HY001 Memory allocation The driver is unable to allocate memory required to
failure support the processing or completion of the
function.
HY009 Argument value that is The length specified in argument cbColNameMax is
not valid less than 1.
The argument szColName or pcbColName is a null
pointer.
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*******************************************************************
** file = typical.c
...
/*******************************************************************
** display_results
**
** - for each column
** - get column name
** - bind column
** - display column headings
** - fetch each row
** - if value truncated, build error message
References
• “SQLColAttribute - Return a column attribute” on page 59
• “SQLColAttributes - Obtain column attributes” on page 65
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLNumResultCols - Get number of result columns” on page 180
Syntax
Function arguments
Usage
Parameter markers are numbered in increasing parameter order, starting with 1, in the order they appear
in the SQL statement.
SQLDescribeParam() does not return the type (input, output, or both input and output) of a parameter
in an SQL statement. Except in calls to procedures, all parameters in SQL statements are input
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
08S01 Communication link failure The communication link between Db2 for i
CLI and the data source to which it is
connected fails before the function
completes processing.
21S01 Insert value list does not The number of parameters in the INSERT
match column list statement does not match the number of
columns in the table named in the
statement.
HY000 General error
HY001 Memory allocation failure Db2 for i CLI is unable to allocate memory
required to support the processing or
completion of the function.
HY008 Operation canceled.
HY009 Argument value that is not The argument DataTypePtr,
valid ParameterSizePtr, DecimalDigitsPtr, or
NullablePtr is a null pointer.
HY010 Function sequence error The function is called before calling
SQLPrepare() or SQLExecDirect() for
the StatementHandle.
Restrictions
None.
References
• “SQLBindParam - Bind a buffer to a parameter marker” on page 43
• “SQLCancel - Cancel statement” on page 57
• “SQLExecute - Execute a statement” on page 96
• “SQLPrepare - Prepare a statement” on page 184
After calling this function, either call SQLConnect() to connect to another database, or call
SQLFreeConnect().
Syntax
Function arguments
Usage
If an application calls SQLDisconnect before it has freed all the statement handles associated with the
connection, Db2 for i CLI frees them after it successfully disconnects from the database.
If SQL_SUCCESS_WITH_INFO is returned, it implies that even though the disconnect from the database is
successful, additional error or implementation specific information is available. For example:
• A problem is encountered on the clean up after the disconnect, or,
• If there is no current connection because of an event that occurred independently of the application
(such as communication failure).
After a successful SQLDisconnect() call, the application can re-use hdbc to make another
SQLConnect() request.
If the hdbc is participating in a DUOW two-phase commit connection, the disconnect might not occur
immediately. The actual disconnect occurs at the next commit issued for the distributed transaction.
Diagnostics
Example
Refer to the example in “SQLAllocEnv - Allocate environment handle” on page 27.
References
• “SQLAllocConnect - Allocate connection handle” on page 25
• “SQLConnect - Connect to a data source” on page 73
• “SQLTransact - Commit or roll back a transaction” on page 251
Function arguments
SQLSMALLINT DriverCompletion Input This indicates when Db2 for i CLI should prompt
the user for more information.
Possible values:
• SQL_DRIVER_COMPLETE
• SQL_DRIVER_COMPLETE_REQUIRED
• SQL_DRIVER_NOPROMPT
Usage
The connection string is used to pass one or more values that are needed to complete a connection. The
contents of the connection string and the value of DriverCompletion determine how the connection should
be established.
UID
PWD
DB2 CLI-defined-keyword
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_NO_DATA_FOUND
• SQL_INVALID_HANDLE
• SQL_ERROR
Error conditions
All of the diagnostics that are generated by SQLConnect() can be returned here as well. The following
table shows the additional diagnostics that can be returned.
HY090 String or buffer length that is The value specified for StringLength1 is less than 0, but not
not valid equal to SQL_NTS.
The value specified for BufferLength is less than 0.
HY110 Driver completion that is not The value specified for the argument DriverCompletion is not
valid equal to one of the valid values.
Restrictions
None.
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
int
drv_connect(SQLHENV henv,
SQLHDBC * hdbc,
SQLCHAR con_type)
{
SQLRETURN rc;
SQLCHAR server[SQL_MAX_DSN_LENGTH + 1];
SQLCHAR uid[MAX_UID_LENGTH + 1];
SQLCHAR pwd[MAX_PWD_LENGTH + 1];
SQLCHAR con_str[255];
SQLCHAR buffer[255];
SQLSMALLINT outlen;
rc = SQLDriverConnect(*hdbc,
(SQLPOINTER) NULL,
con_str,
SQL_NTS,
buffer, 255, &outlen,
SQL_DRIVER_NOPROMPT);
if (rc != SQL_SUCCESS) {
printf("Error while connecting to database, RC= %ld\n", rc);
CHECK_HANDLE( SQL_NULL_HENV, *hdbc, rc);
return (SQL_ERROR);
} else {
printf("Successful Connect\n");
return (SQL_SUCCESS);
}
}
References
“SQLConnect - Connect to a data source” on page 73
All changes to the database that have been made on the connection since connect time or the previous
call to SQLEndTran(), whichever is the most recent, are committed or rolled back.
If a transaction is active on a connection, the application must call SQLEndTran() before it can
disconnect from the database.
Syntax
Function arguments
Usage
Completing a transaction with SQL_COMMIT or SQL_ROLLBACK has the following effects:
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Syntax
Function arguments
Usage
The SQLSTATEs are those defined by the X/OPEN SQL CAE and the X/Open SQL CLI snapshot, augmented
with IBM specific and product specific SQLSTATE values.
• To obtain diagnostic information associated with an environment, pass a valid environment handle. Set
hdbc to SQL_NULL_HDBC. Set hstmt to SQL_NULL_HSTMT.
• To obtain diagnostic information associated with a connection, pass a valid database connection
handle, and set hstmt to SQL_NULL_HSTMT. The henv argument is ignored.
• To obtain diagnostic information associated with a statement, pass a valid statement handle. The henv
and hdbc arguments are ignored.
If diagnostic information generated by one Db2 for i CLI function is not retrieved before a function other
than SQLError() is called with the same handle, the information for the previous function call is lost.
This is true whether diagnostic information is generated for the second Db2 for i CLI function call.
To avoid truncation of the first level error message, declare a buffer length of
SQL_MAX_MESSAGE_LENGTH + 1. To avoid truncation of the second level error message, set the size of
the buffer to a value greater than SQL_MAX_MESSAGE_LENGTH.
Return codes
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
• SQL_SUCCESS
Diagnostics
SQLSTATEs are not defined because SQLError() does not generate diagnostic information for itself.
SQL_ERROR is returned if argument szSqlState, pfNativeError, szErrorMsg, or pcbErrorMsg is a
null pointer.
/*************************************************************************
** file = typical.c
************************************************************************/
int print_error (SQLHENV henv,
SQLHDBC hdbc,
SQLHSTMT hstmt)
{
SQLCHAR buffer[SQL_MAX_MESSAGE_LENGTH + 1];
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
SQLINTEGER sqlcode;
SQLSMALLINT length;
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLExecDirectW(). Refer to “Unicode in Db2 for i CLI” on page 283
for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
The SQL statement cannot be a COMMIT or ROLLBACK. Instead, SQLTransact() must be called to issue
COMMIT or ROLLBACK. For more information about supported SQL statements refer to Table 1 on page 3.
The SQL statement string might contain parameter markers. A parameter marker is represented by a "?"
character, and indicates a position in the statement where the value of an application variable is to be
substituted, when SQLExecDirect() is called. SQLBindParam() binds (or associates) an application
variable to each parameter marker, to indicate if any data conversion should be performed at the time the
data is transferred. All parameters must be bound before calling SQLExecDirect().
If the SQL statement is a SELECT, SQLExecDirect() generates a cursor name, and open the cursor. If
the application has used SQLSetCursorName() to associate a cursor name with the statement handle,
Db2 for i CLI associates the application generated cursor name with the internally generated one.
To retrieve a row from the result set generated by a SELECT statement, call SQLFetch() after
SQLExecDirect() returns successfully.
If the SQL statement is a Positioned DELETE or a Positioned UPDATE, the cursor referenced by the
statement must be positioned on a row. Additionally the SQL statement must be defined on a separate
statement handle under the same connection handle.
There must not be an open cursor on the statement handle.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
SQL_NO_DATA_FOUND is returned if the SQL statement is a Searched UPDATE or Searched DELETE and
no rows satisfy the search condition.
Diagnostics
Note: There are many other SQLSTATE values that can be generated by the Database Management
System (DBMS), on processing of the statement.
Example
References
• “SQLExecute - Execute a statement” on page 96
• “SQLFetch - Fetch next row” on page 100
• “SQLSetParam - Set parameter” on page 230
Syntax
Function arguments
Usage
The SQL statement string might contain parameter markers. A parameter marker is represented by a "?"
character, and indicates a position in the statement where the value of an application variable is to be
substituted, when SQLExecute() is called. SQLBindParam() is used to bind (or associate) an
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
• SQL_NEED_DATA
SQL_NO_DATA_FOUND is returned if the SQL statement is a Searched UPDATE or Searched DELETE and
no rows satisfy the search condition.
Diagnostics
The SQLSTATEs for SQLExecute() include all those for SQLExecDirect() (see Table 53 on page 95)
except for HY009, and with the addition of the SQLSTATEs in the following table.
Note: There are many other SQLSTATE values that can be generated by the Database Management
System (DBMS), on processing of the statement.
Example
References
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLPrepare - Prepare a statement” on page 184
• “SQLFetch - Fetch next row” on page 100
• “SQLSetParam - Set parameter” on page 230
Syntax
Function arguments
Usage
SQLExtendedFetch() is used to perform an array fetch of a set of rows. An application specifies the
size of the array by calling SQLSetStmtAttr() with the SQL_ROWSET_SIZE attribute.
Before SQLExtendedFetch() is called the first time, the cursor is positioned before the first row. After
SQLExtendedFetch() is called, the cursor is positioned on the row in the result set corresponding to
the last row element in the rowset just retrieved.
For any columns in the result set that have been bound by the SQLBindCol() function, Db2 for i CLI
converts the data for the bound columns as necessary and stores it in the locations bound to these
columns. The result set must be bound in a row-wise fashion. This means that the values for all the
columns of the first row are contiguous, followed by the values of the second row, and so on. Also, if
indicator variables are used, they are all returned in one contiguous storage location.
When using this procedure to retrieve multiple rows, all columns must be bound, and the storage must be
contiguous. When using this function to retrieve rows from an SQL procedure result set, only the
SQL_FETCH_NEXT orientation is supported. The user is responsible for allocating enough storage for the
number of rows that are specified in SQL_ROWSET_SIZE.
The cursor must be a scrollable cursor for SQLExtendedFetch() to use any orientation other than
SQL_FETCH_NEXT. See “SQLSetStmtAttr - Set a statement attribute” on page 230 for information about
setting the SQL_ATTR_CURSOR_SCROLLABLE attribute.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
HY021 Internal descriptor that is not The internal descriptor cannot be addressed or allocated, or it
valid contains a value that is not valid.
Restrictions
None.
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLExecute - Execute a statement” on page 96
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLFetch - Fetch next row” on page 100
SQLFetch() can be used to receive the data directly into variables that you specify with SQLBindCol(),
or the columns can be received individually after the fetch by calling SQLGetData(). Data conversion is
also performed when SQLFetch() is called, if conversion is indicated when the column is bound.
Syntax
Function arguments
Usage
SQLFetch() can only be called if the most recently processed statement on hstmt is a SELECT.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
SQL_NO_DATA_FOUND is returned if there are no rows in the result set, or previous SQLFetch() calls
have fetched all the rows from the result set.
Diagnostics
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*************************************************************************
** file = fetch.c
**
** Example of executing an SQL statement.
** SQLBindCol & SQLFetch is used to retrieve data from the result set
** directly into application storage.
**
** Functions used:
**
** SQLAllocConnect SQLFreeConnect
** SQLAllocEnv SQLFreeEnv
** SQLAllocStmt SQLFreeStmt
** SQLConnect SQLDisconnect
**
** SQLBindCol SQLFetch
** SQLTransact SQLExecDirect
** SQLError
**
**************************************************************************/
#include <stdio.h>
#include <string.h>
#include "sqlcli.h"
/*******************************************************************
** main
** - initialize
** - terminate
*******************************************************************/
int main()
{
SQLHENV henv;
SQLHDBC hdbc;
SQLCHAR sqlstmt[MAX_STMT_LEN + 1]="";
SQLRETURN rc;
rc = initialize(&henv, &hdbc);
if (rc == SQL_ERROR) return(terminate(henv, hdbc));
rc = SQLAllocStmt(hdbc, &hstmt);
if (rc != SQL_SUCCESS )
check_error (henv, hdbc, SQL_NULL_HSTMT, rc);
rc = SQLFreeStmt(hstmt, SQL_DROP);
if (rc != SQL_SUCCESS )
check_error (henv, hdbc, SQL_NULL_HSTMT, rc);
}
terminate(henv, hdbc);
return (0);
}/* end main */
/*******************************************************************
** initialize
** - allocate environment handle
** - allocate connection handle
** - prompt for server, user id, & password
** - connect to server
*******************************************************************/
if (uid[0] == '\0')
{ rc = SQLConnect (*hdbc, server, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS);
if (rc != SQL_SUCCESS )
return(SQL_SUCCESS);
}/* end initialize */
/*******************************************************************
** terminate
** - disconnect
** - free connection handle
** - free environment handle
*******************************************************************/
int terminate(SQLHENV henv,
SQLHDBC hdbc)
{
SQLRETURN rc;
return(rc);
}/* end terminate */
/*******************************************************************
** - print_error - call SQLError(), display SQLSTATE and message
*******************************************************************/
return ( SQL_ERROR);
} /* end print_error */
/*******************************************************************
** - check_error - call print_error(), checks severity of return code
*******************************************************************/
int check_error (SQLHENV henv,
SQLHDBC hdbc,
SQLHSTMT hstmt,
SQLRETURN frc)
{
SQLRETURN rc;
switch (frc){
case SQL_SUCCESS : break;
case SQL_ERROR :
case SQL_INVALID_HANDLE:
printf("\n ** FATAL ERROR, Attempting to rollback transaction **\n");
rc = SQLTransact(henv, hdbc, SQL_ROLLBACK);
if (rc != SQL_SUCCESS)
printf("Rollback Failed, Exiting application\n");
else
} /* end check_error */
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLExecute - Execute a statement” on page 96
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLGetCol - Retrieve one column of a row of the result set” on page 117
• “SQLFetchScroll - Fetch from a scrollable cursor” on page 105
SQLFetchScroll() can be used to receive the data directly into variables that you specify with
SQLBindCol(), or the columns can be received individually after the fetch by calling SQLGetData().
Data conversion is also performed when SQLFetchScroll() is called, if conversion is indicated when
the column is bound.
Syntax
Function arguments
Usage
SQLFetchScroll() can only be called if the most recently processed statement on hstmt is a SELECT.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
Diagnostics
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLExecute - Execute a statement” on page 96
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLExtendedFetch - Fetch array of rows” on page 98
• “SQLGetCol - Retrieve one column of a row of the result set” on page 117
• “SQLFetch - Fetch next row” on page 100
• “SQLSetStmtAttr - Set a statement attribute” on page 230
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLForeignKeysW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Usage
If PKTableName contains a table name, and FKTableName is an empty string, SQLForeignKeys()
returns a result set that contains the primary key of the specified table and all of the foreign keys (in other
tables) that refer to it.
If FKTableName contains a table name, and PKTableName is an empty string, SQLForeignKeys()
returns a result set that contains all of the foreign keys in the specified table and the primary keys (in
other tables) to which they refer.
If both PKTableName and FKTableName contain table names, SQLForeignKeys() returns the foreign
keys in the table specified in FKTableName that refer to the primary key of the table specified in
PKTableName. This should be one key at the most.
If the schema qualifier argument that is associated with a table name is not specified, then for the
schema name the default is the one currently in effect for the current connection.
Table 64 on page 109 lists the columns of the result set generated by the SQLForeignKeys() call. If the
foreign keys that are associated with a primary key are requested, the result set is ordered by
FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and ORDINAL_POSITION. If the primary keys that
are associated with a foreign key are requested, the result set is ordered by PKTABLE_CAT,
PKTABLE_SCHEM, PKTABLE_NAME, and ORDINAL_POSITION.
Although new columns might be added and the names of the existing columns might be changed in future
releases, the position of the current columns does not change.
11 DELETE_RULE SMALLINT Action to be applied to the foreign key when the SQL operation is
DELETE:
• SQL_CASCADE
• SQL_NO_ACTION
• SQL_RESTRICT
• SQL_SET_DEFAULT
• SQL_SET_NULL
12 FK_NAME VARCHAR(128) Foreign key identifier. NULL if not applicable to the data source.
13 PK_NAME VARCHAR(128) Primary key identifier. NULL if not applicable to the data source.
14 DEFERRABILITY SMALLINT One of:
• SQL_INITIALLY_DEFERRED
• SQL_INITIALLY_IMMEDIATE
• SQL_NOT_DEFERRABLE
Note: The column names used by Db2 for i CLI follow the X/Open CLI CAE specification style. The column
types, contents and order are identical to those defined for the SQLForeignKeys() result set in ODBC.
Diagnostics
HYC00 Driver not capable Db2 for i CLI does not support catalog as a qualifier for table
name.
HYT00 Timeout expired
Restrictions
None.
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/* ... */
rc = SQLForeignKeys(hstmt, NULL, 0,
schema, SQL_NTS, tablename, SQL_NTS,
Syntax
Function arguments
Usage
If this function is called when a connection still exists, SQL_ERROR is returned, and the connection
handle remains valid.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Example
References
• “SQLDisconnect - Disconnect from a data source” on page 85
• “SQLFreeEnv - Free environment handle” on page 113
Syntax
Function arguments
Usage
If this function is called when there is still a valid connection handle, SQL_ERROR is returned, and the
environment handle remains valid.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Example
References
“SQLFreeConnect - Free connection handle” on page 112
Syntax
Function arguments
Usage
SQLFreeHandle() combines the function of SQLFreeEnv(), SQLFreeConnect(), and
SQLFreeStmt().
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
References
• “SQLFreeConnect - Free connection handle” on page 112
• “SQLFreeEnv - Free environment handle” on page 113
• “SQLFreeStmt - Free (or reset) a statement handle” on page 115
Syntax
Function arguments
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_IN_HANDLE
SQL_SUCCESS_WITH_INFO is not returned if fOption is set to SQL_DROP, because there is no statement
handle to use when SQLError() is called.
Diagnostics
Example
References
• “SQLAllocStmt - Allocate a statement handle” on page 31
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLFetch - Fetch next row” on page 100
• “SQLFreeConnect - Free connection handle” on page 112
• “SQLSetParam - Set parameter” on page 230
Syntax
Function arguments
Usage
SQLGetCol() can be used with SQLBindCol() for the same row, as long as the value of icol does not
specify a column that has been bound. The general steps are:
1. SQLFetch() - advances cursor to first row, retrieves first row, transfers data for bound columns.
2. SQLGetCol() - transfers data for specified (unbound) column.
3. Repeat step 2 for each column needed.
4. SQLFetch() - advances cursor to next row, retrieves next row, transfers data for bound columns.
5. Repeat steps 2, 3 and 4 for each row in the result set, or until the result set is no longer needed.
SQLGetCol() retrieves long columns if the C data type (fCType) is SQL_CHAR or if fCType is
SQL_DEFAULT and the column type is CHAR or VARCHAR.
On each SQLGetCol() call, if the data available for return is greater than or equal to cbValueMax,
truncation occurs. A function return code of SQL_SUCCESS_WITH_INFO that is coupled with an
SQLSTATE that denotes data truncation indicates truncation. The application can call SQLGetCol()
again, with the same icol value, to obtain later data from the same unbound column starting at the point
of truncation. To obtain the entire column, the application repeats such calls until the function returns
SQL_SUCCESS. The next call to SQLGetCol() returns SQL_NO_DATA_FOUND.
To discard the column data part way through the retrieval, the application can call SQLGetCol() with icol
set to the next column position of interest. To discard unretrieved data for the entire row, the application
should call SQLFetch() to advance the cursor to the next row; or, if it is not interested in any more data
from the result set, call SQLFreeStmt() to close the cursor.
The fCType input argument determines the type of data conversion (if any) needed before the column
data is placed into the storage area pointed to by rgbValue.
The contents returned in rgbValue is always null-terminated unless SQLSetEnvAttr() is used to change
the SQL_ATTR_OUTPUT_NTS attribute or if the application is retrieving the data in multiple chunks. If the
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
SQL_NO_DATA_FOUND is returned when the preceding SQLGetCol() call has retrieved all of the data
for this column.
SQL_SUCCESS is returned if a zero-length string is retrieved by SQLGetCol(). If this is the case,
pcbValue contains 0, and rgbValue contains a null terminator.
If the preceding call to SQLFetch() fails, SQLGetCol() should not be called because the result is
undefined.
Diagnostics
HY010 Function sequence error The specified hstmt is not in a cursor positioned
state. The function is called without first calling
SQLFetch().
HY013 * Memory management The driver is unable to access memory required to
problem support the processing or completion of the
function.
HY021 Internal descriptor that The internal descriptor cannot be addressed or
is not valid allocated, or it contains a value that is not valid.
Restrictions
ODBC requires that icol not specify a column of a lower number than the column last retrieved by
SQLGetCol() for the same row on the same statement handle. ODBC also does not permit the use of
SQLGetCol() to retrieve data for a column that resides before the last bound column, (if any columns in
the row have been bound).
Db2 for i CLI has relaxed both of these rules by allowing the value of icol to be specified in any order and
before a bound column, provided that icol does not specify a bound column.
Example
Refer to the example in the “SQLFetch - Fetch next row” on page 100 for a comparison between using
bound columns and using SQLGetCol().
Refer to “Example: Interactive SQL and the equivalent Db2 for i CLI function calls” on page 290 for a
listing of the check_error, initialize, and terminate functions used in the following example.
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*************************************************************************
** file = getcol.c
**
** Example of directly executing an SQL statement.
** Getcol is used to retrieve information from the result set.
** Compare to fetch.c
**
** Functions used:
**
** SQLAllocConnect SQLFreeConnect
** SQLAllocEnv SQLFreeEnv
** SQLAllocStmt SQLFreeStmt
** SQLConnect SQLDisconnect
**
** SQLBindCol SQLFetch
** SQLTransact SQLError
** SQLExecDirect SQLGetCursor
**************************************************************************/
#include <stdio.h>
#include <string.h>
#include "sqlcli.h"
rc = initialize(&henv, &hdbc);
if (rc != SQL_SUCCESS) return(terminate(henv, hdbc));
{SQLHSTMT hstmt;
SQLCHAR sqlstmt[]="SELECT deptname, location from org where division = 'Eastern'";
SQLCHAR deptname[15],
location[14];
SQLINTEGER rlength;
rc = SQLAllocStmt(hdbc, &hstmt);
if (rc != SQL_SUCCESS )
check_error (henv, hdbc, SQL_NULL_HSTMT, rc);
terminate(henv, hdbc);
return (SQL_SUCCESS);
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLFetch - Fetch next row” on page 100
Syntax
Function arguments
Usage
Statement options settings cannot be retrieved through SQLGetConnectAttr().
Diagnostics
HYC00 Driver not capable The fAttr argument is recognized, but is not
supported.
Syntax
Function arguments
Usage
SQLGetConnectOption() provides the same function as SQLGetConnectAttr(). Both functions are
supported for compatibility reasons.
Statement options settings cannot be retrieved through SQLGetConnectOption().
Diagnostics
HYC00 Driver not capable The fOption argument is recognized, but is not
supported.
References
“SQLGetConnectAttr - Get the value of a connection attribute” on page 122
Syntax
Function arguments
Usage
SQLGetCursorName() returns a cursor name if a name is set using SQLSetCursorName() or if a
SELECT statement is processed on the statement handle. If neither of these is true, then calling
SQLGetCusorName() results in an error.
If a name is set explicitly using SQLSetCursorName(), this name is returned until the statement is
dropped, or until another explicit name is set.
If an explicit name is not set, an implicit name is generated when a SELECT statement is processed, and
this name is returned. Implicit cursor names always begin with SQLCUR.
The generated cursor names of ODBC start with SQL_CUR and X/Open CLI generated cursor names begin
with SQLCUR. Db2 for i CLI uses SQLCUR.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
HY010 Function sequence error The statement hstmt is not in execute state. Call
SQLExecute(), SQLExecDirect() or
SQLSetCursorName() before calling
SQLGetCursorName().
HY013 * Memory management The driver is unable to access memory required to
problem support the processing or completion of the
function.
HY015 No cursor name There is no open cursor on the hstmt and no cursor
available. name has been set with SQLSetCursorName().
The statement associated with hstmt does not
support the use of a cursor.
Example
Refer to “Example: Interactive SQL and the equivalent Db2 for i CLI function calls” on page 290 for a
listing of the check_error, initialize, and terminate functions used in the following example.
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*************************************************************************
** file = getcurs.c
**
** Example of directly executing a SELECT and positioned UPDATE SQL statement.
** Two statement handles are used, and SQLGetCursor is used to retrieve the
** generated cursor name.
**
** Functions used:
**
** SQLAllocConnect SQLFreeConnect
** SQLAllocEnv SQLFreeEnv
** SQLAllocStmt SQLFreeStmt
** SQLConnect SQLDisconnect
/*******************************************************************
** main
** - initialize
** - terminate
*******************************************************************/
int main()
{
SQLHENV henv;
SQLHDBC hdbc;
SQLRETURN rc,
rc2;
rc = initialize(&henv, &hdbc);
if (rc != SQL_SUCCESS) return(terminate(henv, hdbc));
{SQLHSTMT hstmt1,
hstmt2;
SQLCHAR sqlstmt[]="SELECT name, job from staff for update of job";
SQLCHAR updstmt[MAX_STMT_LEN + 1];
SQLCHAR name[10],
job[6],
newjob[6],
cursor[19];
rc = SQLAllocStmt(hdbc, &hstmt1);
if (rc != SQL_SUCCESS )
check_error (henv, hdbc, SQL_NULL_HSTMT, rc);
printf("Commiting Transaction\n");
rc = SQLTransact(henv, hdbc, SQL_COMMIT);
if (rc != SQL_NO_DATA_FOUND )
check_error (henv, hdbc, SQL_NULL_HSTMT, rc);
terminate(henv, hdbc);
return (0);
}/* end main */
References
• “SQLExecute - Execute a statement” on page 96
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLSetCursorName - Set cursor name” on page 219
Syntax
Note: Refer to “SQLGetCol - Retrieve one column of a row of the result set” on page 117 for a description
of the applicable sections.
This function is similar to that of SQLDescribeCol(), but SQLGetDescField() can retrieve data from
parameter descriptors as well as row descriptors.
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetDescFieldW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
Diagnostics
HY013 * Memory management The driver is unable to access the memory required
problem to support the processing or completion of the
function.
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLDescribeCol - Describe column attributes” on page 79
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLExecute - Execute a statement” on page 96
• “SQLPrepare - Prepare a statement” on page 184
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetDescRecW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
Calling SQLGetDescRec() retrieves all the data from a descriptor record in one call. It might still be
necessary to call SQLGetDescField() with SQL_DESC_COUNT to determine the number of records in
the descriptor.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLDescribeCol - Describe column attributes” on page 79
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLExecute - Execute a statement” on page 96
• “SQLPrepare - Prepare a statement” on page 184
The information consists of a standardized SQLSTATE, an error code, and a text message. Refer to
“Diagnostics in a Db2 for i CLI application” on page 15 for more information.
Call SQLGetDiagField() after receiving a return code of SQL_ERROR or SQL_SUCCESS_WITH_INFO
from another function call.
Note: Some database servers might provide product-specific diagnostic information after returning
SQL_NO_DATA_FOUND from the processing of a statement.
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetDiagFieldW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Usage
The SQLSTATEs are those defined by the X/OPEN SQL CAE and the X/Open SQL CLI snapshot, augmented
with SQLSTATE values.
If diagnostic information generated by one Db2 for i CLI function is not retrieved before a function other
than SQLGetDiagField() is called with the same handle, the information for the previous function call
is lost. This is true whether diagnostic information is generated for the second Db2 for i CLI function call.
Multiple diagnostic messages might be available after a given Db2 for i CLI function call. These messages
can be retrieved one at a time by repeatedly calling SQLGetDiagField(). When there are no more
messages to retrieve, SQL_NO_DATA_FOUND is returned.
Diagnostic information stored under a given handle is cleared when a call is made to
SQLGetDiagField() with that handle, or when another Db2 for i CLI function call is made with that
handle. However, information associated with a given handle type is not cleared by a call to
SQLGetDiagField() with an associated but different handle type. For example, a call to
SQLGetDiagField() with a connection handle input does not clear errors associated with any
statement handles under that connection.
SQL_SUCCESS is returned even if the buffer for the error message (szDiagFieldMsg) is too short. This is
because the application is not able to retrieve the same error message by calling SQLGetDiagField()
again. The actual length of the message text is returned in the pcbDiagFieldMsg.
To avoid truncation of the first level error message, declare a buffer length of
SQL_MAX_MESSAGE_LENGTH + 1. To avoid truncation of the second level error message, set the size of
the buffer to a value greater than SQL_MAX_MESSAGE_LENGTH.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
SQL_NO_DATA_FOUND is returned if no diagnostic information is available for the input handle, or if all of
the messages have been retrieved through calls to SQLGetDiagField().
SQL_ERROR is returned if the argument diagInfo or sLen is a null pointer.
Diagnostics
SQLSTATEs are not defined, because SQLGetDiagField() does not generate diagnostic information for
itself.
Restrictions
Although ODBC also returns X/Open SQL CAE SQLSTATEs, only Db2 for i CLI returns the additional IBM
defined SQLSTATEs. The ODBC Driver Manager also returns SQLSTATE values in addition to the standard
ones. For more information about ODBC specific SQLSTATEs refer to Microsoft ODBC Programmer's
Reference.
The information consists of a standardized SQLSTATE, the error code, and a text message. See
“Diagnostics in a Db2 for i CLI application” on page 15 for more information.
Call SQLGetDiagRec() after receiving a return code of SQL_ERROR or SQL_SUCCESS_WITH_INFO from
another function call.
Note: Some database servers might provide product-specific diagnostic information after returning
SQL_NO_DATA_FOUND from the processing of a statement.
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetDiagRecW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
The SQLSTATEs are those defined by the X/OPEN SQL CAE and the X/Open SQL CLI snapshot, augmented
with IBM specific and product specific SQLSTATE values.
If diagnostic information generated by one Db2 for i CLI function is not retrieved before a function other
than SQLGetDiagRec() is called with the same handle, the information for the previous function call is
lost. This is true whether diagnostic information is generated for the second Db2 for i CLI function call.
Multiple diagnostic messages might be available after a given Db2 for i CLI function call. These messages
can be retrieved one at a time by repeatedly calling SQLGetDiagRec(). When there are no more
messages to retrieve, SQL_NO_DATA_FOUND is returned, the SQLSTATE is set to "00000", pfNativeError
is set to 0, and pcbErrorMsg and szErrorMsg are undefined.
Diagnostic information stored under a given handle is cleared when a call is made to SQLGetDiagRec()
with that handle, or when another Db2 for i CLI function call is made with that handle. However,
information associated with a given handle type is not cleared by a call to SQLGetDiagRec() with an
associated but different handle type. For example, a call to SQLGetDiagRec() with a connection handle
input does not clear errors associated with any statement handles under that connection.
SQL_SUCCESS is returned even if the buffer for the error message (szErrorMsg) is too short, because the
application is not able to retrieve the same error message by calling SQLGetDiagRec() again. The actual
length of the message text is returned in the pcbErrorMsg.
To avoid truncation of the first level error message, declare a buffer length of
SQL_MAX_MESSAGE_LENGTH + 1. To avoid truncation of the second level error message, set the size of
the buffer to a value greater than SQL_MAX_MESSAGE_LENGTH.
Return codes
• SQL_SUCCESS
• SQL_ERROR
Diagnostics
SQLSTATEs are not defined because SQLGetDiagRec() does not generate diagnostic information for
itself.
Restrictions
Although ODBC also returns X/Open SQL CAE SQLSTATEs, only Db2 for i CLI returns the additional IBM
defined SQLSTATEs. The ODBC Driver Manager also returns SQLSTATE values in addition to the standard
ones. For more information about ODBC specific SQLSTATEs refer to Microsoft ODBC Programmer's
Reference.
Because of this, you should only build dependencies on the standard SQLSTATEs. This means any
branching logic in the application should only rely on the standard SQLSTATEs. The augmented
SQLSTATEs are most useful for debugging purposes.
References
“SQLGetDiagField - Return diagnostic information (extensible)” on page 133
Syntax
Function arguments
If Attribute does not denote a string, then Db2 for i CLI ignores BufferLength and does not set
StringLength.
Usage
SQLGetEnvAttr() can be called at any time between the allocation and freeing of the environment
handle. It obtains the current value of the environment attribute.
Diagnostics
SQLConnect() must be called, and a connection to the data source (database server) must exist before
calling this function.
Syntax
Function arguments
SQL_API_ALLOCCONNECT = TRUE
SQL_API_ALLOCENV = TRUE
SQL_API_ALLOCHANDLE = TRUE
SQL_API_ALLOCSTMT = TRUE
SQL_API_BINDCOL = TRUE
SQL_API_BINDFILETOCOL = TRUE
SQL_API_BINDFILETOPARAM = TRUE
SQL_API_BINDPARAM = TRUE
SQL_API_BINDPARAMETER = TRUE
SQL_API_CANCEL = TRUE
SQL_API_CLOSECURSOR = TRUE
SQL_API_COLATTRIBUTE = TRUE
SQL_API_COLATTRIBUTEW = TRUE
SQL_API_COLATTRIBUTES = TRUE
SQL_API_COLATTRIBUTESW = TRUE
SQL_API_COLUMNS = TRUE
SQL_API_COLUMNSW = TRUE
SQL_API_CONNECT = TRUE
SQL_API_CONNECTW = TRUE
SQL_API_COPYDESC = TRUE
SQL_API_DATASOURCES = TRUE
SQL_API_DATASOURCESW = TRUE
SQL_API_DESCRIBECOL = TRUE
SQL_API_DESCRIBECOLW = TRUE
SQL_API_DESCRIBEPARAM = TRUE
SQL_API_DISCONNECT = TRUE
SQL_API_DRIVERCONNECT = TRUE
SQL_API_DRIVERCONNECTW = TRUE
SQL_API_ENDTRAN = TRUE
SQL_API_ERROR = TRUE
SQL_API_ERRORW = TRUE
SQL_API_EXECDIRECT = TRUE
SQL_API_EXECDIRECTW = TRUE
SQL_API_EXECUTE = TRUE
SQL_API_EXTENDEDFETCH = TRUE
SQL_API_FETCH = TRUE
SQL_API_FOREIGNKEYS = TRUE
SQL_API_FOREIGNKEYSW = TRUE
SQL_API_FREECONNECT = TRUE
SQL_API_FREEENV = TRUE
SQL_API_FREEHANDLE = TRUE
SQL_API_FREESTMT = TRUE
SQL_API_GETCOL = TRUE
SQL_API_GETCONNECTATTR = TRUE
SQL_API_GETCONNECTATTRW = TRUE
SQL_API_GETCONNECTOPTION = TRUE
SQL_API_GETCONNECTOPTIONW = TRUE
SQL_API_GETCURSORNAME = TRUE
SQL_API_GETCURSORNAMEW = TRUE
SQL_API_GETDATA = TRUE
SQL_API_GETDESCFIELD = TRUE
SQL_API_GETDESCFIELDW = TRUE
SQL_API_GETDESCREC = TRUE
SQL_API_GETDESCRECW = TRUE
SQL_API_GETDIAGFIELD = TRUE
SQL_API_GETDIAGFIELDW = TRUE
SQL_API_GETDIAGREC = TRUE
SQL_API_GETDIAGRECW = TRUE
SQL_API_GETENVATTR = TRUE
SQL_API_GETFUNCTIONS = TRUE
SQL_API_GETINFO = TRUE
SQL_API_GETINFOW = TRUE
SQL_API_GETLENGTH = TRUE
SQL_API_GETPOSITION = TRUE
SQL_API_GETPOSITIONW = TRUE
SQL_API_GETSTMTATTR = TRUE
SQL_API_GETSTMTATTRW = TRUE
SQL_API_GETSTMTOPTION = TRUE
SQL_API_GETSTMTOPTIONW = TRUE
SQL_API_GETSUBSTRING = TRUE
SQL_API_GETSUBSTRINGW = TRUE
SQL_API_GETTYPEINFO = TRUE
SQL_API_GETTYPEINFOW = TRUE
SQL_API_LANGUAGES = TRUE
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetInfoW(). Refer to “Unicode in Db2 for i CLI” on page 283 for
more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
Table 95 on page 143 lists the possible values of fInfoType and a description of the information that
SQLGetInfo() returns for that value.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Function arguments
Usage
SQLGetLength() can be used to determine the length of the data value represented by a LOB locator. It
is used by applications to determine the overall length of the referenced LOB value so that the
appropriate strategy to obtain some or all of the LOB value can be chosen.
The Locator argument can contain any valid LOB locator which has not been explicitly freed using a FREE
LOCATOR statement nor implicitly freed because the transaction during which it is created has
terminated.
The statement handle must not have been associated with any prepared statements or catalog function
calls.
Db2 for i restricts the use of LOB locators when running with no isolation level.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Restrictions
This function is not available when connected to a DB2 server that does not support Large Objects.
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLFetch - Fetch next row” on page 100
• “SQLGetPosition - Return starting position of string” on page 158
• “SQLGetSubString - Retrieve portion of a string value” on page 164
The source and search LOB locators can be any that have been returned from the database from a fetch
or an SQLGetSubString() call during the current transaction.
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetPositionW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
SQLINTEGER FromPosition Input For BLOBs and CLOBs, this is the position of the
first byte within the source string at which the
search is to start. to be returned by the function.
For DBCLOBs, this is the first character. The start
byte or character is numbered 1.
1. This is in double byte characters for a call to the SQLGetPositionW API, but in bytes for a call to the
SQLGetPosition API for DBCLOB data.
Usage
SQLGetPosition() is used in conjunction with SQLGetSubString() in order to obtain any portion of a
string in a random manner. In order to use SQLGetSubString(), the location of the substring within the
overall string must be known in advance. In situations where the start of that substring can be found by a
search string, SQLGetPosition() can be used to obtain the starting position of that substring.
The Locator and SearchLocator (if used) arguments can contain any valid LOB locator which has not been
explicitly freed using a FREE LOCATOR statement or implicitly freed because the transaction during which
it is created has terminated.
The Locator and SearchLocator must have the same LOB locator type.
The statement handle must not have been associated with any prepared statements or catalog function
calls.
If a remote connection has been made, the CCSID of the CLOB data (SourceLocator) must be compatible
with the CCSID of the job executing the SQLGetSubString API, otherwise translation problems will occur.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
HY010 Function sequence error The specified StatementHandle argument is not in an allocated
state.
HY021 Internal descriptor that is not The internal descriptor cannot be addressed or allocated, or it
valid contains a value that is not valid.
HY090 String or buffer length that is The value of SearchLiteralLength is less than 1, and not
not valid SQL_NTS.
HYC00 Driver not capable The application is currently connected to a data source that
does not support large objects.
Restrictions
This function is not available when connected to a DB2 server that does not support Large Objects.
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLExtendedFetch - Fetch array of rows” on page 98
• “SQLFetch - Fetch next row” on page 100
• “SQLGetLength - Retrieve length of a string value” on page 156
• “SQLGetSubString - Retrieve portion of a string value” on page 164
These options are set using the SQLSetStmtAttr() function. This function is similar to
SQLGetStmtOption(). Both functions are supported for compatibility reasons.
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetStmtAttrW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Table 101. SQLGetStmtAttr arguments
Usage
SQL_ATTR_APP_PARAM_DESC Integer The descriptor handle used by the application to provide parameter values for this statement handle.
SQL_ATTR_APP_ROW_DESC Integer The descriptor handle for the application to retrieve row data using the statement handle.
SQL_ATTR_CURSOR_SCROLLABLE Integer A 32-bit integer value that specifies if cursors opened for this statement handle should be scrollable.
• SQL_FALSE – Cursors are not scrollable, and SQLFetchScroll() cannot be used against them.
• SQL_TRUE – Cursors are scrollable. SQLFetchScroll() can be used to retrieve data from these
cursors.
SQL_ATTR_CURSOR_TYPE Integer A 32-bit integer value that specifies the behavior of cursors opened for this statement handle.
• SQL_CURSOR_FORWARD_ONLY – Cursors are not scrollable, and SQLFetchScroll() cannot be
used against them.
• SQL_DYNAMIC – Cursors are scrollable. SQLFetchScroll() can be used to retrieve data from
these cursors.
SQL_ATTR_CURSOR_HOLD Integer Returns the HOLDABILITY for the cursor for the statement.
• SQL_FALSE – Cursor position is not held across transaction boundaries.
• SQL_TRUE – Cursor position is held across transaction boundaries.
SQL_ATTR_FOR_FETCH_ONLY Integer This indicates if cursors opened for this statement handle should be read-only.
• SQL_FALSE - Cursors can be used for positioned updates and deletes. This is the default.
• SQL_TRUE - Cursors are read-only and cannot be used for positioned updates or deletes.
SQL_ATTR_IMP_PARAM_DESC Integer The descriptor handle used by the CLI implementation to provide parameter values for this statement
handle.
SQL_ATTR_IMP_ROW_DESC Integer The descriptor handle used by the CLI implementation to retrieve row data using this statement
handle.
SQL_ATTR_ROWSET_SIZE Integer A 32–bit integer value that specifies the number of rows in the rowset. This is the number of rows
returned by each call to SQLExtendedFetch(). The default value is 1.
SQL_ATTR_PARAMSET_SIZE Integer Returns the number of rows for each multiple row statement. These include INSERT, MERGE, and
UPDATE statements.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA
Diagnostics
HYC00 Driver not capable Db2 for i CLI recognizes the option but does not
support it.
Syntax
Usage
SQLGetStmtOption() provides the same function as SQLGetStmtAttr(), both functions are
supported for compatibility reasons.
See Table 102 on page 162 for a list of statement options.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
HYC00 Driver not capable Db2 for i CLI recognizes the option but does not
support it.
References
“SQLGetStmtAttr - Get the value of a statement attribute” on page 161
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetSubStringW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
SQLRETURN SQLGetSubString (
SQLHSTMT StatementHandle,
SQLSMALLINT LocatorCType,
SQLINTEGER SourceLocator,
SQLINTEGER FromPosition,
SQLINTEGER ForLength,
SQLSMALLINT TargetCType,
SQLPOINTER DataPtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLength,
SQLINTEGER *IndicatorValue);
Function arguments
SQLSMALLINT TargetCType input The C data type of the DataPtr. The target
must be a C string variable (SQL_C_CHAR,
SQL_C_WCHAR, SQL_C_BINARY, or
SQL_C_DBCHAR).
SQLPOINTER DataPtr output Pointer to the buffer where the retrieved
string value or a LOB locator is to be stored.
SQLINTEGER BufferLength input Maximum size of the buffer pointed to by
DataPtr in bytes.
Usage
SQLGetSubString() is used to obtain any portion of the string that is represented by the LOB locator.
There are two choices for the target:
• The target can be an appropriate C string variable.
• A new LOB value can be created on the server and the LOB locator for that value can be assigned to a
target application variable on the client.
SQLGetSubString() can be used as an alternative to SQLGetData() for getting data in pieces. In this
case a column is first bound to a LOB locator, which is then used to fetch the LOB as a whole or in pieces.
The Locator argument can contain any valid LOB locator which has not been explicitly freed using a FREE
LOCATOR statement nor implicitly freed because the transaction during which it is created has
terminated.
The statement handle must not have been associated with any prepared statements or catalog function
calls.
If a locator entry exists in the locator table but has no data, SQLGetSubString() will return an
SQL_NO_DATA return code.
If a remote connection has been made, the CCSID of the CLOB data (SourceLocator) must be compatible
with the CCSID of the job executing the SQLGetSubString API, otherwise translation problems will occur.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA
Error conditions
22011 Substring error occurred FromPosition is greater than the length of the source string.
58004 Unexpected system failure Unrecoverable system error.
HY003 Program type out of range LocatorCType is not one of SQL_C_CLOB_LOCATOR,
SQL_C_BLOB_LOCATOR, or SQL_C_DBCLOB_LOCATOR.
HY009 Argument value that is not The value specified for FromPosition or ForLength is not a
valid positive integer.
The argument DataPtr, StringLength, or IndicatorValue is a null
pointer
HY010 Function sequence error The specified StatementHandle is not in an allocated state.
HY021 Internal descriptor that is not The internal descriptor cannot be addressed or allocated, or it
valid contains a value that is not valid.
HY090 String or buffer length that is The value of BufferLength is less than 0.
not valid
HYC00 Driver not capable The application is currently connected to a data source that
does not support large objects.
0F001 No locator currently assigned The value specified for Locator is not currently a LOB locator.
Restrictions
This function is not available when connected to a DB2 server that does not support Large Objects.
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLFetch - Fetch next row” on page 100
• “SQLGetData - Get data from a column” on page 128
• “SQLGetLength - Retrieve length of a string value” on page 156
• “SQLGetPosition - Return starting position of string” on page 158
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLGetTypeInfoW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Function arguments
Usage
Because SQLGetTypeInfo() generates a result set and is equivalent to executing a query, it generates a
cursor and begins a transaction. To prepare and process another statement on this statement handle, the
cursor must be closed.
If SQLGetTypeInfo() is called with a DataType that is not valid, an empty result set is returned.
The columns of the result set that is generated by this function are described below.
8 CASE_SENSITIVE SMALLINT NOT NULL This indicates whether the data type can be treated
as case sensitive for collation purposes; valid values
are SQL_TRUE and SQL_FALSE.
9 SEARCHABLE SMALLINT NOT NULL This indicates how the data type is used in a WHERE
clause. Valid values are:
• SQL_UNSEARCHABLE – if the data type cannot be
used in a WHERE clause.
• SQL_LIKE_ONLY – if the data type can be used in a
WHERE clause only with the LIKE predicate.
• SQL_ALL_EXCEPT_LIKE – if the data type can be
used in a WHERE clause with all comparison
operators except LIKE.
• SQL_SEARCHABLE – if the data type can be used
in a WHERE clause with any comparison operator.
10 UNSIGNED_ATTRIBUTE SMALLINT This indicates where the data type is unsigned. The
valid values are: SQL_TRUE, SQL_FALSE or NULL. A
NULL indicator is returned if this attribute is not
applicable to the data type.
11 FIXED_PREC_SCALE SMALLINT NOT NULL This contains the value SQL_TRUE if the data type is
exact numeric and always has the same precision
and scale; otherwise, it contains SQL_FALSE.
12 AUTO_UNIQUE_VAL SMALLINT This contains SQL_TRUE if a column of this data type
is automatically set to a unique value when a row is
inserted; otherwise, contains SQL_FALSE.
13 LOCAL_TYPE_NAME VARCHAR(128) This column contains any localized name for the
data type that is different from the regular name of
the data type. If there is no localized name, this
column is NULL.
This column is intended for display only. The
character set of the string is locale-dependent and is
typically the default character set of the database.
14 MINIMUM_SCALE INTEGER The minimum scale of the SQL data type. If a data
type has a fixed scale, the MINIMUM_SCALE and
MAXIMUM_SCALE columns both contain the same
value. NULL is returned where scale is not
applicable.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
HY021 Internal descriptor that is not The internal descriptor cannot be addressed or allocated, or it
valid contains a value that is not valid.
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
if ( rc != SQL_NO_DATA_FOUND )
CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLGetInfo - Get general information” on page 142
Syntax
Function arguments
Usage
The function returns dialect and conformance information, in the form of a result set on
StatementHandle. This contains a row for every conformance claim the SQL product makes (including
subsets defined for ISO and vendor-specific versions). For a product that claims to comply with this
specification, the result set thus contains at least one row.
Rows defining ISO standard and vendor-specific languages can exist in the same table. Each row has at
least these columns and, if it makes an X/Open SQL conformance claim, the columns contains these
values.
Return codes
• SQL_SUCCESS
Diagnostics
Syntax
Function arguments
Usage
This function is used to return multiple results that are set in a sequential manner upon the processing of
a stored procedure that contains SQL queries. The cursors have been left open so that the result sets
remain accessible when the stored procedure has finished processing.
After completely processing the first result set, the application can call SQLMoreResults() to
determine if another result set is available. If the current result set has unfetched rows,
SQLMoreResults() discards them by closing the cursor and, if another result set is available, returns
SQL_SUCCESS.
If all the result sets have been processed, SQLMoreResults() returns SQL_NO_DATA_FOUND.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
Error conditions
Restrictions
The ODBC specification of SQLMoreResults() also allow counts associated with the processing of
parameterized INSERT, UPDATE, and DELETE statements with arrays of input parameter values to be
returned. However, Db2 for i CLI does not support the return of such count information.
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLBindParameter - Bind a parameter marker to a buffer” on page 48
Syntax
Function arguments
Usage
This function is called when the application wants to examine or display the transformed SQL string that
is passed to the data source by Db2 for i CLI. Translation (mapping) only occurs if the input SQL statement
string contains vendor escape clause sequences.
There are no vendor escape sequences on the IBM i operating system; this function is provided for
compatibility purposes. Also, note that this function can be used to evaluate an SQL string for syntax
errors.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Restrictions
None.
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
SQLNumParams(hstmt, &pcPar);
CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
Syntax
Function arguments
Usage
This function is used to associate the next result set from StatementHandle with NextResultHandle. This
differs from SQLMoreResults() because it allows both statement handles to process their result sets
simultaneously.
If all the result sets have been processed, SQLNextResult() returns SQL_NO_DATA_FOUND.
If SQLFreeStmt() is called with the SQL_CLOSE or SQL_DROP option, all pending result sets on this
statement handle are discarded.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NO_DATA_FOUND
Error conditions
References
“SQLMoreResults - Determine whether there are more result sets” on page 174
Syntax
Function arguments
Usage
This function can only be called after the statement that is associated with StatementHandle has been
prepared. If the statement does not contain any parameter markers, ParameterCountPtr is set to 0.
An application can call this function to determine how many SQLBindParameter() calls are necessary
for the SQL statement associated with the statement handle.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
HY013 Unexpected memory handling Db2 for i CLI is unable to access memory required to support
error the processing or completion of the function.
HYT00 Timeout expired
Restrictions
None.
Example
Refer to the example in “SQLNativeSql - Get native SQL text” on page 175.
References
• “SQLBindParam - Bind a buffer to a parameter marker” on page 43
• “SQLPrepare - Prepare a statement” on page 184
Syntax
Function arguments
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLColAttributes - Obtain column attributes” on page 65
• “SQLDescribeCol - Describe column attributes” on page 79
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLGetCol - Retrieve one column of a row of the result set” on page 117
• “SQLPrepare - Prepare a statement” on page 184
Syntax
Usage
SQLParamData() returns SQL_NEED_DATA if there is at least one SQL_DATA_AT_EXEC parameter for
which data still has not been assigned. This function returns an application defined value in prgbValue
supplied by the application during the previous SQLBindParam() call. SQLPutData() is called one or
more times to send the parameter data. SQLParamData() is called to signal that all the data has been
sent for the current parameter and to advance to the next SQL_DATA_AT_EXEC parameter.
SQL_SUCCESS is returned when all the parameters have been assigned data values and the associated
statement has been processed successfully. If any errors occur during or before actual statement
processing, SQL_ERROR is returned.
If SQLParamData() returns SQL_NEED_DATA, then only SQLPutData() or SQLCancel() calls can be
made. All other function calls using this statement handle fail. In addition, all function calls referencing
the parent hdbc of hstmt fail if they involve changing any attribute or state of that connection. Those
following function calls on the parent hdbc are also not permitted:
• SQLAllocConnect()
• SQLAllocHandle()
• SQLAllocStmt()
• SQLSetConnectOption()
Should they be called during an SQL_NEED_DATA sequence, these functions return SQL_ERROR with
SQLSTATE of HY010 and the processing of the SQL_DATA_AT_EXEC parameters is not affected.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
• SQL_NEED_DATA
Diagnostics
SQLParamData() can return any SQLSTATE returned by the SQLExecDirect() and SQLExecute()
functions. In addition, the following diagnostics can also be generated:
Syntax
Function arguments
Usage
This function can be used with SQLBindParameter() to set up a multiple-row INSERT statement, or to
process UPDATE, DELETE, and MERGE statements with multiple sets of parameter values. It is assumed
that the storage containing the data which represents the parameters is allocated and available to CLI.
This data can be organized in a either a row-wise or a column-wise fashion. Row-wise binding is the term
used for the case where all the data for the first row is contiguous, followed by all the data for the next
row, and so on. Column-wise binding is used to describe the case where the data for each individual
parameter marker is contiguous. For this case, each parameter marker's data can be provided in an array
that does not need to be contiguous with data for the other parameter markers. The
SQLBindParameter() function should be used to bind all of the input parameter types and lengths.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
Restrictions
None.
References
• “SQLBindParam - Bind a buffer to a parameter marker” on page 43
• “SQLMoreResults - Determine whether there are more result sets” on page 174
If the statement handle has been used with a SELECT statement, SQLFreeStmt() must be called to
close the cursor, before calling SQLPrepare().
Syntax
Function arguments
Usage
As soon as a statement has been prepared using SQLPrepare(), the application can request information
about the format of the result set (if it is a SELECT statement) by calling:
• SQLNumResultCols()
• SQLDescribeCol()
• SQLColAttribute()
A prepared statement can be processed once, or multiple times by calling SQLExecute(). The SQL
statement remains associated with the statement handle until the handle is used with another
SQLPrepare(), SQLExecDirect(), SQLColumns(), SQLSpecialColumns(), SQLStatistics(), or
SQLTables().
The SQL statement string might contain parameter markers. A parameter marker is represented by a "?"
character, and indicates a position in the statement where the value of an application variable is to be
substituted, when SQLExecute() is called. SQLBindParam() is used to bind (or associate) an
application variable to each parameter marker, and to indicate if any data conversion should be
performed at the time the data is transferred.
The SQL statement cannot be a COMMIT or ROLLBACK. SQLTransact() must be called to issue
COMMIT or ROLLBACK.
If the SQL statement is a positioned DELETE or a Positioned UPDATE, the cursor referenced by the
statement must be defined on a separate statement handle under the same connection handle.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Note: Not all Database Management Systems (DBMSs) report all of the above diagnostic messages at
prepare time. Therefore an application must also be able to handle these conditions when calling
SQLExecute().
Example
Refer to “Example: Interactive SQL and the equivalent Db2 for i CLI function calls” on page 290 for a
listing of the check_error, initialize, and terminate functions used in the following example.
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*************************************************************************
** file = prepare.c
**
** Example of preparing then repeatedly executing an SQL statement.
**
** Functions used:
**
** SQLAllocConnect SQLFreeConnect
** SQLAllocEnv SQLFreeEnv
** SQLAllocStmt SQLFreeStmt
** SQLConnect SQLDisconnect
**
** SQLBindCol SQLFetch
** SQLTransact SQLError
** SQLPrepare SQLSetParam
** SQLExecute
**************************************************************************/
/*******************************************************************
** main
** - initialize
** - terminate
*******************************************************************/
int main()
{
SQLHENV henv;
SQLHDBC hdbc;
SQLCHAR sqlstmt[MAX_STMT_LEN + 1]="";
SQLRETURN rc;
rc = initialize(&henv, &hdbc);
if (rc == SQL_ERROR) return(terminate(henv, hdbc));
{SQLHSTMT hstmt;
SQLCHAR sqlstmt[]="SELECT deptname, location from org where division = ?";
SQLCHAR deptname[15],
location[14],
division[11];
SQLINTEGER rlength,
plength;
rc = SQLAllocStmt(hdbc, &hstmt);
if (rc != SQL_SUCCESS )
check_error (henv, hdbc, SQL_NULL_HSTMT, rc);
while(division[0] != 'q')
{
rc = SQLExecute(hstmt);
if (rc != SQL_SUCCESS )
check_error (henv, hdbc, hstmt, rc);
terminate(henv, hdbc);
return (0);
}/* end main */
References
• “SQLColAttributes - Obtain column attributes” on page 65
• “SQLDescribeCol - Describe column attributes” on page 79
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLExecute - Execute a statement” on page 96
• “SQLNumResultCols - Get number of result columns” on page 180
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLPrimaryKeysW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
SQLPrimaryKeys() returns the primary key columns from a single table. Search patterns cannot be
used to specify the schema qualifier or the table name.
The result set contains the columns that are listed in Table 131 on page 189, ordered by TABLE_CAT,
TABLE_SCHEM, TABLE_NAME, and ORDINAL_POSITION.
Because calls to SQLPrimaryKeys() in many cases map to a complex and, thus, expensive query
against the system catalog, they should be used sparingly, and the results saved rather than repeating
calls.
Although new columns might be added and the names of the existing columns might be changed in future
releases, the position of the current columns does not change.
Note: The column names used by Db2 for i CLI follow the X/Open CLI CAE specification style. The column
types, contents and order are identical to those defined for the SQLPrimaryKeys() result set in ODBC.
If the specified table does not contain a primary key, an empty result set is returned.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
Error conditions
Restrictions
None.
References
• “SQLForeignKeys - Get the list of foreign key columns” on page 107
• “SQLStatistics - Get index and statistics information for a base table” on page 242
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLProcedureColumnsW(). Refer to “Unicode in Db2 for i CLI” on
page 283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
Db2 for i CLI returns information about the input, input and output, and output parameters associated
with the stored procedure, but cannot return information about the descriptor for any result sets
returned.
SQLProcedureColumns() returns the information in a result set, ordered by PROCEDURE_CAT,
PROCEDURE_SCHEM, PROCEDURE_NAME, and COLUMN_TYPE. Table 134 on page 192 lists the columns
in the result set. Applications should be aware that columns beyond the last column might be defined in
future releases.
Because calls to SQLProcedureColumns() in many cases map to a complex and thus expensive query
against the system catalog, they should be used sparingly, and the results saved rather than repeating
calls.
Special support was added to handle a keyword "*LIBL" in the SchemaName argument. Specifying this
keyword will tell SQLStatistics to use the schema's on the library list to qualify the search criteria for
retrieving index information for tables. The highest library on the library list hierarchy that matches the
12 NULLABLE SMALLINT not NULL 'SQL_NO_NULLS' if the parameter does not accept
NULL values.
'SQL_NULLABLE' if the parameter accepts NULL
values.
15 SQL_DATA_TYPE SMALLINT not NULL The value of the SQL data type as it appears in the
SQL_DESC_TYPE field of the descriptor. This
column is the same as the DATA_TYPE column
except for datetime data types (Db2 for i CLI does
not support interval data types).
For datetime data types, the SQL_DATA_TYPE field
in the result set is SQL_DATETIME, and the
SQL_DATETIME_SUB field returns the subcode for
the specific datetime data type (SQL_CODE_DATE,
SQL_CODE_TIME or SQL_CODE_TIMESTAMP).
16 SQL_DATETIME_SUB SMALLINT The subtype code for datetime data types. For all
other data types this column returns a NULL
(including interval data types which Db2 for i CLI
does not support).
17 CHAR_OCTET_LENGTH INTEGER The maximum length in bytes of a character data
type column. For all other data types, this column
returns a NULL.
18 ORDINAL_POSITION INTEGER not NULL This contains the ordinal position of the parameter
given by COLUMN_NAME in this result set. This is
the ordinal position of the argument to be provided
on the CALL statement. The leftmost argument has
an ordinal position of 1.
19 IS_NULLABLE VARCHAR(3) • “NO” if the column does not include NULLs.
• “YES” if the column can include NULLs.
• zero-length string if nullability is unknown.
ISO rules are followed to determine nullability.
An ISO SQL-compliant DBMS cannot return an
empty string.
The value returned for this column is different than
the value returned for the NULLABLE column. (See
the description of the NULLABLE column.)
Return codes
• SQL_SUCCESS
Error conditions
Restrictions
SQLProcedureColumns() does not return information about the attributes of result sets that can be
returned from stored procedures.
If an application is connected to a DB2 server that does not provide support for a stored procedure
catalog, or does not provide support for stored procedures, SQLProcedureColumns() returns an empty
result set.
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
References
“SQLProcedures - Get list of procedure names” on page 196
The information is returned in an SQL result set, which can be retrieved using the same functions that are
used to process a result set that is generated by a query.
Syntax
Function arguments
Usage
The result set returned by SQLProcedures() contains the columns listed in Table 137 on page 197 in
the order given. The rows are ordered by PROCEDURE_CAT, PROCEDURE_SCHEMA, and
PROCEDURE_NAME.
Because calls to SQLProcedures() in many cases map to a complex and thus expensive query against
the system catalog, use them sparingly, and save the results rather than repeating calls.
Although new columns might be added and the names of the existing columns might be changed in future
releases, the position of the current columns does not change.
Note: The column names used by Db2 for i CLI follow the X/Open CLI CAE specification style. The column
types, contents and order are identical to those defined for the SQLProcedures() result set in ODBC.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Error conditions
Restrictions
If an application is connected to a DB2 server that does not provide support for a stored procedure
catalog, or does not provide support for stored procedures, SQLProcedureColumns() returns an empty
result set.
Example
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
References
“SQLProcedureColumns - Get input/output parameter information for a procedure” on page 190
Syntax
Function arguments
Usage
The application calls SQLPutData() after calling SQLParamData() on a statement in the
SQL_NEED_DATA state to supply the data values for an SQL_DATA_AT_EXEC parameter. Long data can
be sent in pieces through repeated calls to SQLPutData(). After all the pieces of data for the parameter
have been sent, the application again calls SQLParamData(). SQLParamData(). proceeds to the next
SQL_DATA_AT_EXEC parameter, or, if all parameters have data values, executes the statement.
SQLPutData() cannot be called more than once for a fixed length parameter.
After an SQLPutData() call, the only legal function calls are SQLParamData(), SQLCancel(), or
another SQLPutData() if the input data is character or binary data. As with SQLParamData(), all other
function calls using this statement handle fail. In addition, all function calls referencing the parent hdbc of
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Some of the following diagnostics conditions might be reported on the final SQLParamData() call rather
than at the time the SQLPutData() is called.
HY010 Function sequence error The statement handle hstmt must be in a need data
state and must have been positioned on an
SQL_DATA_AT_EXEC parameter through a
previous SQLParamData() call.
Syntax
Function arguments
Usage
If this function is called when there is still a valid connection handle, SQL_ERROR is returned, and the
environment handle remains valid.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Example
Refer to the example in the “SQLAllocEnv - Allocate environment handle” on page 27.
References
“SQLFreeConnect - Free connection handle” on page 112
Syntax
Function arguments
Usage
If the last processed statement referenced by the input statement handle is not an SELECT from INSERT,
UPDATE, INSERT, MERGE, or DELETE statement, or if it is not processed successfully, then the function
sets the contents of pcrow to 0.
Any rows in other tables that might have been affected by the statement (for example, cascading deletes)
are not included in the count.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
References
• “SQLExecDirect - Execute a statement directly” on page 94
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLSetConnectAttrW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for Db2 for iCLI.
Syntax
Function arguments
Usage
All connection and statement options set through the SQLSetConnectAttr() persist until
SQLFreeConnect() is called or the next SQLSetConnectAttr() call.
The format of information set through vParam depends on the specified fAttr. The option information can
be either a 32-bit integer or a pointer to a null-terminated character string.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
References
• “SQLSetConnectOption - Set connection option” on page 218
• “SQLSetStmtOption - Set statement option” on page 237
Syntax
Function arguments
Usage
The SQLSetConnectOption() provides many of the same attribute functions as
SQLSetConnectAttr() before V5R3. However, SQLSetConnectOption() has since been deprecated,
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
HYC00 Driver not capable The specified fOption is not supported by Db2 for i
CLI or the data source.
Given the specified fOptionvalue, the value
specified for the argument vParam is not
supported.
References
“SQLSetConnectAttr - Set a connection attribute” on page 204
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLSetCursorNameW(). Refer to “Unicode in Db2 for i CLI” on
page 283 for more information about Unicode support for Db2 for i CLI.
Syntax
Usage
Db2 for i CLI always generates and uses an internally generated cursor name when a SELECT statement is
prepared or executed directly. SQLSetCursorName() allows an application-defined cursor name to be
used in an SQL statement (a Positioned UPDATE or DELETE). Db2 for i CLI maps this name to an internal
name. SQLSetCursorName() must be called before an internal name is generated. The name remains
associated with the statement handle, until the handle is dropped. The name also remains after the
transaction has ended, but at this point SQLSetCursorName() can be called to set a different name for
this statement handle.
Cursor names must follow the following rules:
• All cursor names within the connection must be unique.
• Each cursor name must be less than or equal to 128 characters in length. Any attempt to set a cursor
name longer than 128 characters results in an SQL0504 error.
• Because a cursor name is considered an identifier in SQL, it must begin with an English letter (a-z, A-Z)
followed by any combination of digits (0-9), English letters or the underscore character (_).
• Unless the input cursor name is enclosed in double quotation marks, all leading and trailing blanks from
the input cursor name string are removed.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
HY010 Function sequence error The statement handle is not in allocated state.
SQLPrepare() or SQLExecDirect() is called
before SQLSetCursorName().
References
“SQLGetCursorName - Get cursor name” on page 125
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLSetDescFieldW(). Refer to “Unicode in Db2 for i CLI” on
page 283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
Instead of requiring an entire set of arguments like SQLSetDescRec(), SQLSetDescField() specifies
which attribute you want to set for a specific descriptor record.
Although SQLSetDescField() allows for future extensions, it requires more calls to set the same
information than SQLSetDescRec() for each descriptor record.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Syntax
Function arguments
Usage
Calling SQLSetDescRec() sets all the fields in a descriptor record in one call.
Diagnostics
References
• “SQLBindCol - Bind a column to an application variable” on page 32
• “SQLDescribeCol - Describe column attributes” on page 79
• “SQLExecDirect - Execute a statement directly” on page 94
• “SQLExecute - Execute a statement” on page 96
• “SQLPrepare - Prepare a statement” on page 184
Syntax
An environment attribute cannot be set if a connection handle has been allocated. In order for the
attribute to apply to the entire CLI environment, the environment attributes must be in place before this
initial connection is made. An HY010 error code is returned otherwise.
Function arguments
Usage
In environments where the current application may exist in the same job as other applications using CLI,
connections attributes should be used instead of environment attributes. Otherwise, setting environment
attributes may cause the other application to behave unexpectedly. Ideally, the only environment
attributes that should be used are SQL_ATTR_ENVHNDL_COUNTER and SQL_ATTR_SERVER_MODE.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Syntax
References
“SQLBindParameter - Bind a parameter marker to a buffer” on page 48
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLSetStmtAttrW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Usage
Statement options for an hstmt remain in effect until they are changed by another call to
SQLSetStmtAttr() or the hstmt is dropped by calling SQLFreeStmt() with the SQL_DROP option.
Calling SQLFreeStmt() with the SQL_CLOSE, SQL_UNBIND, or SQL_RESET_PARAMS options does not
reset the statement options.
The format of information set through vParam depends on the specified fOption. The format of each is
noted in Table 161 on page 231.
Diagnostics
References
• “SQLFetchScroll - Fetch from a scrollable cursor” on page 105
• “SQLSetStmtOption - Set statement option” on page 237
SQLSetStmtOption() sets an attribute of a specific statement handle. To set an option for all
statement handles associated with a connection handle, the application can call
SQLSetConnectAttr(). See “SQLSetConnectAttr - Set a connection attribute” on page 204 for
additional details.
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLSetStmtOptionW(). Refer to “Unicode in Db2 for i CLI” on
page 283 for more information about Unicode support for DB2 CLI.
Function arguments
Table 163. SQLSetStmtOption arguments
Data type Argument Use Description
SQLHSTMT hstmt Input Statement handle.
SQLSMALLINT fOption Input Option to set. Refer to Table 161 on page 231 for the
list of settable statement options.
SQLPOINTER vParam Input Value associated with fOption. vParam can be a pointer
to a 32-bit integer value or a character string.
Usage
The SQLSetStmtOption() provides many of the same attribute functions as SQLSetStmtAttr()
before V5R3. However, it has since been deprecated, and support for all new attribute functions has gone
into SQLSetStmtAttr(). Users should migrate to the nondeprecated interface.
Statement options for an hstmt remain in effect until they are changed by another call to
SQLSetStmtOption() or the hstmt is dropped by calling SQLFreeStmt() with the SQL_DROP option.
Calling SQLFreeStmt() with the SQL_CLOSE, SQL_UNBIND, or SQL_RESET_PARAMS options does not
reset statement options.
The format of information set through vParam depends on the specified fOption. The format of each is
noted in Table 161 on page 231.
Refer to Table 161 on page 231 for the proper statement options.
Note: Because the SQLSetStmtOption() function has been deprecated, not all the options listed in the
table are supported."
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Table 164. SQLStmtOption SQLSTATEs
40003 * Statement The communication link between the CLI and the data source fails before the function
completion completes processing.
unknown
HY000 General error An error occurred for which there is no specific SQLSTATE and for which no
implementation defined SQLSTATE is defined. The error message returned by SQLError
in the argument szErrorMsg describes the error and its cause.
HY001 Memory The driver is unable to allocate memory required to support the processing or
allocation failure completion of the function.
HY009 Argument value Given the specified fOption value, a value that is not valid is specified for the argument
that is not valid vParam.
A fOption that is not valid value is specified.
The argument szSchemaName or szTableName is a null pointer.
HYC00 Driver not The driver or the data sources does not support the specified option.
capable
References
• “SQLSetConnectAttr - Set a connection attribute” on page 204
• “SQLSetStmtAttr - Set a statement attribute” on page 230
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLSpecialColumnsW(). Refer to “Unicode in Db2 for i CLI” on
page 283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
If multiple ways exist to uniquely identify any row in a table (for example, if there are multiple unique
indexes on the specified table), then Db2 for i CLI returns the best set of row identifier columns based on
its internal criterion.
If there is no column set that allows any row in the table to be uniquely identified, an empty result set is
returned.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLStatisticsW(). Refer to “Unicode in Db2 for i CLI” on page
283 for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Usage
SQLStatistics() returns the following types of information:
• Statistics information for the table (if available):
– When the TYPE column in the following table is set to SQL_TABLE_STAT, the number of rows in the
table and the number of pages used to store the table.
– When the TYPE column indicates an index, the number of unique values in the index, and the number
of pages used to store the indexes.
– Information about each index, where each index column is represented by one row of the result set.
The result set columns are given in the following table in the order shown; the rows in the result set
are ordered by NON_UNIQUE, TYPE, INDEX_QUALIFIER, INDEX_QUALIFIER, INDEX_NAME and
ORDINAL_POSITION.
For the row in the result set that contains table statistics (TYPE is set to SQL_TABLE_STAT), the columns
values of NON_UNIQUE, INDEX_QUALIFIER, INDEX_NAME, ORDINAL_POSITION, COLUMN_NAME, and
COLLATION are set to NULL. If the CARDINALITY or PAGES information cannot be determined, then NULL
is returned for those columns.
If argument szSchemaName is not specified, the schema name qualifier defaults to the one currently in
effect for the current connection.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Syntax
Usage
The results are returned as a standard result set containing the columns listed in the following table. The
result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, and PRIVILEGE. If multiple privileges
are associated with any given table, each privilege is returned as a separate row.
The granularity of each privilege reported here might or might not apply at the column level; for example,
for some data sources, if a table can be updated, every column in that table can also be updated. For
other data sources, the application must call SQLColumnPrivileges() to discover if the individual
columns have the same table privileges.
Because calls to SQLColumnPrivileges() in many cases map to a complex and thus expensive query
against the system catalog, they should be used sparingly, and the results saved rather than repeating
calls.
The VARCHAR columns of the catalog functions result set have been declared with a maximum length
attribute of 128 to be consistent with SQL92 limits. Because DB2 names are always 128 characters or
less , the application may choose to always set aside 128 characters (plus the null-terminator) for the
output buffer, or alternatively, call SQLGetInfo() with SQL_MAX_CATALOG_NAME_LEN,
SQL_MAX_SCHEMA_NAME_LEN, SQL_MAX_TABLE_NAME_LEN, and SQL_MAX_COLUMN_NAME_LEN.
The SQL_MAX_CATALOG_NAME_LEN value determines the actual length of the TABLE_CAT supported by
the connected DBMS. The SQL_MAX_SCHEMA_NAME_LEN value determines the actual length of the
TABLE_SCHEM supported by the connected Database Management System (DBMS). The
SQL_MAX_TABLE_NAME_LEN value determines the actual length of the TABLE_NAME supported by the
connected DBMS. The SQL_MAX_COLUMN_NAME_LEN value determines the actual length of the
COLUMN_NAME supported by the connected DBMS.
Although new columns can be added and the names of the existing columns changed in future releases,
the position of the current columns does not change.
Note: The column names used by Db2 for i CLI follow the X/Open CLI CAE specification style. The column
types, contents and order are identical to those defined for the SQLProcedures() result set in ODBC.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
Restrictions
None.
Example
/* call SQLTablePrivileges */
printf("\n Call SQLTablePrivileges for:\n");
printf(" tbSchemaPattern = %s\n", tbSchemaPattern);
printf(" tbNamePattern = %s\n", tbNamePattern);
sqlrc = SQLTablePrivileges( hstmt, NULL, 0,
tbSchemaPattern, SQL_NTS,
tbNamePattern, SQL_NTS);
STMT_HANDLE_CHECK( hstmt, sqlrc);
Unicode (UTF-16) equivalent: This function can also be used with the Unicode (UTF-16) character set.
The corresponding Unicode function is SQLTablesW(). Refer to “Unicode in Db2 for i CLI” on page 283
for more information about Unicode support for DB2 CLI.
Syntax
Function arguments
Note: The szCatalogName, szSchemaName, and szTableName arguments accept search patterns.
An escape character can be specified in conjunction with a wildcard character to allow that actual
character to be used in the search pattern. The escape character is specified on the
SQL_ATTR_ESCAPE_CHAR environment attribute. Use of SQL_ATTR_ESCAPE_CHAR will be deprecated in
a future release. Support for the SQL_ATTR_ESCAPE_CHAR value is only honored if the connection
attribute SQL_ATTR_OLD_MTADTA_BEHAVIOR is set to SQL_TRUE.
Usage
Table information is returned in a result set where each table is represented by one row of the result set.
To support obtaining just a list of schemas, the following special semantics for the szSchemaName
argument can be applied: if szSchemaName is a string containing a single percent (%) character, and
cbCatalogName, szTableName, and szTableType are empty strings, then the result set contains a list of
non-duplicate schemas in the data source.
The result set returned by SQLTables() contains the columns listed in the following table in the order
given.
Return codes
• SQL_SUCCESS
• SQL_SUCCESS_WITH_INFO
• SQL_ERROR
• SQL_INVALID_HANDLE
Diagnostics
All changes to the database that have been made on the connection since connect time or the previous
call to SQLTransact() (whichever is the most recent) are committed or rolled back.
If a transaction is active on a connection, the application must call SQLTransact() before it can be
disconnected from the database.
Function arguments
Usage
Completing a transaction with SQL_COMMIT or SQL_ROLLBACK has the following effects:
• Statement handles are still valid after a call to SQLTransact().
• Cursor names, bound parameters, and column bindings survive transactions.
• Open cursors are closed, and any result sets that are pending retrieval are discarded.
Completing the transaction with SQL_COMMIT_HOLD or SQL_ROLLBACK_HOLD still commits or rolls
back the database changes, but does not cause cursors to be closed.
If no transaction is currently active on the connection, calling SQLTransact() has no effect on the
database server and returns SQL_SUCCESS.
SQLTransact() might fail while executing the COMMIT or ROLLBACK due to a loss of connection. In this
case the application might be unable to determine whether the COMMIT or ROLLBACK has been
processed, and a database administrator's help might be required. Refer to the DBMS product information
for more information about transaction logs and other transaction management tasks.
Return codes
• SQL_SUCCESS
• SQL_ERROR
• SQL_INVALID_HANDLE
Example
#ifndef SQL_H_SQLCLI
#define SQL_H_SQLCLI /* Permit duplicate Includes */
#ifdef __ILEC400__
#pragma checkout(suspend)
#pragma nomargins nosequence
#else
#pragma info(none)
#endif
#ifndef __SQL_EXTERN
#ifdef __ILEC400__
#pragma argument (SQLAllocConnect , nowiden)
#pragma argument (SQLAllocEnv , nowiden)
#pragma argument (SQLAllocHandle , nowiden)
#pragma argument (SQLAllocStmt , nowiden)
#pragma argument (SQLBindCol , nowiden)
#pragma argument (SQLBindFileToCol , nowiden)
#pragma argument (SQLBindFileToParam , nowiden)
#pragma argument (SQLBindParam , nowiden)
#pragma argument (SQLBindParameter , nowiden)
#pragma argument (SQLCancel , nowiden)
#pragma argument (SQLCloseCursor , nowiden)
#pragma argument (SQLColAttribute , nowiden)
#pragma argument (SQLColAttributeW , nowiden)
#pragma argument (SQLColAttributes , nowiden)
#pragma argument (SQLColAttributesW , nowiden)
#pragma argument (SQLColumnPrivileges , nowiden)
#pragma argument (SQLColumnPrivilegesW , nowiden)
#pragma argument (SQLColumns , nowiden)
#pragma argument (SQLColumnsW , nowiden)
#pragma argument (SQLConnect , nowiden)
#pragma argument (SQLConnectW , nowiden)
#pragma argument (SQLCopyDesc , nowiden)
#pragma argument (SQLDataSources , nowiden)
#pragma argument (SQLDataSourcesW , nowiden)
#pragma argument (SQLDescribeCol , nowiden)
#pragma argument (SQLDescribeColW , nowiden)
#pragma argument (SQLDescribeParam , nowiden)
#pragma argument (SQLDisconnect , nowiden)
#pragma argument (SQLDriverConnect , nowiden)
#pragma argument (SQLDriverConnectW , nowiden)
#pragma argument (SQLEndTran , nowiden)
#pragma argument (SQLError , nowiden)
#pragma argument (SQLErrorW , nowiden)
#pragma argument (SQLExecDirect , nowiden)
#pragma argument (SQLExecDirectW , nowiden)
#pragma argument (SQLExecute , nowiden)
#pragma argument (SQLExecuteW , nowiden)
#pragma argument (SQLExtendedFetch , nowiden)
#pragma argument (SQLFetch , nowiden)
#pragma argument (SQLFetchScroll , nowiden)
#pragma argument (SQLForeignKeys , nowiden)
#pragma argument (SQLForeignKeysW , nowiden)
#pragma argument (SQLFreeConnect , nowiden)
#pragma argument (SQLFreeEnv , nowiden)
#pragma argument (SQLFreeHandle , nowiden)
#pragma argument (SQLFreeStmt , nowiden)
#pragma argument (SQLGetCol , nowiden)
#pragma argument (SQLGetColW , nowiden)
#pragma argument (SQLGetConnectOption , nowiden)
#pragma argument (SQLGetConnectOptionW , nowiden)
#pragma argument (SQLGetCursorName , nowiden)
#pragma argument (SQLGetCursorNameW , nowiden)
#pragma argument (SQLGetConnectAttr , nowiden)
#pragma argument (SQLGetConnectAttrW , nowiden)
#pragma argument (SQLGetData , nowiden)
#pragma argument (SQLGetDescField , nowiden)
#pragma argument (SQLGetDescFieldW , nowiden)
#pragma argument (SQLGetDescRec , nowiden)
#pragma argument (SQLGetDescRecW , nowiden)
#pragma argument (SQLGetDiagField , nowiden)
#pragma argument (SQLGetDiagFieldW , nowiden)
#pragma argument (SQLGetDiagRec , nowiden)
#pragma argument (SQLGetDiagRecW , nowiden)
#pragma argument (SQLGetEnvAttr , nowiden)
#pragma argument (SQLGetFunctions , nowiden)
/* RETCODE values */
/* Note: The return codes will reflect the XA return code specifications,
when using CLI to execute XA transactions (use of the
SQLSetConnectAttr - SQL_ATTR_TXN_INFO attribute).
The XA return codes can be found in the XA.h include file. @D3A*/
#define SQL_SUCCESS 0
#define SQL_SUCCESS_WITH_INFO 1
#define SQL_NO_DATA_FOUND 100
#define SQL_NEED_DATA 99
#define SQL_NO_DATA SQL_NO_DATA_FOUND
#define SQL_ERROR -1
#define SQL_INVALID_HANDLE -2
#define SQL_STILL_EXECUTING 2
/* SQLSetParam defines */
#define SQL_C_DEFAULT 99
#define SQL_LOCK_TYPES -1
#define SQL_POS_OPERATIONS -1
#define SQL_CB_DELETE 1
#define SQL_CB_CLOSE 2
#define SQL_CB_PRESERVE 3
/*
* Output values for SQL_ODBC_API_CONFORMANCE
* info type in SQLGetInfo
*/
#define SQL_OAC_NONE 0 /* @C1A*/
#define SQL_OAC_LEVEL1 1 /* @C1A*/
#define SQL_OAC_LEVEL2 2 /* @C1A*/
/*
* Output values for SQL_ODBC_SQL_CONFORMANCE
* info type in SQLGetInfo
*/
#define SQL_OSC_MINIMUM 0 /* @C1A*/
#define SQL_OSC_CORE 1 /* @C1A*/
#define SQL_OSC_EXTENDED 2 /* @C1A*/
/*
* Output values for SQL_QUALIFIER_USAGE
* info type in SQLGetInfo
/*
* Output values for SQL_QUALIFIER_LOCATION
* info type in SQLGetInfo
*/
#define SQL_QL_START 1 /* @C1A*/
#define SQL_QL_END 2 /* @C1A*/
/*
* Output values for SQL_OWNER_USAGE
* info type in SQLGetInfo
*/
#define SQL_OU_DML_STATEMENTS 0x00000001 /* @C1A*/
#define SQL_OU_PROCEDURE_INVOCATION 0x00000002 /* @C1A*/
#define SQL_OU_TABLE_DEFINITION 0x00000004 /* @C1A*/
#define SQL_OU_INDEX_DEFINITION 0x00000008 /* @C1A*/
#define SQL_OU_PRIVILEGE_DEFINITION 0x00000010 /* @C1A*/
/*
* Output values for SQL_TXN_CAPABLE
* info type in SQLGetInfo
*/
#define SQL_TC_NONE 0 /* @C1A*/
#define SQL_TC_DML 1 /* @C1A*/
#define SQL_TC_ALL 2 /* @C1A*/
#define SQL_TC_DDL_COMMIT 3 /* @C1A*/
#define SQL_TC_DDL_IGNORE 4 /* @C1A*/
/*
* Output values for SQL_DEFAULT_TXN_ISOLATION
* info type in SQLGetInfo
*/
#define SQL_TXN_READ_UNCOMMITTED_MASK 0x00000001 /* @C2A*/
#define SQL_TXN_READ_COMMITTED_MASK 0x00000002 /* @C2A*/
#define SQL_TXN_REPEATABLE_READ_MASK 0x00000004 /* @C2A*/
#define SQL_TXN_SERIALIZABLE_MASK 0x00000008 /* @C2A*/
/*
* Output values for SQL_STRING_FUNCTIONS
* info type in SQLGetInfo
*/
#define SQL_FN_STR_CONCAT 0x00000001
#define SQL_FN_STR_UCASE 0x00000002
#define SQL_FN_STR_LCASE 0x00000004
#define SQL_FN_STR_SUBSTRING 0x00000008
#define SQL_FN_STR_LENGTH 0x00000010
#define SQL_FN_STR_POSITION 0x00000020
#define SQL_FN_STR_LTRIM 0x00000040
#define SQL_FN_STR_RTRIM 0x00000080
/*
* Output values for SQL_POS_OPERATIONS
* info type in SQLGetInfo (not currently supported)
*/
#define SQL_POS_POSITION 0x00000001
#define SQL_POS_REFRESH 0x00000002
#define SQL_POS_UPDATE 0x00000004
#define SQL_POS_DELETE 0x00000008
#define SQL_POS_ADD 0x00000010
/*
* Output values for SQL_NUMERIC_FUNCTIONS
* info type in SQLGetInfo
*/
#define SQL_FN_NUM_ABS 0x00000001
#define SQL_FN_NUM_ACOS 0x00000002
#define SQL_FN_NUM_ASIN 0x00000004
#define SQL_FN_NUM_ATAN 0x00000008
#define SQL_FN_NUM_ATAN2 0x00000010
#define SQL_FN_NUM_CEILING 0x00000020
#define SQL_FN_NUM_COS 0x00000040
#define SQL_FN_NUM_COT 0x00000080
#define SQL_FN_NUM_EXP 0x00000100
/* SQL_SQL92_VALUE_EXPRESSIONS bitmasks */
#define SQL_SVE_CASE 0x00000001
#define SQL_SVE_CAST 0x00000002
#define SQL_SVE_COALESCE 0x00000004
#define SQL_SVE_NULLIF 0x00000008
/* SQL_SQL92_PREDICATES bitmasks */
#define SQL_SP_EXISTS 0x00000001
#define SQL_SP_ISNOTNULL 0x00000002
#define SQL_SP_ISNULL 0x00000004
#define SQL_SP_MATCH_FULL 0x00000008
#define SQL_SP_MATCH_PARTIAL 0x00000010
#define SQL_SP_MATCH_UNIQUE_FULL 0x00000020
#define SQL_SP_MATCH_UNIQUE_PARTIAL 0x00000040
#define SQL_SP_OVERLAPS 0x00000080
#define SQL_SP_UNIQUE 0x00000100
#define SQL_SP_LIKE 0x00000200
#define SQL_SP_IN 0x00000400
#define SQL_SP_BETWEEN 0x00000800
#define SQL_SP_COMPARISON 0x00001000
#define SQL_SP_QUANTIFIED_COMPARISON 0x00002000
/* SQL_AGGREGATE_FUNCTIONS bitmasks */
#define SQL_AF_AVG 0x00000001
#define SQL_AF_COUNT 0x00000002
#define SQL_AF_MAX 0x00000004
#define SQL_AF_MIN 0x00000008
#define SQL_AF_SUM 0x00000010
#define SQL_AF_DISTINCT 0x00000020
#define SQL_AF_ALL 0x00000040
/* SQL_SQL_CONFORMANCE bitmasks */
#define SQL_SC_SQL92_ENTRY 0x00000001
#define SQL_SC_FIPS127_2_TRANSITIONAL 0x00000002
#define SQL_SC_SQL92_INTERMEDIATE 0x00000004
#define SQL_SC_SQL92_FULL 0x00000008
/* SQL_CONVERT_FUNCTIONS functions */
#define SQL_FN_CVT_CONVERT 0x00000001
#define SQL_FN_CVT_CAST 0x00000002
/* SQL_POSITIONED_STATEMENTS bitmasks */
#define SQL_PS_POSITIONED_DELETE 0x00000001
#define SQL_PS_POSITIONED_UPDATE 0x00000002
#define SQL_PS_SELECT_FOR_UPDATE 0x00000004
/* SQL_TIMEDATE_FUNCTIONS bitmasks */
#define SQL_FN_TD_NOW 0x00000001
#define SQL_FN_TD_CURDATE 0x00000002
#define SQL_FN_TD_DAYOFMONTH 0x00000004
#define SQL_FN_TD_DAYOFWEEK 0x00000008
#define SQL_FN_TD_DAYOFYEAR 0x00000010
#define SQL_FN_TD_MONTH 0x00000020
#define SQL_FN_TD_QUARTER 0x00000040
#define SQL_FN_TD_WEEK 0x00000080
#define SQL_FN_TD_YEAR 0x00000100
#define SQL_FN_TD_CURTIME 0x00000200
#define SQL_FN_TD_HOUR 0x00000400
#define SQL_FN_TD_MINUTE 0x00000800
#define SQL_FN_TD_SECOND 0x00001000
#define SQL_FN_TD_TIMESTAMPADD 0x00002000
#define SQL_FN_TD_TIMESTAMPDIFF 0x00004000
#define SQL_FN_TD_DAYNAME 0x00008000
#define SQL_FN_TD_MONTHNAME 0x00010000
#define SQL_FN_TD_CURRENT_DATE 0x00020000
#define SQL_FN_TD_CURRENT_TIME 0x00040000
#define SQL_FN_TD_CURRENT_TIMESTAMP 0x00080000
#define SQL_FN_TD_EXTRACT 0x00100000
/*
* Output values for SQL_CORRELATION_NAME
* info type in SQLGetInfo
*/
#define SQL_CN_NONE 0 /* @C1A*/
#define SQL_CN_DIFFERENT 1 /* @C1A*/
#define SQL_CN_ANY 2 /* @C1A*/
/*
* Output values for SQL_IDENTIFIER_CASE
* info type in SQLGetInfo
*/
#define SQL_IC_UPPER 1 /* @C1A*/
#define SQL_IC_LOWER 2 /* @C1A*/
#define SQL_IC_SENSITIVE 3 /* @C1A*/
#define SQL_IC_MIXED 4 /* @C1A*/
/*
* Output values for SQL_NON_NULLABLE_COLUMNS
* info type in SQLGetInfo
*/
#define SQL_NNC_NULL 0 /* @C1A*/
#define SQL_NNC_NON_NULL 1 /* @C1A*/
/*
* Output values for SQL_GROUP_BY
* info type in SQLGetInfo
*/
#define SQL_GB_NO_RELATION 0 /* @C1A*/
#define SQL_GB_NOT_SUPPORTED 1 /* @C1A*/
#define SQL_GB_GROUP_BY_EQUALS_SELECT 2 /* @C1A*/
#define SQL_GB_GROUP_BY_CONTAINS_SELECT 3 /* @C1A*/
/*
* NULL status defines; these are used in SQLColAttributes, SQLDescribeCol,
* to describe the nullability of a column in a table.
*/
#define SQL_NO_NULLS 0
#define SQL_NULLABLE 1
#define SQL_NULLABLE_UNKNOWN 2
/* SQLColAttributes defines */
#define SQL_ATTR_READONLY 0
#define SQL_ATTR_WRITE 1
#define SQL_ATTR_READWRITE_UNKNOWN 2
/*
* Options for Rounding Modes. These numeric values can
* be set with SQLSetConnectAttr() API for the attribute
* SQL_ATTR_DECFLOAT_ROUNDING_MODE. The SQLGetConnectAttr()
* API will return these values for the
/* statement attributes */
#define SQL_ATTR_APP_ROW_DESC 10010
#define SQL_ATTR_APP_PARAM_DESC 10011
#define SQL_ATTR_IMP_ROW_DESC 10012
#define SQL_ATTR_IMP_PARAM_DESC 10013
#define SQL_ATTR_FOR_FETCH_ONLY 10014
#define SQL_ATTR_CONCURRENCY 10014
#define SQL_CONCURRENCY 10014
#define SQL_ATTR_CURSOR_SCROLLABLE 10015
#define SQL_ATTR_ROWSET_SIZE 10016
#define SQL_ROWSET_SIZE 10016
#define SQL_ATTR_ROW_ARRAY_SIZE 10016
#define SQL_ATTR_CURSOR_HOLD 10017
#define SQL_ATTR_FULL_OPEN 10018
#define SQL_ATTR_BIND_TYPE 10049
#define SQL_BIND_TYPE 10049
#define SQL_ATTR_CURSOR_TYPE 10050
#define SQL_CURSOR_TYPE 10050
#define SQL_ATTR_CURSOR_SENSITIVITY 10051 /* @D1A*/
#define SQL_CURSOR_SENSITIVE 10051 /* @D1A*/
#define SQL_ATTR_ROW_STATUS_PTR 10052 /* @D3A*/
#define SQL_ATTR_ROWS_FETCHED_PTR 10053 /* @D3A*/
#define SQL_ATTR_ROW_BIND_TYPE 10056 /* @E2A*/
#define SQL_ATTR_PARAM_BIND_TYPE 10057 /* @E2A*/
#define SQL_ATTR_PARAMSET_SIZE 10058 /* @E2A*/
#define SQL_ATTR_PARAM_STATUS_PTR 10059 /* @E2A*/
#define SQL_ATTR_PARAMS_PROCESSED_PTR 10060 /* @E2A*/
#define SQL_ATTR_NUMBER_RESULTSET_ROWS_PTR 10061 /* @E2A*/
/* SQLColAttributes defines */
#define SQL_DESC_COUNT 1
#define SQL_DESC_TYPE 2
#define SQL_DESC_LENGTH 3
#define SQL_DESC_LENGTH_PTR 4
#define SQL_DESC_PRECISION 5
#define SQL_DESC_SCALE 6
#define SQL_DESC_DATETIME_INTERVAL_CODE 7
#define SQL_DESC_NULLABLE 8
#define SQL_DESC_INDICATOR_PTR 9
#define SQL_DESC_DATA_PTR 10
#define SQL_DESC_NAME 11
#define SQL_DESC_UNNAMED 12
#define SQL_DESC_DISPLAY_SIZE 13
#define SQL_DESC_AUTO_INCREMENT 14
#define SQL_DESC_SEARCHABLE 15
#define SQL_DESC_UPDATABLE 16
#define SQL_DESC_BASE_COLUMN 17
#define SQL_DESC_BASE_TABLE 18
#define SQL_DESC_BASE_SCHEMA 19
#define SQL_DESC_LABEL 20
#define SQL_DESC_MONEY 21
#define SQL_DESC_TYPE_NAME 23 /* @D3A*/
#define SQL_DESC_ALLOC_TYPE 99
#define SQL_DESC_ALLOC_AUTO 1
#define SQL_DESC_ALLOC_USER 2
#define SQL_COLUMN_COUNT 1
#define SQL_COLUMN_TYPE 2
#define SQL_COLUMN_LENGTH 3
#define SQL_COLUMN_LENGTH_PTR 4
#define SQL_COLUMN_PRECISION 5
#define SQL_COLUMN_SCALE 6
#define SQL_COLUMN_DATETIME_INTERVAL_CODE 7
#define SQL_COLUMN_NULLABLE 8
#define SQL_COLUMN_INDICATOR_PTR 9
#define SQL_COLUMN_DATA_PTR 10
#define SQL_COLUMN_NAME 11
#define SQL_COLUMN_UNNAMED 12
#define SQL_COLUMN_DISPLAY_SIZE 13
#define SQL_COLUMN_AUTO_INCREMENT 14
#define SQL_COLUMN_SEARCHABLE 15
#define SQL_COLUMN_UPDATABLE 16
#define SQL_COLUMN_BASE_COLUMN 17
#define SQL_COLUMN_BASE_TABLE 18
#define SQL_COLUMN_BASE_SCHEMA 19
#define SQL_COLUMN_LABEL 20
#define SQL_COLUMN_MONEY 21
#define SQL_COLUMN_ALLOC_TYPE 99
#define SQL_COLUMN_ALLOC_AUTO 1
#define SQL_COLUMN_ALLOC_USER 2
/*
* SQLColAttributes defines
* These are also used by SQLGetInfo
*/
#define SQL_UNSEARCHABLE 0
#define SQL_LIKE_ONLY 1
#define SQL_ALL_EXCEPT_LIKE 2
#define SQL_SEARCHABLE 3
/* unsupported APIs */
#define SQL_API_SQLSETPOS -1
#ifdef __64BIT__
#if !defined(SDWORD)
typedef int SDWORD;
#endif
#if !defined(UDWORD)
typedef unsigned int UDWORD;
#endif
#else
#if !defined(SDWORD)
typedef long int SDWORD;
#endif
#if !defined(UDWORD)
typedef unsigned long int UDWORD;
#endif
#endif
#if !defined(UWORD)
typedef unsigned short int UWORD;
#endif
#if !defined(SWORD)
typedef signed short int SWORD;
#endif
/* This should be temporary until math.h makes the typedef's below permanent,
without the need of STDC_WANT_DEC_FP or IBM_DFP declaration. Without this
fix QCPIMPRT.c fails b/c it includes math.h w/out these declares
set. @E2A*/
#ifdef __64BIT__
typedef int SQLINTEGER;
typedef int HENV;
typedef int HDBC;
typedef int HSTMT;
typedef int HDESC;
typedef int SQLHANDLE;
#else
typedef long int SQLINTEGER;
/*
* DATE, TIME, and TIMESTAMP structures. These are for compatibility
* purposes only. When actually specifying or retrieving DATE, TIME,
* and TIMESTAMP values, character strings must be used.
*/
#define FAR
#define SQL_SQLSTATE_SIZE 5 /* size of SQLSTATE, not including
null terminating byte */
#define SQL_MAX_DSN_LENGTH 18 /* maximum data source name size */
#define SQL_MAX_ID_LENGTH 18 /* maximum identifier name size,
e.g. cursor names */
#define SQL_MAXLSTR 255 /* Maximum length of an LSTRING */
#define SQL_LVCHAROH 26 /* Overhead for LONG VARCHAR in */
/* record */
#define SQL_LOBCHAROH 312 /* Overhead for LOB in record */
#ifndef __ILEC400__
#pragma info(restore)
#endif
#endif /* SQL_H_SQLCLI */
EXAMPLE.
.
SQLAllocEnv(&henv);
long attr;
attr = SQL_TRUE
SQLSetEnvAttr(henv,SQL_ATTR_SERVER_MODE,&attr,0);
SQLAllocConnect(henv,&hdbc);
.
.
• The second way to set the server mode is using the Change Job (QWTCHGJB) API.
As soon as SQL server mode has been set, all SQL connections and SQL statements run in server mode.
There is no switching back and forth. The job, when in server mode, cannot start commitment control, and
cannot use Interactive SQL.
Related information
Application programming interfaces
Table 179. List of functions with both EBCIDIC and Unicode versions
Functions Functions (continued) Functions (continued)
SQLColAttributeW SQLColAttributesW SQLColumnPrivilegesW
SQLColumnsW SQLConnectW SQLDataSourcesW
SQLDescribeColW SQLDriverConnectW SQLErrorW
SQLExecDirectW SQLForeignKeysW SQLGetConnectAttrW
SQLGetConnectOptionW SQLGetCursorNameW SQLGetDescFieldW
SQLGetDescRecW SQLGetDiagFieldW SQLGetDiagRecW
SQLGetInfoW SQLGetPositionW SQLGetStmtAttrW
SQLGetStmtOptionW SQLGetSubStringW SQLGetTypeInfoW
SQLNativeSQLW SQLPrepareW SQLPrimaryKeysW
SQLProcedureColumnsW SQLProceduresW SQLSetConnectAttrW
SQLSetConnectOptionW SQLSetCursorNameW SQLSetDescFieldW
SQLSetStmtAttrW SQLSetStmtOptionW SQLSpecialColumnsW
SQLStatisticsW SQLTablePrivilegesW SQLTablesW
The syntax for a Db2 for i CLI Wide function is the same as the syntax for its corresponding EBCDIC
function, except that SQLCHAR parameters are defined as SQLWCHAR. Character buffers defined as
SQLPOINTER in the EBCDIC syntax can be defined as either SQLCHAR or SQLWCHAR in the Unicode
function. Refer to the EBCDIC version of the CLI Unicode functions for EBCDIC syntax details.
The SQL types SQL_WCHAR and SQL_WVARCHAR can be used to specify a buffer that contains Unicode
data. So, to specify a particular column or parameter marker containing Unicode data the application can
bind as SQL_WCHAR for fixed length character data or bind as SQL_WVARCHAR for varying length
character data. Since UTF-16 data is double byte character data the input and output lengths must take
this into account. Unicode functions that have arguments which are always character strings interpret
these arguments as the number of double byte characters. When the length might refer to string or non-
string data, the length will be interpreted as the number of bytes needed to store the data. For example,
the SQLGetInfoW()SQLGetInfoW() API accepts the input length as the number of bytes, while
SQLPrepareW() accepts the number of double byte character's.
Db2 for i CLI allows for the mixing of the Wide character API's and non-Wide character API's. Applications
must take into account that Unicode data can only be specified for the Wide API calls, and not the non-
Wide API calls. Most applications will probably want to commit to either running with Unicode encoding
or will choose to run with a non-Unicode character encoding since most data will be in a consistent
encoding. However, support does exist for mixing Unicode and non-Unicode calls in the same CLI
environment. Db2 for i CLI does restrict the mixing of Wide character API's and an environment with
UTF-8 support enabled. Enabling UTF-8 support is discussed in the next section.
Example: Embedded SQL and the equivalent Db2 for i CLI function calls
This example shows embedded statements in comments and the equivalent Db2 for i CLI function calls.
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*************************************************************************
** file = embedded.c
**
** Example of executing an SQL statement using CLI.
** The equivalent embedded SQL statements are shown in comments.
**
** Functions used:
**
** SQLAllocConnect SQLFreeConnect
** SQLAllocEnv SQLFreeEnv
** SQLAllocStmt SQLFreeStmt
** SQLConnect SQLDisconnect
**
** SQLBindCol SQLFetch
** SQLSetParam SQLTransact
** SQLError SQLExecDirect
**
**************************************************************************/
#include <stdio.h>
#include <string.h>
#include "sqlcli.h"
#ifndef NULL
#define NULL 0
#endif
int main ()
{
SQLINTEGER id;
SQLCHAR name[51];
SQLINTEGER namelen, intlen;
SQLSMALLINT scale;
scale = 0;
namelen = SQL_NTS;
/* Set up the second input parameter "name" */
SQLSetParam (hstmt, 2,
SQL_C_CHAR, SQL_VARCHAR,
50,
scale, (SQLPOINTER) name,
(SQLINTEGER *) &namelen);
/* EXEC SQL DECLARE c1 CURSOR FOR SELECT ID, NAME FROM NAMEID; */
/* EXEC SQL OPEN c1; */
/* The application doesn't specify "declare c1 cursor for" */
{
SQLCHAR select[] = "select ID, NAME from NAMEID";
if (SQLExecDirect (hstmt, select, SQL_NTS) != SQL_SUCCESS)
return (print_err (hdbc, hstmt));
}
return (0);
}
return(SQL_ERROR);
/*************************************************************************
** file = CLIXAEXMP1.c
**
** Example of a typical flow of work in an XA transaction using the CLI.
**
** XA Functions used:
**
** xa_open() -- Open an XA resource for use in a transaction
** xa_prepare() -- Prepare for commitment of work in the transaction
** xa_commit() -- Commit work done in the transaction
**
** CLI Functions used:
**
** SQLAllocHanle SQLBindParameter SQLDisconnect
** SQLError SQLExecute SQLFreeHandle
** SQLPrepare SQLSetConnectAttr SQLSetEnvAttr
**
** This example will:
** - Open the XA transaction manager
** - Open a CLI connection and start a transaction for it using SQL_TXN_CREATE
** - Do some commitable CLI work under this transaction
** - End the transaction on the first connection using SQL_TXN_END
** - Close the first CLI connection and open a second connection
** - Use the SQL_TXN_FIND option to find the previous transaction
** - Do more commitable work on this transaction and end the transaction
** - Use the XA APIs to prepare and commit the work
************************************************************************************/
#define _XA_PROTOTYPES
#define _MULTI_THREADED
#include <xa.h>
#include <stdio.h>
#include <string.h>
#include <sqlcli.h>
#include <time.h>
#include <stdlib.h>
/* Commit */
if (xaRc != XA_RDONLY) {
xaRc = xa_commit(&xid, mainRmid, TMNOFLAGS);
printf("xa_commit(xid, %d, TMNOFLAGS) = %d\n", mainRmid, xaRc);
}
else {
printf("xa_commit() skipped for read only TX\n");
}
Example: Interactive SQL and the equivalent Db2 for i CLI function calls
This example shows the processing of interactive SQL statements.
This example follows the flow described in “Writing a Db2 for i CLI application” on page 6.
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 295.
/*************************************************************************
** file = typical.c
**
** Example of executing interactive SQL statements, displaying result sets
** and simple transaction management.
**
** Functions used:
**
** SQLAllocConnect SQLFreeConnect
** SQLAllocEnv SQLFreeEnv
** SQLAllocStmt SQLFreeStmt
** SQLConnect SQLDisconnect
**
** SQLBindCol SQLFetch
** SQLDescribeCol SQLNumResultCols
** SQLError SQLRowCount
** SQLExecDirect SQLTransact
**
**************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "sqlcli.h"
/*******************************************************************
** main
** - initialize
** - start a transaction
** - get statement
** - another statement?
** - COMMIT or ROLLBACK
** - another transaction?
** - terminate
*******************************************************************/
int main()
{
SQLHENV henv;
SQLHDBC hdbc;
SQLCHAR sqlstmt[MAX_STMT_LEN + 1]="";
SQLCHAR sqltrans[sizeof("ROLLBACK")];
SQLRETURN rc;
rc = initialize(&henv, &hdbc);
if (rc == SQL_ERROR) return(terminate(henv, hdbc));
if (sqltrans[0] == 'c')
{
rc = SQLTransact (henv, hdbc, SQL_COMMIT);
if (rc == SQL_SUCCESS)
printf ("Transaction commit was successful\n");
else
check_error (henv, hdbc, SQL_NULL_HSTMT, rc);
}
if (sqltrans[0] == 'r')
{
rc = SQLTransact (henv, hdbc, SQL_ROLLBACK);
if (rc == SQL_SUCCESS)
printf ("Transaction roll back was successful\n");
else
check_error (henv, hdbc, SQL_NULL_HSTMT, rc);
}
terminate(henv, hdbc);
return (SQL_SUCCESS);
}/* end main */
/*******************************************************************
** process_stmt
** - allocates a statement handle
** - executes the statement
** - determines the type of statement
** - if there are no result columns, therefore non-select statement
** - if rowcount > 0, assume statement was UPDATE, INSERT, DELETE
** else
** - assume a DDL, or Grant/Revoke statement
** else
** - must be a select statement.
** - display results
** - frees the statement handle
*******************************************************************/
return (0);
}/* end process_stmt */
/*******************************************************************
** initialize
** - allocate environment handle
** - allocate connection handle
** - prompt for server, user id, & password
** - connect to server
*******************************************************************/
if (uid[0] == '\0')
{ rc = SQLConnect (*hdbc, server, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS);
if (rc != SQL_SUCCESS )
check_error (*henv, *hdbc, SQL_NULL_HSTMT, rc);
}
else
{ rc = SQLConnect (*hdbc, server, SQL_NTS, uid, SQL_NTS, pwd, SQL_NTS);
if (rc != SQL_SUCCESS )
check_error (*henv, *hdbc, SQL_NULL_HSTMT, rc);
}
}/* end initialize */
/*******************************************************************
** terminate
** - disconnect
** - free connection handle
** - free environment handle
*******************************************************************/
int terminate(SQLHENV henv,
SQLHDBC hdbc)
{
SQLRETURN rc;
/*******************************************************************
** display_results - displays the selected character fields
**
** - for each column
** - get column name
** - bind column
** - display column headings
** - fetch each row
** - if value truncated, build error message
** - if column null, set value to "NULL"
** - display row
** - print truncation message
** - free local storage
**
*******************************************************************/
void display_results(SQLHSTMT hstmt,
SQLSMALLINT nresultcols)
{
SQLCHAR colname[32];
SQLSMALLINT coltype[MAXCOLS];
SQLSMALLINT colnamelen;
SQLSMALLINT nullable;
SQLINTEGER collen[MAXCOLS];
SQLSMALLINT scale;
/*******************************************************************
** SUPPORT FUNCTIONS
** - print_error - call SQLError(), display SQLSTATE and message
** - check_error - call print_error
** - check severity of Return Code
** - rollback & exit if error, continue if warning
*******************************************************************/
/*******************************************************************/
int print_error (SQLHENV henv,
SQLHDBC hdbc,
SQLHSTMT hstmt)
{
SQLCHAR buffer[SQL_MAX_MESSAGE_LENGTH + 1];
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
SQLINTEGER sqlcode;
SQLSMALLINT length;
/*******************************************************************/
int check_error (SQLHENV henv,
SQLHDBC hdbc,
SQLHSTMT hstmt,
SQLRETURN frc)
{
SQLRETURN rc;
switch (frc){
case SQL_SUCCESS : break;
case SQL_ERROR :
case SQL_INVALID_HANDLE:
printf("\n ** FATAL ERROR, Attempting to rollback transaction **\n");
rc = SQLTransact(henv, hdbc, SQL_ROLLBACK);
if (rc != SQL_SUCCESS)
printf("Rollback Failed, Exiting application\n");
else
printf("Rollback Successful, Exiting application\n");
terminate(henv, hdbc);
exit(frc);
break;
case SQL_SUCCESS_WITH_INFO :
printf("\n ** Warning Message, application continuing\n");
break;
case SQL_NO_DATA_FOUND :
printf("\n ** No Data Found ** \n");
break;
default :
printf("\n ** Invalid Return Code ** \n");
printf(" ** Attempting to rollback transaction **\n");
SQLTransact(henv, hdbc, SQL_ROLLBACK);
terminate(henv, hdbc);
exit(frc);
break;
}
return(SQL_SUCCESS);
For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property
Department in your country or send inquiries, in writing, to:
The following paragraph does not apply to the United Kingdom or any other country where such
provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION
PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of
express or implied warranties in certain transactions, therefore, this statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically
made to the information herein; these changes will be incorporated in new editions of the publication.
IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this
publication at any time without notice.
Any references in this information to non-IBM Web sites are provided for convenience only and do not in
any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of
the materials for this IBM product and use of those Web sites is at your own risk.
IBM may use or distribute any of the information you supply in any way it believes appropriate without
incurring any obligation to you.
Licensees of this program who wish to have information about it for the purpose of enabling: (i) the
exchange of information between independently created programs and other programs (including this
one) and (ii) the mutual use of the information which has been exchanged, should contact:
IBM Corporation
Software Interoperability Coordinator, Department YBWA
3605 Highway 52 N
Rochester, MN 55901
U.S.A.
Trademarks
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business
Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be
trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at
"Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.
298 Notices
Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or
trademarks of Adobe Systems Incorporated in the United States, and/or other countries.
Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the
United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other countries.
Other product and service names might be trademarks of IBM or other companies.
Notices 299
300 IBM i: SQL call level interface
Index
A D
allocate data conversion
allocate handle, function 30 C data types 16
allocated handle, function 31 data types 16
connection handle, function 25, 27 default data types 16
environment handle, function 27, 30 description 18
statement handle, function 31, 32 SQL data types 16
allocate handle data types
allocate, function 30 C 16, 17
application generic 17
example 285 ODBC 17
sample 285 SQL 16
tasks 6 deferred arguments 12
Assign File Reference, function 40 definition
restricted handle 28
Describe Column Attributes, function 79, 83
B Diagnostic Field Information, return 136
Bind A Buffer To A Parameter Marker, function 48, 57 Diagnostic Information, return 133, 136
Bind Column, function 32, 38 Diagnostic Record Information, return 138
Bind File Reference, function 38 diagnostics 15
BindFileToParam, function 42 Disconnect, function 85, 86
binding DriverConnect, function 86
columns 13 dynamic SQL 6
parameter markers 12
Binds A Buffer To A Parameter Marker, function 43 E
embedded SQL 285
C End Transaction Management, function 90
Cancel statement, function 57 environment handle
case sensitivity 22 allocate, function 27
character strings 21, 22 allocating 8
CLI Free, function 113, 114, 201
writing a Db2 for i CLI application 6 freeing 8
CLI function Error Information, retrieval 91, 94
SQLSetEnvAttr 282 example application 285
CLI XA transaction 288 execute direct 11
CloseCursor statement, function 58 execute statement 11
Column Attribute, function 59, 65 Execute statement Directly, function 94, 96
Column Attributes, function 65, 249 Execute statement, function 96, 98
Column Information, function 69 Extended Fetch, function 98
Column Privileges, function 48
ColumnPrivileges, function 68 F
commit 14
Connect, function 73, 75, 90 Fetch, function 100, 105
connection handle FetchScroll, function 105, 107
allocate, function 25 Foreign key column names, function 112
allocating 8 Foreign Keys Columns, function 107
freeing 8 Free
Connection handle Connection handle, function 112, 113
Free, function 112, 113 environment handle, function 113, 114, 201
CopyDesc statement, function 75 handle, function 115
cursor 2, 14 release environment, function 202
statement handle, function 115, 117
301
G Next Result Sets, function 179
null-terminated strings 21
Get Col, function 122 Number of Parameters, function 179, 180
Get Column Names for a Table, function 68, 72 Number of Result Columns, function 180, 181
Get Connection Attribute, function 122, 123
Get Connection Option, function 123, 124
Get cursor name, function 125, 128
O
Get Data Sources, function 76, 79 ODBC
Get Data, function 128 cursor names 125
Get Description Field, function 129, 131 precision 70
Get descriptor record, function 131 SQLSTATES 16
Get Descriptor Record, function 133
Get Dialect or Conformance Information, function 174
Get Environment Attribute, function 138, 139 P
Get Functions, function 139, 142
Parameter Data, function 181, 183
Get Index and Statistics Information for a Table, function
parameter markers 2
242, 246
parameter markers, binding 12
Get Info, function 142, 156
Parameter Options, function 183
Get List of Procedure Names 196
portability 6
Get List of Procedure Names, function 199
prepare statement 11
Get Number of Result Columns 180
Prepare statement, function 184, 188
Get Parameters for a Procedure, function 196
Primary Key Columns, function 188, 190
Get privileges associated with a table 246
Procedure Parameter Information, function 190
Get privileges associated with the columns of a table,
Put Data for a Parameter, function 200, 201
function 66
Get row count, function 204
Get Row Count, function 202 R
Get special (Row identifier) columns, function 242
Get Special Column Names, function 239 release environment
Get Statement Attribute, function 161, 163 ReleaseEnv, function 202
Get Statement Option, function 163, 164 restricted handle, definition 28
Get Table Information, function 249, 251 Retrieve Length of String Value, function 156
Get Type Information, function 167 Retrieve Portion of A String Value, function 164
GetCol, function 117 return codes 15
Return Starting Position of String, function 158
rollback 14
H
handle S
connection handle 3, 8
environment handle 3, 8 sample application 285
Free, function 115 SELECT 13
statement handle 3 server mode
header files 253 restrictions 282
starting 282
Set a connection attribute, function 218
I Set a Connection Attribute, function 204
Set a Statement Attribute, function 230
include files 253
Set connection option, function 219
initialization 6, 7
Set Connection Option, function 218
INVALID_HANDLE 15
Set cursor name, function 221
ISO standard 9075–3:1999 2
Set Cursor Name, function 219
Set Descriptor Field, function 221, 223
L Set Descriptor Record, function 223, 224
Set Environment Attribute, function 224, 230
Language Information, function 173 Set Parameter, function 230
Set Statement Option, function 237, 239
M SQL
dynamic 6
More Result Sets, function 174, 175 dynamically prepared 3
parameter markers 12
preparing and executing statements 11
N statements
Native SQL Text, function 175, 178 DELETE 14
Next Result Set, function 178 SELECT 13
302
SQL (continued) SQLEndTran, function
statements (continued) description 90
UPDATE 14 SQLError, function
static 6 description 91, 94
SQL_ERROR 15 SQLExecDirect, function
SQL_NO_DATA_FOUND 15 description 94, 96
SQL_NTS 21 overview 9, 11
SQL_SUCCESS 15 SQLExecute, function
SQL_SUCCESS_WITH_INFO 15 description 96, 98
SQLAllocConnect, function overview 9, 11
description 25, 27 SQLExtendedFetch, function
overview 7 description 98
SQLAllocEnv, function SQLFetch, function
description 27, 30, 31 description 100, 105
overview 7 overview 9, 13
SQLAllocHandle, function SQLFetchScroll, function
description 30 description 105, 107
SQLAllocStmt, function SQLForeignKeys, function
description 31, 32 description 107, 112
overview 9 SQLFreeConnect, function
SQLBindCol, function description 112
description 32, 38 Description 113
overview 9, 13 overview 7
SQLBindFileToCol, function SQLFreeEnv, function
description 38 description 113, 114
SQLBindFileToParam, function overview 7
description 40, 42 SQLFreeHandle, function
SQLBindParam, function description 114, 115
description 43, 48 SQLFreeStmt, function
SQLBindParameter, function description 115, 117
description 48, 57 overview 9
overview 11 SQLGetCol, function
SQLCancel, function description 117, 122
description 57 SQLGetConnectAttr, function
SQLCloseCursor, function description 122, 123
description 58 SQLGetConnectOption, function
SQLColAttribute, function description 123, 124
description 59, 65 SQLGetCursorName, function
overview 13 description 125, 128
SQLColAttributes, function SQLGetData, function
description 65, 249 description 128
overview 9 overview 9, 13
SQLColumnPrivileges, function SQLGetDescField, function
description 48, 66, 68 description 129, 131
SQLColumns, function SQLGetDescRec, function
description 68, 69, 72 description 131, 133
SQLConnect, function SQLGetDiagField, function
description 73, 75, 90 description 133, 136
overview 7 SQLGetDiagRec, function
SQLCopyDesc, function description 136, 138
description 75 SQLGetEnvAttr, function
SQLDataSources, function description 138, 139
description 76, 79 SQLGetFunctions, function
overview 9, 13 description 139, 142
SQLDescribeCol, function SQLGetInfo, function
description 79, 83 description 142, 156
overview 9, 13 SQLGetLength, function
SQLDescribeParam, function description 156
description 83 SQLGetPosition, function
SQLDisconnect, function description 158
description 85, 86 SQLGetStmtAttr, function
overview 7 description 161, 163
SQLDriverConnect, function SQLGetStmtOption, function
description 86 description 163, 164
303
SQLGetSubString, function SQLTablePrivileges, function
description 164 description 246
SQLGetTypeInfo, function SQLTables, function
description 167, 172 description 249, 251
SQLLanguages, function SQLTransact, function
description 173, 174 description 251
SQLMoreResults, function overview 9, 13, 14
description 174, 175 statement handle
SQLNativeSql, function allocate, function 31
description 175, 178 allocating 11
SQLNextResult, function Free, function 115, 117
description 178, 179 freeing 14
SQLNumParams, function maximum number of 11
description 179, 180 static SQL 6
SQLNumResultCols, function string arguments 21, 22
description 180, 181
overview 9, 13
SQLParamData, function
T
description 181, 183 termination 6, 7
SQLParamOptions, function transaction management 14
description 183 Transaction Management, function 251
SQLPrepare, function transaction processing 6
description 184, 188 truncation 21
overview 9, 11, 13
SQLPrimaryKeys, function
description 188, 190 U
SQLProcedureColumns, function
UCS-2 283
description 190, 196
unicode 283
SQLProcedures, function
UTF-16 283
description 196, 199
UTF-8 283
SQLPutData, function
description 200, 201
SQLReleaseEnv, function W
description 201, 202
SQLRowCount, function writing 6
description 202, 204
overview 9
SQLSetConnectAttr, function
description 204, 218
SQLSetConnectOption, function
description 218, 219
SQLSetCursorName, function
description 219, 221
SQLSetDescField, function
description 221, 223
SQLSetDescRec, function
description 223, 224
SQLSetEnvAttr, function
description 224, 230
SQLSetParam, function
description 230
overview 9, 13
SQLSetStmtAttr, function
description 230, 237
Set Statement Attribute, function 237
SQLSetStmtOption, function
description 237, 239
SQLSpecialColumns, function
description 239, 242
SQLSTATE 3
SQLSTATE, format of 16
SQLSTATEs 16
SQLStatistics, function
description 242, 246
304
IBM®