解决ubuntu20.04编译问题

This commit is contained in:
fasiondog 2020-08-01 18:52:56 +08:00
parent 7f6843d7b9
commit 8c4ae3b8c9
9 changed files with 5 additions and 513 deletions

1
.gitignore vendored
View File

@ -40,6 +40,7 @@ hikyuu_cpp/hikyuu/config.h
hikyuu_cpp/hikyuu/version.h
hikyuu/tools/maintain/importdata.ini
hikyuu/libboost_*
hikyuu/cpp/libboost_*
hikyuu/importdata
Hikyuu.egg-info
dist

View File

@ -1,112 +0,0 @@
/*
* MySQLConnect.cpp
*
* Copyright (c) 2019, hikyuu.org
*
* Created on: 2019-8-17
* Author: fasiondog
*/
#include "MySQLConnect.h"
namespace hku {
class MySQLCloser {
public:
void operator()(MYSQL* db) {
if (db) {
mysql_close(db);
delete db;
db = nullptr;
}
}
};
MySQLConnect::MySQLConnect(const Parameter& param) : DBConnectBase(param) {
shared_ptr<MYSQL> mysql(new MYSQL, MySQLCloser());
if (!mysql) {
HKU_THROW("Can't create MYSQL instance!");
return;
}
string host("127.0.0.1");
if (haveParam("host")) {
host = getParam<string>("host");
} else {
setParam<string>("host", host);
}
string usr("root");
if (haveParam("usr")) {
usr = getParam<string>("usr");
} else {
setParam<string>("usr", usr);
}
string pwd;
if (haveParam("pwd")) {
pwd = getParam<string>("pwd");
} else {
setParam<string>("pwd", pwd);
}
string database("hku_base");
if (haveParam("db")) {
database = getParam<string>("db");
} else {
setParam<string>("db", database);
}
string port_str("3306");
if (haveParam("port")) {
port_str = getParam<string>("port");
} else {
setParam<string>("port", port_str);
}
unsigned int port;
try {
port = boost::lexical_cast<unsigned int>(port_str);
} catch (...) {
port = 3306;
}
// HKU_TRACE("MYSQL host: {}", host);
// HKU_TRACE("MYSQL port: {}", port);
// HKU_TRACE("MYSQL database: {}", database);
HKU_ASSERT_M(mysql_init(mysql.get()) != NULL, "Initial MySQL handle error!");
my_bool reconnect = 1;
HKU_ASSERT_M(mysql_options(mysql.get(), MYSQL_OPT_RECONNECT, &reconnect) == 0,
"Failed set reconnect options");
HKU_ASSERT_M(mysql_real_connect(mysql.get(), host.c_str(), usr.c_str(), pwd.c_str(),
database.c_str(), port, NULL, CLIENT_MULTI_STATEMENTS) != NULL,
"Failed to connect to database! {}", mysql_error(mysql.get()));
HKU_ASSERT_M(mysql_set_character_set(mysql.get(), "utf8") == 0,
"mysql_set_character_set error!");
m_mysql = mysql;
return;
}
MySQLConnect::~MySQLConnect() {}
void MySQLConnect::exec(const string& sql_string) {
HKU_ASSERT_M(m_mysql, "database is not open!");
int ret = mysql_query(m_mysql.get(), sql_string.c_str());
HKU_ASSERT_M(ret == 0, "SQL error {}! error code{}", sql_string, ret);
}
SQLStatementPtr MySQLConnect::getStatement(const string& sql_statement) {
return make_shared<MySQLStatement>(shared_from_this(), sql_statement);
;
}
bool MySQLConnect::tableExist(const string& tablename) {
return false;
}
} // namespace hku

View File

@ -1,41 +0,0 @@
/*
* MySQLConnect.h
*
* Copyright (c) 2019, hikyuu.org
*
* Created on: 2019-8-17
* Author: fasiondog
*/
#pragma once
#ifndef HIYUU_DB_CONNECT_MYSQL_MYSQLCONNECT_H
#define HIYUU_DB_CONNECT_MYSQL_MYSQLCONNECT_H
#include "../DBConnectBase.h"
#include "MySQLStatement.h"
#if defined(_MSC_VER)
#include <mysql.h>
#else
#include <mysql/mysql.h>
#endif
namespace hku {
class HKU_API MySQLConnect : public DBConnectBase {
public:
MySQLConnect(const Parameter& param);
virtual ~MySQLConnect();
virtual void exec(const string& sql_string) override;
virtual SQLStatementPtr getStatement(const string& sql_statement) override;
virtual bool tableExist(const string& tablename) override;
private:
friend class MySQLStatement;
shared_ptr<MYSQL> m_mysql;
};
} // namespace hku
#endif /* HIYUU_DB_CONNECT_MYSQL_MYSQLCONNECT_H */

