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

Work in progress on RDB$VIEW_RELATIONS

This commit is contained in:
asfernandes 2009-12-17 15:07:02 +00:00
parent c5d8b2f385
commit 1b1f90d06c
8 changed files with 32 additions and 47 deletions

View File

@ -1683,7 +1683,8 @@ dsql_rel* METD_get_view_base(CompiledStatement* statement,
DSQL_REQUEST(irq_view_base) = handle1;
// return NULL if there is more than one context
if (X.RDB$VIEW_CONTEXT != 1)
if (X.RDB$VIEW_CONTEXT != 1 || X.RDB$CONTEXT_TYPE == VCT_SIMPLE_PROC ||
X.RDB$CONTEXT_TYPE == VCT_PACKAGED_PROC)
{
relation = NULL;
cont = false;

View File

@ -35,10 +35,12 @@ class ViewContext
{
public:
explicit ViewContext(MemoryPool& p, const TEXT* context_name,
const TEXT* relation_name, USHORT context) :
vcx_context_name(p, context_name, strlen(context_name)),
vcx_relation_name(relation_name),
vcx_context(context)
const TEXT* relation_name, USHORT context,
ViewContextType type)
: vcx_context_name(p, context_name, strlen(context_name)),
vcx_relation_name(relation_name),
vcx_context(context),
vcx_type(type)
{
}
@ -47,9 +49,10 @@ public:
return vc->vcx_context;
}
const Firebird::string vcx_context_name;
const Firebird::MetaName vcx_relation_name;
const USHORT vcx_context;
const Firebird::string vcx_context_name;
const Firebird::MetaName vcx_relation_name;
const USHORT vcx_context;
const ViewContextType vcx_type;
};
typedef Firebird::SortedArray<ViewContext*, Firebird::EmptyStorage<ViewContext*>,

View File

