/home/martin/workspace/OpenStreetNav/src/psql/Database.h
Go to the documentation of this file.
00001 #ifndef PSQL_DATABASE_H_
00002 #define PSQL_DATABASE_H_
00003 
00004 #include <libpq-fe.h>
00005 #include <string>
00006 #include <vector>
00007 #include <unordered_map>
00008 #include <unordered_set>
00009 #include <set>
00010 #include <boost/signal.hpp>
00011 
00012 namespace psql
00013 {
00014 class IStatement;
00015 class ICursor;
00016 
00021 class Database
00022 {
00023 public:
00024     Database(Database const&) = delete;
00025     Database& operator=(Database const&) = delete;
00030     Database(Database && other);
00036     Database& operator=(Database && other);
00042     Database(std::string const& conninfo, bool synchr = false);
00050     void regist(std::string const& name, std::string const& sql, IStatement* st);
00057     void unregist(std::string const& name, IStatement* st);
00061     void begin_transaction();
00065     void commit_transaction();
00069     void rollback_transaction();
00074     void savepoint(std::string const& name);
00079     void rollback_to_savepoint(std::string const& name);
00083     void analyze();
00088     void set_schema(std::string schema);
00093     void create_schema(std::string const& schema);
00098     bool in_transaction();
00103     bool in_failed_transaction();
00108     PGconn* get_db();
00113     boost::signal<void (PGresult const&)>& notice_signal();
00119     void add_cursor(ICursor* curs);
00125     void remove_cursor(ICursor* curs);
00131     bool is_cursor(ICursor* curs) const;
00132     virtual ~Database();
00133 private:
00134     PGconn* conn;
00135     bool async;
00136     bool conn_synchr;
00137     std::unordered_map<std::string, IStatement*> stmts;
00138     std::unordered_set<ICursor*> cursors;
00139     boost::signal<void (PGresult const&)> notice_sig;
00140     std::vector<std::string> to_dealloc;
00141     std::set<std::string> savepoints;
00142     void receiveNotice(PGresult const* res);
00143     friend void noticeReceiver(void* arg, PGresult const* res);
00144 };
00145 
00146 }
00147 
00148 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines