23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

E<strong>SQL</strong> elements and statements<br />

Examples The first example is a code fragment from the DynUpd function in sample program 3DynUpd.pc,<br />

which illustrates dynamic processing of an UPDATE statement:<br />

340<br />

Syntax<br />

{ :host_variable | quoted_literal }<br />

/*<br />

** Process a dynamic non-SELECT input statement<br />

** PREPARE the statement<br />

** EXECUTE the prepared statement<br />

** COMMIT WORK<br />

*/<br />

EXEC <strong>SQL</strong> PREPARE dynstmt FROM :sql_stmt_v ;<br />

EXEC <strong>SQL</strong> EXECUTE dynstmt ;<br />

EXEC <strong>SQL</strong> COMMIT WORK ;<br />

This example is a code fragment from the DynSel function in sample program 4DynSel.pc,<br />

which illustrates dynamic processing of a SELECT statement:<br />

/*<br />

** PREPARE a the dynamic SELECT statement.<br />

** DECLARE cursor for the prepared SELECT statement.<br />

** NOTE: You must set input parameter values before OPEN CURSOR.<br />

** If your query has input parameters, you must define them in<br />

** the DECLARE SECTION.<br />

** OPEN the declared cursor.<br />

** NOTE: For static statements, if a DECLARE CURSOR<br />

** statement contains references to automatic variables,<br />

** the OPEN CURSOR statement must be in the same C function.<br />

**<br />

** Name WHENEVER routine for NOT FOUND condition.<br />

** FETCH a row and print results until no more rows.<br />

*/<br />

EXEC <strong>SQL</strong> PREPARE stmtid from :sel_stmt_v ;<br />

EXEC <strong>SQL</strong> DECLARE dyncur CURSOR FOR stmtid ;<br />

EXEC <strong>SQL</strong> OPEN dyncur ;<br />

EXEC <strong>SQL</strong> WHENEVER NOT FOUND GOTO seldone ;<br />

Notes • A statement string can have one or more references to input variables. These variables<br />

represent values supplied at run time to:<br />

– INSERT and UPDATE statements<br />

– Predicates in DELETE, UPDATE, and SELECT statements<br />

• A program supplies an input variable to a PREPARE statement either as a substitution name<br />

or as a parameter marker. For example:<br />

– A substitution name is a name preceded by a colon ( : ) in a statement string. This<br />

name does not refer to a C Language variable, but acts only as a placeholder for input<br />

variables.<br />

– A parameter marker is a question mark ( ? ) in the statement string, serving as a<br />

placeholder for input variables.

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

Saved successfully!

Ooh no, something went wrong!