-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
228 lines (185 loc) · 5.78 KB
/
main.cpp
File metadata and controls
228 lines (185 loc) · 5.78 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include "ql_Manager.h"
using namespace std;
#define DEBUG_SQL
#include <iostream>
#include "cparse\shunting-yard.h"
#ifdef DEBUG_SQL
int main() {
ql_Manager qm;
string sql = "";
while (true) {
string tmp;
getline(cin, tmp);
sql += " " + tmp;
int ret = sql.find(';');
if (ret != string::npos) {
qm.run(sql.substr(0, ret + 1));
sql = "";
}
}
}
#endif // DEBUG_SQL
/*
select * from test;
/*
select ID, Firstname from
test where date=='2016-10-10';
select ID, Firstname from
test where date=='2016-10-11';
select ID, Firstname from
(select ID, Firstname from
test where date=='2016-10-10') where id==1;
*/
/*
select count(id), married from test group by married;
select max(age), married from test group by married;
select max(age) from test;
*/
/*
select max(age), date from test group by date order by date;
select max(age), date from test group by date order by date desc;
select max(age), date from test group by date having max(age)>10;
select max(age), date from test group by date having max(age)>10 order by age;
*/
/*
create table stu (
id int,
name varchar(20),
sex char,
weight double,
birtyday date
);
insert into stu values (1, 'zhangsan', 'M', 90.0, '1996-10-10');
insert into stu values (2, 'lisi', 'M', 100.1, '1996-10-10');
insert into stu values (3, 'tom', 'M', 101.0, '1996-10-11');
insert into stu values (4, 'xiaohong', 'F', 80.3, '1996-10-11');
insert into stu values (5, 'xiaoming', 'M', 92.5, '1996-10-12');
insert into stu values (6, 'alice', 'F', 96.5, '1996-10-12');
select * from stu;
select id, name from stu where id>=2&&id<=5;
select id from (select id, name from stu where id>=2&&id<=5);
select max(weight), sex from stu group by sex;
select max(weight), sex from stu group by sex having max(weight)>=100;
select ave(weight), birtyday from stu group by birtyday;
select ave(weight), birtyday from stu group by birtyday order by weight;
*/
#ifdef DEBUG_DBF
int main(int argc, char *argv[])
{
/*
TokenMap vars;
calculator calu;
calu.compile("(d != 'abcdef')");
vars["a"] = 2.33;
vars["b"] = 2.34;
vars["c"] = "1234";
vars["d"] = "4567";
std::cout << calu.eval(vars).str() << std::endl;
packToken pt;
*/
if (false)
{
string sFileReadTest = "TestCreate.dbf";
//sFileReadTest = argv[1]; // do a read test on the given file
DBF mydbf;
std::cerr << "Read Test of " << sFileReadTest << std::endl;
int nRet = mydbf.open(sFileReadTest);
if (nRet)
{
std::cerr << "Unable to Open File " << sFileReadTest << std::endl;
}
else
{
int nRecs = mydbf.GetNumRecords();
int nFields = mydbf.GetNumFields();
std::cout << "Open() found " << nRecs << " records, and " << nFields << " fields." << std::endl;
mydbf.dumpAsCSV();
std::cout << "Done Read Test " << std::endl;
mydbf.close();
}
}
else
{
// no param, means to run a test to create, read and delete a record in the dbf
// now create a db
std::cout << "Create file TestCreate.dbf from code" << std::endl;
DBF newdbf;
int nRet = newdbf.create("TestCreate.dbf", 6);
if (nRet == 0)
{
// create the 5 fields
fieldDefinition fd = TypeInteger();
strncpy(fd.cFieldName, "ID", 10);
newdbf.assignField(fd, 0);
fd = TypeString();
strncpy(fd.cFieldName, "FirstName", 10);
fd.uLength = 20;
newdbf.assignField(fd, 1);
fd = TypeDouble();
strncpy(fd.cFieldName, "Weight", 10);
newdbf.assignField(fd, 2);
fd = TypeInteger();
strncpy(fd.cFieldName, "Age", 10);
newdbf.assignField(fd, 3);
fd = TypeBoolean();
strncpy(fd.cFieldName, "Married", 10);
newdbf.assignField(fd, 4);
fd = TypeDate();
strncpy(fd.cFieldName, "Date", 10);
newdbf.assignField(fd, 5);
// now create some records to test it!
string s1[6] = { "1" ,"Ric G","210.123456789123456","43","T", "2016-10-10" };
newdbf.appendRecord(&s1[0], 6);
string s2[6] = { "1000" ,"Paul F","196.2","33","T", "2016-10-10" };
newdbf.appendRecord(s2, 6);
string s3[6] = { "20000" ,"Dean K","186.1","23","F", "2016-10-11" };
newdbf.appendRecord(s3, 6);
string s4[6] = { "300000" ,"Gary\" Q","175.123456789","13","F", "2016-10-11" };
newdbf.appendRecord(s4, 6);
string s5[6] = { "2000000" ,"Dan'e \"D, with comma and over sized field that will be truncated","65.2","6","F", "2016-10-12" };
newdbf.appendRecord(s5, 6);
// now add a huge pile of random records to see if it crashes
//int nID = 2000001;
//for( int i=0; i < 1000; i++)
//{
// stringstream ssName;
// ssName << "FirstName" << nID;
// float fWeight = (float) nID / 40000.0;
// int nAge = i % 120;
// stringstream ssID;
// ssID << nID;
// stringstream ssWeight;
// ssWeight << fWeight;
// stringstream ssAge;
// ssAge << nAge;
// string sMarried = "F";
// if( nID % 2 == 0 )
// sMarried = "T";
// string sRec[5]={ssID.str(),ssName.str(),ssWeight.str(),ssAge.str(),sMarried};
// newdbf.appendRecord(sRec,5);
// nID++;
//}
newdbf.close();
std::cout << "Done Creating the DBF" << std::endl;
//std::cout << "Open the DBF for reading and writing" << std::endl;
//// now read the dbf back to test that it worked!
//DBF readTest;
//readTest.open("TestCreate.dbf",true);
//int nRecs = readTest.GetNumRecords();
//int nFields = readTest.GetNumFields();
//std::cout << "Open() found " << nRecs << " records, and " << nFields << " fields." << std::endl;
//readTest.dumpAsCSV();
//std::cout << "Done Reading a freshly created DBF! " << std::endl;
//std::cout << "Test Delete Record 1 in DBF! " << std::endl;
//std::cout << "Test Delete Record 3 in DBF! " << std::endl;
//readTest.markAsDeleted(1);
//readTest.markAsDeleted(3);
//readTest.dumpAsCSV();
//std::cout << "Done Test Delete Record DBF! " << std::endl;
//readTest.close();
}
}
system("pause");
return 0;
}
#endif // DEBUG