1*9b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9b5730f6SAndrew Rist * distributed with this work for additional information 6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an 15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 17*9b5730f6SAndrew Rist * specific language governing permissions and limitations 18*9b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9b5730f6SAndrew Rist *************************************************************/ 21*9b5730f6SAndrew Rist 22*9b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "flat/EConnection.hxx" 27cdf0e10cSrcweir #include "flat/EDatabaseMetaData.hxx" 28cdf0e10cSrcweir #include "flat/ECatalog.hxx" 29cdf0e10cSrcweir #ifndef _CONNECTIVITY_FLAT_ODRIVER_HXX_ 30cdf0e10cSrcweir #include "flat/EDriver.hxx" 31cdf0e10cSrcweir #endif 32cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 33cdf0e10cSrcweir #include <tools/urlobj.hxx> 34cdf0e10cSrcweir #include "flat/EPreparedStatement.hxx" 35cdf0e10cSrcweir #ifndef _CONNECTIVITY_FLAT_DSTATEMENT_HXX_ 36cdf0e10cSrcweir #include "flat/EStatement.hxx" 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir #include <comphelper/extract.hxx> 39cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir using namespace connectivity::flat; 42cdf0e10cSrcweir using namespace connectivity::file; 43cdf0e10cSrcweir 44cdf0e10cSrcweir typedef connectivity::file::OConnection OConnection_B; 45cdf0e10cSrcweir 46cdf0e10cSrcweir //------------------------------------------------------------------------------ 47cdf0e10cSrcweir using namespace ::com::sun::star::uno; 48cdf0e10cSrcweir using namespace ::com::sun::star::beans; 49cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 50cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 51cdf0e10cSrcweir using namespace ::com::sun::star::lang; 52cdf0e10cSrcweir 53cdf0e10cSrcweir // -------------------------------------------------------------------------------- 54cdf0e10cSrcweir OFlatConnection::OFlatConnection(ODriver* _pDriver) : OConnection(_pDriver) 55cdf0e10cSrcweir ,m_nMaxRowsToScan(50) 56cdf0e10cSrcweir ,m_bHeaderLine(sal_True) 57cdf0e10cSrcweir ,m_cFieldDelimiter(';') 58cdf0e10cSrcweir ,m_cStringDelimiter('"') 59cdf0e10cSrcweir ,m_cDecimalDelimiter(',') 60cdf0e10cSrcweir ,m_cThousandDelimiter('.') 61cdf0e10cSrcweir { 62cdf0e10cSrcweir } 63cdf0e10cSrcweir //----------------------------------------------------------------------------- 64cdf0e10cSrcweir OFlatConnection::~OFlatConnection() 65cdf0e10cSrcweir { 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir // XServiceInfo 69cdf0e10cSrcweir // -------------------------------------------------------------------------------- 70cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OFlatConnection, "com.sun.star.sdbc.drivers.flat.Connection", "com.sun.star.sdbc.Connection") 71cdf0e10cSrcweir 72cdf0e10cSrcweir //----------------------------------------------------------------------------- 73cdf0e10cSrcweir void OFlatConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info) throw(SQLException) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir ::rtl::OUString aExt; 78cdf0e10cSrcweir const PropertyValue *pBegin = info.getConstArray(); 79cdf0e10cSrcweir const PropertyValue *pEnd = pBegin + info.getLength(); 80cdf0e10cSrcweir for(;pBegin != pEnd;++pBegin) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir if(!pBegin->Name.compareToAscii("HeaderLine")) 83cdf0e10cSrcweir OSL_VERIFY( pBegin->Value >>= m_bHeaderLine ); 84cdf0e10cSrcweir else if(!pBegin->Name.compareToAscii("FieldDelimiter")) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir ::rtl::OUString aVal; 87cdf0e10cSrcweir OSL_VERIFY( pBegin->Value >>= aVal ); 88cdf0e10cSrcweir m_cFieldDelimiter = aVal.toChar(); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir else if(!pBegin->Name.compareToAscii("StringDelimiter")) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir ::rtl::OUString aVal; 93cdf0e10cSrcweir OSL_VERIFY( pBegin->Value >>= aVal ); 94cdf0e10cSrcweir m_cStringDelimiter = aVal.toChar(); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir else if(!pBegin->Name.compareToAscii("DecimalDelimiter")) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir ::rtl::OUString aVal; 99cdf0e10cSrcweir OSL_VERIFY( pBegin->Value >>= aVal ); 100cdf0e10cSrcweir m_cDecimalDelimiter = aVal.toChar(); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir else if(!pBegin->Name.compareToAscii("ThousandDelimiter")) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir ::rtl::OUString aVal; 105cdf0e10cSrcweir OSL_VERIFY( pBegin->Value >>= aVal ); 106cdf0e10cSrcweir m_cThousandDelimiter = aVal.toChar(); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir else if ( !pBegin->Name.compareToAscii("MaxRowScan") ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir pBegin->Value >>= m_nMaxRowsToScan; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 115cdf0e10cSrcweir OConnection::construct(url,info); 116cdf0e10cSrcweir m_bShowDeleted = sal_True; // we do not supported rows for this type 117cdf0e10cSrcweir } 118cdf0e10cSrcweir // -------------------------------------------------------------------------------- 119cdf0e10cSrcweir Reference< XDatabaseMetaData > SAL_CALL OFlatConnection::getMetaData( ) throw(SQLException, RuntimeException) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 122cdf0e10cSrcweir checkDisposed(OConnection_B::rBHelper.bDisposed); 123cdf0e10cSrcweir 124cdf0e10cSrcweir 125cdf0e10cSrcweir Reference< XDatabaseMetaData > xMetaData = m_xMetaData; 126cdf0e10cSrcweir if(!xMetaData.is()) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir xMetaData = new OFlatDatabaseMetaData(this); 129cdf0e10cSrcweir m_xMetaData = xMetaData; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir return xMetaData; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir //------------------------------------------------------------------------------ 135cdf0e10cSrcweir ::com::sun::star::uno::Reference< XTablesSupplier > OFlatConnection::createCatalog() 136cdf0e10cSrcweir { 137cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 138cdf0e10cSrcweir Reference< XTablesSupplier > xTab = m_xCatalog; 139cdf0e10cSrcweir if(!xTab.is()) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir OFlatCatalog *pCat = new OFlatCatalog(this); 142cdf0e10cSrcweir xTab = pCat; 143cdf0e10cSrcweir m_xCatalog = xTab; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir return xTab; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir // -------------------------------------------------------------------------------- 148cdf0e10cSrcweir Reference< XStatement > SAL_CALL OFlatConnection::createStatement( ) throw(SQLException, RuntimeException) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 151cdf0e10cSrcweir checkDisposed(OConnection_B::rBHelper.bDisposed); 152cdf0e10cSrcweir 153cdf0e10cSrcweir OFlatStatement* pStmt = new OFlatStatement(this); 154cdf0e10cSrcweir 155cdf0e10cSrcweir Reference< XStatement > xStmt = pStmt; 156cdf0e10cSrcweir m_aStatements.push_back(WeakReferenceHelper(*pStmt)); 157cdf0e10cSrcweir return xStmt; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir // -------------------------------------------------------------------------------- 160cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 163cdf0e10cSrcweir checkDisposed(OConnection_B::rBHelper.bDisposed); 164cdf0e10cSrcweir 165cdf0e10cSrcweir 166cdf0e10cSrcweir OFlatPreparedStatement* pStmt = new OFlatPreparedStatement(this); 167cdf0e10cSrcweir Reference< XPreparedStatement > xStmt = pStmt; 168cdf0e10cSrcweir pStmt->construct(sql); 169cdf0e10cSrcweir 170cdf0e10cSrcweir m_aStatements.push_back(WeakReferenceHelper(*pStmt)); 171cdf0e10cSrcweir return xStmt; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir // -------------------------------------------------------------------------------- 174cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 177cdf0e10cSrcweir checkDisposed(OConnection_B::rBHelper.bDisposed); 178cdf0e10cSrcweir 179cdf0e10cSrcweir ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this ); 180cdf0e10cSrcweir return NULL; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir 184