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() throw(SQLException); 128 public: 129 OUString getMysqlVariable(const char *varname) 130 throw(SQLException, RuntimeException); 131 132 sal_Int32 getMysqlVersion() 133 throw(SQLException, RuntimeException); 134 135 virtual void construct(const OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) 136 throw(SQLException); 137 138 OConnection(MysqlCDriver& _rDriver, sql::Driver * cppDriver); 139 virtual ~OConnection(); 140 141 void closeAllStatements () throw(SQLException); 142 143 getConnectionEncoding()144 rtl_TextEncoding getConnectionEncoding() { return m_settings.encoding; } 145 146 147 // OComponentHelper 148 virtual void SAL_CALL disposing(void); 149 150 // XInterface 151 virtual void SAL_CALL release() throw(); 152 153 // XServiceInfo 154 DECLARE_SERVICE_INFO(); 155 // XConnection 156 my_XStatementRef SAL_CALL createStatement() 157 throw(SQLException, RuntimeException); 158 159 my_XPreparedStatementRef SAL_CALL prepareStatement(const OUString& sql) 160 throw(SQLException, RuntimeException); 161 162 my_XPreparedStatementRef SAL_CALL prepareCall(const OUString& sql) 163 throw(SQLException, RuntimeException); 164 165 OUString SAL_CALL nativeSQL(const OUString& sql) 166 throw(SQLException, RuntimeException); 167 168 void SAL_CALL setAutoCommit(sal_Bool autoCommit) 169 throw(SQLException, RuntimeException); 170 171 sal_Bool SAL_CALL getAutoCommit() 172 throw(SQLException, RuntimeException); 173 174 void SAL_CALL commit() 175 throw(SQLException, RuntimeException); 176 177 void SAL_CALL rollback() 178 throw(SQLException, RuntimeException); 179 180 sal_Bool SAL_CALL isClosed() 181 throw(SQLException, RuntimeException); 182 183 my_XDatabaseMetaDataRef SAL_CALL getMetaData() 184 throw(SQLException, RuntimeException); 185 186 void SAL_CALL setReadOnly(sal_Bool readOnly) 187 throw(SQLException, RuntimeException); 188 189 sal_Bool SAL_CALL isReadOnly() 190 throw(SQLException, RuntimeException); 191 192 void SAL_CALL setCatalog(const OUString& catalog) 193 throw(SQLException, RuntimeException); 194 195 OUString SAL_CALL getCatalog() 196 throw(SQLException, RuntimeException); 197 198 void SAL_CALL setTransactionIsolation(sal_Int32 level) 199 throw(SQLException, RuntimeException); 200 201 sal_Int32 SAL_CALL getTransactionIsolation() 202 throw(SQLException, RuntimeException); 203 204 my_XNameAccessRef SAL_CALL getTypeMap() 205 throw(SQLException, RuntimeException); 206 207 void SAL_CALL setTypeMap(const my_XNameAccessRef& typeMap) 208 throw(SQLException, RuntimeException); 209 // XCloseable 210 void SAL_CALL close() 211 throw(SQLException, RuntimeException); 212 // XWarningsSupplier 213 ::com::sun::star::uno::Any SAL_CALL getWarnings() 214 throw(SQLException, RuntimeException); 215 void SAL_CALL clearWarnings() 216 throw(SQLException, RuntimeException); 217 218 // TODO: Not used 219 //sal_Int32 sdbcColumnType(OUString typeName); getConnectionSettings() const220 inline const ConnectionSettings& getConnectionSettings() const { return m_settings; } 221 ::rtl::OUString transFormPreparedStatement(const ::rtl::OUString& _sSQL); 222 223 // should we use the catalog on filebased databases isCatalogUsed() const224 inline sal_Bool isCatalogUsed() const { return m_bUseCatalog; } getUserName() const225 inline OUString getUserName() const { return m_sUser; } getDriver() const226 inline const MysqlCDriver& getDriver() const { return m_rDriver;} getTextEncoding() const227 inline rtl_TextEncoding getTextEncoding() const { return m_settings.encoding; } 228 229 }; /* OConnection */ 230 // TODO: Not used. 231 //inline OUString getPattern(OUString p) { return (p.getLength()) ? p : ASC2OU("%"); } 232 } /* mysqlc */ 233 } /* connectivity */ 234 #endif // MYSQLC_CONNECTION_HXX 235 236 /* 237 * Local variables: 238 * tab-width: 4 239 * c-basic-offset: 4 240 * End: 241 * vim600: noet sw=4 ts=4 fdm=marker 242 * vim<600: noet sw=4 ts=4 243 */ 244 245