Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-24938] add comment to dblink query for statement type checking in gateway #4591

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/parser/name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -5193,14 +5193,14 @@ pt_dblink_table_get_column_defs (PARSER_CONTEXT * parser, PT_NODE * dblink, S_RE
rmt_tbl_cols->set_select_star ();

/* preparing the query to get the column info */
var_buf = pt_append_nulstring (parser, var_buf, "SELECT * FROM ");
var_buf = pt_append_nulstring (parser, var_buf, table_name);
sql = (char *) var_buf->bytes;
sql = pt_append_string (parser, "/* DBLINK SELECT */ SELECT * FROM ", table_name);
}
else
{
/* for collecting column info from "SELECT sel-list form dblink(server, 'SELECT ...') */
sql = (char *) dblink_table->qstr->info.value.data_value.str->bytes;
sql =
pt_append_string (parser, "/* DBLINK SELECT */ ",
(char *) dblink_table->qstr->info.value.data_value.str->bytes);
}

find = strstr (url, ":?");
Expand Down
26 changes: 25 additions & 1 deletion src/parser/parser_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -11607,6 +11607,8 @@ pt_convert_dblink_dml_query (PARSER_CONTEXT * parser, PT_NODE * node,
PT_NODE *list = NULL; /* for insert select list */
PT_NODE *spec, *into_spec = NULL, *upd_spec = NULL, *server;

PARSER_VARCHAR *comment, *dml;

switch (node->node_type)
{
case PT_INSERT:
Expand Down Expand Up @@ -11721,10 +11723,32 @@ pt_convert_dblink_dml_query (PARSER_CONTEXT * parser, PT_NODE * node,

save_custom_print = parser->custom_print;

switch (node->node_type)
{
case PT_INSERT:
comment = pt_append_bytes (parser, NULL, "/* DBLINK INSERT */ ", 20);
break;
case PT_UPDATE:
comment = pt_append_bytes (parser, NULL, "/* DBLINK UPDATE */ ", 20);
break;
case PT_DELETE:
comment = pt_append_bytes (parser, NULL, "/* DBLINK DELETE */ ", 20);
break;
case PT_MERGE:
comment = pt_append_bytes (parser, NULL, "/* DBLINK MERGE */ ", 19);
break;
default:
/* must not reach here */
assert (false);
}

parser->custom_print |=
PT_PRINT_SUPPRESS_SERVER_NAME | PT_PRINT_SUPPRESS_SERIAL_CONV | PT_PRINT_NO_HOST_VAR_INDEX |
PT_PRINT_SUPPRESS_FOR_DBLINK;
val->info.value.data_value.str = pt_print_bytes (parser, node);

dml = pt_print_bytes (parser, node);

val->info.value.data_value.str = pt_append_bytes (parser, comment, (const char *) dml->bytes, dml->length);

parser->custom_print = save_custom_print;

Expand Down
4 changes: 2 additions & 2 deletions src/parser/xasl_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12983,11 +12983,11 @@ pt_to_dblink_table_spec_list (PARSER_CONTEXT * parser, PT_NODE * spec, PT_NODE *

if (pdblink->rewritten)
{
sql = (char *) pdblink->rewritten->bytes;
sql = pt_append_string (parser, "/* DBLINK SELECT */ ", (char *) pdblink->rewritten->bytes);
}
else
{
sql = (char *) pdblink->qstr->info.value.data_value.str->bytes;
sql = pt_append_string (parser, "/* DBLINK SELECT */ ", (char *) pdblink->qstr->info.value.data_value.str->bytes);
}

if (pdblink->pushed_pred)
Expand Down