1*079eb577SAndrew Rist /**************************************************************
2*079eb577SAndrew Rist  *
3*079eb577SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*079eb577SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*079eb577SAndrew Rist  * distributed with this work for additional information
6*079eb577SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*079eb577SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*079eb577SAndrew Rist  * "License"); you may not use this file except in compliance
9*079eb577SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*079eb577SAndrew Rist  *
11*079eb577SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*079eb577SAndrew Rist  *
13*079eb577SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*079eb577SAndrew Rist  * software distributed under the License is distributed on an
15*079eb577SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*079eb577SAndrew Rist  * KIND, either express or implied.  See the License for the
17*079eb577SAndrew Rist  * specific language governing permissions and limitations
18*079eb577SAndrew Rist  * under the License.
19*079eb577SAndrew Rist  *
20*079eb577SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir #ifndef MYSQLC_CONNECTION_HXX
23cdf0e10cSrcweir #define MYSQLC_CONNECTION_HXX
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include "mysqlc_subcomponent.hxx"
26cdf0e10cSrcweir #include "mysqlc_types.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnSearch.hpp>
34cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
35cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
36cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
37cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
38cdf0e10cSrcweir #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
39cdf0e10cSrcweir #include <com/sun/star/util/XStringSubstitution.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <preextstl.h>
42cdf0e10cSrcweir #include <cppconn/driver.h>
43cdf0e10cSrcweir #include <postextstl.h>
44cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx>
45cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
46cdf0e10cSrcweir #include <rtl/string.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <map>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #define UNUSED_PARAM __attribute__((unused))
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace sql
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     class SQLException;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir namespace connectivity
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	class OMetaConnection;
60cdf0e10cSrcweir 	class ODatabaseMetaData;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	namespace mysqlc
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		using ::rtl::OUString;
65cdf0e10cSrcweir 		using ::com::sun::star::sdbc::SQLWarning;
66cdf0e10cSrcweir 		using ::com::sun::star::sdbc::SQLException;
67cdf0e10cSrcweir 		using ::com::sun::star::uno::RuntimeException;
68cdf0e10cSrcweir 		typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > my_XStatementRef;
69cdf0e10cSrcweir 		typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > my_XPreparedStatementRef;
70cdf0e10cSrcweir 		typedef ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > my_XNameAccessRef;
71cdf0e10cSrcweir 		typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > my_XDatabaseMetaDataRef;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		typedef ::cppu::WeakComponentImplHelper3<	::com::sun::star::sdbc::XConnection,
74cdf0e10cSrcweir 													::com::sun::star::sdbc::XWarningsSupplier,
75cdf0e10cSrcweir 													::com::sun::star::lang::XServiceInfo
76cdf0e10cSrcweir 												> OMetaConnection_BASE;
77cdf0e10cSrcweir 		struct ConnectionSettings
78cdf0e10cSrcweir 		{
79cdf0e10cSrcweir 			rtl_TextEncoding encoding;
80cdf0e10cSrcweir 			std::auto_ptr<sql::Connection> cppConnection;
81cdf0e10cSrcweir 			OUString schema;
82cdf0e10cSrcweir 			OUString quoteIdentifier;
83cdf0e10cSrcweir             OUString connectionURL;
84cdf0e10cSrcweir 			sal_Bool readOnly;
85cdf0e10cSrcweir 		};
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		class MysqlCDriver;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 		typedef OMetaConnection_BASE OConnection_BASE;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 		typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		class OConnection : public OBase_Mutex,
94cdf0e10cSrcweir 							public OConnection_BASE,
95cdf0e10cSrcweir 							public connectivity::mysqlc::OSubComponent<OConnection, OConnection_BASE>
96cdf0e10cSrcweir 		{
97cdf0e10cSrcweir 			friend class connectivity::mysqlc::OSubComponent<OConnection, OConnection_BASE>;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         private:
100cdf0e10cSrcweir 			ConnectionSettings  m_settings;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 		private:
103cdf0e10cSrcweir 			::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > m_typeMap;
104cdf0e10cSrcweir             ::com::sun::star::uno::Reference< com::sun::star::util::XStringSubstitution > m_xParameterSubstitution;
105cdf0e10cSrcweir 		protected:
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 			//====================================================================
108cdf0e10cSrcweir 			// Data attributes
109cdf0e10cSrcweir 			//====================================================================
110cdf0e10cSrcweir 			::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 			OWeakRefArray	m_aStatements;	// vector containing a list
113cdf0e10cSrcweir 											// of all the Statement objects
114cdf0e10cSrcweir 											// for this Connection
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 			SQLWarning	    m_aLastWarning;	// Last SQLWarning generated by an operation
117cdf0e10cSrcweir 			OUString	    m_aURL;			// URL of connection
118cdf0e10cSrcweir 			OUString	    m_sUser;		// the user name
119cdf0e10cSrcweir 			MysqlCDriver&   m_rDriver;	    // Pointer to the owning driver object
120cdf0e10cSrcweir 			sql::Driver*    cppDriver;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 			sal_Bool	m_bClosed;
123cdf0e10cSrcweir 			sal_Bool	m_bUseCatalog;	// should we use the catalog on filebased databases
124cdf0e10cSrcweir 			sal_Bool	m_bUseOldDateFormat;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 			void		buildTypeInfo() throw(SQLException);
128cdf0e10cSrcweir 		public:
129cdf0e10cSrcweir 			OUString getMysqlVariable(const char *varname)
130cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 			sal_Int32 getMysqlVersion()
133cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 			virtual void construct(const OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info)
136cdf0e10cSrcweir 																throw(SQLException);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 			OConnection(MysqlCDriver& _rDriver, sql::Driver * cppDriver);
139cdf0e10cSrcweir 			virtual ~OConnection();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 			void closeAllStatements ()							throw(SQLException);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
getConnectionEncoding()144cdf0e10cSrcweir 			rtl_TextEncoding getConnectionEncoding() { return m_settings.encoding; }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 			// OComponentHelper
148cdf0e10cSrcweir 			virtual void SAL_CALL disposing(void);
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 			// XInterface
151cdf0e10cSrcweir 			virtual void SAL_CALL release()						throw();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 			// XServiceInfo
154cdf0e10cSrcweir 			DECLARE_SERVICE_INFO();
155cdf0e10cSrcweir 			// XConnection
156cdf0e10cSrcweir 			my_XStatementRef SAL_CALL createStatement()
157cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 			my_XPreparedStatementRef SAL_CALL prepareStatement(const OUString& sql)
160cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 			my_XPreparedStatementRef SAL_CALL prepareCall(const OUString& sql)
163cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 			OUString SAL_CALL nativeSQL(const OUString& sql)
166cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 			void SAL_CALL setAutoCommit(sal_Bool autoCommit)
169cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 			sal_Bool SAL_CALL getAutoCommit()
172cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 			void SAL_CALL commit()
175cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 			void SAL_CALL rollback()
178cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 			sal_Bool SAL_CALL isClosed()
181cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 			my_XDatabaseMetaDataRef SAL_CALL getMetaData()
184cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 			void SAL_CALL setReadOnly(sal_Bool readOnly)
187cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 			sal_Bool SAL_CALL isReadOnly()
190cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 			void SAL_CALL setCatalog(const OUString& catalog)
193cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 			OUString SAL_CALL getCatalog()
196cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 			void SAL_CALL setTransactionIsolation(sal_Int32 level)
199cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 			sal_Int32 SAL_CALL getTransactionIsolation()
202cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 			my_XNameAccessRef SAL_CALL getTypeMap()
205cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 			void SAL_CALL setTypeMap(const my_XNameAccessRef& typeMap)
208cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
209cdf0e10cSrcweir 			// XCloseable
210cdf0e10cSrcweir 			void SAL_CALL close()
211cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
212cdf0e10cSrcweir 			// XWarningsSupplier
213cdf0e10cSrcweir 			::com::sun::star::uno::Any SAL_CALL getWarnings()
214cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
215cdf0e10cSrcweir 			void SAL_CALL clearWarnings()
216cdf0e10cSrcweir 																throw(SQLException, RuntimeException);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir             // TODO: Not used
219cdf0e10cSrcweir 			//sal_Int32 sdbcColumnType(OUString typeName);
getConnectionSettings() const220cdf0e10cSrcweir             inline const ConnectionSettings& getConnectionSettings() const { return m_settings; }
221cdf0e10cSrcweir             ::rtl::OUString transFormPreparedStatement(const ::rtl::OUString& _sSQL);
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 			// should we use the catalog on filebased databases
isCatalogUsed() const224cdf0e10cSrcweir             inline sal_Bool			    isCatalogUsed()     const { return m_bUseCatalog; }
getUserName() const225cdf0e10cSrcweir             inline OUString			    getUserName()       const { return m_sUser; }
getDriver() const226cdf0e10cSrcweir             inline const MysqlCDriver&  getDriver()			const { return m_rDriver;}
getTextEncoding() const227cdf0e10cSrcweir             inline rtl_TextEncoding	    getTextEncoding()	const { return m_settings.encoding; }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 		}; /* OConnection */
230cdf0e10cSrcweir         // TODO: Not used.
231cdf0e10cSrcweir 		//inline OUString getPattern(OUString p) { return (p.getLength()) ? p : ASC2OU("%"); }
232cdf0e10cSrcweir 	} /* mysqlc */
233cdf0e10cSrcweir } /* connectivity */
234cdf0e10cSrcweir #endif // MYSQLC_CONNECTION_HXX
235cdf0e10cSrcweir 
236cdf0e10cSrcweir /*
237cdf0e10cSrcweir  * Local variables:
238cdf0e10cSrcweir  * tab-width: 4
239cdf0e10cSrcweir  * c-basic-offset: 4
240cdf0e10cSrcweir  * End:
241cdf0e10cSrcweir  * vim600: noet sw=4 ts=4 fdm=marker
242cdf0e10cSrcweir  * vim<600: noet sw=4 ts=4
243cdf0e10cSrcweir  */
244cdf0e10cSrcweir 
245