aboutsummaryrefslogtreecommitdiff
path: root/engine.cpp
blob: 568245b538103fe2065423a0e6fadd959e169cfe (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
#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");

	{
		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 [-1 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;
	}

	{
		FindQuery fqu;
		fqu.tablename="hoi";
		RowItem ri; ri.v.rh_uint32=UINT_MAX;
		fqu.where.emplace_back(1,ri);

		QueryResult res=fqu.execute(tables);

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

	{
		DeleteQuery dqu;
		dqu.tablename="hoi";
		RowItem ri; ri.v.rh_int32=-1;
		dqu.where.emplace_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;
	}

	{
		FindQuery fqu;
		fqu.tablename="hoi";
		RowItem ri; ri.v.rh_uint32=UINT_MAX;
		fqu.where.emplace_back(1,ri);

		QueryResult res=fqu.execute(tables);

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

	return 0;
}