123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- #ifndef CPPDB_BACKEND_H
- #define CPPDB_BACKEND_H
- #include <iosfwd>
- #include <ctime>
- #include <string>
- #include <memory>
- #include <map>
- #include <typeinfo>
- #include <cppdb/defs.h>
- #include <cppdb/errors.h>
- #include <cppdb/ref_ptr.h>
- #include <cppdb/connection_specific.h>
- #ifdef __BORLANDC__
- #include <cppdb/pool.h>
- #endif
- namespace cppdb {
- class connection_info;
-
- #ifndef __BORLANDC__
- class pool;
- #endif
-
-
-
- namespace backend {
-
-
-
-
-
-
-
- class CPPDB_API result : public ref_counted {
- public:
-
-
-
-
- typedef enum {
- last_row_reached,
- next_row_exists,
- next_row_unknown
- } next_row;
-
-
-
-
- virtual next_row has_next() = 0;
-
-
-
-
- virtual bool next() = 0;
-
-
-
-
-
-
- virtual bool fetch(int col,short &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,unsigned short &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,int &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,unsigned &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,long &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,unsigned long &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,long long &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,unsigned long long &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,float &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,double &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,long double &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,std::string &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,std::ostream &v) = 0;
-
-
-
-
-
-
-
- virtual bool fetch(int col,std::tm &v) = 0;
-
-
-
- virtual bool is_null(int col) = 0;
-
-
-
- virtual int cols() = 0;
-
-
-
-
- virtual int name_to_column(std::string const &) = 0;
-
-
-
-
-
- virtual std::string column_to_name(int) = 0;
- result();
- virtual ~result();
- private:
- struct data;
- std::unique_ptr<data> d;
- };
- class statements_cache;
-
-
-
- class CPPDB_API statement : public ref_counted {
- public:
-
-
-
-
-
- virtual void reset() = 0;
-
-
-
-
- virtual std::string const &sql_query() = 0;
-
-
-
-
-
-
-
-
- virtual void bind(int col,std::string const &) = 0;
-
-
-
-
-
-
-
-
- virtual void bind(int col,char const *s) = 0;
-
-
-
-
-
-
-
-
- virtual void bind(int col,char const *b,char const *e) = 0;
-
-
-
-
-
-
-
- virtual void bind(int col,std::tm const &) = 0;
-
-
-
-
-
-
-
- virtual void bind(int col,std::istream &) = 0;
-
-
-
-
-
-
-
- virtual void bind(int col,int v) = 0;
-
-
-
-
-
-
-
-
-
- virtual void bind(int col,unsigned v) = 0;
-
-
-
-
-
-
-
-
-
- virtual void bind(int col,long v) = 0;
-
-
-
-
-
-
-
-
-
- virtual void bind(int col,unsigned long v) = 0;
-
-
-
-
-
-
-
-
-
- virtual void bind(int col,long long v) = 0;
-
-
-
-
-
-
-
-
-
- virtual void bind(int col,unsigned long long v) = 0;
-
-
-
-
-
-
-
- virtual void bind(int col,double v) = 0;
-
-
-
-
-
-
-
- virtual void bind(int col,long double v) = 0;
-
-
-
-
-
-
-
- virtual void bind_null(int col) = 0;
-
-
-
-
-
-
-
-
-
- virtual long long sequence_last(std::string const &sequence) = 0;
-
-
-
-
-
- virtual unsigned long long affected() = 0;
-
-
-
- virtual result *query() = 0;
-
-
-
- virtual void exec() = 0;
-
-
- static void dispose(statement *selfp);
-
- void cache(statements_cache *c);
- statement();
- virtual ~statement() ;
-
- private:
- struct data;
- std::unique_ptr<data> d;
- statements_cache *cache_;
- };
-
-
- class CPPDB_API statements_cache {
- statements_cache(statements_cache const &);
- void operator=(statements_cache const &);
- public:
- statements_cache();
- bool active();
- void set_size(size_t n);
- void put(statement *p_in);
- void clear();
- ref_ptr<statement> fetch(std::string const &q);
- ~statements_cache();
- private:
- struct data;
- std::unique_ptr<data> d;
- };
-
- class connection;
-
-
-
-
-
- class CPPDB_API driver : public ref_counted {
- driver(driver const &);
- void operator=(driver const &);
- public:
- driver() {}
- virtual ~driver() {}
-
-
-
-
- virtual bool in_use() = 0;
-
-
-
- virtual connection *open(connection_info const &cs) = 0;
-
-
-
-
- virtual connection *connect(connection_info const &cs);
- };
-
-
-
-
- class CPPDB_API loadable_driver : public driver {
- loadable_driver(loadable_driver const &);
- void operator=(loadable_driver const &);
- public:
- loadable_driver() {}
-
-
-
- virtual bool in_use();
- virtual ~loadable_driver() {}
-
-
-
- virtual connection *connect(connection_info const &cs);
- };
- extern "C" {
-
-
-
- typedef cppdb::backend::connection *cppdb_backend_connect_function(connection_info const &ci);
- }
-
-
-
- class CPPDB_API static_driver : public driver {
- public:
-
-
-
- typedef cppdb_backend_connect_function *connect_function_type;
-
-
-
- static_driver(connect_function_type c);
- ~static_driver();
-
-
-
- bool in_use();
-
-
-
- backend::connection *open(connection_info const &ci);
- private:
- connect_function_type connect_;
- };
-
-
-
- class CPPDB_API connection : public ref_counted {
- public:
-
-
-
- connection(connection_info const &info);
- virtual ~connection();
-
- void set_pool(ref_ptr<pool> p);
- ref_ptr<pool> get_pool();
- void set_driver(ref_ptr<loadable_driver> drv);
- static void dispose(connection *c);
- ref_ptr<statement> prepare(std::string const &q);
- ref_ptr<statement> get_prepared_statement(std::string const &q);
- ref_ptr<statement> get_prepared_uncached_statement(std::string const &q);
- ref_ptr<statement> get_statement(std::string const &q);
-
-
-
-
-
-
- virtual void begin() = 0;
-
-
-
-
- virtual void commit() = 0;
-
-
-
- virtual void rollback() = 0;
-
-
-
-
- virtual statement *prepare_statement(std::string const &q) = 0;
-
-
-
-
- virtual statement *create_statement(std::string const &q) = 0;
-
-
-
- virtual std::string escape(std::string const &) = 0;
-
-
-
- virtual std::string escape(char const *s) = 0;
-
-
-
- virtual std::string escape(char const *b,char const *e) = 0;
-
-
-
- virtual std::string driver() = 0;
-
-
-
-
- virtual std::string engine() = 0;
-
-
-
- void clear_cache();
-
-
-
-
-
- bool once_called() const;
-
-
-
-
- void once_called(bool v);
-
-
-
-
-
- connection_specific_data *connection_specific_get(std::type_info const &type) const;
-
-
-
- connection_specific_data *connection_specific_release(std::type_info const &type);
-
-
-
-
- void connection_specific_reset(std::type_info const &type,connection_specific_data *p = 0);
-
-
-
-
-
-
-
-
- bool recyclable();
-
-
-
-
-
- void recyclable(bool value);
- private:
- struct data;
- std::unique_ptr<data> d;
- statements_cache cache_;
- ref_ptr<loadable_driver> driver_;
- ref_ptr<pool> pool_;
- unsigned default_is_prepared_ : 1;
- unsigned once_called_ : 1;
- unsigned recyclable_ : 1;
- unsigned reserverd_ : 29;
- };
- }
- }
- #endif
|