1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FPreparedStatement.cxx,v $
10 * $Revision: 1.42.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
35 #include "connectivity/sdbcx/VColumn.hxx"
36 #include <osl/diagnose.h>
37 #include "file/FPreparedStatement.hxx"
38 #include <com/sun/star/sdbc/DataType.hpp>
39 #include "file/FResultSetMetaData.hxx"
40 #include <cppuhelper/typeprovider.hxx>
41 #include <comphelper/sequence.hxx>
42 #include <com/sun/star/lang/DisposedException.hpp>
43 #include "connectivity/dbconversion.hxx"
44 #include "connectivity/dbexception.hxx"
45 #include "connectivity/dbtools.hxx"
46 #include "connectivity/PColumn.hxx"
47 #include "diagnose_ex.h"
48 #include <comphelper/types.hxx>
49 #include <com/sun/star/sdbc/ColumnValue.hpp>
50 #include <tools/debug.hxx>
51 #include "resource/file_res.hrc"
52 #include <rtl/logfile.hxx>
54 using namespace connectivity
;
55 using namespace comphelper
;
56 using namespace ::dbtools
;
57 using namespace connectivity::file
;
58 using namespace com::sun::star::uno
;
59 using namespace com::sun::star::lang
;
60 using namespace com::sun::star::beans
;
61 using namespace com::sun::star::sdbc
;
62 using namespace com::sun::star::sdbcx
;
63 using namespace com::sun::star::container
;
64 using namespace com::sun::star::util
;
66 IMPLEMENT_SERVICE_INFO(OPreparedStatement
,"com.sun.star.sdbc.driver.file.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
68 DBG_NAME( file_OPreparedStatement
)
69 // -------------------------------------------------------------------------
70 OPreparedStatement::OPreparedStatement( OConnection
* _pConnection
)
71 : OStatement_BASE2( _pConnection
)
74 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::OPreparedStatement" );
75 DBG_CTOR( file_OPreparedStatement
, NULL
);
78 // -------------------------------------------------------------------------
79 OPreparedStatement::~OPreparedStatement()
81 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::~OPreparedStatement" );
82 DBG_DTOR( file_OPreparedStatement
, NULL
);
85 // -------------------------------------------------------------------------
86 void OPreparedStatement::disposing()
88 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::disposing" );
89 ::osl::MutexGuard
aGuard(m_aMutex
);
92 OStatement_BASE2::disposing();
96 m_pResultSet
->release();
100 m_xParamColumns
= NULL
;
102 if(m_aParameterRow
.isValid())
104 m_aParameterRow
->get().clear();
105 m_aParameterRow
= NULL
;
110 // -------------------------------------------------------------------------
111 void OPreparedStatement::construct(const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
113 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::construct" );
114 OStatement_Base::construct(sql
);
116 m_aParameterRow
= new OValueRefVector();
117 m_aParameterRow
->get().push_back(new ORowSetValueDecorator(sal_Int32(0)) );
119 Reference
<XIndexAccess
> xNames(m_xColNames
,UNO_QUERY
);
121 if ( m_aSQLIterator
.getStatementType() == SQL_STATEMENT_SELECT
)
122 m_xParamColumns
= m_aSQLIterator
.getParameters();
125 m_xParamColumns
= new OSQLColumns();
126 // describe all parameters need for the resultset
131 OResultSet::setBoundedColumns(m_aEvaluateRow
,aTemp
,m_xParamColumns
,xNames
,sal_False
,m_xDBMetaData
,m_aColMapping
);
133 m_pResultSet
= createResultSet();
134 m_pResultSet
->acquire();
135 m_xResultSet
= Reference
<XResultSet
>(m_pResultSet
);
136 initializeResultSet(m_pResultSet
);
138 // -------------------------------------------------------------------------
140 Any SAL_CALL
OPreparedStatement::queryInterface( const Type
& rType
) throw(RuntimeException
)
142 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::queryInterface" );
143 Any aRet
= OStatement_BASE2::queryInterface(rType
);
144 return aRet
.hasValue() ? aRet
: ::cppu::queryInterface( rType
,
145 static_cast< XPreparedStatement
*>(this),
146 static_cast< XParameters
*>(this),
147 static_cast< XResultSetMetaDataSupplier
*>(this));
149 // -------------------------------------------------------------------------
150 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException
)
152 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::getTypes" );
153 ::cppu::OTypeCollection
aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference
< XPreparedStatement
> *)0 ),
154 ::getCppuType( (const ::com::sun::star::uno::Reference
< XParameters
> *)0 ),
155 ::getCppuType( (const ::com::sun::star::uno::Reference
< XResultSetMetaDataSupplier
> *)0 ));
157 return ::comphelper::concatSequences(aTypes
.getTypes(),OStatement_BASE2::getTypes());
159 // -------------------------------------------------------------------------
161 Reference
< XResultSetMetaData
> SAL_CALL
OPreparedStatement::getMetaData( ) throw(SQLException
, RuntimeException
)
163 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::getMetaData" );
164 ::osl::MutexGuard
aGuard( m_aMutex
);
165 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
168 if(!m_xMetaData
.is())
169 m_xMetaData
= new OResultSetMetaData(m_aSQLIterator
.getSelectColumns(),m_aSQLIterator
.getTables().begin()->first
,m_pTable
);
172 // -------------------------------------------------------------------------
174 void SAL_CALL
OPreparedStatement::close( ) throw(SQLException
, RuntimeException
)
176 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::close" );
177 ::osl::MutexGuard
aGuard( m_aMutex
);
178 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
183 // -------------------------------------------------------------------------
185 sal_Bool SAL_CALL
OPreparedStatement::execute( ) throw(SQLException
, RuntimeException
)
187 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::execute" );
188 ::osl::MutexGuard
aGuard( m_aMutex
);
189 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
193 return m_aSQLIterator
.getStatementType() == SQL_STATEMENT_SELECT
;
195 // -------------------------------------------------------------------------
197 sal_Int32 SAL_CALL
OPreparedStatement::executeUpdate( ) throw(SQLException
, RuntimeException
)
199 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::executeUpdate" );
200 ::osl::MutexGuard
aGuard( m_aMutex
);
201 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
205 return m_pResultSet
? m_pResultSet
->getRowCountResult() : sal_Int32(0);
207 // -------------------------------------------------------------------------
209 void SAL_CALL
OPreparedStatement::setString( sal_Int32 parameterIndex
, const ::rtl::OUString
& x
) throw(SQLException
, RuntimeException
)
211 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setString" );
212 setParameter(parameterIndex
,x
);
214 // -------------------------------------------------------------------------
216 Reference
< XConnection
> SAL_CALL
OPreparedStatement::getConnection( ) throw(SQLException
, RuntimeException
)
218 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::getConnection" );
219 ::osl::MutexGuard
aGuard( m_aMutex
);
220 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
222 return (Reference
< XConnection
>)m_pConnection
;
224 // -------------------------------------------------------------------------
226 Reference
< XResultSet
> SAL_CALL
OPreparedStatement::executeQuery( ) throw(SQLException
, RuntimeException
)
228 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::executeQuery" );
229 ::osl::MutexGuard
aGuard( m_aMutex
);
230 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
232 return initResultSet();
234 // -------------------------------------------------------------------------
236 void SAL_CALL
OPreparedStatement::setBoolean( sal_Int32 parameterIndex
, sal_Bool x
) throw(SQLException
, RuntimeException
)
238 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setBoolean" );
239 setParameter(parameterIndex
,x
);
241 // -------------------------------------------------------------------------
242 void SAL_CALL
OPreparedStatement::setByte( sal_Int32 parameterIndex
, sal_Int8 x
) throw(SQLException
, RuntimeException
)
244 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setByte" );
245 setParameter(parameterIndex
,x
);
247 // -------------------------------------------------------------------------
249 void SAL_CALL
OPreparedStatement::setDate( sal_Int32 parameterIndex
, const Date
& aData
) throw(SQLException
, RuntimeException
)
251 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setDate" );
252 setParameter(parameterIndex
,DBTypeConversion::toDouble(aData
));
254 // -------------------------------------------------------------------------
255 void SAL_CALL
OPreparedStatement::setTime( sal_Int32 parameterIndex
, const Time
& aVal
) throw(SQLException
, RuntimeException
)
257 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setTime" );
258 setParameter(parameterIndex
,DBTypeConversion::toDouble(aVal
));
260 // -------------------------------------------------------------------------
262 void SAL_CALL
OPreparedStatement::setTimestamp( sal_Int32 parameterIndex
, const DateTime
& aVal
) throw(SQLException
, RuntimeException
)
264 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setTimestamp" );
265 setParameter(parameterIndex
,DBTypeConversion::toDouble(aVal
));
267 // -------------------------------------------------------------------------
269 void SAL_CALL
OPreparedStatement::setDouble( sal_Int32 parameterIndex
, double x
) throw(SQLException
, RuntimeException
)
271 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setDouble" );
272 setParameter(parameterIndex
,x
);
275 // -------------------------------------------------------------------------
277 void SAL_CALL
OPreparedStatement::setFloat( sal_Int32 parameterIndex
, float x
) throw(SQLException
, RuntimeException
)
279 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setFloat" );
280 setParameter(parameterIndex
,x
);
282 // -------------------------------------------------------------------------
284 void SAL_CALL
OPreparedStatement::setInt( sal_Int32 parameterIndex
, sal_Int32 x
) throw(SQLException
, RuntimeException
)
286 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setInt" );
287 setParameter(parameterIndex
,x
);
289 // -------------------------------------------------------------------------
291 void SAL_CALL
OPreparedStatement::setLong( sal_Int32
/*parameterIndex*/, sal_Int64
/*aVal*/ ) throw(SQLException
, RuntimeException
)
293 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setLong" );
294 throwFeatureNotImplementedException( "XParameters::setLong", *this );
296 // -------------------------------------------------------------------------
298 void SAL_CALL
OPreparedStatement::setNull( sal_Int32 parameterIndex
, sal_Int32
/*sqlType*/ ) throw(SQLException
, RuntimeException
)
300 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setNull" );
301 ::osl::MutexGuard
aGuard( m_aMutex
);
302 checkAndResizeParameters(parameterIndex
);
304 if ( m_aAssignValues
.isValid() )
305 (m_aAssignValues
->get())[m_aParameterIndexes
[parameterIndex
]]->setNull();
307 (m_aParameterRow
->get())[parameterIndex
]->setNull();
309 // -------------------------------------------------------------------------
311 void SAL_CALL
OPreparedStatement::setClob( sal_Int32
/*parameterIndex*/, const Reference
< XClob
>& /*x*/ ) throw(SQLException
, RuntimeException
)
313 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setClob" );
314 throwFeatureNotImplementedException( "XParameters::setClob", *this );
316 // -------------------------------------------------------------------------
318 void SAL_CALL
OPreparedStatement::setBlob( sal_Int32
/*parameterIndex*/, const Reference
< XBlob
>& /*x*/ ) throw(SQLException
, RuntimeException
)
320 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setBlob" );
321 throwFeatureNotImplementedException( "XParameters::setBlob", *this );
323 // -------------------------------------------------------------------------
325 void SAL_CALL
OPreparedStatement::setArray( sal_Int32
/*parameterIndex*/, const Reference
< XArray
>& /*x*/ ) throw(SQLException
, RuntimeException
)
327 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setArray" );
328 throwFeatureNotImplementedException( "XParameters::setArray", *this );
330 // -------------------------------------------------------------------------
332 void SAL_CALL
OPreparedStatement::setRef( sal_Int32
/*parameterIndex*/, const Reference
< XRef
>& /*x*/ ) throw(SQLException
, RuntimeException
)
334 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setRef" );
335 throwFeatureNotImplementedException( "XParameters::setRef", *this );
337 // -------------------------------------------------------------------------
339 void SAL_CALL
OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex
, const Any
& x
, sal_Int32 sqlType
, sal_Int32 scale
) throw(SQLException
, RuntimeException
)
341 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setObjectWithInfo" );
344 case DataType::DECIMAL
:
345 case DataType::NUMERIC
:
346 setString(parameterIndex
,::comphelper::getString(x
));
349 ::dbtools::setObjectWithInfo(this,parameterIndex
,x
,sqlType
,scale
);
353 // -------------------------------------------------------------------------
355 void SAL_CALL
OPreparedStatement::setObjectNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
, const ::rtl::OUString
& /*typeName*/ ) throw(SQLException
, RuntimeException
)
357 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setObjectNull" );
358 setNull(parameterIndex
,sqlType
);
360 // -------------------------------------------------------------------------
362 void SAL_CALL
OPreparedStatement::setObject( sal_Int32 parameterIndex
, const Any
& x
) throw(SQLException
, RuntimeException
)
364 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setObject" );
365 if(!::dbtools::implSetObject(this,parameterIndex
,x
))
367 const ::rtl::OUString
sError( m_pConnection
->getResources().getResourceStringWithSubstitution(
368 STR_UNKNOWN_PARA_TYPE
,
369 "$position$", ::rtl::OUString::valueOf(parameterIndex
)
371 ::dbtools::throwGenericSQLException(sError
,*this);
373 // setObject (parameterIndex, x, sqlType, 0);
375 // -------------------------------------------------------------------------
377 void SAL_CALL
OPreparedStatement::setShort( sal_Int32 parameterIndex
, sal_Int16 x
) throw(SQLException
, RuntimeException
)
379 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setShort" );
380 setParameter(parameterIndex
,x
);
382 // -------------------------------------------------------------------------
384 void SAL_CALL
OPreparedStatement::setBytes( sal_Int32 parameterIndex
, const Sequence
< sal_Int8
>& x
) throw(SQLException
, RuntimeException
)
386 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setBytes" );
387 setParameter(parameterIndex
,x
);
389 // -------------------------------------------------------------------------
392 void SAL_CALL
OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
394 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setCharacterStream" );
395 setBinaryStream(parameterIndex
,x
,length
);
397 // -------------------------------------------------------------------------
399 void SAL_CALL
OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
401 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setBinaryStream" );
403 ::dbtools::throwFunctionSequenceException(*this);
405 Sequence
<sal_Int8
> aSeq
;
406 x
->readBytes(aSeq
,length
);
407 setParameter(parameterIndex
,aSeq
);
409 // -------------------------------------------------------------------------
411 void SAL_CALL
OPreparedStatement::clearParameters( ) throw(SQLException
, RuntimeException
)
413 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::clearParameters" );
414 ::osl::MutexGuard
aGuard( m_aMutex
);
415 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
417 m_aParameterRow
->get().clear();
418 m_aParameterRow
->get().push_back(new ORowSetValueDecorator(sal_Int32(0)) );
420 // -------------------------------------------------------------------------
421 OResultSet
* OPreparedStatement::createResultSet()
423 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::createResultSet" );
424 return new OResultSet(this,m_aSQLIterator
);
426 // -----------------------------------------------------------------------------
427 Reference
<XResultSet
> OPreparedStatement::initResultSet()
429 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::initResultSet" );
430 m_pResultSet
->clear();
431 Reference
<XResultSet
> xRs(m_pResultSet
);
433 // check if we got enough paramters
434 if ( (m_aParameterRow
.isValid() && ( m_aParameterRow
->get().size() -1 ) < m_xParamColumns
->get().size()) ||
435 (m_xParamColumns
.isValid() && !m_aParameterRow
.isValid() && !m_aParameterRow
->get().empty()) )
436 m_pConnection
->throwGenericSQLException(STR_INVALID_PARA_COUNT
,*this);
438 m_pResultSet
->OpenImpl();
439 m_pResultSet
->setMetaData(getMetaData());
443 // -----------------------------------------------------------------------------
444 void SAL_CALL
OPreparedStatement::acquire() throw()
446 OStatement_BASE2::acquire();
448 // -----------------------------------------------------------------------------
449 void SAL_CALL
OPreparedStatement::release() throw()
451 OStatement_BASE2::release();
453 // -----------------------------------------------------------------------------
454 void OPreparedStatement::checkAndResizeParameters(sal_Int32 parameterIndex
)
456 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::checkAndResizeParameters" );
457 ::connectivity::checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
458 if ( m_aAssignValues
.isValid() && (parameterIndex
< 1 || parameterIndex
>= static_cast<sal_Int32
>(m_aParameterIndexes
.size())) )
459 throwInvalidIndexException(*this);
460 else if ( static_cast<sal_Int32
>((m_aParameterRow
->get()).size()) <= parameterIndex
)
462 sal_Int32 i
= m_aParameterRow
->get().size();
463 (m_aParameterRow
->get()).resize(parameterIndex
+1);
464 for ( ;i
<= parameterIndex
+1; ++i
)
466 if ( !(m_aParameterRow
->get())[i
].isValid() )
467 (m_aParameterRow
->get())[i
] = new ORowSetValueDecorator
;
471 // -----------------------------------------------------------------------------
472 void OPreparedStatement::setParameter(sal_Int32 parameterIndex
, const ORowSetValue
& x
)
474 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::setParameter" );
475 ::osl::MutexGuard
aGuard( m_aMutex
);
476 checkAndResizeParameters(parameterIndex
);
478 if(m_aAssignValues
.isValid())
479 *(m_aAssignValues
->get())[m_aParameterIndexes
[parameterIndex
]] = x
;
481 *((m_aParameterRow
->get())[parameterIndex
]) = x
;
483 // -----------------------------------------------------------------------------
484 UINT32
OPreparedStatement::AddParameter(OSQLParseNode
* pParameter
, const Reference
<XPropertySet
>& _xCol
)
486 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::AddParameter" );
487 OSL_UNUSED( pParameter
);
488 OSL_ENSURE(SQL_ISRULE(pParameter
,parameter
),"OResultSet::AddParameter: Argument ist kein Parameter");
489 OSL_ENSURE(pParameter
->count() > 0,"OResultSet: Fehler im Parse Tree");
490 #if OSL_DEBUG_LEVEL > 0
491 OSQLParseNode
* pMark
= pParameter
->getChild(0);
495 ::rtl::OUString sParameterName
;
496 // Parameter-Column aufsetzen:
497 sal_Int32 eType
= DataType::VARCHAR
;
498 UINT32 nPrecision
= 255;
499 sal_Int32 nScale
= 0;
500 sal_Int32 nNullable
= ColumnValue::NULLABLE
;
504 // Typ, Precision, Scale ... der angegebenen Column verwenden,
505 // denn dieser Column wird der Wert zugewiesen bzw. mit dieser
506 // Column wird der Wert verglichen.
507 _xCol
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
)) >>= eType
;
508 _xCol
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION
)) >>= nPrecision
;
509 _xCol
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE
)) >>= nScale
;
510 _xCol
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE
)) >>= nNullable
;
511 _xCol
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
)) >>= sParameterName
;
514 Reference
<XPropertySet
> xParaColumn
= new connectivity::parse::OParseColumn(sParameterName
523 ,m_aSQLIterator
.isCaseSensitive());
524 m_xParamColumns
->get().push_back(xParaColumn
);
525 return m_xParamColumns
->get().size();
527 // -----------------------------------------------------------------------------
528 void OPreparedStatement::describeColumn(OSQLParseNode
* _pParameter
,OSQLParseNode
* _pNode
,const OSQLTable
& _xTable
)
530 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::describeColumn" );
531 Reference
<XPropertySet
> xProp
;
532 if(SQL_ISRULE(_pNode
,column_ref
))
534 ::rtl::OUString sColumnName
,sTableRange
;
535 m_aSQLIterator
.getColumnRange(_pNode
,sColumnName
,sTableRange
);
536 if ( sColumnName
.getLength() )
538 Reference
<XNameAccess
> xNameAccess
= _xTable
->getColumns();
539 if(xNameAccess
->hasByName(sColumnName
))
540 xNameAccess
->getByName(sColumnName
) >>= xProp
;
541 AddParameter(_pParameter
,xProp
);
545 // AddParameter(_pParameter,xProp);
547 // -------------------------------------------------------------------------
548 void OPreparedStatement::describeParameter()
550 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::describeParameter" );
551 ::std::vector
< OSQLParseNode
*> aParseNodes
;
552 scanParameter(m_pParseTree
,aParseNodes
);
553 if ( !aParseNodes
.empty() )
555 // m_xParamColumns = new OSQLColumns();
556 const OSQLTables
& xTabs
= m_aSQLIterator
.getTables();
559 OSQLTable xTable
= xTabs
.begin()->second
;
560 ::std::vector
< OSQLParseNode
*>::const_iterator aIter
= aParseNodes
.begin();
561 for (;aIter
!= aParseNodes
.end();++aIter
)
563 describeColumn(*aIter
,(*aIter
)->getParent()->getChild(0),xTable
);
568 // -----------------------------------------------------------------------------
569 void OPreparedStatement::initializeResultSet(OResultSet
* _pResult
)
571 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::initializeResultSet" );
572 OStatement_Base::initializeResultSet(_pResult
);
574 m_pResultSet
->setParameterColumns(m_xParamColumns
);
575 m_pResultSet
->setParameterRow(m_aParameterRow
);
577 // Parameter substituieren (AssignValues und Kriterien):
578 if (!m_xParamColumns
->get().empty())
580 // Zunaechst AssignValues
581 USHORT nParaCount
=0; // gibt die aktuelle Anzahl der bisher gesetzen Parameter an
583 // Nach zu substituierenden Parametern suchen:
584 size_t nCount
= m_aAssignValues
.isValid() ? m_aAssignValues
->get().size() : 1; // 1 ist wichtig fuer die Kriterien
585 for (size_t j
= 1; j
< nCount
; j
++)
587 UINT32 nParameter
= (*m_aAssignValues
).getParameterIndex(j
);
588 if (nParameter
== SQL_NO_PARAMETER
)
589 continue; // dieser AssignValue ist kein Parameter
591 ++nParaCount
; // ab hier ist der Parameter gueltig
592 // Parameter ersetzen. Wenn Parameter nicht verfuegbar,
593 // Value auf NULL setzen.
594 // (*m_aAssignValues)[j] = (*m_aParameterRow)[(UINT16)nParameter];
597 if (m_aParameterRow
.isValid() && (m_xParamColumns
->get().size()+1) != m_aParameterRow
->get().size() )
599 sal_Int32 i
= m_aParameterRow
->get().size();
600 sal_Int32 nParamColumns
= m_xParamColumns
->get().size()+1;
601 m_aParameterRow
->get().resize(nParamColumns
);
602 for ( ;i
< nParamColumns
; ++i
)
604 if ( !(m_aParameterRow
->get())[i
].isValid() )
605 (m_aParameterRow
->get())[i
] = new ORowSetValueDecorator
;
607 //m_aParameterRow->resize(m_xParamColumns->size()+1);
609 if (m_aParameterRow
.isValid() && nParaCount
< m_aParameterRow
->get().size() )
612 m_pSQLAnalyzer
->bindParameterRow(m_aParameterRow
);
616 // -----------------------------------------------------------------------------
617 void OPreparedStatement::parseParamterElem(const String
& _sColumnName
,OSQLParseNode
* pRow_Value_Constructor_Elem
)
619 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OPreparedStatement::parseParamterElem" );
620 Reference
<XPropertySet
> xCol
;
621 m_xColNames
->getByName(_sColumnName
) >>= xCol
;
622 sal_Int32 nParameter
= -1;
623 if(m_xParamColumns
.isValid())
625 OSQLColumns::Vector::const_iterator aIter
= find(m_xParamColumns
->get().begin(),m_xParamColumns
->get().end(),_sColumnName
,::comphelper::UStringMixEqual(m_pTable
->isCaseSensitive()));
626 if(aIter
!= m_xParamColumns
->get().end())
627 nParameter
= m_xParamColumns
->get().size() - (m_xParamColumns
->get().end() - aIter
) + 1;// +1 because the rows start at 1
630 nParameter
= AddParameter(pRow_Value_Constructor_Elem
,xCol
);
631 // Nr. des Parameters in der Variablen merken:
632 SetAssignValue(_sColumnName
, String(), TRUE
, nParameter
);
634 // -----------------------------------------------------------------------------