Templates and Pro*C/C++ (maybe EXEC SQL TYPE?)
From: Alex Vinokur <alexander.vinokur_at_telrad.co.il>
Date: Mon, 11 Oct 1999 08:59:18 GMT
Message-ID: <7ts8t1$fp0$1_at_nnrp1.deja.com>
template <class T1, class T2>
bool updateRow (
#include <oraca.h>
{
const char* execute_line__host = ((const char*)tmp_str); EXEC SQL END DECLARE SECTION;
=== Pro*C/C++ : Release 8.0.5.0.0
=== SunOS 5.6
Date: Mon, 11 Oct 1999 08:59:18 GMT
Message-ID: <7ts8t1$fp0$1_at_nnrp1.deja.com>
Hi,
I need the following function updateRow() in Pro*C/C++.
//-------------------------------------
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
);
//-------------------------------------
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() :
- updateRow ("AAA", "emp_no", 127, "salary", 7925);
- updateRow ("BBB", "weight", 101, "dep_name", "Testing");
- updateRow ("AAA", "job", "analyst", dep_no, 3112);
- updateRow ("AAA", "location", "boston", "job", "manager");
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 <string>
#include <sqlca.h>
#include <oraca.h>
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;
const char* execute_line__host = ((const char*)tmp_str); EXEC SQL END 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
=== Pro*C/C++ : Release 8.0.5.0.0
=== SunOS 5.6
//--------------------------------------------------------- //#########################################################
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Mon Oct 11 1999 - 10:59:18 CEST
