1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef MYSQLC_CONNECTION_HXX
21 #define MYSQLC_CONNECTION_HXX
23 #include "mysqlc_subcomponent.hxx"
24 #include "mysqlc_types.hxx"
26 #include <boost/shared_ptr.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <com/sun/star/sdbc/ColumnSearch.hpp>
32 #include <com/sun/star/sdbc/ColumnValue.hpp>
33 #include <com/sun/star/sdbc/DataType.hpp>
34 #include <com/sun/star/sdbc/SQLWarning.hpp>
35 #include <com/sun/star/sdbc/XConnection.hpp>
36 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
37 #include <com/sun/star/util/XStringSubstitution.hpp>
39 #include <cppconn/driver.h>
41 #include <cppuhelper/compbase3.hxx>
42 #include <cppuhelper/weakref.hxx>
43 #include <rtl/string.hxx>
47 #define UNUSED_PARAM __attribute__((unused))
54 namespace connectivity
56 class OMetaConnection
;
57 class ODatabaseMetaData
;
61 using ::com::sun::star::sdbc::SQLWarning
;
62 using ::com::sun::star::sdbc::SQLException
;
63 using ::com::sun::star::uno::RuntimeException
;
64 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XStatement
> my_XStatementRef
;
65 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XPreparedStatement
> my_XPreparedStatementRef
;
66 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> my_XNameAccessRef
;
67 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDatabaseMetaData
> my_XDatabaseMetaDataRef
;
69 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::sdbc::XConnection
,
70 ::com::sun::star::sdbc::XWarningsSupplier
,
71 ::com::sun::star::lang::XServiceInfo
72 > OMetaConnection_BASE
;
73 struct ConnectionSettings
75 rtl_TextEncoding encoding
;
76 std::auto_ptr
<sql::Connection
> cppConnection
;
78 OUString quoteIdentifier
;
79 OUString connectionURL
;
85 typedef OMetaConnection_BASE OConnection_BASE
;
87 typedef std::vector
< ::com::sun::star::uno::WeakReferenceHelper
> OWeakRefArray
;
89 class OConnection
: public OBase_Mutex
,
90 public OConnection_BASE
,
91 public connectivity::mysqlc::OSubComponent
<OConnection
, OConnection_BASE
>
93 friend class connectivity::mysqlc::OSubComponent
<OConnection
, OConnection_BASE
>;
96 ConnectionSettings m_settings
;
99 ::com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
> m_typeMap
;
100 ::com::sun::star::uno::Reference
< com::sun::star::util::XStringSubstitution
> m_xParameterSubstitution
;
103 //====================================================================
105 //====================================================================
106 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XDatabaseMetaData
> m_xMetaData
;
108 OWeakRefArray m_aStatements
; // vector containing a list
109 // of all the Statement objects
110 // for this Connection
112 SQLWarning m_aLastWarning
; // Last SQLWarning generated by an operation
113 OUString m_aURL
; // URL of connection
114 OUString m_sUser
; // the user name
115 MysqlCDriver
& m_rDriver
; // Pointer to the owning driver object
116 sql::Driver
* cppDriver
;
119 sal_Bool m_bUseCatalog
; // should we use the catalog on filebased databases
120 sal_Bool m_bUseOldDateFormat
;
123 void buildTypeInfo() throw(SQLException
);
125 OUString
getMysqlVariable(const char *varname
)
126 throw(SQLException
, RuntimeException
);
128 sal_Int32
getMysqlVersion()
129 throw(SQLException
, RuntimeException
);
131 virtual void construct(const OUString
& url
,const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& info
)
134 OConnection(MysqlCDriver
& _rDriver
, sql::Driver
* cppDriver
);
135 virtual ~OConnection();
137 void closeAllStatements () throw(SQLException
);
140 rtl_TextEncoding
getConnectionEncoding() { return m_settings
.encoding
; }
144 virtual void SAL_CALL
disposing(void);
147 virtual void SAL_CALL
release() throw();
150 DECLARE_SERVICE_INFO();
152 my_XStatementRef SAL_CALL
createStatement()
153 throw(SQLException
, RuntimeException
);
155 my_XPreparedStatementRef SAL_CALL
prepareStatement(const OUString
& sql
)
156 throw(SQLException
, RuntimeException
);
158 my_XPreparedStatementRef SAL_CALL
prepareCall(const OUString
& sql
)
159 throw(SQLException
, RuntimeException
);
161 OUString SAL_CALL
nativeSQL(const OUString
& sql
)
162 throw(SQLException
, RuntimeException
);
164 void SAL_CALL
setAutoCommit(sal_Bool autoCommit
)
165 throw(SQLException
, RuntimeException
);
167 sal_Bool SAL_CALL
getAutoCommit()
168 throw(SQLException
, RuntimeException
);
170 void SAL_CALL
commit()
171 throw(SQLException
, RuntimeException
);
173 void SAL_CALL
rollback()
174 throw(SQLException
, RuntimeException
);
176 sal_Bool SAL_CALL
isClosed()
177 throw(SQLException
, RuntimeException
);
179 my_XDatabaseMetaDataRef SAL_CALL
getMetaData()
180 throw(SQLException
, RuntimeException
);
182 void SAL_CALL
setReadOnly(sal_Bool readOnly
)
183 throw(SQLException
, RuntimeException
);
185 sal_Bool SAL_CALL
isReadOnly()
186 throw(SQLException
, RuntimeException
);
188 void SAL_CALL
setCatalog(const OUString
& catalog
)
189 throw(SQLException
, RuntimeException
);
191 OUString SAL_CALL
getCatalog()
192 throw(SQLException
, RuntimeException
);
194 void SAL_CALL
setTransactionIsolation(sal_Int32 level
)
195 throw(SQLException
, RuntimeException
);
197 sal_Int32 SAL_CALL
getTransactionIsolation()
198 throw(SQLException
, RuntimeException
);
200 my_XNameAccessRef SAL_CALL
getTypeMap()
201 throw(SQLException
, RuntimeException
);
203 void SAL_CALL
setTypeMap(const my_XNameAccessRef
& typeMap
)
204 throw(SQLException
, RuntimeException
);
206 void SAL_CALL
close()
207 throw(SQLException
, RuntimeException
);
209 ::com::sun::star::uno::Any SAL_CALL
getWarnings()
210 throw(SQLException
, RuntimeException
);
211 void SAL_CALL
clearWarnings()
212 throw(SQLException
, RuntimeException
);
215 //sal_Int32 sdbcColumnType(OUString typeName);
216 inline const ConnectionSettings
& getConnectionSettings() const { return m_settings
; }
217 OUString
transFormPreparedStatement(const OUString
& _sSQL
);
219 // should we use the catalog on filebased databases
220 inline sal_Bool
isCatalogUsed() const { return m_bUseCatalog
; }
221 inline OUString
getUserName() const { return m_sUser
; }
222 inline const MysqlCDriver
& getDriver() const { return m_rDriver
;}
223 inline rtl_TextEncoding
getTextEncoding() const { return m_settings
.encoding
; }
227 //inline OUString getPattern(OUString p) { return (p.getLength()) ? p : ASC2OU("%"); }
230 #endif // MYSQLC_CONNECTION_HXX
237 * vim600: noet sw=4 ts=4 fdm=marker
238 * vim<600: noet sw=4 ts=4
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */