Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Templates and Pro*C/C++ (maybe EXEC SQL TYPE?)
Hi,
I need the following function updateRow() in Pro*C/C++.
//-------------------------------------template <class T1, class T2>
const string& tableName_i, const string& keyColName_i, const T1& keyColValue_i, const string& dataColName_i, const T2& dataColValue_i ); //------------------------------------- I want updateRow() to update column dataColName_i (new value is dataColValue_i) if column keyColValue_i is equal keyColValue_i; Notes. Tables contain several columns of different types (NUMBER, VARCHAR2, CHAR). I don't know beforehand what keyColName_i and dataColName_i will be checked and updated in my main program.
Here is examples of desirable calling updateRow() :
Questions.
A) How can we write (in Pro*C/C++) template function
something like code below?
The problem is how to define host variables
from template variables.
B) Can we use another Pro*C/C++ features
to gain our goal not using template function (For instance, EXEC SQL TYPE ...)?
Thanks in advance, Alex //######################################################### //------------------- Pro*C/C++ code : BEGIN --------------#include <sqlca.h>
#include <string>
template <class T1, class T2>
bool updateRow (
const string& tableName_i, const string& keyColName_i, const T1& keyColValue_i, const string& dataColName_i, const T2& dataColValue_i )
string tmp_str;
#define KEY_COL_VALUE_HOST keyColValue_host;
#define DATA_COL_VALUE_HOST dataColValue_host;
//----------------------------------------- EXEC SQL BEGIN DECLARE SECTION; T1 KEY_COL_VALUE_HOST = keyColValue_i; // ??? T2 DATA_COL_VALUE_HOST = keyColValue_i; // ???// By the way : can we use string (STL-string) as host variable? EXEC SQL END DECLARE SECTION;
//----------------------------------------- //========================================= EXEC SQL WHENEVER SQLERROR GOTO case_update_error; //----------------------------------------- //----------------------------------------- tmp_str = "EXEC SQL UPDATE "; tmp_str += tableName_i; tmp_str += " SET "; tmp_str += dataColName_i; tmp_str += " = :"; tmp_str += KEY_COL_VALUE_HOST; tmp_str += " WHERE "; tmp_str += dataColName_i; tmp_str += " = :"; tmp_str += KEY_COL_VALUE_HOST; //----------------------------------------- //-----------------------------------------EXEC SQL BEGIN DECLARE SECTION;
//----------------------------------------- //----------------------------------------- EXEC SQL EXECUTE IMMEDIATE : execute_line__host; return true; //----------------------------------------- //===================================== case_update_error: EXEC SQL WHENEVER SQLERROR DO sql_bug(); sql_error_message (); return false; //===================================== } // bool updateRow () //------------------- Pro*C/C++ code : END ---------------- //######################################################### //------------------- System ------------------------------ === Oracle 8.0.5
//--------------------------------------------------------- //#########################################################
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Mon Oct 11 1999 - 03:59:18 CDT