-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainbibliography.sqc
More file actions
418 lines (370 loc) · 9.42 KB
/
mainbibliography.sqc
File metadata and controls
418 lines (370 loc) · 9.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#include <stdio.h>
#include "util.h"
#include <string.h>
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
char sample[6] = "cs348";
char author[7] = "author";
char authorurl[10] = "authorurl";
char book[5] = "book";
char journal[8] = "journal";
char proceedings[12] = "proceedings";
char article[8] = "article";
char name[23];
char givenName[23];
char url[43];
char pubid[11];
char title[71];
char publisher[51];
char appearsin[11];
int aid;
int aorder;
int year;
int volume;
int number;
int startpage;
int endpage;
int occurs;
int temp;
EXEC SQL END DECLARE SECTION;
void getAuthors() {
EXEC SQL DECLARE CUR1 CURSOR FOR
SELECT (A.name)
FROM author A, wrote W
WHERE A.aid = :aid
AND W.pubid = :pubid;
EXEC SQL OPEN CUR1;
EXEC SQL FETCH CUR1 INTO :name;
if (SQLCODE != 100) {
printf("Authors: %s", name);
}
for(;;) {
EXEC SQL FETCH CUR1 INTO :name;
if (SQLCODE == 100) {
break;
} else if (SQLCODE < 0) {
break;
}
printf(", %s", name);
}
printf("\n");
EXEC SQL CLOSE CUR1;
}
void updateAuthor(char* inputStr) {
char* aidStr;
char* authName;
aidStr = strtok(NULL, "#");
aid = atoi(aidStr);
authName = strtok(NULL, ")");
strcpy(name, authName);
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM author A
WHERE A.aid = :aid;
if (occurs == 0) {
EXEC SQL
INSERT INTO author (aid, name)
VALUES (:aid, :name);
} else {
EXEC SQL
UPDATE author
SET name = :name
WHERE aid = :aid;
}
//// printf("aid: %d, \n", aid);
//// printf("Authors: %s, \n", name);
}
void updateAuthorurl(char* inputStr) {
char* aidStr;
char* authUrl;
aidStr = strtok(NULL, "#");
aid = atoi(aidStr);
authUrl = strtok(NULL, ")");
strcpy(url, authUrl);
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM author A
WHERE A.aid = :aid;
if(occurs == 0) {
EXEC SQL
INSERT INTO author (url)
VALUES (:url);
}else {
EXEC SQL
UPDATE author
SET url = :url
WHERE aid = :aid;
}
}
void updateBook(char* inputStr) {
char* pubidStr;
char* pubTitle;
pubidStr = strtok(NULL, "#");
pubTitle = strtok(NULL, "#");
strcpy(pubid, pubidStr);
strcpy(title, pubTitle);
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM publication P
WHERE P.pubid = :pubid;
if (occurs == 0) {
EXEC SQL
INSERT INTO publication (pubid, title)
VALUES (:pubid, :title);
} else {
EXEC SQL
UPDATE publication
SET title = :title
WHERE pubid = :pubid;
}
printf("Pubid: %s\n", pubid);
printf("Type: book\n");
printf("Title: %s\n", title);
char* newAuthors;
char* aidStr1;
newAuthors = strtok(NULL, "#");
char* publisherStr;
char* yearStr;
publisherStr = strtok(NULL, "#");
yearStr = strtok(NULL, ")");
strcpy(publisher, publisherStr);
year = atoi(yearStr);
EXEC SQL
DELETE FROM wrote
WHERE pubid = :pubid;
aidStr1 = strtok(newAuthors, ";");
printf("Authors: ");
for(temp = 1; aidStr1 != 0; temp++) {
aid = atoi(aidStr1);
aorder = temp;
EXEC SQL
INSERT INTO wrote (aid, pubid, aorder)
VALUES (:aid, :pubid, :aorder);
aidStr1 = strtok(NULL, ";");
///// getAuthors();
printf("%d ", aid);
}
printf("\n");
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM book B
WHERE B.pubid = :pubid;
if (occurs == 0) {
EXEC SQL
INSERT INTO book (pubid, publisher, year)
VALUES (:pubid, :publisher, :year);
} else {
EXEC SQL
UPDATE book
SET publisher = :publisher, year = :year
WHERE pubid = :pubid;
}
printf("Publisher: %s\n", publisher);
printf("Year: %d\n\n", year);
}
void updateJournal(char* inputStr) {
char* pubidStr;
char* pubTitle;
pubidStr = strtok(NULL, "#");;
pubTitle = strtok(NULL, "#");
strcpy(pubid, pubidStr);
strcpy(title, pubTitle);
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM publication P
WHERE P.pubid = :pubid;
if (occurs == 0) {
EXEC SQL
INSERT INTO publication (pubid, title)
VALUES (:pubid, :title);
} else {
EXEC SQL
UPDATE publication
SET title = :title
WHERE pubid = :pubid;
}
printf("Pubid: %s\n", pubid);
printf("Type: journal\n");
printf("Title: %s\n", title);
char* volumeStr;
char* numberStr;
char* yearStr;
volumeStr = strtok(NULL, "#");
numberStr = strtok(NULL, "#");
yearStr = strtok(NULL, ")");
volume = atoi(volumeStr);
number = atoi(numberStr);
year = atoi(yearStr);
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM journal J
WHERE J.pubid = :pubid;
if (occurs == 0) {
EXEC SQL
INSERT INTO journal (pubid, volume, number, year)
VALUES (:pubid, :volume, :number, :year);
} else {
EXEC SQL
UPDATE journal
SET volume = :volume, number = :number, year = :year
WHERE pubid = :pubid;
}
printf("Volume: %d\n", volume);
printf("Number: %d\n", number);
printf("Year: %d\n\n", year);
}
void updateProceedings(char* inputStr) {
char* pubidStr;
char* pubTitle;
pubidStr = strtok(NULL, "#");
pubTitle = strtok(NULL, "#");
strcpy(pubid, pubidStr);
strcpy(title, pubTitle);
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM publication P
WHERE P.pubid = :pubid;
if (occurs == 0) {
EXEC SQL
INSERT INTO publication (pubid, title)
VALUES (:pubid, :title);
} else {
EXEC SQL
UPDATE publication
SET title = :title
WHERE pubid = :pubid;
}
printf("Pubid: %s\n", pubid);
printf("Type: proceedings\n");
printf("Title: %s\n", title);
char* yearStr;
yearStr = strtok(NULL, ")");
year = atoi(yearStr);
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM proceedings P
WHERE P.pubid = :pubid;
if(occurs == 0) {
EXEC SQL
INSERT INTO proceedings (pubid, year)
VALUES (:pubid, :year);
} else {
EXEC SQL
UPDATE proceedings
SET year = :year
WHERE pubid = :pubid;
}
printf("Year: %d\n\n", year);
}
void updateArticle(char* inputStr) {
char* pubidStr;
char* pubTitle;
pubidStr = strtok(NULL, "#");
pubTitle = strtok(NULL, "#");
strcpy(pubid, pubidStr);
strcpy(title, pubTitle);
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM publication P
WHERE P.pubid = :pubid;
if (occurs == 0) {
EXEC SQL
INSERT INTO publication (pubid, title)
VALUES (:pubid, :title);
} else {
EXEC SQL
UPDATE publication
SET title = :title
WHERE pubid = :pubid;
}
printf("Pubid: %s\n", pubid);
printf("Type: article\n");
printf("Title: %s\n", title);
char* newAuthors;
char* aidStr1;
newAuthors = strtok(NULL, "#");
char* strappearsin;
char* startpageStr;
char* endpageStr;
strappearsin = strtok(NULL, "#");
strcpy(appearsin, strappearsin);
startpageStr = strtok(NULL, "#");
startpage = atoi(startpageStr);
endpageStr = strtok(NULL, ")");
endpage = atoi(endpageStr);
EXEC SQL
DELETE FROM wrote
WHERE pubid = :pubid;
aidStr1 = strtok(newAuthors, ";");
printf("Authors: ");
for(temp = 1; aidStr1 != 0; temp++) {
aid = atoi(aidStr1);
aorder = temp;
EXEC SQL
INSERT INTO wrote (aid, pubid, aorder)
VALUES (:aid, :pubid, :aorder);
aidStr1 = strtok(NULL, ";");
//// getAuthors()
printf(" %d ", aid);
}
printf("\n");
EXEC SQL
SELECT COUNT(*) INTO :occurs
FROM article A
WHERE A.pubid = :pubid;
if(occurs == 0) {
EXEC SQL
INSERT INTO article (pubid, appearsin, startpage, endpage)
VALUES (:pubid, :appearsin, :startpage, :endpage);
} else {
EXEC SQL
UPDATE article
SET appearsin = :appearsin, startpage = :startpage, endpage = :endpage
WHERE pubid = :pubid;
}
printf("In: %s\n", appearsin);
printf("Pages: %d--%d\n\n", startpage, endpage);
}
int main(int argc, char *argv[]) {
char * getpass();
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL CONNECT TO :sample;
char* inputStr = NULL;
char *inputType = NULL;
size_t len = 0;
if (stdin == NULL) {
return(-1);
}
for(;;) {
getline(&inputStr, &len, stdin);
if(feof(stdin)) {
break;
}
inputType = strtok(inputStr, "(");
if (strcmp(inputType, author) == 0) {
updateAuthor(inputStr);
}
if (strcmp(inputType, authorurl) == 0) {
updateAuthorurl(inputStr);
}
if (strcmp(inputType, book) == 0) {
updateBook(inputStr);
}
if (strcmp(inputType, journal) == 0) {
updateJournal(inputStr);
}
if(strcmp(inputType, proceedings) == 0) {
updateProceedings(inputStr);
}
if (strcmp(inputType, article) == 0) {
updateArticle(inputStr);
}
}
EXEC SQL COMMIT WORK;
EXEC SQL CONNECT RESET;
return(0);
error:
printf("update failed, sqlcode = %d\n",SQLCODE );
EXEC SQL ROLLBACK WORK;
return(-1);
}