|
|
1.1 root 1: # include <ingres.h>
2: # include <symbol.h>
3: # include <access.h>
4: # include <lock.h>
5: # include <sccs.h>
6:
7: SCCSID(@(#)scan_dups.c 7.1 2/5/81)
8:
9:
10: /*
11: ** Scan for duplicates. Start with the page
12: ** specified by tid and
13: ** continue until there are no more pages
14: **
15: ** Scan_dups guarantees that the same page will
16: ** be in the buffer on entry and exit
17: **
18: ** returns:
19: ** <0 if fatal error
20: ** 0 if not duplicate
21: ** 1 if duplicate
22: */
23:
24: scan_dups(d, tid, tuple)
25: DESC *d;
26: register TID *tid;
27: char *tuple;
28: {
29: register int dup, pagerr;
30: TID savetid;
31:
32: stuff_page(&savetid, &Acc_head->thispage);
33:
34: Acclock = FALSE; /* turn concurrency off */
35: dup = 0; /* assume success */
36:
37: do
38: {
39: if (pagerr = get_page(d, tid))
40: break; /* fatal error */
41:
42: if (dup = dup_check(d, tid, tuple))
43: break; /* found duplicate */
44:
45: stuff_page(tid, &Acc_head->ovflopg);
46: } while (Acc_head->ovflopg);
47:
48: if (pagerr || (pagerr = get_page(d, &savetid)))
49: dup = pagerr; /* return fatal page error */
50:
51: Acclock = TRUE; /* turn concurency on */
52: return (dup);
53: }
54: /*
55: ** DUP_CHECK -- check current page for a duplicate of tuple;
56: **
57: ** returns:
58: ** 0 if not duplicate
59: ** 1 if duplicate
60: */
61:
62: dup_check(d, tid, tuple1)
63: register DESC *d;
64: TID *tid;
65: char *tuple1;
66: {
67: register int i, dom;
68: short *lp;
69: int len, lastline, tups_equal;
70: char *tup1, *tup2;
71: char tuple2[MAXTUP];
72: char *getint_tuple();
73:
74: /* determine starting and ending points */
75: lastline = Acc_head->nxtlino;
76: lp = Acc_head->linetab;
77:
78: /* check each tuple for duplication */
79: for (i = 0; i < lastline; i++)
80: {
81: /* is this line used? */
82: if (*lp--)
83: {
84: /* yes. get tuple and check it */
85: tid->line_id = i;
86: tup2 = getint_tuple(d, tid, tuple2);
87: tup1 = tuple1;
88: tups_equal = TRUE; /* assume equal */
89:
90: /* now check each domain for duplication */
91: for (dom = 1; dom <= d->reldum.relatts; dom++)
92: {
93: len = d->relfrml[dom] & I1MASK;
94: if (d->relfrmt[dom] == CHAR)
95: tups_equal = scompare(tup1, len, tup2, len) == 0;
96: else
97: tups_equal = bequal(tup1, tup2, len);
98: if (!tups_equal)
99: {
100: /* not duplicates */
101: break;
102: }
103: tup1 += len;
104: tup2 += len;
105: }
106: if (tups_equal)
107: return (1); /* duplicate */
108: }
109: }
110: return (0); /* no duplicate */
111: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.