@ -2764,17 +2764,22 @@ static bool create_relation(thread_db* tdbb, SSHORT phase, DeferredWork* work, j
else
{
// update the dbkey length to include each of the base relations
Y.RDB$DBKEY_LENGTH = 0;
handle = NULL;
Y.RDB$DBKEY_LENGTH = 0;
FOR(REQUEST_HANDLE handle)
Z IN RDB$VIEW_RELATIONS CROSS
R IN RDB$RELATIONS OVER RDB$RELATION_NAME
WITH Z.RDB$VIEW_NAME = work->dfw_name.c_str()
R IN RDB$RELATIONS OVER RDB$RELATION_NAME
WITH Z.RDB$VIEW_NAME = work->dfw_name.c_str() AND
(Z.RDB$CONTEXT_TYPE MISSING OR
(Z.RDB$CONTEXT_TYPE <> VCT_SIMPLE_PROC AND
Z.RDB$CONTEXT_TYPE <> VCT_PACKAGED_PROC))
{
Y.RDB$DBKEY_LENGTH += R.RDB$DBKEY_LENGTH;
}
END_FOR
END_FOR;
CMP_release(tdbb, handle);
}
END_MODIFY
@ -4121,11 +4126,13 @@ static bool delete_rfr(thread_db* tdbb, SSHORT phase, DeferredWork* work, jrd_tr
CMP_release(tdbb, handle);
if (field_count)
{
ERR_post(Arg::Gds(isc_no_meta_update) <<
Arg::Gds(isc_no_delete) << // Msg353: can not delete
Arg::Gds(isc_field_name) << Arg::Str(f) <<
Arg::Gds(isc_dependency) << Arg::Num(field_count));
// Msg310: there are %ld dependencies
}
// now check if there are any dependencies generated through the blr
// that defines the relation

View File

@ -50,7 +50,7 @@
#define DYN_REQUEST(drt) dbb->dbb_dyn_req[drt]
const int drq_l_prot_mask = 0; // lookup protection mask
const int drq_l_fld_src4 = 1; // lookup a field source
///const int drq_l_fld_src4 = 1; // lookup a field source
const int drq_s_rel_con = 2; // store relation constraints
const int drq_s_chk_con = 3; // store check constraints
const int drq_s_ref_con = 4; // store ref constraints

View File

@ -2942,6 +2942,7 @@ void DYN_define_relation(Global* gbl, const UCHAR** ptr, bool view)
FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction)
VRL IN RDB$VIEW_RELATIONS CROSS
PREL IN RDB$RELATIONS OVER RDB$RELATION_NAME WITH
VRL.RDB$PACKAGE_NAME MISSING AND
VRL.RDB$VIEW_NAME EQ relation_name.c_str()
if (!DYN_REQUEST(drq_l_view_rels))
DYN_REQUEST(drq_l_view_rels) = request;

View File

@ -659,12 +659,11 @@ bool DYN_UTIL_find_field_source(thread_db* tdbb,
VRL IN RDB$VIEW_RELATIONS CROSS
PPR IN RDB$PROCEDURE_PARAMETERS
WITH VRL.RDB$RELATION_NAME EQ PPR.RDB$PROCEDURE_NAME AND
PPR.RDB$PACKAGE_NAME MISSING AND
PPR.RDB$PACKAGE_NAME EQUIV VRL.RDB$PACKAGE_NAME AND
VRL.RDB$VIEW_NAME EQ view_name.c_str() AND
VRL.RDB$VIEW_CONTEXT EQ context AND
(VRL.RDB$CONTEXT_TYPE MISSING OR VRL.RDB$CONTEXT_TYPE EQ VCT_EXPRESSION OR
VRL.RDB$CONTEXT_TYPE EQ VCT_SIMPLE_PROC) AND
VRL.RDB$PACKAGE_NAME MISSING AND
PPR.RDB$PARAMETER_NAME EQ local_name
if (!DYN_REQUEST(drq_l_fld_src3)) {
@ -679,36 +678,6 @@ bool DYN_UTIL_find_field_source(thread_db* tdbb,
DYN_REQUEST(drq_l_fld_src3) = request;
}
}
if (!found)
{
request = CMP_find_request(tdbb, drq_l_fld_src4, DYN_REQUESTS);
FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction)
VRL IN RDB$VIEW_RELATIONS CROSS
PPR IN RDB$PROCEDURE_PARAMETERS
WITH VRL.RDB$RELATION_NAME EQ PPR.RDB$PROCEDURE_NAME AND
//PPR.RDB$PACKAGE_NAME NOT MISSING AND redundant
VRL.RDB$VIEW_NAME EQ view_name.c_str() AND
VRL.RDB$VIEW_CONTEXT EQ context AND
(VRL.RDB$CONTEXT_TYPE MISSING OR VRL.RDB$CONTEXT_TYPE EQ VCT_EXPRESSION OR
VRL.RDB$CONTEXT_TYPE EQ VCT_PACKAGED_PROC) AND
//VRL.RDB$PACKAGE_NAME NOT MISSING redundant
PPR.RDB$PACKAGE_NAME EQ VRL.RDB$PACKAGE_NAME AND
PPR.RDB$PARAMETER_NAME EQ local_name
if (!DYN_REQUEST(drq_l_fld_src4)) {
DYN_REQUEST(drq_l_fld_src4) = request;
}
found = true;
fb_utils::exact_name_limit(PPR.RDB$FIELD_SOURCE, sizeof(PPR.RDB$FIELD_SOURCE));
strcpy(output_field_name, PPR.RDB$FIELD_SOURCE);
END_FOR;
if (!DYN_REQUEST(drq_l_fld_src4)) {
DYN_REQUEST(drq_l_fld_src4) = request;
}
}
}
catch (const Firebird::Exception& ex)
{

View File

@ -4518,7 +4518,8 @@ static void lookup_view_contexts( thread_db* tdbb, jrd_rel* view)
ViewContext* view_context = FB_NEW(*dbb->dbb_permanent)
ViewContext(*dbb->dbb_permanent,
V.RDB$CONTEXT_NAME, V.RDB$RELATION_NAME, V.RDB$VIEW_CONTEXT);
V.RDB$CONTEXT_NAME, V.RDB$RELATION_NAME, V.RDB$VIEW_CONTEXT,
(V.RDB$CONTEXT_TYPE.NULL ? VCT_TABLE : ViewContextType(V.RDB$CONTEXT_TYPE)));
view->rel_view_contexts.add(view_context);

View File

@ -2312,6 +2312,9 @@ static void expand_view_lock(thread_db* tdbb, jrd_tra* transaction, jrd_rel* rel
for (size_t i = 0; i < ctx.getCount(); ++i)
{
if (ctx[i]->vcx_type == VCT_SIMPLE_PROC || ctx[i]->vcx_type == VCT_PACKAGED_PROC)
continue;
jrd_rel* base_rel = MET_lookup_relation(tdbb, ctx[i]->vcx_relation_name);
if (!base_rel)
{