From 5a712a4fee9abf6443d5d3806a04c28a47ccb019 Mon Sep 17 00:00:00 2001 From: skidder Date: Sat, 16 Nov 2002 18:48:01 +0000 Subject: [PATCH] Fixed restore problem for databases having views that use procedures AND are used by procedures. General procedure metadata related cleanup. --- src/jrd/cmp.cpp | 9 ++++++--- src/jrd/dbg.cpp | 7 +++---- src/jrd/jrd.h | 2 +- src/jrd/met.epp | 51 +++++++++++++++++++++++-------------------------- src/jrd/opt.cpp | 5 +++-- src/jrd/par.cpp | 4 ++-- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/jrd/cmp.cpp b/src/jrd/cmp.cpp index 1414d8da66..cf41c45cb1 100644 --- a/src/jrd/cmp.cpp +++ b/src/jrd/cmp.cpp @@ -40,7 +40,7 @@ * */ /* -$Id: cmp.cpp,v 1.20 2002-11-14 13:39:02 skidder Exp $ +$Id: cmp.cpp,v 1.21 2002-11-16 18:48:00 skidder Exp $ */ #include "firebird.h" @@ -2638,7 +2638,9 @@ static JRD_NOD copy( remap[stream] = (UCHAR) new_stream; node->nod_arg[e_prc_procedure] = input->nod_arg[e_prc_procedure]; element = CMP_csb_element(csb, new_stream); - element->csb_procedure = (PRC) node->nod_arg[e_prc_procedure]; + // SKIDDER: Maybe we need to check if we really found a procedure ? + element->csb_procedure = MET_lookup_procedure_id(tdbb, + (SSHORT)node->nod_arg[e_prc_procedure],FALSE,FALSE,0); (*csb)->csb_rpt[new_stream].csb_flags |= (*csb)->csb_rpt[stream].csb_flags & csb_no_dbkey; @@ -3841,7 +3843,8 @@ static void pass1_source( PRC procedure; pass1(tdbb, csb, source, parent_view, view_stream, FALSE); - procedure = (PRC) source->nod_arg[e_prc_procedure]; + procedure = MET_lookup_procedure_id(tdbb, + (SSHORT)source->nod_arg[e_prc_procedure], FALSE, FALSE, 0); post_procedure_access(tdbb, *csb, procedure); CMP_post_resource(tdbb, &(*csb)->csb_resources, (BLK) procedure, rsc_procedure, procedure->prc_id); diff --git a/src/jrd/dbg.cpp b/src/jrd/dbg.cpp index c3f14a87d2..a75e4ed04b 100644 --- a/src/jrd/dbg.cpp +++ b/src/jrd/dbg.cpp @@ -804,10 +804,9 @@ int DBG_pretty(register NOD node, register int column) return TRUE; case nod_procedure: - procedure = (PRC) node->nod_arg[e_prc_procedure]; - ib_fprintf(dbg_file, ", stream: %d, %s (%X)\n", - node->nod_arg[e_prc_stream], procedure->prc_name->str_data, - procedure); + SSHORT procedure_id = (SSHORT) node->nod_arg[e_prc_procedure]; + ib_fprintf(dbg_file, ", stream: %d, prc_id: %d\n", + node->nod_arg[e_prc_stream], procedure_id); if (node->nod_arg[e_prc_inputs]) DBG_pretty(node->nod_arg[e_prc_inputs], column); return TRUE; diff --git a/src/jrd/jrd.h b/src/jrd/jrd.h index 37d0ce3dcd..37629315e8 100644 --- a/src/jrd/jrd.h +++ b/src/jrd/jrd.h @@ -474,7 +474,7 @@ typedef att* ATT; class prc : public pool_alloc_rpt { public: - USHORT prc_id; + USHORT prc_id; // Should be first field because MET_remove_procedure relies on that USHORT prc_flags; USHORT prc_inputs; USHORT prc_outputs; diff --git a/src/jrd/met.epp b/src/jrd/met.epp index f0a687e29c..f36254e384 100644 --- a/src/jrd/met.epp +++ b/src/jrd/met.epp @@ -37,7 +37,7 @@ * */ /* -$Id: met.epp,v 1.34 2002-11-14 13:39:02 skidder Exp $ +$Id: met.epp,v 1.35 2002-11-16 18:48:01 skidder Exp $ */ // This MUST be at the top of the file #ifdef DARWIN @@ -257,7 +257,7 @@ BOOLEAN MET_clear_cache(TDBB tdbb, PRC proc) SET_TDBB(tdbb); dbb = tdbb->tdbb_database; - + relations = dbb->dbb_relations; for (ptr = relations->begin(), end = relations->end(); ptr < end; ptr++) @@ -305,7 +305,7 @@ BOOLEAN MET_clear_cache(TDBB tdbb, PRC proc) if (proc) { result = proc->prc_use_count == proc->prc_int_use_count; - adjust_dependencies(proc); + adjust_dependencies(proc); } /* Deallocate all used requests */ @@ -341,6 +341,7 @@ BOOLEAN MET_clear_cache(TDBB tdbb, PRC proc) MET_remove_procedure(tdbb, procedure->prc_id, procedure); } } + } return result; } @@ -2002,25 +2003,23 @@ PRC MET_lookup_procedure(TDBB tdbb, SCHAR * name, BOOLEAN noscan) PRC procedure; vec::iterator ptr, end; VEC procedures; - SCHAR *p, *q; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; -/* See if we already know the relation by name */ +/* See if we already know the procedure by name */ if ( (procedures = dbb->dbb_procedures) ) for (ptr = procedures->begin(), end = procedures->end(); ptr < end; ptr++) { if ((procedure = PRC(*ptr))&& !(procedure->prc_flags & PRC_obsolete) - && (procedure->prc_flags & PRC_scanned) + && ((procedure->prc_flags & PRC_scanned) || noscan) && !(procedure->prc_flags & PRC_being_scanned) && !(procedure->prc_flags & PRC_being_altered) - && (p = (SCHAR*)procedure->prc_name->str_data)) for (q = (SCHAR*)name; - *p == *q; - p++, q++) - if (*p == 0) - return procedure; + && !(strcmp((SCHAR*)procedure->prc_name->str_data, (SCHAR*)name))) + { + return procedure; + } } /* We need to look up the procedure name in RDB$PROCEDURES */ @@ -2062,24 +2061,22 @@ PRC MET_lookup_procedure_id(TDBB tdbb, SSHORT id, DBB dbb; BLK request; PRC procedure; - vec::iterator ptr, end; VEC procedures; SET_TDBB(tdbb); dbb = tdbb->tdbb_database; -/* See if we already know the relation by name */ - - if ( (procedures = dbb->dbb_procedures) ) - for (ptr = procedures->begin(), end = procedures->end(); - ptr < end; ptr++) { - if ((procedure = PRC(*ptr)) && procedure->prc_id == id - && !(procedure->prc_flags & PRC_being_scanned) - && ((procedure->prc_flags & PRC_scanned) || noscan) - && !(procedure->prc_flags & PRC_being_altered) - && (!(procedure->prc_flags & PRC_obsolete) || return_deleted)) - return procedure; - } + if ((procedures = dbb->dbb_procedures) + && id < procedures->count() + && (procedure = (PRC)(*procedures)[id]) + && procedure->prc_id == id + && !(procedure->prc_flags & PRC_being_scanned) + && ((procedure->prc_flags & PRC_scanned) || noscan) + && !(procedure->prc_flags & PRC_being_altered) + && (!(procedure->prc_flags & PRC_obsolete) || return_deleted)) + { + return procedure; + } /* We need to look up the procedure name in RDB$PROCEDURES */ @@ -3104,9 +3101,9 @@ void MET_remove_procedure( TDBB tdbb, int id, PRC procedure) } else { - save_proc_flags = procedure->prc_flags; - memset(((SCHAR *) procedure) + sizeof(struct blk), 0, - sizeof(struct prc) - sizeof(struct blk)); + save_proc_flags = procedure->prc_flags; + memset(((SCHAR *)&procedure->prc_id), 0, + sizeof(struct prc) - ((SCHAR *)&procedure->prc_id-(SCHAR *)procedure)); procedure->prc_flags = save_proc_flags; } } diff --git a/src/jrd/opt.cpp b/src/jrd/opt.cpp index 5e09d07362..14c33c9976 100644 --- a/src/jrd/opt.cpp +++ b/src/jrd/opt.cpp @@ -3587,8 +3587,9 @@ static RSB gen_procedure(TDBB tdbb, OPT opt, JRD_NOD node) DEV_BLKCHK(opt, type_opt); DEV_BLKCHK(node, type_nod); SET_TDBB(tdbb); - csb = opt->opt_csb; - procedure = (PRC) node->nod_arg[e_prc_procedure]; + csb = opt->opt_csb; + procedure = MET_lookup_procedure_id(tdbb, + (SSHORT)node->nod_arg[e_prc_procedure], FALSE, FALSE, 0); rsb = FB_NEW_RPT(*tdbb->tdbb_default, RSB_PRC_count) Rsb(); rsb->rsb_type = rsb_procedure; rsb->rsb_stream = (UCHAR) node->nod_arg[e_prc_stream]; diff --git a/src/jrd/par.cpp b/src/jrd/par.cpp index 92594827b4..f773b8854f 100644 --- a/src/jrd/par.cpp +++ b/src/jrd/par.cpp @@ -34,7 +34,7 @@ * */ /* -$Id: par.cpp,v 1.21 2002-11-11 19:42:46 hippoman Exp $ +$Id: par.cpp,v 1.22 2002-11-16 18:48:01 skidder Exp $ */ #include "firebird.h" @@ -1783,7 +1783,7 @@ static JRD_NOD par_procedure(TDBB tdbb, CSB * csb, SSHORT operator_) node = PAR_make_node(tdbb, e_prc_length); node->nod_type = nod_procedure; node->nod_count = count_table[blr_procedure]; - node->nod_arg[e_prc_procedure] = (JRD_NOD) procedure; + node->nod_arg[e_prc_procedure] = (JRD_NOD) (SLONG) procedure->prc_id; stream = par_context(csb, 0); node->nod_arg[e_prc_stream] = (JRD_NOD) (SLONG) stream;