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

Fixed problems with recursive PSQL functions. Minor refactoring.

This commit is contained in:
dimitr 2010-10-08 09:40:14 +00:00
parent 4d66b4e1ac
commit df245ba88e
3 changed files with 44 additions and 46 deletions

View File

@ -261,7 +261,6 @@ Function* Function::loadMetadata(thread_db* tdbb, USHORT id, bool noscan, USHORT
memset(temp, 0, sizeof(temp));
ULONG length = 0;
function->setUndefined(false);
function->fun_inputs = 0;
function->fun_defaults = 0;
@ -364,23 +363,20 @@ Function* Function::loadMetadata(thread_db* tdbb, USHORT id, bool noscan, USHORT
function->fun_exception_message.printf(EXCEPTION_MESSAGE,
function->getName().toString().c_str(), X.RDB$ENTRYPOINT, X.RDB$MODULE_NAME);
if (!X.RDB$LEGACY_FLAG.NULL)
{
function->fun_legacy = (X.RDB$LEGACY_FLAG != 0);
}
if (!X.RDB$INVARIANT_FLAG.NULL)
{
function->fun_invariant = (X.RDB$INVARIANT_FLAG != 0);
}
function->setUndefined(false);
function->setImplemented(true);
function->fun_entrypoint = NULL;
function->fun_external = NULL;
function->setStatement(NULL);
if (!X.RDB$ENGINE_NAME.NULL)
{
fb_assert(!function->fun_legacy);
function->fun_entrypoint = NULL;
function->setStatement(NULL);
HalfStaticArray<UCHAR, 512> body;
if (!X.RDB$FUNCTION_SOURCE.NULL)
@ -395,17 +391,17 @@ Function* Function::loadMetadata(thread_db* tdbb, USHORT id, bool noscan, USHORT
body.getBuffer(1)[0] = 0;
}
function->fun_external = dbb->dbb_extManager.makeFunction(
tdbb, function, X.RDB$ENGINE_NAME,
function->fun_external =
dbb->dbb_extManager.makeFunction(tdbb, function, X.RDB$ENGINE_NAME,
(X.RDB$ENTRYPOINT.NULL ? "" : X.RDB$ENTRYPOINT), (char*) body.begin());
if (!function->fun_external)
{
function->setImplemented(false);
}
}
else if (!X.RDB$FUNCTION_BLR.NULL)
{
fb_assert(!function->fun_legacy);
function->fun_external = NULL;
function->fun_entrypoint = NULL;
MemoryPool* const csb_pool = dbb->createPool();
Jrd::ContextPoolHolder context(tdbb, csb_pool);
@ -436,31 +432,27 @@ Function* Function::loadMetadata(thread_db* tdbb, USHORT id, bool noscan, USHORT
function->makeFormat();
}
else if (!X.RDB$MODULE_NAME.NULL && !X.RDB$ENTRYPOINT.NULL)
{
function->fun_entrypoint =
Module::lookup(X.RDB$MODULE_NAME, X.RDB$ENTRYPOINT, dbb->dbb_modules);
// Could not find a function with given MODULE, ENTRYPOINT.
// Try the list of internally implemented functions.
if (!function->fun_entrypoint)
{
function->fun_entrypoint =
BUILTIN_entrypoint(X.RDB$MODULE_NAME, X.RDB$ENTRYPOINT);
}
if (!function->fun_entrypoint)
{
function->setImplemented(false);
}
}
else
{
function->fun_external = NULL;
function->setStatement(NULL);
if (!X.RDB$MODULE_NAME.NULL && !X.RDB$ENTRYPOINT.NULL)
{
fb_assert(function->fun_legacy);
function->fun_entrypoint =
Module::lookup(X.RDB$MODULE_NAME, X.RDB$ENTRYPOINT, dbb->dbb_modules);
// Could not find a function with given MODULE, ENTRYPOINT.
// Try the list of internally implemented functions.
if (!function->fun_entrypoint)
{
function->fun_entrypoint =
BUILTIN_entrypoint(X.RDB$MODULE_NAME, X.RDB$ENTRYPOINT);
}
}
else
{
function->fun_entrypoint = NULL;
function->setUndefined(true);
}
function->setUndefined(true);
}
if (X.RDB$VALID_BLR.NULL || X.RDB$VALID_BLR == FALSE)
@ -704,9 +696,8 @@ dsc* Function::execute(thread_db* tdbb, const jrd_nod* args, impure_value* value
{
fun_external->execute(tdbb, args, value);
}
else
else if (getStatement())
{
fb_assert(getStatement());
fb_assert(!fun_return_arg);
fb_assert(args->nod_count == fun_inputs);
@ -805,6 +796,10 @@ dsc* Function::execute(thread_db* tdbb, const jrd_nod* args, impure_value* value
MOV_move(tdbb, &arg_desc, &value->vlu_desc);
}
}
else
{
fb_assert(false);
}
return (request->req_flags & req_null) ? NULL : &value->vlu_desc;
}

View File

@ -76,7 +76,6 @@ namespace Jrd
fun_existence_lock(NULL),
fun_alter_count(0),
fun_exception_message(p),
fun_legacy(true),
fun_invariant(false),
fun_external(NULL)
{
@ -117,7 +116,6 @@ namespace Jrd
Firebird::string fun_exception_message; // message containing the exception error message
bool fun_legacy;
bool fun_invariant;
const ExtEngineManager::Function* fun_external;
};

View File

@ -38,7 +38,8 @@ namespace Jrd
name(p),
securityName(p),
statement(NULL),
undefined(false)
undefined(false),
implemented(true)
{
}
@ -63,6 +64,9 @@ namespace Jrd
bool isUndefined() const { return undefined; }
void setUndefined(bool value) { undefined = value; }
bool isImplemented() const { return implemented; }
void setImplemented(bool value) { implemented = value; }
public:
virtual int getObjectType() const = 0;
virtual SLONG getSclType() const = 0;
@ -73,6 +77,7 @@ namespace Jrd
Firebird::MetaName securityName; // security class name
JrdStatement* statement; // compiled routine statement
bool undefined; // Is the packaged routine missing the body/entrypoint?
bool implemented; // routine has its implementation available
};
}