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