| | |
| | | namespace qtl |
| | | { |
| | | |
| | | namespace odbc |
| | | { |
| | | |
| | | class database_pool : public qtl::database_pool<database> |
| | | { |
| | | public: |
| | | database_pool() { } |
| | | virtual ~database_pool() { } |
| | | virtual database* new_database() throw() override |
| | | namespace odbc |
| | | { |
| | | database* db=NULL; |
| | | try |
| | | { |
| | | db=new database(m_env); |
| | | db->open(m_connection); |
| | | } |
| | | catch(error& e) |
| | | { |
| | | if(db) |
| | | { |
| | | delete db; |
| | | db=NULL; |
| | | } |
| | | } |
| | | return db; |
| | | } |
| | | |
| | | protected: |
| | | std::string m_connection; |
| | | environment m_env; |
| | | }; |
| | | class database_pool : public qtl::database_pool<database> |
| | | { |
| | | public: |
| | | database_pool() {} |
| | | virtual ~database_pool() {} |
| | | virtual database *new_database() throw() override |
| | | { |
| | | database *db = NULL; |
| | | try |
| | | { |
| | | db = new database(m_env); |
| | | db->open(m_connection); |
| | | } |
| | | catch (error &e) |
| | | { |
| | | if (db) |
| | | { |
| | | delete db; |
| | | db = NULL; |
| | | } |
| | | } |
| | | return db; |
| | | } |
| | | |
| | | protected: |
| | | std::string m_connection; |
| | | 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 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; |
| | | |
| | | 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 { |
| | | 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); |
| | | handler(e, db); }, m_connection); |
| | | } |
| | | |
| | | protected: |
| | | std::string m_connection; |
| | | environment m_env; |
| | | }; |
| | | |
| | | #endif // QTL_ODBC_ENABLE_ASYNC_MODE |
| | | |
| | | } |
| | | |
| | | protected: |
| | | std::string m_connection; |
| | | environment m_env; |
| | | }; |
| | | |
| | | #endif //QTL_ODBC_ENABLE_ASYNC_MODE |
| | | |
| | | } |
| | | |
| | | } |
| | | |