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