hikyuu 2.1.0__cp39-none-win_amd64.whl → 2.1.1__cp39-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hikyuu/cpp/boost_date_time-mt.dll +0 -0
- hikyuu/cpp/boost_serialization-mt.dll +0 -0
- hikyuu/cpp/boost_wserialization-mt.dll +0 -0
- hikyuu/cpp/core39.pyd +0 -0
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/extend.py +3 -1
- hikyuu/gui/HikyuuTDX.py +11 -6
- hikyuu/include/hikyuu/DataType.h +2 -1
- hikyuu/include/hikyuu/KRecord.h +1 -1
- hikyuu/include/hikyuu/StockManager.h +3 -0
- hikyuu/include/hikyuu/analysis/combinate.h +1 -1
- hikyuu/include/hikyuu/config.h +0 -12
- hikyuu/include/hikyuu/strategy/AccountTradeManager.h +3 -1
- hikyuu/include/hikyuu/utilities/FilterNode.h +267 -0
- hikyuu/include/hikyuu/utilities/LRUCache11.h +230 -0
- hikyuu/include/hikyuu/{Log.h → utilities/Log.h} +91 -113
- hikyuu/include/hikyuu/utilities/Null.h +1 -0
- hikyuu/include/hikyuu/utilities/Parameter.h +2 -1
- hikyuu/include/hikyuu/utilities/ResourcePool.h +636 -0
- hikyuu/include/hikyuu/utilities/SpendTimer.h +10 -9
- hikyuu/include/hikyuu/utilities/TimerManager.h +2 -2
- hikyuu/include/hikyuu/utilities/any_to_string.h +142 -0
- hikyuu/include/hikyuu/utilities/arithmetic.h +69 -33
- hikyuu/include/hikyuu/utilities/base64.h +59 -0
- hikyuu/include/hikyuu/utilities/config.h +41 -0
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +41 -31
- hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +24 -13
- hikyuu/include/hikyuu/utilities/db_connect/DBCondition.h +48 -48
- hikyuu/include/hikyuu/utilities/db_connect/DBConnect.h +10 -0
- hikyuu/include/hikyuu/utilities/db_connect/DBConnectBase.h +5 -22
- hikyuu/include/hikyuu/utilities/db_connect/DBUpgrade.h +3 -3
- hikyuu/include/hikyuu/utilities/db_connect/SQLException.h +1 -1
- hikyuu/include/hikyuu/utilities/db_connect/SQLResultSet.h +1 -1
- hikyuu/include/hikyuu/utilities/db_connect/SQLStatementBase.h +7 -7
- hikyuu/include/hikyuu/utilities/db_connect/TableMacro.h +1 -2
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +9 -9
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLStatement.h +18 -18
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h +3 -3
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteStatement.h +2 -2
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteUtil.h +6 -6
- hikyuu/include/hikyuu/{exception.h → utilities/exception.h} +1 -0
- hikyuu/include/hikyuu/utilities/http_client/HttpClient.h +229 -0
- hikyuu/include/hikyuu/utilities/http_client/nng_wrap.h +517 -0
- hikyuu/include/hikyuu/utilities/http_client/url.h +25 -0
- hikyuu/include/hikyuu/utilities/{IniParser.h → ini_parser/IniParser.h} +10 -5
- hikyuu/include/hikyuu/utilities/ini_parser/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/md5.h +41 -0
- hikyuu/include/hikyuu/utilities/mo/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/mo/mo.h +48 -0
- hikyuu/include/hikyuu/utilities/mo/moFileReader.h +836 -0
- hikyuu/include/hikyuu/{global → utilities}/node/NodeClient.h +25 -18
- hikyuu/include/hikyuu/{global → utilities}/node/NodeError.h +1 -1
- hikyuu/include/hikyuu/{global → utilities}/node/NodeMessage.h +3 -2
- hikyuu/include/hikyuu/utilities/node/NodeServer.h +246 -0
- hikyuu/include/hikyuu/utilities/node/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/os.h +16 -15
- hikyuu/include/hikyuu/utilities/snowflake.h +110 -0
- hikyuu/include/hikyuu/utilities/string_view.h +70 -0
- hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +3 -3
- hikyuu/include/hikyuu/version.h +4 -4
- hikyuu/sqlite3.dll +0 -0
- hikyuu/vcruntime140.dll +0 -0
- hikyuu/vcruntime140_1.dll +0 -0
- hikyuu-2.1.1.dist-info/METADATA +115 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.1.dist-info}/RECORD +73 -53
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.1.dist-info}/top_level.txt +4 -1
- hikyuu/README.rst +0 -79
- hikyuu-2.1.0.dist-info/METADATA +0 -126
- /hikyuu/include/hikyuu/{global/node → utilities/http_client}/__init__.py +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.1.dist-info}/LICENSE +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.1.dist-info}/WHEEL +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.1.dist-info}/entry_points.txt +0 -0
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
#include <fmt/ostream.h>
|
|
21
21
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
22
22
|
|
|
23
|
-
#ifndef
|
|
24
|
-
#define
|
|
23
|
+
#ifndef HKU_UTILS_API
|
|
24
|
+
#define HKU_UTILS_API
|
|
25
25
|
#endif
|
|
26
26
|
|
|
27
27
|
namespace hku {
|
|
@@ -33,7 +33,7 @@ namespace bd = boost::gregorian;
|
|
|
33
33
|
* 时长,用于时间计算
|
|
34
34
|
* @ingroup DataType
|
|
35
35
|
*/
|
|
36
|
-
class
|
|
36
|
+
class HKU_UTILS_API TimeDelta {
|
|
37
37
|
public:
|
|
38
38
|
/**
|
|
39
39
|
* 构造函数
|
|
@@ -58,11 +58,14 @@ public:
|
|
|
58
58
|
/** 通过 boost::posix_time::time_duration 构造 */
|
|
59
59
|
explicit TimeDelta(bt::time_duration td);
|
|
60
60
|
|
|
61
|
+
/** 从字符串构造,格式:-1 days, hh:mm:ss.000000) */
|
|
62
|
+
explicit TimeDelta(const std::string& delta);
|
|
63
|
+
|
|
61
64
|
/** 赋值构造函数 */
|
|
62
|
-
TimeDelta(const TimeDelta&) = default;
|
|
65
|
+
TimeDelta(const TimeDelta &) = default;
|
|
63
66
|
|
|
64
67
|
/** 赋值拷贝函数 */
|
|
65
|
-
TimeDelta&
|
|
68
|
+
TimeDelta &operator=(const TimeDelta &other) {
|
|
66
69
|
if (this != &other) {
|
|
67
70
|
m_duration = other.m_duration;
|
|
68
71
|
}
|
|
@@ -259,8 +262,8 @@ private:
|
|
|
259
262
|
static constexpr const int64_t m_one_day_ticks = 24 * 60 * 60 * 1000000LL;
|
|
260
263
|
};
|
|
261
264
|
|
|
262
|
-
std::ostream&
|
|
263
|
-
inline std::ostream&
|
|
265
|
+
std::ostream &operator<<(std::ostream &out, TimeDelta td);
|
|
266
|
+
inline std::ostream &operator<<(std::ostream &out, TimeDelta td) {
|
|
264
267
|
out << td.str();
|
|
265
268
|
return out;
|
|
266
269
|
}
|
|
@@ -280,28 +283,28 @@ inline TimeDelta Days(int64_t days) {
|
|
|
280
283
|
* @param hours 小时数
|
|
281
284
|
* @ingroup DataType
|
|
282
285
|
*/
|
|
283
|
-
TimeDelta
|
|
286
|
+
TimeDelta HKU_UTILS_API Hours(int64_t hours);
|
|
284
287
|
|
|
285
288
|
/**
|
|
286
289
|
* TimeDelta 快捷创建函数
|
|
287
290
|
* @param mins 分钟数
|
|
288
291
|
* @ingroup DataType
|
|
289
292
|
*/
|
|
290
|
-
TimeDelta
|
|
293
|
+
TimeDelta HKU_UTILS_API Minutes(int64_t mins);
|
|
291
294
|
|
|
292
295
|
/**
|
|
293
296
|
* TimeDelta 快捷创建函数
|
|
294
297
|
* @param secs 秒数
|
|
295
298
|
* @ingroup DataType
|
|
296
299
|
*/
|
|
297
|
-
TimeDelta
|
|
300
|
+
TimeDelta HKU_UTILS_API Seconds(int64_t secs);
|
|
298
301
|
|
|
299
302
|
/**
|
|
300
303
|
* TimeDelta 快捷创建函数
|
|
301
304
|
* @param milliseconds 毫秒数
|
|
302
305
|
* @ingroup DataType
|
|
303
306
|
*/
|
|
304
|
-
TimeDelta
|
|
307
|
+
TimeDelta HKU_UTILS_API Milliseconds(int64_t milliseconds);
|
|
305
308
|
|
|
306
309
|
/**
|
|
307
310
|
* TimeDelta 快捷创建函数
|
|
@@ -315,15 +318,23 @@ inline TimeDelta Microseconds(int64_t microsecs) {
|
|
|
315
318
|
|
|
316
319
|
} /* namespace hku */
|
|
317
320
|
|
|
321
|
+
namespace std {
|
|
322
|
+
|
|
323
|
+
inline string to_string(const hku::TimeDelta &delta) {
|
|
324
|
+
return delta.str();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
} // namespace std
|
|
328
|
+
|
|
318
329
|
#if FMT_VERSION >= 90000
|
|
319
330
|
template <>
|
|
320
331
|
struct fmt::formatter<hku::TimeDelta> {
|
|
321
|
-
constexpr auto parse(format_parse_context&
|
|
332
|
+
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
|
|
322
333
|
return ctx.end();
|
|
323
334
|
}
|
|
324
335
|
|
|
325
336
|
template <typename FormatContext>
|
|
326
|
-
auto format(const hku::TimeDelta&
|
|
337
|
+
auto format(const hku::TimeDelta &d, FormatContext &ctx) const -> decltype(ctx.out()) {
|
|
327
338
|
return fmt::format_to(ctx.out(), "{}", d.str());
|
|
328
339
|
}
|
|
329
340
|
};
|
|
@@ -13,23 +13,23 @@
|
|
|
13
13
|
#include <vector>
|
|
14
14
|
#include <fmt/format.h>
|
|
15
15
|
#include <fmt/ranges.h>
|
|
16
|
-
#include "
|
|
16
|
+
#include "hikyuu/utilities/Log.h"
|
|
17
17
|
|
|
18
|
-
#ifndef
|
|
19
|
-
#define
|
|
18
|
+
#ifndef HKU_UTILS_API
|
|
19
|
+
#define HKU_UTILS_API
|
|
20
20
|
#endif
|
|
21
21
|
|
|
22
22
|
namespace hku {
|
|
23
23
|
|
|
24
24
|
struct ASC {
|
|
25
|
-
explicit ASC(const char*
|
|
26
|
-
explicit ASC(const std::string&
|
|
25
|
+
explicit ASC(const char *name) : name(name) {}
|
|
26
|
+
explicit ASC(const std::string &name) : name(name) {}
|
|
27
27
|
std::string name;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
struct DESC {
|
|
31
|
-
explicit DESC(const char*
|
|
32
|
-
explicit DESC(const std::string&
|
|
31
|
+
explicit DESC(const char *name) : name(name) {}
|
|
32
|
+
explicit DESC(const std::string &name) : name(name) {}
|
|
33
33
|
std::string name;
|
|
34
34
|
};
|
|
35
35
|
|
|
@@ -38,50 +38,50 @@ struct LIMIT {
|
|
|
38
38
|
int limit = 1;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
class
|
|
41
|
+
class HKU_UTILS_API DBCondition {
|
|
42
42
|
public:
|
|
43
43
|
DBCondition() = default;
|
|
44
|
-
DBCondition(const DBCondition&) = default;
|
|
45
|
-
DBCondition(DBCondition&&
|
|
44
|
+
DBCondition(const DBCondition &) = default;
|
|
45
|
+
DBCondition(DBCondition &&rv) : m_condition(std::move(rv.m_condition)) {}
|
|
46
46
|
|
|
47
|
-
explicit DBCondition(const char*
|
|
48
|
-
explicit DBCondition(const std::string&
|
|
47
|
+
explicit DBCondition(const char *cond) : m_condition(cond) {}
|
|
48
|
+
explicit DBCondition(const std::string &cond) : m_condition(cond) {}
|
|
49
49
|
|
|
50
|
-
DBCondition&
|
|
51
|
-
DBCondition&
|
|
50
|
+
DBCondition &operator=(const DBCondition &) = default;
|
|
51
|
+
DBCondition &operator=(DBCondition &&rv) {
|
|
52
52
|
if (this != &rv) {
|
|
53
53
|
m_condition = std::move(rv.m_condition);
|
|
54
54
|
}
|
|
55
55
|
return *this;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
DBCondition&
|
|
59
|
-
DBCondition&
|
|
58
|
+
DBCondition &operator&(const DBCondition &other);
|
|
59
|
+
DBCondition &operator|(const DBCondition &other);
|
|
60
60
|
|
|
61
61
|
enum ORDERBY { ORDER_ASC, ORDER_DESC };
|
|
62
62
|
|
|
63
|
-
void orderBy(const std::string&
|
|
63
|
+
void orderBy(const std::string &field, ORDERBY order) {
|
|
64
64
|
m_condition = order == ORDERBY::ORDER_ASC
|
|
65
65
|
? fmt::format("{} order by {} ASC", m_condition, field)
|
|
66
66
|
: fmt::format("{} order by {} DESC", m_condition, field);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
DBCondition&
|
|
69
|
+
DBCondition &operator+(const ASC &asc) {
|
|
70
70
|
orderBy(asc.name, ORDER_ASC);
|
|
71
71
|
return *this;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
DBCondition&
|
|
74
|
+
DBCondition &operator+(const DESC &desc) {
|
|
75
75
|
orderBy(desc.name, ORDER_DESC);
|
|
76
76
|
return *this;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
DBCondition&
|
|
79
|
+
DBCondition &operator+(const LIMIT &limit) {
|
|
80
80
|
m_condition = fmt::format("{} limit {}", m_condition, limit.limit);
|
|
81
81
|
return *this;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
const std::string&
|
|
84
|
+
const std::string &str() const {
|
|
85
85
|
return m_condition;
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -90,27 +90,27 @@ private:
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
struct Field {
|
|
93
|
-
explicit Field(const char*
|
|
94
|
-
explicit Field(const std::string&
|
|
93
|
+
explicit Field(const char *name) : name(name) {}
|
|
94
|
+
explicit Field(const std::string &name) : name(name) {}
|
|
95
95
|
|
|
96
96
|
// in 和 not_in 不支持 字符串,一般不会用到 in ("stra", "strb") 的 SQL 操作
|
|
97
97
|
template <typename T>
|
|
98
|
-
DBCondition in(const std::vector<T
|
|
98
|
+
DBCondition in(const std::vector<T> &vals) {
|
|
99
99
|
HKU_CHECK(!vals.empty(), "input vals can't be empty!");
|
|
100
100
|
return DBCondition(fmt::format("({} in ({}))", name, fmt::join(vals, ",")));
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
template <typename T>
|
|
104
|
-
DBCondition not_in(const std::vector<T
|
|
104
|
+
DBCondition not_in(const std::vector<T> &vals) {
|
|
105
105
|
HKU_CHECK(!vals.empty(), "input vals can't be empty!");
|
|
106
106
|
return DBCondition(fmt::format("({} not in ({}))", name, fmt::join(vals, ",")));
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
DBCondition like(const std::string&
|
|
109
|
+
DBCondition like(const std::string &pattern) {
|
|
110
110
|
return DBCondition(fmt::format(R"(({} like "{}"))", name, pattern));
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
DBCondition like(const char*
|
|
113
|
+
DBCondition like(const char *pattern) {
|
|
114
114
|
return DBCondition(fmt::format(R"(({} like "{}"))", name, pattern));
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -120,7 +120,7 @@ struct Field {
|
|
|
120
120
|
// linux下类成员函数模板特化必须放在类外实现
|
|
121
121
|
// 否则编译时会报:explicit specialization in non-namespace scope
|
|
122
122
|
template <>
|
|
123
|
-
inline DBCondition Field::in<std::string>(const std::vector<std::string
|
|
123
|
+
inline DBCondition Field::in<std::string>(const std::vector<std::string> &vals) {
|
|
124
124
|
HKU_CHECK(!vals.empty(), "input vals can't be empty!");
|
|
125
125
|
std::ostringstream out;
|
|
126
126
|
out << "(" << name << " in (";
|
|
@@ -133,7 +133,7 @@ inline DBCondition Field::in<std::string>(const std::vector<std::string>& vals)
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
template <>
|
|
136
|
-
inline DBCondition Field::not_in<std::string>(const std::vector<std::string
|
|
136
|
+
inline DBCondition Field::not_in<std::string>(const std::vector<std::string> &vals) {
|
|
137
137
|
HKU_CHECK(!vals.empty(), "input vals can't be empty!");
|
|
138
138
|
std::ostringstream out;
|
|
139
139
|
out << "(" << name << " not in (";
|
|
@@ -145,103 +145,103 @@ inline DBCondition Field::not_in<std::string>(const std::vector<std::string>& va
|
|
|
145
145
|
return DBCondition(out.str());
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
inline std::ostream&
|
|
148
|
+
inline std::ostream &operator<<(std::ostream &out, const DBCondition &d) {
|
|
149
149
|
out << d.str();
|
|
150
150
|
return out;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
template <typename T>
|
|
154
|
-
inline DBCondition operator==(const Field&
|
|
154
|
+
inline DBCondition operator==(const Field &field, T val) {
|
|
155
155
|
std::ostringstream out;
|
|
156
156
|
out << "(" << field.name << "=" << val << ")";
|
|
157
157
|
return DBCondition(out.str());
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
template <typename T>
|
|
161
|
-
inline DBCondition operator!=(const Field&
|
|
161
|
+
inline DBCondition operator!=(const Field &field, T val) {
|
|
162
162
|
std::ostringstream out;
|
|
163
163
|
out << "(" << field.name << "<>" << val << ")";
|
|
164
164
|
return DBCondition(out.str());
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
template <typename T>
|
|
168
|
-
inline DBCondition operator>(const Field&
|
|
168
|
+
inline DBCondition operator>(const Field &field, T val) {
|
|
169
169
|
std::ostringstream out;
|
|
170
170
|
out << "(" << field.name << ">" << val << ")";
|
|
171
171
|
return DBCondition(out.str());
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
template <typename T>
|
|
175
|
-
inline DBCondition operator>=(const Field&
|
|
175
|
+
inline DBCondition operator>=(const Field &field, T val) {
|
|
176
176
|
std::ostringstream out;
|
|
177
177
|
out << "(" << field.name << ">=" << val << ")";
|
|
178
178
|
return DBCondition(out.str());
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
template <typename T>
|
|
182
|
-
inline DBCondition operator<(const Field&
|
|
182
|
+
inline DBCondition operator<(const Field &field, T val) {
|
|
183
183
|
std::ostringstream out;
|
|
184
184
|
out << "(" << field.name << "<" << val << ")";
|
|
185
185
|
return DBCondition(out.str());
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
template <typename T>
|
|
189
|
-
inline DBCondition operator<=(const Field&
|
|
189
|
+
inline DBCondition operator<=(const Field &field, T val) {
|
|
190
190
|
std::ostringstream out;
|
|
191
191
|
out << "(" << field.name << "<=" << val << ")";
|
|
192
192
|
return DBCondition(out.str());
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
template <>
|
|
196
|
-
inline DBCondition operator!=(const Field&
|
|
196
|
+
inline DBCondition operator!=(const Field &field, const char *val) {
|
|
197
197
|
return DBCondition(fmt::format(R"(({}<>"{}"))", field.name, val));
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
template <>
|
|
201
|
-
inline DBCondition operator>(const Field&
|
|
201
|
+
inline DBCondition operator>(const Field &field, const char *val) {
|
|
202
202
|
return DBCondition(fmt::format(R"(({}>"{}"))", field.name, val));
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
template <>
|
|
206
|
-
inline DBCondition operator<(const Field&
|
|
206
|
+
inline DBCondition operator<(const Field &field, const char *val) {
|
|
207
207
|
return DBCondition(fmt::format(R"(({}<"{}"))", field.name, val));
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
template <>
|
|
211
|
-
inline DBCondition operator>=(const Field&
|
|
211
|
+
inline DBCondition operator>=(const Field &field, const char *val) {
|
|
212
212
|
return DBCondition(fmt::format(R"(({}>="{}"))", field.name, val));
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
template <>
|
|
216
|
-
inline DBCondition operator<=(const Field&
|
|
216
|
+
inline DBCondition operator<=(const Field &field, const char *val) {
|
|
217
217
|
return DBCondition(fmt::format(R"(({}<="{}"))", field.name, val));
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
inline DBCondition operator==(const Field&
|
|
220
|
+
inline DBCondition operator==(const Field &field, const std::string &val) {
|
|
221
221
|
return DBCondition(fmt::format(R"(({}="{}"))", field.name, val));
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
inline DBCondition operator!=(const Field&
|
|
224
|
+
inline DBCondition operator!=(const Field &field, const std::string &val) {
|
|
225
225
|
return DBCondition(fmt::format(R"(({}<>"{}"))", field.name, val));
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
inline DBCondition operator>(const Field&
|
|
228
|
+
inline DBCondition operator>(const Field &field, const std::string &val) {
|
|
229
229
|
return DBCondition(fmt::format(R"(({}>"{}"))", field.name, val));
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
inline DBCondition operator<(const Field&
|
|
232
|
+
inline DBCondition operator<(const Field &field, const std::string &val) {
|
|
233
233
|
return DBCondition(fmt::format(R"(({}<"{}"))", field.name, val));
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
inline DBCondition operator>=(const Field&
|
|
236
|
+
inline DBCondition operator>=(const Field &field, const std::string &val) {
|
|
237
237
|
return DBCondition(fmt::format(R"(({}>="{}"))", field.name, val));
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
inline DBCondition operator<=(const Field&
|
|
240
|
+
inline DBCondition operator<=(const Field &field, const std::string &val) {
|
|
241
241
|
return DBCondition(fmt::format(R"(({}<="{}"))", field.name, val));
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
inline DBCondition operator==(const Field&
|
|
244
|
+
inline DBCondition operator==(const Field &field, const char *val) {
|
|
245
245
|
return DBCondition(fmt::format(R"(({}="{}"))", field.name, val));
|
|
246
246
|
}
|
|
247
247
|
|
|
@@ -17,4 +17,14 @@
|
|
|
17
17
|
#include "TableMacro.h"
|
|
18
18
|
#include "DBUpgrade.h"
|
|
19
19
|
|
|
20
|
+
#include "hikyuu/utilities/config.h"
|
|
21
|
+
#if HKU_ENABLE_MYSQL
|
|
22
|
+
#include "mysql/MySQLConnect.h"
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
#if HKU_ENABLE_SQLITE
|
|
26
|
+
#include "sqlite/SQLiteConnect.h"
|
|
27
|
+
#include "sqlite/SQLiteUtil.h"
|
|
28
|
+
#endif
|
|
29
|
+
|
|
20
30
|
#endif /* HIKYUU_DB_CONNECT_H */
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
#ifndef HIKYUU_DB_CONNECT_DBCONNECTBASE_H
|
|
11
11
|
#define HIKYUU_DB_CONNECT_DBCONNECTBASE_H
|
|
12
12
|
|
|
13
|
-
#include "../../DataType.h"
|
|
14
13
|
#include "../../utilities/Parameter.h"
|
|
14
|
+
#include "../Null.h"
|
|
15
15
|
#include "DBCondition.h"
|
|
16
16
|
#include "SQLStatementBase.h"
|
|
17
17
|
#include "SQLException.h"
|
|
@@ -25,7 +25,7 @@ class SQLResultSet;
|
|
|
25
25
|
* 数据库连接基类
|
|
26
26
|
* @ingroup DBConnect
|
|
27
27
|
*/
|
|
28
|
-
class
|
|
28
|
+
class HKU_UTILS_API DBConnectBase : public std::enable_shared_from_this<DBConnectBase> {
|
|
29
29
|
PARAMETER_SUPPORT // NOSONAR
|
|
30
30
|
|
|
31
31
|
public :
|
|
@@ -297,7 +297,7 @@ private:
|
|
|
297
297
|
};
|
|
298
298
|
|
|
299
299
|
/** @ingroup DBConnect */
|
|
300
|
-
typedef shared_ptr<DBConnectBase> DBConnectPtr;
|
|
300
|
+
typedef std::shared_ptr<DBConnectBase> DBConnectPtr;
|
|
301
301
|
|
|
302
302
|
//-------------------------------------------------------------------------
|
|
303
303
|
// inline方法实现
|
|
@@ -366,19 +366,16 @@ void DBConnectBase::save(T &item, bool autotrans) {
|
|
|
366
366
|
if (autotrans) {
|
|
367
367
|
commit();
|
|
368
368
|
}
|
|
369
|
-
|
|
370
369
|
} catch (hku::SQLException &e) {
|
|
371
370
|
if (autotrans) {
|
|
372
371
|
rollback();
|
|
373
372
|
}
|
|
374
373
|
SQL_THROW(e.errcode(), "failed save! sql: {}! {}", st->getSqlString(), e.what());
|
|
375
|
-
|
|
376
374
|
} catch (std::exception &e) {
|
|
377
375
|
if (autotrans) {
|
|
378
376
|
rollback();
|
|
379
377
|
}
|
|
380
378
|
HKU_THROW("failed save! sql: {}! {}", st->getSqlString(), e.what());
|
|
381
|
-
|
|
382
379
|
} catch (...) {
|
|
383
380
|
if (autotrans) {
|
|
384
381
|
rollback();
|
|
@@ -409,19 +406,16 @@ void DBConnectBase::batchSave(InputIterator first, InputIterator last, bool auto
|
|
|
409
406
|
if (autotrans) {
|
|
410
407
|
commit();
|
|
411
408
|
}
|
|
412
|
-
|
|
413
409
|
} catch (hku::SQLException &e) {
|
|
414
410
|
if (autotrans) {
|
|
415
411
|
rollback();
|
|
416
412
|
}
|
|
417
413
|
SQL_THROW(e.errcode(), "failed batch save! sql: {}! {}", st->getSqlString(), e.what());
|
|
418
|
-
|
|
419
414
|
} catch (std::exception &e) {
|
|
420
415
|
if (autotrans) {
|
|
421
416
|
rollback();
|
|
422
417
|
}
|
|
423
418
|
HKU_THROW("failed batch save! sql: {}! {}", st->getSqlString(), e.what());
|
|
424
|
-
|
|
425
419
|
} catch (...) {
|
|
426
420
|
if (autotrans) {
|
|
427
421
|
rollback();
|
|
@@ -431,7 +425,7 @@ void DBConnectBase::batchSave(InputIterator first, InputIterator last, bool auto
|
|
|
431
425
|
}
|
|
432
426
|
|
|
433
427
|
template <typename T>
|
|
434
|
-
void DBConnectBase::load(T &item, const string &where) {
|
|
428
|
+
void DBConnectBase::load(T &item, const std::string &where) {
|
|
435
429
|
std::ostringstream sql;
|
|
436
430
|
if (where != "") {
|
|
437
431
|
sql << T::getSelectSQL() << " where " << where << " limit 1";
|
|
@@ -451,7 +445,7 @@ void DBConnectBase::load(T &item, const DBCondition &cond) {
|
|
|
451
445
|
}
|
|
452
446
|
|
|
453
447
|
template <typename Container>
|
|
454
|
-
void DBConnectBase::batchLoad(Container &container, const string &where) {
|
|
448
|
+
void DBConnectBase::batchLoad(Container &container, const std::string &where) {
|
|
455
449
|
std::ostringstream sql;
|
|
456
450
|
if (where != "") {
|
|
457
451
|
sql << Container::value_type::getSelectSQL() << " where " << where;
|
|
@@ -513,19 +507,16 @@ void DBConnectBase::batchUpdate(InputIterator first, InputIterator last, bool au
|
|
|
513
507
|
if (autotrans) {
|
|
514
508
|
commit();
|
|
515
509
|
}
|
|
516
|
-
|
|
517
510
|
} catch (hku::SQLException &e) {
|
|
518
511
|
if (autotrans) {
|
|
519
512
|
rollback();
|
|
520
513
|
}
|
|
521
514
|
SQL_THROW(e.errcode(), "failed batch save! sql: {}! {}", st->getSqlString(), e.what());
|
|
522
|
-
|
|
523
515
|
} catch (std::exception &e) {
|
|
524
516
|
if (autotrans) {
|
|
525
517
|
rollback();
|
|
526
518
|
}
|
|
527
519
|
HKU_THROW("failed batch update! sql: {}! {}", st->getSqlString(), e.what());
|
|
528
|
-
|
|
529
520
|
} catch (...) {
|
|
530
521
|
if (autotrans) {
|
|
531
522
|
rollback();
|
|
@@ -570,19 +561,16 @@ void DBConnectBase::remove(T &item, bool autotrans) {
|
|
|
570
561
|
commit();
|
|
571
562
|
}
|
|
572
563
|
item.rowid(0);
|
|
573
|
-
|
|
574
564
|
} catch (hku::SQLException &e) {
|
|
575
565
|
if (autotrans) {
|
|
576
566
|
rollback();
|
|
577
567
|
}
|
|
578
568
|
SQL_THROW(e.errcode(), "failed delete! sql: {}! {}", st->getSqlString(), e.what());
|
|
579
|
-
|
|
580
569
|
} catch (std::exception &e) {
|
|
581
570
|
if (autotrans) {
|
|
582
571
|
rollback();
|
|
583
572
|
}
|
|
584
573
|
HKU_THROW("failed delete! sql: {}! {}", st->getSqlString(), e.what());
|
|
585
|
-
|
|
586
574
|
} catch (...) {
|
|
587
575
|
if (autotrans) {
|
|
588
576
|
rollback();
|
|
@@ -610,19 +598,16 @@ void DBConnectBase::batchRemove(InputIterator first, InputIterator last, bool au
|
|
|
610
598
|
if (autotrans) {
|
|
611
599
|
commit();
|
|
612
600
|
}
|
|
613
|
-
|
|
614
601
|
} catch (hku::SQLException &e) {
|
|
615
602
|
if (autotrans) {
|
|
616
603
|
rollback();
|
|
617
604
|
}
|
|
618
605
|
SQL_THROW(e.errcode(), "failed batch delete! {}", e.what());
|
|
619
|
-
|
|
620
606
|
} catch (std::exception &e) {
|
|
621
607
|
if (autotrans) {
|
|
622
608
|
rollback();
|
|
623
609
|
}
|
|
624
610
|
HKU_THROW("failed batch delete! {}", e.what());
|
|
625
|
-
|
|
626
611
|
} catch (...) {
|
|
627
612
|
if (autotrans) {
|
|
628
613
|
rollback();
|
|
@@ -645,13 +630,11 @@ inline void DBConnectBase::remove(const std::string &tablename, const std::strin
|
|
|
645
630
|
if (autotrans) {
|
|
646
631
|
commit();
|
|
647
632
|
}
|
|
648
|
-
|
|
649
633
|
} catch (hku::SQLException &e) {
|
|
650
634
|
if (autotrans) {
|
|
651
635
|
rollback();
|
|
652
636
|
}
|
|
653
637
|
SQL_THROW(e.errcode(), "Failed exec sql: {}! {}", sql, e.what());
|
|
654
|
-
|
|
655
638
|
} catch (std::exception &e) {
|
|
656
639
|
if (autotrans) {
|
|
657
640
|
rollback();
|
|
@@ -21,8 +21,8 @@ namespace hku {
|
|
|
21
21
|
* @param create_script 数据库创建脚本,若对应的数据库不存在则使用该脚本创建数据库
|
|
22
22
|
* @ingroup DataDriver
|
|
23
23
|
*/
|
|
24
|
-
void
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
void HKU_UTILS_API DBUpgrade(const DBConnectPtr &driver, const char *module_name,
|
|
25
|
+
const std::vector<std::string> &upgrade_scripts, int start_version = 2,
|
|
26
|
+
const char *create_script = nullptr);
|
|
27
27
|
|
|
28
28
|
} // namespace hku
|
|
@@ -21,7 +21,7 @@ namespace hku {
|
|
|
21
21
|
class DBConnectBase;
|
|
22
22
|
|
|
23
23
|
/** @ingroup DBConnect */
|
|
24
|
-
typedef shared_ptr<DBConnectBase> DBConnectPtr;
|
|
24
|
+
typedef std::shared_ptr<DBConnectBase> DBConnectPtr;
|
|
25
25
|
|
|
26
26
|
/** @ingroup DBConnect */
|
|
27
27
|
class null_blob_exception : public exception {
|
|
@@ -34,19 +34,19 @@ public:
|
|
|
34
34
|
* SQL Statement 基类
|
|
35
35
|
* @ingroup DBConnect
|
|
36
36
|
*/
|
|
37
|
-
class
|
|
37
|
+
class HKU_UTILS_API SQLStatementBase {
|
|
38
38
|
public:
|
|
39
39
|
/**
|
|
40
40
|
* 构造函数
|
|
41
41
|
* @param driver 数据库连接
|
|
42
42
|
* @param sql_statement SQL语句
|
|
43
43
|
*/
|
|
44
|
-
SQLStatementBase(DBConnectBase *driver, const string &sql_statement);
|
|
44
|
+
SQLStatementBase(DBConnectBase *driver, const std::string &sql_statement);
|
|
45
45
|
|
|
46
46
|
virtual ~SQLStatementBase() = default;
|
|
47
47
|
|
|
48
48
|
/** 获取构建时传入的表达式SQL语句 */
|
|
49
|
-
const string &getSqlString() const;
|
|
49
|
+
const std::string &getSqlString() const;
|
|
50
50
|
|
|
51
51
|
/** 获取数据驱动 */
|
|
52
52
|
DBConnectBase *getConnect() const;
|
|
@@ -163,7 +163,7 @@ protected:
|
|
|
163
163
|
};
|
|
164
164
|
|
|
165
165
|
/** @ingroup DBConnect */
|
|
166
|
-
typedef shared_ptr<SQLStatementBase> SQLStatementPtr;
|
|
166
|
+
typedef std::shared_ptr<SQLStatementBase> SQLStatementPtr;
|
|
167
167
|
|
|
168
168
|
inline SQLStatementBase ::SQLStatementBase(DBConnectBase *driver, const std::string &sql_statement)
|
|
169
169
|
: m_driver(driver), m_sql_string(sql_statement) {
|
|
@@ -183,7 +183,7 @@ inline void SQLStatementBase::bind(int idx, float item) {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
inline void SQLStatementBase::exec() {
|
|
186
|
-
#
|
|
186
|
+
#if HKU_SQL_TRACE
|
|
187
187
|
HKU_DEBUG(m_sql_string);
|
|
188
188
|
#endif
|
|
189
189
|
sub_exec();
|
|
@@ -277,7 +277,7 @@ inline void SQLStatementBase::getColumn(int idx, std::vector<char> &item) {
|
|
|
277
277
|
template <typename T>
|
|
278
278
|
typename std::enable_if<!std::numeric_limits<T>::is_integer>::type SQLStatementBase::getColumn(
|
|
279
279
|
int idx, T &item) {
|
|
280
|
-
string tmp;
|
|
280
|
+
std::string tmp;
|
|
281
281
|
try {
|
|
282
282
|
sub_getColumnAsBlob(idx, tmp);
|
|
283
283
|
} catch (null_blob_exception &) {
|
|
@@ -2168,8 +2168,7 @@ public:
|
|
|
2168
2168
|
}
|
|
2169
2169
|
|
|
2170
2170
|
#define TABLE_NO_AUTOID_BIND12(ROWID, table, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12) \
|
|
2171
|
-
pprivate:
|
|
2172
|
-
uint64_t m_rowid = 0; \
|
|
2171
|
+
pprivate : uint64_t m_rowid = 0; \
|
|
2173
2172
|
\
|
|
2174
2173
|
public: \
|
|
2175
2174
|
bool valid() const { \
|