Skip to content

Commit 193b01e

Browse files
committed
Merge pull request #8169 from FirebirdSQL/work/gh-8168
Fixed bug #8168 : MAKE_DBKEY bug after backup/restore
1 parent 7c57f2d commit 193b01e

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

doc/sql.extensions/README.builtin_functions.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ Notes:
729729
In the case of string literal, relation ID is evaluated at prepare time.
730730
In the case of expression, relation ID is evaluated at execution time.
731731
If the relation couldn't be found, then isc_relnotdef error is raised.
732+
Relation ID's could be changed after database restore thus beware of using
733+
integer literals in the first argument (relation) in stored PSQL code
734+
(procedures, functions, triggers).
732735
2) If the first argument (relation) is a numeric expression or literal, then
733736
it's treated as a relation ID and used "as is", without verification
734737
against existing relations.

src/dsql/ExprNodes.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12321,6 +12321,23 @@ DmlNode* SysFuncCallNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScrat
1232112321

1232212322
node->args = PAR_args(tdbb, csb);
1232312323

12324+
if (name == "MAKE_DBKEY")
12325+
{
12326+
// Special handling for system function MAKE_DBKEY:
12327+
// convert constant relation name into ID at the parsing time
12328+
12329+
auto literal = nodeAs<LiteralNode>(node->args->items[0]);
12330+
12331+
if (literal && literal->litDesc.isText())
12332+
{
12333+
const MetaName relName = literal->getText();
12334+
const jrd_rel* const relation = MET_lookup_relation(tdbb, relName);
12335+
12336+
if (relation)
12337+
node->args->items[0] = MAKE_const_slong(relation->rel_id);
12338+
}
12339+
}
12340+
1232412341
return node;
1232512342
}
1232612343

@@ -12462,32 +12479,6 @@ ValueExprNode* SysFuncCallNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
1246212479

1246312480
if (node->function)
1246412481
{
12465-
if (name == "MAKE_DBKEY")
12466-
{
12467-
// Special handling for system function MAKE_DBKEY:
12468-
// convert constant relation name into ID at the parsing time
12469-
12470-
auto literal = nodeAs<LiteralNode>(node->args->items[0]);
12471-
12472-
if (literal && literal->litDesc.isText())
12473-
{
12474-
const MetaName relName = literal->getText();
12475-
12476-
const dsql_rel* const relation =
12477-
METD_get_relation(dsqlScratch->getTransaction(), dsqlScratch, relName);
12478-
12479-
if (!relation)
12480-
{
12481-
status_exception::raise(
12482-
Arg::Gds(isc_sqlerr) << Arg::Num(-607) <<
12483-
Arg::Gds(isc_dsql_command_err) <<
12484-
Arg::Gds(isc_dsql_table_not_found) << relName);
12485-
}
12486-
12487-
node->args->items[0] = MAKE_const_slong(relation->rel_id);
12488-
}
12489-
}
12490-
1249112482
if (node->function->setParamsFunc)
1249212483
{
1249312484
Array<dsc> tempDescs(node->args->items.getCount());

0 commit comments

Comments
 (0)