#pragma once #if __cplusplus >= 201703L /* MySQL override. This needed to be inclided before cppconn/exception.h to define them */ #include #include #include /* Now remove the trow */ #define throw(...) #include #undef throw /* reset */ #endif #include #include "sql/SqlQuery.h" #include #include #define ERROR_MYSQL_MISSING_DRIVER -1 #define ERROR_MYSQL_INVLID_CONNECT -2 #define ERROR_MYSQL_INVLID_PROPERTIES -3 #define ERROR_MYSQL_INVLID_URL -4 namespace sql { namespace mysql { class MySQLManager; struct LocalConnection; bool evaluate_sql_query(std::string& sql, const std::vector& vars, std::vector& result); class MySQLCommand : public CommandData { }; struct ConnectionEntry { friend class MySQLManager; friend class LocalConnection; public: typedef std::function DisconnectListener; private: ConnectionEntry(std::unique_ptr&& connection, bool used) : connection(std::move(connection)), used(used) {} std::auto_ptr save_point; std::unique_ptr connection; bool used = false; }; struct LocalConnection { LocalConnection(MySQLManager* mgr, const std::shared_ptr& entry); ~LocalConnection(); MySQLManager* _mgr; std::shared_ptr _connection; }; class MySQLManager : public SqlManager { friend class LocalConnection; public: typedef std::function&)> ListenerConnectionDisconnect; typedef std::function&)> ListenerConnectionCreated; typedef std::function ListenerConnected; typedef std::function ListenerDisconnected; MySQLManager(); virtual ~MySQLManager(); result connect(const std::string &string) override; bool connected() override; result disconnect() override; ListenerDisconnected listener_disconnected; result execute_raw(const std::string& /* command */); protected: std::shared_ptr copyCommandData(std::shared_ptr ptr) override; std::shared_ptr allocateCommandData() override; result executeCommand(std::shared_ptr ptr) override; result queryCommand(std::shared_ptr ptr, const QueryCallback &fn) override; public: inline std::unique_ptr next_connection(); std::mutex connections_lock; std::condition_variable connections_condition; std::deque> connections; sql::Driver* driver = nullptr; bool disconnecting = false; }; } }