8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 12:43:03 +01:00

Add possibility to have default expressions in system packages' procedures and functions parameters.

This commit is contained in:
Adriano dos Santos Fernandes 2022-05-13 10:42:29 -03:00
parent 73aa49604f
commit 1bb89356c8
2 changed files with 95 additions and 3 deletions

View File

@ -38,9 +38,32 @@ namespace Jrd
{
struct SystemProcedureParameter
{
SystemProcedureParameter(
const char* aName,
USHORT aFieldId,
bool aNullable,
const char* aDefaultText = nullptr,
std::initializer_list<UCHAR> aDefaultBlr = {}
)
: name(aName),
fieldId(aFieldId),
nullable(aNullable),
defaultText(aDefaultText),
defaultBlr(*getDefaultMemoryPool(), aDefaultBlr)
{
}
SystemProcedureParameter(Firebird::MemoryPool& pool, const SystemProcedureParameter& other)
: defaultBlr(pool)
{
*this = other;
}
const char* name;
USHORT fieldId;
bool nullable;
const char* defaultText = nullptr;
Firebird::Array<UCHAR> defaultBlr;
};
struct SystemProcedure
@ -79,15 +102,38 @@ namespace Jrd
const char* name;
Factory factory;
prc_t type;
Firebird::Array<SystemProcedureParameter> inputParameters;
Firebird::Array<SystemProcedureParameter> outputParameters;
Firebird::ObjectsArray<SystemProcedureParameter> inputParameters;
Firebird::ObjectsArray<SystemProcedureParameter> outputParameters;
};
struct SystemFunctionParameter
{
SystemFunctionParameter(
const char* aName,
USHORT aFieldId,
bool aNullable,
const char* aDefaultText = nullptr,
std::initializer_list<UCHAR> aDefaultBlr = {}
)
: name(aName),
fieldId(aFieldId),
nullable(aNullable),
defaultText(aDefaultText),
defaultBlr(*getDefaultMemoryPool(), aDefaultBlr)
{
}
SystemFunctionParameter(Firebird::MemoryPool& pool, const SystemFunctionParameter& other)
: defaultBlr(pool)
{
*this = other;
}
const char* name;
USHORT fieldId;
bool nullable;
const char* defaultText = nullptr;
Firebird::Array<UCHAR> defaultBlr;
};
struct SystemFunctionReturnType
@ -128,7 +174,7 @@ namespace Jrd
const char* name;
Factory factory;
Firebird::Array<SystemFunctionParameter> parameters;
Firebird::ObjectsArray<SystemFunctionParameter> parameters;
SystemFunctionReturnType returnType;
};

View File

@ -1787,6 +1787,29 @@ static void store_packages(thread_db* tdbb, const MetaName& owner)
PP.RDB$NULL_FLAG = !parameter.nullable;
PAD(names[gfields[parameter.fieldId].gfld_name], PP.RDB$FIELD_SOURCE);
fb_assert(parameter.defaultBlr.isEmpty() == !parameter.defaultText);
if (parameter.defaultBlr.hasData())
{
attachment->storeMetaDataBlob(tdbb, attachment->getSysTransaction(), &PP.RDB$DEFAULT_SOURCE,
string("default ") + parameter.defaultText);
PP.RDB$DEFAULT_SOURCE.NULL = FALSE;
Array<UCHAR> blrData(1 + parameter.defaultBlr.getCount() + 1);
blrData.push(blr_version5);
blrData.append(parameter.defaultBlr);
blrData.push(blr_eoc);
attachment->storeBinaryBlob(tdbb, attachment->getSysTransaction(), &PP.RDB$DEFAULT_VALUE,
blrData);
PP.RDB$DEFAULT_VALUE.NULL = FALSE;
}
else
{
PP.RDB$DEFAULT_SOURCE.NULL = TRUE;
PP.RDB$DEFAULT_VALUE.NULL = TRUE;
}
}
END_STORE
}
@ -1844,6 +1867,29 @@ static void store_packages(thread_db* tdbb, const MetaName& owner)
ARG.RDB$NULL_FLAG = !parameter.nullable;
PAD(names[gfields[parameter.fieldId].gfld_name], ARG.RDB$FIELD_SOURCE);
fb_assert(parameter.defaultBlr.isEmpty() == !parameter.defaultText);
if (parameter.defaultBlr.hasData())
{
attachment->storeMetaDataBlob(tdbb, attachment->getSysTransaction(), &ARG.RDB$DEFAULT_SOURCE,
string("default ") + parameter.defaultText);
ARG.RDB$DEFAULT_SOURCE.NULL = FALSE;
Array<UCHAR> blrData(1 + parameter.defaultBlr.getCount() + 1);
blrData.push(blr_version5);
blrData.append(parameter.defaultBlr);
blrData.push(blr_eoc);
attachment->storeBinaryBlob(tdbb, attachment->getSysTransaction(), &ARG.RDB$DEFAULT_VALUE,
blrData);
ARG.RDB$DEFAULT_VALUE.NULL = FALSE;
}
else
{
ARG.RDB$DEFAULT_SOURCE.NULL = TRUE;
ARG.RDB$DEFAULT_VALUE.NULL = TRUE;
}
}
END_STORE
}