Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / flat / EConnection.cxx
blob03bb821ff8441d6d41f9a98c715fcf9dd94c9a05
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include "flat/EConnection.hxx"
21 #include "flat/EDatabaseMetaData.hxx"
22 #include "flat/ECatalog.hxx"
23 #include "flat/EDriver.hxx"
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include "flat/EPreparedStatement.hxx"
26 #include "flat/EStatement.hxx"
27 #include <comphelper/extract.hxx>
28 #include <connectivity/dbexception.hxx>
30 using namespace connectivity::flat;
31 using namespace connectivity::file;
33 typedef connectivity::file::OConnection OConnection_B;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::sdbcx;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::lang;
43 OFlatConnection::OFlatConnection(ODriver* _pDriver) : OConnection(_pDriver)
44 ,m_nMaxRowsToScan(50)
45 ,m_bHeaderLine(true)
46 ,m_cFieldDelimiter(';')
47 ,m_cStringDelimiter('"')
48 ,m_cDecimalDelimiter(',')
49 ,m_cThousandDelimiter('.')
53 OFlatConnection::~OFlatConnection()
57 // XServiceInfo
59 IMPLEMENT_SERVICE_INFO(OFlatConnection, "com.sun.star.sdbc.drivers.flat.Connection", "com.sun.star.sdbc.Connection")
62 void OFlatConnection::construct(const OUString& url,const Sequence< PropertyValue >& info)
63 throw(css::sdbc::SQLException, css::uno::RuntimeException)
65 osl_atomic_increment( &m_refCount );
67 const PropertyValue *pBegin = info.getConstArray();
68 const PropertyValue *pEnd = pBegin + info.getLength();
69 for(;pBegin != pEnd;++pBegin)
71 if(pBegin->Name.equalsAscii("HeaderLine"))
72 OSL_VERIFY( pBegin->Value >>= m_bHeaderLine );
73 else if(pBegin->Name.equalsAscii("FieldDelimiter"))
75 OUString aVal;
76 OSL_VERIFY( pBegin->Value >>= aVal );
77 m_cFieldDelimiter = aVal.toChar();
79 else if(pBegin->Name.equalsAscii("StringDelimiter"))
81 OUString aVal;
82 OSL_VERIFY( pBegin->Value >>= aVal );
83 m_cStringDelimiter = aVal.toChar();
85 else if(pBegin->Name.equalsAscii("DecimalDelimiter"))
87 OUString aVal;
88 OSL_VERIFY( pBegin->Value >>= aVal );
89 m_cDecimalDelimiter = aVal.toChar();
91 else if(pBegin->Name.equalsAscii("ThousandDelimiter"))
93 OUString aVal;
94 OSL_VERIFY( pBegin->Value >>= aVal );
95 m_cThousandDelimiter = aVal.toChar();
97 else if ( pBegin->Name.equalsAscii("MaxRowScan") )
99 pBegin->Value >>= m_nMaxRowsToScan;
103 osl_atomic_decrement( &m_refCount );
104 OConnection::construct(url,info);
105 m_bShowDeleted = true; // we do not supported rows for this type
108 Reference< XDatabaseMetaData > SAL_CALL OFlatConnection::getMetaData( ) throw(SQLException, RuntimeException, std::exception)
110 ::osl::MutexGuard aGuard( m_aMutex );
111 checkDisposed(OConnection_B::rBHelper.bDisposed);
114 Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
115 if(!xMetaData.is())
117 xMetaData = new OFlatDatabaseMetaData(this);
118 m_xMetaData = xMetaData;
121 return xMetaData;
124 ::com::sun::star::uno::Reference< XTablesSupplier > OFlatConnection::createCatalog()
126 ::osl::MutexGuard aGuard( m_aMutex );
127 Reference< XTablesSupplier > xTab = m_xCatalog;
128 if(!xTab.is())
130 OFlatCatalog *pCat = new OFlatCatalog(this);
131 xTab = pCat;
132 m_xCatalog = xTab;
134 return xTab;
137 Reference< XStatement > SAL_CALL OFlatConnection::createStatement( ) throw(SQLException, RuntimeException, std::exception)
139 ::osl::MutexGuard aGuard( m_aMutex );
140 checkDisposed(OConnection_B::rBHelper.bDisposed);
142 OFlatStatement* pStmt = new OFlatStatement(this);
144 Reference< XStatement > xStmt = pStmt;
145 m_aStatements.push_back(WeakReferenceHelper(*pStmt));
146 return xStmt;
149 Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareStatement( const OUString& sql ) throw(SQLException, RuntimeException, std::exception)
151 ::osl::MutexGuard aGuard( m_aMutex );
152 checkDisposed(OConnection_B::rBHelper.bDisposed);
155 OFlatPreparedStatement* pStmt = new OFlatPreparedStatement(this);
156 Reference< XPreparedStatement > xStmt = pStmt;
157 pStmt->construct(sql);
159 m_aStatements.push_back(WeakReferenceHelper(*pStmt));
160 return xStmt;
163 Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareCall( const OUString& /*sql*/ ) throw(SQLException, RuntimeException, std::exception)
165 ::osl::MutexGuard aGuard( m_aMutex );
166 checkDisposed(OConnection_B::rBHelper.bDisposed);
168 ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );
169 return NULL;
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */