|
|
1.1 root 1: # include <ingres.h>
2: # include <aux.h>
3: # include <catalog.h>
4: # include <tree.h>
5: # include <symbol.h>
6: # include <access.h>
7: # include <func.h>
8: # include <pv.h>
9: # include <sccs.h>
10:
11: SCCSID(@(#)display.c 7.2 5/31/83)
12:
13: /*
14: ** DISPLAY -- display query corresponding to view, permission,
15: ** or intgerity declaration
16: */
17:
18:
19:
20:
21: extern short tTdbu[];
22: extern int display();
23: extern int null_fn();
24:
25: struct fn_def DsplayFn =
26: {
27: "DISPLAY",
28: display,
29: null_fn,
30: null_fn,
31: NULL,
32: 0,
33: tTdbu,
34: 100,
35: 'Z',
36: 0
37: };
38: /*
39: ** DISPLAY -- display query
40: **
41: ** Parameters:
42: ** pc -- number of args in pv
43: ** pv -- pv[i] == 4 for VIEW, 5 for PERMIT, 6 for INTEGRITY
44: ** where i % 2 == 0
45: ** pv[i] -- relation names for which pv[i-1] is mode
46: ** where i%2==1
47: **
48: ** Returns:
49: ** 0 -- total success
50: ** err -- error number of last error
51: **
52: ** Side Effects:
53: ** prints out definition of appropriate characteristic of relation
54: **
55: ** Trace Flags:
56: ** 33, -1
57: */
58:
59:
60: display(pc, pv)
61: int pc;
62: PARM pv[];
63: {
64: register int ac;
65: register PARM *av;
66: extern DESC Treedes;
67: register int i;
68: int err;
69: char err_array[PV_MAXPC];
70: auto int mode;
71:
72: # ifdef xZTR1
73: if (tTf(50, -1))
74: {
75: printf("display: ");
76: prvect(pc, pv);
77: }
78: # endif
79:
80: err = 0;
81: if (pc % 2 != 0)
82: syserr("display: bad param count %d", pc);
83: opencatalog("tree", 0);
84:
85: for (ac = 0, av = pv; ac < pc; av++, ac++)
86: {
87: mode = atoi(av->pv_val.pv_str);
88: av++;
89: err_array[ac++] = 0;
90: err_array[ac] = disp(av->pv_val.pv_str, mode);
91: }
92: for (ac = 0, av = pv; ac < pc; av++, ac++)
93: {
94: if (err_array[ac])
95: err = error(5400 + err_array[ac], (av->pv_val).pv_str, 0);
96: }
97: return (err);
98: }
99: /*
100: ** DISP -- display integrity, permit, or define query on a relation
101: **
102: ** Finds a relation owned by the user or the DBA and passes
103: ** the name and owner to the appropritae routine depending on
104: ** mode.
105: **
106: ** Parameters:
107: ** relation -- relation on which query is to be printed
108: ** mode -- the print mode:
109: ** 4 -- view
110: ** 5 -- permit
111: ** 6 -- integrity
112: **
113: ** Returns:
114: ** 0 -- success
115: ** 1 -- no such relation, or none seeable by the user.
116: ** 3 -- VIEW mode and relation not a view
117: ** 4 -- PERMIT and no permissions on relation
118: ** 5 -- INTEGRITY mode and no integrity constraints
119: **
120: ** Trace Flags:
121: ** 33, 8
122: */
123:
124: disp(relation, mode)
125: char *relation;
126: int mode;
127: {
128: DESC d;
129: register int i;
130: extern char *Resrel;
131:
132: # ifdef xZTR1
133: if (tTf(50, 8))
134: printf("disp: relation %s\n", relation);
135: # endif
136:
137: Resrel = relation;
138: i = openr(&d, -1, relation);
139: if (i > 0)
140: return (1);
141: else if (i < 0)
142: syserr("disp: openr(%s) ret %d", relation, i);
143: switch (mode)
144: {
145: case 4: /* View query */
146: if (d.reldum.relstat & S_VIEW)
147: pr_def(relation, d.reldum.relowner);
148: else
149: return (3);
150: break;
151:
152: case 5:
153: if (pr_prot(relation, &d))
154: return (4);
155: break;
156:
157: case 6:
158: if (d.reldum.relstat & S_INTEG)
159: pr_integrity(relation, d.reldum.relowner);
160: else
161: return (5);
162: break;
163:
164: default:
165: syserr("disp: mode == %d", mode);
166: }
167: return (0);
168: }
169: /*
170: ** PR_DEF -- Print "define view" query of a view
171: **
172: ** Parameters:
173: ** relation -- relation in question
174: ** owner -- relowner
175: **
176: ** Returns:
177: ** none
178: **
179: ** Side Effects:
180: ** reads a tree, clears range table
181: **
182: ** Trace Flags:
183: ** 33, 9
184: */
185:
186: pr_def(relation, owner)
187: char *relation;
188: char *owner;
189: {
190: register QTREE *t;
191: QTREE *gettree();
192:
193: # ifdef xZTR1
194: if (tTf(50, 9))
195: printf("pr_def(relation=\"%s\", owner=%s)\n", relation, owner);
196: # endif
197:
198: printf("View %s defined:\n\n", relation);
199: clrrange();
200:
201: /* Treeid == 0 because views have only one definition */
202: t = gettree(relation, owner, mdVIEW, 0);
203: pr_range();
204: printf("define view ");
205: pr_tree(t);
206: }
207: /*
208: ** PR_INTEGRITY -- print out integrity constraints on a relation
209: **
210: ** Finds all integrity tuples for this unique relation, and
211: ** calls pr_int() to print a query from them.
212: **
213: ** Parameters:
214: ** relid -- rel name
215: ** relowner -- 2 byte owner id
216: **
217: ** Returns:
218: ** none
219: **
220: ** Side Effects:
221: ** file activity, query printing
222: **
223: ** Trace Flags:
224: ** 33, 9
225: */
226:
227: pr_integrity(relid, relowner)
228: char *relid;
229: char *relowner;
230: {
231: extern DESC Intdes;
232: TID hitid, lotid;
233: struct integrity key, tuple;
234: register int i;
235:
236:
237: # ifdef xZTR1
238: if (tTf(50, 9))
239: printf("pr_integrity(relid =%s, relowner=%s)\n",
240: relid, relowner);
241: # endif
242:
243: printf("Integrity constraints on %s are:\n\n", relid);
244: opencatalog("integrities", 0);
245:
246: /* get integrities tuples for relid, relowner */
247: clearkeys(&Intdes);
248: setkey(&Intdes, &key, relid, INTRELID);
249: setkey(&Intdes, &key, relowner, INTRELOWNER);
250: if (i = find(&Intdes, EXACTKEY, &lotid, &hitid, &key))
251: syserr("pr_integrity: find %d", i);
252: for ( ; ; )
253: {
254: if (i = get(&Intdes, &lotid, &hitid, &tuple, TRUE))
255: break;
256: if (kcompare(&Intdes, &tuple, &key) == 0)
257: pr_int(&tuple, relid);
258: }
259: if (i != 1)
260: syserr("pr_integrity: get %d", i);
261: }
262: /*
263: ** PR_INT -- print an integrity definition given a integrities tuple
264: **
265: ** Parameters:
266: ** i -- integrity tuple
267: **
268: ** Returns:
269: ** none
270: **
271: ** Side Effects:
272: ** prints a query
273: ** reads a tree
274: */
275:
276: pr_int(i, relid)
277: register struct integrity *i;
278: char *relid;
279: {
280: register QTREE *t;
281: QTREE *gettree();
282:
283: clrrange();
284: t = gettree(i->intrelid, i->intrelowner, mdINTEG, i->inttree);
285: printf("Integrity constraint %d -\n\n", i->inttree);
286: pr_range();
287:
288: printf("define integrity on ");
289: pr_rv(Qt.qt_resvar = i->intresvar);
290: printf(" is ");
291: pr_qual(t->right);
292: printf("\n\n\n");
293:
294: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.