Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / flat / EConnection.cxx
blobc84e7684b97219dfae8b11a00a9315e0afd1895c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "flat/EConnection.hxx"
30 #include "flat/EDatabaseMetaData.hxx"
31 #include "flat/ECatalog.hxx"
32 #include "flat/EDriver.hxx"
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include "flat/EPreparedStatement.hxx"
35 #include "flat/EStatement.hxx"
36 #include <comphelper/extract.hxx>
37 #include <connectivity/dbexception.hxx>
39 using namespace connectivity::flat;
40 using namespace connectivity::file;
42 typedef connectivity::file::OConnection OConnection_B;
44 //------------------------------------------------------------------------------
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::sdbcx;
48 using namespace ::com::sun::star::sdbc;
49 using namespace ::com::sun::star::lang;
51 // --------------------------------------------------------------------------------
52 OFlatConnection::OFlatConnection(ODriver* _pDriver) : OConnection(_pDriver)
53 ,m_nMaxRowsToScan(50)
54 ,m_bHeaderLine(sal_True)
55 ,m_cFieldDelimiter(';')
56 ,m_cStringDelimiter('"')
57 ,m_cDecimalDelimiter(',')
58 ,m_cThousandDelimiter('.')
61 //-----------------------------------------------------------------------------
62 OFlatConnection::~OFlatConnection()
66 // XServiceInfo
67 // --------------------------------------------------------------------------------
68 IMPLEMENT_SERVICE_INFO(OFlatConnection, "com.sun.star.sdbc.drivers.flat.Connection", "com.sun.star.sdbc.Connection")
70 //-----------------------------------------------------------------------------
71 void OFlatConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info) throw(SQLException)
73 osl_incrementInterlockedCount( &m_refCount );
75 const PropertyValue *pBegin = info.getConstArray();
76 const PropertyValue *pEnd = pBegin + info.getLength();
77 for(;pBegin != pEnd;++pBegin)
79 if(!pBegin->Name.compareToAscii("HeaderLine"))
80 OSL_VERIFY( pBegin->Value >>= m_bHeaderLine );
81 else if(!pBegin->Name.compareToAscii("FieldDelimiter"))
83 ::rtl::OUString aVal;
84 OSL_VERIFY( pBegin->Value >>= aVal );
85 m_cFieldDelimiter = aVal.toChar();
87 else if(!pBegin->Name.compareToAscii("StringDelimiter"))
89 ::rtl::OUString aVal;
90 OSL_VERIFY( pBegin->Value >>= aVal );
91 m_cStringDelimiter = aVal.toChar();
93 else if(!pBegin->Name.compareToAscii("DecimalDelimiter"))
95 ::rtl::OUString aVal;
96 OSL_VERIFY( pBegin->Value >>= aVal );
97 m_cDecimalDelimiter = aVal.toChar();
99 else if(!pBegin->Name.compareToAscii("ThousandDelimiter"))
101 ::rtl::OUString aVal;
102 OSL_VERIFY( pBegin->Value >>= aVal );
103 m_cThousandDelimiter = aVal.toChar();
105 else if ( !pBegin->Name.compareToAscii("MaxRowScan") )
107 pBegin->Value >>= m_nMaxRowsToScan;
111 osl_decrementInterlockedCount( &m_refCount );
112 OConnection::construct(url,info);
113 m_bShowDeleted = sal_True; // we do not supported rows for this type
115 // --------------------------------------------------------------------------------
116 Reference< XDatabaseMetaData > SAL_CALL OFlatConnection::getMetaData( ) throw(SQLException, RuntimeException)
118 ::osl::MutexGuard aGuard( m_aMutex );
119 checkDisposed(OConnection_B::rBHelper.bDisposed);
122 Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
123 if(!xMetaData.is())
125 xMetaData = new OFlatDatabaseMetaData(this);
126 m_xMetaData = xMetaData;
129 return xMetaData;
131 //------------------------------------------------------------------------------
132 ::com::sun::star::uno::Reference< XTablesSupplier > OFlatConnection::createCatalog()
134 ::osl::MutexGuard aGuard( m_aMutex );
135 Reference< XTablesSupplier > xTab = m_xCatalog;
136 if(!xTab.is())
138 OFlatCatalog *pCat = new OFlatCatalog(this);
139 xTab = pCat;
140 m_xCatalog = xTab;
142 return xTab;
144 // --------------------------------------------------------------------------------
145 Reference< XStatement > SAL_CALL OFlatConnection::createStatement( ) throw(SQLException, RuntimeException)
147 ::osl::MutexGuard aGuard( m_aMutex );
148 checkDisposed(OConnection_B::rBHelper.bDisposed);
150 OFlatStatement* pStmt = new OFlatStatement(this);
152 Reference< XStatement > xStmt = pStmt;
153 m_aStatements.push_back(WeakReferenceHelper(*pStmt));
154 return xStmt;
156 // --------------------------------------------------------------------------------
157 Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
159 ::osl::MutexGuard aGuard( m_aMutex );
160 checkDisposed(OConnection_B::rBHelper.bDisposed);
163 OFlatPreparedStatement* pStmt = new OFlatPreparedStatement(this);
164 Reference< XPreparedStatement > xStmt = pStmt;
165 pStmt->construct(sql);
167 m_aStatements.push_back(WeakReferenceHelper(*pStmt));
168 return xStmt;
170 // --------------------------------------------------------------------------------
171 Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException)
173 ::osl::MutexGuard aGuard( m_aMutex );
174 checkDisposed(OConnection_B::rBHelper.bDisposed);
176 ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );
177 return NULL;
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */