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 17 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
5 changes: 1 addition & 4 deletions msg/en_US.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1951,15 +1951,12 @@ $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 The argument specifying the language must be a string literal.

325 The argument specifying the language must be a string literal.
326 Stored procedure/function "%1$s" does not exist.
327 Attempting to assign DEFAULT on an Out parameter is not allowed: '%1$s'.
328 Only trailing default parameter is allowed: invalid at '%1$s'.
329 Grant option is not allowed for %1$s.


330 Column not allowed here

$set 9 MSGCAT_SET_PARSER_RUNTIME
1 Out of virtual memory: unable to allocate %1$d bytes.
Expand Down
5 changes: 1 addition & 4 deletions msg/ko_KR.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1950,15 +1950,12 @@ $set 8 MSGCAT_SET_PARSER_SEMANTIC
322 테이블 컬럼 '%1$s.%2$s'이 정의되지 않았습니다
323 저장 프로시저/함수 '%1$s' 이(가) OUT 또는 IN OUT 인수를 가지고 있습니다.
324 '%1$s'은 레코드 변수가 아닙니다.
325 언어를 지정하는 인수는 문자열 리터럴이어야 합니다.

325 언어를 지정하는 인수는 문자열 리터럴이어야 합니다.
326 저장 프로시저/함수 "%1$s"이(가) 존재하지 않습니다.
327 Out 매개변수에 DEFAULT를 할당하는 것은 허용되지 않습니다: '%1$s'.
328 오직 후행 기본 인수만 허용합니다: '%1$s' 에서 유효하지 않음.
329 %1$s에 대해 GRANT 옵션을 부여할 수 없습니다.


330 열을 사용할 수 없습니다

$set 9 MSGCAT_SET_PARSER_RUNTIME
1 가상 메모리 없음: %1$d 바이트를 할당할 수 없습니다.
Expand Down
6 changes: 3 additions & 3 deletions src/object/trigger_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ static const int TR_RETURN_TRUE = 1;

static const int TR_EST_MAP_SIZE = 1024;

static const char *OBJ_REFERENCE_NAME = "obj";
static const char *NEW_REFERENCE_NAME = "new";
static const char *OLD_REFERENCE_NAME = "old";
const char *OBJ_REFERENCE_NAME = "obj";
const char *NEW_REFERENCE_NAME = "new";
const char *OLD_REFERENCE_NAME = "old";

/*
* Formerly had a semicolon at the end, not sure that is acceptable since
Expand Down
4 changes: 4 additions & 0 deletions src/object/trigger_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ extern int tr_Recursion_level_max;
extern TR_TRIGLIST *tr_Deferred_triggers;
extern TR_TRIGLIST *tr_Deferred_triggers_tail;

extern const char *OBJ_REFERENCE_NAME;
extern const char *NEW_REFERENCE_NAME;
extern const char *OLD_REFERENCE_NAME;

/* INTERFACE FUNCTIONS */

/* Module control */
Expand Down
72 changes: 72 additions & 0 deletions src/parser/name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "db_json.hpp"

#include "dbtype.h"
#include "trigger_manager.h"

#ifndef DBDEF_HEADER_
#define DBDEF_HEADER_
Expand Down Expand Up @@ -256,6 +257,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 @@ -3096,6 +3101,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 @@ -11957,6 +11968,67 @@ 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;

while (list && error == NO_ERROR)
{
if (PT_NODE_IS_NAME (list) && list->info.name.meta_class == PT_NORMAL)
{
error = handle_name_node (parser, list);
}
else if (PT_NODE_IS_EXPR (list))
{
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;

if (PT_NAME_INFO_IS_FLAGED (node, PT_NAME_INFO_DOT_NAME))
{
error = check_trigger_correlation_names (node->info.name.resolved);
}
else
{
error = (PT_NAME_INFO_IS_FLAGED (node, PT_NAME_DEFAULTF_ACCEPTS) &&
!PT_NAME_INFO_IS_FLAGED (node, 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, OBJ_REFERENCE_NAME) == 0 || strcmp (name, NEW_REFERENCE_NAME) == 0
|| strcmp (name, OLD_REFERENCE_NAME) == 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
5 changes: 2 additions & 3 deletions src/parser/parser_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,12 @@
#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_NOT_SUPPORT_TYPE_TO_DATE_LANG MSGCAT_SEMANTIC_NO(325)

#define MSGCAT_SEMANTIC_NOT_SUPPORT_TYPE_TO_DATE_LANG MSGCAT_SEMANTIC_NO(325)
#define MSGCAT_SEMANTIC_NOT_SUPPORT_TYPE_TO_DATE_LANG MSGCAT_SEMANTIC_NO(325)
#define MSTCAT_SEMANTIC_SP_NOT_EXIST MSGCAT_SEMANTIC_NO(326)
#define MSGCAT_SEMANTIC_SP_OUT_DEFAULT_ARG_NOT_ALLOWED MSGCAT_SEMANTIC_NO(327)
#define MSGCAT_SEMANTIC_SP_NON_TRAILING_OPTIONAL_PARAMS MSGCAT_SEMANTIC_NO(328)
#define MSGCAT_SEMATNIC_AU_GRANT_OPTION_NOT_ALLOWED MSGCAT_SEMANTIC_NO(329)
#define MSGCAT_SEMANTIC_COLUMN_NOT_ALLOWED MSGCAT_SEMANTIC_NO(330)



Expand Down
Loading