]> andersk Git - moira.git/blame_incremental - dbck/phase4.dc
always check error status of every query
[moira.git] / dbck / phase4.dc
... / ...
CommitLineData
1/* $Header$
2 *
3 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
5 * <mit-copyright.h>.
6 */
7
8#include <mit-copyright.h>
9#include <moira.h>
10#include "dbck.h"
11EXEC SQL INCLUDE sqlca;
12
13static char phase4_qc_rcsid[] = "$Header$";
14
15
16count_boxes(id, u, boxes)
17int id;
18struct user *u;
19struct hash *boxes;
20{
21 int i;
22
23 if (u->potype == 'P') {
24 if (i = (int) hash_lookup(boxes, u->pobox_id))
25 hash_store(boxes, u->pobox_id, i+1);
26 else {
27 printf("User %s(%s) has pobox on non-POP server %d\n",
28 u->fullname, u->login, u->pobox_id);
29 printf("Not fixing this error\n");
30 }
31 }
32}
33
34
35check_box_counts(id, cnt, counts)
36EXEC SQL BEGIN DECLARE SECTION;
37int id, cnt;
38EXEC SQL END DECLARE SECTION;
39struct hash *counts;
40{
41 EXEC SQL BEGIN DECLARE SECTION;
42 int oldval, rowcount;
43 EXEC SQL END DECLARE SECTION;
44
45 oldval = (int) hash_lookup(counts, id);
46 cnt--;
47 if (oldval != cnt) {
48 printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
49 ((struct machine *) hash_lookup(machines, id))->name,
50 oldval, cnt);
51 if (single_fix("Update", 1)) {
52 EXEC SQL UPDATE serverhosts SET value1 = :cnt
53 WHERE service='POP' AND mach_id = :id;
54 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
55 if (rowcount > 0)
56 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
57 else
58 printf("Not fixed\n");
59 modified("serverhosts");
60 }
61 }
62}
63
64
65check_nfs_counts(id, n, hint)
66EXEC SQL BEGIN DECLARE SECTION;
67int id, hint;
68EXEC SQL END DECLARE SECTION;
69struct nfsphys *n;
70{
71 EXEC SQL BEGIN DECLARE SECTION;
72 int val, rowcount;
73 EXEC SQL END DECLARE SECTION;
74
75 val = n->count;
76 if (n->allocated != val) {
77 printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
78 ((struct machine *) hash_lookup(machines, n->mach_id))->name,
79 n->dir, n->allocated, val);
80 if (single_fix("Update", 1)) {
81 EXEC SQL UPDATE nfsphys SET allocated = :val
82 WHERE nfsphys_id = :id;
83 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
84 if (rowcount > 0)
85 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
86 else
87 printf("Not fixed\n");
88 modified("nfsphys");
89 }
90 }
91}
92
93
94phase4()
95{
96 struct hash *boxes, *counts;
97 EXEC SQL BEGIN DECLARE SECTION;
98 int id, cnt;
99 EXEC SQL END DECLARE SECTION;
100
101 printf("Phase 4 - Checking counts\n");
102
103 dprintf("Doing POBoxes...\n");
104 boxes = create_hash(10);
105 counts = create_hash(10);
106 EXEC SQL DECLARE csr401 CURSOR FOR
107 SELECT mach_id, value1 FROM serverhosts
108 WHERE service='POP';
109 EXEC SQL OPEN csr401;
110 while(1) {
111 EXEC SQL FETCH csr401 INTO :id, :cnt;
112 if (sqlca.sqlcode != 0) {
113 ingerr(&sqlca.sqlcode);
114 break;
115 }
116
117 hash_store(boxes, id, 1);
118 hash_store(counts, id, cnt);
119 }
120 EXEC SQL CLOSE csr401;
121 hash_step(users, count_boxes, boxes);
122 hash_step(boxes, check_box_counts, counts);
123
124 dprintf("Doing NFSphys...\n");
125 hash_step(nfsphys, check_nfs_counts, 0);
126}
127
128
129count_only_setup()
130{
131 EXEC SQL BEGIN DECLARE SECTION;
132 int id, status, id2, id3;
133 char name[33], last[17], first[17], buf[257];
134 EXEC SQL END DECLARE SECTION;
135 struct save_queue *sq;
136 struct user *u;
137 struct nfsphys *n;
138 struct machine *m;
139
140 dprintf("Loading users...\n");
141 users = create_hash(10000);
142 EXEC SQL DECLARE csr402 CURSOR FOR
143 SELECT users_id, login, last, first, status,
144 potype, pop_id, box_id FROM users
145 WHERE potype='POP';
146 EXEC SQL OPEN csr402;
147 while(1) {
148 EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status,
149 :buf, :id2, :id3;
150 if (sqlca.sqlcode != 0) {
151 ingerr(&sqlca.sqlcode);
152 break;
153 }
154
155 u = (struct user *) malloc(sizeof(struct user));
156 if (u == NULL)
157 out_of_mem("storing users");
158 strcpy(u->login, strtrim(name));
159 u->potype = buf[0];
160 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
161 u->fullname = strsave(buf);
162 u->status = status;
163 u->users_id = id;
164 switch (u->potype) {
165 case 'P':
166 u->pobox_id = id2;
167 break;
168 case 'S':
169 u->pobox_id = id3;
170 break;
171 default:
172 u->pobox_id = 0;
173 }
174 hash_store(users, id, u);
175 }
176 EXEC SQL CLOSE csr402;
177
178 dprintf("Loading machines...\n");
179 machines = create_hash(1000);
180 EXEC SQL DECLARE csr403 CURSOR FOR
181 SELECT mach_id, name FROM machine;
182 EXEC SQL OPEN csr403;
183 while(1) {
184 EXEC SQL FETCH csr403 INTO :id, :name;
185 if (sqlca.sqlcode != 0) {
186 ingerr(&sqlca.sqlcode);
187 break;
188 }
189
190 m = (struct machine *) malloc(sizeof(struct machine));
191 if (m == NULL)
192 out_of_mem("storing machines");
193 strcpy(m->name, strtrim(name));
194 m->mach_id = id;
195 hash_store(machines, id, m);
196 }
197 EXEC SQL CLOSE csr403;
198
199 dprintf("Loading nfsphys...\n");
200 nfsphys = create_hash(500);
201 EXEC SQL DECLARE csr404 CURSOR FOR
202 SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
203 EXEC SQL OPEN csr404;
204 while(1) {
205 EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
206 if (sqlca.sqlcode != 0) {
207 ingerr(&sqlca.sqlcode);
208 break;
209 }
210
211 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
212 if (n == NULL)
213 out_of_mem("storing nfsphys");
214 strcpy(n->dir, strtrim(name));
215 n->mach_id = id2;
216 n->nfsphys_id = id;
217 n->allocated = id3;
218 n->count = 0;
219 hash_store(nfsphys, id, n);
220 }
221 EXEC SQL CLOSE csr404;
222
223 dprintf("Counting quotas...\n");
224 EXEC SQL DECLARE csr405 CURSOR FOR
225 SELECT phys_id, quota FROM quota;
226 EXEC SQL OPEN csr405;
227 while(1) {
228 EXEC SQL FETCH csr405 INTO :id, :id2;
229 if (sqlca.sqlcode != 0) {
230 ingerr(&sqlca.sqlcode);
231 break;
232 }
233
234 if (n = (struct nfsphys *) hash_lookup(nfsphys, id)) {
235 n->count += id2;
236 }
237 }
238 EXEC SQL CLOSE csr405;
239}
This page took 0.078135 seconds and 5 git commands to generate.