优化MYSQL模块
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#ifndef _WIN32
|
||||
#ifndef _WIN32
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
#include "base/define.h"
|
||||
@@ -37,12 +37,13 @@ namespace ylib::mysql
|
||||
class result :public ylib::error_base
|
||||
{
|
||||
public:
|
||||
result();
|
||||
result(void* handle);
|
||||
~result();
|
||||
// 列名
|
||||
std::string field_name(uint32 index);
|
||||
ylib::mysql::field field(uint32 index);
|
||||
|
||||
// 列类型
|
||||
std::string field_type(uint32 index);
|
||||
std::string field_type(const std::string& name);
|
||||
// 列数量
|
||||
uint32 field_count();
|
||||
// 行数量
|
||||
@@ -72,11 +73,12 @@ namespace ylib::mysql
|
||||
|
||||
ylib::json to_json();
|
||||
|
||||
friend class ylib::mysql::prepare_statement;
|
||||
private:
|
||||
void* m_handle = nullptr;
|
||||
uint32 m_field_count = 0;
|
||||
uint32 m_row_count = 0;
|
||||
|
||||
std::vector<ylib::mysql::field> m_fields;
|
||||
};
|
||||
|
||||
class prepare_statement:public ylib::error_base{
|
||||
|
||||
@@ -81,11 +81,13 @@ namespace ylib
|
||||
/// 查询
|
||||
/// </summary>
|
||||
ylib::mysql::result* query();
|
||||
#if 0
|
||||
/// <summary>
|
||||
/// 查询转换为layui需求模板
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ylib::json query_layui();
|
||||
#endif
|
||||
private:
|
||||
/// <summary>
|
||||
/// 生成SQL片段
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ylib
|
||||
struct interceptor_info {
|
||||
std::regex express;
|
||||
std::string express_string;
|
||||
std::function<bool(network::http::reqpack* rp)> callback;
|
||||
std::function<bool(network::http::reqpack* rp, const std::string& express)> callback;
|
||||
};
|
||||
/******************************************************
|
||||
* class:拦截器
|
||||
@@ -26,9 +26,8 @@ namespace ylib
|
||||
{
|
||||
public:
|
||||
interceptor();
|
||||
~interceptor();
|
||||
size_t add(const std::string& regex_express, std::function<bool(network::http::reqpack* rp)> callback);
|
||||
void remove(size_t index);
|
||||
~interceptor();
|
||||
size_t add(const std::string& regex_express, std::function<bool(network::http::reqpack* rp,const std::string& express)> callback);
|
||||
bool trigger(const std::string& url, network::http::reqpack* rp);
|
||||
private:
|
||||
ylib::nolock_array<interceptor_info*> m_array;
|
||||
|
||||
@@ -8,7 +8,7 @@ file(GLOB_RECURSE HEADER_FILES
|
||||
"${PROJECT_SOURCE_DIR}/include/*.h"
|
||||
)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/mysql/jdbc)
|
||||
include_directories(D:/3rdparty/mysql-connector-c++-8.2.0-winx64/include/jdbc)
|
||||
if(MSVC)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Windows/Include)
|
||||
add_compile_options(/utf-8)
|
||||
|
||||
@@ -409,8 +409,7 @@ ylib::mysql::result *ylib::mysql::prepare_statement::query()
|
||||
clear();
|
||||
try
|
||||
{
|
||||
m_result = new ylib::mysql::result;
|
||||
m_result->m_handle = PREPARE_STATEMENT->executeQuery();
|
||||
m_result = new ylib::mysql::result(PREPARE_STATEMENT->executeQuery());
|
||||
}
|
||||
catch (const sql::SQLException & e)
|
||||
{
|
||||
@@ -419,9 +418,16 @@ ylib::mysql::result *ylib::mysql::prepare_statement::query()
|
||||
return m_result;
|
||||
}
|
||||
|
||||
ylib::mysql::result::result()
|
||||
ylib::mysql::result::result(void* handle):m_handle(handle)
|
||||
{
|
||||
m_handle = nullptr;
|
||||
for (uint32 i = 0; i < RESULT_SET->getMetaData()->getColumnCount(); i++)
|
||||
{
|
||||
ylib::mysql::field field;
|
||||
field.name = RESULT_SET->getMetaData()->getColumnName(i + 1).c_str();;
|
||||
field.type_name = strutils::change_case(RESULT_SET->getMetaData()->getColumnTypeName(i + 1).c_str(), false);
|
||||
field.index = i;
|
||||
m_fields.push_back(field);
|
||||
}
|
||||
}
|
||||
|
||||
ylib::mysql::result::~result()
|
||||
@@ -448,13 +454,19 @@ std::string ylib::mysql::result::field_name(uint32 index)
|
||||
return RESULT_SET->getMetaData()->getColumnName(index);
|
||||
}
|
||||
|
||||
ylib::mysql::field ylib::mysql::result::field(uint32 index)
|
||||
std::string ylib::mysql::result::field_type(uint32 index)
|
||||
{
|
||||
ylib::mysql::field result;
|
||||
result.index = index;
|
||||
result.name = RESULT_SET->getMetaData()->getColumnName(index).c_str();
|
||||
result.type_name = strutils::change_case(RESULT_SET->getMetaData()->getColumnTypeName(index).c_str(), false);
|
||||
return result;
|
||||
return RESULT_SET->getMetaData()->getColumnTypeName(index);
|
||||
}
|
||||
|
||||
std::string ylib::mysql::result::field_type(const std::string& name)
|
||||
{
|
||||
for (size_t i = 0; i < m_fields.size(); i++)
|
||||
{
|
||||
if (m_fields[i].name == name)
|
||||
return m_fields[i].type_name;
|
||||
}
|
||||
throw ylib::exception("not found field: "+name);
|
||||
}
|
||||
|
||||
uint32 ylib::mysql::result::field_count()
|
||||
|
||||
@@ -209,7 +209,7 @@ ylib::mysql::result* ylib::select::query()
|
||||
setInsetValue(ppst, i + 1, insert_values[i]);
|
||||
return ppst->query();
|
||||
}
|
||||
|
||||
#if 0
|
||||
ylib::json ylib::select::query_layui()
|
||||
{
|
||||
auto __orderby = m_orderby;
|
||||
@@ -236,7 +236,7 @@ ylib::json ylib::select::query_layui()
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
#endif
|
||||
void ylib::select::make_sql(std::string& field_name, std::string& where, std::string& orderby, std::string& limit, std::vector<std::any>& insert_values)
|
||||
{
|
||||
if (m_fields.size() == 0)
|
||||
|
||||
Reference in New Issue
Block a user