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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

#<br />

|<br />

|<br />

|<br />

Part 6. Additional programming techniques<br />

Chapter 24. Coding dynamic <strong>SQL</strong> in application programs . . . . . . . 543<br />

Choosing between static <strong>and</strong> dynamic <strong>SQL</strong> . . . . . . . . . . . . . . 543<br />

Flexibility of static <strong>SQL</strong> with host variables . . . . . . . . . . . . . 544<br />

Flexibility of dynamic <strong>SQL</strong> . . . . . . . . . . . . . . . . . . . 544<br />

Limitations of dynamic <strong>SQL</strong> . . . . . . . . . . . . . . . . . . . 544<br />

Dynamic <strong>SQL</strong> processing . . . . . . . . . . . . . . . . . . . 544<br />

Performance of static <strong>and</strong> dynamic <strong>SQL</strong> . . . . . . . . . . . . . . 545<br />

Static <strong>SQL</strong> statements with no input host variables . . . . . . . . . 545<br />

Static <strong>SQL</strong> statements with input host variables . . . . . . . . . . 545<br />

Dynamic <strong>SQL</strong> statements . . . . . . . . . . . . . . . . . . 545<br />

Caching dynamic <strong>SQL</strong> statements . . . . . . . . . . . . . . . . . 546<br />

Using the dynamic statement cache . . . . . . . . . . . . . . . . 547<br />

Conditions for statement sharing . . . . . . . . . . . . . . . . 548<br />

Using the statement cache table . . . . . . . . . . . . . . . . . 549<br />

Keeping prepared statements after commit points . . . . . . . . . . 549<br />

Limiting dynamic <strong>SQL</strong> with the resource limit facility . . . . . . . . . . . 551<br />

Writing an application to h<strong>and</strong>le reactive governing . . . . . . . . . . 552<br />

Writing an application to h<strong>and</strong>le predictive governing . . . . . . . . . 552<br />

H<strong>and</strong>ling the +495 <strong>SQL</strong>CODE . . . . . . . . . . . . . . . . . 552<br />

Using predictive governing <strong>and</strong> down-level DRDA requesters . . . . . . 552<br />

Using predictive governing <strong>and</strong> enabled requesters . . . . . . . . . . 553<br />

Choosing a host language for dynamic <strong>SQL</strong> applications . . . . . . . . . 553<br />

Dynamic <strong>SQL</strong> for non-SELECT statements . . . . . . . . . . . . . . 553<br />

Dynamic execution using EXECUTE IMMEDIATE . . . . . . . . . . . 554<br />

Declaring the host variable . . . . . . . . . . . . . . . . . . 554<br />

Dynamic execution using PREPARE <strong>and</strong> EXECUTE . . . . . . . . . 555<br />

Using parameter markers with PREPARE <strong>and</strong> EXECUTE . . . . . . . 556<br />

Using the PREPARE statement . . . . . . . . . . . . . . . . 556<br />

Using the EXECUTE statement . . . . . . . . . . . . . . . . 557<br />

Preparing <strong>and</strong> executing the example DELETE statement . . . . . . 557<br />

Using more than one parameter marker . . . . . . . . . . . . . 557<br />

Dynamic execution of a multiple-row INSERT statement . . . . . . . . 557<br />

Using EXECUTE with host variable arrays . . . . . . . . . . . . 558<br />

Using EXECUTE with a descriptor . . . . . . . . . . . . . . . 558<br />

Using DESCRIBE INPUT to put parameter information in an <strong>SQL</strong>DA . . . 559<br />

Dynamic <strong>SQL</strong> for fixed-list SELECT statements . . . . . . . . . . . . 560<br />

Declaring a cursor for the statement name . . . . . . . . . . . . . 561<br />

Preparing the statement . . . . . . . . . . . . . . . . . . . . 561<br />

Opening the cursor . . . . . . . . . . . . . . . . . . . . . . 562<br />

Fetching rows from the result table . . . . . . . . . . . . . . . . 562<br />

Closing the cursor . . . . . . . . . . . . . . . . . . . . . . 562<br />

Dynamic <strong>SQL</strong> for varying-list SELECT statements . . . . . . . . . . . 562<br />

What your application program must do . . . . . . . . . . . . . . 562<br />

Preparing a varying-list SELECT statement . . . . . . . . . . . . . 563<br />

An <strong>SQL</strong> descriptor area . . . . . . . . . . . . . . . . . . . 563<br />

Obtaining information about the <strong>SQL</strong> statement . . . . . . . . . . 564<br />

Declaring a cursor for the statement . . . . . . . . . . . . . . 564<br />

Preparing the statement using the minimum <strong>SQL</strong>DA . . . . . . . . 565<br />

<strong>SQL</strong>N determines what <strong>SQL</strong>VAR gets . . . . . . . . . . . . . . 565<br />

If the statement is not a SELECT . . . . . . . . . . . . . . . . 565<br />

Acquiring storage for a second <strong>SQL</strong>DA if needed . . . . . . . . . . 566<br />

Describing the SELECT statement again . . . . . . . . . . . . . 566<br />

Acquiring storage to hold a row . . . . . . . . . . . . . . . . 567<br />

© Copyright IBM Corp. 1983, 2004 533

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

Saved successfully!

Ooh no, something went wrong!