aboutsummaryrefslogtreecommitdiff
path: root/engine.cpp
blob: 8b34f29ef357db0fc0e55edda3871281cfa29607 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "enginedata.h"
#include "query.h"
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <climits>

using namespace std;


map<string,Table> tables;


template <class... T>
void createTable(string name,T&&... args){
	//const Table tbl=Table(forward<T>(args)...);
	//tables.emplace(tbl.name,move(tbl));
	tables.emplace(piecewise_construct,
	               forward_as_tuple(name),
	               forward_as_tuple(name,forward<T>(args)...));
}


int main(int argc,char **argv){
	{
		ColHeader *header=new ColHeader[3];
		header[0]={RH_INT32,0};
		header[1]={RH_UINT32,0};
		header[2]={RH_BYTES,10};

		CreateQuery cqu;
		cqu.tablename="hoi";
		cqu.nc=3;
		cqu.setHeader(header);
		QueryResult res=cqu.execute(tables);

		cout<<"Create table \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl;
		for(const Row &r : res.rows)cout<<"- "<<r<<endl;
	}

	Table *hoitb=&tables.at("hoi");



	//Shitty. Works.
#define FINDQUERYEVERYTHING(PAR_tnm) \
	{ \
		FindQuery fqu; \
		fqu.tablename= PAR_tnm ; \
		QueryResult res=fqu.execute(tables); \
		cout<<"Find in \"" PAR_tnm "\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; \
		for(const Row &r : res.rows)cout<<"- "<<r<<endl; \
	}



	{
		Row row(3,hoitb);
		row.items[0].v.rh_int32=UINT_MAX;
		row.items[1].v.rh_uint32=UINT_MAX;
		row.items[2].v.rh_bytes=new unsigned char[10];
		memcpy((char*)row.items[2].v.rh_bytes,"hallo daar",10);

		InsertQuery iqu(move(row));
		iqu.tablename="hoi";

		QueryResult res=iqu.execute(tables);

		cout<<"Insert [UINT_MAX UINT_MAX \"hallo daar\"] into \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl;
		for(const Row &r : res.rows)cout<<"- "<<r<<endl;
	}

	{
		Row row(3,hoitb);
		row.items[0].v.rh_int32=42;
		row.items[1].v.rh_uint32=UINT_MAX;
		row.items[2].v.rh_bytes=new unsigned char[10];
		memcpy((char*)row.items[2].v.rh_bytes,"doei!\0\0\0\0",10);

		InsertQuery iqu(move(row));
		iqu.tablename="hoi";

		QueryResult res=iqu.execute(tables);

		cout<<"Insert [42 UINT_MAX \"doei\"] into \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl;
		for(const Row &r : res.rows)cout<<"- "<<r<<endl;
	}

	FINDQUERYEVERYTHING("hoi")

	{
		UpdateQuery uqu;
		uqu.tablename="hoi";

		RowItem ri;
		ri.v.rh_bytes=new unsigned char[10];
		memcpy(ri.v.rh_bytes,"hallo daar",10);
		uqu.where.push_back({2,{ri}});

		delete[] ri.v.rh_bytes;
		ri.v.rh_int32=20;
		uqu.updates.push_back({0,ri});

		QueryResult res=uqu.execute(tables);

		cout<<"Update in \"hoi\" where {2}=\"hallo daar\" {0}->20, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl;
		for(const Row &r : res.rows)cout<<"- "<<r<<endl;
	}

	FINDQUERYEVERYTHING("hoi")

	{
		UpdateQuery uqu;
		uqu.tablename="hoi";

		RowItem ri;
		ri.v.rh_uint32=UINT_MAX;
		uqu.where.push_back({1,{ri}});

		ri.v.rh_uint32=12345;
		uqu.updates.push_back({1,ri});

		QueryResult res=uqu.execute(tables);

		cout<<"Update in \"hoi\" where {1}=UINT_MAX {1}->12345, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl;
		for(const Row &r : res.rows)cout<<"- "<<r<<endl;
	}

	FINDQUERYEVERYTHING("hoi")

	{
		DeleteQuery dqu;
		dqu.tablename="hoi";
		RowItem ri; ri.v.rh_int32=-1;
		dqu.where.push_back({0,{ri}});

		QueryResult res=dqu.execute(tables);

		cout<<"Delete from \"hoi\" where {0}=-1, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl;
		for(const Row &r : res.rows)cout<<"- "<<r<<endl;
	}

	FINDQUERYEVERYTHING("hoi")

	{
		DropQuery drqu;
		drqu.tablename="hoi";

		QueryResult res=drqu.execute(tables);

		cout<<"Drop table \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl;
		for(const Row &r : res.rows)cout<<"- "<<r<<endl;
	}

	FINDQUERYEVERYTHING("hoi")

	return 0;
}