Database SQL Call Level Interface 7.1
Total Page:16
File Type:pdf, Size:1020Kb
IBM IBM i Database SQL call level interface 7.1 IBM IBM i Database SQL call level interface 7.1 Note Before using this information and the product it supports, read the information in “Notices,” on page 321. This edition applies to IBM i 7.1 (product number 5770-SS1) and to all subsequent releases and modifications until otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor does it run on CISC models. © Copyright IBM Corporation 1999, 2010. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents SQL call level interface ........ 1 SQLExecute - Execute a statement ..... 103 What's new for IBM i 7.1 .......... 1 SQLExtendedFetch - Fetch array of rows ... 105 PDF file for SQL call level interface ....... 1 SQLFetch - Fetch next row ........ 107 Getting started with DB2 for i CLI ....... 2 SQLFetchScroll - Fetch from a scrollable cursor 113 | Differences between DB2 for i CLI and embedded SQLForeignKeys - Get the list of foreign key | SQL ................ 2 columns .............. 115 Advantages of using DB2 for i CLI instead of SQLFreeConnect - Free connection handle ... 120 embedded SQL ............ 5 SQLFreeEnv - Free environment handle ... 121 Deciding between DB2 for i CLI, dynamic SQL, SQLFreeHandle - Free a handle ...... 122 and static SQL ............. 6 SQLFreeStmt - Free (or reset) a statement handle 123 Writing a DB2 for i CLI application ....... 6 SQLGetCol - Retrieve one column of a row of Initialization and termination tasks in a DB2 for i the result set ............ 125 CLI application ............ 7 SQLGetConnectAttr - Get the value of a Transaction processing task in a DB2 for i CLI connection attribute .......... 131 application ............. 10 SQLGetConnectOption - Return current setting Diagnostics in a DB2 for i CLI application ... 16 of a connect option .......... 132 Data types and data conversion in DB2 for i CLI SQLGetCursorName - Get cursor name.... 134 functions .............. 17 SQLGetData - Get data from a column .... 138 Working with the XML data type ...... 19 SQLGetDescField - Get descriptor field .... 139 Working with string arguments in DB2 for i CLI SQLGetDescRec - Get descriptor record ... 142 functions .............. 21 SQLGetDiagField - Return diagnostic DB2 for i CLI functions .......... 22 information (extensible) ......... 144 Categories of DB2 for i CLI functions..... 23 SQLGetDiagRec - Return diagnostic information SQLAllocConnect - Allocate connection handle 26 (concise) .............. 147 SQLAllocEnv - Allocate environment handle .. 29 SQLGetEnvAttr - Return current setting of an SQLAllocHandle - Allocate handle...... 32 environment attribute ......... 150 SQLAllocStmt - Allocate a statement handle .. 33 SQLGetFunctions - Get functions ...... 151 SQLBindCol - Bind a column to an application SQLGetInfo - Get general information .... 154 variable............... 35 SQLGetLength - Retrieve length of a string SQLBindFileToCol - Bind LOB file reference to value ............... 166 LOB column ............. 40 SQLGetPosition - Return starting position of SQLBindFileToParam - Bind LOB file reference to string ............... 168 LOB parameter ............ 43 SQLGetStmtAttr - Get the value of a statement SQLBindParam - Bind a buffer to a parameter attribute .............. 171 marker ............... 46 SQLGetStmtOption - Return current setting of a SQLBindParameter - Bind a parameter marker to statement option ........... 173 a buffer............... 51 SQLGetSubString - Retrieve portion of a string SQLCancel - Cancel statement ....... 60 value ............... 175 SQLCloseCursor - Close cursor statement ... 61 SQLGetTypeInfo - Get data type information 178 SQLColAttribute - Return a column attribute .. 62 SQLLanguages - Get SQL dialect or SQLColAttributes - Obtain column attributes .. 68 conformance information ........ 183 SQLColumnPrivileges - Get privileges associated SQLMoreResults - Determine whether there are with the columns of a table ........ 69 more result sets ........... 185 SQLColumns - Get column information for a SQLNativeSql - Get native SQL text ..... 187 table................ 72 SQLNextResult - Process the next result set .. 189 SQLConnect - Connect to a data source .... 76 SQLNumParams - Get number of parameters in SQLCopyDesc - Copy description statement .. 79 an SQL statement ........... 191 SQLDataSources - Get list of data sources ... 80 SQLNumResultCols - Get number of result SQLDescribeCol - Describe column attributes .. 84 columns .............. 193 SQLDescribeParam - Return description of a SQLParamData - Get next parameter for which parameter marker ........... 88 a data value is needed ......... 195 SQLDisconnect - Disconnect from a data source 90 SQLParamOptions - Specify an input array for a SQLDriverConnect - Connect to a data source .. 92 parameter ............. 197 SQLEndTran - Commit or roll back a transaction 96 SQLPrepare - Prepare a statement ..... 199 SQLError - Retrieve error information .... 98 SQLPrimaryKeys - Get primary key columns of SQLExecDirect - Execute a statement directly 101 a table............... 203 © Copyright IBM Corp. 1999, 2010 iii SQLProcedureColumns - Get input/output SQLTransact - Commit or roll back a transaction 267 parameter information for a procedure .... 205 DB2 for i CLI include file ......... 268 SQLProcedures - Get list of procedure names 211 Running DB2 for i CLI in server mode ..... 303 SQLPutData - Pass data value for a parameter 214 Starting DB2 for i CLI in SQL server mode .. 303 SQLReleaseEnv - Release all environment Restrictions for running DB2 for i CLI in server resources .............. 216 mode ............... 304 SQLRowCount - Get row count ...... 217 Unicode in DB2 for iCLI.......... 305 SQLSetConnectAttr - Set a connection attribute 219 Examples: DB2 for i CLI applications ..... 306 SQLSetConnectOption - Set connection option 231 Example: Embedded SQL and the equivalent SQLSetCursorName - Set cursor name .... 233 DB2 for i CLI function calls ....... 306 SQLSetDescField - Set a descriptor field ... 235 Example: Using the CLI XA transaction SQLSetDescRec - Set a descriptor record ... 237 connection attributes .......... 309 SQLSetEnvAttr - Set environment attribute .. 239 Example: Interactive SQL and the equivalent SQLSetParam - Set parameter ....... 244 DB2 for i CLI function calls ....... 312 SQLSetStmtAttr - Set a statement attribute... 245 SQLSetStmtOption - Set statement option ... 251 Appendix. Notices ......... 321 SQLSpecialColumns - Get special (row Programming interface information ...... 323 identifier) columns .......... 253 Trademarks .............. 323 SQLStatistics - Get index and statistics Terms and conditions........... 323 information for a base table ....... 257 SQLTablePrivileges - Get privileges associated Index ............... 325 with a table ............. 261 SQLTables - Get table information ..... 264 iv IBM i: Database SQL call level interface 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 319. What's new for IBM i 7.1 | Read about new or significantly changed information for the SQL CLI topic collection. v Support for the XML data type. Columns defined with the XML data type can be bound in and out to character, wide character or binary data types depending on the column definition. See SQLBindCol() and SQLBindParameter() functions for more information on binding the XML data type in a CLI application. In addition, there are two new connection attributes that provide configuration settings related to XML. See SQLSetConnectAttr() for more information on these new attributes. v Support for Concurrent Access Resolution through the use of a new connection attribute, SQL_ATTR_CONCURRENT_ACCESS_RESOLUTION. See a description of the new attribute under the SQLSetConnectAttr() function. v Support for multiple-row processing on UPDATE, DELETE, and MERGE statements similar to how it is supported for INSERT statements. v Support for TINYINT data type. CLI applications being ported from other platforms that bind TINYINT types as application data types will now run on IBM i. How to see what's new or changed To help you see where technical changes have been made, this information uses: v The image to mark where new or changed information begins. v The image to mark where new or changed information ends. In PDF files, you might see revision bars (|) in the left margin of new and changed information. To find other information about what's new or changed this release, see the Memo to users. PDF file for SQL call level interface You can view and print a PDF file of this