Skip to content

Commit

Permalink
Resolve issue mridoni#181
Browse files Browse the repository at this point in the history
Parameters in cursor usage with prepared statements are not considered
  • Loading branch information
sergiosa61 committed May 14, 2024
1 parent 04695f0 commit 8df1b72
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libgixpp/ESQLDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ struct cb_exec_sql_stmt_t
bool startup_item;
bool cursor_hold;
bool transaction_release;
bool cursor_from_prepared;

int sql_query_list_id;

Expand All @@ -169,6 +170,7 @@ struct cb_exec_sql_stmt_t
startup_item = false;
cursor_hold = false;
transaction_release = false;
cursor_from_prepared = false;
}

~cb_exec_sql_stmt_t()
Expand Down
12 changes: 12 additions & 0 deletions libgixpp/TPESQLProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,23 @@ bool TPESQLProcessor::put_cursor_declarations()

put_output_line(std::string(_areab) + "GO TO GIX-SKIP-CRSR-INIT.");

auto cursor_open_list = startup_items;
auto other_crsrs_open = cpplinq::from(*(parser_data->exec_list())).where([](cb_exec_sql_stmt_ptr p) { return p->startup_item == 0 && p->commandName == ESQL_OPEN && !p->cursorName.empty(); }).to_vector();
cursor_open_list.insert(cursor_open_list.end(), other_crsrs_open.begin(), other_crsrs_open.end());

auto cursor_list = startup_items;
auto other_crsrs = cpplinq::from(*(parser_data->exec_list())).where([](cb_exec_sql_stmt_ptr p) { return p->startup_item == 0 && p->commandName == ESQL_SELECT && !p->cursorName.empty(); }).to_vector();
cursor_list.insert(cursor_list.end(), other_crsrs.begin(), other_crsrs.end());

for (cb_exec_sql_stmt_ptr stmt : cursor_list) {
if (stmt->host_list->size() <= 0 && stmt->cursor_from_prepared) {
for (cb_exec_sql_stmt_ptr stmt_open : cursor_open_list) {
if (stmt->cursorName == stmt_open->cursorName && stmt_open->commandName == ESQL_OPEN && stmt_open->host_list->size() > 0) {

stmt->host_list = stmt_open->host_list;
}
}
}
bool has_params = stmt->host_list->size() > 0;

//if (stmt->statementSource && !stmt->statementSource->is_literal) {
Expand Down
2 changes: 2 additions & 0 deletions libgixpp/gix_esql_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ gix_esql_driver::gix_esql_driver ()
sqlname = "";
incfilename = "";
transaction_release = false;
cursor_from_prepared = false;
hostreferenceCount = 0;
host_reference_list = NULL;
res_host_reference_list = NULL;
Expand Down Expand Up @@ -370,6 +371,7 @@ void gix_esql_driver::put_exec_list()
l->textContent = text_content;
l->command_putother = command_putother;
l->transaction_release = transaction_release;
l->cursor_from_prepared = cursor_from_prepared;
l->sqlName = sqlname;
l->incfileName = incfilename;
l->statementName = statement_name;
Expand Down
1 change: 1 addition & 0 deletions libgixpp/gix_esql_driver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public:
std::string incfilename;
std::string text_content;
bool transaction_release;
bool cursor_from_prepared;

hostref_or_literal_t *connectionid = nullptr;

Expand Down
1 change: 1 addition & 0 deletions libgixpp/gix_esql_parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ CURSOR opt_with_hold FOR select { driver->cb_set_cursor_hold($2); }

cursor_declaration_from_prepared_stmt:
CURSOR opt_with_hold FOR strliteral_or_hostref {
driver->cursor_from_prepared = true;
driver->cb_set_cursor_hold($2);
driver->statement_source = $4;
driver->commandname = "SELECT";
Expand Down
5 changes: 5 additions & 0 deletions libgixpp/gix_esql_scanner.ll
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ SUBSYSTEM "SQL"|"CICS"|"DLI"
return yy::gix_esql_parser::make_WHENEVER(loc);
}
{HOSTWORD} {
return yy::gix_esql_parser::make_HOSTTOKEN(yytext, loc);
}
({WORD}|{JPNWORD})+ {
__yy_push_state(ESQL_STATE);
Expand Down Expand Up @@ -709,6 +713,7 @@ SUBSYSTEM "SQL"|"CICS"|"DLI"
}
"CURSOR" {
cur_token_list.push_back("CURSOR");
return yy::gix_esql_parser::make_CURSOR(loc);
}
Expand Down

0 comments on commit 8df1b72

Please sign in to comment.