mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 19:08:48 +08:00
update for mysql kdata (continue)
This commit is contained in:
parent
2a280e173f
commit
b7674ce567
@ -8,22 +8,100 @@
|
||||
#ifndef HIKYUU_DATA_DRIVER_KDATA_MYSQL_KRECORDTABLE_H
|
||||
#define HIKYUU_DATA_DRIVER_KDATA_MYSQL_KRECORDTABLE_H
|
||||
|
||||
#include "../../../KQuery.h"
|
||||
#include "../../../utilities/db_connect/SQLStatementBase.h"
|
||||
|
||||
namespace hku {
|
||||
|
||||
class KRecordTable {
|
||||
public:
|
||||
KRecordTable();
|
||||
KRecordTable() = delete;
|
||||
KRecordTable(const string& market, const string& code, const KQuery::KType& ktype)
|
||||
: m_code(code),
|
||||
m_date(0),
|
||||
m_open(0.0),
|
||||
m_high(0.0),
|
||||
m_low(0.0),
|
||||
m_close(0.0),
|
||||
m_amount(0.0),
|
||||
m_count(0.0) {
|
||||
m_db_name = fmt::format("{}{}", market, ktype);
|
||||
to_lower(m_db_name);
|
||||
};
|
||||
|
||||
Datetime date() const {
|
||||
return m_date == 0 ? Null<Datetime>() : Datetime((uint64_t)m_date);
|
||||
}
|
||||
|
||||
price_t open() const {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
price_t high() const {
|
||||
return m_high;
|
||||
}
|
||||
|
||||
price_t low() const {
|
||||
return m_low;
|
||||
}
|
||||
|
||||
price_t close() const {
|
||||
return m_close;
|
||||
}
|
||||
|
||||
price_t amount() const {
|
||||
return m_amount;
|
||||
}
|
||||
|
||||
price_t count() const {
|
||||
return m_count;
|
||||
}
|
||||
|
||||
public:
|
||||
static string getInsertSQL() {
|
||||
return fmt::format(
|
||||
"insert into `{}`.`{}` "
|
||||
"(`date`, `open`, `high`, `low`, `close`, `amount`, `count`) "
|
||||
"values (?,?,?,?,?,?,?)",
|
||||
m_db_name, m_code);
|
||||
}
|
||||
|
||||
static string getUpdateSQL() {
|
||||
return fmt::format(
|
||||
"update `{}`.`{}` set `open`=?, `high`=?, `low`=?, "
|
||||
"`close`=?, `amount`=? `count`=? where `date`=?",
|
||||
m_db_name, m_code);
|
||||
}
|
||||
|
||||
static string getSelectSQL() {
|
||||
return fmt::format(
|
||||
"select `date`,`open`,`high`, `low`, `close`, `amount`, `count` from `{}`.`{}`",
|
||||
m_db_name, m_code);
|
||||
}
|
||||
|
||||
void save(const SQLStatementPtr& st) const {
|
||||
st->bind(0, m_date, m_open, m_high, m_low, m_close, m_amount, m_count);
|
||||
}
|
||||
|
||||
void update(const SQLStatementPtr& st) const {
|
||||
st->bind(0, m_open, m_high, m_low, m_close, m_amount, m_count);
|
||||
}
|
||||
|
||||
void load(const SQLStatementPtr& st) {
|
||||
st->getColumn(0, m_date, m_open, m_high, m_low, m_close, m_amount, m_count);
|
||||
}
|
||||
|
||||
private:
|
||||
int64_t date;
|
||||
price_t open;
|
||||
price_t high;
|
||||
price_t low;
|
||||
price_t close;
|
||||
price_t amount;
|
||||
price_t count;
|
||||
string m_db_name;
|
||||
string m_code;
|
||||
|
||||
int64_t m_date;
|
||||
price_t m_open;
|
||||
price_t m_high;
|
||||
price_t m_low;
|
||||
price_t m_close;
|
||||
price_t m_amount;
|
||||
price_t m_count;
|
||||
};
|
||||
|
||||
} // namespace hku
|
||||
|
Loading…
Reference in New Issue
Block a user