View File

@ -1,288 +0,0 @@
/*
* MySQLStatement.cpp
*
* Copyright (c) 2019, hikyuu.org
*
* Created on: 2019-8-17
* Author: fasiondog
*/
#include "MySQLStatement.h"
#include "MySQLConnect.h"
namespace hku {
MySQLStatement::MySQLStatement(const DBConnectPtr& driver, const string& sql_statement)
: SQLStatementBase(driver, sql_statement),
m_db((dynamic_cast<MySQLConnect*>(driver.get()))->m_mysql),
m_stmt(nullptr),
m_meta_result(nullptr),
m_needs_reset(false),
m_has_bind_result(false) {
m_stmt = mysql_stmt_init(m_db.get());
HKU_ASSERT_M(m_stmt != nullptr, "Failed mysql_stmt_init!");
int ret = mysql_stmt_prepare(m_stmt, sql_statement.c_str(), sql_statement.size());
if (ret != 0) {
std::string stmt_errorstr = mysql_stmt_error(m_stmt);
mysql_stmt_close(m_stmt);
m_stmt = nullptr;
HKU_THROW("Failed prepare statement! error: {} SQL: {}", stmt_errorstr.c_str(),
sql_statement);
}
auto param_count = mysql_stmt_param_count(m_stmt);
if (param_count > 0) {
m_param_bind.resize(param_count);
memset(m_param_bind.data(), 0, param_count * sizeof(MYSQL_BIND));
}
m_meta_result = mysql_stmt_result_metadata(m_stmt);
if (m_meta_result) {
int column_count = mysql_num_fields(m_meta_result);
m_result_bind.resize(column_count);
memset(m_result_bind.data(), 0, column_count * sizeof(MYSQL_BIND));
m_result_length.resize(column_count, 0);
m_result_is_null.resize(column_count, 0);
m_result_error.resize(column_count, 0);
}
}
MySQLStatement::~MySQLStatement() {
if (m_meta_result) {
mysql_free_result(m_meta_result);
}
mysql_stmt_close(m_stmt);
}
bool MySQLStatement::sub_isValid() const {
return m_stmt ? true : false;
}
void MySQLStatement::_reset() {
if (m_needs_reset) {
int ret = mysql_stmt_reset(m_stmt);
HKU_ASSERT_M(ret == 0, "Failed reset statement! {}", mysql_stmt_error(m_stmt));
// m_param_bind.clear();
// m_result_bind.clear();
m_param_buffer.clear();
m_result_buffer.clear();
m_needs_reset = false;
m_has_bind_result = false;
}
}
void MySQLStatement::sub_exec() {
_reset();
m_needs_reset = true;
if (m_param_bind.size() > 0) {
HKU_ASSERT_M(mysql_stmt_bind_param(m_stmt, m_param_bind.data()) == 0,
"Failed mysql_stmt_bind_param! {}", mysql_stmt_error(m_stmt));
}
HKU_ASSERT_M(mysql_stmt_execute(m_stmt) == 0, "Failed mysql_stmt_execute: {}",
mysql_stmt_error(m_stmt));
}
void MySQLStatement::_bindResult() {
if (!m_meta_result) {
return;
}
MYSQL_FIELD* field;
int idx = 0;
while ((field = mysql_fetch_field(m_meta_result))) {
m_result_bind[idx].buffer_type = field->type;
m_result_bind[idx].is_null = &m_result_is_null[idx];
m_result_bind[idx].length = &m_result_length[idx];
m_result_bind[idx].error = &m_result_error[idx];
if (field->type == MYSQL_TYPE_LONGLONG) {
int64 item = 0;
m_result_buffer.push_back(item);
auto& buf = m_result_buffer.back();
m_result_bind[idx].buffer = boost::any_cast<int64>(&buf);
} else if (field->type == MYSQL_TYPE_DOUBLE) {
double item = 0;
m_result_buffer.push_back(item);
auto& buf = m_result_buffer.back();
m_result_bind[idx].buffer = boost::any_cast<double>(&buf);
} else if (field->type == MYSQL_TYPE_VAR_STRING || field->type == MYSQL_TYPE_BLOB) {
m_result_bind[idx].buffer_length = 4096;
vector<char> item(4096);
m_result_buffer.push_back(item);
auto& buf = m_result_buffer.back();
vector<char>* p = boost::any_cast<vector<char>>(&buf);
m_result_bind[idx].buffer = p->data();
}
idx++;
}
}
bool MySQLStatement::sub_moveNext() {
if (!m_has_bind_result) {
_bindResult();
m_has_bind_result = true;
HKU_ASSERT_M(mysql_stmt_bind_result(m_stmt, m_result_bind.data()) == 0,
"Failed mysql_stmt_bind_result! {}", mysql_stmt_error(m_stmt));
HKU_ASSERT_M(mysql_stmt_store_result(m_stmt) == 0, "Failed mysql_stmt_store_result! {}",
mysql_stmt_error(m_stmt));
}
int ret = mysql_stmt_fetch(m_stmt);
if (ret == 0) {
return true;
} else if (ret == 1) {
HKU_THROW("Error occurred in mysql_stmt_fetch! {}", mysql_stmt_error(m_stmt));
}
return false;
}
void MySQLStatement::sub_bindNull(int idx) {
HKU_ASSERT_M(idx < m_param_bind.size(), "idx out of range! idx: {}, total: {}", idx,
m_param_bind.size());
m_param_bind[idx].buffer_type = MYSQL_TYPE_NULL;
}
void MySQLStatement::sub_bindInt(int idx, int64 value) {
HKU_ASSERT_M(idx < m_param_bind.size(), "idx out of range! idx: {}, total: {}", idx,
m_param_bind.size());
m_param_buffer.push_back(value);
auto& buf = m_param_buffer.back();
m_param_bind[idx].buffer_type = MYSQL_TYPE_LONGLONG;
m_param_bind[idx].buffer = boost::any_cast<int64>(&buf);
}
void MySQLStatement::sub_bindDouble(int idx, double item) {
HKU_ASSERT_M(idx < m_param_bind.size(), "idx out of range! idx: {}, total: {}", idx,
m_param_bind.size());
m_param_buffer.push_back(item);
auto& buf = m_param_buffer.back();
m_param_bind[idx].buffer_type = MYSQL_TYPE_DOUBLE;
m_param_bind[idx].buffer = boost::any_cast<double>(&buf);
}
void MySQLStatement::sub_bindText(int idx, const string& item) {
HKU_ASSERT_M(idx < m_param_bind.size(), "idx out of range! idx: {}, total: {}", idx,
m_param_bind.size());
m_param_buffer.push_back(item);
auto& buf = m_param_buffer.back();
string* p = boost::any_cast<string>(&buf);
m_param_bind[idx].buffer_type = MYSQL_TYPE_VAR_STRING;
m_param_bind[idx].buffer = (void*)p->data();
m_param_bind[idx].buffer_length = item.size();
m_param_bind[idx].is_null = 0;
unsigned long str_len = item.size();
m_param_buffer.push_back(str_len);
auto& ref = m_param_buffer.back();
m_param_bind[idx].length = boost::any_cast<unsigned long>(&ref);
;
}
void MySQLStatement::sub_bindBlob(int idx, const string& item) {
HKU_ASSERT_M(idx < m_param_bind.size(), "idx out of range! idx: {}, total: {}", idx,
m_param_bind.size());
m_param_buffer.push_back(item);
auto& buf = m_param_buffer.back();
string* p = boost::any_cast<string>(&buf);
m_param_bind[idx].buffer_type = MYSQL_TYPE_BLOB;
m_param_bind[idx].buffer = (void*)p->data();
m_param_bind[idx].buffer_length = item.size();
m_param_bind[idx].is_null = 0;
unsigned long str_len = item.size();
m_param_buffer.push_back(str_len);
auto& ref = m_param_buffer.back();
m_param_bind[idx].length = boost::any_cast<unsigned long>(&ref);
;
}
int MySQLStatement::sub_getNumColumns() const {
return mysql_stmt_field_count(m_stmt);
}
void MySQLStatement::sub_getColumnAsInt64(int idx, int64& item) {
HKU_ASSERT_M(idx < m_result_buffer.size(), "idx out of range! idx: {}, total: {}",
m_result_buffer.size());
HKU_ASSERT_M(m_result_error[idx] == 0, "Error occurred in sub_getColumnAsInt64! idx: {}", idx);
if (m_result_is_null[idx]) {
item = 0;
return;
}
try {
item = boost::any_cast<int64>(m_result_buffer[idx]);
} catch (...) {
HKU_THROW("Field type mismatch! idx: {}", idx);
}
}
void MySQLStatement::sub_getColumnAsDouble(int idx, double& item) {
HKU_ASSERT_M(idx < m_result_buffer.size(), "idx out of range! idx: {}, total: {}",
m_result_buffer.size());
HKU_ASSERT_M(m_result_error[idx] == 0, "Error occurred in sub_getColumnAsDouble! idx: {}", idx);
if (m_result_is_null[idx]) {
item = 0;
return;
}
try {
item = boost::any_cast<double>(m_result_buffer[idx]);
} catch (...) {
HKU_THROW("Field type mismatch! idx: {}", idx);
}
}
void MySQLStatement::sub_getColumnAsText(int idx, string& item) {
HKU_ASSERT_M(idx < m_result_buffer.size(), "idx out of range! idx: {}, total: {}",
m_result_buffer.size());
HKU_ASSERT_M(m_result_error[idx] == 0, "Error occurred in sub_getColumnAsText! idx: {}", idx);
if (m_result_is_null[idx]) {
item.clear();
return;
}
try {
vector<char>* p = boost::any_cast<vector<char>*>(m_result_buffer[idx]);
std::ostringstream buf;
for (unsigned long i = 0; i < m_result_length[idx]; i++) {
buf << (*p)[i];
}
item = buf.str();
} catch (...) {
HKU_THROW("Field type mismatch! idx: {}", idx);
}
}
void MySQLStatement::sub_getColumnAsBlob(int idx, string& item) {
HKU_ASSERT_M(idx < m_result_buffer.size(), "idx out of range! idx: {}, total: {}",
m_result_buffer.size());
HKU_ASSERT_M(m_result_error[idx] == 0, "Error occurred in sub_getColumnAsBlob! idx: {}", idx);
if (m_result_is_null[idx]) {
item.clear();
return;
}
try {
vector<char>* p = boost::any_cast<vector<char>*>(m_result_buffer[idx]);
std::ostringstream buf;
for (unsigned long i = 0; i < m_result_length[idx]; i++) {
buf << (*p)[i];
}
item = buf.str();
} catch (...) {
HKU_THROW("Field type mismatch! idx: {}", idx);
}
}
} // namespace hku

