Skip to content

Commit

Permalink
635e3d9 merge 이후, 누락된 내용 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
jongmin-won committed Jul 3, 2024
1 parent 3f5ca09 commit 8140d1b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/parser/name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,6 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
short i, k, lhs_location, rhs_location, level;
PT_JOIN_TYPE join_type;
void *save_etc = NULL;
DB_VALUE value;

*continue_walk = PT_CONTINUE_WALK;

Expand Down Expand Up @@ -3299,7 +3298,6 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
}
}
}

break;

case PT_DATA_TYPE:
Expand Down
48 changes: 39 additions & 9 deletions src/sp/jsp_cl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jsp_find_stored_procedure (const char *name)

checked_name = jsp_check_stored_procedure_name (name);
db_make_string (&value, checked_name);
mop = db_find_unique (db_find_class (SP_CLASS_NAME), SP_ATTR_NAME, &value);
mop = db_find_unique (db_find_class (SP_CLASS_NAME), SP_ATTR_UNIQUE_NAME, &value);

if (er_errid () == ER_OBJ_OBJECT_NOT_FOUND)
{
Expand Down Expand Up @@ -647,6 +647,7 @@ int
jsp_create_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
{
const char *decl = NULL, *comment = NULL;
char owner_name[DB_MAX_USER_LENGTH] = { '\0' };

PT_NODE *param_list, *p;
PT_TYPE_ENUM ret_type = PT_TYPE_NONE;
Expand Down Expand Up @@ -675,7 +676,14 @@ jsp_create_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
return er_errid ();
}

sp_info.sp_name = PT_NODE_SP_NAME (statement);
sp_info.unique_name = jsp_check_stored_procedure_name (PT_NODE_SP_NAME (statement));
if (sp_info.unique_name.empty ())
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_INVALID_NAME, 0);
return er_errid ();
}

sp_info.sp_name = sm_remove_qualifier_name (sp_info.unique_name.data ());
if (sp_info.sp_name.empty ())
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_INVALID_NAME, 0);
Expand All @@ -697,7 +705,7 @@ jsp_create_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
param_list = PT_NODE_SP_ARGS (statement);
for (p = param_list; p != NULL; p = p->next)
{
SP_ARG_INFO arg_info (sp_info.sp_name, sp_info.pkg_name);
SP_ARG_INFO arg_info (sp_info.unique_name, sp_info.pkg_name);

arg_info.index_of = param_count++;
arg_info.arg_name = PT_NODE_SP_ARG_NAME (p);
Expand All @@ -722,7 +730,7 @@ jsp_create_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
// check # of args constraint
if (param_count > MAX_ARG_COUNT)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_TOO_MANY_ARG_COUNT, 1, sp_info.sp_name.data ());
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_TOO_MANY_ARG_COUNT, 1, sp_info.unique_name.data ());
goto error_exit;
}

Expand Down Expand Up @@ -773,7 +781,12 @@ jsp_create_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
}
}
sp_info.target = decl ? decl : "";
sp_info.owner = Au_user; // current user
if (sm_qualifier_name (sp_info.unique_name.data (), owner_name, DB_MAX_USER_LENGTH) == NULL)
{
ASSERT_ERROR ();
return NULL;
}
sp_info.owner = owner_name[0] == '\0' ? Au_user : db_find_user (owner_name);
sp_info.comment = (char *) PT_NODE_SP_COMMENT (statement);

if (err != NO_ERROR)
Expand All @@ -782,7 +795,7 @@ jsp_create_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
}

/* check already exists */
if (jsp_is_exist_stored_procedure (sp_info.sp_name.data ()))
if (jsp_is_exist_stored_procedure (sp_info.unique_name.data ()))
{
if (statement->info.sp.or_replace)
{
Expand All @@ -794,15 +807,15 @@ jsp_create_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
}
has_savepoint = true;

err = drop_stored_procedure (sp_info.sp_name.data (), sp_info.sp_type);
err = drop_stored_procedure (sp_info.unique_name.data (), sp_info.sp_type);
if (err != NO_ERROR)
{
goto error_exit;
}
}
else
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_ALREADY_EXIST, 1, sp_info.sp_name.data ());
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_ALREADY_EXIST, 1, sp_info.unique_name.data ());
goto error_exit;
}
}
Expand Down Expand Up @@ -862,6 +875,8 @@ jsp_alter_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
int err = NO_ERROR;
PT_NODE *sp_name = NULL, *sp_owner = NULL, *sp_comment = NULL;
const char *name_str = NULL, *owner_str = NULL, *comment_str = NULL;
char new_name_str[DB_MAX_IDENTIFIER_LENGTH] = { '\0' };
char downcase_owner_name[DB_MAX_USER_LENGTH] = { '\0' };
PT_MISC_TYPE type;
SP_TYPE_ENUM real_type;
MOP sp_mop = NULL, new_owner = NULL;
Expand Down Expand Up @@ -946,6 +961,21 @@ jsp_alter_stored_procedure (PARSER_CONTEXT *parser, PT_NODE *statement)
goto error;
}

/* change the unique_name */
sm_downcase_name (owner_str, downcase_owner_name, DB_MAX_USER_LENGTH);
sprintf (new_name_str, "%s.%s", downcase_owner_name, sm_remove_qualifier_name (name_str));

if (new_name_str != NULL)
{
db_make_string (&user_val, new_name_str);
err = obj_set (sp_mop, SP_ATTR_UNIQUE_NAME, &user_val);
if (err < 0)
{
goto error;
}
pr_clear_value (&user_val);
}

/* change the owner */
if (sp_owner != NULL)
{
Expand Down Expand Up @@ -1046,7 +1076,7 @@ jsp_check_stored_procedure_name (const char *str)
char buffer[SM_MAX_IDENTIFIER_LENGTH + 2];
char *name = NULL;

sm_downcase_name (str, buffer, SM_MAX_IDENTIFIER_LENGTH);
sm_user_specified_name (str, buffer, SM_MAX_IDENTIFIER_LENGTH);
name = strdup (buffer);

return name;
Expand Down
2 changes: 2 additions & 0 deletions src/sp/sp_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define SP_ARG_CLASS_NAME "_db_stored_procedure_args"
#define SP_CODE_CLASS_NAME "_db_stored_procedure_code"

#define SP_ATTR_UNIQUE_NAME "unique_name"
#define SP_ATTR_NAME "sp_name"
#define SP_ATTR_SP_TYPE "sp_type"
#define SP_ATTR_RETURN_TYPE "return_type"
Expand All @@ -36,6 +37,7 @@
#define SP_ATTR_OWNER "owner"
#define SP_ATTR_COMMENT "comment"

#define SP_ATTR_SP_OF "sp_of"
#define SP_ATTR_ARG_NAME "arg_name"
#define SP_ATTR_INDEX_OF_NAME "index_of"
#define SP_ATTR_DATA_TYPE "data_type"
Expand Down

0 comments on commit 8140d1b

Please sign in to comment.