connection.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _CONNECTION_H_
00023 #define _CONNECTION_H_
00024
00025 #include <string>
00026
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #include <odbcinst.h>
00030 #endif
00031
00032 #include <sqltypes.h>
00033 #include <sql.h>
00034 #include <sqlext.h>
00035
00036 #include <dcl/exception.h>
00037
00038 namespace dbp {
00039 namespace odbc {
00040
00042
00045 class connection_exception: public dbp::exception {
00046 public:
00048 connection_exception(const std::string &msg): exception(msg) { }
00049 };
00050
00052
00055 class connection {
00056 friend class query;
00057 public:
00059 typedef enum {
00060 READ_UNCOMMITTED,
00061 READ_COMMITTED,
00062 REPEATABLE_READ,
00063 SERIALIZABLE
00064 } transaction_isolation;
00066 connection();
00068 virtual ~connection();
00070
00077 void open(const std::string &dsn, const std::string &user_name,
00078 const std::string &password);
00080
00085 void open(const std::string &connect_string);
00087
00092 bool is_open() const;
00094
00097 void close();
00099
00105 void begin_transaction(transaction_isolation level = READ_COMMITTED);
00107
00111 void commit();
00113
00117 void rollback();
00118 protected:
00119 std::string get_error() const;
00120 private:
00121 SQLHENV henv;
00122 SQLHDBC hdbc;
00123 bool _is_open;
00124 };
00125
00126 }}
00127
00128 #endif
00129