Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <osl/diagnose.h>
21 : : #include "file/FStatement.hxx"
22 : : #include "file/FConnection.hxx"
23 : : #include "file/FDriver.hxx"
24 : : #include "file/FResultSet.hxx"
25 : : #include <comphelper/property.hxx>
26 : : #include <comphelper/uno3.hxx>
27 : : #include <osl/thread.h>
28 : : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
29 : : #include <com/sun/star/sdbc/ResultSetType.hpp>
30 : : #include <com/sun/star/sdbc/FetchDirection.hpp>
31 : : #include <com/sun/star/lang/DisposedException.hpp>
32 : : #include <comphelper/sequence.hxx>
33 : : #include <cppuhelper/typeprovider.hxx>
34 : : #include "connectivity/dbexception.hxx"
35 : : #include "resource/file_res.hrc"
36 : : #include <algorithm>
37 : : #include <tools/debug.hxx>
38 : : #include <rtl/logfile.hxx>
39 : :
40 : : namespace connectivity
41 : : {
42 : : namespace file
43 : : {
44 : :
45 : : //------------------------------------------------------------------------------
46 : : using namespace dbtools;
47 : : using namespace com::sun::star::uno;
48 : : using namespace com::sun::star::lang;
49 : : using namespace com::sun::star::beans;
50 : : using namespace com::sun::star::sdbc;
51 : : using namespace com::sun::star::sdbcx;
52 : : using namespace com::sun::star::container;
53 : : DBG_NAME( file_OStatement_Base )
54 : :
55 : : //------------------------------------------------------------------------------
56 : 132 : OStatement_Base::OStatement_Base(OConnection* _pConnection )
57 : : :OStatement_BASE(m_aMutex)
58 : : ,::comphelper::OPropertyContainer(OStatement_BASE::rBHelper)
59 : 132 : ,m_xDBMetaData(_pConnection->getMetaData())
60 : : ,m_aParser(_pConnection->getDriver()->getFactory())
61 [ + - ][ + - ]: 264 : ,m_aSQLIterator( _pConnection, _pConnection->createCatalog()->getTables(), m_aParser, NULL )
62 : : ,m_pConnection(_pConnection)
63 : : ,m_pParseTree(NULL)
64 : : ,m_pSQLAnalyzer(NULL)
65 : : ,m_pEvaluationKeySet(NULL)
66 : : ,m_pTable(NULL)
67 : : ,m_nMaxFieldSize(0)
68 : : ,m_nMaxRows(0)
69 : : ,m_nQueryTimeOut(0)
70 : : ,m_nFetchSize(0)
71 : : ,m_nResultSetType(ResultSetType::FORWARD_ONLY)
72 : : ,m_nFetchDirection(FetchDirection::FORWARD)
73 : : ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
74 : : ,m_bEscapeProcessing(sal_True)
75 [ + - ][ + - ]: 396 : ,rBHelper(OStatement_BASE::rBHelper)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
76 : : {
77 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::OStatement_Base" );
78 : : DBG_CTOR( file_OStatement_Base, NULL );
79 : :
80 : 132 : m_pConnection->acquire();
81 : :
82 : 132 : sal_Int32 nAttrib = 0;
83 : :
84 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), PROPERTY_ID_CURSORNAME, nAttrib,&m_aCursorName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
[ + - ][ + - ]
85 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), PROPERTY_ID_MAXFIELDSIZE, nAttrib,&m_nMaxFieldSize, ::getCppuType(static_cast<sal_Int32*>(0)));
[ + - ][ + - ]
86 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), PROPERTY_ID_MAXROWS, nAttrib,&m_nMaxRows, ::getCppuType(static_cast<sal_Int32*>(0)));
[ + - ][ + - ]
87 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), PROPERTY_ID_QUERYTIMEOUT, nAttrib,&m_nQueryTimeOut, ::getCppuType(static_cast<sal_Int32*>(0)));
[ + - ][ + - ]
88 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), PROPERTY_ID_FETCHSIZE, nAttrib,&m_nFetchSize, ::getCppuType(static_cast<sal_Int32*>(0)));
[ + - ][ + - ]
89 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), PROPERTY_ID_RESULTSETTYPE, nAttrib,&m_nResultSetType, ::getCppuType(static_cast<sal_Int32*>(0)));
[ + - ][ + - ]
90 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), PROPERTY_ID_FETCHDIRECTION, nAttrib,&m_nFetchDirection, ::getCppuType(static_cast<sal_Int32*>(0)));
[ + - ][ + - ]
91 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING),PROPERTY_ID_ESCAPEPROCESSING, nAttrib,&m_bEscapeProcessing,::getCppuBooleanType());
[ + - ][ + - ]
92 : :
93 [ + - ][ + - ]: 132 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY, nAttrib,&m_nResultSetConcurrency, ::getCppuType(static_cast<sal_Int32*>(0)));
[ + - ][ + - ]
94 : 132 : }
95 : : // -----------------------------------------------------------------------------
96 [ + - ][ + - ]: 132 : OStatement_Base::~OStatement_Base()
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
97 : : {
98 [ + - ]: 132 : osl_incrementInterlockedCount( &m_refCount );
99 [ + - ]: 132 : disposing();
100 [ + + ][ + - ]: 132 : delete m_pSQLAnalyzer;
101 : :
102 : : DBG_DTOR( file_OStatement_Base, NULL );
103 [ - + ]: 132 : }
104 : : //------------------------------------------------------------------------------
105 : 132 : void OStatement_Base::disposeResultSet()
106 : : {
107 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::disposeResultSet" );
108 : : // free the cursor if alive
109 [ + - ][ + - ]: 132 : Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY);
110 [ - + ]: 132 : if (xComp.is())
111 [ # # ][ # # ]: 0 : xComp->dispose();
112 [ + - ]: 132 : m_xResultSet = Reference< XResultSet>();
113 : 132 : }
114 : : //------------------------------------------------------------------------------
115 : 132 : void OStatement_BASE2::disposing()
116 : : {
117 [ + - ]: 132 : ::osl::MutexGuard aGuard(m_aMutex);
118 : :
119 [ + - ]: 132 : disposeResultSet();
120 : :
121 [ + + ]: 132 : if(m_pSQLAnalyzer)
122 [ + - ]: 88 : m_pSQLAnalyzer->dispose();
123 : :
124 [ + + ]: 132 : if(m_aRow.is())
125 : : {
126 : 88 : m_aRow->get().clear();
127 [ + - ]: 88 : m_aRow = NULL;
128 : : }
129 : :
130 [ + - ]: 132 : m_aSQLIterator.dispose();
131 : :
132 [ + + ]: 132 : if(m_pTable)
133 : : {
134 : 88 : m_pTable->release();
135 : 88 : m_pTable = NULL;
136 : : }
137 : :
138 [ + - ]: 132 : if (m_pConnection)
139 : : {
140 : 132 : m_pConnection->release();
141 : 132 : m_pConnection = NULL;
142 : : }
143 : :
144 [ + - ]: 132 : dispose_ChildImpl();
145 : :
146 [ + - ]: 132 : if ( m_pParseTree )
147 : : {
148 [ + - ][ + - ]: 132 : delete m_pParseTree;
149 : 132 : m_pParseTree = NULL;
150 : : }
151 : :
152 [ + - ][ + - ]: 132 : OStatement_Base::disposing();
153 : 132 : }
154 : : // -----------------------------------------------------------------------------
155 : 3034 : void SAL_CALL OStatement_Base::acquire() throw()
156 : : {
157 : 3034 : OStatement_BASE::acquire();
158 : 3034 : }
159 : : //-----------------------------------------------------------------------------
160 : 3034 : void SAL_CALL OStatement_BASE2::release() throw()
161 : : {
162 : 3034 : relase_ChildImpl();
163 : 3034 : }
164 : : //-----------------------------------------------------------------------------
165 : 1244 : Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
166 : : {
167 : : //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::queryInterface" );
168 [ + - ]: 1244 : const Any aRet = OStatement_BASE::queryInterface(rType);
169 [ + + ][ + - ]: 1244 : return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
170 : : }
171 : : // -------------------------------------------------------------------------
172 : 0 : Sequence< Type > SAL_CALL OStatement_Base::getTypes( ) throw(RuntimeException)
173 : : {
174 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::getTypes" );
175 [ # # ]: 0 : ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
176 [ # # ]: 0 : ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
177 [ # # ][ # # ]: 0 : ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
[ # # ][ # # ]
178 : :
179 [ # # ][ # # ]: 0 : return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes());
[ # # ][ # # ]
[ # # ][ # # ]
180 : : }
181 : : // -------------------------------------------------------------------------
182 : :
183 : 0 : void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException)
184 : : {
185 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::cancel" );
186 : 0 : }
187 : : // -------------------------------------------------------------------------
188 : :
189 : 22 : void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException)
190 : : {
191 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::close" );
192 : : {
193 [ + - ]: 22 : ::osl::MutexGuard aGuard( m_aMutex );
194 [ + - ][ + - ]: 22 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
195 : : }
196 : 22 : dispose();
197 : 22 : }
198 : : // -------------------------------------------------------------------------
199 : :
200 : 0 : void OStatement_Base::reset() throw (SQLException)
201 : : {
202 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::reset" );
203 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
204 [ # # ]: 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
205 : :
206 : :
207 [ # # ]: 0 : clearWarnings ();
208 : :
209 [ # # ][ # # ]: 0 : if (m_xResultSet.get().is())
210 [ # # ][ # # ]: 0 : clearMyResultSet();
211 : 0 : }
212 : : //--------------------------------------------------------------------
213 : : // clearMyResultSet
214 : : // If a ResultSet was created for this Statement, close it
215 : : //--------------------------------------------------------------------
216 : :
217 : 198 : void OStatement_Base::clearMyResultSet () throw (SQLException)
218 : : {
219 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::clearMyResultSet " );
220 [ + - ]: 198 : ::osl::MutexGuard aGuard( m_aMutex );
221 [ + - ]: 198 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
222 : :
223 : : try
224 : : {
225 : 198 : Reference<XCloseable> xCloseable;
226 [ + - ][ + + ]: 198 : if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) )
[ + - ]
227 [ + - ][ + - ]: 198 : xCloseable->close();
[ # # ]
228 : : }
229 [ # # ]: 0 : catch( const DisposedException& ) { }
230 : :
231 [ + - ][ + - ]: 198 : m_xResultSet = Reference< XResultSet>();
232 : 198 : }
233 : :
234 : : // -------------------------------------------------------------------------
235 : 0 : Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException)
236 : : {
237 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::getWarnings" );
238 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
239 [ # # ]: 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
240 : :
241 [ # # ][ # # ]: 0 : return makeAny(m_aLastWarning);
242 : : }
243 : : // -------------------------------------------------------------------------
244 : 0 : void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException)
245 : : {
246 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::clearWarnings" );
247 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
248 [ # # ]: 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
249 : :
250 [ # # ][ # # ]: 0 : m_aLastWarning = SQLWarning();
[ # # ][ # # ]
251 : 0 : }
252 : : // -------------------------------------------------------------------------
253 : 62 : ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const
254 : : {
255 : : //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::createArrayHelper" );
256 [ + - ]: 62 : Sequence< Property > aProps;
257 [ + - ]: 62 : describeProperties(aProps);
258 [ + - ][ + - ]: 62 : return new ::cppu::OPropertyArrayHelper(aProps);
259 : : }
260 : :
261 : : // -------------------------------------------------------------------------
262 : 466 : ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper()
263 : : {
264 : : //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::getInfoHelper" );
265 : 466 : return *const_cast<OStatement_Base*>(this)->getArrayHelper();
266 : : }
267 : : // -------------------------------------------------------------------------
268 : 0 : OResultSet* OStatement::createResultSet()
269 : : {
270 [ # # ]: 0 : return new OResultSet(this,m_aSQLIterator);
271 : : }
272 : : // -------------------------------------------------------------------------
273 [ # # ][ # # ]: 0 : IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbc.driver.file.Statement","com.sun.star.sdbc.Statement");
[ # # ][ # # ]
[ # # ][ # # ]
274 : : // -----------------------------------------------------------------------------
275 : 484 : void SAL_CALL OStatement::acquire() throw()
276 : : {
277 : 484 : OStatement_BASE2::acquire();
278 : 484 : }
279 : : // -----------------------------------------------------------------------------
280 : 484 : void SAL_CALL OStatement::release() throw()
281 : : {
282 : 484 : OStatement_BASE2::release();
283 : 484 : }
284 : : // -----------------------------------------------------------------------------
285 : : // -------------------------------------------------------------------------
286 : 0 : sal_Bool SAL_CALL OStatement::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
287 : : {
288 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
289 : :
290 [ # # ]: 0 : executeQuery(sql);
291 : :
292 [ # # ]: 0 : return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT;
293 : : }
294 : :
295 : : // -------------------------------------------------------------------------
296 : :
297 : 22 : Reference< XResultSet > SAL_CALL OStatement::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
298 : : {
299 [ + - ]: 22 : ::osl::MutexGuard aGuard( m_aMutex );
300 [ + - ]: 22 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
301 : :
302 [ - + ]: 22 : construct(sql);
303 : 0 : Reference< XResultSet > xRS;
304 [ # # ]: 0 : OResultSet* pResult = createResultSet();
305 [ # # ][ # # ]: 0 : xRS = pResult;
306 [ # # ]: 0 : initializeResultSet(pResult);
307 [ # # ][ # # ]: 0 : m_xResultSet = Reference<XResultSet>(pResult);
[ # # ]
308 : :
309 [ # # ]: 0 : pResult->OpenImpl();
310 : :
311 [ # # ]: 22 : return xRS;
312 : : }
313 : : // -------------------------------------------------------------------------
314 : 0 : Reference< XConnection > SAL_CALL OStatement::getConnection( ) throw(SQLException, RuntimeException)
315 : : {
316 [ # # ]: 0 : return (Reference< XConnection >)m_pConnection;
317 : : }
318 : : // -------------------------------------------------------------------------
319 : 0 : sal_Int32 SAL_CALL OStatement::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
320 : : {
321 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
322 [ # # ]: 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
323 : :
324 : :
325 [ # # ]: 0 : construct(sql);
326 [ # # ]: 0 : OResultSet* pResult = createResultSet();
327 [ # # ][ # # ]: 0 : Reference< XResultSet > xRS = pResult;
328 [ # # ]: 0 : initializeResultSet(pResult);
329 [ # # ]: 0 : pResult->OpenImpl();
330 : :
331 [ # # ]: 0 : return pResult->getRowCountResult();
332 : : }
333 : :
334 : : // -----------------------------------------------------------------------------
335 : 264 : void SAL_CALL OStatement_Base::disposing(void)
336 : : {
337 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::disposing" );
338 [ + + ]: 264 : if(m_aEvaluateRow.is())
339 : : {
340 : 88 : m_aEvaluateRow->get().clear();
341 : 88 : m_aEvaluateRow = NULL;
342 : : }
343 [ - + ]: 264 : delete m_pEvaluationKeySet;
344 : 264 : OStatement_BASE::disposing();
345 : 264 : }
346 : : // -----------------------------------------------------------------------------
347 : 40 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo( ) throw(RuntimeException)
348 : : {
349 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::getPropertySetInfo" );
350 : 40 : return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
351 : : }
352 : : // -----------------------------------------------------------------------------
353 : 198 : Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException)
354 : : {
355 [ + - ]: 198 : Any aRet = OStatement_XStatement::queryInterface( rType);
356 [ + + ][ + - ]: 198 : return aRet.hasValue() ? aRet : OStatement_BASE2::queryInterface( rType);
357 : : }
358 : : // -----------------------------------------------------------------------------
359 : 88 : OSQLAnalyzer* OStatement_Base::createAnalyzer()
360 : : {
361 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::createAnalyzer" );
362 [ + - ]: 88 : return new OSQLAnalyzer(m_pConnection);
363 : : }
364 : : // -----------------------------------------------------------------------------
365 : 88 : void OStatement_Base::anylizeSQL()
366 : : {
367 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::anylizeSQL" );
368 : : OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::anylizeSQL: Analyzer isn't set!");
369 : : // start analysing the statement
370 : 88 : m_pSQLAnalyzer->setOrigColumns(m_xColNames);
371 : 88 : m_pSQLAnalyzer->start(m_pParseTree);
372 : :
373 : 88 : const OSQLParseNode* pOrderbyClause = m_aSQLIterator.getOrderTree();
374 [ + + ]: 88 : if(pOrderbyClause)
375 : : {
376 : 2 : OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2);
377 : : OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Fehler im Parse Tree");
378 : :
379 [ + + ]: 4 : for (sal_uInt32 m = 0; m < pOrderingSpecCommalist->count(); m++)
380 : : {
381 : 2 : OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m);
382 : : OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Fehler im Parse Tree");
383 : : OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Fehler im Parse Tree");
384 : :
385 : 2 : OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0);
386 [ - + ][ - + ]: 2 : if(!SQL_ISRULE(pColumnRef,column_ref))
[ + - ]
387 : : {
388 [ # # ]: 0 : throw SQLException();
389 : : }
390 : 2 : OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1);
391 : 2 : setOrderbyColumn(pColumnRef,pAscendingDescending);
392 : : }
393 : : }
394 : 88 : }
395 : : //------------------------------------------------------------------
396 : 2 : void OStatement_Base::setOrderbyColumn( OSQLParseNode* pColumnRef,
397 : : OSQLParseNode* pAscendingDescending)
398 : : {
399 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::setOrderbyColumn" );
400 : 2 : ::rtl::OUString aColumnName;
401 [ - + ]: 2 : if (pColumnRef->count() == 1)
402 [ # # ]: 0 : aColumnName = pColumnRef->getChild(0)->getTokenValue();
403 [ + - ]: 2 : else if (pColumnRef->count() == 3)
404 : : {
405 [ + - ][ + - ]: 2 : pColumnRef->getChild(2)->parseNodeToStr( aColumnName, getOwnConnection(), NULL, sal_False, sal_False );
[ + - ][ + - ]
406 : : }
407 : : else
408 : : {
409 [ # # ]: 0 : throw SQLException();
410 : : }
411 : :
412 [ + - ]: 2 : Reference<XColumnLocate> xColLocate(m_xColNames,UNO_QUERY);
413 [ - + ]: 2 : if(!xColLocate.is())
414 : 2 : return;
415 : : // Everything tested and we have the name of the Column.
416 : : // What number is the Column?
417 [ + - ]: 2 : ::rtl::Reference<OSQLColumns> aSelectColumns = m_aSQLIterator.getSelectColumns();
418 : 2 : ::comphelper::UStringMixEqual aCase;
419 [ + - ][ + - ]: 2 : OSQLColumns::Vector::const_iterator aFind = ::connectivity::find(aSelectColumns->get().begin(),aSelectColumns->get().end(),aColumnName,aCase);
[ + - ]
420 [ + - ][ - + ]: 2 : if ( aFind == aSelectColumns->get().end() )
421 [ # # ]: 0 : throw SQLException();
422 [ + - ][ + - ]: 2 : m_aOrderbyColumnNumber.push_back((aFind - aSelectColumns->get().begin()) + 1);
423 : :
424 : : // Ascending or Descending?
425 [ - + ][ # # ]: 2 : m_aOrderbyAscending.push_back((SQL_ISTOKEN(pAscendingDescending,DESC)) ? SQL_DESC : SQL_ASC);
[ + - ][ + - ]
[ - + ][ + - ]
426 : : }
427 : :
428 : : // -----------------------------------------------------------------------------
429 : 132 : void OStatement_Base::construct(const ::rtl::OUString& sql) throw(SQLException, RuntimeException)
430 : : {
431 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::construct" );
432 : 132 : ::rtl::OUString aErr;
433 [ + - ]: 132 : m_pParseTree = m_aParser.parseTree(aErr,sql);
434 [ + - ]: 132 : if(m_pParseTree)
435 : : {
436 [ + - ]: 132 : m_aSQLIterator.setParseTree(m_pParseTree);
437 [ + - ]: 132 : m_aSQLIterator.traverseAll();
438 [ + - ]: 132 : const OSQLTables& xTabs = m_aSQLIterator.getTables();
439 : :
440 : : // sanity checks
441 [ + + ]: 132 : if ( xTabs.empty() )
442 : : // no tables -> nothing to operate on -> error
443 [ + - ][ - + ]: 44 : m_pConnection->throwGenericSQLException(STR_QUERY_NO_TABLE,*this);
444 : :
445 [ + - ][ - + ]: 88 : if ( xTabs.size() > 1 || m_aSQLIterator.hasErrors() )
[ - + ]
446 : : // more than one table -> can't operate on them -> error
447 [ # # ][ # # ]: 0 : m_pConnection->throwGenericSQLException(STR_QUERY_MORE_TABLES,*this);
448 : :
449 [ + - ][ + - ]: 88 : if ( (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT) && m_aSQLIterator.getSelectColumns()->get().empty() )
[ - + ][ + - ]
[ + - ]
[ - + # # ]
450 : : // SELECT statement without columns -> error
451 [ # # ][ # # ]: 0 : m_pConnection->throwGenericSQLException(STR_QUERY_NO_COLUMN,*this);
452 : :
453 [ - + ]: 88 : switch(m_aSQLIterator.getStatementType())
454 : : {
455 : : case SQL_STATEMENT_CREATE_TABLE:
456 : : case SQL_STATEMENT_ODBC_CALL:
457 : : case SQL_STATEMENT_UNKNOWN:
458 [ # # ][ # # ]: 0 : m_pConnection->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,*this);
459 : 0 : break;
460 : : default:
461 : 88 : break;
462 : : }
463 : :
464 : : // at this moment we support only one table per select statement
465 [ + - ]: 88 : Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(xTabs.begin()->second,UNO_QUERY);
466 [ + - ]: 88 : if(xTunnel.is())
467 : : {
468 [ - + ]: 88 : if(m_pTable)
469 : 0 : m_pTable->release();
470 [ + - ][ + - ]: 88 : m_pTable = reinterpret_cast<OFileTable*>(xTunnel->getSomething(OFileTable::getUnoTunnelImplementationId()));
[ + - ][ + - ]
471 [ + - ]: 88 : if(m_pTable)
472 : 88 : m_pTable->acquire();
473 : : }
474 : : OSL_ENSURE(m_pTable,"No table!");
475 [ + - ]: 88 : if ( m_pTable )
476 [ + - ][ + - ]: 88 : m_xColNames = m_pTable->getColumns();
477 [ + - ]: 88 : Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY);
478 : : // set the binding of the resultrow
479 [ + - ][ + - ]: 88 : m_aRow = new OValueRefVector(xNames->getCount());
[ + - ][ + - ]
480 : 88 : (m_aRow->get())[0]->setBound(sal_True);
481 [ + - ][ + - ]: 88 : ::std::for_each(m_aRow->get().begin()+1,m_aRow->get().end(),TSetRefBound(sal_False));
482 : :
483 : : // set the binding of the resultrow
484 [ + - ][ + - ]: 88 : m_aEvaluateRow = new OValueRefVector(xNames->getCount());
[ + - ][ + - ]
485 : :
486 : 88 : (m_aEvaluateRow->get())[0]->setBound(sal_True);
487 [ + - ][ + - ]: 88 : ::std::for_each(m_aEvaluateRow->get().begin()+1,m_aEvaluateRow->get().end(),TSetRefBound(sal_False));
488 : :
489 : : // set the select row
490 [ + - ][ + - ]: 88 : m_aSelectRow = new OValueRefVector(m_aSQLIterator.getSelectColumns()->get().size());
[ + - ][ + - ]
491 [ + - ]: 88 : ::std::for_each(m_aSelectRow->get().begin(),m_aSelectRow->get().end(),TSetRefBound(sal_True));
492 : :
493 : : // create the column mapping
494 [ + - ]: 88 : createColumnMapping();
495 : :
496 [ + - ]: 88 : m_pSQLAnalyzer = createAnalyzer();
497 : :
498 [ + - ]: 88 : Reference<XIndexesSupplier> xIndexSup(xTunnel,UNO_QUERY);
499 [ + - ]: 88 : if(xIndexSup.is())
500 [ + - ][ + - ]: 88 : m_pSQLAnalyzer->setIndexes(xIndexSup->getIndexes());
[ + - ]
501 : :
502 [ + - ]: 132 : anylizeSQL();
503 : : }
504 : : else
505 [ # # ][ # # ]: 132 : throw SQLException(aErr,*this,::rtl::OUString(),0,Any());
506 : 88 : }
507 : : // -----------------------------------------------------------------------------
508 : 88 : void OStatement_Base::createColumnMapping()
509 : : {
510 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::createColumnMapping" );
511 : : // initialize the column index map (mapping select columns to table columns)
512 [ + - ]: 88 : ::rtl::Reference<connectivity::OSQLColumns> xColumns = m_aSQLIterator.getSelectColumns();
513 [ + - ]: 88 : m_aColMapping.resize(xColumns->get().size() + 1);
514 [ + + ]: 1192 : for (sal_Int32 i=0; i<(sal_Int32)m_aColMapping.size(); ++i)
515 [ + - ]: 1104 : m_aColMapping[i] = i;
516 : :
517 [ + - ]: 88 : Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY);
518 : : // now check which columns are bound
519 [ + - ][ + - ]: 88 : OResultSet::setBoundedColumns(m_aRow,m_aSelectRow,xColumns,xNames,sal_True,m_xDBMetaData,m_aColMapping);
520 : 88 : }
521 : : // -----------------------------------------------------------------------------
522 : 88 : void OStatement_Base::initializeResultSet(OResultSet* _pResult)
523 : : {
524 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::initializeResultSet" );
525 : 88 : GetAssignValues();
526 : :
527 : 88 : _pResult->setSqlAnalyzer(m_pSQLAnalyzer);
528 : 88 : _pResult->setOrderByColumns(m_aOrderbyColumnNumber);
529 : 88 : _pResult->setOrderByAscending(m_aOrderbyAscending);
530 : 88 : _pResult->setBindingRow(m_aRow);
531 : 88 : _pResult->setColumnMapping(m_aColMapping);
532 : 88 : _pResult->setEvaluationRow(m_aEvaluateRow);
533 : 88 : _pResult->setAssignValues(m_aAssignValues);
534 : 88 : _pResult->setSelectRow(m_aSelectRow);
535 : :
536 : 88 : m_pSQLAnalyzer->bindSelectRow(m_aRow);
537 : 88 : m_pEvaluationKeySet = m_pSQLAnalyzer->bindEvaluationRow(m_aEvaluateRow); // Set values in the code of the Compiler
538 : 88 : _pResult->setEvaluationKeySet(m_pEvaluationKeySet);
539 : 88 : }
540 : : // -----------------------------------------------------------------------------
541 : 88 : void OStatement_Base::GetAssignValues()
542 : : {
543 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::GetAssignValues" );
544 [ - + ]: 88 : if (m_pParseTree == NULL)
545 : : {
546 [ # # ][ # # ]: 0 : ::dbtools::throwFunctionSequenceException(*this);
547 : 0 : return;
548 : : }
549 : :
550 [ + - ][ + - ]: 88 : if (SQL_ISRULE(m_pParseTree,select_statement))
[ + - ]
551 : : // no values have to be set for SELECT
552 : 88 : return;
553 [ # # ][ # # ]: 0 : else if (SQL_ISRULE(m_pParseTree,insert_statement))
[ # # ]
554 : : {
555 : : // Create Row for the values to be set (Reference trough new)
556 [ # # ]: 0 : if(m_aAssignValues.is())
557 : 0 : m_aAssignValues->get().clear();
558 [ # # ][ # # ]: 0 : sal_Int32 nCount = Reference<XIndexAccess>(m_xColNames,UNO_QUERY)->getCount();
[ # # ]
559 [ # # ][ # # ]: 0 : m_aAssignValues = new OAssignValues(nCount);
560 : : // unbound all
561 [ # # ][ # # ]: 0 : ::std::for_each(m_aAssignValues->get().begin()+1,m_aAssignValues->get().end(),TSetRefBound(sal_False));
562 : :
563 [ # # ]: 0 : m_aParameterIndexes.resize(nCount+1,SQL_NO_PARAMETER);
564 : :
565 : : // List of Column-Names, that exist in the column_commalist (seperated by ;):
566 [ # # ]: 0 : ::std::vector<String> aColumnNameList;
567 : :
568 : : OSL_ENSURE(m_pParseTree->count() >= 4,"OResultSet: Fehler im Parse Tree");
569 : :
570 [ # # ]: 0 : OSQLParseNode * pOptColumnCommalist = m_pParseTree->getChild(3);
571 : : OSL_ENSURE(pOptColumnCommalist != NULL,"OResultSet: Fehler im Parse Tree");
572 : : OSL_ENSURE(SQL_ISRULE(pOptColumnCommalist,opt_column_commalist),"OResultSet: Fehler im Parse Tree");
573 [ # # ]: 0 : if (pOptColumnCommalist->count() == 0)
574 : : {
575 [ # # ][ # # ]: 0 : const Sequence< ::rtl::OUString>& aNames = m_xColNames->getElementNames();
576 : 0 : const ::rtl::OUString* pBegin = aNames.getConstArray();
577 : 0 : const ::rtl::OUString* pEnd = pBegin + aNames.getLength();
578 [ # # ]: 0 : for (; pBegin != pEnd; ++pBegin)
579 [ # # ][ # # ]: 0 : aColumnNameList.push_back(*pBegin);
[ # # ][ # # ]
580 : : }
581 : : else
582 : : {
583 : : OSL_ENSURE(pOptColumnCommalist->count() == 3,"OResultSet: Fehler im Parse Tree");
584 : :
585 [ # # ]: 0 : OSQLParseNode * pColumnCommalist = pOptColumnCommalist->getChild(1);
586 : : OSL_ENSURE(pColumnCommalist != NULL,"OResultSet: Fehler im Parse Tree");
587 : : OSL_ENSURE(SQL_ISRULE(pColumnCommalist,column_commalist),"OResultSet: Fehler im Parse Tree");
588 : : OSL_ENSURE(pColumnCommalist->count() > 0,"OResultSet: Fehler im Parse Tree");
589 : :
590 : : // All Columns in the column_commalist ...
591 [ # # ]: 0 : for (sal_uInt32 i = 0; i < pColumnCommalist->count(); i++)
592 : : {
593 [ # # ]: 0 : OSQLParseNode * pCol = pColumnCommalist->getChild(i);
594 : : OSL_ENSURE(pCol != NULL,"OResultSet: Fehler im Parse Tree");
595 [ # # ][ # # ]: 0 : aColumnNameList.push_back(pCol->getTokenValue());
[ # # ]
596 : : }
597 : : }
598 [ # # ]: 0 : if ( aColumnNameList.empty() )
599 [ # # ][ # # ]: 0 : throwFunctionSequenceException(*this);
600 : :
601 : : // Values ...
602 [ # # ]: 0 : OSQLParseNode * pValuesOrQuerySpec = m_pParseTree->getChild(4);
603 : : OSL_ENSURE(pValuesOrQuerySpec != NULL,"OResultSet: pValuesOrQuerySpec darf nicht NULL sein!");
604 : : OSL_ENSURE(SQL_ISRULE(pValuesOrQuerySpec,values_or_query_spec),"OResultSet: ! SQL_ISRULE(pValuesOrQuerySpec,values_or_query_spec)");
605 : : OSL_ENSURE(pValuesOrQuerySpec->count() > 0,"OResultSet: pValuesOrQuerySpec->count() <= 0");
606 : :
607 : : // just "VALUES" is allowed ...
608 [ # # ][ # # ]: 0 : if (! SQL_ISTOKEN(pValuesOrQuerySpec->getChild(0),VALUES))
[ # # ][ # # ]
[ # # ]
609 [ # # ][ # # ]: 0 : throwFunctionSequenceException(*this);
610 : :
611 : : OSL_ENSURE(pValuesOrQuerySpec->count() == 4,"OResultSet: pValuesOrQuerySpec->count() != 4");
612 : :
613 : : // List of values
614 [ # # ]: 0 : OSQLParseNode * pInsertAtomCommalist = pValuesOrQuerySpec->getChild(2);
615 : : OSL_ENSURE(pInsertAtomCommalist != NULL,"OResultSet: pInsertAtomCommalist darf nicht NULL sein!");
616 : : OSL_ENSURE(pInsertAtomCommalist->count() > 0,"OResultSet: pInsertAtomCommalist <= 0");
617 : :
618 [ # # ]: 0 : String aColumnName;
619 : : OSQLParseNode * pRow_Value_Const;
620 : 0 : xub_StrLen nIndex=0;
621 [ # # ]: 0 : for (sal_uInt32 i = 0; i < pInsertAtomCommalist->count(); i++)
622 : : {
623 [ # # ]: 0 : pRow_Value_Const = pInsertAtomCommalist->getChild(i); // row_value_constructor
624 : : OSL_ENSURE(pRow_Value_Const != NULL,"OResultSet: pRow_Value_Const darf nicht NULL sein!");
625 [ # # ][ # # ]: 0 : if(SQL_ISRULE(pRow_Value_Const,parameter))
[ # # ][ # # ]
626 : : {
627 [ # # ]: 0 : ParseAssignValues(aColumnNameList,pRow_Value_Const,nIndex++); // only one Columnname allowed per loop
628 : : }
629 [ # # ]: 0 : else if(pRow_Value_Const->isToken())
630 [ # # ]: 0 : ParseAssignValues(aColumnNameList,pRow_Value_Const,static_cast<xub_StrLen>(i));
631 : : else
632 : : {
633 [ # # ]: 0 : if(pRow_Value_Const->count() == aColumnNameList.size())
634 : : {
635 [ # # ]: 0 : for (sal_uInt32 j = 0; j < pRow_Value_Const->count(); ++j)
636 [ # # ][ # # ]: 0 : ParseAssignValues(aColumnNameList,pRow_Value_Const->getChild(j),nIndex++);
637 : : }
638 : : else
639 [ # # ][ # # ]: 0 : throwFunctionSequenceException(*this);
640 : : }
641 [ # # ]: 0 : }
642 : : }
643 [ # # ][ # # ]: 0 : else if (SQL_ISRULE(m_pParseTree,update_statement_searched))
[ # # ]
644 : : {
645 [ # # ]: 0 : if(m_aAssignValues.is())
646 : 0 : m_aAssignValues->get().clear();
647 [ # # ][ # # ]: 0 : sal_Int32 nCount = Reference<XIndexAccess>(m_xColNames,UNO_QUERY)->getCount();
[ # # ]
648 [ # # ][ # # ]: 0 : m_aAssignValues = new OAssignValues(nCount);
649 : : // unbound all
650 [ # # ][ # # ]: 0 : ::std::for_each(m_aAssignValues->get().begin()+1,m_aAssignValues->get().end(),TSetRefBound(sal_False));
651 : :
652 [ # # ]: 0 : m_aParameterIndexes.resize(nCount+1,SQL_NO_PARAMETER);
653 : :
654 : : OSL_ENSURE(m_pParseTree->count() >= 4,"OResultSet: Fehler im Parse Tree");
655 : :
656 [ # # ]: 0 : OSQLParseNode * pAssignmentCommalist = m_pParseTree->getChild(3);
657 : : OSL_ENSURE(pAssignmentCommalist != NULL,"OResultSet: pAssignmentCommalist == NULL");
658 : : OSL_ENSURE(SQL_ISRULE(pAssignmentCommalist,assignment_commalist),"OResultSet: Fehler im Parse Tree");
659 : : OSL_ENSURE(pAssignmentCommalist->count() > 0,"OResultSet: pAssignmentCommalist->count() <= 0");
660 : :
661 : : // work on all assignments (commalist) ...
662 [ # # ]: 0 : ::std::vector< String> aList(1);
663 [ # # ]: 0 : for (sal_uInt32 i = 0; i < pAssignmentCommalist->count(); i++)
664 : : {
665 [ # # ]: 0 : OSQLParseNode * pAssignment = pAssignmentCommalist->getChild(i);
666 : : OSL_ENSURE(pAssignment != NULL,"OResultSet: pAssignment == NULL");
667 : : OSL_ENSURE(SQL_ISRULE(pAssignment,assignment),"OResultSet: Fehler im Parse Tree");
668 : : OSL_ENSURE(pAssignment->count() == 3,"OResultSet: pAssignment->count() != 3");
669 : :
670 [ # # ]: 0 : OSQLParseNode * pCol = pAssignment->getChild(0);
671 : : OSL_ENSURE(pCol != NULL,"OResultSet: pCol == NULL");
672 : :
673 [ # # ]: 0 : OSQLParseNode * pComp = pAssignment->getChild(1);
674 : : OSL_ENSURE(pComp != NULL,"OResultSet: pComp == NULL");
675 : : OSL_ENSURE(pComp->getNodeType() == SQL_NODE_EQUAL,"OResultSet: pComp->getNodeType() != SQL_NODE_COMPARISON");
676 [ # # ]: 0 : if (pComp->getTokenValue().toChar() != '=')
677 : : {
678 [ # # ][ # # ]: 0 : throwFunctionSequenceException(*this);
679 : : }
680 : :
681 [ # # ]: 0 : OSQLParseNode * pVal = pAssignment->getChild(2);
682 : : OSL_ENSURE(pVal != NULL,"OResultSet: pVal == NULL");
683 [ # # ][ # # ]: 0 : aList[0] = pCol->getTokenValue();
684 [ # # ]: 0 : ParseAssignValues(aList,pVal,0);
685 : 88 : }
686 : :
687 : : }
688 : : }
689 : : // -------------------------------------------------------------------------
690 : 0 : void OStatement_Base::ParseAssignValues(const ::std::vector< String>& aColumnNameList,OSQLParseNode* pRow_Value_Constructor_Elem,xub_StrLen nIndex)
691 : : {
692 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::ParseAssignValues" );
693 : : OSL_ENSURE(nIndex <= aColumnNameList.size(),"SdbFileCursor::ParseAssignValues: nIndex > aColumnNameList.GetTokenCount()");
694 [ # # ][ # # ]: 0 : String aColumnName(aColumnNameList[nIndex]);
695 : : OSL_ENSURE(aColumnName.Len() > 0,"OResultSet: Column-Name nicht gefunden");
696 : : OSL_ENSURE(pRow_Value_Constructor_Elem != NULL,"OResultSet: pRow_Value_Constructor_Elem darf nicht NULL sein!");
697 : :
698 [ # # # # : 0 : if (pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_STRING ||
# # ][ # # ]
699 : 0 : pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_INTNUM ||
700 : 0 : pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_APPROXNUM)
701 : : {
702 : : // set value:
703 [ # # ][ # # ]: 0 : SetAssignValue(aColumnName, pRow_Value_Constructor_Elem->getTokenValue());
[ # # ]
704 : : }
705 [ # # ][ # # ]: 0 : else if (SQL_ISTOKEN(pRow_Value_Constructor_Elem,NULL))
[ # # ]
706 : : {
707 : : // set NULL
708 [ # # ][ # # ]: 0 : SetAssignValue(aColumnName, String(), sal_True);
[ # # ]
709 : : }
710 [ # # ][ # # ]: 0 : else if (SQL_ISRULE(pRow_Value_Constructor_Elem,parameter))
[ # # ][ # # ]
711 [ # # ]: 0 : parseParamterElem(aColumnName,pRow_Value_Constructor_Elem);
712 : : else
713 : : {
714 [ # # ][ # # ]: 0 : throwFunctionSequenceException(*this);
715 [ # # ]: 0 : }
716 : 0 : }
717 : : //------------------------------------------------------------------
718 : 0 : void OStatement_Base::SetAssignValue(const String& aColumnName,
719 : : const String& aValue,
720 : : sal_Bool bSetNull,
721 : : sal_uInt32 nParameter)
722 : : {
723 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::SetAssignValue" );
724 : 0 : Reference<XPropertySet> xCol;
725 [ # # ][ # # ]: 0 : m_xColNames->getByName(aColumnName) >>= xCol;
[ # # ][ # # ]
726 [ # # ][ # # ]: 0 : sal_Int32 nId = Reference<XColumnLocate>(m_xColNames,UNO_QUERY)->findColumn(aColumnName);
[ # # ][ # # ]
727 : : // does this column actually exist in the file?
728 : :
729 [ # # ]: 0 : if (!xCol.is())
730 : : {
731 : : // This Column doesn't exist!
732 [ # # ][ # # ]: 0 : throwFunctionSequenceException(*this);
733 : : }
734 : :
735 : :
736 : : // Everything tested and we have the names of the Column.
737 : : // Now allocate one Value, set the value and tie the value to the Row.
738 [ # # ]: 0 : if (bSetNull)
739 [ # # ]: 0 : (m_aAssignValues->get())[nId]->setNull();
740 : : else
741 : : {
742 [ # # ][ # # ]: 0 : switch (::comphelper::getINT32(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
[ # # ][ # # ]
[ # # ]
[ # # # # ]
743 : : {
744 : : // put criteria depending on the Type as String or double in the variable
745 : : case DataType::CHAR:
746 : : case DataType::VARCHAR:
747 : : case DataType::LONGVARCHAR:
748 [ # # ][ # # ]: 0 : *(m_aAssignValues->get())[nId] = ORowSetValue(aValue);
[ # # ][ # # ]
749 : : //Characterset is already converted, since the entire statement was converted
750 : 0 : break;
751 : :
752 : : case DataType::BIT:
753 : : {
754 [ # # ][ # # ]: 0 : if (aValue.EqualsIgnoreCaseAscii("TRUE") || aValue.GetChar(0) == '1')
[ # # ][ # # ]
755 [ # # ][ # # ]: 0 : *(m_aAssignValues->get())[nId] = sal_True;
[ # # ]
756 [ # # ][ # # ]: 0 : else if (aValue.EqualsIgnoreCaseAscii("FALSE") || aValue.GetChar(0) == '0')
[ # # ][ # # ]
757 [ # # ][ # # ]: 0 : *(m_aAssignValues->get())[nId] = sal_False;
[ # # ]
758 : : else
759 : : {
760 [ # # ][ # # ]: 0 : throwFunctionSequenceException(*this);
761 : : }
762 : : }
763 : 0 : break;
764 : : case DataType::TINYINT:
765 : : case DataType::SMALLINT:
766 : : case DataType::INTEGER:
767 : : case DataType::DECIMAL:
768 : : case DataType::NUMERIC:
769 : : case DataType::REAL:
770 : : case DataType::DOUBLE:
771 : : case DataType::DATE:
772 : : case DataType::TIME:
773 : : case DataType::TIMESTAMP:
774 : : {
775 [ # # ][ # # ]: 0 : *(m_aAssignValues->get())[nId] = ORowSetValue(aValue);
[ # # ][ # # ]
776 : 0 : } break;
777 : : default:
778 [ # # ][ # # ]: 0 : throwFunctionSequenceException(*this);
779 : : }
780 : : }
781 : :
782 : : // save Parameter-No. (as User Data)
783 : : // SQL_NO_PARAMETER = no Parameter.
784 [ # # ]: 0 : m_aAssignValues->setParameterIndex(nId,nParameter);
785 [ # # ]: 0 : if(nParameter != SQL_NO_PARAMETER)
786 [ # # ]: 0 : m_aParameterIndexes[nParameter] = nId;
787 : 0 : }
788 : : // -----------------------------------------------------------------------------
789 : 0 : void OStatement_Base::parseParamterElem(const String& /*_sColumnName*/,OSQLParseNode* /*pRow_Value_Constructor_Elem*/)
790 : : {
791 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OStatement_Base::parseParamterElem" );
792 : : // do nothing here
793 : 0 : }
794 : : // =============================================================================
795 : : } // namespace file
796 : : // =============================================================================
797 : : }// namespace connectivity
798 : : // -----------------------------------------------------------------------------
799 : :
800 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|