1: # include "../ingres.h" 2: # include "../aux.h" 3: # include "../symbol.h" 4: # include "../tree.h" 5: # include "../pipes.h" 6: # include "ovqp.h" 7: 8: extern struct pipfrmt Inpipe, Outpipe; 9: extern struct descriptor Reldesc, Srcdesc; 10: struct descriptor Indesc; 11: 12: endqry(code) 13: int code; 14: 15: /* 16: ** Endqry is called at the end of a query, either 17: ** in response to getqry receiving an EXIT or as a 18: ** result of a user error 19: */ 20: { 21: register int i; 22: 23: i = code; 24: 25: if (Equel && Retrieve) 26: equeleol(EXIT); /* signal end of query to equel process */ 27: if (i == ACK) 28: { 29: if (Bopen) 30: i = UPDATE; 31: else 32: i = NOUPDATE; 33: 34: closeall(); 35: retdecomp(i); 36: } 37: else 38: { 39: if (i == NOACK) 40: { 41: if (Bopen) 42: { 43: /* remove the batch file */ 44: rmbatch(); 45: Bopen = FALSE; 46: } 47: } 48: else 49: syserr("endqry:bad ack %d",code); 50: closeall(); 51: } 52: } 53: 54: 55: 56: 57: ov_err(code) 58: int code; 59: /* 60: ** Usererr is called when a user generated 61: ** error is detected. The error number is 62: ** sent to DECOMP for processing. The read pipe 63: ** is flushed. A non-local goto (reset) returns 64: ** to main.c (see setexit()). 65: */ 66: { 67: retdecomp(code); /* send error message to decomp */ 68: endqry(NOACK); /* end the query with no ack to decomp */ 69: /* and close all relations */ 70: rdpipe(P_SYNC, &Inpipe, R_decomp); /* flush the pipe */ 71: 72: /* copy the error message from decomp to the parser */ 73: copyreturn(); 74: reset(); /* return to main.c */ 75: syserr("ov_err:impossible return from reset"); 76: } 77: 78: 79: 80: closeall() 81: { 82: closerel(&Srcdesc); 83: closerel(&Reldesc); 84: closecatalog(FALSE); 85: closerel(&Indesc); 86: if (Bopen) 87: { 88: closebatch(); 89: Bopen = FALSE; 90: } 91: } 92: 93: retdecomp(code) 94: int code; 95: /* 96: ** writes a RETVAL symbol with value "code". 97: ** if code = EMPTY then retdecomp will wait 98: ** for an EOP acknowledgement from DECOM before 99: ** returning. 100: ** If the query was a simple 101: ** aggregate, then the aggregate values are also written. 102: */ 103: 104: { 105: struct retcode ret; 106: register i, t; 107: struct stacksym ressym; 108: struct symbol **alist; 109: struct al_sym 110: { 111: char type; 112: char len; 113: int aoper; 114: char atype; 115: char alen; 116: }; 117: 118: # ifdef xOTR1 119: if (tTf(33, 1)) 120: printf("RETDECOMP: returning %d\n", code); 121: # endif 122: ret.rc_status = code; 123: ret.rc_tupcount = Tupsfound; 124: wrpipe(P_NORM, &Outpipe, W_decomp, &ret, sizeof (ret)); 125: 126: if (Alist && !Bylist) 127: { 128: alist = Alist; 129: i = Agcount; 130: Tend = Outtup; 131: 132: while (i--) 133: { 134: 135: /* find next AOP */ 136: while ((t = (*++alist)->type) != AOP) 137: if (t == ROOT) 138: syserr("retdecomp:missing aop %d", i); 139: 140: ressym.type = ((struct al_sym *) *alist)->atype; 141: t = ressym.len = ((struct al_sym *) *alist)->alen; 142: t &= I1MASK; 143: if (ressym.type == CHAR) 144: { 145: cpderef(ressym.value) = Tend; 146: /* make sure it is blank padded */ 147: pad(Tend, t); 148: } 149: else 150: bmove(Tend, ressym.value, t); 151: Tend += t; 152: 153: # ifdef xOTR1 154: if (tTf(33, 2)) 155: { 156: printf("returning aggregate:"); 157: prstack(&ressym); 158: } 159: # endif 160: pwritesym(&Outpipe, W_decomp, &ressym); /* write top of stack to decomp */ 161: } 162: } 163: 164: wrpipe(P_END, &Outpipe, W_decomp); 165: } 166: openrel(desc, relname, mode) 167: struct descriptor *desc; 168: char *relname; 169: int mode; 170: 171: /* 172: ** openrel checks to see if the descriptor already 173: ** holds the relation to be opened. If so it returns. 174: ** Otherwise it closes the relation and opens the new one 175: */ 176: 177: { 178: register struct descriptor *d; 179: register char *name; 180: register int i; 181: 182: d = desc; 183: name = relname; 184: # ifdef xOTR1 185: if (tTf(33, 4)) 186: printf("openrel: open=%d current=%.12s, new=%.12s\n", d->relopn, d->relid, name); 187: # endif 188: 189: if (d->relopn) 190: { 191: if (bequal(d->relid, name, MAXNAME)) 192: return; 193: # ifdef xOTR1 194: if (tTf(33, 5)) 195: printf("openrel:closing the old\n"); 196: # endif 197: closerel(d); 198: } 199: if (i = openr(d, mode, name)) 200: syserr("can't open %.12s %d", name, i); 201: } 202: 203: 204: closerel(desc) 205: struct descriptor *desc; 206: 207: /* 208: ** close the relation 209: */ 210: 211: { 212: register struct descriptor *d; 213: register int i; 214: 215: d = desc; 216: # ifdef xOTR1 217: if (tTf(33, 6)) 218: printf("closerel open=%d rel=%.12s\n", d->relopn, d->relid); 219: # endif 220: if (d->relopn) 221: if (i = closer(d)) 222: { 223: printf("closerel open=%d rel=%.12s\n", d->relopn, d->relid); 224: syserr("can't close %.12s %d", d->relid, i); 225: } 226: } 227: struct descriptor *openindex(relid) 228: char *relid; 229: { 230: openrel(&Indesc, relid, 0); 231: return (&Indesc); 232: } 233: 234: /* 235: ** SYSTEM RELATION DESCRIPTOR CACHE DEFINITION 236: ** 237: */ 238: 239: extern struct descriptor Inddes; 240: 241: 242: 243: struct desxx Desxx[] = 244: { 245: "indexes", &Inddes, 0, 246: 0 247: };