1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <flat/EPreparedStatement.hxx>
25 #include <flat/EStatement.hxx>
26 #include <connectivity/dbexception.hxx>
27 #include <sal/log.hxx>
29 using namespace connectivity::flat
;
30 using namespace connectivity::file
;
32 typedef connectivity::file::OConnection OConnection_B
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::sdbcx
;
38 using namespace ::com::sun::star::sdbc
;
41 OFlatConnection::OFlatConnection(ODriver
* _pDriver
) : OConnection(_pDriver
)
44 ,m_cFieldDelimiter(';')
45 ,m_cStringDelimiter('"')
46 ,m_cDecimalDelimiter(',')
47 ,m_cThousandDelimiter('.')
51 OFlatConnection::~OFlatConnection()
57 IMPLEMENT_SERVICE_INFO(OFlatConnection
, u
"com.sun.star.sdbc.drivers.flat.Connection"_ustr
, u
"com.sun.star.sdbc.Connection"_ustr
)
60 void OFlatConnection::construct(const OUString
& url
,const Sequence
< PropertyValue
>& info
)
62 osl_atomic_increment( &m_refCount
);
64 const PropertyValue
*pBegin
= info
.getConstArray();
65 const PropertyValue
*pEnd
= pBegin
+ info
.getLength();
66 for(;pBegin
!= pEnd
;++pBegin
)
68 if(pBegin
->Name
== "HeaderLine")
70 if( ! (pBegin
->Value
>>= m_bHeaderLine
) )
71 SAL_WARN("connectivity.flat", "construct: unable to get property HeaderLine");
73 else if(pBegin
->Name
== "FieldDelimiter")
76 if( ! (pBegin
->Value
>>= aVal
) )
77 SAL_WARN("connectivity.flat", "construct: unable to get property FieldDelimiter");
79 m_cFieldDelimiter
= aVal
.toChar();
81 else if(pBegin
->Name
== "StringDelimiter")
84 if( ! (pBegin
->Value
>>= aVal
) )
85 SAL_WARN("connectivity.flat", "construct: unable to get property StringDelimiter");
87 m_cStringDelimiter
= aVal
.toChar();
89 else if(pBegin
->Name
== "DecimalDelimiter")
92 if( ! (pBegin
->Value
>>= aVal
) )
93 SAL_WARN("connectivity.flat", "construct: unable to get property DecimalDelimiter");
95 m_cDecimalDelimiter
= aVal
.toChar();
97 else if(pBegin
->Name
== "ThousandDelimiter")
100 if( ! (pBegin
->Value
>>= aVal
) )
101 SAL_WARN("connectivity.flat", "construct: unable to get property ThousandDelimiter");
103 m_cThousandDelimiter
= aVal
.toChar();
105 else if ( pBegin
->Name
== "MaxRowScan" )
107 pBegin
->Value
>>= m_nMaxRowsToScan
;
111 osl_atomic_decrement( &m_refCount
);
112 OConnection::construct(url
,info
);
113 m_bShowDeleted
= true; // we do not supported rows for this type
116 Reference
< XDatabaseMetaData
> SAL_CALL
OFlatConnection::getMetaData( )
118 ::osl::MutexGuard
aGuard( m_aMutex
);
119 checkDisposed(OConnection_B::rBHelper
.bDisposed
);
122 Reference
< XDatabaseMetaData
> xMetaData
= m_xMetaData
;
125 xMetaData
= new OFlatDatabaseMetaData(this);
126 m_xMetaData
= xMetaData
;
132 css::uno::Reference
< XTablesSupplier
> OFlatConnection::createCatalog()
134 ::osl::MutexGuard
aGuard( m_aMutex
);
135 rtl::Reference
< connectivity::sdbcx::OCatalog
> xTab
= m_xCatalog
;
138 xTab
= new OFlatCatalog(this);
139 m_xCatalog
= xTab
.get();
144 Reference
< XStatement
> SAL_CALL
OFlatConnection::createStatement( )
146 ::osl::MutexGuard
aGuard( m_aMutex
);
147 checkDisposed(OConnection_B::rBHelper
.bDisposed
);
149 rtl::Reference
<OFlatStatement
> pStmt
= new OFlatStatement(this);
150 m_aStatements
.push_back(WeakReferenceHelper(*pStmt
));
154 Reference
< XPreparedStatement
> SAL_CALL
OFlatConnection::prepareStatement( const OUString
& sql
)
156 ::osl::MutexGuard
aGuard( m_aMutex
);
157 checkDisposed(OConnection_B::rBHelper
.bDisposed
);
159 rtl::Reference
<OFlatPreparedStatement
> pStmt
= new OFlatPreparedStatement(this);
160 pStmt
->construct(sql
);
161 m_aStatements
.push_back(WeakReferenceHelper(*pStmt
));
165 Reference
< XPreparedStatement
> SAL_CALL
OFlatConnection::prepareCall( const OUString
& /*sql*/ )
167 ::osl::MutexGuard
aGuard( m_aMutex
);
168 checkDisposed(OConnection_B::rBHelper
.bDisposed
);
170 ::dbtools::throwFeatureNotImplementedSQLException( u
"XConnection::prepareCall"_ustr
, *this );
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */