1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EConnection.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "flat/EConnection.hxx"
34 #include "flat/EDatabaseMetaData.hxx"
35 #include "flat/ECatalog.hxx"
36 #ifndef _CONNECTIVITY_FLAT_ODRIVER_HXX_
37 #include "flat/EDriver.hxx"
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <tools/urlobj.hxx>
41 #include "flat/EPreparedStatement.hxx"
42 #ifndef _CONNECTIVITY_FLAT_DSTATEMENT_HXX_
43 #include "flat/EStatement.hxx"
45 #include <comphelper/extract.hxx>
46 #include <connectivity/dbexception.hxx>
48 using namespace connectivity::flat
;
49 using namespace connectivity::file
;
51 typedef connectivity::file::OConnection OConnection_B
;
53 //------------------------------------------------------------------------------
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::beans
;
56 using namespace ::com::sun::star::sdbcx
;
57 using namespace ::com::sun::star::sdbc
;
58 using namespace ::com::sun::star::lang
;
60 // --------------------------------------------------------------------------------
61 OFlatConnection::OFlatConnection(ODriver
* _pDriver
) : OConnection(_pDriver
)
62 ,m_bHeaderLine(sal_True
)
63 ,m_cFieldDelimiter(';')
64 ,m_cStringDelimiter('"')
65 ,m_cDecimalDelimiter(',')
66 ,m_cThousandDelimiter('.')
69 //-----------------------------------------------------------------------------
70 OFlatConnection::~OFlatConnection()
75 // --------------------------------------------------------------------------------
76 IMPLEMENT_SERVICE_INFO(OFlatConnection
, "com.sun.star.sdbc.drivers.flat.Connection", "com.sun.star.sdbc.Connection")
78 //-----------------------------------------------------------------------------
79 void OFlatConnection::construct(const ::rtl::OUString
& url
,const Sequence
< PropertyValue
>& info
) throw(SQLException
)
81 osl_incrementInterlockedCount( &m_refCount
);
84 const PropertyValue
*pBegin
= info
.getConstArray();
85 const PropertyValue
*pEnd
= pBegin
+ info
.getLength();
86 for(;pBegin
!= pEnd
;++pBegin
)
88 if(!pBegin
->Name
.compareToAscii("HeaderLine"))
89 OSL_VERIFY( pBegin
->Value
>>= m_bHeaderLine
);
90 else if(!pBegin
->Name
.compareToAscii("FieldDelimiter"))
93 OSL_VERIFY( pBegin
->Value
>>= aVal
);
94 m_cFieldDelimiter
= aVal
.toChar();
96 else if(!pBegin
->Name
.compareToAscii("StringDelimiter"))
99 OSL_VERIFY( pBegin
->Value
>>= aVal
);
100 m_cStringDelimiter
= aVal
.toChar();
102 else if(!pBegin
->Name
.compareToAscii("DecimalDelimiter"))
104 ::rtl::OUString aVal
;
105 OSL_VERIFY( pBegin
->Value
>>= aVal
);
106 m_cDecimalDelimiter
= aVal
.toChar();
108 else if(!pBegin
->Name
.compareToAscii("ThousandDelimiter"))
110 ::rtl::OUString aVal
;
111 OSL_VERIFY( pBegin
->Value
>>= aVal
);
112 m_cThousandDelimiter
= aVal
.toChar();
116 osl_decrementInterlockedCount( &m_refCount
);
117 OConnection::construct(url
,info
);
119 // --------------------------------------------------------------------------------
120 Reference
< XDatabaseMetaData
> SAL_CALL
OFlatConnection::getMetaData( ) throw(SQLException
, RuntimeException
)
122 ::osl::MutexGuard
aGuard( m_aMutex
);
123 checkDisposed(OConnection_B::rBHelper
.bDisposed
);
126 Reference
< XDatabaseMetaData
> xMetaData
= m_xMetaData
;
129 xMetaData
= new OFlatDatabaseMetaData(this);
130 m_xMetaData
= xMetaData
;
135 //------------------------------------------------------------------------------
136 ::com::sun::star::uno::Reference
< XTablesSupplier
> OFlatConnection::createCatalog()
138 ::osl::MutexGuard
aGuard( m_aMutex
);
139 Reference
< XTablesSupplier
> xTab
= m_xCatalog
;
142 OFlatCatalog
*pCat
= new OFlatCatalog(this);
148 // --------------------------------------------------------------------------------
149 Reference
< XStatement
> SAL_CALL
OFlatConnection::createStatement( ) throw(SQLException
, RuntimeException
)
151 ::osl::MutexGuard
aGuard( m_aMutex
);
152 checkDisposed(OConnection_B::rBHelper
.bDisposed
);
154 OFlatStatement
* pStmt
= new OFlatStatement(this);
156 Reference
< XStatement
> xStmt
= pStmt
;
157 m_aStatements
.push_back(WeakReferenceHelper(*pStmt
));
160 // --------------------------------------------------------------------------------
161 Reference
< XPreparedStatement
> SAL_CALL
OFlatConnection::prepareStatement( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
163 ::osl::MutexGuard
aGuard( m_aMutex
);
164 checkDisposed(OConnection_B::rBHelper
.bDisposed
);
167 OFlatPreparedStatement
* pStmt
= new OFlatPreparedStatement(this);
168 Reference
< XPreparedStatement
> xStmt
= pStmt
;
169 pStmt
->construct(sql
);
171 m_aStatements
.push_back(WeakReferenceHelper(*pStmt
));
174 // --------------------------------------------------------------------------------
175 Reference
< XPreparedStatement
> SAL_CALL
OFlatConnection::prepareCall( const ::rtl::OUString
& /*sql*/ ) throw(SQLException
, RuntimeException
)
177 ::osl::MutexGuard
aGuard( m_aMutex
);
178 checkDisposed(OConnection_B::rBHelper
.bDisposed
);
180 ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );