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