修复linux编译问题
This commit is contained in:
@@ -65,8 +65,9 @@ add_subdirectory(3rdparty/lua)
|
||||
add_subdirectory(3rdparty/sqlite3)
|
||||
if(MSVC)
|
||||
add_subdirectory(3rdparty/libzip)
|
||||
endif()
|
||||
add_subdirectory(3rdparty/leveldb)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
2
build.sh
2
build.sh
@@ -8,6 +8,8 @@ sudo apt install -y libssl-dev
|
||||
sudo apt install -y xorg libx11-dev libgl1-mesa-dev
|
||||
sudo apt install -y openssl
|
||||
sudo apt install -y libboost-dev
|
||||
sudo apt install -y libmysqlcppconn-dev
|
||||
sudo apt install -y libleveldb-dev
|
||||
# 初始化变量
|
||||
|
||||
src_dir=$(pwd)
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace ylib::mssql
|
||||
class prepare_statement;
|
||||
struct mssql_conn_info
|
||||
{
|
||||
mssql_conn_info(){
|
||||
mssql_conn_info() {
|
||||
}
|
||||
std::string odbcname;
|
||||
std::string username;
|
||||
@@ -68,19 +68,19 @@ namespace ylib::mssql
|
||||
std::map<std::string, short> m_field_name_index;
|
||||
};
|
||||
|
||||
class prepare_statement:public ylib::error_base{
|
||||
class prepare_statement :public ylib::error_base {
|
||||
public:
|
||||
prepare_statement();
|
||||
~prepare_statement();
|
||||
void set_boolean(uint32 index,bool value);
|
||||
void set_datetime(uint32 index,const std::string& value);
|
||||
void set_double(uint32 index,double value);
|
||||
void set_int32(uint32 index,int32 value);
|
||||
void set_uint32(uint32 index,uint32 value);
|
||||
void set_int64(uint32 index,int64 value);
|
||||
void set_uint64(uint32 index,uint64 value);
|
||||
void set_boolean(uint32 index, bool value);
|
||||
void set_datetime(uint32 index, const std::string& value);
|
||||
void set_double(uint32 index, double value);
|
||||
void set_int32(uint32 index, int32 value);
|
||||
void set_uint32(uint32 index, uint32 value);
|
||||
void set_int64(uint32 index, int64 value);
|
||||
void set_uint64(uint32 index, uint64 value);
|
||||
void set_null(uint32 index);
|
||||
void set_string(uint32 index,const std::string& value);
|
||||
void set_string(uint32 index, const std::string& value);
|
||||
void clear();
|
||||
uint64 update();
|
||||
ylib::mssql::result* query();
|
||||
@@ -90,12 +90,12 @@ namespace ylib::mssql
|
||||
ylib::mssql::result* m_result = nullptr;
|
||||
void* m_handle = nullptr;
|
||||
};
|
||||
class conn :public ylib::example<ylib::mssql::mssql_conn_info>,public ylib::error_base
|
||||
class conn :public ylib::example<ylib::mssql::mssql_conn_info>, public ylib::error_base
|
||||
{
|
||||
public:
|
||||
conn();
|
||||
~conn();
|
||||
virtual EXAMPLE_START_RESULT start(const ylib::mssql::mssql_conn_info&info) override;
|
||||
virtual EXAMPLE_START_RESULT start(const ylib::mssql::mssql_conn_info& info) override;
|
||||
virtual void close() override;
|
||||
|
||||
|
||||
@@ -110,14 +110,14 @@ namespace ylib::mssql
|
||||
void rollback();
|
||||
friend class ylib::mssql::pool;
|
||||
private:
|
||||
void *m_handle = nullptr;
|
||||
void* m_handle = nullptr;
|
||||
ylib::mssql::mssql_conn_info m_info;
|
||||
class prepare_statement* m_ppst = nullptr;
|
||||
int m_sw = 0;
|
||||
};
|
||||
|
||||
|
||||
class pool: public ylib::pool<ylib::mssql::conn, ylib::mssql::mssql_conn_info>
|
||||
class pool : public ylib::pool<ylib::mssql::conn, ylib::mssql::mssql_conn_info>
|
||||
{
|
||||
public:
|
||||
pool();
|
||||
|
||||
@@ -17,14 +17,14 @@ namespace ylib::mysql
|
||||
class result;
|
||||
class conn;
|
||||
class prepare_statement;
|
||||
struct field{
|
||||
struct field {
|
||||
uint32 index = 0;
|
||||
std::string name;
|
||||
std::string type_name;
|
||||
};
|
||||
struct mysql_conn_info
|
||||
{
|
||||
mysql_conn_info(){
|
||||
mysql_conn_info() {
|
||||
port = 0;
|
||||
}
|
||||
std::string ipaddress;
|
||||
@@ -81,21 +81,21 @@ namespace ylib::mysql
|
||||
std::vector<ylib::mysql::field> m_fields;
|
||||
};
|
||||
|
||||
class prepare_statement:public ylib::error_base{
|
||||
class prepare_statement :public ylib::error_base {
|
||||
public:
|
||||
prepare_statement();
|
||||
~prepare_statement();
|
||||
void set_bigint(uint32 index,const std::string& value);
|
||||
void set_boolean(uint32 index,bool value);
|
||||
void set_datetime(uint32 index,const std::string& value);
|
||||
void set_double(uint32 index,double value);
|
||||
void set_int32(uint32 index,int32 value);
|
||||
void set_uint32(uint32 index,uint32 value);
|
||||
void set_int64(uint32 index,int64 value);
|
||||
void set_uint64(uint32 index,uint64 value);
|
||||
void set_bigint(uint32 index, const std::string& value);
|
||||
void set_boolean(uint32 index, bool value);
|
||||
void set_datetime(uint32 index, const std::string& value);
|
||||
void set_double(uint32 index, double value);
|
||||
void set_int32(uint32 index, int32 value);
|
||||
void set_uint32(uint32 index, uint32 value);
|
||||
void set_int64(uint32 index, int64 value);
|
||||
void set_uint64(uint32 index, uint64 value);
|
||||
void set_null(uint32 index);
|
||||
void set_string(uint32 index,const std::string& value);
|
||||
void set_blob(uint32 index,const ylib::buffer& value);
|
||||
void set_string(uint32 index, const std::string& value);
|
||||
void set_blob(uint32 index, const ylib::buffer& value);
|
||||
void clear();
|
||||
uint64 update();
|
||||
ylib::mysql::result* query();
|
||||
@@ -105,12 +105,12 @@ namespace ylib::mysql
|
||||
ylib::mysql::result* m_result = nullptr;
|
||||
void* m_handle = nullptr;
|
||||
};
|
||||
class conn :public ylib::example<ylib::mysql::mysql_conn_info>,public ylib::error_base
|
||||
class conn :public ylib::example<ylib::mysql::mysql_conn_info>, public ylib::error_base
|
||||
{
|
||||
public:
|
||||
conn();
|
||||
~conn();
|
||||
virtual EXAMPLE_START_RESULT start(const ylib::mysql::mysql_conn_info&info) override;
|
||||
virtual EXAMPLE_START_RESULT start(const ylib::mysql::mysql_conn_info& info) override;
|
||||
virtual void close() override;
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace ylib::mysql
|
||||
|
||||
friend class ylib::mysql::pool;
|
||||
private:
|
||||
void *m_handle = nullptr;
|
||||
void* m_handle = nullptr;
|
||||
ylib::mysql::mysql_conn_info m_info;
|
||||
class prepare_statement* m_ppst = nullptr;
|
||||
// 事务状态 0=未开启 1=已开启 2=执行完毕
|
||||
@@ -138,7 +138,7 @@ namespace ylib::mysql
|
||||
};
|
||||
|
||||
|
||||
class pool: public ylib::pool<ylib::mysql::conn, ylib::mysql::mysql_conn_info>
|
||||
class pool : public ylib::pool<ylib::mysql::conn, ylib::mysql::mysql_conn_info>
|
||||
{
|
||||
public:
|
||||
pool()
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace ylib
|
||||
};
|
||||
struct order_by {
|
||||
std::string field;
|
||||
sort sort;
|
||||
ylib::sort sort;
|
||||
};
|
||||
struct keyvalue {
|
||||
std::string name;
|
||||
@@ -31,7 +31,7 @@ namespace ylib
|
||||
/// <summary>
|
||||
/// MYSQL SELECT 查询器
|
||||
/// </summary>
|
||||
class select:public ylib::error_base {
|
||||
class select :public ylib::error_base {
|
||||
public:
|
||||
select(mysql::conn* conn);
|
||||
~select();
|
||||
@@ -51,11 +51,11 @@ namespace ylib
|
||||
/// <summary>
|
||||
/// 条件[A=B]
|
||||
/// </summary>
|
||||
select& where(const std::string& name,const std::string& expression,const std::any& value);
|
||||
select& where(const std::string& name, const std::string& expression, const std::any& value);
|
||||
/// <summary>
|
||||
/// 条件[模糊查询]
|
||||
/// </summary>
|
||||
select& where_like(const std::string& name,const std::string& value);
|
||||
select& where_like(const std::string& name, const std::string& value);
|
||||
/// <summary>
|
||||
/// 条件[自定义]
|
||||
/// </summary>
|
||||
@@ -63,7 +63,7 @@ namespace ylib
|
||||
/// <summary>
|
||||
/// LIMIT[页]
|
||||
/// </summary>
|
||||
select& page(uint32 page,uint32 count);
|
||||
select& page(uint32 page, uint32 count);
|
||||
/// <summary>
|
||||
/// LIMIT
|
||||
/// </summary>
|
||||
@@ -96,7 +96,7 @@ namespace ylib
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <param name="limit"></param>
|
||||
void make_sql(std::string& field_name,std::string& where,std::string& orderby,std::string& limit,std::vector<std::any>& insert_values);
|
||||
void make_sql(std::string& field_name, std::string& where, std::string& orderby, std::string& limit, std::vector<std::any>& insert_values);
|
||||
private:
|
||||
mysql::conn* m_conn = nullptr;
|
||||
std::vector<ylib::where> m_wheres;
|
||||
@@ -106,18 +106,6 @@ namespace ylib
|
||||
order_by m_orderby;
|
||||
|
||||
};
|
||||
#if 0
|
||||
class Lselect :public ylib::select {
|
||||
public:
|
||||
Lselect(void* conn);
|
||||
~Lselect();
|
||||
void where_i32(const std::string& name, const std::string& expression,int32 value);
|
||||
void where_i64(const std::string& name, const std::string& expression,int64 value);
|
||||
void where_dob(const std::string& name, const std::string& expression,double value);
|
||||
void where_str(const std::string& name, const std::string& expression, const std::string& value);
|
||||
void where_expression(const std::string& expression);
|
||||
};
|
||||
#endif
|
||||
/// <summary>
|
||||
/// MYSQL UPDATE
|
||||
/// </summary>
|
||||
@@ -189,26 +177,6 @@ namespace ylib
|
||||
order_by m_orderby;
|
||||
|
||||
};
|
||||
#if 0
|
||||
class Lupdate :public ylib::update {
|
||||
public:
|
||||
Lupdate(mysql::conn* conn);
|
||||
~Lupdate();
|
||||
|
||||
void set_i32(const std::string& name, int32 value);
|
||||
void set_i64(const std::string& name, int64 value);
|
||||
void set_dob(const std::string& name, double value);
|
||||
void set_str(const std::string& name, const std::string& value);
|
||||
|
||||
void where_i32(const std::string& name, const std::string& expression, int32 value);
|
||||
void where_i64(const std::string& name, const std::string& expression, int64 value);
|
||||
void where_dob(const std::string& name, const std::string& expression, double value);
|
||||
void where_str(const std::string& name, const std::string& expression, const std::string& value);
|
||||
|
||||
void where_expression(const std::string& expression);
|
||||
};
|
||||
|
||||
#endif
|
||||
/// <summary>
|
||||
/// MYSQL INSERT
|
||||
/// </summary>
|
||||
@@ -236,17 +204,6 @@ namespace ylib
|
||||
std::string m_table_name;
|
||||
std::vector<keyvalue> m_sets;
|
||||
};
|
||||
#if 0
|
||||
class Linsert :public ylib::insert {
|
||||
public:
|
||||
Linsert(mysql::conn* conn);
|
||||
~Linsert();
|
||||
void i32(const std::string& name, int32 value);
|
||||
void i64(const std::string& name, int64 value);
|
||||
void dob(const std::string& name, double value);
|
||||
void str(const std::string& name, const std::string& value);
|
||||
};
|
||||
#endif
|
||||
/// <summary>
|
||||
/// MYSQL DELETE
|
||||
/// </summary>
|
||||
@@ -304,16 +261,4 @@ namespace ylib
|
||||
order_by m_orderby;
|
||||
|
||||
};
|
||||
#if 0
|
||||
class Ldelete :public ylib::delete_ {
|
||||
public:
|
||||
Ldelete(mysql::conn* conn);
|
||||
~Ldelete();
|
||||
void where_i32(const std::string& name, const std::string& expression, int32 value);
|
||||
void where_i64(const std::string& name, const std::string& expression, int64 value);
|
||||
void where_dob(const std::string& name, const std::string& expression, double value);
|
||||
void where_str(const std::string& name, const std::string& expression, const std::string& value);
|
||||
void where_expression(const std::string& expression);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
127
src/db/mssql.h
127
src/db/mssql.h
@@ -1,127 +0,0 @@
|
||||
#pragma once
|
||||
#ifdef _WIN32
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#ifndef _WIN32
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
#include "ybase/define.h"
|
||||
#include "ybase/error.h"
|
||||
#include "yutil/json.h"
|
||||
#include "yutil/pool.hpp"
|
||||
|
||||
namespace ylib::mssql
|
||||
{
|
||||
class pool;
|
||||
class result;
|
||||
class conn;
|
||||
class prepare_statement;
|
||||
struct mssql_conn_info
|
||||
{
|
||||
mssql_conn_info(){
|
||||
}
|
||||
std::string odbcname;
|
||||
std::string username;
|
||||
std::string password;
|
||||
};
|
||||
class result :public ylib::error_base
|
||||
{
|
||||
public:
|
||||
result();
|
||||
~result();
|
||||
// 列数量
|
||||
uint32 field_count();
|
||||
// 行数量
|
||||
size_t row_count();
|
||||
// 取文本值
|
||||
std::string get(uint32 field);
|
||||
// 下一行
|
||||
bool next();
|
||||
int32 get_int32(uint32 index);
|
||||
int32 get_int32(const std::string& name);
|
||||
|
||||
uint32 get_uint32(uint32 index);
|
||||
uint32 get_uint32(const std::string& name);
|
||||
|
||||
int64 get_int64(uint32 index);
|
||||
int64 get_int64(const std::string& name);
|
||||
|
||||
uint64 get_uint64(uint32 index);
|
||||
uint64 get_uint64(const std::string& name);
|
||||
|
||||
std::string get_string(uint32 index);
|
||||
std::string get_string(const std::string& name);
|
||||
|
||||
bool get_boolean(uint32 index);
|
||||
bool get_boolean(const std::string& name);
|
||||
|
||||
double get_double(uint32 index);
|
||||
double get_double(const std::string& name);
|
||||
|
||||
friend class ylib::mssql::prepare_statement;
|
||||
private:
|
||||
void* m_handle = nullptr;
|
||||
uint32 m_field_count = 0;
|
||||
uint32 m_row_count = 0;
|
||||
|
||||
std::map<std::string, short> m_field_name_index;
|
||||
};
|
||||
|
||||
class prepare_statement:public ylib::error_base{
|
||||
public:
|
||||
prepare_statement();
|
||||
~prepare_statement();
|
||||
void set_boolean(uint32 index,bool value);
|
||||
void set_datetime(uint32 index,const std::string& value);
|
||||
void set_double(uint32 index,double value);
|
||||
void set_int32(uint32 index,int32 value);
|
||||
void set_uint32(uint32 index,uint32 value);
|
||||
void set_int64(uint32 index,int64 value);
|
||||
void set_uint64(uint32 index,uint64 value);
|
||||
void set_null(uint32 index);
|
||||
void set_string(uint32 index,const std::string& value);
|
||||
void clear();
|
||||
uint64 update();
|
||||
ylib::mssql::result* query();
|
||||
|
||||
friend class ylib::mssql::conn;
|
||||
private:
|
||||
ylib::mssql::result* m_result = nullptr;
|
||||
void* m_handle = nullptr;
|
||||
};
|
||||
class conn :public ylib::example<ylib::mssql::mssql_conn_info>,public ylib::error_base
|
||||
{
|
||||
public:
|
||||
conn();
|
||||
~conn();
|
||||
virtual EXAMPLE_START_RESULT start(const ylib::mssql::mssql_conn_info&info) override;
|
||||
virtual void close() override;
|
||||
|
||||
|
||||
virtual void recover() override;
|
||||
virtual void task_out() override;
|
||||
|
||||
|
||||
void clear();
|
||||
ylib::mssql::prepare_statement* setsql(const std::string& sql);
|
||||
void begin();
|
||||
void commit();
|
||||
void rollback();
|
||||
friend class ylib::mssql::pool;
|
||||
private:
|
||||
void *m_handle = nullptr;
|
||||
ylib::mssql::mssql_conn_info m_info;
|
||||
class prepare_statement* m_ppst = nullptr;
|
||||
int m_sw = 0;
|
||||
};
|
||||
|
||||
|
||||
class pool: public ylib::pool<ylib::mssql::conn, ylib::mssql::mssql_conn_info>
|
||||
{
|
||||
public:
|
||||
pool();
|
||||
~pool();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
161
src/db/mysql.h
161
src/db/mysql.h
@@ -1,161 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#ifndef _WIN32
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
#include "ybase/define.h"
|
||||
#include "ybase/error.h"
|
||||
#include "yutil/json.h"
|
||||
#include "yutil/pool.hpp"
|
||||
|
||||
namespace ylib::mysql
|
||||
{
|
||||
class pool;
|
||||
class result;
|
||||
class conn;
|
||||
class prepare_statement;
|
||||
struct field{
|
||||
uint32 index = 0;
|
||||
std::string name;
|
||||
std::string type_name;
|
||||
};
|
||||
struct mysql_conn_info
|
||||
{
|
||||
mysql_conn_info(){
|
||||
port = 0;
|
||||
}
|
||||
std::string ipaddress;
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string database;
|
||||
std::string charset;
|
||||
uint32 port;
|
||||
};
|
||||
class result :public ylib::error_base
|
||||
{
|
||||
public:
|
||||
result();
|
||||
~result();
|
||||
// 列名
|
||||
std::string field_name(uint32 index);
|
||||
ylib::mysql::field field(uint32 index);
|
||||
|
||||
// 列数量
|
||||
uint32 field_count();
|
||||
// 行数量
|
||||
size_t row_count();
|
||||
// 下一行
|
||||
bool next();
|
||||
int32 get_int32(uint32 index);
|
||||
int32 get_int32(const std::string& name);
|
||||
|
||||
uint32 get_uint32(uint32 index);
|
||||
uint32 get_uint32(const std::string& name);
|
||||
|
||||
int64 get_int64(uint32 index);
|
||||
int64 get_int64(const std::string& name);
|
||||
|
||||
uint64 get_uint64(uint32 index);
|
||||
uint64 get_uint64(const std::string& name);
|
||||
|
||||
std::string get_string(uint32 index);
|
||||
std::string get_string(const std::string& name);
|
||||
|
||||
bool get_boolean(uint32 index);
|
||||
bool get_boolean(const std::string& name);
|
||||
|
||||
double get_double(uint32 index);
|
||||
double get_double(const std::string& name);
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
class prepare_statement:public ylib::error_base{
|
||||
public:
|
||||
prepare_statement();
|
||||
~prepare_statement();
|
||||
void set_bigint(uint32 index,const std::string& value);
|
||||
void set_boolean(uint32 index,bool value);
|
||||
void set_datetime(uint32 index,const std::string& value);
|
||||
void set_double(uint32 index,double value);
|
||||
void set_int32(uint32 index,int32 value);
|
||||
void set_uint32(uint32 index,uint32 value);
|
||||
void set_int64(uint32 index,int64 value);
|
||||
void set_uint64(uint32 index,uint64 value);
|
||||
void set_null(uint32 index);
|
||||
void set_string(uint32 index,const std::string& value);
|
||||
void set_blob(uint32 index,const ylib::buffer& value);
|
||||
void clear();
|
||||
uint64 update();
|
||||
ylib::mysql::result* query();
|
||||
|
||||
friend class ylib::mysql::conn;
|
||||
private:
|
||||
ylib::mysql::result* m_result = nullptr;
|
||||
void* m_handle = nullptr;
|
||||
};
|
||||
class conn :public ylib::example<ylib::mysql::mysql_conn_info>,public ylib::error_base
|
||||
{
|
||||
public:
|
||||
conn();
|
||||
~conn();
|
||||
virtual EXAMPLE_START_RESULT start(const ylib::mysql::mysql_conn_info&info) override;
|
||||
virtual void close() override;
|
||||
|
||||
|
||||
virtual void recover() override;
|
||||
virtual void task_out() override;
|
||||
|
||||
|
||||
void clear();
|
||||
ylib::mysql::prepare_statement* setsql(const std::string& sql);
|
||||
uint64 insert_id();
|
||||
|
||||
void begin(bool autocommit = false);
|
||||
void commit();
|
||||
void rollback();
|
||||
|
||||
void setDatabase(const std::string& name);
|
||||
|
||||
friend class ylib::mysql::pool;
|
||||
private:
|
||||
void *m_handle = nullptr;
|
||||
ylib::mysql::mysql_conn_info m_info;
|
||||
class prepare_statement* m_ppst = nullptr;
|
||||
// 事务状态 0=未开启 1=已开启 2=执行完毕
|
||||
int m_sw = 0;
|
||||
};
|
||||
|
||||
|
||||
class pool: public ylib::pool<ylib::mysql::conn, ylib::mysql::mysql_conn_info>
|
||||
{
|
||||
public:
|
||||
pool()
|
||||
{
|
||||
|
||||
}
|
||||
~pool()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 协程调用
|
||||
/// 执行期间会让出协程,并等待再次调度
|
||||
/// </summary>
|
||||
/// <param name="ppst"></param>
|
||||
/// <returns></returns>
|
||||
std::tuple<bool, std::string> co_query(ylib::mysql::prepare_statement* ppst);
|
||||
}
|
||||
317
src/db/sqler.h
317
src/db/sqler.h
@@ -1,317 +0,0 @@
|
||||
#pragma once
|
||||
#include "ybase/error.h"
|
||||
#include "mysql.h"
|
||||
#include <any>
|
||||
namespace ylib
|
||||
{
|
||||
struct where {
|
||||
std::string name;
|
||||
std::string expression;
|
||||
std::any value;
|
||||
// 0=普通 1=Like 2=自定义
|
||||
int type = 0;
|
||||
};
|
||||
struct limit {
|
||||
int64 start = -1;
|
||||
int64 count = -1;
|
||||
};
|
||||
enum sort {
|
||||
ASC,
|
||||
DESC
|
||||
};
|
||||
struct order_by {
|
||||
std::string field;
|
||||
sort sort;
|
||||
};
|
||||
struct keyvalue {
|
||||
std::string name;
|
||||
std::any value;
|
||||
int extra = 0;
|
||||
};
|
||||
/// <summary>
|
||||
/// MYSQL SELECT 查询器
|
||||
/// </summary>
|
||||
class select:public ylib::error_base {
|
||||
public:
|
||||
select(mysql::conn* conn);
|
||||
~select();
|
||||
/// <summary>
|
||||
/// 表名
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
select& table(const std::string& table_name);
|
||||
/// <summary>
|
||||
/// 查询字段
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <param name="sort"></param>
|
||||
/// <returns></returns>
|
||||
select& field(const std::vector<std::string>& field);
|
||||
/// <summary>
|
||||
/// 条件[A=B]
|
||||
/// </summary>
|
||||
select& where(const std::string& name,const std::string& expression,const std::any& value);
|
||||
/// <summary>
|
||||
/// 条件[模糊查询]
|
||||
/// </summary>
|
||||
select& where_like(const std::string& name,const std::string& value);
|
||||
/// <summary>
|
||||
/// 条件[自定义]
|
||||
/// </summary>
|
||||
select& where(const std::string& expression);
|
||||
/// <summary>
|
||||
/// LIMIT[页]
|
||||
/// </summary>
|
||||
select& page(uint32 page,uint32 count);
|
||||
/// <summary>
|
||||
/// LIMIT
|
||||
/// </summary>
|
||||
select& limit(uint32 start, uint32 count);
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
select& orderby(const std::string& field, sort sort = DESC);
|
||||
/// <summary>
|
||||
/// 查询数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
uint64 count();
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
ylib::mysql::result* query();
|
||||
/// <summary>
|
||||
/// 查询转换为layui需求模板
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ylib::json query_layui();
|
||||
private:
|
||||
/// <summary>
|
||||
/// 生成SQL片段
|
||||
/// </summary>
|
||||
/// <param name="field_name"></param>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <param name="limit"></param>
|
||||
void make_sql(std::string& field_name,std::string& where,std::string& orderby,std::string& limit,std::vector<std::any>& insert_values);
|
||||
private:
|
||||
mysql::conn* m_conn = nullptr;
|
||||
std::vector<ylib::where> m_wheres;
|
||||
std::string m_table_name;
|
||||
std::vector<std::string> m_fields;
|
||||
ylib::limit m_limit;
|
||||
order_by m_orderby;
|
||||
|
||||
};
|
||||
#if 0
|
||||
class Lselect :public ylib::select {
|
||||
public:
|
||||
Lselect(void* conn);
|
||||
~Lselect();
|
||||
void where_i32(const std::string& name, const std::string& expression,int32 value);
|
||||
void where_i64(const std::string& name, const std::string& expression,int64 value);
|
||||
void where_dob(const std::string& name, const std::string& expression,double value);
|
||||
void where_str(const std::string& name, const std::string& expression, const std::string& value);
|
||||
void where_expression(const std::string& expression);
|
||||
};
|
||||
#endif
|
||||
/// <summary>
|
||||
/// MYSQL UPDATE
|
||||
/// </summary>
|
||||
class update :public ylib::error_base {
|
||||
struct set {
|
||||
std::string name;
|
||||
std::any value;
|
||||
std::string expression;
|
||||
// 0=普通 1=表达式
|
||||
int type = 0;
|
||||
};
|
||||
public:
|
||||
update(mysql::conn* conn);
|
||||
~update();
|
||||
/// <summary>
|
||||
/// 表名
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
update& table(const std::string& table_name);
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
update& set(const std::string& name, const std::any& value);
|
||||
update& set(const std::string& expression);
|
||||
/// <summary>
|
||||
/// 条件[A=B]
|
||||
/// </summary>
|
||||
update& where(const std::string& name, const std::string& expression, const std::any& value);
|
||||
/// <summary>
|
||||
/// 条件[模糊查询]
|
||||
/// </summary>
|
||||
update& where_like(const std::string& name, const std::string& value);
|
||||
/// <summary>
|
||||
/// 条件[自定义]
|
||||
/// </summary>
|
||||
update& where(const std::string& expression);
|
||||
/// <summary>
|
||||
/// LIMIT[页]
|
||||
/// </summary>
|
||||
update& page(uint32 page, uint32 count);
|
||||
/// <summary>
|
||||
/// LIMIT
|
||||
/// </summary>
|
||||
update& limit(uint32 start, uint32 count);
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
update& orderby(const std::string& field, sort sort = DESC);
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
uint64 exec();
|
||||
private:
|
||||
/// <summary>
|
||||
/// 生成SQL片段
|
||||
/// </summary>
|
||||
/// <param name="set"></param>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <param name="limit"></param>
|
||||
void make_sql(std::string& set, std::string& where, std::string& orderby, std::string& limit, std::vector<std::any>& insert_values);
|
||||
private:
|
||||
mysql::conn* m_conn = nullptr;
|
||||
std::vector<ylib::where> m_wheres;
|
||||
std::string m_table_name;
|
||||
std::vector<struct ylib::update::set> m_sets;
|
||||
ylib::limit m_limit;
|
||||
order_by m_orderby;
|
||||
|
||||
};
|
||||
#if 0
|
||||
class Lupdate :public ylib::update {
|
||||
public:
|
||||
Lupdate(mysql::conn* conn);
|
||||
~Lupdate();
|
||||
|
||||
void set_i32(const std::string& name, int32 value);
|
||||
void set_i64(const std::string& name, int64 value);
|
||||
void set_dob(const std::string& name, double value);
|
||||
void set_str(const std::string& name, const std::string& value);
|
||||
|
||||
void where_i32(const std::string& name, const std::string& expression, int32 value);
|
||||
void where_i64(const std::string& name, const std::string& expression, int64 value);
|
||||
void where_dob(const std::string& name, const std::string& expression, double value);
|
||||
void where_str(const std::string& name, const std::string& expression, const std::string& value);
|
||||
|
||||
void where_expression(const std::string& expression);
|
||||
};
|
||||
|
||||
#endif
|
||||
/// <summary>
|
||||
/// MYSQL INSERT
|
||||
/// </summary>
|
||||
class insert :public ylib::error_base {
|
||||
public:
|
||||
insert(mysql::conn* conn);
|
||||
~insert();
|
||||
/// <summary>
|
||||
/// 表名
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
insert& table(const std::string& table_name);
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
insert& set(const std::string& name, const std::any& value);
|
||||
insert& set_not_pret(const std::string& name, const std::string& value);
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
uint64 exec();
|
||||
private:
|
||||
mysql::conn* m_conn = nullptr;
|
||||
std::string m_table_name;
|
||||
std::vector<keyvalue> m_sets;
|
||||
};
|
||||
#if 0
|
||||
class Linsert :public ylib::insert {
|
||||
public:
|
||||
Linsert(mysql::conn* conn);
|
||||
~Linsert();
|
||||
void i32(const std::string& name, int32 value);
|
||||
void i64(const std::string& name, int64 value);
|
||||
void dob(const std::string& name, double value);
|
||||
void str(const std::string& name, const std::string& value);
|
||||
};
|
||||
#endif
|
||||
/// <summary>
|
||||
/// MYSQL DELETE
|
||||
/// </summary>
|
||||
class delete_ :public ylib::error_base {
|
||||
public:
|
||||
delete_(mysql::conn* conn);
|
||||
~delete_();
|
||||
/// <summary>
|
||||
/// 表名
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
delete_& table(const std::string& table_name);
|
||||
/// <summary>
|
||||
/// 条件[A=B]
|
||||
/// </summary>
|
||||
delete_& where(const std::string& name, const std::string& expression, const std::any& value);
|
||||
/// <summary>
|
||||
/// 条件[模糊查询]
|
||||
/// </summary>
|
||||
delete_& where_like(const std::string& name, const std::string& value);
|
||||
/// <summary>
|
||||
/// 条件[自定义]
|
||||
/// </summary>
|
||||
delete_& where(const std::string& expression);
|
||||
/// <summary>
|
||||
/// LIMIT[页]
|
||||
/// </summary>
|
||||
delete_& page(uint32 page, uint32 count);
|
||||
/// <summary>
|
||||
/// LIMIT
|
||||
/// </summary>
|
||||
delete_& limit(uint32 start, uint32 count);
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
delete_& orderby(const std::string& field, sort sort = DESC);
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
uint64 exec();
|
||||
private:
|
||||
/// <summary>
|
||||
/// 生成SQL片段
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <param name="limit"></param>
|
||||
void make_sql(std::string& where, std::string& orderby, std::string& limit, std::vector<std::any>& insert_values);
|
||||
private:
|
||||
mysql::conn* m_conn = nullptr;
|
||||
std::vector<ylib::where> m_wheres;
|
||||
std::string m_table_name;
|
||||
ylib::limit m_limit;
|
||||
order_by m_orderby;
|
||||
|
||||
};
|
||||
#if 0
|
||||
class Ldelete :public ylib::delete_ {
|
||||
public:
|
||||
Ldelete(mysql::conn* conn);
|
||||
~Ldelete();
|
||||
void where_i32(const std::string& name, const std::string& expression, int32 value);
|
||||
void where_i64(const std::string& name, const std::string& expression, int64 value);
|
||||
void where_dob(const std::string& name, const std::string& expression, double value);
|
||||
void where_str(const std::string& name, const std::string& expression, const std::string& value);
|
||||
void where_expression(const std::string& expression);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user