From 50457f28fa7567b81ccf6a423e09312d5587cfbc Mon Sep 17 00:00:00 2001
From: znone <glyc@sina.com.cn>
Date: Fri, 04 Dec 2020 14:40:30 +0000
Subject: [PATCH] ODBC database can be accessed asynchronously.
---
include/qtl_odbc_pool.hpp | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/include/qtl_odbc_pool.hpp b/include/qtl_odbc_pool.hpp
index 4014cb1..eb5eb5e 100644
--- a/include/qtl_odbc_pool.hpp
+++ b/include/qtl_odbc_pool.hpp
@@ -39,6 +39,37 @@
environment m_env;
};
+#ifdef QTL_ODBC_ENABLE_ASYNC_MODE
+
+template<typename EventLoop>
+class async_pool : public qtl::async_pool<async_pool<EventLoop>, EventLoop, async_connection>
+{
+ typedef qtl::async_pool<async_pool<EventLoop>, EventLoop, async_connection> base_class;
+public:
+ async_pool(EventLoop& ev) : base_class(ev) { }
+ virtual ~async_pool() { }
+
+ template<typename Handler>
+ void new_connection(EventLoop& ev, Handler&& handler) throw()
+ {
+ async_connection* db = new async_connection(env);
+ db->open(ev, [this, handler, db](const mysql::error& e) mutable {
+ if (e)
+ {
+ delete db;
+ db = nullptr;
+ }
+ handler(e, db);
+ }, m_connection);
+ }
+
+protected:
+ std::string m_connection;
+ environment m_env;
+};
+
+#endif //QTL_ODBC_ENABLE_ASYNC_MODE
+
}
}
--
Gitblit v1.9.3