开发者

EXEC SQL DECLARE variable in .h header files preprocessed by Oracle pro*c

开发者 https://www.devze.com 2023-03-16 03:13 出处:网络
I am porting some C++ code with embedded SQL into a linux server with oracle database. The data Access Objects are C++ classes providing

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号