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