Background : I'm trying to implement a C++ STL iterator like layer around Pro*C embedded SQL (PL/SQL). Basically, I'll need something like these methods :
int select_init(string sql_cmd) {
EXEC SQL DECLARE cur1 CURSOR FOR ...;
EXEC SQL OPEN cur1;
}
int select_get(ResultType &result) {
EXEC SQL FETCH cur1 INTO ...;
}
int select_close() {
EXEC SQL CLOSE cur1;
}
which would then be called in order for a given SQL request.
Called like this, there's no problem :
select_init(cmd);
while (select_get(res)) {
// do something with res
}
select_close();
But what if I call a second select_init, before the select_close was called for the first ?
select_init(cmd1);
select_init(cmd2);
// some more code
select_close();
select_close();
The problem is that two cursors are now opened with the same identifier (cur1). That won't work like this afaik.
Now, finally on to my questions :
1) has something like this already been done, and where can I find it ?
2) is my approach good, or would you do it differently ?
3) if my approach is good, how do I solve the described problem ? Is there a way to get different cursor id's for subsequent calls to select_open ?
I tried to be as brief as possible in my question, so if I left anything important out, please let me know :)
Start Free Trial