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-25352] Add a user schema to your stored procedures for consistency with other objects #5258

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
76f3145
Merge the code from the main development branch (CBRD-25352) into the…
Jun 14, 2024
1ce9ff5
Modify to execute the CALL PROCEDURE/FUNCTION statement correctly. Ad…
Jun 18, 2024
fab738a
Modify to execute the SELECT PROCEDURE/FUNCTION statement correctly. …
Jun 19, 2024
b2ade1d
Merge commit 'f101fbc9c' into feature/plcsql-CBRD-25352
Jun 19, 2024
95a96e0
1) Add unique_name to sp_info object to find pl/casl system stored pr…
Jun 21, 2024
1aeb682
1) Resolving the issue where the OWNER is changed to the current sess…
Jun 21, 2024
6f190ca
Modify the if-statement in the case PT_METHOD_CALL: part of pt_bind_n…
Jun 28, 2024
f90eab9
Merge branch 'goodone' into feature/plcsql-CBRD-25352
Jul 3, 2024
4fabc96
1) Modified the logic to allow for separate execution of SP and Metho…
Jul 3, 2024
1a797f1
Merge commit 'fe9cd5192' into feature/plcsql-CBRD-25352
Jul 4, 2024
c658a6c
dba 와 dba 그룹 이외 사용자가 다른 사용자의 CREATE PROCEDURE/FUNCTION 구문을 사용할 경우 에러가…
Jul 5, 2024
e2d51a1
1) test_sql 에서 error가 발생하는 case 수정(trigger_action, query_spec), 2) sy…
Jul 9, 2024
54be451
pt_bind_names()에서 다음과 같은 이유로 [user_schema]를 다시 제거되도록 수정함. 첫 번째 arg_li…
Jul 10, 2024
170b14c
1) ALTER PROCEDURE/FUNCTION 구문에서 OWNER TO 없이 수행시 unique_name의 값이 empt…
Jul 11, 2024
df41f70
[Rollback] PT_FUNCTION 노드를 수행시 generic_name 값은 사용자가 입력한 그대로 출력하게 수정 e…
Jul 11, 2024
aca5193
name_resolution 파일에 오타 수정
Jul 11, 2024
f869886
name_resolution 파일에 누락된 if-statement 추가
Jul 11, 2024
c0fa0ff
sp_param_def 토큰 내부의 sp_param_type 토큰 위치에 data_type 토큰이 잘못 사용되었기 때문에 d…
Jul 15, 2024
f8ab9a0
Merge commit 'c18553564' into feature/plcsql-CBRD-25352
Jul 15, 2024
61fb31e
Merge commit 'ca9beeff5' into feature/plcsql-CBRD-25352
Jul 15, 2024
b9cae15
Fixed an error where the next value of the PT_DOT node is missing
Jul 16, 2024
fc2d58a
1) The procedure_name and function_name tokens were merged into a pro…
Jul 17, 2024
89d439b
Merge remote-tracking branch 'upstream/feature/plcsql-p1n' into featu…
Jul 19, 2024
df4f051
Add dbms_output user_schema to CALL enable and CALL disalbe related t…
Jul 19, 2024
5694430
I modified it by referring to the code review.
Jul 22, 2024
bbdd267
1) I modified it by referring to the code review. 2) The unique_name …
Jul 23, 2024
4ac8596
Merge commit '59c98d544' into feature/plcsql-CBRD-25352
Jul 23, 2024
01ba477
The maximum length of the identifier name that includes the user_sche…
Jul 24, 2024
fd1de0c
Merge commit '5ae12df82' into feature/plcsql-CBRD-25352
Jul 29, 2024
0572d68
Reflecting the code review content and adding a part to change the un…
Jul 29, 2024
b7482bb
There was a part where the ; (semicolon) was omitted, so I corrected it.
Jul 29, 2024
c6ae8b8
1) Modify sp_name to be downcased in pl/csql, 2) We previously used s…
Jul 31, 2024
45d26fd
We added that part by omitting the length value of the NULL terminati…
Jul 31, 2024
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
6 changes: 3 additions & 3 deletions src/executables/csql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,11 +1541,11 @@ csql_set_server_output (CSQL_ARGUMENT * csql_arg, bool server_output)
csql_arg->pl_server_output = server_output;
if (server_output)
{
csql_execute_query ("CALL enable (50000);");
csql_execute_query ("CALL dbms_output.enable (50000);");
}
else
{
csql_execute_query ("CALL disable ();");
csql_execute_query ("CALL dbms_output.disable ();");
}
}

