/******************************************************************************/ /* File : pr_delete.c */ /* Schema : olc96fa.sch */ /* Chgen Version : v10 */ /******************************************************************************/ #include #include "olc96fa.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 = 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 = 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 = ca##temp->p##_fpp = 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 = 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; { char temp_key[HCG_KEY_SIZE+1]; switch( encoding(hcg_table_seq_list[tbl_idx].ttabbrev) ) { case 0 : /* encoding of SM */ unlink_child_bp_m(ET,SM,SMid,ETid); unlink_child_bp_m(ST,SM,SMid,STid); unlink_child_bp_m(AC,SM,SMid,ACid); #ifdef DEBUG decode(temp_key, &SMcurr->SMid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(SM); break; case 1 : /* encoding of AC */ unlink_child_bp_m(AI,AC,ACid,AIid); unlink_parent_bp_m(AC,SM,SMid,ACid); #ifdef DEBUG decode(temp_key, &ACcurr->ACid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(AC); break; case 2 : /* encoding of ST */ unlink_child_bp_m(TR,ST,STid1,TRid1); unlink_child_bp_m(TR,ST,STid2,TRid2); unlink_parent_bp_m(ST,SM,SMid,STid); #ifdef DEBUG decode(temp_key, &STcurr->STid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(ST); break; case 3 : /* encoding of AI */ unlink_child_bp_m(TF,AI,AIid,TFid); unlink_child_bp_m(CK,AI,AIid1,CKid1); unlink_child_bp_m(TI,AI,AIid1,TIid1); unlink_child_bp_m(EI,AI,AIid1,EIid1); unlink_child_bp_m(TF,AI,AIid1_source,TFid1); unlink_child_bp_m(CK,AI,AIid2,CKid2); unlink_child_bp_m(TI,AI,AIid2,TIid2); unlink_child_bp_m(EI,AI,AIid2,EIid2); unlink_child_bp_m(TF,AI,AIid2_reply,TFid2); unlink_child_bp_m(CK,AI,AIid3,CKid3); unlink_child_bp_m(TI,AI,AIid3,TIid3); unlink_parent_bp_m(AI,AC,ACid,AIid); #ifdef DEBUG decode(temp_key, &AIcurr->AIid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(AI); break; case 4 : /* encoding of TR */ unlink_child_bp_m(EN,TR,TRid,ENid); unlink_parent_bp_m(TR,ST,STid1,TRid1); unlink_parent_bp_m(TR,ST,STid2,TRid2); #ifdef DEBUG decode(temp_key, &TRcurr->TRid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(TR); break; case 5 : /* encoding of ET */ unlink_child_bp_m(CK,ET,ETid,CKid); unlink_child_bp_m(TI,ET,ETid,TIid); unlink_child_bp_m(EI,ET,ETid,EIid); unlink_child_bp_m(EN,ET,ETid,ENid); unlink_parent_bp_m(ET,SM,SMid,ETid); #ifdef DEBUG decode(temp_key, &ETcurr->ETid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(ET); break; case 6 : /* encoding of EN */ unlink_parent_bp_m(EN,TR,TRid,ENid); unlink_parent_bp_m(EN,ET,ETid,ENid); #ifdef DEBUG decode(temp_key, &ENcurr->ENid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(EN); break; case 7 : /* encoding of EI */ unlink_parent_bp_m(EI,ET,ETid,EIid); unlink_parent_bp_m(EI,AI,AIid1,EIid1); unlink_parent_bp_m(EI,AI,AIid2,EIid2); #ifdef DEBUG decode(temp_key, &EIcurr->EIid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(EI); break; case 8 : /* encoding of TF */ unlink_parent_bp_m(TF,AI,AIid,TFid); unlink_parent_bp_m(TF,AI,AIid1_source,TFid1); unlink_parent_bp_m(TF,AI,AIid2_reply,TFid2); #ifdef DEBUG decode(temp_key, &TFcurr->TFid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(TF); break; case 9 : /* encoding of TI */ unlink_parent_bp_m(TI,ET,ETid,TIid); unlink_parent_bp_m(TI,AI,AIid1,TIid1); unlink_parent_bp_m(TI,AI,AIid2,TIid2); unlink_parent_bp_m(TI,AI,AIid3,TIid3); #ifdef DEBUG decode(temp_key, &TIcurr->TIid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(TI); break; case 10 : /* encoding of CK */ unlink_parent_bp_m(CK,ET,ETid,CKid); unlink_parent_bp_m(CK,AI,AIid1,CKid1); unlink_parent_bp_m(CK,AI,AIid2,CKid2); unlink_parent_bp_m(CK,AI,AIid3,CKid3); #ifdef DEBUG decode(temp_key, &CKcurr->CKid); printf("The primary key deleted is %s\n",temp_key); #endif del_row(CK); 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 ) { } }