1: #
   2: 
   3: /*
   4: **  DISPLAY -- display query corresponding to view, permission,
   5: **		or intgerity declaration
   6: **
   7: **	Defines:
   8: **		display() -- main function
   9: **		disp() -- routes VIEW, PERMIT, and INTEGRITY
  10: **		pr_def() -- print view definition
  11: **		pr_integrity() -- print out integrity contstraints on a rel
  12: **
  13: **	Requires:
  14: **		pr_permit() -- to print perissions
  15: **
  16: **	History:
  17: **		11/15/78 (marc) -- written
  18: */
  19: 
  20: 
  21: 
  22: # include   "../ingres.h"
  23: # include   "../aux.h"
  24: # include   "../catalog.h"
  25: # include   "../tree.h"
  26: # include   "../symbol.h"
  27: # include   "../access.h"
  28: 
  29: # define    QTREE       struct querytree
  30: 
  31: 
  32: char        *Resrel;    /* Used in pr_tree() [pr_tree.c] */
  33: char        Mode;       /* 4 - View, 5 - permission, 6 - interity
  34: 				 * query print
  35: 				 */
  36: 
  37: /*
  38: **  DISPLAY -- display query
  39: **
  40: **	Parameters:
  41: **		argc -- number of args in argv
  42: **		argv -- argv [i] == 4 for VIEW, 5 for PERMIT, 6 for INTEGRITY
  43: **				where i % 2 == 0
  44: **		argv [i] -- relation names for which argv[i-1] is Mode
  45: **				where i%2==1
  46: **
  47: **	Returns:
  48: **		0 -- total success
  49: **		err -- error number of last error
  50: **
  51: **	Side Effects:
  52: **		prints out definition of appropriate characteristic of relation
  53: **
  54: **	Requires:
  55: **		disp()
  56: **
  57: **	Called By:
  58: **		dbu/main.c -- DBU controller
  59: **
  60: **	Diagnostics:
  61: **		5401 -- "relation" doesn't exist or
  62: **			does not belong to the user nor the DBA.
  63: **		5403 -- "relation" is not a view [Mode == 4]
  64: **		5404 -- "relation" has no permissions granted [Mode == 5]
  65: **		5405 -- "relation" has no integrity constraints on it [Mode == 6]
  66: **
  67: **	Trace Flags:
  68: **		11, -1
  69: **
  70: **	Syserrs:
  71: **		display: bad openr
  72: **		display: bad argc (odd)
  73: **			bad Mode parameter
  74: **
  75: **	History:
  76: **		11/15/78 (marc) -- written
  77: */
  78: 
  79: 
  80: display(argc, argv)
  81: int     argc;
  82: char        **argv;
  83: {
  84:     register int            ac;
  85:     register char           **av;
  86:     extern struct descriptor    Treedes;
  87:     register            i;
  88:     char                err_array [MAXPARMS]; /* errors are coded
  89: 							  * this array for
  90: 							  * printing out
  91: 							  * at the end
  92: 							  */
  93:     int             err;
  94: 
  95: #	ifdef xZTR1
  96:     if (tTf(11, -1))
  97:     {
  98:         printf("display: ");
  99:         prargs(argc, argv);
 100:     }
 101: #	endif
 102: 
 103:     err = 0;
 104:     if (argc % 2 != 0)
 105:         syserr("display: bad argc %d", argc);
 106:     opencatalog("tree", 0);
 107: 
 108:     for (ac = 0, av = argv; ac < argc; av++, ac++)
 109:     {
 110:         if (atoi(*av, &Mode))
 111:             syserr("display: bad mode \"%s\"", *av);
 112:         Resrel = *++av;
 113:         err_array[ac++] = 0;
 114:         err_array [ac] = disp(*av);
 115:     }
 116:     for (ac = 0, av = argv; ac < argc; av++, ac++)
 117:     {
 118:         if (err_array [ac])
 119:             err = error(5400 + err_array [ac], *av, 0);
 120:     }
 121:     return (err);
 122: }
 123: 
 124: /*
 125: ** DISP -- display integrity, permit, or define query on a relation
 126: **
 127: **	Finds a relation owned by the user or the DBA and passes
 128: **	the name and owner to the appropritae routine depending on
 129: **	Mode.
 130: **
 131: **	Parameters:
 132: **		relation -- relation on which query is to be printed
 133: **
 134: **	Returns:
 135: **		0 -- success
 136: **		1 -- no such relation, or none seeable by the user.
 137: **		3 -- VIEW mode and relation not a view
 138: **		4 -- PERMIT and no permissions on relation
 139: **		5 -- INTEGRITY mode and no integrity constraints
 140: **
 141: **	Requires:
 142: **		Mode -- for type of query to print
 143: **		pr_def(),
 144: **		pr_prot() -- to print queries
 145: **
 146: **	Called By:
 147: **		display()
 148: **
 149: **	Trace Flags:
 150: **		11, 8
 151: **
 152: **	History:
 153: **		11/15/78 -- (marc) written
 154: **		12/19/78 -- (marc) changed pr_prot call to accomodate
 155: **			S_PROT[12] in relation.relstat
 156: */
 157: 
 158: disp(relation)
 159: char    *relation;
 160: {
 161:     struct descriptor       d;
 162:     register            i;
 163: 
 164: #	ifdef xZTR1
 165:     if (tTf(11, 8))
 166:         printf("disp: relation %s\n", relation);
 167: #	endif
 168: 
 169:     i = openr(&d, -1, relation);
 170:     if (i > 0)
 171:         return (1);
 172:     else if (i < 0)
 173:         syserr("disp: openr(%s) ret %d", relation, i);
 174:     switch (Mode)
 175:     {
 176:       case 4:       /* View query */
 177:         if (d.relstat & S_VIEW)
 178:             pr_def(relation, d.relowner);
 179:         else
 180:             return (3);
 181:         break;
 182: 
 183:       case 5:
 184:         if (pr_prot(relation, &d))
 185:             return (4);
 186:         break;
 187: 
 188:       case 6:
 189:         if (d.relstat & S_INTEG)
 190:             pr_integrity(relation, d.relowner);
 191:         else
 192:             return (5);
 193:         break;
 194: 
 195:       default:
 196:         syserr("disp: Mode == %d", Mode);
 197:     }
 198:     return (0);
 199: }
 200: 
 201: /*
 202: **  PR_DEF -- Print "define view" query of a view
 203: **
 204: **	Parameters:
 205: **		relation -- relation in question
 206: **		owner -- relowner
 207: **
 208: **	Returns:
 209: **		none
 210: **
 211: **	Side Effects:
 212: **		reads a tree, clears range table
 213: **
 214: **	Requires:
 215: **		pr_tree() [pr_tree.c]
 216: **		Depends on treeid == 0 because there is only on view
 217: **		definition.
 218: **
 219: **	Called By:
 220: **		disp()
 221: **
 222: **	Trace Flags:
 223: **		11, 9
 224: **
 225: **	History:
 226: **		11/15/78 -- (marc) written
 227: */
 228: 
 229: pr_def(relation, owner)
 230: char        *relation;
 231: char        *owner;
 232: {
 233:     register QTREE      *t;
 234:     QTREE           *gettree();
 235: 
 236: #	ifdef xZTR1
 237:     if (tTf(11, 9))
 238:         printf("pr_def(relation=\"%s\", owner=%s)\n", relation, owner);
 239: #	endif
 240: 
 241:     printf("View %s defined:\n\n", relation);
 242:     clrrange();
 243: 
 244:     /* Treeid == 0 because views have only one definition */
 245:     t = gettree(relation, owner, mdVIEW, 0);
 246:     pr_range();
 247:     printf("define view ");
 248:     pr_tree(t);
 249: }
 250: 
 251: /*
 252: **  PR_INTEGRITY -- print out integrity constraints on a relation
 253: **
 254: **	Finds all integrity tuples for this unique relation, and
 255: **	calls pr_int() to print a query from them.
 256: **
 257: **	Parameters:
 258: **		relid -- rel name
 259: **		relowner -- 2 byte owner id
 260: **
 261: **	Returns:
 262: **		none
 263: **
 264: **	Side Effects:
 265: **		file activity, query printing
 266: **
 267: **	Requires:
 268: **		pr_int() -- to print a query given an integrity
 269: **			tuple
 270: **
 271: **	Called By:
 272: **		disp()
 273: **
 274: **	Trace Flags:
 275: **		11, 9
 276: **
 277: **	Syserrs:
 278: **		"pr_integrity: find %d" -- find error
 279: **
 280: **	History:
 281: **		12/17/78 -- (marc) written
 282: */
 283: 
 284: pr_integrity(relid, relowner)
 285: char    *relid;
 286: char    *relowner;
 287: {
 288:     extern struct descriptor    Intdes;
 289:     struct tup_id           hitid, lotid;
 290:     struct integrity        key, tuple;
 291:     register            i;
 292: 
 293: 
 294: #	ifdef xZTR1
 295:     if (tTf(11, 9))
 296:         printf("pr_integrity(relid =%s, relowner=%s)\n",
 297:         relid, relowner);
 298: #	endif
 299: 
 300:     printf("Integrity constraints on %s are:\n\n", relid);
 301:     opencatalog("integrities", 0);
 302: 
 303:     /* get integrities tuples for relid, relowner */
 304:     clearkeys(&Intdes);
 305:     setkey(&Intdes, &key, relid, INTRELID);
 306:     setkey(&Intdes, &key, relowner, INTRELOWNER);
 307:     if (i = find(&Intdes, EXACTKEY, &lotid, &hitid, &key))
 308:         syserr("pr_integrity: find %d", i);
 309:     for ( ; ; )
 310:     {
 311:         if (i = get(&Intdes, &lotid, &hitid, &tuple, TRUE))
 312:             break;
 313:         if (kcompare(&Intdes, &tuple, &key) == 0)
 314:             pr_int(&tuple);
 315:     }
 316:     if (i != 1)
 317:         syserr("pr_integrity: get %d", i);
 318: }
 319: 
 320: /*
 321: **  PR_INT -- print an integrity definition given a integrities tuple
 322: **
 323: **	Parameters:
 324: **		g -- integrity tuple
 325: **
 326: **	Returns:
 327: **		none
 328: **
 329: **	Side Effects:
 330: **		prints a query
 331: **		reads a tree
 332: **
 333: **	Requires:
 334: **		gettree(), clrrange(), pr_range()
 335: **
 336: **	Called By:
 337: **		pr_integrity()
 338: **
 339: **	History:
 340: **		12/17/78 (marc) -- written
 341: **		1/9/79   -- (marc) modified to print inttree
 342: */
 343: 
 344: pr_int(g)
 345: struct integrity    *g;
 346: {
 347:     register struct integrity   *i;
 348:     register QTREE          *t;
 349:     extern int          Resultvar;
 350:     QTREE               *gettree();
 351: 
 352:     i = g;
 353:     clrrange();
 354:     t = gettree(i->intrelid, i->intrelowner, mdINTEG, i->inttree);
 355:     printf("Integrity constraint %d -\n\n", i->inttree);
 356:     pr_range();
 357: 
 358:     printf("define integrity on ");
 359:     pr_rv(Resultvar = i->intresvar);
 360:     printf(" is ");
 361:     pr_qual(t->right);
 362:     printf("\n\n\n");
 363: }

Defined functions

disp defined in line 158; used 1 times
pr_def defined in line 229; used 1 times
pr_int defined in line 344; used 1 times
pr_integrity defined in line 284; used 1 times

Defined variables

Mode defined in line 33; used 3 times
Resrel defined in line 32; used 1 times

Defined macros

QTREE defined in line 29; used 4 times
Last modified: 1995-02-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2758
Valid CSS Valid XHTML 1.0 Strict