znone
2020-01-11 121e56738835b2d710d4612f567d07ced290af6e
Fix some bugs.
4 files modified
43 ■■■■■ changed files
README.md 2 ●●● patch | view | raw | blame | history
include/qtl_common.hpp 12 ●●●● patch | view | raw | blame | history
include/qtl_mysql.hpp 28 ●●●●● patch | view | raw | blame | history
include/qtl_sqlite.hpp 1 ●●●● patch | view | raw | blame | history
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也可以将字符字段绑定到这些类型上。扩展方法是:
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
{
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([&params](statement& stmt) {
            qtl::bind_params(stmt, params);
        });
    }
    template<typename Types>
    bool fetch(Types&& values)
    {
        if(m_result==nullptr)
include/qtl_sqlite.hpp
@@ -4,6 +4,7 @@
#include "sqlite3.h"
#include <algorithm>
#include <array>
#include <sstream>
#include "qtl_common.hpp"
namespace qtl