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