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 :
21 : #include <stdio.h>
22 : #include "connectivity/sdbcx/VColumn.hxx"
23 : #include <osl/diagnose.h>
24 : #include "file/FPreparedStatement.hxx"
25 : #include <com/sun/star/sdbc/DataType.hpp>
26 : #include "file/FResultSetMetaData.hxx"
27 : #include <cppuhelper/typeprovider.hxx>
28 : #include <comphelper/sequence.hxx>
29 : #include <com/sun/star/lang/DisposedException.hpp>
30 : #include "connectivity/dbconversion.hxx"
31 : #include "connectivity/dbexception.hxx"
32 : #include "connectivity/dbtools.hxx"
33 : #include "connectivity/PColumn.hxx"
34 : #include "diagnose_ex.h"
35 : #include <comphelper/types.hxx>
36 : #include <com/sun/star/sdbc/ColumnValue.hpp>
37 : #include <tools/debug.hxx>
38 : #include "resource/file_res.hrc"
39 : #include <rtl/logfile.hxx>
40 :
41 : using namespace connectivity;
42 : using namespace comphelper;
43 : using namespace ::dbtools;
44 : using namespace connectivity::file;
45 : using namespace com::sun::star::uno;
46 : using namespace com::sun::star::lang;
47 : using namespace com::sun::star::beans;
48 : using namespace com::sun::star::sdbc;
49 : using namespace com::sun::star::sdbcx;
50 : using namespace com::sun::star::container;
51 : using namespace com::sun::star;
52 :
53 0 : IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbc.driver.file.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
54 :
55 : DBG_NAME( file_OPreparedStatement )
56 : // -------------------------------------------------------------------------
57 0 : OPreparedStatement::OPreparedStatement( OConnection* _pConnection)
58 : : OStatement_BASE2( _pConnection )
59 0 : ,m_pResultSet(NULL)
60 : {
61 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::OPreparedStatement" );
62 : DBG_CTOR( file_OPreparedStatement, NULL );
63 0 : }
64 :
65 : // -------------------------------------------------------------------------
66 0 : OPreparedStatement::~OPreparedStatement()
67 : {
68 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::~OPreparedStatement" );
69 : DBG_DTOR( file_OPreparedStatement, NULL );
70 0 : }
71 :
72 : // -------------------------------------------------------------------------
73 0 : void OPreparedStatement::disposing()
74 : {
75 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::disposing" );
76 0 : ::osl::MutexGuard aGuard(m_aMutex);
77 :
78 0 : clearMyResultSet();
79 0 : OStatement_BASE2::disposing();
80 :
81 0 : if(m_pResultSet)
82 : {
83 0 : m_pResultSet->release();
84 0 : m_pResultSet = NULL;
85 : }
86 :
87 0 : m_xParamColumns = NULL;
88 0 : m_xMetaData.clear();
89 0 : if(m_aParameterRow.is())
90 : {
91 0 : m_aParameterRow->get().clear();
92 0 : m_aParameterRow = NULL;
93 0 : }
94 :
95 :
96 0 : }
97 : // -------------------------------------------------------------------------
98 0 : void OPreparedStatement::construct(const ::rtl::OUString& sql) throw(SQLException, RuntimeException)
99 : {
100 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::construct" );
101 0 : OStatement_Base::construct(sql);
102 :
103 0 : m_aParameterRow = new OValueRefVector();
104 0 : m_aParameterRow->get().push_back(new ORowSetValueDecorator(sal_Int32(0)) );
105 :
106 0 : Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY);
107 :
108 0 : if ( m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT )
109 0 : m_xParamColumns = m_aSQLIterator.getParameters();
110 : else
111 : {
112 0 : m_xParamColumns = new OSQLColumns();
113 : // describe all parameters need for the resultset
114 0 : describeParameter();
115 : }
116 :
117 0 : OValueRefRow aTemp;
118 0 : OResultSet::setBoundedColumns(m_aEvaluateRow,aTemp,m_xParamColumns,xNames,sal_False,m_xDBMetaData,m_aColMapping);
119 :
120 0 : m_pResultSet = createResultSet();
121 0 : m_pResultSet->acquire();
122 0 : m_xResultSet = Reference<XResultSet>(m_pResultSet);
123 0 : initializeResultSet(m_pResultSet);
124 0 : }
125 : // -------------------------------------------------------------------------
126 :
127 0 : Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException)
128 : {
129 0 : Any aRet = OStatement_BASE2::queryInterface(rType);
130 0 : return aRet.hasValue() ? aRet : ::cppu::queryInterface( rType,
131 : static_cast< XPreparedStatement*>(this),
132 : static_cast< XParameters*>(this),
133 0 : static_cast< XResultSetMetaDataSupplier*>(this));
134 : }
135 : // -------------------------------------------------------------------------
136 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException)
137 : {
138 0 : ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedStatement > *)0 ),
139 0 : ::getCppuType( (const ::com::sun::star::uno::Reference< XParameters > *)0 ),
140 0 : ::getCppuType( (const ::com::sun::star::uno::Reference< XResultSetMetaDataSupplier > *)0 ));
141 :
142 0 : return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE2::getTypes());
143 : }
144 : // -------------------------------------------------------------------------
145 :
146 0 : Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) throw(SQLException, RuntimeException)
147 : {
148 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::getMetaData" );
149 0 : ::osl::MutexGuard aGuard( m_aMutex );
150 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
151 :
152 :
153 0 : if(!m_xMetaData.is())
154 0 : m_xMetaData = new OResultSetMetaData(m_aSQLIterator.getSelectColumns(),m_aSQLIterator.getTables().begin()->first,m_pTable);
155 0 : return m_xMetaData;
156 : }
157 : // -------------------------------------------------------------------------
158 :
159 0 : void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException)
160 : {
161 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::close" );
162 0 : ::osl::MutexGuard aGuard( m_aMutex );
163 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
164 :
165 :
166 0 : clearMyResultSet();
167 0 : }
168 : // -------------------------------------------------------------------------
169 :
170 0 : sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeException)
171 : {
172 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::execute" );
173 0 : ::osl::MutexGuard aGuard( m_aMutex );
174 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
175 :
176 0 : initResultSet();
177 :
178 0 : return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT;
179 : }
180 : // -------------------------------------------------------------------------
181 :
182 0 : sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, RuntimeException)
183 : {
184 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::executeUpdate" );
185 0 : ::osl::MutexGuard aGuard( m_aMutex );
186 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
187 :
188 0 : initResultSet();
189 :
190 0 : return m_pResultSet ? m_pResultSet->getRowCountResult() : sal_Int32(0);
191 : }
192 : // -------------------------------------------------------------------------
193 :
194 0 : void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
195 : {
196 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setString" );
197 0 : setParameter(parameterIndex,x);
198 0 : }
199 : // -------------------------------------------------------------------------
200 :
201 0 : Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) throw(SQLException, RuntimeException)
202 : {
203 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::getConnection" );
204 0 : ::osl::MutexGuard aGuard( m_aMutex );
205 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
206 :
207 0 : return (Reference< XConnection >)m_pConnection;
208 : }
209 : // -------------------------------------------------------------------------
210 :
211 0 : Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException)
212 : {
213 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::executeQuery" );
214 0 : ::osl::MutexGuard aGuard( m_aMutex );
215 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
216 :
217 0 : return initResultSet();
218 : }
219 : // -------------------------------------------------------------------------
220 :
221 0 : void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException)
222 : {
223 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setBoolean" );
224 0 : setParameter(parameterIndex,x);
225 0 : }
226 : // -------------------------------------------------------------------------
227 0 : void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
228 : {
229 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setByte" );
230 0 : setParameter(parameterIndex,x);
231 0 : }
232 : // -------------------------------------------------------------------------
233 :
234 0 : void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const util::Date& aData ) throw(SQLException, RuntimeException)
235 : {
236 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setDate" );
237 0 : setParameter(parameterIndex,DBTypeConversion::toDouble(aData));
238 0 : }
239 : // -------------------------------------------------------------------------
240 0 : void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const util::Time& aVal ) throw(SQLException, RuntimeException)
241 : {
242 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setTime" );
243 0 : setParameter(parameterIndex,DBTypeConversion::toDouble(aVal));
244 0 : }
245 : // -------------------------------------------------------------------------
246 :
247 0 : void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const util::DateTime& aVal ) throw(SQLException, RuntimeException)
248 : {
249 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setTimestamp" );
250 0 : setParameter(parameterIndex,DBTypeConversion::toDouble(aVal));
251 0 : }
252 : // -------------------------------------------------------------------------
253 :
254 0 : void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException)
255 : {
256 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setDouble" );
257 0 : setParameter(parameterIndex,x);
258 0 : }
259 :
260 : // -------------------------------------------------------------------------
261 :
262 0 : void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException)
263 : {
264 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setFloat" );
265 0 : setParameter(parameterIndex,x);
266 0 : }
267 : // -------------------------------------------------------------------------
268 :
269 0 : void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
270 : {
271 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setInt" );
272 0 : setParameter(parameterIndex,x);
273 0 : }
274 : // -------------------------------------------------------------------------
275 :
276 0 : void SAL_CALL OPreparedStatement::setLong( sal_Int32 /*parameterIndex*/, sal_Int64 /*aVal*/ ) throw(SQLException, RuntimeException)
277 : {
278 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setLong" );
279 0 : throwFeatureNotImplementedException( "XParameters::setLong", *this );
280 0 : }
281 : // -------------------------------------------------------------------------
282 :
283 0 : void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
284 : {
285 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setNull" );
286 0 : ::osl::MutexGuard aGuard( m_aMutex );
287 0 : checkAndResizeParameters(parameterIndex);
288 :
289 0 : if ( m_aAssignValues.is() )
290 0 : (m_aAssignValues->get())[m_aParameterIndexes[parameterIndex]]->setNull();
291 : else
292 0 : (m_aParameterRow->get())[parameterIndex]->setNull();
293 0 : }
294 : // -------------------------------------------------------------------------
295 :
296 0 : void SAL_CALL OPreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
297 : {
298 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setClob" );
299 0 : throwFeatureNotImplementedException( "XParameters::setClob", *this );
300 0 : }
301 : // -------------------------------------------------------------------------
302 :
303 0 : void SAL_CALL OPreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
304 : {
305 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setBlob" );
306 0 : throwFeatureNotImplementedException( "XParameters::setBlob", *this );
307 0 : }
308 : // -------------------------------------------------------------------------
309 :
310 0 : void SAL_CALL OPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
311 : {
312 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setArray" );
313 0 : throwFeatureNotImplementedException( "XParameters::setArray", *this );
314 0 : }
315 : // -------------------------------------------------------------------------
316 :
317 0 : void SAL_CALL OPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
318 : {
319 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setRef" );
320 0 : throwFeatureNotImplementedException( "XParameters::setRef", *this );
321 0 : }
322 : // -------------------------------------------------------------------------
323 :
324 0 : void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException)
325 : {
326 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setObjectWithInfo" );
327 0 : switch(sqlType)
328 : {
329 : case DataType::DECIMAL:
330 : case DataType::NUMERIC:
331 0 : setString(parameterIndex,::comphelper::getString(x));
332 0 : break;
333 : default:
334 0 : ::dbtools::setObjectWithInfo(this,parameterIndex,x,sqlType,scale);
335 0 : break;
336 : }
337 0 : }
338 : // -------------------------------------------------------------------------
339 :
340 0 : void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
341 : {
342 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setObjectNull" );
343 0 : setNull(parameterIndex,sqlType);
344 0 : }
345 : // -------------------------------------------------------------------------
346 :
347 0 : void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
348 : {
349 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setObject" );
350 0 : if(!::dbtools::implSetObject(this,parameterIndex,x))
351 : {
352 0 : const ::rtl::OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
353 : STR_UNKNOWN_PARA_TYPE,
354 : "$position$", ::rtl::OUString::valueOf(parameterIndex)
355 0 : ) );
356 0 : ::dbtools::throwGenericSQLException(sError,*this);
357 : }
358 : // setObject (parameterIndex, x, sqlType, 0);
359 0 : }
360 : // -------------------------------------------------------------------------
361 :
362 0 : void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
363 : {
364 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setShort" );
365 0 : setParameter(parameterIndex,x);
366 0 : }
367 : // -------------------------------------------------------------------------
368 :
369 0 : void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
370 : {
371 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setBytes" );
372 0 : setParameter(parameterIndex,x);
373 0 : }
374 : // -------------------------------------------------------------------------
375 :
376 :
377 0 : void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
378 : {
379 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setCharacterStream" );
380 0 : setBinaryStream(parameterIndex,x,length );
381 0 : }
382 : // -------------------------------------------------------------------------
383 :
384 0 : void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
385 : {
386 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setBinaryStream" );
387 0 : if(!x.is())
388 0 : ::dbtools::throwFunctionSequenceException(*this);
389 :
390 0 : Sequence<sal_Int8> aSeq;
391 0 : x->readBytes(aSeq,length);
392 0 : setParameter(parameterIndex,aSeq);
393 0 : }
394 : // -------------------------------------------------------------------------
395 :
396 0 : void SAL_CALL OPreparedStatement::clearParameters( ) throw(SQLException, RuntimeException)
397 : {
398 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::clearParameters" );
399 0 : ::osl::MutexGuard aGuard( m_aMutex );
400 0 : checkDisposed(OStatement_BASE::rBHelper.bDisposed);
401 :
402 0 : m_aParameterRow->get().clear();
403 0 : m_aParameterRow->get().push_back(new ORowSetValueDecorator(sal_Int32(0)) );
404 0 : }
405 : // -------------------------------------------------------------------------
406 0 : OResultSet* OPreparedStatement::createResultSet()
407 : {
408 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::createResultSet" );
409 0 : return new OResultSet(this,m_aSQLIterator);
410 : }
411 : // -----------------------------------------------------------------------------
412 0 : Reference<XResultSet> OPreparedStatement::initResultSet()
413 : {
414 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::initResultSet" );
415 0 : m_pResultSet->clear();
416 0 : Reference<XResultSet> xRs(m_pResultSet);
417 :
418 : // check if we got enough parameters
419 0 : if ( (m_aParameterRow.is() && ( m_aParameterRow->get().size() -1 ) < m_xParamColumns->get().size()) ||
420 0 : (m_xParamColumns.is() && !m_aParameterRow.is() && !m_aParameterRow->get().empty()) )
421 0 : m_pConnection->throwGenericSQLException(STR_INVALID_PARA_COUNT,*this);
422 :
423 0 : m_pResultSet->OpenImpl();
424 0 : m_pResultSet->setMetaData(getMetaData());
425 :
426 0 : return xRs;
427 : }
428 : // -----------------------------------------------------------------------------
429 0 : void SAL_CALL OPreparedStatement::acquire() throw()
430 : {
431 0 : OStatement_BASE2::acquire();
432 0 : }
433 : // -----------------------------------------------------------------------------
434 0 : void SAL_CALL OPreparedStatement::release() throw()
435 : {
436 0 : OStatement_BASE2::release();
437 0 : }
438 : // -----------------------------------------------------------------------------
439 0 : void OPreparedStatement::checkAndResizeParameters(sal_Int32 parameterIndex)
440 : {
441 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::checkAndResizeParameters" );
442 0 : ::connectivity::checkDisposed(OStatement_BASE::rBHelper.bDisposed);
443 0 : if ( m_aAssignValues.is() && (parameterIndex < 1 || parameterIndex >= static_cast<sal_Int32>(m_aParameterIndexes.size())) )
444 0 : throwInvalidIndexException(*this);
445 0 : else if ( static_cast<sal_Int32>((m_aParameterRow->get()).size()) <= parameterIndex )
446 : {
447 0 : sal_Int32 i = m_aParameterRow->get().size();
448 0 : (m_aParameterRow->get()).resize(parameterIndex+1);
449 0 : for ( ;i <= parameterIndex+1; ++i )
450 : {
451 0 : if ( !(m_aParameterRow->get())[i].is() )
452 0 : (m_aParameterRow->get())[i] = new ORowSetValueDecorator;
453 : }
454 : }
455 0 : }
456 : // -----------------------------------------------------------------------------
457 0 : void OPreparedStatement::setParameter(sal_Int32 parameterIndex, const ORowSetValue& x)
458 : {
459 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setParameter" );
460 0 : ::osl::MutexGuard aGuard( m_aMutex );
461 0 : checkAndResizeParameters(parameterIndex);
462 :
463 0 : if(m_aAssignValues.is())
464 0 : *(m_aAssignValues->get())[m_aParameterIndexes[parameterIndex]] = x;
465 : else
466 0 : *((m_aParameterRow->get())[parameterIndex]) = x;
467 0 : }
468 : // -----------------------------------------------------------------------------
469 0 : sal_uInt32 OPreparedStatement::AddParameter(OSQLParseNode * pParameter, const Reference<XPropertySet>& _xCol)
470 : {
471 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::AddParameter" );
472 : OSL_UNUSED( pParameter );
473 : OSL_ENSURE(SQL_ISRULE(pParameter,parameter),"OResultSet::AddParameter: Argument ist kein Parameter");
474 : OSL_ENSURE(pParameter->count() > 0,"OResultSet: Fehler im Parse Tree");
475 : #if OSL_DEBUG_LEVEL > 0
476 : OSQLParseNode * pMark = pParameter->getChild(0);
477 : OSL_UNUSED( pMark );
478 : #endif
479 :
480 0 : ::rtl::OUString sParameterName;
481 : // set up Parameter-Column:
482 0 : sal_Int32 eType = DataType::VARCHAR;
483 0 : sal_uInt32 nPrecision = 255;
484 0 : sal_Int32 nScale = 0;
485 0 : sal_Int32 nNullable = ColumnValue::NULLABLE;
486 :
487 0 : if (_xCol.is())
488 : {
489 : // Use type, precision, scale ... from the given column,
490 : // because this Column will get a value assigned or
491 : // with this Column the value will be compared.
492 0 : _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= eType;
493 0 : _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)) >>= nPrecision;
494 0 : _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale;
495 0 : _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nNullable;
496 0 : _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sParameterName;
497 : }
498 :
499 : Reference<XPropertySet> xParaColumn = new connectivity::parse::OParseColumn(sParameterName
500 : ,::rtl::OUString()
501 : ,::rtl::OUString()
502 : ,::rtl::OUString()
503 : ,nNullable
504 : ,nPrecision
505 : ,nScale
506 : ,eType
507 : ,sal_False
508 : ,sal_False
509 0 : ,m_aSQLIterator.isCaseSensitive()
510 : ,::rtl::OUString()
511 : ,::rtl::OUString()
512 0 : ,::rtl::OUString());
513 0 : m_xParamColumns->get().push_back(xParaColumn);
514 0 : return m_xParamColumns->get().size();
515 : }
516 : // -----------------------------------------------------------------------------
517 0 : void OPreparedStatement::describeColumn(OSQLParseNode* _pParameter,OSQLParseNode* _pNode,const OSQLTable& _xTable)
518 : {
519 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::describeColumn" );
520 0 : Reference<XPropertySet> xProp;
521 0 : if(SQL_ISRULE(_pNode,column_ref))
522 : {
523 0 : ::rtl::OUString sColumnName,sTableRange;
524 0 : m_aSQLIterator.getColumnRange(_pNode,sColumnName,sTableRange);
525 0 : if ( !sColumnName.isEmpty() )
526 : {
527 0 : Reference<XNameAccess> xNameAccess = _xTable->getColumns();
528 0 : if(xNameAccess->hasByName(sColumnName))
529 0 : xNameAccess->getByName(sColumnName) >>= xProp;
530 0 : AddParameter(_pParameter,xProp);
531 0 : }
532 0 : }
533 : // else
534 : // AddParameter(_pParameter,xProp);
535 0 : }
536 : // -------------------------------------------------------------------------
537 0 : void OPreparedStatement::describeParameter()
538 : {
539 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::describeParameter" );
540 0 : ::std::vector< OSQLParseNode*> aParseNodes;
541 0 : scanParameter(m_pParseTree,aParseNodes);
542 0 : if ( !aParseNodes.empty() )
543 : {
544 : // m_xParamColumns = new OSQLColumns();
545 0 : const OSQLTables& xTabs = m_aSQLIterator.getTables();
546 0 : if( !xTabs.empty() )
547 : {
548 0 : OSQLTable xTable = xTabs.begin()->second;
549 0 : ::std::vector< OSQLParseNode*>::const_iterator aIter = aParseNodes.begin();
550 0 : for (;aIter != aParseNodes.end();++aIter )
551 : {
552 0 : describeColumn(*aIter,(*aIter)->getParent()->getChild(0),xTable);
553 0 : }
554 : }
555 0 : }
556 0 : }
557 : // -----------------------------------------------------------------------------
558 0 : void OPreparedStatement::initializeResultSet(OResultSet* _pResult)
559 : {
560 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::initializeResultSet" );
561 0 : OStatement_Base::initializeResultSet(_pResult);
562 :
563 0 : m_pResultSet->setParameterColumns(m_xParamColumns);
564 0 : m_pResultSet->setParameterRow(m_aParameterRow);
565 :
566 : // Substitute parameter (AssignValues and criteria):
567 0 : if (!m_xParamColumns->get().empty())
568 : {
569 : // begin with AssignValues
570 0 : sal_uInt16 nParaCount=0; // gives the current number of previously set Parameters
571 :
572 : // search for parameters to be substituted:
573 0 : size_t nCount = m_aAssignValues.is() ? m_aAssignValues->get().size() : 1; // 1 is important for the Criteria
574 0 : for (size_t j = 1; j < nCount; j++)
575 : {
576 0 : sal_uInt32 nParameter = (*m_aAssignValues).getParameterIndex(j);
577 0 : if (nParameter == SQL_NO_PARAMETER)
578 0 : continue; // this AssignValue is no Parameter
579 :
580 0 : ++nParaCount; // now the Parameter is valid
581 : }
582 :
583 0 : if (m_aParameterRow.is() && (m_xParamColumns->get().size()+1) != m_aParameterRow->get().size() )
584 : {
585 0 : sal_Int32 i = m_aParameterRow->get().size();
586 0 : sal_Int32 nParamColumns = m_xParamColumns->get().size()+1;
587 0 : m_aParameterRow->get().resize(nParamColumns);
588 0 : for ( ;i < nParamColumns; ++i )
589 : {
590 0 : if ( !(m_aParameterRow->get())[i].is() )
591 0 : (m_aParameterRow->get())[i] = new ORowSetValueDecorator;
592 : }
593 : }
594 0 : if (m_aParameterRow.is() && nParaCount < m_aParameterRow->get().size() )
595 0 : m_pSQLAnalyzer->bindParameterRow(m_aParameterRow);
596 : }
597 0 : }
598 : // -----------------------------------------------------------------------------
599 0 : void OPreparedStatement::parseParamterElem(const String& _sColumnName,OSQLParseNode* pRow_Value_Constructor_Elem)
600 : {
601 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::parseParamterElem" );
602 0 : Reference<XPropertySet> xCol;
603 0 : m_xColNames->getByName(_sColumnName) >>= xCol;
604 0 : sal_Int32 nParameter = -1;
605 0 : if(m_xParamColumns.is())
606 : {
607 0 : OSQLColumns::Vector::const_iterator aIter = find(m_xParamColumns->get().begin(),m_xParamColumns->get().end(),_sColumnName,::comphelper::UStringMixEqual(m_pTable->isCaseSensitive()));
608 0 : if(aIter != m_xParamColumns->get().end())
609 0 : nParameter = m_xParamColumns->get().size() - (m_xParamColumns->get().end() - aIter) + 1;// +1 because the rows start at 1
610 : }
611 0 : if(nParameter == -1)
612 0 : nParameter = AddParameter(pRow_Value_Constructor_Elem,xCol);
613 : // Save number of parameter in the variable:
614 0 : SetAssignValue(_sColumnName, String(), sal_True, nParameter);
615 0 : }
616 : // -----------------------------------------------------------------------------
617 :
618 :
619 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|