2

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
ProC-Guy
  • 21
  • 2
  • Is it just because it's in a header file? Because in that case I'd recommend using the pimpl idiom to isolate the EXEC SQL stuff in a cpp file. – user786653 Jun 27 '11 at 14:29
  • Yes. the problem seems to be the EXEC SQL. I shall try to use the pimpl idiom, and check if it solves the problem. – ProC-Guy Jun 28 '11 at 10:21

0 Answers0