1: # include   "../ingres.h"
   2: # include   "../aux.h"
   3: # include   "../catalog.h"
   4: # include   "../symbol.h"
   5: # include   "../access.h"
   6: # include   "../batch.h"
   7: 
   8: secupdate(rel)
   9: struct descriptor   *rel;
  10: {
  11:     register struct descriptor  *r;
  12:     register char           *p;
  13:     register int            i;
  14:     int             j, domcnt, mode, dom;
  15:     long                tupcnt;
  16:     long                oldtid, newtid;
  17:     long                lotid, hitid, uptid;
  18:     char                oldtup[MAXTUP], newtup[MAXTUP];
  19:     char                oldkey[MAXTUP], newkey[MAXTUP];
  20:     char                dumtup[MAXTUP];
  21:     struct index            itup;
  22:     struct descriptor       si_desc;
  23:     extern struct descriptor    Inddes;
  24:     struct key_pt
  25:     {
  26:         char    *pt_old;
  27:         char    *pt_new;
  28:     };
  29:     struct key_pt           keys[MAXKEYS+1];
  30:     long                ltemp;
  31: 
  32:     r = rel;
  33:     mode = Batchhd.mode_up;
  34:     Batch_dirty = FALSE;
  35: #	ifdef xZTR1
  36:     if (tTf(15, -1))
  37:         printf("SECUPDATE\n");
  38: #	endif
  39:     opencatalog("indexes", 0);
  40:     setkey(&Inddes, &itup, r->relid, IRELIDP);
  41:     setkey(&Inddes, &itup, r->relowner, IOWNERP);
  42:     if (i = find(&Inddes, EXACTKEY, &lotid, &hitid, &itup))
  43:         syserr("secupdate:find indexes %d", i);
  44: 
  45:     /* update each secondary index */
  46:     while(!(i = get(&Inddes, &lotid, &hitid, &itup, TRUE)))
  47:     {
  48:         /* check if the index is on the right relation */
  49: #		ifdef xZTR1
  50:         if (tTf(15, 7))
  51:             printup(&Inddes, &itup);
  52: #		endif
  53:         if (!bequal(itup.irelidp, r->relid, MAXNAME) ||
  54:             !bequal(itup.iownerp, r->relowner, 2))
  55:             continue;
  56: 
  57:         if (i = openr(&si_desc, 1, itup.irelidi))
  58:             syserr("secupdate:can't openr %.12s %d", itup.irelidi, i);
  59:         /* reposition batch file to the beginning. */
  60:         ltemp = 0;
  61:         if (lseek(Batch_fp, ltemp, 0) < 0)
  62:             syserr("secupdate:seek %d", Batch_fp);
  63:         Batch_cnt = BATCHSIZE;
  64:         getbatch(&Batchhd, sizeof Batchhd); /* reread header */
  65: 
  66:         /* set up the key structure */
  67:         p = itup.idom;
  68:         for (domcnt = 0; domcnt < MAXKEYS; domcnt++)
  69:         {
  70:             if ((dom = *p++) == 0)
  71:                 break;  /* no more key domains */
  72: #			ifdef xZTR1
  73:             if (tTf(15, 15))
  74: 
  75:                 printf("dom %d,tupo_off %d\n", dom, Batchhd.si[dom].tupo_off);
  76: #			endif
  77:             keys[domcnt].pt_old = &oldtup[Batchhd.si[dom].tupo_off];
  78:             keys[domcnt].pt_new = &newtup[r->reloff[dom]];
  79:         }
  80: 
  81:         /* the last domain is the "tidp" field */
  82:         keys[domcnt].pt_old = (char *) &oldtid;
  83:         keys[domcnt].pt_new = (char *) &newtid;
  84: 
  85:         /*
  86: 		** Start reading the batch file and updating
  87: 		** the secondary indexes.
  88: 		*/
  89:         tupcnt = Batchhd.num_updts;
  90:         while (tupcnt--)
  91:         {
  92:             getbatch(&oldtid, Batchhd.tido_size);
  93:             getbatch(oldtup, Batchhd.tupo_size);
  94:             getbatch(newtup, Batchhd.tupn_size);
  95:             getbatch(&newtid, Batchhd.tidn_size);
  96: 
  97:             /* if this is a replace or append form the new key */
  98:             if (mode != mdDEL)
  99:             {
 100:                 for (j = 0; j <= domcnt; j++)
 101:                     setkey(&si_desc, newkey, keys[j].pt_new, j+1);
 102: #				ifdef xZTR1
 103:                 if (tTf(15, 7))
 104:                     printup(&si_desc, newkey);
 105: #				endif
 106:             }
 107: 
 108:             /* if this is delete or replace form the old key */
 109:             if (mode != mdAPP)
 110:             {
 111:                 for (j = 0; j <= domcnt; j++)
 112:                     setkey(&si_desc, oldkey, keys[j].pt_old, j+1);
 113: #				ifdef xZTR1
 114:                 if (tTf(15, 8))
 115:                     printup(&si_desc, oldkey);
 116: #				endif
 117:             }
 118: 
 119:             switch (mode)
 120:             {
 121: 
 122:               case mdDEL:
 123:                 if (i = getequal(&si_desc, oldkey, dumtup, &uptid))
 124:                 {
 125:                     if (i > 0)
 126:                         break;
 127:                     syserr("secupdate:getequal %d", i);
 128:                 }
 129:                 if ((i = delete(&si_desc, &uptid)) < 0)
 130:                     syserr("secupdate:delete %d", i);
 131:                 break;
 132: 
 133:               case mdREPL:
 134:                 /* if the newtup = oldtup then do nothing */
 135:                 if (bequal(oldkey, newkey, si_desc.relwid))
 136:                     break;
 137:                 if (i = getequal(&si_desc, oldkey, dumtup, &uptid))
 138:                 {
 139:                     if (Batch_recovery && i > 0)
 140:                         goto secinsert;
 141:                     syserr("secupdate:getequal-repl %d", i);
 142:                 }
 143:                 if (i = replace(&si_desc, &uptid, newkey, TRUE))
 144:                 {
 145:                     /* if newtuple is dup of old, ok */
 146:                     if (i == 1)
 147:                         break;
 148:                     /* if this is recovery and old tid not there, try an insert */
 149:                     if (Batch_recovery && i == 2)
 150:                         goto secinsert;
 151:                     syserr("secupdate:replace %d", i);
 152:                 }
 153:                 break;
 154: 
 155:               case mdAPP:
 156:               secinsert:
 157:                 if ((i = insert(&si_desc, &uptid, newkey, TRUE)) < 0)
 158:                     syserr("secupdate:insert %d", i);
 159:             }
 160:         }
 161:         if (i = closer(&si_desc))
 162:             syserr("secupdate:closer %.12s %d", si_desc.relid, i);
 163:     }
 164:     if (i < 0)
 165:         syserr("secupdate:bad get from indexes %d", i);
 166: }

Defined functions

secupdate defined in line 8; used 1 times

Defined struct's

key_pt defined in line 24; used 2 times
  • in line 29(2)
Last modified: 1995-02-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 808
Valid CSS Valid XHTML 1.0 Strict