Ferenc Szontágh
2024-07-02 fdb165bed6e1ae4f49e95258de0ac8233338a92d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef _QTL_ODBC_POOL_HPP_
#define _QTL_ODBC_POOL_HPP_
 
#include "qtl_database_pool.hpp"
#include "qtl_odbc.hpp"
 
namespace qtl
{
 
    namespace odbc
    {
 
        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 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
 
    }
 
}
 
#endif //_QTL_ODBC_POOL_HPP_