connection.h

00001 /*
00002  * connection.h
00003  * This file is part of dbPager Classes Library (DCL)
00004  *
00005  * Copyright (c) 2008 Dennis Prochko <wolfsoft@mail.ru>
00006  *
00007  * DCL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation version 3.
00010  *
00011  * DCL is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with DCL; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00019  * Boston, MA  02110-1301  USA
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 }} // namespace
00127 
00128 #endif /*_CONNECTION_H_*/
00129 

 
Support This Project
SourceForge.net Logo