mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 18:03:03 +01:00
Added the ability to change deterministic option (#7758)
* Added the ability to change deterministic option Added the ability to change deterministic opt without specifiying the entire body of the function. Extended "ALTER FUNCTION" syntax: ALTER FUNCTION <name> DETERMINISTIC; ALTER FUNCTION <name> NOT DETERMINISTIC; * added const qualifier to flag, removed nested if/else * added doc --------- Co-authored-by: Alexander Zhdanov <alexander.zhdanov@red-soft.ru>
This commit is contained in:
parent
effb648813
commit
5327ed835c
@ -603,3 +603,8 @@ ALTER TABLE <name> ... [ {ENABLE | DISABLE} PUBLICATION ]
|
|||||||
|
|
||||||
Defines whether replication is enabled for the specified table.
|
Defines whether replication is enabled for the specified table.
|
||||||
If not specified in the CREATE TABLE statement, the database-level default behaviour is applied.
|
If not specified in the CREATE TABLE statement, the database-level default behaviour is applied.
|
||||||
|
|
||||||
|
24) Added the ability to change deterministic option without specifying the entire body of the function.
|
||||||
|
(Alexander Zhdanov)
|
||||||
|
|
||||||
|
ALTER FUNCTION <name> {DETERMINISTIC | NOT DETERMINISTIC}
|
||||||
|
@ -1726,10 +1726,19 @@ void CreateAlterFunctionNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsql
|
|||||||
AutoSavePoint savePoint(tdbb, transaction);
|
AutoSavePoint savePoint(tdbb, transaction);
|
||||||
bool altered = false;
|
bool altered = false;
|
||||||
|
|
||||||
|
const bool alterIndividualParameters = !(body || external);
|
||||||
|
|
||||||
// first pass
|
// first pass
|
||||||
if (alter)
|
if (alter)
|
||||||
{
|
{
|
||||||
if (executeAlter(tdbb, dsqlScratch, transaction, false, true))
|
if (alterIndividualParameters)
|
||||||
|
{
|
||||||
|
if (executeAlterIndividualParameters(tdbb, dsqlScratch, transaction, false, true))
|
||||||
|
altered = true;
|
||||||
|
else
|
||||||
|
status_exception::raise(Arg::Gds(isc_dyn_func_not_found) << Arg::Str(name));
|
||||||
|
}
|
||||||
|
else if (executeAlter(tdbb, dsqlScratch, transaction, false, true))
|
||||||
{
|
{
|
||||||
altered = true;
|
altered = true;
|
||||||
}
|
}
|
||||||
@ -1746,7 +1755,12 @@ void CreateAlterFunctionNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsql
|
|||||||
|
|
||||||
compile(tdbb, dsqlScratch);
|
compile(tdbb, dsqlScratch);
|
||||||
|
|
||||||
executeAlter(tdbb, dsqlScratch, transaction, true, false); // second pass
|
// second pass
|
||||||
|
if (alterIndividualParameters)
|
||||||
|
executeAlterIndividualParameters(tdbb, dsqlScratch, transaction, true, false);
|
||||||
|
else
|
||||||
|
executeAlter(tdbb, dsqlScratch, transaction, true, false);
|
||||||
|
|
||||||
|
|
||||||
if (package.isEmpty())
|
if (package.isEmpty())
|
||||||
{
|
{
|
||||||
@ -2062,6 +2076,43 @@ bool CreateAlterFunctionNode::executeAlter(thread_db* tdbb, DsqlCompilerScratch*
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CreateAlterFunctionNode::executeAlterIndividualParameters(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction, bool secondPass, bool runTriggers)
|
||||||
|
{
|
||||||
|
Attachment* const attachment = transaction->getAttachment();
|
||||||
|
|
||||||
|
bool modifed = false;
|
||||||
|
|
||||||
|
AutoCacheRequest requestHandle(tdbb, drq_m_prm_funcs2, DYN_REQUESTS);
|
||||||
|
|
||||||
|
FOR (REQUEST_HANDLE requestHandle TRANSACTION_HANDLE transaction)
|
||||||
|
FUN IN RDB$FUNCTIONS
|
||||||
|
WITH FUN.RDB$FUNCTION_NAME EQ name.c_str() AND
|
||||||
|
FUN.RDB$PACKAGE_NAME EQUIV NULLIF(package.c_str(), '')
|
||||||
|
{
|
||||||
|
if (FUN.RDB$SYSTEM_FLAG)
|
||||||
|
{
|
||||||
|
status_exception::raise(
|
||||||
|
Arg::Gds(isc_dyn_cannot_mod_sysfunc) << MetaName(FUN.RDB$FUNCTION_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!secondPass && runTriggers && package.isEmpty())
|
||||||
|
{
|
||||||
|
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE,
|
||||||
|
DDL_TRIGGER_ALTER_FUNCTION, name, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
MODIFY FUN
|
||||||
|
FUN.RDB$DETERMINISTIC_FLAG.NULL = FALSE;
|
||||||
|
FUN.RDB$DETERMINISTIC_FLAG = deterministic ? TRUE : FALSE;
|
||||||
|
|
||||||
|
modifed = true;
|
||||||
|
END_MODIFY
|
||||||
|
}
|
||||||
|
END_FOR
|
||||||
|
|
||||||
|
return modifed;
|
||||||
|
}
|
||||||
|
|
||||||
void CreateAlterFunctionNode::storeArgument(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch,
|
void CreateAlterFunctionNode::storeArgument(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch,
|
||||||
jrd_tra* transaction, unsigned pos, bool returnArg, ParameterClause* parameter,
|
jrd_tra* transaction, unsigned pos, bool returnArg, ParameterClause* parameter,
|
||||||
const CollectedParameter* collectedParameter)
|
const CollectedParameter* collectedParameter)
|
||||||
|
@ -455,6 +455,8 @@ private:
|
|||||||
void executeCreate(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction);
|
void executeCreate(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction);
|
||||||
bool executeAlter(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction,
|
bool executeAlter(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction,
|
||||||
bool secondPass, bool runTriggers);
|
bool secondPass, bool runTriggers);
|
||||||
|
bool executeAlterIndividualParameters(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction,
|
||||||
|
bool secondPass, bool runTriggers);
|
||||||
|
|
||||||
void storeArgument(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction,
|
void storeArgument(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction,
|
||||||
unsigned pos, bool returnArg, ParameterClause* parameter,
|
unsigned pos, bool returnArg, ParameterClause* parameter,
|
||||||
|
@ -2831,6 +2831,11 @@ function_clause
|
|||||||
: psql_function_clause
|
: psql_function_clause
|
||||||
| external_function_clause;
|
| external_function_clause;
|
||||||
|
|
||||||
|
%type <createAlterFunctionNode> change_opt_function_clause
|
||||||
|
change_opt_function_clause
|
||||||
|
: change_deterministic_opt_function_clause
|
||||||
|
;
|
||||||
|
|
||||||
%type <createAlterFunctionNode> psql_function_clause
|
%type <createAlterFunctionNode> psql_function_clause
|
||||||
psql_function_clause
|
psql_function_clause
|
||||||
: function_clause_start sql_security_clause_opt AS local_declarations_opt full_proc_block
|
: function_clause_start sql_security_clause_opt AS local_declarations_opt full_proc_block
|
||||||
@ -2859,7 +2864,7 @@ function_clause_start
|
|||||||
: symbol_UDF_name
|
: symbol_UDF_name
|
||||||
{ $$ = newNode<CreateAlterFunctionNode>(*$1); }
|
{ $$ = newNode<CreateAlterFunctionNode>(*$1); }
|
||||||
input_parameters(NOTRIAL(&$2->parameters))
|
input_parameters(NOTRIAL(&$2->parameters))
|
||||||
RETURNS domain_or_non_array_type collate_clause deterministic_opt
|
RETURNS domain_or_non_array_type collate_clause deterministic_clause_opt
|
||||||
{
|
{
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
$$->returnType = newNode<ParameterClause>($5, optName($6));
|
$$->returnType = newNode<ParameterClause>($5, optName($6));
|
||||||
@ -2867,13 +2872,30 @@ function_clause_start
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
%type <boolVal> deterministic_opt
|
%type <createAlterFunctionNode> change_deterministic_opt_function_clause
|
||||||
deterministic_opt
|
change_deterministic_opt_function_clause
|
||||||
: { $$ = false; }
|
: symbol_UDF_name
|
||||||
| NOT DETERMINISTIC { $$ = false; }
|
{ $$ = newNode<CreateAlterFunctionNode>(*$1); }
|
||||||
|
deterministic_clause
|
||||||
|
{
|
||||||
|
$$ = $2;
|
||||||
|
$$->deterministic = $3;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
%type <boolVal> deterministic_clause
|
||||||
|
deterministic_clause
|
||||||
|
: NOT DETERMINISTIC { $$ = false; }
|
||||||
| DETERMINISTIC { $$ = true; }
|
| DETERMINISTIC { $$ = true; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
%type <boolVal> deterministic_clause_opt
|
||||||
|
deterministic_clause_opt
|
||||||
|
: { $$ = false; }
|
||||||
|
| deterministic_clause { $$ = $1; }
|
||||||
|
;
|
||||||
|
|
||||||
%type <externalClause> external_clause
|
%type <externalClause> external_clause
|
||||||
external_clause
|
external_clause
|
||||||
: EXTERNAL NAME utf_string ENGINE valid_symbol_name
|
: EXTERNAL NAME utf_string ENGINE valid_symbol_name
|
||||||
@ -2903,6 +2925,12 @@ alter_function_clause
|
|||||||
$$->alter = true;
|
$$->alter = true;
|
||||||
$$->create = false;
|
$$->create = false;
|
||||||
}
|
}
|
||||||
|
| change_opt_function_clause
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
$$->alter = true;
|
||||||
|
$$->create = false;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
%type <createAlterFunctionNode> replace_function_clause
|
%type <createAlterFunctionNode> replace_function_clause
|
||||||
@ -3149,7 +3177,7 @@ local_declaration_subfunc_start
|
|||||||
$$->dsqlBlock = newNode<ExecBlockNode>();
|
$$->dsqlBlock = newNode<ExecBlockNode>();
|
||||||
}
|
}
|
||||||
input_parameters(NOTRIAL(&$4->dsqlBlock->parameters))
|
input_parameters(NOTRIAL(&$4->dsqlBlock->parameters))
|
||||||
RETURNS domain_or_non_array_type collate_clause deterministic_opt
|
RETURNS domain_or_non_array_type collate_clause deterministic_clause_opt
|
||||||
{
|
{
|
||||||
$$ = $4;
|
$$ = $4;
|
||||||
$$->dsqlBlock->returns.add(newNode<ParameterClause>($<legacyField>7, optName($8)));
|
$$->dsqlBlock->returns.add(newNode<ParameterClause>($<legacyField>7, optName($8)));
|
||||||
|
@ -176,6 +176,7 @@ enum drq_type_t
|
|||||||
drq_s_funcs2, // store functions (CreateAlterFunctionNode)
|
drq_s_funcs2, // store functions (CreateAlterFunctionNode)
|
||||||
drq_s_func_args2, // store function arguments (CreateAlterFunctionNode)
|
drq_s_func_args2, // store function arguments (CreateAlterFunctionNode)
|
||||||
drq_m_funcs2, // modify functions (CreateAlterFunctionNode)
|
drq_m_funcs2, // modify functions (CreateAlterFunctionNode)
|
||||||
|
drq_m_prm_funcs2, // modify individual function parameters (CreateAlterFunctionNode)
|
||||||
drq_e_func_args2, // erase function arguments (CreateAlterFunctionNode)
|
drq_e_func_args2, // erase function arguments (CreateAlterFunctionNode)
|
||||||
drq_s_prcs2,
|
drq_s_prcs2,
|
||||||
drq_s_prms4,
|
drq_s_prms4,
|
||||||
|
Loading…
Reference in New Issue
Block a user