1: # include   <ingres.h>
   2: # include   <access.h>
   3: # include   <catalog.h>
   4: # include   <btree.h>
   5: # include   <sccs.h>
   6: 
   7: SCCSID(@(#)insert.c	8.1	12/31/84)
   8: 
   9: /*
  10: **	INSERT - add a new tuple to a relation
  11: **
  12: **	Insert puts a given tuple into a relation in
  13: **	the "correct" position.
  14: **
  15: **	If insert is called with checkdups == TRUE then
  16: **	the tuple will not be inserted if it is a duplicate
  17: **	of some already existing tuple. If the relation is a
  18: **	heap then checkdups is made false.
  19: **
  20: **	Tid will be set to the tuple id where the
  21: **	tuple is placed.
  22: **
  23: **	returns:
  24: **		<0  fatal error
  25: **		0   success
  26: **		1   tuple was a duplicate
  27: **		2   bad lid
  28: */
  29: 
  30: insert(d, tid, tuple, checkdups)
  31: register DESC   *d;
  32: register TID    *tid;
  33: char        *tuple;
  34: bool        checkdups;
  35: {
  36:     register int    i, j;
  37:     int     need;
  38:     char        *tp;
  39:     long        lid[MAXLID], l;
  40:     char        btree[MAXNAME + 4];
  41:     TID     tidpos;
  42:     struct locator  tidloc;
  43:     short       nolid;
  44: 
  45: #	ifdef xATR1
  46:     if (tTf(24, 0))
  47:     {
  48:         printf("insert:%.14s,", d->reldum.relid);
  49:         dumptid(tid);
  50:         printup(d, tuple);
  51:     }
  52: #	endif
  53: 
  54:     if (d->reldum.reldim != 0)
  55:         checkdups = FALSE;
  56: 
  57:     /* determine how much space is needed for tuple */
  58:     need = canonical(d, tuple);
  59: 
  60:     /* find the "best" page to place tuple */
  61:     if (i = findbest(d, tid, tuple, need, checkdups))
  62:         return (i);
  63: 
  64:     if (d->reldum.reldim > 0)
  65:     /* get lids and check for errors */
  66:     {
  67:         btreename(d->reldum.relid, btree);
  68:         tp = tuple + d->reldum.relwid - LIDSIZE * d->reldum.reldim;
  69:         bmove(tp, lid, LIDSIZE * d->reldum.reldim);
  70:         nolid = 0;
  71:         for (i = 0; i < d->reldum.reldim; ++i)
  72:         {
  73:             if (lid[i] < 0 || (lid[i] > 0 && nolid))
  74:                 return(2);
  75:             nolid = !(lid[i]);
  76:         }
  77:     }
  78: 
  79:     if (d->reldum.reldim > 0)
  80:     {
  81:         if (insert_mbtree(d, btree, lid, tid, &tidpos) < 0)
  82:             return(2);
  83:         tp = tuple + d->reldum.relwid - LIDSIZE * d->reldum.reldim;
  84:         bmove(lid, tp, d->reldum.reldim * LIDSIZE);
  85:     }
  86: 
  87:     /* put tuple in position "tid" */
  88:     put_tuple(tid, Acctuple, need);
  89: 
  90:     d->reladds++;
  91: 
  92:     return (0);
  93: }

Defined functions

insert defined in line 7; never used
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 847
Valid CSS Valid XHTML 1.0 Strict