Expand Down Expand Up @@ -1845,7 +1845,7 @@ csql_print_server_output (const CSQL_ARGUMENT * csql_arg)

do
{
errors = csql_execute_query ("CALL get_line (:pl_output_str, :pl_output_status);");
errors = csql_execute_query ("CALL dbms_output.get_line (:pl_output_str, :pl_output_status);");
if (errors != 0)
{
break;
Expand Down
36 changes: 35 additions & 1 deletion src/object/authenticate_owner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,16 @@ au_change_sp_owner (MOP sp, MOP owner)
{
int error = NO_ERROR;
int save;
DB_VALUE value;
const char *name_str = NULL, *owner_str = NULL;
char new_name_str[DB_MAX_IDENTIFIER_LENGTH];
new_name_str[0]= '\0';
char downcase_owner_name[DB_MAX_USER_LENGTH];
downcase_owner_name[0] = '\0';
DB_VALUE value, name_value, owner_value;

db_make_null (&value);
db_make_null (&name_value);
db_make_null (&owner_value);

AU_DISABLE (save);
if (!au_is_dba_group_member (Au_user))
Expand All @@ -488,6 +497,31 @@ au_change_sp_owner (MOP sp, MOP owner)
}
else
{
error = obj_get (sp, "sp_name", &name_value);
if (error != NO_ERROR)
{
goto end;
}
error = obj_get (owner, "name", &owner_value);
if (error != NO_ERROR)
{
goto end;
}

name_str = db_get_string (&name_value);
owner_str = db_get_string (&owner_value);

sm_downcase_name (owner_str, downcase_owner_name, DB_MAX_USER_LENGTH);
sprintf (new_name_str, "%s.%s", downcase_owner_name, name_str);

/* change the unique_name */
db_make_string (&value, new_name_str);
error = obj_set (sp, SP_ATTR_UNIQUE_NAME, &value);
if (error < 0)
{
goto end;
}

db_make_object (&value, owner);
error = obj_set (sp, SP_ATTR_OWNER, &value);
if (error < 0)
Expand Down
8 changes: 5 additions & 3 deletions src/object/schema_system_catalog_install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ namespace cubschema
CT_STORED_PROC_NAME,
// columns
{
{"unique_name", format_varchar (255)},
{"sp_name", format_varchar (255)},
{"sp_type", "integer"},
{"return_type", "integer"},
Expand All @@ -847,7 +848,7 @@ namespace cubschema
},
// constraints
{
{DB_CONSTRAINT_UNIQUE, "", {"sp_name", nullptr}, false},
{DB_CONSTRAINT_PRIMARY_KEY, "pk_db_stored_procedure_unique_name", {"unique_name", nullptr}, false}
},
// authorization
{
Expand All @@ -868,7 +869,7 @@ namespace cubschema
CT_STORED_PROC_ARGS_NAME,
// columns
{
{"sp_name", format_varchar (255)},
{"sp_of", CT_STORED_PROC_NAME},
{"pkg_name", format_varchar (255)},
{"index_of", "integer"},
{"is_system_generated", "integer"},
Expand All @@ -881,7 +882,7 @@ namespace cubschema
},
// constraints
{
{DB_CONSTRAINT_INDEX, "", {"sp_name", nullptr}, false},
{DB_CONSTRAINT_INDEX, "", {"sp_of", nullptr}, false},
},
// authorization
{
Expand Down Expand Up @@ -1844,6 +1845,7 @@ namespace cubschema
// columns
{
{"sp_name", "varchar(255)"},
{"owner_name", "varchar(255)"},
{"pkg_name", "varchar (255)"},
{"index_of", "integer"},
{"arg_name", "varchar(255)"},
Expand Down
5 changes: 3 additions & 2 deletions src/object/schema_system_catalog_install_query_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,8 @@ sm_define_view_stored_procedure_arguments_spec (void)
// *INDENT-OFF*
sprintf (stmt,
"SELECT "
"[sp].[sp_name] AS [sp_name], "
"[sp].[sp_of].[sp_name] AS [sp_name], "
"CAST ([sp].[sp_of].[owner].[name] AS VARCHAR(255)) AS [sp_owner_name], " /* string -> varchar(255) */
"[sp].[pkg_name] AS [pkg_name], "
"[sp].[index_of] AS [index_of], "
"[sp].[arg_name] AS [arg_name], "
Expand All @@ -1212,7 +1213,7 @@ sm_define_view_stored_procedure_arguments_spec (void)
"[%s] AS [sp] "
"WHERE [sp].[is_system_generated] = 0 "
"ORDER BY " /* Is it possible to remove ORDER BY? */
"[sp].[sp_name], "
"[sp].[sp_of].[sp_name], "
"[sp].[index_of]",
CT_DATATYPE_NAME,
CT_STORED_PROC_ARGS_NAME);
Expand Down
72 changes: 59 additions & 13 deletions src/parser/csql_grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@ static char *g_plcsql_text;
%type <node> serial_name
%type <node> synonym_name_without_dot
%type <node> synonym_name
%type <node> procedure_or_function_name_without_dot
%type <node> procedure_or_function_name
%type <node> procedure_or_function_name_list
%type <node> opt_alter_synonym
%type <node> opt_identifier
%type <node> normal_or_class_attr_list_with_commas
Expand Down Expand Up @@ -3063,7 +3066,8 @@ create_stmt
push_msg(MSGCAT_SYNTAX_INVALID_CREATE_PROCEDURE);
expecting_pl_lang_spec = 1;
}
identifier opt_sp_param_list /* 5, 6 */
procedure_or_function_name_without_dot /* 5 */
opt_sp_param_list /* 6 */
opt_authid /* 7 */
is_or_as pl_language_spec /* 8, 9 */
opt_comment_spec /* 10 */
Expand Down Expand Up @@ -3096,7 +3100,8 @@ create_stmt
push_msg(MSGCAT_SYNTAX_INVALID_CREATE_FUNCTION);
expecting_pl_lang_spec = 1;
}
identifier opt_sp_param_list /* 5, 6 */
procedure_or_function_name_without_dot /* 5 */
opt_sp_param_list /* 6 */
RETURN sp_return_type /* 7, 8 */
opt_authid /* 9 */
is_or_as pl_language_spec /* 10, 11 */
Expand Down Expand Up @@ -4092,10 +4097,10 @@ alter_stmt
DBG_PRINT}}
| ALTER /* 1 */
procedure_or_function /* 2 */
identifier /* 3 */
opt_owner_clause /* 4 */
opt_comment_spec /* 5 */
{{ DBG_TRACE_GRAMMAR(alter_stmt, | ALTER procedure_or_function identifier opt_owner_clause opt_comment_spec);
procedure_or_function_name /* 3 */
opt_owner_clause /* 4 */
opt_comment_spec /* 5 */
{{ DBG_TRACE_GRAMMAR(alter_stmt, | ALTER procedure_or_function procedure_or_function_name opt_owner_clause opt_comment_spec);

PT_NODE *node = parser_new_node (this_parser, PT_ALTER_STORED_PROCEDURE);

Expand Down Expand Up @@ -4671,8 +4676,8 @@ drop_stmt
PARSER_SAVE_ERR_CONTEXT ($$, @$.buffer_pos)

DBG_PRINT}}
| DROP PROCEDURE identifier_list
{{ DBG_TRACE_GRAMMAR(drop_stmt, | DROP PROCEDURE identifier_list);
| DROP PROCEDURE procedure_or_function_name_list
{{ DBG_TRACE_GRAMMAR(drop_stmt, | DROP PROCEDURE procedure_or_function_name_list);

PT_NODE *node = parser_new_node (this_parser, PT_DROP_STORED_PROCEDURE);

Expand All @@ -4687,8 +4692,8 @@ drop_stmt
PARSER_SAVE_ERR_CONTEXT ($$, @$.buffer_pos)

DBG_PRINT}}
| DROP FUNCTION identifier_list
{{ DBG_TRACE_GRAMMAR(drop_stmt, | DROP FUNCTION identifier_list);
| DROP FUNCTION procedure_or_function_name_list
{{ DBG_TRACE_GRAMMAR(drop_stmt, | DROP FUNCTION procedure_or_function_name_list);

PT_NODE *node = parser_new_node (this_parser, PT_DROP_STORED_PROCEDURE);

Expand Down Expand Up @@ -5882,6 +5887,37 @@ synonym_name
}
;

procedure_or_function_name_without_dot
: user_specified_name_without_dot
{ DBG_TRACE_GRAMMAR(procedure_or_function_name_without_dot, : user_specified_name_without_dot);
$$ = $1;
}
;

procedure_or_function_name
: user_specified_name
{ DBG_TRACE_GRAMMAR(procedure_or_function_name, : user_specified_name);
$$ = $1;
}
;

procedure_or_function_name_list
: procedure_or_function_name_list ',' procedure_or_function_name
{{ DBG_TRACE_GRAMMAR(procedure_or_function_name_list, : procedure_or_function_name_list ',' procedure_or_function_name);

ctshim marked this conversation as resolved.
Show resolved Hide resolved
$$ = parser_make_link($1, $3);
PARSER_SAVE_ERR_CONTEXT ($$, @$.buffer_pos)

DBG_PRINT}}
| procedure_or_function_name
{{ DBG_TRACE_GRAMMAR(procedure_or_function_name_list, : procedure_or_function_name);

ctshim marked this conversation as resolved.
Show resolved Hide resolved
$$ = $1;
PARSER_SAVE_ERR_CONTEXT ($$, @$.buffer_pos)

DBG_PRINT}}
;

opt_partition_spec
: /* empty */
{{ DBG_TRACE_GRAMMAR(opt_partition_spec, : );
Expand Down Expand Up @@ -19351,7 +19387,7 @@ generic_function
;

generic_function_for_call
: identifier
: procedure_or_function_name
{
if(pwd_info.parser_call_check)
{
Expand All @@ -19366,8 +19402,7 @@ generic_function_for_call
}
}
'(' opt_expression_list_for_call ')' opt_on_target
{{ DBG_TRACE_GRAMMAR(generic_function_for_call, : identifier '(' opt_expression_list ')' opt_on_target );

{{ DBG_TRACE_GRAMMAR(generic_function_for_call, : procedure_or_function_name '(' opt_expression_list_for_call ')' opt_on_target );
PT_NODE *node = NULL;

if ($6 == NULL)
Expand All @@ -19384,6 +19419,17 @@ generic_function_for_call
node->info.method_call.method_name = $1;
node->info.method_call.arg_list = $4;
node->info.method_call.on_call_target = $6;
if (node->info.method_call.on_call_target != NULL)
{
PT_NAME_INFO_CLEAR_FLAG (node->info.method_call.method_name, PT_NAME_INFO_USER_SPECIFIED);
}
else
{
if (node->info.method_call.arg_list != NULL && node->info.method_call.arg_list->node_type == PT_NAME && node->info.method_call.arg_list->info.name.meta_class == PT_META_CLASS)
{
PT_NAME_INFO_CLEAR_FLAG (node->info.method_call.method_name, PT_NAME_INFO_USER_SPECIFIED);
}
}
node->info.method_call.call_or_expr = PT_IS_MTHD_EXPR;
}

Expand Down
72 changes: 68 additions & 4 deletions src/parser/name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,19 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
node->info.method_call.on_call_target = node->info.method_call.arg_list;
node->info.method_call.arg_list = node->info.method_call.arg_list->next;
node->info.method_call.on_call_target->next = NULL;

hyunikn marked this conversation as resolved.
Show resolved Hide resolved
/*
* When using a session variable in the first arg_list,
* It is unknown whether the session variable contains a class, object, or constant value.
* So, if it's not a Java stored procedure and there is an on_call_target, then it's considered a method and [user_schema] is removed.
*
* ex) create class x (xint int, xstr string, class cint int) method add_int(int, int) int function add_int file '$METHOD_FILE';
* insert into x values (4, 'string 4');
* select x into p1 from x where xint = 4;
* call add_int(p1, 1, 2);
*/
node->info.method_call.method_name->info.name.original =
sm_remove_qualifier_name (node->info.method_call.method_name->info.name.original);
}

/* make method name look resolved */
Expand Down Expand Up @@ -3286,9 +3299,7 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
node->info.method_call.method_name->info.name.spec_id = entity->info.spec.id;
}
}

}

break;

case PT_DATA_TYPE:
Expand Down Expand Up @@ -3345,6 +3356,49 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
{
node = temp;
}
else if (PT_CHECK_USER_SCHEMA_PROCEDURE_OR_FUNCTION (node))
{
/*
* jsp_is_exist_stored_procedure() could not be checked in pt_set_user_specified_name(), so it was checked in pt_bind_names().
* Created a temporary node in name.original to join user_schema(dot.arg1) and sp_name(dot.arg2).
*/
char downcase_owner_name[DB_MAX_USER_LENGTH];
downcase_owner_name[0] = '\0';
char *generic_name = NULL;

sm_downcase_name (node->info.dot.arg1->info.name.original, downcase_owner_name, DB_MAX_USER_LENGTH);
generic_name = pt_append_string (parser, downcase_owner_name, ".");
generic_name = pt_append_string (parser, generic_name, node->info.dot.arg2->info.function.generic_name);
node->info.dot.arg2->info.function.generic_name = generic_name;

if (jsp_is_exist_stored_procedure (node->info.dot.arg2->info.function.generic_name))
{
/*
* If (dot.arg1->node_type == PT_NAME) & (dot.arg2->node_type == PT_FUNCTION), pt_bind_name_or_path_in_scope() always returns NULL and has an er_errid() value.
*/
if (er_errid () == NO_ERROR)
ctshim marked this conversation as resolved.
Show resolved Hide resolved
{
pt_reset_error (parser);
}

node1 = pt_resolve_stored_procedure (parser, node->info.dot.arg2, bind_arg);
if (node1 == NULL)
{
break; // FIXME: something wrong
}
PT_NODE_COPY_NUMBER_OUTERLINK (node1, node);

PT_NODE_INIT_OUTERLINK (node);
parser_free_tree (parser, node);
node = node1; /* return the new node */
/* don't revisit leaves */
*continue_walk = PT_LIST_WALK;
}
else if (pt_has_error (parser))
{
return NULL;
}
}
else if (pt_has_error (parser))
{
return NULL;
Expand Down Expand Up @@ -3379,7 +3433,9 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
case PT_FUNCTION:
if (node->info.function.function_type == PT_GENERIC)
{
const char *generic_name = node->info.function.generic_name;
const char *dot = NULL;
const char *current_schema_name = NULL;
char buffer[SM_MAX_IDENTIFIER_LENGTH];
node->info.function.function_type = pt_find_function_type (node->info.function.generic_name);

if (node->info.function.function_type == PT_GENERIC)
Expand All @@ -3389,8 +3445,16 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
* nodes PT_FUNCTION. If so, pt_make_stored_procedure() and pt_make_method_call() will
* translate it into a method_call.
*/
if (jsp_is_exist_stored_procedure (generic_name))
if (jsp_is_exist_stored_procedure (node->info.function.generic_name))
{
dot = strchr (node->info.function.generic_name, '.');
if (dot == NULL)
{
current_schema_name = sc_current_schema_name ();
sprintf (buffer, "%s.%s", current_schema_name, node->info.function.generic_name);
node->info.function.generic_name = pt_append_string (parser, NULL, buffer);
}

node1 = pt_resolve_stored_procedure (parser, node, bind_arg);
}
else
Expand Down
6 changes: 6 additions & 0 deletions src/parser/parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ struct json_t;
|| (n->node_type == PT_UPDATE && n->info.update.spec->info.spec.remote_server_name) \
|| (n->node_type == PT_MERGE && n->info.merge.into->info.spec.remote_server_name))

#define PT_CHECK_USER_SCHEMA_PROCEDURE_OR_FUNCTION(n) \
hyunikn marked this conversation as resolved.
Show resolved Hide resolved
((n->info.dot.arg1->node_type == PT_NAME) \
&& (n->info.dot.arg2->node_type == PT_FUNCTION) \
&& (n->info.dot.arg2->info.function.function_type == PT_GENERIC) \
&& (strchr (n->info.dot.arg2->info.function.generic_name, '.') == NULL))

#if !defined (SERVER_MODE)
/* the following defines support host variable binding for internal statements.
internal statements can be generated on TEXT handling, and these statements
Expand Down
Loading
Loading