mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 02:03:04 +01:00
Implemented CREATE OR ALTER statement for procedures/triggers/views.
This commit is contained in:
parent
33db541f18
commit
b45eb004a2
@ -20,7 +20,7 @@
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
*
|
||||
* $Id: ddl.cpp,v 1.11 2002-08-11 08:04:52 dimitr Exp $
|
||||
* $Id: ddl.cpp,v 1.12 2002-08-27 07:48:33 dimitr Exp $
|
||||
* 2001.5.20 Claudio Valderrama: Stop null pointer that leads to a crash,
|
||||
* caused by incomplete yacc syntax that allows ALTER DOMAIN dom SET;
|
||||
*
|
||||
@ -367,13 +367,17 @@ int DDL_ids(REQ request)
|
||||
}
|
||||
|
||||
if (ddl_node->nod_type == nod_def_view ||
|
||||
ddl_node->nod_type == nod_mod_view ||
|
||||
ddl_node->nod_type == nod_replace_view ||
|
||||
ddl_node->nod_type == nod_def_constraint ||
|
||||
ddl_node->nod_type == nod_def_trigger ||
|
||||
ddl_node->nod_type == nod_mod_trigger ||
|
||||
ddl_node->nod_type == nod_replace_trigger ||
|
||||
ddl_node->nod_type == nod_def_procedure ||
|
||||
ddl_node->nod_type == nod_def_computed ||
|
||||
ddl_node->nod_type == nod_mod_procedure ||
|
||||
ddl_node->nod_type == nod_redef_procedure) {
|
||||
ddl_node->nod_type == nod_mod_procedure ||
|
||||
ddl_node->nod_type == nod_replace_procedure ||
|
||||
ddl_node->nod_type == nod_redef_procedure) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -2258,12 +2262,25 @@ static void define_procedure( REQ request, NOD_TYPE op)
|
||||
NOD procedure_node = request->req_ddl_node;
|
||||
STR procedure_name = (STR) procedure_node->nod_arg[e_prc_name];
|
||||
|
||||
if (op == nod_def_procedure || op == nod_redef_procedure) {
|
||||
if (op == nod_replace_procedure)
|
||||
{
|
||||
if (METD_get_procedure(request, procedure_name))
|
||||
{
|
||||
define_procedure(request, nod_mod_procedure);
|
||||
}
|
||||
else
|
||||
{
|
||||
define_procedure(request, nod_def_procedure);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (op == nod_def_procedure || op == nod_redef_procedure)
|
||||
{
|
||||
request->append_cstring(gds_dyn_def_procedure,
|
||||
reinterpret_cast<char*>(procedure_name->str_data));
|
||||
request->append_number(gds_dyn_rel_sql_protection, 1);
|
||||
}
|
||||
else
|
||||
else // op == nod_mod_procedure
|
||||
{
|
||||
request->append_cstring(gds_dyn_mod_procedure,
|
||||
reinterpret_cast<char*>(procedure_name->str_data));
|
||||
@ -2709,7 +2726,22 @@ static void define_trigger( REQ request, NOD node)
|
||||
|
||||
STR trigger_name = (STR) node->nod_arg[e_trg_name];
|
||||
|
||||
if (node->nod_type == nod_def_trigger)
|
||||
if (node->nod_type == nod_replace_view)
|
||||
{
|
||||
if (METD_get_trigger_relation(request,
|
||||
trigger_name,
|
||||
&trig_type))
|
||||
{
|
||||
node->nod_type = nod_mod_trigger;
|
||||
}
|
||||
else
|
||||
{
|
||||
node->nod_type = nod_def_trigger;
|
||||
}
|
||||
define_trigger(request, node);
|
||||
return;
|
||||
}
|
||||
else if (node->nod_type == nod_def_trigger)
|
||||
{
|
||||
assert(trigger_name->str_length <= MAX_USHORT);
|
||||
request->append_string( gds_dyn_def_trigger,
|
||||
@ -2723,9 +2755,8 @@ static void define_trigger( REQ request, NOD node)
|
||||
(USHORT) relation_name->str_length);
|
||||
request->append_uchar(gds_dyn_sql_object);
|
||||
}
|
||||
else
|
||||
{ /* if (node->nod_type == nod_mod_trigger) */
|
||||
|
||||
else // nod_mod_trigger
|
||||
{
|
||||
assert(node->nod_type == nod_mod_trigger);
|
||||
assert(trigger_name->str_length <= MAX_USHORT);
|
||||
request->append_string( gds_dyn_mod_trigger,
|
||||
@ -3295,14 +3326,26 @@ static void define_view( REQ request, NOD_TYPE op)
|
||||
node = request->req_ddl_node;
|
||||
view_name = (STR) node->nod_arg[e_view_name];
|
||||
|
||||
if (op == nod_def_view)
|
||||
if (op == nod_replace_view)
|
||||
{
|
||||
if (METD_get_relation(request, view_name))
|
||||
{
|
||||
define_view(request, nod_mod_view);
|
||||
}
|
||||
else
|
||||
{
|
||||
define_view(request, nod_def_view);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (op == nod_def_view)
|
||||
{
|
||||
request->append_cstring(gds_dyn_def_view,
|
||||
reinterpret_cast<char*>(view_name->str_data));
|
||||
request->append_number(gds_dyn_rel_sql_protection, 1);
|
||||
save_relation(request, view_name);
|
||||
}
|
||||
else // nod_mod_view
|
||||
else // op == nod_mod_view
|
||||
{
|
||||
request->append_cstring(gds_dyn_mod_view,
|
||||
reinterpret_cast<char*>(view_name->str_data));
|
||||
@ -3982,6 +4025,7 @@ static void generate_dyn( REQ request, NOD node)
|
||||
|
||||
case nod_def_view:
|
||||
case nod_mod_view:
|
||||
case nod_replace_view:
|
||||
define_view(request, node->nod_type);
|
||||
break;
|
||||
|
||||
@ -3993,6 +4037,7 @@ static void generate_dyn( REQ request, NOD node)
|
||||
|
||||
case nod_def_procedure:
|
||||
case nod_mod_procedure:
|
||||
case nod_replace_procedure:
|
||||
define_procedure(request, node->nod_type);
|
||||
break;
|
||||
|
||||
@ -4010,6 +4055,7 @@ static void generate_dyn( REQ request, NOD node)
|
||||
|
||||
case nod_def_trigger:
|
||||
case nod_mod_trigger:
|
||||
case nod_replace_trigger:
|
||||
define_trigger(request, node);
|
||||
break;
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
$Id: dsql.cpp,v 1.19 2002-08-03 15:27:20 dimitr Exp $
|
||||
$Id: dsql.cpp,v 1.20 2002-08-27 07:48:33 dimitr Exp $
|
||||
*/
|
||||
/**************************************************************
|
||||
V4 Multi-threading changes.
|
||||
@ -1929,6 +1929,12 @@ void DSQL_pretty(NOD node, int column)
|
||||
case nod_def_view:
|
||||
verb = "define view";
|
||||
break;
|
||||
case nod_mod_view:
|
||||
verb = "modify view";
|
||||
break;
|
||||
case nod_replace_view:
|
||||
verb = "replace view";
|
||||
break;
|
||||
case nod_delete:
|
||||
verb = "delete";
|
||||
break;
|
||||
@ -1954,6 +1960,12 @@ void DSQL_pretty(NOD node, int column)
|
||||
case nod_def_procedure:
|
||||
verb = "define procedure";
|
||||
break;
|
||||
case nod_mod_procedure:
|
||||
verb = "modify procedure";
|
||||
break;
|
||||
case nod_replace_procedure:
|
||||
verb = "replace procedure";
|
||||
break;
|
||||
/* CVC: New node redef_procedure. */
|
||||
case nod_redef_procedure:
|
||||
verb = "redefine procedure";
|
||||
@ -1967,6 +1979,9 @@ void DSQL_pretty(NOD node, int column)
|
||||
case nod_mod_trigger:
|
||||
verb = "modify trigger";
|
||||
break;
|
||||
case nod_replace_trigger:
|
||||
verb = "replace trigger";
|
||||
break;
|
||||
case nod_del_trigger:
|
||||
verb = "delete trigger";
|
||||
break;
|
||||
|
@ -318,7 +318,10 @@ typedef ENUM nod_t
|
||||
nod_searched_case, /* searched CASE function */
|
||||
nod_simple_case, /* simple CASE function */
|
||||
nod_coalesce, /* COALESCE function */
|
||||
nod_mod_view /* ALTER VIEW */
|
||||
nod_mod_view, /* ALTER VIEW */
|
||||
nod_replace_procedure, /* REPLACE PROCEDURE */
|
||||
nod_replace_trigger, /* REPLACE TRIGGER */
|
||||
nod_replace_view /* REPLACE VIEW */
|
||||
} NOD_TYPE;
|
||||
|
||||
|
||||
|
6716
src/dsql/parse.cpp
6716
src/dsql/parse.cpp
File diff suppressed because it is too large
Load Diff
@ -450,6 +450,7 @@ statement : alter
|
||||
| insert
|
||||
| invoke_procedure
|
||||
| recreate
|
||||
| replace
|
||||
| revoke
|
||||
| rollback
|
||||
| select
|
||||
@ -762,7 +763,20 @@ recreate_clause : PROCEDURE rprocedure_clause
|
||||
| DOMAIN rdomain_clause
|
||||
{ $$ = $2; }
|
||||
*/
|
||||
;
|
||||
;
|
||||
|
||||
replace : CREATE OR ALTER replace_clause
|
||||
{ $$ = $4; }
|
||||
;
|
||||
|
||||
replace_clause : PROCEDURE replace_procedure_clause
|
||||
{ $$ = $2; }
|
||||
| TRIGGER replace_trigger_clause
|
||||
{ $$ = $2; }
|
||||
| VIEW replace_view_clause
|
||||
{ $$ = $2; }
|
||||
;
|
||||
|
||||
|
||||
/* CREATE INDEX */
|
||||
|
||||
@ -1327,6 +1341,17 @@ rprocedure_clause : symbol_procedure_name input_parameters
|
||||
$1, $2, $3, $6, $7, $8, NULL); }
|
||||
;
|
||||
|
||||
replace_procedure_clause : symbol_procedure_name input_parameters
|
||||
output_parameters
|
||||
AS begin_string
|
||||
var_declaration_list
|
||||
full_proc_block
|
||||
end_trigger
|
||||
{ $$ = make_node (nod_replace_procedure,
|
||||
(int) e_prc_count,
|
||||
$1, $2, $3, $6, $7, $8, NULL); }
|
||||
;
|
||||
|
||||
alter_procedure_clause : symbol_procedure_name input_parameters
|
||||
output_parameters
|
||||
AS begin_string
|
||||
@ -1570,12 +1595,18 @@ rview_clause : symbol_view_name column_parens_opt AS begin_string union_view
|
||||
;
|
||||
*/
|
||||
|
||||
replace_view_clause : symbol_view_name column_parens_opt AS begin_string union_view
|
||||
check_opt end_string
|
||||
{ $$ = make_node (nod_replace_view, (int) e_view_count,
|
||||
$1, $2, $5, $6, $7); }
|
||||
;
|
||||
|
||||
alter_view_clause : symbol_view_name column_parens_opt AS begin_string union_view
|
||||
end_string
|
||||
check_opt end_string
|
||||
{ $$ = make_node (nod_mod_view, (int) e_view_count,
|
||||
$1, $2, $5, NULL, $6); }
|
||||
$1, $2, $5, $6, $7); }
|
||||
;
|
||||
|
||||
|
||||
union_view : union_view_expr
|
||||
{ $$ = make_node (nod_select, (int) 2, $1, NULL); }
|
||||
;
|
||||
@ -1665,6 +1696,17 @@ def_trigger_clause : symbol_trigger_name FOR simple_table_name
|
||||
$1, $3, $4, $5, $6, $8, $9, NULL); }
|
||||
;
|
||||
|
||||
replace_trigger_clause : symbol_trigger_name FOR simple_table_name
|
||||
trigger_active
|
||||
trigger_type
|
||||
trigger_position
|
||||
begin_trigger
|
||||
trigger_action
|
||||
end_trigger
|
||||
{ $$ = make_node (nod_replace_trigger, (int) e_trg_count,
|
||||
$1, $3, $4, $5, $6, $8, $9, NULL); }
|
||||
;
|
||||
|
||||
trigger_active : ACTIVE
|
||||
{ $$ = MAKE_constant ((STR) 0, CONSTANT_SLONG); }
|
||||
| INACTIVE
|
||||
|
@ -934,6 +934,7 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag)
|
||||
case nod_def_exception:
|
||||
case nod_mod_relation:
|
||||
case nod_mod_view:
|
||||
case nod_replace_view:
|
||||
case nod_mod_exception:
|
||||
case nod_del_relation:
|
||||
case nod_del_view:
|
||||
@ -963,6 +964,7 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag)
|
||||
|
||||
case nod_def_trigger:
|
||||
case nod_mod_trigger:
|
||||
case nod_replace_trigger:
|
||||
case nod_del_trigger:
|
||||
request->req_type = REQ_DDL;
|
||||
request->req_flags |= REQ_procedure;
|
||||
@ -977,6 +979,7 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag)
|
||||
case nod_def_procedure:
|
||||
case nod_redef_procedure:
|
||||
case nod_mod_procedure:
|
||||
case nod_replace_procedure:
|
||||
request->req_type = REQ_DDL;
|
||||
request->req_flags |= REQ_procedure;
|
||||
|
||||
@ -1093,8 +1096,10 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag)
|
||||
(procedure->nod_type == nod_def_procedure ||
|
||||
procedure->nod_type == nod_redef_procedure ||
|
||||
procedure->nod_type == nod_mod_procedure ||
|
||||
procedure->nod_type == nod_def_trigger ||
|
||||
procedure->nod_type == nod_mod_trigger )) {
|
||||
procedure->nod_type == nod_replace_procedure ||
|
||||
procedure->nod_type == nod_def_trigger ||
|
||||
procedure->nod_type == nod_mod_trigger ||
|
||||
procedure->nod_type == nod_replace_trigger )) {
|
||||
cursor->nod_arg[e_cur_next] = procedure->nod_arg[e_prc_cursors];
|
||||
procedure->nod_arg[e_prc_cursors] = cursor;
|
||||
cursor->nod_arg[e_cur_context] = node;
|
||||
@ -1126,10 +1131,12 @@ NOD PASS1_statement(REQ request, NOD input, USHORT proc_flag)
|
||||
|
||||
if (cursor && procedure
|
||||
&& (procedure->nod_type == nod_def_procedure ||
|
||||
procedure->nod_type == nod_redef_procedure ||
|
||||
procedure->nod_type == nod_mod_procedure ||
|
||||
procedure->nod_type == nod_def_trigger ||
|
||||
procedure->nod_type == nod_mod_trigger))
|
||||
procedure->nod_type == nod_redef_procedure ||
|
||||
procedure->nod_type == nod_mod_procedure ||
|
||||
procedure->nod_type == nod_replace_procedure ||
|
||||
procedure->nod_type == nod_def_trigger ||
|
||||
procedure->nod_type == nod_mod_trigger ||
|
||||
procedure->nod_type == nod_replace_trigger))
|
||||
procedure->nod_arg[e_prc_cursors] = cursor->nod_arg[e_cur_next];
|
||||
|
||||
if (request->req_error_handlers &&
|
||||
@ -4485,11 +4492,14 @@ static NOD pass1_variable( REQ request, NOD input)
|
||||
(procedure_node->nod_type == nod_def_procedure ||
|
||||
procedure_node->nod_type == nod_redef_procedure ||
|
||||
procedure_node->nod_type == nod_mod_procedure ||
|
||||
procedure_node->nod_type == nod_replace_procedure ||
|
||||
procedure_node->nod_type == nod_def_trigger ||
|
||||
procedure_node->nod_type == nod_mod_trigger)) {
|
||||
procedure_node->nod_type == nod_mod_trigger ||
|
||||
procedure_node->nod_type == nod_replace_trigger)) {
|
||||
if (procedure_node->nod_type == nod_def_procedure ||
|
||||
procedure_node->nod_type == nod_redef_procedure ||
|
||||
procedure_node->nod_type == nod_mod_procedure) {
|
||||
procedure_node->nod_type == nod_redef_procedure ||
|
||||
procedure_node->nod_type == nod_mod_procedure ||
|
||||
procedure_node->nod_type == nod_replace_procedure) {
|
||||
/* Try to resolve variable name against input, output
|
||||
and local variables */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user