From 121e56738835b2d710d4612f567d07ced290af6e Mon Sep 17 00:00:00 2001
From: znone <glyc@sina.com.cn>
Date: Sat, 11 Jan 2020 13:55:34 +0000
Subject: [PATCH] Fix some bugs.
---
include/qtl_sqlite.hpp | 1 +
include/qtl_common.hpp | 12 ++++++------
include/qtl_mysql.hpp | 28 +++++++++++++++++++---------
README.md | 2 +-
4 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index 1fe49a6..87e108f 100644
--- a/README.md
+++ b/README.md
@@ -109,7 +109,7 @@
- is_truncated 数据是否被截断
#### 9. std::optional和std::any
-可以绑定字段到 C++17 中的 std::optional 和 std::any。当字段为null时,它们不包含任何内容,否则他们包含字段的值。
+可以绑定字段到 C++17 中的 std::optional 和 std::any。当字段为null时,它们不包含任何内容,否则它们包含字段的值。
#### 10. 支持标准库以外的字符串类型
除了标准库提供的std::string,另外其他库也提供了自己的字符串类,比如QT的QString,MFC/ATL的CString等。qtl也可以将字符字段绑定到这些类型上。扩展方法是:
diff --git a/include/qtl_common.hpp b/include/qtl_common.hpp
index aaaa0d6..34436c2 100644
--- a/include/qtl_common.hpp
+++ b/include/qtl_common.hpp
@@ -294,12 +294,6 @@
#endif // C++17
-template<typename Command, typename... Fields>
-inline size_t bind_fields(Command& command, Fields&&... fields)
-{
- return bind_fields(command, (size_t)0, std::forward<Fields>(fields)...);
-}
-
template<typename Command, typename T>
inline size_t bind_fields(Command& command, size_t index, T&& value)
{
@@ -314,6 +308,12 @@
return bind_fields(command, start+1, std::forward<Other>(other)...);
}
+template<typename Command, typename... Fields>
+inline size_t bind_fields(Command& command, Fields&&... fields)
+{
+ return bind_fields(command, (size_t)0, std::forward<Fields>(fields)...);
+}
+
namespace detail
{
diff --git a/include/qtl_mysql.hpp b/include/qtl_mysql.hpp
index 8174bca..8bb6e6d 100644
--- a/include/qtl_mysql.hpp
+++ b/include/qtl_mysql.hpp
@@ -656,7 +656,9 @@
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_ENUM:
+#if LIBMYSQL_VERSION_ID >= 50700
case MYSQL_TYPE_JSON:
+#endif
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
case MYSQL_TYPE_GEOMETRY:
@@ -779,27 +781,35 @@
throw_exception();
}
- template<typename Types>
- void execute(const Types& params)
+ template<typename BindProc>
+ void execute_custom(BindProc&& bind_proc)
{
- unsigned long count=mysql_stmt_param_count(m_stmt);
- if(count>0)
+ unsigned long count = mysql_stmt_param_count(m_stmt);
+ if (count > 0)
{
resize_binders(count);
- qtl::bind_params(*this, params);
- if(mysql_stmt_bind_param(m_stmt, &m_binders.front()))
+ bind_proc(*this);
+ if (mysql_stmt_bind_param(m_stmt, &m_binders.front()))
throw_exception();
- for(size_t i=0; i!=count; i++)
+ for (size_t i = 0; i != count; i++)
{
- if(m_binderAddins[i].m_after_fetch)
+ if (m_binderAddins[i].m_after_fetch)
m_binderAddins[i].m_after_fetch(m_binders[i]);
}
}
- if(mysql_stmt_execute(m_stmt)!=0)
+ if (mysql_stmt_execute(m_stmt) != 0)
throw_exception();
}
template<typename Types>
+ void execute(const Types& params)
+ {
+ execute_custom([¶ms](statement& stmt) {
+ qtl::bind_params(stmt, params);
+ });
+ }
+
+ template<typename Types>
bool fetch(Types&& values)
{
if(m_result==nullptr)
diff --git a/include/qtl_sqlite.hpp b/include/qtl_sqlite.hpp
index b0e1807..99147ad 100644
--- a/include/qtl_sqlite.hpp
+++ b/include/qtl_sqlite.hpp
@@ -4,6 +4,7 @@
#include "sqlite3.h"
#include <algorithm>
#include <array>
+#include <sstream>
#include "qtl_common.hpp"
namespace qtl
--
Gitblit v1.9.3