-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqlEngine.h
72 lines (63 loc) · 2.24 KB
/
SqlEngine.h
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
/*
* Copyright (C) 2008 by The Regents of the University of California
* Redistribution of this file is permitted under the terms of the GNU
* Public License (GPL).
*
* @author Junghoo "John" Cho <cho AT cs.ucla.edu>
* @date 3/24/2008
*/
#ifndef SQLENGINE_H
#define SQLENGINE_H
#include <vector>
#include "Bruinbase.h"
#include "RecordFile.h"
/**
* data structure to represent a condition in the WHERE clause
*/
struct SelCond {
int attr; // attribute: 1 - key column, 2 - value column
enum Comparator { EQ, NE, LT, GT, LE, GE } comp;
char* value; // the value to compare
};
/**
* the class that takes, parses, and executes the user commands.
*/
class SqlEngine {
public:
/**
* takes the user commands from commandline and executes them.
* when user issues SELECT or LOAD from commandline, this function
* calls SqlEngine::select() or SqlEngine::load() functions.
* @param commandline[IN] the input stream to get user commands
* @return error code. 0 if no error
*/
static RC run(FILE* commandline);
/**
* executes a SELECT statement.
* all conditions in conds must be ANDed together.
* the result of the SELECT is printed on screen.
* @param attr[IN] attribute in the SELECT clause
* (1: key, 2: value, 3: *, 4: count(*))
* @param table[IN] the table name in the FROM clause
* @param conds[IN] list of conditions in the WHERE clause
* @return error code. 0 if no error
*/
static RC select(int attr, const std::string& table, const std::vector<SelCond>& conds);
/**
* load a table from a load file.
* @param table[IN] the table name in the LOAD command
* @param loadfile[IN] the file name of the load file
* @param index[IN] true if "WITH INDEX" option was specified
* @return error code. 0 if no error
*/
static RC load(const std::string& table, const std::string& loadfile, bool index);
/**
* parse a line from the load file into the (key, value) pair.
* @param line[IN] a line from a load file
* @param key[OUT] the key field of the tuple in the line
* @param value[OUT] the value field of the tuple in the line
* @return error code. 0 if no error
*/
static RC parseLoadLine(const std::string& line, int& key, std::string& value);
};
#endif /* SQLENGINE_H */