Skip to content

Commit

Permalink
规范文件大小写命名
Browse files Browse the repository at this point in the history
  • Loading branch information
zxffffffff committed Aug 13, 2024
1 parent 8dda67f commit 9a2f286
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 12 deletions.
23 changes: 12 additions & 11 deletions sample-db/mysql/MySQLClient_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
#include <mutex>
#include <iostream>
#include <sstream>
#include <chrono>
#include <mysqlx/xdevapi.h>
#include "Chrono.h"
#include "chrono.h"

#if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1900)
/* msvc兼容utf-8: https://support.microsoft.com/en-us/kb/980263 */
#if (_MSC_VER >= 1700)
#pragma execution_character_set("utf-8")
#endif
#pragma warning(disable:4566)
#pragma warning(disable : 4566)
#endif

using namespace ::mysqlx;
Expand Down Expand Up @@ -54,10 +53,10 @@ class MySQLClientPrivate
Client client;

public:
MySQLClientPrivate(const char* host, int port, const char* user, const char* pwd)
:client(SessionOption::HOST, host, SessionOption::PORT, port,
SessionOption::USER, user, SessionOption::PWD, pwd,
ClientOption::POOLING, true, ClientOption::POOL_MAX_SIZE, 10)
MySQLClientPrivate(const char *host, int port, const char *user, const char *pwd)
: client(SessionOption::HOST, host, SessionOption::PORT, port,
SessionOption::USER, user, SessionOption::PWD, pwd,
ClientOption::POOLING, true, ClientOption::POOL_MAX_SIZE, 10)
{
CheckVersion();
}
Expand Down Expand Up @@ -85,7 +84,7 @@ class MySQLClientPrivate
return true;
}

bool RunSQL(const std::string& sql, std::vector<std::vector<std::string>>& ret)
bool RunSQL(const std::string &sql, std::vector<std::vector<std::string>> &ret)
{
LOG(INFO) << "[RunSQL sql] " << sql;
try
Expand All @@ -97,9 +96,11 @@ class MySQLClientPrivate
auto rows = res.fetchAll();

ret.clear();
for (auto row : rows) {
for (auto row : rows)
{
std::vector<std::string> fields;
for (size_t i = 0; i < row.colCount(); ++i) {
for (size_t i = 0; i < row.colCount(); ++i)
{
auto field = row.get(i);
auto type = field.getType();
std::string s_val;
Expand Down Expand Up @@ -137,7 +138,7 @@ class MySQLClientPrivate
LOG(INFO) << "[RunSQL res] use_time=" << use_time << "ms size=" << ret.size();
return true;
}
catch (const std::exception& e)
catch (const std::exception &e)
{
LOG(ERROR) << "[RunSQL error] " << e.what();
return false;
Expand Down
2 changes: 1 addition & 1 deletion sample-db/redis/RedisClient_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "glog/logging.h"
#include "RedisCommon.h"
#include "hiredis/hiredis.h"
#include "Chrono.h"
#include "chrono.h"

#if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1900)
/* msvc兼容utf-8: https://support.microsoft.com/en-us/kb/980263 */
Expand Down
56 changes: 56 additions & 0 deletions sample-tools/chrono.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/****************************************************************************
** MIT License
**
** Author : xiaofeng.zhu
** Support : [email protected], [email protected]
**
****************************************************************************/
#pragma once
#include <memory>
#include <chrono>

#if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1900)
/* msvc兼容utf-8: https://support.microsoft.com/en-us/kb/980263 */
#if (_MSC_VER >= 1700)
#pragma execution_character_set("utf-8")
#endif
#pragma warning(disable : 4566)
#endif

/* 高精度 ms */
class Chrono
{
public:
Chrono(bool _start = true)
{
if (_start)
start();
}

~Chrono() = default;

void start()
{
time_start = std::chrono::high_resolution_clock::now();
}

double stop()
{
time_stop = std::chrono::high_resolution_clock::now();
return use_time();
}

double use_time() const
{
return std::chrono::duration<double, std::milli>(time_stop - time_start).count();
}

double now_use_time() const
{
auto time_now = std::chrono::high_resolution_clock::now();
return std::chrono::duration<double, std::milli>(time_now - time_start).count();
}

private:
std::chrono::high_resolution_clock::time_point time_start, time_stop;
};

0 comments on commit 9a2f286

Please sign in to comment.