13.01.2013 Views

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

RDBMS Stored Procedure Details<br />

3–12<br />

DEFINE VARIABLE handle1 AS INTEGER NO-UNDO.<br />

RUN STORED-PROC send-sql-statement handle1 = PROC-HANDLE<br />

("SELECT name, address, city, state, postal_code<br />

FROM customer WHERE credit_limit >= 500").<br />

FOR EACH proc-text-buffer WHERE PROC-HANDLE = handle1:<br />

DISPLAY proc-text-buffer.<br />

END.<br />

CLOSE STORED-PROC send-sql-statement WHERE PROC-HANDLE = handle1.<br />

Example 3–1: Passing a SELECT statement as a parameter<br />

Example 3–1 returns the name, address, city, state, and postal_code <strong>for</strong> all customers<br />

whose max–credit is greater than or equal to $500. You must read the results into a buffer as<br />

you would with a stored procedure called by an <strong>OpenEdge</strong> procedure. You can read the results<br />

into the proc–text–buffer defined by <strong>OpenEdge</strong> as shown in the example above.<br />

Alternatively, you can define your own buffer from within your data source that can accept<br />

other data types as well as the CHARACTER data type.<br />

With the Load-Result-Into option<br />

Example 3–2 shows how to use the send-sql-statement with the LOAD-RESULT-INTO option. It<br />

also shows that the PROC-STATUS phrase must be defined as part of the RUN STORED-PROC<br />

statement because of the implicit CLOSE STORED-PROC that is associated with the<br />

LOAD-RESULT-INTO phrase.<br />

DEFINE VARIABLE res AS INTEGER NO-UNDO.<br />

DEFINE VARIABLE tthndl AS HANDLE NO-UNDO.<br />

CREATE TEMP-TABLE tthndl.<br />

RUN STORED-PROCEDURE send-sql-statement LOAD-RESULT-INTO tthndl<br />

res = PROC-STATUS (“SELECT * FROM customer”).<br />

IF res THEN<br />

DISPLAY “succeeded”.<br />

DISPLAY stat.<br />

Example 3–2: Using the send-sql-statement with the LOAD-RESULT-INTO<br />

option<br />

Also note in Example 3–2 that the PROC-STATUS phrase does not need an associated<br />

PROC-HANDLE phrase to close the associated procedure because it is retrieved using the RUN<br />

STORED-PROC statement; although the PROC-HANDLE is typically used after the execution of the<br />

RUN STORED-PROC statement, it is not needed in this context because of the implicit procedure<br />

close.

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

Saved successfully!

Ooh no, something went wrong!