View File

@ -1,68 +0,0 @@
/*
* MySQLStatement.h
*
* Copyright (c) 2019, hikyuu.org
*
* Created on: 2019-8-17
* Author: fasiondog
*/
#pragma once
#ifndef HIYUU_DB_CONNECT_MYSQL_MYSQLSTATEMENT_H
#define HIYUU_DB_CONNECT_MYSQL_MYSQLSTATEMENT_H
#include <boost/any.hpp>
#include "../SQLStatementBase.h"
#if defined(_MSC_VER)
#include <mysql.h>
#else
#include <mysql/mysql.h>
#endif
namespace hku {
class HKU_API MySQLStatement : public SQLStatementBase {
public:
MySQLStatement() = delete;
MySQLStatement(const DBConnectPtr& driver, const string& sql_statement);
virtual ~MySQLStatement();
virtual bool sub_isValid() const override;
virtual void sub_exec() override;
virtual bool sub_moveNext() override;
virtual void sub_bindNull(int idx) override;
virtual void sub_bindInt(int idx, int64 value) override;
virtual void sub_bindDouble(int idx, double item) override;
virtual void sub_bindText(int idx, const string& item) override;
virtual void sub_bindBlob(int idx, const string& item) override;
virtual int sub_getNumColumns() const override;
virtual void sub_getColumnAsInt64(int idx, int64& item) override;
virtual void sub_getColumnAsDouble(int idx, double& item) override;
virtual void sub_getColumnAsText(int idx, string& item) override;
virtual void sub_getColumnAsBlob(int idx, string& item) override;
private:
void _reset();
void _bindResult();
private:
shared_ptr<MYSQL> m_db;
MYSQL_STMT* m_stmt;
MYSQL_RES* m_meta_result;
bool m_needs_reset;
bool m_has_bind_result;
vector<MYSQL_BIND> m_param_bind;
vector<MYSQL_BIND> m_result_bind;
vector<boost::any> m_param_buffer;
vector<boost::any> m_result_buffer;
vector<unsigned long> m_result_length;
vector<my_bool> m_result_is_null;
vector<my_bool> m_result_error;
};
} // namespace hku
#endif /* HIYUU_DB_CONNECT_MYSQL_MYSQLSTATEMENT_H */

View File

@ -8,7 +8,7 @@
*/
#include "doctest/doctest.h"
#include < fstream >
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ROC.h>
#include <hikyuu/indicator/crt/KDATA.h>

View File

@ -8,7 +8,7 @@
*/
#include "doctest/doctest.h"
#include < fstream >
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CVAL.h>
#include <hikyuu/indicator/crt/SUMBARS.h>

View File

@ -33,7 +33,7 @@ T python_list_to_vector(py::list pylist) {
size_t total = py::len(pylist);
T result(total);
for (size_t i = 0; i < total; i++) {
result[i] = py::extract<T::value_type>(pylist[i])();
result[i] = py::extract<typename T::value_type>(pylist[i])();
}
return result;
}

View File

@ -36,10 +36,10 @@ target("core")
add_deps("hikyuu")
if is_plat("windows") then
set_filename("core.pyd")
add_cxflags("-wd4251")
else
set_filename("core.so")
end
add_cxflags("-wd4251")
add_files("./**.cpp")
add_rpathdirs("$ORIGIN", "$ORIGIN/lib", "$ORIGIN/../lib")