-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
56 lines (47 loc) · 1.18 KB
/
parser.h
File metadata and controls
56 lines (47 loc) · 1.18 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
#ifndef PARSER_H
#define PARSER_H
#include <string>
#include <vector>
#include <memory>
#include "database.h"
namespace databos {
enum class CommandType {
CREATE_TABLE,
DROP_TABLE,
INSERT,
SELECT,
UPDATE,
DELETE,
SHOW_TABLES,
DESCRIBE,
UNKNOWN,
EXIT,
HELP
};
struct ParsedCommand {
CommandType type;
std::string tableName;
std::vector<Column> columns;
std::map<std::string, ColumnValue> values;
std::vector<std::string> selectColumns;
std::string whereColumn;
std::string whereOp;
ColumnValue whereValue;
std::string updateColumn;
ColumnValue updateValue;
bool hasWhere;
std::string errorMessage;
ParsedCommand() : type(CommandType::UNKNOWN), hasWhere(false) {}
};
class Parser {
public:
static ParsedCommand parse(const std::string& query);
private:
static std::vector<std::string> tokenize(const std::string& query);
static std::string trim(const std::string& str);
static std::string toUpper(const std::string& str);
static DataType stringToDataType(const std::string& typeStr);
static ColumnValue parseValue(const std::string& value, DataType type);
};
}
#endif