-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
150 lines (138 loc) · 3.7 KB
/
test.cpp
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
//
// Created by 93773 on 2019/5/14.
//
#include "dbCore.h"
/*
int main() {
Core * core = new Core();
cout << "start" << endl;
auto rs = core->getTables();
for (auto r : rs) {
cout << r.tableName << endl;
}
auto cols = core->getColumn(_S("database"));
for (auto c : cols) {
cout << c.field_name << endl;
}
// select test
select_node snode;
table_field_node tfnode;
table_node tnode;
tnode.tableName = _S("database");
tfnode.field_name = _S("*");
snode.table = &tnode;
snode.field = &tfnode;
auto selectrs = core->select_mult(&snode);
for (auto s : selectrs.second) {
for (auto ss : s) {
cout << ss.chval << '\t';
}
cout << endl;
}
table_node tnode2;
tnode2.tableName = _S("database");
tnode.next = &tnode2;
table_field_node tfnode2;
tfnode2.field_name = _S("datfile");
tfnode.next = &tfnode2;
snode.table = &tnode;
snode.field = &tfnode;
selectrs = core->select_mult(&snode);
for (auto s : selectrs.second) {
for (auto ss : s) {
cout << ss.chval << '\t';
}
cout << endl;
}
core->createDatabase("test3");
core->useDatabase("test3");
table_field_node tfn1;
tfn1.field_name = _S("SNAME");
tfn1.len = 50;
table_field_node tfn2;
tfn2.field_name = _S("SAGE");
tfn2.len = 0;
table_field_node tfn3;
tfn3.field_name = _S("SEX");
tfn3.len = 0;
tfn1.next = &tfn2;
tfn2.next = &tfn3;
core->createTable("students", &tfn1);
core->createTable("students22", &tfn1);
insert_node insetNode;
values_node val1;
val1.type = values_node::STRING;
val1.chval = _S("SincereXIA");
values_node val2;
val2.type = values_node::INT;
val2.intval = 22;
values_node val3;
val3.type = values_node::INT;
val3.intval = 1;
val1.next = &val2;
val2.next = NULL;
table_node tbn;
tbn.tableName = _S("students");
insetNode.table = &tbn;
insetNode.values = &val1;
char temp[20];
val1.chval = temp;
for (int i = 0; i < 100; i++) {
_itoa_s(i, temp, 10);
core->insert(&insetNode);
}
tbn.tableName = _S("students22");
core->insert(&insetNode);
// select test
tnode.tableName = _S("students");
tfnode.field_name = _S("*");
tfnode.next = NULL;
tnode.next = NULL;
snode.table = &tnode;
snode.field = &tfnode;
selectrs = core->select_mult(&snode);
for (auto s : selectrs.second) {
for (auto ss : s) {
if (ss.type == values_node::INT)
cout << ss.intval << '\t';
else
cout << ss.chval << '\t';
}
cout << endl;
}
tnode.tableName = _S("students22");
selectrs = core->select_mult(&snode);
for (auto s : selectrs.second) {
for (auto ss : s) {
if (ss.type == values_node::INT)
cout << ss.intval << '\t';
else
cout << ss.chval << '\t';
}
cout << endl;
}
cout << "cond select test" << endl;
condexp_node cond;
cond.op = cond.EQ;
condexp_node condleft;
condleft.chval = _S("SNAME");
condexp_node condright;
condright.chval = _S("66");
condright.type = condright.STRING;
cond.left = &condleft;
cond.right = &condright;
snode.table->tableName = _S("students");
snode.cons = &cond;
selectrs = core->select_mult(&snode);
for (auto s : selectrs.second) {
for (auto ss : s) {
if (ss.type == values_node::INT)
cout << ss.intval << '\t';
else
cout << ss.chval << '\t';
}
cout << endl;
}
system("pause");
}
*/