xale-db 1.0
minimal SQL engine, written in c++
Loading...
Searching...
No Matches
Statement.h
Go to the documentation of this file.
1#ifndef QUERY_STATEMENT_H
2#define QUERY_STATEMENT_H
3
4#include <string>
5#include <vector>
6#include <memory>
7#include <variant>
8
9namespace Xale::Query
10{
25
37
41 struct Expression;
42 struct BinaryExpression;
43
48 {
50 std::string value;
51 std::unique_ptr<BinaryExpression> binary;
52
54 explicit Expression(ExpressionType t, std::string val = "")
55 : type(t), value(std::move(val)) {}
56 };
57
62 {
63 std::unique_ptr<Expression> left;
64 std::string op;
65 std::unique_ptr<Expression> right;
66
67 BinaryExpression() = default;
68 BinaryExpression(std::unique_ptr<Expression> l, std::string operation, std::unique_ptr<Expression> r)
69 : left(std::move(l)), op(std::move(operation)), right(std::move(r)) {}
70 };
71
76 {
77 std::unique_ptr<Expression> condition;
78
79 WhereClause() = default;
80 explicit WhereClause(std::unique_ptr<Expression> cond)
81 : condition(std::move(cond)) {}
82 };
83
87 struct Statement
88 {
90
91 explicit Statement(StatementType t) : type(t) {}
92 virtual ~Statement() = default;
93 };
94
98 struct SelectStatement : public Statement
99 {
100 std::vector<Expression> columns;
101 std::string tableName;
102 std::unique_ptr<WhereClause> where;
103
105 };
106
111 {
112 std::string tableName;
113 std::vector<std::string> columns;
114 std::vector<Expression> values;
115
117 };
118
123 {
124 std::string tableName;
125 std::vector<std::pair<std::string, Expression>> assignments;
126 std::unique_ptr<WhereClause> where;
127
129 };
130
135 {
136 std::string tableName;
137 std::unique_ptr<WhereClause> where;
138
140 };
141
146 {
147 std::string name;
148 std::string type;
150
152 ColumnDefinitionStmt(std::string n, std::string t, bool pk = false)
153 : name(std::move(n)), type(std::move(t)), isPrimaryKey(pk) {}
154 };
155
160 {
161 std::string tableName;
162 std::vector<ColumnDefinitionStmt> columns;
163
165 };
166
170 struct DropStatement : public Statement
171 {
172 std::string tableName;
173
175 };
176
177
185}
186
187#endif // QUERY_STATEMENT_H
Definition BasicParser.h:16
StatementType
Types of SQL statements.
Definition Statement.h:15
@ Update
Definition Statement.h:18
@ Drop
Definition Statement.h:21
@ List
Definition Statement.h:22
@ Create
Definition Statement.h:20
@ Unknown
Definition Statement.h:23
@ Insert
Definition Statement.h:17
@ Select
Definition Statement.h:16
@ Delete
Definition Statement.h:19
ExpressionType
Types of expression nodes.
Definition Statement.h:30
@ Identifier
Definition Statement.h:31
@ StringLiteral
Definition Statement.h:32
@ BinaryOp
Definition Statement.h:34
@ NumericLiteral
Definition Statement.h:33
@ Wildcard
Definition Statement.h:35
std::unique_ptr< Expression > right
Definition Statement.h:65
BinaryExpression(std::unique_ptr< Expression > l, std::string operation, std::unique_ptr< Expression > r)
Definition Statement.h:68
std::string op
Definition Statement.h:64
std::unique_ptr< Expression > left
Definition Statement.h:63
std::string name
Definition Statement.h:147
bool isPrimaryKey
Definition Statement.h:149
std::string type
Definition Statement.h:148
ColumnDefinitionStmt()
Definition Statement.h:151
ColumnDefinitionStmt(std::string n, std::string t, bool pk=false)
Definition Statement.h:152
std::vector< ColumnDefinitionStmt > columns
Definition Statement.h:162
std::string tableName
Definition Statement.h:161
CreateStatement()
Definition Statement.h:164
std::unique_ptr< WhereClause > where
Definition Statement.h:137
DeleteStatement()
Definition Statement.h:139
std::string tableName
Definition Statement.h:136
DropStatement()
Definition Statement.h:174
std::string tableName
Definition Statement.h:172
Expression()
Definition Statement.h:53
Expression(ExpressionType t, std::string val="")
Definition Statement.h:54
std::unique_ptr< BinaryExpression > binary
Definition Statement.h:51
ExpressionType type
Definition Statement.h:49
std::string value
Definition Statement.h:50
InsertStatement()
Definition Statement.h:116
std::vector< std::string > columns
Definition Statement.h:113
std::vector< Expression > values
Definition Statement.h:114
std::string tableName
Definition Statement.h:112
ListStatement()
Definition Statement.h:183
std::vector< Expression > columns
Definition Statement.h:100
SelectStatement()
Definition Statement.h:104
std::unique_ptr< WhereClause > where
Definition Statement.h:102
std::string tableName
Definition Statement.h:101
Statement(StatementType t)
Definition Statement.h:91
StatementType type
Definition Statement.h:89
virtual ~Statement()=default
std::string tableName
Definition Statement.h:124
std::unique_ptr< WhereClause > where
Definition Statement.h:126
std::vector< std::pair< std::string, Expression > > assignments
Definition Statement.h:125
UpdateStatement()
Definition Statement.h:128
WhereClause(std::unique_ptr< Expression > cond)
Definition Statement.h:80
std::unique_ptr< Expression > condition
Definition Statement.h:77