Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

odbc++/connection.h

00001 /* 
00002    This file is part of libodbc++.
00003    
00004    Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
00005    
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010    
00011    This library 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 GNU
00014    Library General Public License for more details.
00015    
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #ifndef __ODBCXX_CONNECTION_H
00023 #define __ODBCXX_CONNECTION_H
00024 
00025 #include <odbc++/setup.h>
00026 #include <odbc++/types.h>
00027 #include <odbc++/errorhandler.h>
00028 
00029 namespace odbc {
00030 
00031   class DriverInfo;
00032   class DatabaseMetaData;
00033   class Statement;
00034   class PreparedStatement;
00035   class CallableStatement;
00036 
00038   class ODBCXX_EXPORT Connection : public ErrorHandler {
00039     friend class DriverManager;
00040     friend class Statement;
00041     friend class DatabaseMetaData;
00042     friend class DriverInfo;
00043 
00044   private:
00045     struct PD;
00046 
00047     SQLHDBC hdbc_;
00048     // private data
00049     PD* pd_;
00050 
00051     DatabaseMetaData* metaData_;
00052     DriverInfo* driverInfo_;
00053     
00054 #ifdef ODBCXX_ENABLE_THREADS
00055     Mutex access_;
00056 #endif
00057 
00058 
00059     //utilities
00060     SQLUINTEGER _getNumericOption(SQLINTEGER optnum);
00061     ODBCXX_STRING _getStringOption(SQLINTEGER optnum);
00062     void _setNumericOption(SQLINTEGER optnum, SQLUINTEGER value);
00063     void _setStringOption(SQLINTEGER optnum, const ODBCXX_STRING& value);
00064     
00065     SQLHSTMT _allocStmt();
00066 
00067     //private constructor, called from DriverManager
00068     Connection(SQLHDBC h);
00069 
00070     void _connect(const ODBCXX_STRING& dsn,
00071                   const ODBCXX_STRING& user,
00072                   const ODBCXX_STRING& password);
00073 
00074     void _connect(const ODBCXX_STRING& connectString);
00075 
00076     void _registerStatement(Statement* stmt);
00077     void _unregisterStatement(Statement* stmt);
00078 
00079     const DriverInfo* _getDriverInfo() const {
00080       return driverInfo_;
00081     }
00082 
00083   public:
00086     enum TransactionIsolation {
00088       TRANSACTION_NONE,
00090       TRANSACTION_READ_UNCOMMITTED,
00092       TRANSACTION_READ_COMMITTED,
00094       TRANSACTION_REPEATABLE_READ,
00096       TRANSACTION_SERIALIZABLE
00097     };
00098     
00100     virtual ~Connection();
00101     
00103     bool getAutoCommit();
00104     
00108     void setAutoCommit(bool autoCommit);
00109 
00111     void commit();
00112 
00114     void rollback();
00115 
00117     ODBCXX_STRING getCatalog();
00118 
00120     void setCatalog(const ODBCXX_STRING& catalog);
00121 
00123     TransactionIsolation getTransactionIsolation();
00124 
00126     void setTransactionIsolation(TransactionIsolation isolation);
00127 
00129     bool isReadOnly();
00130 
00132     void setReadOnly(bool readOnly);
00133 
00136     bool getTrace();
00137 
00139     void setTrace(bool on);
00140 
00142     ODBCXX_STRING getTraceFile();
00143 
00145     void setTraceFile(const ODBCXX_STRING& s);
00146 
00152     DatabaseMetaData* getMetaData();
00153 
00154     
00156     Statement* createStatement();
00157 
00164     Statement* createStatement(int resultSetType,
00165                                int resultSetConcurrency);
00166     
00167     
00172     PreparedStatement* prepareStatement(const ODBCXX_STRING& sql);
00173 
00182     PreparedStatement* prepareStatement(const ODBCXX_STRING& sql,
00183                                         int resultSetType,
00184                                         int resultSetConcurrency);
00185     
00190     CallableStatement* prepareCall(const ODBCXX_STRING& sql);
00191 
00200     CallableStatement* prepareCall(const ODBCXX_STRING& sql,
00201                                    int resultSetType,
00202                                    int resultSetConcurrency);
00203 
00207     ODBCXX_STRING nativeSQL(const ODBCXX_STRING& sql);
00208   };
00209 
00210 
00211 
00212 }; // namespace odbc
00213 
00214 
00215 #endif // __ODBCXX_CONNECTION_H

Go back to the freeodbc++ homepage