| | |
| | | - 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也可以将字符字段绑定到这些类型上。扩展方法是: |
| | |
| | | |
| | | #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) |
| | | { |
| | |
| | | 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 |
| | | { |
| | | |
| | |
| | | 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: |
| | |
| | | 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) |
| | | { |
| | | resize_binders(count); |
| | | qtl::bind_params(*this, params); |
| | | bind_proc(*this); |
| | | if(mysql_stmt_bind_param(m_stmt, &m_binders.front())) |
| | | throw_exception(); |
| | | for(size_t i=0; i!=count; i++) |
| | |
| | | } |
| | | |
| | | 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) |
| | |
| | | #include "sqlite3.h" |
| | | #include <algorithm> |
| | | #include <array> |
| | | #include <sstream> |
| | | #include "qtl_common.hpp" |
| | | |
| | | namespace qtl |