-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathql_create.cpp
More file actions
76 lines (66 loc) · 1.56 KB
/
ql_create.cpp
File metadata and controls
76 lines (66 loc) · 1.56 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
#include "ql_create.h"
ql_create::ql_create(string q) : q_line(q)
{
}
ql_create::~ql_create()
{
}
void ql_create::run()
{
q_line = Praser::toLowerString(q_line);
fileName = Praser::split(q_line, ' ')[2];
int p1 = -1, p2 = -1;
for (int i = 0; i < q_line.length(); ++i) {
if (q_line[i] == '(') {
p1 = i;
break;
}
}
q_line = q_line.substr(p1 + 1, q_line.length());
q_line.pop_back();
std::vector<string> fields = Praser::split(q_line, ',');
for (string & tmp : fields) {
tmp = Praser::trim(tmp);
}
DBF newdbf;
int cnt = 0;
newdbf.create(fileName + ".dbf", fields.size());
for (string field : fields) {
string name = Praser::split(field, ' ')[0];
string type = Praser::split(field, ' ')[1];
fieldDefinition fd;
if (Praser::findFirstOf(type, type_int) == 0) {
fd = TypeInteger();
}
else if (Praser::findFirstOf(type, type_double) == 0) {
fd = TypeDouble();
}
else if (Praser::findFirstOf(type, type_date) == 0) {
fd = TypeDate();
}
else if (Praser::findFirstOf(type, type_char) == 0) {
fd = TypeString();
fd.uLength = 1;
}
else if (Praser::findFirstOf(type, type_bool) == 0) {
fd = TypeString();
fd.uLength = 1;
}
else if (Praser::findFirstOf(type, type_varchar) == 0) {
fd = TypeString();
for (int i = 0; i < type.length(); ++i) {
if (type[i] == '(') {
p1 = i;
}
if (type[i] == ')') {
p2 = i;
}
}
std::stringstream ss(type.substr(p1 + 1, p2 - p1 - 1));
ss >> fd.uLength;
}
strncpy(fd.cFieldName, name.c_str(), 10);
newdbf.assignField(fd, cnt++);
}
newdbf.close();
}