BG
This commit is contained in:
@@ -41,6 +41,7 @@ public:
|
||||
~buffer();
|
||||
void set(const char* data, size_t length);
|
||||
void set(const ylib::buffer& data);
|
||||
void append(const std::string& data);
|
||||
void append(const char* data, size_t length);
|
||||
void append(const ylib::buffer& data);
|
||||
void append(std::initializer_list<uchar> char_list);
|
||||
|
||||
@@ -2,19 +2,26 @@
|
||||
#include "http_define.h"
|
||||
#if USE_NET_HTTP_UTIL
|
||||
#include <map>
|
||||
namespace ylib::network::http
|
||||
namespace ylib
|
||||
{
|
||||
class cookie
|
||||
namespace network
|
||||
{
|
||||
public:
|
||||
cookie();
|
||||
~cookie();
|
||||
void merge(const cookie& ck);
|
||||
void merge(const std::string& ck);
|
||||
std::string to_string();
|
||||
void clear();
|
||||
private:
|
||||
std::map<std::string, std::string> m_param;
|
||||
};
|
||||
namespace http
|
||||
{
|
||||
class cookie
|
||||
{
|
||||
public:
|
||||
cookie();
|
||||
~cookie();
|
||||
void merge(const cookie& ck);
|
||||
void merge(const std::string& ck);
|
||||
std::string to_string();
|
||||
void clear();
|
||||
private:
|
||||
std::map<std::string, std::string> m_param;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
127
include/ysql/mssql.h
Normal file
127
include/ysql/mssql.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#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
|
||||
@@ -6,7 +6,7 @@ namespace ylib {
|
||||
public:
|
||||
counter(const T& default_value = 0){m_value = default_value;}
|
||||
~counter() {}
|
||||
size_t make(){
|
||||
T make(){
|
||||
std::unique_lock<std::mutex> guard(m_mutex);
|
||||
return ++m_value;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
namespace ylib
|
||||
{
|
||||
namespace debug
|
||||
{
|
||||
// 检测异常产生DUMP文件
|
||||
void detect_exception();
|
||||
#ifdef _WIN32
|
||||
// 打印VS控制台
|
||||
void vs_console_println(const std::string& value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
32
include/yutil/interval.hpp
Normal file
32
include/yutil/interval.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <mutex>
|
||||
#include "yutil/time.h"
|
||||
namespace ylib {
|
||||
class interval {
|
||||
public:
|
||||
interval(timestamp msec):m_interval_msec(msec),m_pre_msec(0){
|
||||
m_pre_msec = time::now_msec();
|
||||
}
|
||||
~interval() {}
|
||||
/// <summary>
|
||||
/// 是否超市
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool isTimeout() {
|
||||
auto now_msec = time::now_msec();
|
||||
if (m_pre_msec + m_interval_msec < now_msec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
void timeout() {
|
||||
m_pre_msec = time::now_msec() - m_interval_msec - 1;
|
||||
}
|
||||
void update() {
|
||||
m_pre_msec = time::now_msec();
|
||||
}
|
||||
|
||||
private:
|
||||
timestamp m_interval_msec = 0;
|
||||
timestamp m_pre_msec = 0;
|
||||
};
|
||||
}
|
||||
@@ -29,6 +29,8 @@ namespace ylib {
|
||||
m_pop_size--;
|
||||
m_queue.push(example);
|
||||
}
|
||||
public:
|
||||
void* env = nullptr;
|
||||
protected:
|
||||
ylib::queue<void*> m_queue;
|
||||
std::mutex m_mutex;
|
||||
@@ -150,6 +152,8 @@ namespace ylib {
|
||||
{
|
||||
bool init_success = false;
|
||||
example = new EXAMPLE;
|
||||
//example->pool((void*)this);
|
||||
((EXAMPLE*)example)->pool(this);
|
||||
for (uint32 i = 0; i < 3; i++)
|
||||
{
|
||||
auto SR = ((EXAMPLE*)example)->start(m_info);
|
||||
@@ -172,7 +176,7 @@ namespace ylib {
|
||||
if (init_success)
|
||||
{
|
||||
m_pop_size++;
|
||||
((EXAMPLE*)example)->pool(this);
|
||||
|
||||
((EXAMPLE*)example)->task_out();
|
||||
return ((EXAMPLE*)example);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user