Prevent overwrite of named statements

Previously, issuing a PARSE with an existing statement name would silently overwrite the prepared statement. This fix ensures that named prepared statements cannot be overwritten and will raise an error if redefined. Only unnamed statements (empty name) are allowed to be replaced on reissue.
pull/5044/head
Rahim Kanji 9 months ago
parent 98fbc9e513
commit 7c71fe1a05

@ -5959,16 +5959,21 @@ int PgSQL_Session::handle_post_sync_parse_message(PgSQL_Parse_Message* parse_msg
}
}
//mybe = find_or_create_backend(current_hostgroup);
// if the same statement name is used, we drop it
//FIXME: Revisit this logic
PgSQL_STMTs_local_v14* local_stmts = client_myds->myconn->local_stmts;
std::string stmt_name(extended_query_info.stmt_client_name);
if (auto it = local_stmts->stmt_name_to_global_ids.find(stmt_name);
it != local_stmts->stmt_name_to_global_ids.end()) {
if (!stmt_name.empty()) {
const std::string& errmsg = "prepared statement \"" + stmt_name + "\" already exist";
handle_post_sync_error(PGSQL_ERROR_CODES::ERRCODE_DUPLICATE_PSTATEMENT,
errmsg.c_str(), false);
l_free(parse_pkt.size, parse_pkt.ptr);
return 2;
}
uint64_t global_id = it->second;
auto range = local_stmts->global_id_to_stmt_names.equal_range(global_id);

Loading…
Cancel
Save