1: # include "../ingres.h" 2: # include "../aux.h" 3: # include "../pipes.h" 4: # include "qrymod.h" 5: # include "../unix.h" 6: 7: 8: /* 9: ** QRYMOD -- query modification process 10: ** 11: ** This process modifies queries to implement views, protection, 12: ** and integrity. 13: ** 14: ** Positional Parameters: 15: ** standard 16: ** 17: ** Flags: 18: ** none 19: ** 20: ** Files: 21: ** 'tree' relation -- stores trees for use by all 22: ** subsections. 23: ** 'view' relation -- stores maps between views and 24: ** base relations. In fact, this is not needed 25: ** by query modification, but only by destroy 26: ** and help. 27: ** 'protect' relation -- stores information to tell 28: ** which protection constraint is appropriate 29: ** at a given time. 30: ** 'constraint' relation -- maintains mappings between 31: ** relations and trees in the 'tree' catalog; 32: ** the qualifications on these trees must remain 33: ** true at the completion of every query. 34: ** 'relation' relation -- the relstat field contains 35: ** useful information for several of the commands. 36: ** For views, most of the domains are ignored 37: ** by the rest of the system. 38: ** 39: ** Return Codes: 40: ** standard 41: ** 42: ** Defines: 43: ** Pipe -- the input pipe block. 44: ** Outpipe -- the output pipe block. 45: ** Terminal -- the current terminal id. 46: ** Reldes -- the relation relation descriptor. 47: ** Treedes -- the tree relation descriptor. 48: ** Prodes -- the protection relation descriptor. 49: ** Nullsync -- set if we should send a null query on an 50: ** error (to free up an EQUEL program). 51: ** main() 52: ** rubproc() 53: ** 54: ** Requires: 55: ** define -- to define new constraints. 56: ** readqry -- to read and build a query with tree. 57: ** qrymod -- to do query modification. 58: ** issue -- to issue a query. 59: ** copypipes -- to copy dbu requests through. 60: ** rdpipe, wrpipe 61: ** tTrace, initproc -- for initialization 62: ** setexit -- for disasters (such as rubout). 63: ** openr -- to open the 'tree' catalog for use by 64: ** 'define' and 'qrymod'. 65: ** ttyn -- to get the current terminal id. 66: ** acc_init -- to initialize the DBA code. 67: ** 68: ** Trace Flags: 69: ** 0 70: ** 71: ** Diagnostics: 72: ** none 73: ** 74: ** History: 75: ** 2/14/79 -- version 6.2 release. 76: */ 77: 78: 79: 80: struct pipfrmt Pipe, Outpipe; 81: # ifndef xV7_UNIX 82: char Terminal; /* terminal descriptor */ 83: # endif 84: # ifdef xV7_UNIX 85: char Terminal[3]; /* terminal id */ 86: # endif 87: struct descriptor Prodes; /* protection catalog descriptor */ 88: struct descriptor Reldes; /* relation catalog descriptor */ 89: struct descriptor Treedes; /* tree catalog descriptor */ 90: struct descriptor Intdes; /* integrity catalog descriptor */ 91: int Nullsync; /* send null qry on error */ 92: extern int Equel; /* equel flag */ 93: char *Qbuf; /* the query buffer */ 94: 95: 96: 97: main(argc, argv) 98: int argc; 99: char **argv; 100: { 101: extern QTREE *readqry(); 102: extern QTREE *qrymod(); 103: extern int pipetrrd(); 104: extern int relntrrd(); 105: register char execid; 106: register char funcid; 107: register QTREE *root; 108: struct retcode *rc; 109: extern struct retcode *issue(); 110: int qbufbuf[QBUFSIZ / 2]; 111: # ifdef xV7_UNIX 112: extern char *ttyname(); 113: char *tty; 114: # endif 115: 116: # ifdef xQTR1 117: tTrace(&argc, argv, 'Q'); 118: # endif 119: initproc("QRYMOD", argv); 120: acc_init(); 121: Qbuf = (char *) qbufbuf; 122: 123: /* determine user's terminal for protection algorithm */ 124: # ifndef xV7_UNIX 125: Terminal = ttyn(1); 126: if (Terminal == 'x') 127: Terminal = ' '; 128: # endif 129: # ifdef xV7_UNIX 130: tty = ttyname(1); 131: if (bequal(tty, "/dev/", 5)) 132: tty = &tty[5]; 133: if (bequal(tty, "tty", 3)) 134: tty = &tty[3]; 135: pmove(tty, Terminal, 2, ' '); 136: Terminal[2] = '\0'; 137: # endif 138: 139: setexit(); 140: # ifdef xQTR3 141: if (tTf(0, 1)) 142: printf("setexit->\n"); 143: # endif 144: 145: /* 146: ** MAIN LOOP 147: ** Executed once for each query, this loop reads the 148: ** exec & funcid, determines if the query is 149: ** "interesting", modifies it if appropriate, and 150: ** if there is anything left worth running, passes 151: ** it down the pipe. 152: */ 153: 154: for (;;) 155: { 156: Nullsync = FALSE; 157: 158: /* read the new function */ 159: rdpipe(P_PRIME, &Pipe); 160: execid = rdpipe(P_EXECID, &Pipe, R_up); 161: funcid = rdpipe(P_FUNCID, &Pipe, R_up); 162: 163: /* decide on the action to perform */ 164: switch (execid) 165: { 166: 167: case EXEC_DECOMP: 168: /* read in query and return tree */ 169: root = readqry(&pipetrrd, TRUE); 170: rdpipe(P_SYNC, &Pipe, R_up); 171: 172: /* test for sync of Equel on errors */ 173: if (Resultvar == -1 && Equel) 174: Nullsync = TRUE; 175: 176: /* do tree modification and issue query */ 177: root = qrymod(root); 178: rc = issue(execid, funcid, root); 179: 180: break; 181: 182: case EXEC_QRYMOD: /* define, view, protect, or integrity */ 183: define(funcid); 184: rc = NULL; 185: break; 186: 187: default: /* DBU function */ 188: wrpipe(P_PRIME, &Outpipe, execid, 0, funcid); 189: copypipes(&Pipe, R_up, &Outpipe, W_down); 190: rc = issue(execid, funcid, NULL); 191: break; 192: 193: } 194: 195: /* signal done to above */ 196: wrpipe(P_PRIME, &Pipe, execid, 0, funcid); 197: if (rc != NULL) 198: wrpipe(P_NORM, &Pipe, W_up, rc, sizeof *rc); 199: wrpipe(P_END, &Pipe, W_up); 200: } 201: } 202: 203: rubproc() 204: { 205: resyncpipes(); 206: }