1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "connectivity/sqlparse.hxx"
27cdf0e10cSrcweir #include "ado/APreparedStatement.hxx"
28cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
29cdf0e10cSrcweir #include "ado/AResultSetMetaData.hxx"
30cdf0e10cSrcweir #include "ado/AResultSet.hxx"
31cdf0e10cSrcweir #include "ado/ADriver.hxx"
32cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
33cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
34cdf0e10cSrcweir #include <comphelper/sequence.hxx>
35cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
36cdf0e10cSrcweir #include "connectivity/dbtools.hxx"
37cdf0e10cSrcweir #include "resource/ado_res.hrc"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <limits>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #define CHECK_RETURN(x)													\
42cdf0e10cSrcweir 	if(!x)																\
43cdf0e10cSrcweir 		ADOS::ThrowException(*m_pConnection->getConnection(),*this);
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #ifdef max
46cdf0e10cSrcweir #	undef max
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //------------------------------------------------------------------------------
50cdf0e10cSrcweir //------------------------------------------------------------------------------
51cdf0e10cSrcweir using namespace connectivity::ado;
52cdf0e10cSrcweir using namespace connectivity;
53cdf0e10cSrcweir using namespace com::sun::star::uno;
54cdf0e10cSrcweir using namespace com::sun::star::lang;
55cdf0e10cSrcweir using namespace com::sun::star::beans;
56cdf0e10cSrcweir using namespace com::sun::star::sdbc;
57cdf0e10cSrcweir using namespace com::sun::star::util;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.APreparedStatement","com.sun.star.sdbc.PreparedStatement");
61cdf0e10cSrcweir 
OPreparedStatement(OConnection * _pConnection,const OTypeInfoMap & _TypeInfo,const::rtl::OUString & sql)62cdf0e10cSrcweir OPreparedStatement::OPreparedStatement( OConnection* _pConnection,const OTypeInfoMap& _TypeInfo,const ::rtl::OUString& sql)
63cdf0e10cSrcweir 	: OStatement_Base( _pConnection )
64cdf0e10cSrcweir 	,m_aTypeInfo(_TypeInfo)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	OSQLParser aParser(_pConnection->getDriver()->getORB());
69cdf0e10cSrcweir 	::rtl::OUString sErrorMessage;
70cdf0e10cSrcweir 	::rtl::OUString sNewSql;
71cdf0e10cSrcweir 	OSQLParseNode* pNode = aParser.parseTree(sErrorMessage,sql);
72cdf0e10cSrcweir 	if(pNode)
73cdf0e10cSrcweir 	{	// special handling for parameters
74cdf0e10cSrcweir         /* we recusive replace all occurences of ? in the statement and replace them with name like "��" */
75cdf0e10cSrcweir 		sal_Int32 nParameterCount = 0;
76cdf0e10cSrcweir 		::rtl::OUString sDefaultName = ::rtl::OUString::createFromAscii("parame");
77cdf0e10cSrcweir 		replaceParameterNodeName(pNode,sDefaultName,nParameterCount);
78cdf0e10cSrcweir 		pNode->parseNodeToStr( sNewSql, _pConnection );
79cdf0e10cSrcweir 		delete pNode;
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir 	else
82cdf0e10cSrcweir 		sNewSql = sql;
83cdf0e10cSrcweir 	CHECK_RETURN(m_Command.put_CommandText(sNewSql))
84cdf0e10cSrcweir 	CHECK_RETURN(m_Command.put_Prepared(VARIANT_TRUE))
85cdf0e10cSrcweir 	m_pParameters = m_Command.get_Parameters();
86cdf0e10cSrcweir 	m_pParameters->AddRef();
87cdf0e10cSrcweir 	m_pParameters->Refresh();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // -------------------------------------------------------------------------
~OPreparedStatement()93cdf0e10cSrcweir OPreparedStatement::~OPreparedStatement()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	if (m_pParameters)
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "OPreparedStatement::~OPreparedStatement: not disposed!" );
98cdf0e10cSrcweir 		m_pParameters->Release();
99cdf0e10cSrcweir 		m_pParameters = NULL;
100cdf0e10cSrcweir 	}
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // -------------------------------------------------------------------------
104cdf0e10cSrcweir 
queryInterface(const Type & rType)105cdf0e10cSrcweir Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	Any aRet = OStatement_Base::queryInterface(rType);
108cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : ::cppu::queryInterface(	rType,
109cdf0e10cSrcweir 										static_cast< XPreparedStatement*>(this),
110cdf0e10cSrcweir 										static_cast< XParameters*>(this),
111cdf0e10cSrcweir 										static_cast< XPreparedBatchExecution*>(this),
112cdf0e10cSrcweir 										static_cast< XResultSetMetaDataSupplier*>(this));
113cdf0e10cSrcweir }
114cdf0e10cSrcweir // -------------------------------------------------------------------------
getTypes()115cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes(  ) throw(::com::sun::star::uno::RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	::cppu::OTypeCollection aTypes(	::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedStatement > *)0 ),
118cdf0e10cSrcweir 									::getCppuType( (const ::com::sun::star::uno::Reference< XParameters > *)0 ),
119cdf0e10cSrcweir 									::getCppuType( (const ::com::sun::star::uno::Reference< XResultSetMetaDataSupplier > *)0 ),
120cdf0e10cSrcweir 									::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedBatchExecution > *)0 ));
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_Base::getTypes());
123cdf0e10cSrcweir }
124cdf0e10cSrcweir // -------------------------------------------------------------------------
125cdf0e10cSrcweir 
getMetaData()126cdf0e10cSrcweir Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData(  ) throw(SQLException, RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	if(!m_xMetaData.is() && m_RecordSet.IsValid())
129cdf0e10cSrcweir 		m_xMetaData = new OResultSetMetaData(m_RecordSet);
130cdf0e10cSrcweir 	return m_xMetaData;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir // -------------------------------------------------------------------------
disposing()133cdf0e10cSrcweir void OPreparedStatement::disposing()
134cdf0e10cSrcweir {
135cdf0e10cSrcweir m_xMetaData.clear();
136cdf0e10cSrcweir 	if (m_pParameters)
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir 		m_pParameters->Release();
139cdf0e10cSrcweir 		m_pParameters = NULL;
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir 	OStatement_Base::disposing();
142cdf0e10cSrcweir }
143cdf0e10cSrcweir // -------------------------------------------------------------------------
144cdf0e10cSrcweir 
close()145cdf0e10cSrcweir void SAL_CALL OPreparedStatement::close(  ) throw(SQLException, RuntimeException)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	{
149cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
150cdf0e10cSrcweir 		checkDisposed(OStatement_BASE::rBHelper.bDisposed);
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir 	dispose();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // -------------------------------------------------------------------------
157cdf0e10cSrcweir 
execute()158cdf0e10cSrcweir sal_Bool SAL_CALL OPreparedStatement::execute(  ) throw(SQLException, RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
161cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	SQLWarning	warning;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	// Reset warnings
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	clearWarnings ();
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	// Reset the statement handle, warning and saved Resultset
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	//	reset();
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	// Call SQLExecute
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	try {
177cdf0e10cSrcweir 		ADORecordset* pSet=NULL;
178cdf0e10cSrcweir 		CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet))
179cdf0e10cSrcweir 		m_RecordSet = WpADORecordset(pSet);
180cdf0e10cSrcweir 	}
181cdf0e10cSrcweir 	catch (SQLWarning& ex)
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 		// Save pointer to warning and save with ResultSet
185cdf0e10cSrcweir 		// object once it is created.
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 		warning = ex;
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 	return m_RecordSet.IsValid();
190cdf0e10cSrcweir }
191cdf0e10cSrcweir // -------------------------------------------------------------------------
192cdf0e10cSrcweir 
executeUpdate()193cdf0e10cSrcweir sal_Int32 SAL_CALL OPreparedStatement::executeUpdate(  ) throw(SQLException, RuntimeException)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
196cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 	ADORecordset* pSet=NULL;
200cdf0e10cSrcweir 	CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet))
201cdf0e10cSrcweir 	if ( VT_ERROR == m_RecordsAffected.getType() )
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		ADOS::ThrowException(*m_pConnection->getConnection(),*this);
204cdf0e10cSrcweir 		// to be sure that we get the error really thrown
205cdf0e10cSrcweir 		throw SQLException();
206cdf0e10cSrcweir 	}
207cdf0e10cSrcweir 	m_RecordSet = WpADORecordset(pSet);
208cdf0e10cSrcweir 	return  static_cast<sal_Int32>(m_RecordsAffected);
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir // -------------------------------------------------------------------------
setParameter(sal_Int32 parameterIndex,const DataTypeEnum & _eType,const sal_Int32 & _nSize,const OLEVariant & _Val)212cdf0e10cSrcweir void OPreparedStatement::setParameter(sal_Int32 parameterIndex, const DataTypeEnum& _eType,
213cdf0e10cSrcweir 									  const sal_Int32& _nSize,const OLEVariant& _Val) throw(SQLException, RuntimeException)
214cdf0e10cSrcweir {
215cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
216cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	sal_Int32 nCount = 0;
220cdf0e10cSrcweir 	m_pParameters->get_Count(&nCount);
221cdf0e10cSrcweir 	if(nCount < (parameterIndex-1))
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		::rtl::OUString sDefaultName = ::rtl::OUString::createFromAscii("parame");
224cdf0e10cSrcweir 		sDefaultName += ::rtl::OUString::valueOf(parameterIndex);
225cdf0e10cSrcweir 		ADOParameter* pParam = m_Command.CreateParameter(sDefaultName,_eType,adParamInput,_nSize,_Val);
226cdf0e10cSrcweir 		if(pParam)
227cdf0e10cSrcweir 		{
228cdf0e10cSrcweir 			m_pParameters->Append(pParam);
229cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
230cdf0e10cSrcweir 			ADOParameter* pParam = NULL;
231cdf0e10cSrcweir 			m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&pParam);
232cdf0e10cSrcweir 			WpADOParameter aParam(pParam);
233cdf0e10cSrcweir 			if(pParam)
234cdf0e10cSrcweir 			{
235cdf0e10cSrcweir 				DataTypeEnum eType = aParam.GetADOType();
236cdf0e10cSrcweir                 (void)eType;
237cdf0e10cSrcweir 			}
238cdf0e10cSrcweir #endif
239cdf0e10cSrcweir 		}
240cdf0e10cSrcweir 	}
241cdf0e10cSrcweir 	else
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		ADOParameter* pParam = NULL;
244cdf0e10cSrcweir 		m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&pParam);
245cdf0e10cSrcweir 		WpADOParameter aParam(pParam);
246cdf0e10cSrcweir 		if(pParam)
247cdf0e10cSrcweir 		{
248cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
249cdf0e10cSrcweir 			::rtl::OUString sParam = aParam.GetName();
250cdf0e10cSrcweir 
251cdf0e10cSrcweir #endif // OSL_DEBUG_LEVEL
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 			DataTypeEnum eType = aParam.GetADOType();
254cdf0e10cSrcweir 			if ( _eType != eType && _eType != adDBTimeStamp )
255cdf0e10cSrcweir 			{
256cdf0e10cSrcweir 				aParam.put_Type(_eType);
257cdf0e10cSrcweir 				eType = _eType;
258cdf0e10cSrcweir 				aParam.put_Size(_nSize);
259cdf0e10cSrcweir 			}
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 			if ( adVarBinary == eType && aParam.GetAttributes() == adParamLong )
262cdf0e10cSrcweir 			{
263cdf0e10cSrcweir 				aParam.AppendChunk(_Val);
264cdf0e10cSrcweir 			}
265cdf0e10cSrcweir 			else
266cdf0e10cSrcweir 				CHECK_RETURN(aParam.PutValue(_Val));
267cdf0e10cSrcweir 		}
268cdf0e10cSrcweir 	}
269cdf0e10cSrcweir 	ADOS::ThrowException(*m_pConnection->getConnection(),*this);
270cdf0e10cSrcweir }
271cdf0e10cSrcweir // -------------------------------------------------------------------------
setString(sal_Int32 parameterIndex,const::rtl::OUString & x)272cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     setParameter( parameterIndex, adLongVarWChar, ::std::numeric_limits< sal_Int32 >::max(), x );
275cdf0e10cSrcweir }
276cdf0e10cSrcweir // -------------------------------------------------------------------------
277cdf0e10cSrcweir 
getConnection()278cdf0e10cSrcweir Reference< XConnection > SAL_CALL OPreparedStatement::getConnection(  ) throw(SQLException, RuntimeException)
279cdf0e10cSrcweir {
280cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
281cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 	return (Reference< XConnection >)m_pConnection;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir // -------------------------------------------------------------------------
287cdf0e10cSrcweir 
executeQuery()288cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery(  ) throw(SQLException, RuntimeException)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
291cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 	// first clear the old things
295cdf0e10cSrcweir m_xMetaData.clear();
296cdf0e10cSrcweir 	disposeResultSet();
297cdf0e10cSrcweir 	if(m_RecordSet.IsValid())
298cdf0e10cSrcweir 		m_RecordSet.Close();
299cdf0e10cSrcweir 	m_RecordSet.clear();
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 	// the create the new onces
303cdf0e10cSrcweir 	m_RecordSet.Create();
304cdf0e10cSrcweir 	OLEVariant aCmd;
305cdf0e10cSrcweir 	aCmd.setIDispatch(m_Command);
306cdf0e10cSrcweir 	OLEVariant aCon;
307cdf0e10cSrcweir 	aCon.setNoArg();
308cdf0e10cSrcweir 	CHECK_RETURN(m_RecordSet.put_CacheSize(m_nFetchSize))
309cdf0e10cSrcweir 	CHECK_RETURN(m_RecordSet.put_MaxRecords(m_nMaxRows))
310cdf0e10cSrcweir 	CHECK_RETURN(m_RecordSet.Open(aCmd,aCon,m_eCursorType,m_eLockType,adOpenUnspecified))
311cdf0e10cSrcweir 	CHECK_RETURN(m_RecordSet.get_CacheSize(m_nFetchSize))
312cdf0e10cSrcweir 	CHECK_RETURN(m_RecordSet.get_MaxRecords(m_nMaxRows))
313cdf0e10cSrcweir 	CHECK_RETURN(m_RecordSet.get_CursorType(m_eCursorType))
314cdf0e10cSrcweir 	CHECK_RETURN(m_RecordSet.get_LockType(m_eLockType))
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 	OResultSet* pSet = new OResultSet(m_RecordSet,this);
317cdf0e10cSrcweir 	Reference< XResultSet > xRs = pSet;
318cdf0e10cSrcweir 	pSet->construct();
319cdf0e10cSrcweir     pSet->setMetaData(getMetaData());
320cdf0e10cSrcweir 	m_xResultSet = WeakReference<XResultSet>(xRs);
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 	return xRs;
323cdf0e10cSrcweir }
324cdf0e10cSrcweir // -------------------------------------------------------------------------
325cdf0e10cSrcweir 
setBoolean(sal_Int32 parameterIndex,sal_Bool x)326cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException)
327cdf0e10cSrcweir {
328cdf0e10cSrcweir 	setParameter(parameterIndex,adBoolean,sizeof(x),x);
329cdf0e10cSrcweir }
330cdf0e10cSrcweir // -------------------------------------------------------------------------
331cdf0e10cSrcweir 
setByte(sal_Int32 parameterIndex,sal_Int8 x)332cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 	setParameter(parameterIndex,adTinyInt,sizeof(x),x);
335cdf0e10cSrcweir }
336cdf0e10cSrcweir // -------------------------------------------------------------------------
337cdf0e10cSrcweir 
setDate(sal_Int32 parameterIndex,const Date & x)338cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& x ) throw(SQLException, RuntimeException)
339cdf0e10cSrcweir {
340cdf0e10cSrcweir 	setParameter(parameterIndex,adDBDate,sizeof(x),x);
341cdf0e10cSrcweir }
342cdf0e10cSrcweir // -------------------------------------------------------------------------
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 
setTime(sal_Int32 parameterIndex,const Time & x)345cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& x ) throw(SQLException, RuntimeException)
346cdf0e10cSrcweir {
347cdf0e10cSrcweir 	setParameter(parameterIndex,adDBTime,sizeof(x),x);
348cdf0e10cSrcweir }
349cdf0e10cSrcweir // -------------------------------------------------------------------------
350cdf0e10cSrcweir 
setTimestamp(sal_Int32 parameterIndex,const DateTime & x)351cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& x ) throw(SQLException, RuntimeException)
352cdf0e10cSrcweir {
353cdf0e10cSrcweir 	setParameter(parameterIndex,adDBTimeStamp,sizeof(x),x);
354cdf0e10cSrcweir }
355cdf0e10cSrcweir // -------------------------------------------------------------------------
356cdf0e10cSrcweir 
setDouble(sal_Int32 parameterIndex,double x)357cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException)
358cdf0e10cSrcweir {
359cdf0e10cSrcweir 	setParameter(parameterIndex,adDouble,sizeof(x),x);
360cdf0e10cSrcweir }
361cdf0e10cSrcweir // -------------------------------------------------------------------------
362cdf0e10cSrcweir 
setFloat(sal_Int32 parameterIndex,float x)363cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir 	setParameter(parameterIndex,adSingle,sizeof(x),x);
366cdf0e10cSrcweir }
367cdf0e10cSrcweir // -------------------------------------------------------------------------
368cdf0e10cSrcweir 
setInt(sal_Int32 parameterIndex,sal_Int32 x)369cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
370cdf0e10cSrcweir {
371cdf0e10cSrcweir 	setParameter(parameterIndex,adInteger,sizeof(x),x);
372cdf0e10cSrcweir }
373cdf0e10cSrcweir // -------------------------------------------------------------------------
374cdf0e10cSrcweir 
setLong(sal_Int32 parameterIndex,sal_Int64 x)375cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
376cdf0e10cSrcweir {
377cdf0e10cSrcweir 	setParameter(parameterIndex,adBigInt,sizeof(x),x);
378cdf0e10cSrcweir }
379cdf0e10cSrcweir // -------------------------------------------------------------------------
380cdf0e10cSrcweir 
setNull(sal_Int32 parameterIndex,sal_Int32)381cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
382cdf0e10cSrcweir {
383cdf0e10cSrcweir 	OLEVariant aVal;
384cdf0e10cSrcweir 	aVal.setNull();
385cdf0e10cSrcweir 	setParameter(parameterIndex,adEmpty,0,aVal);
386cdf0e10cSrcweir }
387cdf0e10cSrcweir // -------------------------------------------------------------------------
388cdf0e10cSrcweir 
setClob(sal_Int32,const Reference<XClob> &)389cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
390cdf0e10cSrcweir {
391cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::setClob", *this );
392cdf0e10cSrcweir }
393cdf0e10cSrcweir // -------------------------------------------------------------------------
394cdf0e10cSrcweir 
setBlob(sal_Int32,const Reference<XBlob> &)395cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
396cdf0e10cSrcweir {
397cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::setBlob", *this );
398cdf0e10cSrcweir }
399cdf0e10cSrcweir // -------------------------------------------------------------------------
400cdf0e10cSrcweir 
setArray(sal_Int32,const Reference<XArray> &)401cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
402cdf0e10cSrcweir {
403cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::setArray", *this );
404cdf0e10cSrcweir }
405cdf0e10cSrcweir // -------------------------------------------------------------------------
406cdf0e10cSrcweir 
setRef(sal_Int32,const Reference<XRef> &)407cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
408cdf0e10cSrcweir {
409cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::setRef", *this );
410cdf0e10cSrcweir }
411cdf0e10cSrcweir // -------------------------------------------------------------------------
412cdf0e10cSrcweir 
setObjectWithInfo(sal_Int32 parameterIndex,const Any & x,sal_Int32 sqlType,sal_Int32 scale)413cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException)
414cdf0e10cSrcweir {
415cdf0e10cSrcweir     switch(sqlType)
416cdf0e10cSrcweir 	{
417cdf0e10cSrcweir         case DataType::DECIMAL:
418cdf0e10cSrcweir         case DataType::NUMERIC:
419cdf0e10cSrcweir             setString(parameterIndex,::comphelper::getString(x));
420cdf0e10cSrcweir             break;
421cdf0e10cSrcweir         default:
422cdf0e10cSrcweir             ::dbtools::setObjectWithInfo(this,parameterIndex,x,sqlType,scale);
423cdf0e10cSrcweir             break;
424cdf0e10cSrcweir     }
425cdf0e10cSrcweir }
426cdf0e10cSrcweir // -------------------------------------------------------------------------
427cdf0e10cSrcweir 
setObjectNull(sal_Int32 parameterIndex,sal_Int32 sqlType,const::rtl::OUString &)428cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
429cdf0e10cSrcweir {
430cdf0e10cSrcweir 	setNull(parameterIndex,sqlType);
431cdf0e10cSrcweir }
432cdf0e10cSrcweir // -------------------------------------------------------------------------
433cdf0e10cSrcweir 
setObject(sal_Int32 parameterIndex,const Any & x)434cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
435cdf0e10cSrcweir {
436cdf0e10cSrcweir     if(!::dbtools::implSetObject(this,parameterIndex,x))
437cdf0e10cSrcweir 	{
438cdf0e10cSrcweir         const ::rtl::OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
439cdf0e10cSrcweir                 STR_UNKNOWN_PARA_TYPE,
440cdf0e10cSrcweir                 "$position$", ::rtl::OUString::valueOf(parameterIndex)
441cdf0e10cSrcweir              ) );
442cdf0e10cSrcweir 		::dbtools::throwGenericSQLException(sError,*this);
443cdf0e10cSrcweir 	}
444cdf0e10cSrcweir 	//	setObject (parameterIndex, x, sqlType, 0);
445cdf0e10cSrcweir }
446cdf0e10cSrcweir // -------------------------------------------------------------------------
447cdf0e10cSrcweir 
setShort(sal_Int32 parameterIndex,sal_Int16 x)448cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir 	setParameter(parameterIndex,adSmallInt,sizeof(x),x);
451cdf0e10cSrcweir }
452cdf0e10cSrcweir // -------------------------------------------------------------------------
453cdf0e10cSrcweir 
setBytes(sal_Int32 parameterIndex,const Sequence<sal_Int8> & x)454cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
455cdf0e10cSrcweir {
456cdf0e10cSrcweir 	setParameter(parameterIndex,adVarBinary,sizeof(sal_Int8)*x.getLength(),x);
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir // -------------------------------------------------------------------------
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 
setCharacterStream(sal_Int32,const Reference<::com::sun::star::io::XInputStream> &,sal_Int32)462cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 /*parameterIndex*/, const Reference< ::com::sun::star::io::XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
463cdf0e10cSrcweir {
464cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XParameters::setCharacterStream", *this );
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir // -------------------------------------------------------------------------
468cdf0e10cSrcweir 
setBinaryStream(sal_Int32 parameterIndex,const Reference<::com::sun::star::io::XInputStream> & x,sal_Int32 length)469cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir 	if(x.is())
472cdf0e10cSrcweir 	{
473cdf0e10cSrcweir 		Sequence< sal_Int8 > aData;
474cdf0e10cSrcweir 		x->readBytes(aData,length);
475cdf0e10cSrcweir 		setBytes(parameterIndex,aData);
476cdf0e10cSrcweir 	}
477cdf0e10cSrcweir }
478cdf0e10cSrcweir // -------------------------------------------------------------------------
479cdf0e10cSrcweir 
clearParameters()480cdf0e10cSrcweir void SAL_CALL OPreparedStatement::clearParameters(  ) throw(SQLException, RuntimeException)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
483cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 	if(m_pParameters)
487cdf0e10cSrcweir 	{
488cdf0e10cSrcweir 		sal_Int32 nCount = 0;
489cdf0e10cSrcweir 		m_pParameters->get_Count(&nCount);
490cdf0e10cSrcweir 		OLEVariant aVal;
491cdf0e10cSrcweir 		aVal.setEmpty();
492cdf0e10cSrcweir 		for(sal_Int32 i=0;i<nCount;++i)
493cdf0e10cSrcweir 		{
494cdf0e10cSrcweir 			ADOParameter* pParam = NULL;
495cdf0e10cSrcweir 			m_pParameters->get_Item(OLEVariant(i),&pParam);
496cdf0e10cSrcweir 			WpADOParameter aParam(pParam);
497cdf0e10cSrcweir 			if(pParam)
498cdf0e10cSrcweir 			{
499cdf0e10cSrcweir 				::rtl::OUString sParam = aParam.GetName();
500cdf0e10cSrcweir 				CHECK_RETURN(aParam.PutValue(aVal));
501cdf0e10cSrcweir 			}
502cdf0e10cSrcweir 		}
503cdf0e10cSrcweir 			//	m_pParameters->Delete(OLEVariant(i));
504cdf0e10cSrcweir 
505cdf0e10cSrcweir 	}
506cdf0e10cSrcweir }
507cdf0e10cSrcweir // -------------------------------------------------------------------------
clearBatch()508cdf0e10cSrcweir void SAL_CALL OPreparedStatement::clearBatch(  ) throw(SQLException, RuntimeException)
509cdf0e10cSrcweir {
510cdf0e10cSrcweir 	//	clearParameters(  );
511cdf0e10cSrcweir 	//	m_aBatchList.erase();
512cdf0e10cSrcweir }
513cdf0e10cSrcweir // -------------------------------------------------------------------------
514cdf0e10cSrcweir 
addBatch()515cdf0e10cSrcweir void SAL_CALL OPreparedStatement::addBatch( ) throw(SQLException, RuntimeException)
516cdf0e10cSrcweir {
517cdf0e10cSrcweir }
518cdf0e10cSrcweir // -------------------------------------------------------------------------
519cdf0e10cSrcweir 
executeBatch()520cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch(  ) throw(SQLException, RuntimeException)
521cdf0e10cSrcweir {
522cdf0e10cSrcweir 	return Sequence< sal_Int32 > ();
523cdf0e10cSrcweir }
524cdf0e10cSrcweir // -----------------------------------------------------------------------------
525cdf0e10cSrcweir // -----------------------------------------------------------------------------
acquire()526cdf0e10cSrcweir void SAL_CALL OPreparedStatement::acquire() throw()
527cdf0e10cSrcweir {
528cdf0e10cSrcweir 	OStatement_Base::acquire();
529cdf0e10cSrcweir }
530cdf0e10cSrcweir // -----------------------------------------------------------------------------
release()531cdf0e10cSrcweir void SAL_CALL OPreparedStatement::release() throw()
532cdf0e10cSrcweir {
533cdf0e10cSrcweir 	OStatement_Base::release();
534cdf0e10cSrcweir }
535cdf0e10cSrcweir // -----------------------------------------------------------------------------
replaceParameterNodeName(OSQLParseNode * _pNode,const::rtl::OUString & _sDefaultName,sal_Int32 & _rParameterCount)536cdf0e10cSrcweir void OPreparedStatement::replaceParameterNodeName(OSQLParseNode* _pNode,
537cdf0e10cSrcweir 												  const ::rtl::OUString& _sDefaultName,
538cdf0e10cSrcweir 												  sal_Int32& _rParameterCount)
539cdf0e10cSrcweir {
540cdf0e10cSrcweir 	sal_Int32 nCount = _pNode->count();
541cdf0e10cSrcweir 	for(sal_Int32 i=0;i < nCount;++i)
542cdf0e10cSrcweir 	{
543cdf0e10cSrcweir 		OSQLParseNode* pChildNode = _pNode->getChild(i);
544cdf0e10cSrcweir 		if(SQL_ISRULE(pChildNode,parameter) && pChildNode->count() == 1)
545cdf0e10cSrcweir 		{
546cdf0e10cSrcweir 			OSQLParseNode* pNewNode = new OSQLParseNode(::rtl::OUString::createFromAscii(":") ,SQL_NODE_PUNCTUATION,0);
547cdf0e10cSrcweir 			delete pChildNode->replace(pChildNode->getChild(0),pNewNode);
548cdf0e10cSrcweir 			::rtl::OUString sParameterName = _sDefaultName;
549cdf0e10cSrcweir 			sParameterName += ::rtl::OUString::valueOf(++_rParameterCount);
550cdf0e10cSrcweir 			pChildNode->append(new OSQLParseNode( sParameterName,SQL_NODE_NAME,0));
551cdf0e10cSrcweir 		}
552cdf0e10cSrcweir 		else
553cdf0e10cSrcweir 			replaceParameterNodeName(pChildNode,_sDefaultName,_rParameterCount);
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 	}
556cdf0e10cSrcweir }
557cdf0e10cSrcweir // -----------------------------------------------------------------------------
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 
561