10.12.2012 Views

Application Programming and SQL Guide - Kmlinux

Application Programming and SQL Guide - Kmlinux

Application Programming and SQL Guide - Kmlinux

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

|<br />

|<br />

|<br />

|<br />

|<br />

|<br />

|<br />

|<br />

|<br />

Using the <strong>SQL</strong> communication area (<strong>SQL</strong>CA) . . . . . . . . . . . . 87<br />

<strong>SQL</strong>CODE <strong>and</strong> <strong>SQL</strong>STATE . . . . . . . . . . . . . . . . . . . 88<br />

The WHENEVER statement . . . . . . . . . . . . . . . . . . . 88<br />

H<strong>and</strong>ling arithmetic or conversion errors . . . . . . . . . . . . . . 89<br />

The GET DIAGNOSTICS statement . . . . . . . . . . . . . . . . 89<br />

Calling DSNTIAR to display <strong>SQL</strong>CA fields . . . . . . . . . . . . . . 94<br />

Chapter 7. Using a cursor to retrieve a set of rows . . . . . . . . . . 99<br />

Accessing data by using a row-positioned cursor . . . . . . . . . . . . 99<br />

Step 1: Declare the cursor . . . . . . . . . . . . . . . . . . . . 99<br />

Step 2: Open the cursor . . . . . . . . . . . . . . . . . . . . 101<br />

Step 3: Specify what to do at end-of-data . . . . . . . . . . . . . . 101<br />

Step 4: Execute <strong>SQL</strong> statements . . . . . . . . . . . . . . . . . 102<br />

Step 5: Close the cursor . . . . . . . . . . . . . . . . . . . . 104<br />

Accessing data by using a rowset-positioned cursor . . . . . . . . . . . 104<br />

Step 1: Declare the rowset cursor . . . . . . . . . . . . . . . . 104<br />

Step 2: Open the rowset cursor . . . . . . . . . . . . . . . . . 104<br />

Step 3: Specify what to do at end-of-data for a rowset cursor . . . . . . 105<br />

Step 4: Execute <strong>SQL</strong> statements with a rowset cursor . . . . . . . . . 105<br />

Step 5: Close the rowset cursor . . . . . . . . . . . . . . . . . 109<br />

Types of cursors . . . . . . . . . . . . . . . . . . . . . . . . 109<br />

Scrollable <strong>and</strong> non-scrollable cursors . . . . . . . . . . . . . . . 109<br />

Held <strong>and</strong> non-held cursors . . . . . . . . . . . . . . . . . . . 118<br />

Examples of using cursors . . . . . . . . . . . . . . . . . . . . 120<br />

Chapter 8. Generating declarations for your tables using DCLGEN . . . . 127<br />

Invoking DCLGEN through DB2I . . . . . . . . . . . . . . . . . . 127<br />

Including the data declarations in your program . . . . . . . . . . . . 128<br />

DCLGEN support of C, COBOL, <strong>and</strong> PL/I languages . . . . . . . . . . 129<br />

Example: Adding a table declaration <strong>and</strong> host-variable structure to a library 130<br />

Step 1. Specify COBOL as the host language . . . . . . . . . . . . 130<br />

Step 2. Create the table declaration <strong>and</strong> host structure . . . . . . . . . 131<br />

Step 3. Examine the results . . . . . . . . . . . . . . . . . . . 133<br />

Chapter 9. Embedding <strong>SQL</strong> statements in host languages . . . . . . . 135<br />

Coding <strong>SQL</strong> statements in an assembler application . . . . . . . . . . . 135<br />

Defining the <strong>SQL</strong> communications area . . . . . . . . . . . . . . 135<br />

Defining <strong>SQL</strong> descriptor areas . . . . . . . . . . . . . . . . . . 136<br />

Embedding <strong>SQL</strong> statements . . . . . . . . . . . . . . . . . . 137<br />

Using host variables . . . . . . . . . . . . . . . . . . . . . 139<br />

Declaring host variables . . . . . . . . . . . . . . . . . . . . 139<br />

Determining equivalent <strong>SQL</strong> <strong>and</strong> assembler data types . . . . . . . . 142<br />

Determining compatibility of <strong>SQL</strong> <strong>and</strong> assembler data types . . . . . . . 146<br />

Using indicator variables . . . . . . . . . . . . . . . . . . . . 147<br />

H<strong>and</strong>ling <strong>SQL</strong> error return codes . . . . . . . . . . . . . . . . . 148<br />

Macros for assembler applications . . . . . . . . . . . . . . . . 149<br />

Coding <strong>SQL</strong> statements in a C or C++ application . . . . . . . . . . . 149<br />

Defining the <strong>SQL</strong> communication area . . . . . . . . . . . . . . . 149<br />

Defining <strong>SQL</strong> descriptor areas . . . . . . . . . . . . . . . . . . 150<br />

Embedding <strong>SQL</strong> statements . . . . . . . . . . . . . . . . . . 151<br />

Using host variables <strong>and</strong> host variable arrays . . . . . . . . . . . . 152<br />

Declaring host variables . . . . . . . . . . . . . . . . . . . . 153<br />

Declaring host variable arrays . . . . . . . . . . . . . . . . . . 159<br />

Using host structures . . . . . . . . . . . . . . . . . . . . . 164<br />

Determining equivalent <strong>SQL</strong> <strong>and</strong> C data types . . . . . . . . . . . . 166<br />

Determining compatibility of <strong>SQL</strong> <strong>and</strong> C data types . . . . . . . . . . 172<br />

Contents v

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!