-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathql_insert.cpp
More file actions
84 lines (68 loc) · 1.42 KB
/
ql_insert.cpp
File metadata and controls
84 lines (68 loc) · 1.42 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
#include "ql_insert.h"
ql_insert::ql_insert(string q) : q_line(q)
{
}
ql_insert::~ql_insert()
{
}
void ql_insert::run()
{
q_line = Praser::trim(q_line);
q_line = Praser::toLowerString(q_line);
std::vector<string> v_fields = Praser::split(q_line, { ' ', ',' });
fileName = v_fields[2] + ".dbf";
DBF dbfFile;
dbfFile.open(fileName, true);
std::vector<string> vRec;
vRec.resize(dbfFile.GetNumFields());
std::vector<string> fields;
std::vector<string> v_values;
for (string & t : v_fields) {
if (t[0] == '(') {
t = t.substr(1, t.length() - 1);
}
if (t.back() == ')') {
t.pop_back();
}
if (t[0] == '\'') {
t = t.substr(1, t.length() - 1);
}
if (t.back() == '\'') {
t.pop_back();
}
}
bool b_into = false;
bool b_values = false;
for (string & t : v_fields) {
t = Praser::trim(t);
if (t == fileName) {
b_into = true;
continue;
}
if (t == values) {
b_values = true;
continue;
}
if (b_into) {
fields.push_back(t);
}
if (b_values) {
v_values.push_back(t);
}
}
if (fields.size() == 0) {
for (int i = 0; i < v_values.size(); ++i) {
vRec[i] = v_values[i];
}
}
else {
if (fields.size() != v_values.size()) {
std::cerr << "[ERROR] insert ×ֶδíÎó!" << std::endl;
}
for (int i = 0; i < v_fields.size(); ++i) {
vRec[dbfFile.getFieldIndex(v_fields[i])] = v_values[i];
}
}
dbfFile.appendRecord(&vRec[0], dbfFile.GetNumFields());
dbfFile.close();
}