-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.c
62 lines (48 loc) · 1.48 KB
/
select.c
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
// select.c ... run queries
// part of signature indexed files
// Ask a query on a named relation
// Usage: ./select [-v] RelName v1,v2,v3,v4,... Sigs
// where any of the vi's can be "?" (unknown)
#include "defs.h"
#include "query.h"
#include "tuple.h"
#include "reln.h"
#define USAGE "./select [-v] RelName v1,v2,v3,v4,... [t|p|b]"
// Main ... process args, run query
int main(int argc, char **argv)
{
Reln r; // open relation info
Query q; // query iteration information
int verbose; // show extra info on query progress
char *rname; // name of table/file
char *qstr; // query string
char type = '?'; // type of signatures to use
char err[MAXERRMSG]; // buffer for error messages
// process command-line args
if (argc < 3) fatal(USAGE, "");
if (strcmp(argv[1], "-v") == 0) {
verbose = 1; rname = argv[2]; qstr = argv[3];
if (argc > 4) type = argv[4][0];
}
else {
verbose = 0; rname = argv[1]; qstr = argv[2];
if (argc > 3) type = argv[3][0];
}
if (verbose) { /* keeps compiler quiet */ }
// initialise relation and scan descriptors
if ((r = openRelation(rname)) == NULL) {
sprintf(err, "Can't open relation: %s",rname);
fatal("", err);
}
if ((q = startQuery(r, qstr, type)) == NULL) {
sprintf(err, "Invalid query: %s",qstr);
fatal("",err);
}
// scan selected pages to find matching tuples
scanAndDisplayMatchingTuples(q);
printf("Query Stats:\n"); queryStats(q);
// clean up
closeQuery(q);
closeRelation(r);
return 0;
}