How to reuse PREPAREd queries in ProC/C++

From: ChgMan <ChgMan_at_earthlink.net>
Date: Sat, 28 Dec 2002 05:35:45 GMT
Message-ID: <RKaP9.2718$Oc.335628_at_newsread2.prod.itd.earthlink.net>



Hi,

I use Release 8.1.6 of ProC/C++.
I want to reuse PREPAREd statements, i.e. I want to prepare multiple statements,
obtain handles to them, and execute prepared statements when needed. The code might look like below:




EXEC SQL BEGIN DECLARE SECTION
int statement_id;
const char sql_statement[1024];
const char name[128];
EXEC SQL END DECLARE SECTION
// Following method prepares statement from the string sql_statement.
// It takes sql_statement as an input parameter and places handle to the
prepared
// statement into statement_id, using it as an output variable. We can store
// such handles in some container.
// For the sake of example we can assume that sql_statement has exactly one
placeholder, like in
// "DELETE FROM employee WHERE name = :n";
void createPreparedStatement() {
  EXEC SQL PREPARE :statement_id FROM :sql_statement; // Incorrect }

// Following method executes prepared statement referred by statement_id. It
also
// takes host variable name as an input parameter
void executePreparedStatement() {
  EXEC SQL EXECUTE :statement_id USING :name; // Incorrect }


Unfortunately, statement_id cannot be host variable, it must be Oracle variable:

EXEC SQL PREPARE STATEMENT_ID FROM :sql_statement; // Correct, but doesn't work for me
EXEC SQL EXECUTE STATEMENT_ID USING :name; // Correct, but doesn't work for me

Can I still achieve my goal using PREPAREd statements or some other technique, like
stored procedures etc.?

Thank you,
YP Received on Sat Dec 28 2002 - 06:35:45 CET

Original text of this message