]> andersk Git - moira.git/blame - dbck/fix.qc
moved generic_fix; keep track of modified tables; missing newline on
[moira.git] / dbck / fix.qc
CommitLineData
d2543f8c 1/* $Header$
2 *
3 * User interface routines for dbck (SMS database consistency checker)
4 *
5 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 */
9
10#include <mit-copyright.h>
11#include <sms.h>
12#include <stdio.h>
13#include "dbck.h"
14
afda48e8 15static char fix_qc_rcsid[] = "$Header$";
16
d2543f8c 17
18##char *_table;
19##char *_idfield;
20
21##generic_ffunc(id)
22##int id;
23##{
24## int rowcount;
25
26## delete _table where _table._idfield = id
27## inquire_equel(rowcount = "rowcount")
28 if (rowcount > 0)
29 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
30 else
31 printf("Not deleted\n");
afda48e8 32 modified(_table);
d2543f8c 33##}
34
35
36generic_delete(sq, pfunc, table, idfield, preen)
37struct save_queue *sq;
38void (*pfunc)();
39char *table, *idfield;
40int preen;
41{
42 _table = table;
43 _idfield = idfield;
44 generic_fix(sq, pfunc, "Delete", generic_ffunc, preen);
45}
46
47
48single_delete(table, idfield, id)
49char *table, *idfield;
50int id;
51{
52 _table = table;
53 _idfield = idfield;
54 generic_ffunc(id);
55}
56
57
58##zero_fix(table, zrfield, idfield, id)
59##char *table, *zrfield, *idfield;
60##int id;
61##{
62## int rowcount;
63
64## replace table (zrfield = 0) where table.idfield = id
65## inquire_equel(rowcount = "rowcount")
66 if (rowcount > 0)
67 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
68 else
69 printf("Not fixed\n");
afda48e8 70 modified(table);
d2543f8c 71##}
72
73
d2543f8c 74int single_fix(msg, preen)
75char *msg;
76int preen;
77{
78 int lmode;
79
80 lmode = mode;
81 if (mode == MODE_PREEN) {
82 if (preen)
83 lmode = MODE_YES;
84 else
85 lmode = MODE_NO;
86 }
87
88 switch (lmode) {
89 case MODE_ASK:
90 if (!prompt(msg))
91 break;
92 case MODE_YES:
93 return(1);
94 break;
95 case MODE_NO:
96 ;
97 }
98 return(0);
99}
100
101
afda48e8 102generic_fix(sq, pfunc, msg, ffunc, preen)
103struct save_queue *sq;
104char *msg;
105int (*pfunc)(), (*ffunc)();
106int preen;
107{
108 int id;
109
110 while (sq_get_data(sq, &id)) {
111 if ((*pfunc)(id) == 0 && single_fix(msg, preen))
112 (*ffunc)(id);
113 }
114 sq_destroy(sq);
115}
116
117
d2543f8c 118int prompt(msg)
119char *msg;
120{
121 char buf[BUFSIZ];
122## extern int dcmenable;
123
124 while (1) {
125 printf("%s (Y/N/Q)? ", msg);
126 fflush(stdout);
127 gets(buf);
128 if (buf[0] == 'Y' || buf[0] == 'y')
129 return(1);
130 if (buf[0] == 'N' || buf[0] == 'n')
131 return(0);
132 if (buf[0] == 'Q' || buf[0] == 'q') {
133 if (prompt("Are you sure you want to quit")) {
134 if (prompt("Save database changes")) {
135## end transaction
afda48e8 136 cleanup();
d2543f8c 137 exit(0);
138 } else {
afda48e8 139## abort
140## replace values (value = dcmenable)
141## where values.name = "dcm_enable"
142## exit
143 exit(1);
d2543f8c 144 }
145 }
146 }
147 }
148}
149
150
151/**
152 ** set_next_object_id - set next object id in values table
153 **
154 ** Inputs: object - object name in values table and in objects
155 ** table - name of table objects are found in
156 **
157 ** - called before an APPEND operation to set the next object id to
158 ** be used for the new record to the next free value
159 **
160 **/
161
162int set_next_object_id(object, table)
163 char *object;
164 char *table;
165##{
166## char *name, *tbl;
167## int rowcount, exists, value;
168
169 name = object;
170 tbl = table;
171## range of v is values
172## repeat retrieve (value = v.#value) where v.#name = @name
173## inquire_equel(rowcount = "rowcount")
174 if (rowcount != 1)
175 return(SMS_NO_ID);
176
177## retrieve (exists = any(tbl.name where tbl.name = value))
178## inquire_equel(rowcount = "rowcount")
179 if (rowcount != 1)
180 return(SMS_NO_ID);
181 while (exists) {
182 value++;
183 if (value > MAX_ID_VALUE)
184 value = MIN_ID_VALUE;
185## retrieve (exists = any(tbl.name where tbl.name = value))
186 }
187
afda48e8 188 printf("setting ID %s to %d\n", name, value);
d2543f8c 189## repeat replace v (#value = @value) where v.#name = @name
afda48e8 190 modified("values");
d2543f8c 191 return(SMS_SUCCESS);
192##}
193
194
195##generic_fix_id(table, idfield, txtfield, oldid, name)
196##char *table;
197##char *idfield;
198##char *txtfield;
199##int oldid;
200##char *name;
201##{
202## int rowcount, id;
203
204 set_next_object_id(table, idfield);
205## retrieve (id = values.value) where values.#name = idfield
206## replace table (idfield = values.value) where values.#name = idfield and
207## table.idfield = oldid and table.txtfield = name
208## inquire_equel(rowcount = "rowcount")
209 if (rowcount == 1)
210 printf("Fixed\n");
211 else
212 printf("Not fixed, rowcount = %d\n", rowcount);
afda48e8 213 modified(table);
d2543f8c 214 return(id);
215##}
This page took 0.075012 seconds and 5 git commands to generate.