Skip to content

Commit ee5df51

Browse files
committed
Improvement #8722 - The "IF NOT EXISTS" clause is missing for DECLARE FILTER
1 parent aa3a08d commit ee5df51

6 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/dsql/DdlNodes.epp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10758,6 +10758,12 @@ void CreateFilterNode::execute(thread_db* tdbb, DsqlCompilerScratch* /*dsqlScrat
1075810758
{
1075910759
Attachment* const attachment = transaction->tra_attachment;
1076010760
const MetaString& ownerName = attachment->getEffectiveUserName();
10761+
const QualifiedName qualifiedName(name);
10762+
10763+
if (createIfNotExistsOnly && !DYN_UTIL_check_unique_name_nothrow(tdbb, transaction, qualifiedName, obj_blob_filter))
10764+
return;
10765+
10766+
DYN_UTIL_check_unique_name(tdbb, transaction, qualifiedName, obj_blob_filter);
1076110767

1076210768
// run all statements under savepoint control
1076310769
AutoSavePoint savePoint(tdbb, transaction);

src/dsql/DdlNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,7 @@ class CreateFilterNode final : public DdlNode
20722072
NestConst<NameNumber> outputFilter;
20732073
Firebird::string entryPoint;
20742074
Firebird::string moduleName;
2075+
bool createIfNotExistsOnly = false;
20752076
};
20762077

20772078

src/dsql/parse-conflicts.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
132 shift/reduce conflicts, 13 reduce/reduce conflicts.
1+
133 shift/reduce conflicts, 13 reduce/reduce conflicts.

src/dsql/parse.y

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ using namespace Firebird;
822822
Jrd::CreateAlterExceptionNode* createAlterExceptionNode;
823823
Jrd::CreateAlterSequenceNode* createAlterSequenceNode;
824824
Jrd::CreateAlterSchemaNode* createAlterSchemaNode;
825+
Jrd::CreateFilterNode* createFilterNode;
825826
Jrd::CreateShadowNode* createShadowNode;
826827
Firebird::Array<Jrd::CreateAlterPackageNode::Item>* packageItems;
827828
Jrd::ExceptionArray* exceptionArray;
@@ -1469,7 +1470,12 @@ declare
14691470

14701471
%type <ddlNode> declare_clause
14711472
declare_clause
1472-
: FILTER filter_decl_clause { $$ = $2; }
1473+
: FILTER if_not_exists_opt filter_decl_clause
1474+
{
1475+
const auto node = $3;
1476+
node->createIfNotExistsOnly = $2;
1477+
$$ = node;
1478+
}
14731479
| EXTERNAL FUNCTION if_not_exists_opt udf_decl_clause
14741480
{
14751481
const auto node = $4;
@@ -1570,7 +1576,7 @@ return_mechanism
15701576
;
15711577

15721578

1573-
%type <ddlNode> filter_decl_clause
1579+
%type <createFilterNode> filter_decl_clause
15741580
filter_decl_clause
15751581
: symbol_filter_name
15761582
INPUT_TYPE blob_filter_subtype

src/include/firebird/impl/msg/dyn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,4 @@ FB_IMPL_MSG(DYN, 318, dyn_cannot_drop_non_emptyschema, -607, "HY", "000", "Canno
311311
FB_IMPL_MSG(DYN, 319, dyn_cannot_mod_obj_sys_schema, -607, "28", "000", "Cannot CREATE/ALTER/DROP @1 in SYSTEM schema")
312312
FB_IMPL_MSG(DYN, 320, dyn_cannot_create_reserved_schema, -607, "HY", "000", "Schema name @1 is reserved and cannot be created")
313313
FB_IMPL_MSG(DYN, 321, dyn_cannot_infer_schema, -901, "42", "000", "Cannot infer schema name as there is no valid schema in the search path")
314+
FB_IMPL_MSG_SYMBOL(DYN, 322, dyn_dup_blob_filter, "Blob filter @1 already exists")

src/jrd/dyn_util.epp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,24 @@ bool DYN_UTIL_check_unique_name_nothrow(thread_db* tdbb, jrd_tra* transaction,
283283
break;
284284
}
285285

286+
case obj_blob_filter:
287+
{
288+
fb_assert(object_name.schema.isEmpty());
289+
290+
static const CachedRequestId schemaHandleId;
291+
requestHandle.reset(tdbb, schemaHandleId);
292+
293+
FOR(REQUEST_HANDLE requestHandle TRANSACTION_HANDLE transaction)
294+
FIL IN RDB$FILTERS
295+
WITH FIL.RDB$FUNCTION_NAME EQ object_name.object.c_str()
296+
{
297+
*errorCode = 322; // isc_dyn_dup_blob_filter
298+
}
299+
END_FOR
300+
301+
break;
302+
}
303+
286304
default:
287305
fb_assert(false);
288306
}

0 commit comments

Comments
 (0)