/******************************************************************************/ /* File : pr_delete.c */ /* Schema : metaschema.sch */ /* Chgen Version : genMerge chgenv11-karner-spinney */ /******************************************************************************/ #include #include "metaschema.h" /******************************************************************************/ /* This private macro is used by pr_delete to physically delete a row. It */ /* also unlinks the row from its table's row chain. */ /******************************************************************************/ /* New version of del_row - 93/2/8 by RJL and CMurphy: */ /* tbl == tbl*//*end != NULL (and rcount = 1) means a single-row table */ /* tbl == tbl*//*end == NULL (and rcount = 0) means an empty table -RJL */ #define del_row(tbl) \ if (tbl##end == NULL) \ printf("del_row error: empty table");\ else \ if (tbl##curr == NULL) \ printf("del_row error: NULL curr row ptr");\ else\ {\ if( tbl##btidx == BTREESEARCH ) \ { \ sprintf(tempbtree,"tbl"); \ tempbtree[HCG_ABBR_SIZE]='\0'; \ pr_del_bt(tempbtree,tbl##curr->tbl##id); \ } \ if (tbl##end == tbl##curr) /*last row: next_ptr = NULL - RJL 93/2/8 */\ tbl##end = tbl##curr->prev_ptr; /* = NULL iff curr row = first row */\ if (tbl == tbl##curr) /* first row: prev_ptr = NULL - RJL 93/2/8 */\ tbl = tbl##curr->next_ptr; /* = NULL iff curr row = last row */\ if (tbl##curr->prev_ptr != NULL) \ { \ tbl##curr->prev_ptr->next_ptr = tbl##curr->next_ptr; \ } \ if (tbl##curr->next_ptr != NULL) \ { \ tbl##curr->next_ptr->prev_ptr = tbl##curr->prev_ptr; \ } \ hcg_ts_list[tbl##_idx].ts_list[get_version(&tbl##curr->tbl##id)].rcount--; \ hcg_table_seq_list[tbl##_idx].rcount--;\ free(tbl##curr);\ } /******************************************************************************/ /* This private macro is used by pr_del to unlink a row from the specified */ /* parent table. It is identical to unlink_parent_nobp except that its is */ /* for a singleton child. */ /******************************************************************************/ #define unlink_parent_1(ca,pa,p,c) \ pa##temp = ca##curr->p##_pp; \ if (pa##temp != NULL) \ pa##temp->c##_fcp = NULL /******************************************************************************/ /* This private macro is used by pr_del to unlink a row from the specified */ /* parent table. It is identical to unlink_parent_nobp except that back */ /* pointers are also unlinked. */ /******************************************************************************/ #define unlink_parent_bp_m(ca,pa,p,c) \ pa##temp = ca##curr->p##_pp; \ ca##temp = ca##curr; /* Change CEM & RJL 20 APR 93*/ \ if (pa##temp != NULL) \ { \ if (( pa##temp->c##_fcp == ca##temp) && \ ( (struct pa *) ca##curr->p##_fpp == pa##temp)) /* only child case */ \ { \ pa##temp->c##_fcp = NULL; \ pa##temp->c##_bcp = NULL; \ } \ else \ if ( pa##temp->c##_fcp == ca##temp ) /* first child case */ \ { \ pa##temp->c##_fcp = (struct ca *)ca##curr->p##_fpp; \ ca##curr2 = (struct ca *)ca##curr->p##_fpp; \ (struct pa *) ca##curr2->p##_bpp = pa##temp; \ } \ else \ if ( (struct pa *) ca##curr->p##_fpp == pa##temp) /* last child case */ \ { \ pa##temp->c##_bcp = (struct ca *)ca##curr->p##_bpp; \ ca##curr2 = (struct ca *)ca##curr->p##_bpp; \ (struct pa *) ca##curr2->p##_fpp = pa##temp; \ } \ else /* middle of child chain case */ \ { \ ca##curr2 = (struct ca *)ca##curr->p##_bpp; \ ca##curr2->p##_fpp = ca##curr->p##_fpp; \ ca##curr2 = (struct ca *)ca##curr->p##_fpp; \ ca##curr2->p##_bpp = ca##curr->p##_bpp; \ } \ } /******************************************************************************/ /* This private macro is used by pr_del to unlink a row from the specified */ /* parent table. It is identical to unlink_parent_bp except that back */ /* pointers are not unlinked. */ /******************************************************************************/ #define unlink_parent_nobp_m(ca,pa,p,c) \ pa##temp = ca##curr->p##_pp; \ ca##temp = ca##curr; /* Change CEM & RJL 20 APR 93*/ \ if (pa##temp != NULL) \ { \ if (( pa##temp->c##_fcp == ca##temp) && \ ( (struct pa *) ca##curr->p##_fpp == pa##temp)) /* only child case */ \ { \ pa##temp->c##_fcp = NULL; \ } \ else \ if ( pa##temp->c##_fcp == ca##temp ) /* first child case */ \ { \ pa##temp->c##_fcp = (struct ca *)ca##curr->p##_fpp; \ ca##curr2 = (struct ca *)ca##curr->p##_fpp; \ } \ else \ if ( (struct pa *) ca##curr->p##_fpp == pa##temp) /* last child case */ \ { \ (struct pa *) ca##curr2->p##_fpp = pa##temp; \ } \ else /* middle of child chain case */ \ { \ ca##curr2->p##_fpp = ca##curr->p##_fpp; \ ca##curr2 = (struct ca *)ca##curr->p##_fpp; \ } \ } /******************************************************************************/ /* This private macro is used by pr_del to unlink a row from the specified */ /* child table. It is identical to link_child_nobp except that it is for a */ /* singleton child. */ /******************************************************************************/ #define unlink_child_1(ca,pa,p,c) \ ca##temp = (struct ca *) pa##curr->c##_fcp; \ if (ca##temp != NULL) \ ca##temp->p##_pp = NULL /******************************************************************************/ /* This private macro is used by pr_del to unlink a row from the specified */ /* child table. It is identical to link_child_nobp except that back pointers */ /* are also unlinked. */ /******************************************************************************/ #define unlink_child_bp_m(ca,pa,p,c) \ ca##temp = (struct ca *) pa##curr->c##_fcp; \ while ((ca##temp != NULL) && \ ((struct pa *) ca##temp != pa##curr)) \ { \ ca##temp2 = (struct ca *)ca##temp->p##_fpp; \ ca##temp->p##_bpp = (void *)ca##temp->p##_fpp = (void *)ca##temp->p##_pp = NULL; \ ca##temp = ca##temp2; \ } /******************************************************************************/ /* This private macro is used by pr_del to unlink a row from the specified */ /* child table. It is identical to link_child_bp except that back pointers */ /* are not unlinked. */ /******************************************************************************/ #define unlink_child_nobp_m(ca,pa,p,c) \ ca##temp = (struct ca *) pa##curr->c##_fcp; \ while ((ca##temp != NULL) && \ ((struct pa *) ca##temp != pa##curr)) \ { \ ca##temp2 = (struct ca *) ca##temp->p##_fpp; \ ca##temp->p##_fpp = ca##temp->p##_pp = NULL; \ ca##temp = ca##temp2; \ } /******************************************************************************/ /* This routine will delete a single row from the database. The row is the */ /* one pointed to by the XXcurr variable. */ /******************************************************************************/ void pr_del(tbl_idx) int tbl_idx; { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; switch( encoding(hcg_table_seq_list[tbl_idx].ttabbrev) ) { case 0 : /* encoding of SV */ unlink_child_bp_m(VV,SV,SVid,VVid); unlink_child_bp_m(TT,SV,SVid,TTid); #ifdef DEBUG decode(temp_key, &SVcurr->SVid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(SV); break; case 1 : /* encoding of TT */ unlink_child_bp_m(TS,TT,TTid,TSid); unlink_child_bp_m(TA,TT,TTid,TAid); unlink_parent_bp_m(TT,SV,SVid,TTid); #ifdef DEBUG decode(temp_key, &TTcurr->TTid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(TT); break; case 2 : /* encoding of TA */ unlink_parent_bp_m(TA,TT,TTid,TAid); #ifdef DEBUG decode(temp_key, &TAcurr->TAid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(TA); break; case 3 : /* encoding of VV */ unlink_child_bp_m(TS,VV,VVid,TSid); unlink_parent_bp_m(VV,SV,SVid,VVid); #ifdef DEBUG decode(temp_key, &VVcurr->VVid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(VV); break; case 4 : /* encoding of TS */ unlink_parent_bp_m(TS,TT,TTid,TSid); unlink_parent_bp_m(TS,VV,VVid,TSid); #ifdef DEBUG decode(temp_key, &TScurr->TSid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(TS); break; } } /******************************************************************************/ /* Description: This routine is used to delete a row in btree. */ /* Input: the special table name and its pkey value. */ /* *temp1 is the table name. temp2 is the pkey value. */ /* Output: none.( it will delete the specific row from btree. ) */ /******************************************************************************/ pr_del_bt(temp1,temp2) char *temp1; hcg_key temp2; { int tbl_encoding, finish=FALSE ; hcg_key result; pr_find_bt( temp1, &temp2); tbl_encoding = encoding( hcg_table_seq_list[hcg_tbl_idx].ttabbrev ); switch( tbl_encoding ) { } }