1: # include   <ingres.h>
   2: # include   <access.h>
   3: # include   <sccs.h>
   4: 
   5: SCCSID(@(#)seq_atts.c	8.1	12/31/84)
   6: 
   7: /*
   8: ** Seq_attributes - get all attributes of a relation in their correct order.
   9: **
  10: **	Seq_attributes() can be called when it is desired to get all
  11: **	attribute tuples for a relation. They are guaranteed to be in
  12: **	the same order as they were created in; that is "attid" order.
  13: **
  14: **	The calling convention is:
  15: **
  16: **		seq_init(Attribute_descriptor, Descriptor_for_relation)
  17: **
  18: **		while (seq_attribute(Att_desc, Des_for_rel, Tuple)
  19: **		{
  20: **		}
  21: **
  22: **	The first parameter is an OPEN descriptor for the attribute
  23: **	relation. The second parameter is a descriptor for the relation.
  24: **	It must have the relation-relation tuple (ie openr mode -1).
  25: **	The third parameter is a place to put the attribute. Its
  26: **	dimension must be at least sizeof (attribute structure).
  27: **
  28: **	Seq_attribute attempts to optimize the retrieval of the
  29: **	attributes. It assumes initially that the are physically
  30: **	stored sequentially. If so it will retrieve them in the
  31: **	minimum possible number of accesses.
  32: **
  33: **	If it finds one tuple out of sequence then all future
  34: **	scans will start from that first out of sequence tuple.
  35: */
  36: 
  37: struct tup_id   Seq_tdl, Seq_tdh, Seq_tdf;
  38: int     Seq_seqmode, Seq_next;
  39: 
  40: 
  41: 
  42: seq_init(a, r)
  43: register DESC   *a;
  44: register DESC   *r;
  45: {
  46:     register int        i;
  47:     struct attribute    attkey;
  48: 
  49:     clearkeys(a);
  50:     setkey(a, &attkey, r->reldum.relid, ATTRELID);
  51:     setkey(a, &attkey, r->reldum.relowner, ATTOWNER);
  52:     if (i = find(a, EXACTKEY, &Seq_tdl, &Seq_tdh, &attkey))
  53:         syserr("seq_init:find:%d", i);
  54: 
  55:     Seq_seqmode = TRUE;
  56:     Seq_next = 1;
  57: }
  58: 
  59: 
  60: seq_attributes(a, r, atup)
  61: register DESC           *a;
  62: register DESC           *r;
  63: register struct attribute   *atup;
  64: {
  65:     int i, nxttup;
  66: 
  67:     if (Seq_next > r->reldum.relatts)
  68:         return (0); /* no more attributes */
  69: 
  70:     if (!Seq_seqmode)
  71:     {
  72:         /* attributes not stored sequencially, start from first attribute */
  73:         bmove(&Seq_tdf, &Seq_tdl, sizeof (Seq_tdl));
  74:         nxttup = FALSE;
  75:     }
  76:     else
  77:         nxttup = TRUE;
  78: 
  79:     while ((i = get(a, &Seq_tdl, &Seq_tdh, atup, nxttup)) == 0)
  80:     {
  81: 
  82:         nxttup = TRUE;
  83:         /* make sure this is a tuple for the right relation */
  84:         if (kcompare(a, atup, r))
  85:             continue;
  86: 
  87:         /* is this the attribute we want? */
  88:         if (atup->attid != Seq_next)
  89:         {
  90:             if (Seq_seqmode)
  91:             {
  92:                 /*
  93: 				** Turn off seq mode. Save the tid of
  94: 				** the current tuple. It will be the
  95: 				** starting point for the next call
  96: 				** to seq_attribute
  97: 				*/
  98:                 bmove(&Seq_tdl, &Seq_tdf, sizeof (Seq_tdf));
  99:                 Seq_seqmode = FALSE;
 100:             }
 101: 
 102:             continue;
 103:         }
 104: 
 105:         /* got current attribute. increment to next attribute */
 106:         Seq_next++;
 107:         return (1);
 108:     }
 109: 
 110:     /* fell out of loop. either bad get return or missing attribute */
 111:     syserr("seq_att:bad or missing %d,%d", i, Seq_next);
 112: }

Defined functions

seq_init defined in line 42; used 2 times

Defined variables

Seq_next defined in line 38; used 5 times
Seq_seqmode defined in line 38; used 4 times
Seq_tdf defined in line 37; used 3 times
Seq_tdh defined in line 37; used 2 times
Seq_tdl defined in line 37; used 5 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 585
Valid CSS Valid XHTML 1.0 Strict