xref: /AOO41X/main/mysqlc/source/mysqlc_connection.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir *
4*cdf0e10cSrcweir * Copyright 2008 by Sun Microsystems, Inc.
5*cdf0e10cSrcweir *
6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir *
8*cdf0e10cSrcweir * $RCSfile: mysqlc_connection.hxx,v $
9*cdf0e10cSrcweir *
10*cdf0e10cSrcweir * $Revision: 1.1.2.4 $
11*cdf0e10cSrcweir *
12*cdf0e10cSrcweir * This file is part of OpenOffice.org.
13*cdf0e10cSrcweir *
14*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify
15*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3
16*cdf0e10cSrcweir * only, as published by the Free Software Foundation.
17*cdf0e10cSrcweir *
18*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful,
19*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of
20*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details
22*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code).
23*cdf0e10cSrcweir *
24*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License
25*cdf0e10cSrcweir * version 3 along with OpenOffice.org.  If not, see
26*cdf0e10cSrcweir * <http://www.openoffice.org/license.html>
27*cdf0e10cSrcweir * for a copy of the LGPLv3 License.
28*cdf0e10cSrcweir ************************************************************************/
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #ifndef MYSQLC_CONNECTION_HXX
31*cdf0e10cSrcweir #define MYSQLC_CONNECTION_HXX
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "mysqlc_subcomponent.hxx"
34*cdf0e10cSrcweir #include "mysqlc_types.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnSearch.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/util/XStringSubstitution.hpp>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <preextstl.h>
50*cdf0e10cSrcweir #include <cppconn/driver.h>
51*cdf0e10cSrcweir #include <postextstl.h>
52*cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx>
53*cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
54*cdf0e10cSrcweir #include <rtl/string.hxx>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #include <map>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #define UNUSED_PARAM __attribute__((unused))
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir namespace sql
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir     class SQLException;
63*cdf0e10cSrcweir }
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir namespace connectivity
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	class OMetaConnection;
68*cdf0e10cSrcweir 	class ODatabaseMetaData;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 	namespace mysqlc
71*cdf0e10cSrcweir 	{
72*cdf0e10cSrcweir 		using ::rtl::OUString;
73*cdf0e10cSrcweir 		using ::com::sun::star::sdbc::SQLWarning;
74*cdf0e10cSrcweir 		using ::com::sun::star::sdbc::SQLException;
75*cdf0e10cSrcweir 		using ::com::sun::star::uno::RuntimeException;
76*cdf0e10cSrcweir 		typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > my_XStatementRef;
77*cdf0e10cSrcweir 		typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > my_XPreparedStatementRef;
78*cdf0e10cSrcweir 		typedef ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > my_XNameAccessRef;
79*cdf0e10cSrcweir 		typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > my_XDatabaseMetaDataRef;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 		typedef ::cppu::WeakComponentImplHelper3<	::com::sun::star::sdbc::XConnection,
82*cdf0e10cSrcweir 													::com::sun::star::sdbc::XWarningsSupplier,
83*cdf0e10cSrcweir 													::com::sun::star::lang::XServiceInfo
84*cdf0e10cSrcweir 												> OMetaConnection_BASE;
85*cdf0e10cSrcweir 		struct ConnectionSettings
86*cdf0e10cSrcweir 		{
87*cdf0e10cSrcweir 			rtl_TextEncoding encoding;
88*cdf0e10cSrcweir 			std::auto_ptr<sql::Connection> cppConnection;
89*cdf0e10cSrcweir 			OUString schema;
90*cdf0e10cSrcweir 			OUString quoteIdentifier;
91*cdf0e10cSrcweir             OUString connectionURL;
92*cdf0e10cSrcweir 			sal_Bool readOnly;
93*cdf0e10cSrcweir 		};
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 		class MysqlCDriver;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 		typedef OMetaConnection_BASE OConnection_BASE;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 		typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 		class OConnection : public OBase_Mutex,
102*cdf0e10cSrcweir 							public OConnection_BASE,
103*cdf0e10cSrcweir 							public connectivity::mysqlc::OSubComponent<OConnection, OConnection_BASE>
104*cdf0e10cSrcweir 		{
105*cdf0e10cSrcweir 			friend class connectivity::mysqlc::OSubComponent<OConnection, OConnection_BASE>;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         private:
108*cdf0e10cSrcweir 			ConnectionSettings  m_settings;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 		private:
111*cdf0e10cSrcweir 			::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > m_typeMap;
112*cdf0e10cSrcweir             ::com::sun::star::uno::Reference< com::sun::star::util::XStringSubstitution > m_xParameterSubstitution;
113*cdf0e10cSrcweir 		protected:
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 			//====================================================================
116*cdf0e10cSrcweir 			// Data attributes
117*cdf0e10cSrcweir 			//====================================================================
118*cdf0e10cSrcweir 			::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 			OWeakRefArray	m_aStatements;	// vector containing a list
121*cdf0e10cSrcweir 											// of all the Statement objects
122*cdf0e10cSrcweir 											// for this Connection
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 			SQLWarning	    m_aLastWarning;	// Last SQLWarning generated by an operation
125*cdf0e10cSrcweir 			OUString	    m_aURL;			// URL of connection
126*cdf0e10cSrcweir 			OUString	    m_sUser;		// the user name
127*cdf0e10cSrcweir 			MysqlCDriver&   m_rDriver;	    // Pointer to the owning driver object
128*cdf0e10cSrcweir 			sql::Driver*    cppDriver;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 			sal_Bool	m_bClosed;
131*cdf0e10cSrcweir 			sal_Bool	m_bUseCatalog;	// should we use the catalog on filebased databases
132*cdf0e10cSrcweir 			sal_Bool	m_bUseOldDateFormat;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 			void		buildTypeInfo() throw(SQLException);
136*cdf0e10cSrcweir 		public:
137*cdf0e10cSrcweir 			OUString getMysqlVariable(const char *varname)
138*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 			sal_Int32 getMysqlVersion()
141*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 			virtual void construct(const OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info)
144*cdf0e10cSrcweir 																throw(SQLException);
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 			OConnection(MysqlCDriver& _rDriver, sql::Driver * cppDriver);
147*cdf0e10cSrcweir 			virtual ~OConnection();
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 			void closeAllStatements ()							throw(SQLException);
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 			rtl_TextEncoding getConnectionEncoding() { return m_settings.encoding; }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 			// OComponentHelper
156*cdf0e10cSrcweir 			virtual void SAL_CALL disposing(void);
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 			// XInterface
159*cdf0e10cSrcweir 			virtual void SAL_CALL release()						throw();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 			// XServiceInfo
162*cdf0e10cSrcweir 			DECLARE_SERVICE_INFO();
163*cdf0e10cSrcweir 			// XConnection
164*cdf0e10cSrcweir 			my_XStatementRef SAL_CALL createStatement()
165*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 			my_XPreparedStatementRef SAL_CALL prepareStatement(const OUString& sql)
168*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 			my_XPreparedStatementRef SAL_CALL prepareCall(const OUString& sql)
171*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 			OUString SAL_CALL nativeSQL(const OUString& sql)
174*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 			void SAL_CALL setAutoCommit(sal_Bool autoCommit)
177*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 			sal_Bool SAL_CALL getAutoCommit()
180*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 			void SAL_CALL commit()
183*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 			void SAL_CALL rollback()
186*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 			sal_Bool SAL_CALL isClosed()
189*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 			my_XDatabaseMetaDataRef SAL_CALL getMetaData()
192*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 			void SAL_CALL setReadOnly(sal_Bool readOnly)
195*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 			sal_Bool SAL_CALL isReadOnly()
198*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 			void SAL_CALL setCatalog(const OUString& catalog)
201*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 			OUString SAL_CALL getCatalog()
204*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 			void SAL_CALL setTransactionIsolation(sal_Int32 level)
207*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 			sal_Int32 SAL_CALL getTransactionIsolation()
210*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 			my_XNameAccessRef SAL_CALL getTypeMap()
213*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 			void SAL_CALL setTypeMap(const my_XNameAccessRef& typeMap)
216*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
217*cdf0e10cSrcweir 			// XCloseable
218*cdf0e10cSrcweir 			void SAL_CALL close()
219*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
220*cdf0e10cSrcweir 			// XWarningsSupplier
221*cdf0e10cSrcweir 			::com::sun::star::uno::Any SAL_CALL getWarnings()
222*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
223*cdf0e10cSrcweir 			void SAL_CALL clearWarnings()
224*cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir             // TODO: Not used
227*cdf0e10cSrcweir 			//sal_Int32 sdbcColumnType(OUString typeName);
228*cdf0e10cSrcweir             inline const ConnectionSettings& getConnectionSettings() const { return m_settings; }
229*cdf0e10cSrcweir             ::rtl::OUString transFormPreparedStatement(const ::rtl::OUString& _sSQL);
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 			// should we use the catalog on filebased databases
232*cdf0e10cSrcweir             inline sal_Bool			    isCatalogUsed()     const { return m_bUseCatalog; }
233*cdf0e10cSrcweir             inline OUString			    getUserName()       const { return m_sUser; }
234*cdf0e10cSrcweir             inline const MysqlCDriver&  getDriver()			const { return m_rDriver;}
235*cdf0e10cSrcweir             inline rtl_TextEncoding	    getTextEncoding()	const { return m_settings.encoding; }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 		}; /* OConnection */
238*cdf0e10cSrcweir         // TODO: Not used.
239*cdf0e10cSrcweir 		//inline OUString getPattern(OUString p) { return (p.getLength()) ? p : ASC2OU("%"); }
240*cdf0e10cSrcweir 	} /* mysqlc */
241*cdf0e10cSrcweir } /* connectivity */
242*cdf0e10cSrcweir #endif // MYSQLC_CONNECTION_HXX
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir /*
245*cdf0e10cSrcweir  * Local variables:
246*cdf0e10cSrcweir  * tab-width: 4
247*cdf0e10cSrcweir  * c-basic-offset: 4
248*cdf0e10cSrcweir  * End:
249*cdf0e10cSrcweir  * vim600: noet sw=4 ts=4 fdm=marker
250*cdf0e10cSrcweir  * vim<600: noet sw=4 ts=4
251*cdf0e10cSrcweir  */
252*cdf0e10cSrcweir 
253