8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:43:02 +01:00

Merge pull request #8169 from FirebirdSQL/work/gh-8168

Fixed bug #8168 : MAKE_DBKEY bug after backup/restore
This commit is contained in:
Vlad Khorsun 2024-06-27 18:48:10 +03:00 committed by GitHub
commit 72f4b1a748
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 26 deletions

View File

@ -726,6 +726,9 @@ Notes:
In the case of string literal, relation ID is evaluated at prepare time.
In the case of expression, relation ID is evaluated at execution time.
If the relation couldn't be found, then isc_relnotdef error is raised.
Relation ID's could be changed after database restore thus beware of using
integer literals in the first argument (relation) in stored PSQL code
(procedures, functions, triggers).
2) If the first argument (relation) is a numeric expression or literal, then
it's treated as a relation ID and used "as is", without verification
against existing relations.

View File

@ -12297,6 +12297,23 @@ DmlNode* SysFuncCallNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScrat
node->args = PAR_args(tdbb, csb);
if (name == "MAKE_DBKEY")
{
// Special handling for system function MAKE_DBKEY:
// convert constant relation name into ID at the parsing time
auto literal = nodeAs<LiteralNode>(node->args->items[0]);
if (literal && literal->litDesc.isText())
{
const MetaName relName = literal->getText();
const jrd_rel* const relation = MET_lookup_relation(tdbb, relName);
if (relation)
node->args->items[0] = MAKE_const_slong(relation->rel_id);
}
}
return node;
}
@ -12443,32 +12460,6 @@ ValueExprNode* SysFuncCallNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
if (node->function)
{
if (name == "MAKE_DBKEY")
{
// Special handling for system function MAKE_DBKEY:
// convert constant relation name into ID at the parsing time
auto literal = nodeAs<LiteralNode>(node->args->items[0]);
if (literal && literal->litDesc.isText())
{
const MetaName relName = literal->getText();
const dsql_rel* const relation =
METD_get_relation(dsqlScratch->getTransaction(), dsqlScratch, relName);
if (!relation)
{
status_exception::raise(
Arg::Gds(isc_sqlerr) << Arg::Num(-607) <<
Arg::Gds(isc_dsql_command_err) <<
Arg::Gds(isc_dsql_table_not_found) << relName);
}
node->args->items[0] = MAKE_const_slong(relation->rel_id);
}
}
if (node->function->setParamsFunc)
{
Array<dsc> tempDescs(node->args->items.getCount());