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-25515] Do not check column names in VALUES clause of INSERT statement #5630

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions msg/en_US.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,7 @@ $set 8 MSGCAT_SET_PARSER_SEMANTIC
322 Table column '%1$s.%2$s' has not been defined
323 Stored procedure/function '%1$s' has OUT or IN OUT arguments
324 '%1$s' is not a record variable.
325 Column not allowed here

$set 9 MSGCAT_SET_PARSER_RUNTIME
1 Out of virtual memory: unable to allocate %1$d bytes.
Expand Down
1 change: 1 addition & 0 deletions msg/ko_KR.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,7 @@ $set 8 MSGCAT_SET_PARSER_SEMANTIC
322 테이블 컬럼 '%1$s.%2$s'이 정의되지 않았습니다
323 Stored procedure/function '%1$s' 이(가) OUT 또는 IN OUT 인수를 가지고 있습니다.
324 '%1$s'은 레코드 변수가 아닙니다.
325 열을 사용할 수 없습니다

$set 9 MSGCAT_SET_PARSER_RUNTIME
1 가상 메모리 없음: %1$d 바이트를 할당할 수 없습니다.
Expand Down
73 changes: 73 additions & 0 deletions src/parser/name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ static int pt_resolve_dblink_server_name (PARSER_CONTEXT * parser, PT_NODE * nod
static int pt_resolve_dblink_check_owner_name (PARSER_CONTEXT * parser, PT_NODE * node, char **server_owner_name);

static void pt_gather_dblink_colums (PARSER_CONTEXT * parser, PT_NODE * query_stmt);
static int check_insert_value_nodes (PARSER_CONTEXT * parser, PT_NODE * node);
static int handle_name_node (PARSER_CONTEXT * parser, PT_NODE * node);
static int check_trigger_correlation_names (const char *name);
static int handle_expr_node (PARSER_CONTEXT * parser, PT_NODE * node);
typedef struct
{
int norder;
Expand Down Expand Up @@ -3089,6 +3093,12 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
parser_walk_leaves (parser, node, pt_bind_names, bind_arg, pt_bind_names_post, bind_arg);
}

if (pt_has_error (parser) ||
check_insert_value_nodes (parser, node->info.insert.value_clauses->info.node_list.list) != NO_ERROR)
{
goto insert_end;
}

/* Check for double assignments */
pt_no_double_insert_assignments (parser, node);
if (pt_has_error (parser))
Expand Down Expand Up @@ -11847,6 +11857,69 @@ pt_gather_dblink_colums (PARSER_CONTEXT * parser, PT_NODE * query_stmt)
}
}

static int
check_insert_value_nodes (PARSER_CONTEXT * parser, PT_NODE * list)
{
int error = NO_ERROR;
PT_NODE_TYPE node_type = PT_NODE_NONE;

while (list && error == NO_ERROR)
{
node_type = list->node_type;

if (node_type == PT_NAME && list->info.name.meta_class == PT_NORMAL)
{
error = handle_name_node (parser, list);
}
else if (node_type == PT_EXPR)
{
error = handle_expr_node (parser, list);
}
list = list->next;
}

return error;
}

static int
handle_name_node (PARSER_CONTEXT * parser, PT_NODE * node)
{
int error = NO_ERROR;
short flag = node->info.name.flag;

if (flag & PT_NAME_INFO_DOT_NAME)
{
error = check_trigger_correlation_names (node->info.name.resolved);
}
else
{
error = (flag & PT_NAME_DEFAULTF_ACCEPTS) && (!(flag & PT_NAME_INFO_FILL_DEFAULT)) ? ER_FAILED : NO_ERROR;
}

if (error == ER_FAILED)
{
PT_ERRORm (parser, node, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_COLUMN_NOT_ALLOWED);
}

return error;
}

static int
check_trigger_correlation_names (const char *name)
{
return strcmp (name, "new") == 0 || strcmp (name, "old") == 0 || strcmp (name, "obj") == 0 ? NO_ERROR : ER_FAILED;
}

static int
handle_expr_node (PARSER_CONTEXT * parser, PT_NODE * node)
{
int check_arg1 = check_insert_value_nodes (parser, node->info.expr.arg1);
int check_arg2 = check_insert_value_nodes (parser, node->info.expr.arg2);

return (check_arg1 == NO_ERROR && check_arg2 == NO_ERROR) ? NO_ERROR : ER_FAILED;
}


PT_NODE *
pt_check_dblink_query (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
Expand Down
1 change: 1 addition & 0 deletions src/parser/parser_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@
#define MSGCAT_SEMANTIC_UNDEFINED_TABLE_COLUMN MSGCAT_SEMANTIC_NO(322)
#define MSGCAT_SEMANTIC_SP_OUT_ARGS_EXISTS_IN_QUERY MSGCAT_SEMANTIC_NO(323)
#define MSGCAT_SEMANTIC_SP_INTO_FIELD_EXPR_IN_NON_STATIC_SQL MSGCAT_SEMANTIC_NO(324)
#define MSGCAT_SEMANTIC_COLUMN_NOT_ALLOWED MSGCAT_SEMANTIC_NO(325)

/* Message id in the set MSGCAT_SET_PARSER_RUNTIME */
#define MSGCAT_RUNTIME_NO(n) n
Expand Down
Loading