I am porting some C++ code with embedded SQL into a linux server with oracle database.
The data Access Objects are C++ classes providing .select() .insert() .findByPrimaryKey() etc, methods for database interactions.
This is the testdao.h header file.
class TestDAO
{
private:
EXEC SQL BEGIN DECLARE SECTION;
int hv_col1;
int hv_col2;
.. .. upto 20 host variables ...
EXEC SQL END DECLARE SECTION;
public:
testObj* select();
bool insert(testObj);
testObj* findByPrimaryKey(primaryKeyObj);
}
This is testdao.ecpp file
class TestDAO::select()
{
... select into hostvariables hv_col1, hv_col2 ..
... copy hostvariables data into object ...
}
class TestDAO::insert(testObj)
{
.开发者_开发技巧.. copy data from the testObj into hostvariables ...
... EXEC SQL INSERT using hostvariales ...
}
class TestDAO::findByPrimaryKey(primaryKeyObj)
{
... copy primaryKeyObj data into hostvariables ...
... EXEC SQL SELECT where primary key ..
}
Oracle pro*C precompiler can't handle EXEC SQL in header files. How do i declare the hostvariables so that I don't have to declare them repeatedly in each of the methods?
I can't have them as global variables.
精彩评论