aboutsummaryrefslogtreecommitdiff
path: root/query.h
blob: 264463dc415154cc7b47f837eb5a8ed7051a7cca (plain)
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
#pragma once

#include "enginedata.h"
#include <vector>
#include <string>
#include <map>

using namespace std;

struct WhereClause{
	int col;
	vector<RowItem> values;

	WhereClause(void);
	WhereClause(const int _c,const vector<RowItem> &_v);
};

struct UpdateClause{
	int col;
	RowItem value;

	UpdateClause(void);
	UpdateClause(const int _c,const RowItem &_v);
};



struct QueryResult{
	int res;
	vector<Row> rows;
	string msg; //empty message indicates success

	QueryResult(void);
	QueryResult(int);
	QueryResult(int,const vector<Row>&);
	QueryResult(int,const vector<Row>&,const string&);
	QueryResult(int,const string&);
};


struct Query{
	string tablename;

	virtual QueryResult execute(map<string,Table>&);
	virtual ~Query(void);
};

struct CreateQuery : public Query{
	int nc;
	ColHeader *header;

	CreateQuery(void);
	void setHeader(const ColHeader *hd);
	QueryResult execute(map<string,Table> &tables);
};

struct FindQuery : public Query{
	unsigned int limit; //-1=unlimited
	vector<WhereClause> where;

	FindQuery(void);
	pair<vector<map<string,Row>::const_iterator>,string> executeIterators(map<string,Table> &tables);
	pair<vector<map<string,Row>::const_iterator>,string> executeIterators(const Table &table);
	QueryResult execute(map<string,Table> &tables);
};

struct InsertQuery : public Query{
	Row row;

	InsertQuery(const Row &_r);
	InsertQuery(Row &&_r);
	QueryResult execute(map<string,Table> &tables);
};

struct UpdateQuery : public Query{
	vector<WhereClause> where;
	vector<UpdateClause> updates;

	UpdateQuery(void);
	QueryResult execute(map<string,Table> &tables);
};

struct DeleteQuery : public Query{
	vector<WhereClause> where;

	DeleteQuery(void);
	QueryResult execute(map<string,Table> &tables);
};

struct DropQuery : public Query{
	DropQuery(void);
	QueryResult execute(map<string,Table> &tables);
};