2000-09-18 15:18:56 +00:00
|
|
|
|
/*************************************************************************
|
|
|
|
|
*
|
2008-04-10 07:22:12 +00:00
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 15:18:56 +00:00
|
|
|
|
*
|
2008-04-10 07:22:12 +00:00
|
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-09-18 15:18:56 +00:00
|
|
|
|
*
|
2008-04-10 07:22:12 +00:00
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
|
*
|
2008-04-10 07:22:12 +00:00
|
|
|
|
* $RCSfile: APreparedStatement.cxx,v $
|
2008-06-25 10:41:04 +00:00
|
|
|
|
* $Revision: 1.27 $
|
2000-09-18 15:18:56 +00:00
|
|
|
|
*
|
2008-04-10 07:22:12 +00:00
|
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 15:18:56 +00:00
|
|
|
|
*
|
2008-04-10 07:22:12 +00:00
|
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
|
*
|
2008-04-10 07:22:12 +00:00
|
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 15:18:56 +00:00
|
|
|
|
*
|
2008-04-10 07:22:12 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 15:18:56 +00:00
|
|
|
|
*
|
|
|
|
|
************************************************************************/
|
2001-09-28 06:00:09 +00:00
|
|
|
|
|
2006-09-17 01:14:52 +00:00
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
|
#include "precompiled_connectivity.hxx"
|
2001-09-28 06:00:09 +00:00
|
|
|
|
#include "connectivity/sqlparse.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
|
#include "ado/APreparedStatement.hxx"
|
|
|
|
|
#include <com/sun/star/sdbc/DataType.hpp>
|
|
|
|
|
#include "ado/AResultSetMetaData.hxx"
|
|
|
|
|
#include "ado/AResultSet.hxx"
|
2001-09-28 06:00:09 +00:00
|
|
|
|
#include "ado/ADriver.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
|
#include <com/sun/star/lang/DisposedException.hpp>
|
|
|
|
|
#include <cppuhelper/typeprovider.hxx>
|
2000-10-09 10:26:03 +00:00
|
|
|
|
#include <comphelper/sequence.hxx>
|
2001-05-14 10:42:44 +00:00
|
|
|
|
#include "connectivity/dbexception.hxx"
|
2008-01-30 06:49:46 +00:00
|
|
|
|
#include "connectivity/dbtools.hxx"
|
2009-04-23 10:42:05 +00:00
|
|
|
|
#include "resource/ado_res.hrc"
|
2001-09-28 06:00:09 +00:00
|
|
|
|
|
2008-06-25 10:41:04 +00:00
|
|
|
|
#include <limits>
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
#define CHECK_RETURN(x) \
|
|
|
|
|
if(!x) \
|
|
|
|
|
ADOS::ThrowException(*m_pConnection->getConnection(),*this);
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
using namespace connectivity::ado;
|
|
|
|
|
using namespace connectivity;
|
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
|
using namespace com::sun::star::beans;
|
|
|
|
|
using namespace com::sun::star::sdbc;
|
|
|
|
|
using namespace com::sun::star::util;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.APreparedStatement","com.sun.star.sdbc.PreparedStatement");
|
|
|
|
|
|
2001-04-12 11:33:30 +00:00
|
|
|
|
OPreparedStatement::OPreparedStatement( OConnection* _pConnection,const OTypeInfoMap& _TypeInfo,const ::rtl::OUString& sql)
|
|
|
|
|
: OStatement_Base( _pConnection )
|
|
|
|
|
,m_aTypeInfo(_TypeInfo)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
|
|
|
|
osl_incrementInterlockedCount( &m_refCount );
|
|
|
|
|
|
2001-09-28 06:00:09 +00:00
|
|
|
|
OSQLParser aParser(_pConnection->getDriver()->getORB());
|
|
|
|
|
::rtl::OUString sErrorMessage;
|
|
|
|
|
::rtl::OUString sNewSql;
|
|
|
|
|
OSQLParseNode* pNode = aParser.parseTree(sErrorMessage,sql);
|
|
|
|
|
if(pNode)
|
|
|
|
|
{ // special handling for parameters
|
2005-02-16 16:23:30 +00:00
|
|
|
|
/* we recusive replace all occurences of ? in the statement and replace them with name like "<22><><EFBFBD>" */
|
2001-09-28 06:00:09 +00:00
|
|
|
|
sal_Int32 nParameterCount = 0;
|
|
|
|
|
::rtl::OUString sDefaultName = ::rtl::OUString::createFromAscii("parame");
|
|
|
|
|
replaceParameterNodeName(pNode,sDefaultName,nParameterCount);
|
2006-12-13 15:15:25 +00:00
|
|
|
|
pNode->parseNodeToStr( sNewSql, _pConnection );
|
2001-09-28 06:00:09 +00:00
|
|
|
|
delete pNode;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
sNewSql = sql;
|
|
|
|
|
CHECK_RETURN(m_Command.put_CommandText(sNewSql))
|
2000-09-18 15:18:56 +00:00
|
|
|
|
CHECK_RETURN(m_Command.put_Prepared(VARIANT_TRUE))
|
|
|
|
|
m_pParameters = m_Command.get_Parameters();
|
|
|
|
|
m_pParameters->AddRef();
|
|
|
|
|
m_pParameters->Refresh();
|
|
|
|
|
|
|
|
|
|
osl_decrementInterlockedCount( &m_refCount );
|
|
|
|
|
}
|
2002-01-18 15:35:28 +00:00
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
OPreparedStatement::~OPreparedStatement()
|
|
|
|
|
{
|
|
|
|
|
if (m_pParameters)
|
|
|
|
|
{
|
|
|
|
|
OSL_ENSURE( sal_False, "OPreparedStatement::~OPreparedStatement: not disposed!" );
|
|
|
|
|
m_pParameters->Release();
|
|
|
|
|
m_pParameters = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
Any aRet = OStatement_Base::queryInterface(rType);
|
2001-08-24 05:19:41 +00:00
|
|
|
|
return aRet.hasValue() ? aRet : ::cppu::queryInterface( rType,
|
2000-09-18 15:18:56 +00:00
|
|
|
|
static_cast< XPreparedStatement*>(this),
|
|
|
|
|
static_cast< XParameters*>(this),
|
|
|
|
|
static_cast< XPreparedBatchExecution*>(this),
|
|
|
|
|
static_cast< XResultSetMetaDataSupplier*>(this));
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedStatement > *)0 ),
|
|
|
|
|
::getCppuType( (const ::com::sun::star::uno::Reference< XParameters > *)0 ),
|
|
|
|
|
::getCppuType( (const ::com::sun::star::uno::Reference< XResultSetMetaDataSupplier > *)0 ),
|
|
|
|
|
::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedBatchExecution > *)0 ));
|
|
|
|
|
|
2000-10-09 10:26:03 +00:00
|
|
|
|
return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_Base::getTypes());
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
2006-11-06 13:34:33 +00:00
|
|
|
|
if(!m_xMetaData.is() && m_RecordSet.IsValid())
|
2001-01-09 11:39:19 +00:00
|
|
|
|
m_xMetaData = new OResultSetMetaData(m_RecordSet);
|
|
|
|
|
return m_xMetaData;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
void OPreparedStatement::disposing()
|
|
|
|
|
{
|
2009-09-08 09:50:48 +00:00
|
|
|
|
m_xMetaData.clear();
|
2002-01-18 15:35:28 +00:00
|
|
|
|
if (m_pParameters)
|
|
|
|
|
{
|
2000-09-18 15:18:56 +00:00
|
|
|
|
m_pParameters->Release();
|
2002-01-18 15:35:28 +00:00
|
|
|
|
m_pParameters = NULL;
|
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
OStatement_Base::disposing();
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2001-05-17 06:30:42 +00:00
|
|
|
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
dispose();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2001-05-17 06:30:42 +00:00
|
|
|
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
|
SQLWarning warning;
|
|
|
|
|
|
|
|
|
|
// Reset warnings
|
|
|
|
|
|
|
|
|
|
clearWarnings ();
|
|
|
|
|
|
|
|
|
|
// Reset the statement handle, warning and saved Resultset
|
|
|
|
|
|
2001-04-12 11:33:30 +00:00
|
|
|
|
// reset();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
|
// Call SQLExecute
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ADORecordset* pSet=NULL;
|
|
|
|
|
CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet))
|
|
|
|
|
m_RecordSet = WpADORecordset(pSet);
|
|
|
|
|
}
|
|
|
|
|
catch (SQLWarning& ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Save pointer to warning and save with ResultSet
|
|
|
|
|
// object once it is created.
|
|
|
|
|
|
|
|
|
|
warning = ex;
|
|
|
|
|
}
|
|
|
|
|
return m_RecordSet.IsValid();
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2001-05-17 06:30:42 +00:00
|
|
|
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
|
ADORecordset* pSet=NULL;
|
|
|
|
|
CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet))
|
2003-05-22 09:49:26 +00:00
|
|
|
|
if ( VT_ERROR == m_RecordsAffected.getType() )
|
|
|
|
|
{
|
|
|
|
|
ADOS::ThrowException(*m_pConnection->getConnection(),*this);
|
|
|
|
|
// to be sure that we get the error really thrown
|
|
|
|
|
throw SQLException();
|
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
m_RecordSet = WpADORecordset(pSet);
|
2003-05-22 09:49:26 +00:00
|
|
|
|
return static_cast<sal_Int32>(m_RecordsAffected);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
void OPreparedStatement::setParameter(sal_Int32 parameterIndex, const DataTypeEnum& _eType,
|
|
|
|
|
const sal_Int32& _nSize,const OLEVariant& _Val) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2001-05-17 06:30:42 +00:00
|
|
|
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
|
sal_Int32 nCount = 0;
|
|
|
|
|
m_pParameters->get_Count(&nCount);
|
2001-12-11 08:10:12 +00:00
|
|
|
|
if(nCount < (parameterIndex-1))
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
2001-12-11 08:10:12 +00:00
|
|
|
|
::rtl::OUString sDefaultName = ::rtl::OUString::createFromAscii("parame");
|
|
|
|
|
sDefaultName += ::rtl::OUString::valueOf(parameterIndex);
|
|
|
|
|
ADOParameter* pParam = m_Command.CreateParameter(sDefaultName,_eType,adParamInput,_nSize,_Val);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
if(pParam)
|
2005-10-24 07:20:35 +00:00
|
|
|
|
{
|
2000-09-18 15:18:56 +00:00
|
|
|
|
m_pParameters->Append(pParam);
|
2005-10-24 07:20:35 +00:00
|
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
|
|
|
|
ADOParameter* pParam = NULL;
|
|
|
|
|
m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&pParam);
|
|
|
|
|
WpADOParameter aParam(pParam);
|
|
|
|
|
if(pParam)
|
|
|
|
|
{
|
|
|
|
|
DataTypeEnum eType = aParam.GetADOType();
|
2006-06-20 00:14:41 +00:00
|
|
|
|
(void)eType;
|
2005-10-24 07:20:35 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ADOParameter* pParam = NULL;
|
2001-04-12 11:33:30 +00:00
|
|
|
|
m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&pParam);
|
|
|
|
|
WpADOParameter aParam(pParam);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
if(pParam)
|
2001-04-12 11:33:30 +00:00
|
|
|
|
{
|
2003-04-15 16:36:21 +00:00
|
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2001-04-12 11:33:30 +00:00
|
|
|
|
::rtl::OUString sParam = aParam.GetName();
|
2003-05-22 09:49:26 +00:00
|
|
|
|
|
2003-04-15 16:36:21 +00:00
|
|
|
|
#endif // OSL_DEBUG_LEVEL
|
2003-05-22 09:49:26 +00:00
|
|
|
|
|
|
|
|
|
DataTypeEnum eType = aParam.GetADOType();
|
2005-10-24 07:20:35 +00:00
|
|
|
|
if ( _eType != eType && _eType != adDBTimeStamp )
|
2003-05-22 09:49:26 +00:00
|
|
|
|
{
|
|
|
|
|
aParam.put_Type(_eType);
|
2004-08-02 15:57:43 +00:00
|
|
|
|
eType = _eType;
|
2003-05-22 09:49:26 +00:00
|
|
|
|
aParam.put_Size(_nSize);
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-02 15:57:43 +00:00
|
|
|
|
if ( adVarBinary == eType && aParam.GetAttributes() == adParamLong )
|
2003-05-22 09:49:26 +00:00
|
|
|
|
{
|
|
|
|
|
aParam.AppendChunk(_Val);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
CHECK_RETURN(aParam.PutValue(_Val));
|
2001-04-12 11:33:30 +00:00
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
ADOS::ThrowException(*m_pConnection->getConnection(),*this);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
2008-06-25 10:41:04 +00:00
|
|
|
|
setParameter( parameterIndex, adLongVarWChar, ::std::numeric_limits< sal_Int32 >::max(), x );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2001-05-17 06:30:42 +00:00
|
|
|
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
|
return (Reference< XConnection >)m_pConnection;
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2001-05-17 06:30:42 +00:00
|
|
|
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
2001-04-12 11:33:30 +00:00
|
|
|
|
// first clear the old things
|
2009-09-08 09:50:48 +00:00
|
|
|
|
m_xMetaData.clear();
|
2001-04-12 11:33:30 +00:00
|
|
|
|
disposeResultSet();
|
|
|
|
|
if(m_RecordSet.IsValid())
|
|
|
|
|
m_RecordSet.Close();
|
|
|
|
|
m_RecordSet.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the create the new onces
|
|
|
|
|
m_RecordSet.Create();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
OLEVariant aCmd;
|
|
|
|
|
aCmd.setIDispatch(m_Command);
|
|
|
|
|
OLEVariant aCon;
|
|
|
|
|
aCon.setNoArg();
|
2001-04-12 11:33:30 +00:00
|
|
|
|
CHECK_RETURN(m_RecordSet.put_CacheSize(m_nFetchSize))
|
|
|
|
|
CHECK_RETURN(m_RecordSet.put_MaxRecords(m_nMaxRows))
|
|
|
|
|
CHECK_RETURN(m_RecordSet.Open(aCmd,aCon,m_eCursorType,m_eLockType,adOpenUnspecified))
|
|
|
|
|
CHECK_RETURN(m_RecordSet.get_CacheSize(m_nFetchSize))
|
|
|
|
|
CHECK_RETURN(m_RecordSet.get_MaxRecords(m_nMaxRows))
|
|
|
|
|
CHECK_RETURN(m_RecordSet.get_CursorType(m_eCursorType))
|
|
|
|
|
CHECK_RETURN(m_RecordSet.get_LockType(m_eLockType))
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
2001-04-12 11:33:30 +00:00
|
|
|
|
OResultSet* pSet = new OResultSet(m_RecordSet,this);
|
2005-12-21 12:15:13 +00:00
|
|
|
|
Reference< XResultSet > xRs = pSet;
|
|
|
|
|
pSet->construct();
|
2007-09-26 13:28:22 +00:00
|
|
|
|
pSet->setMetaData(getMetaData());
|
2005-12-21 12:15:13 +00:00
|
|
|
|
m_xResultSet = WeakReference<XResultSet>(xRs);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
2005-12-21 12:15:13 +00:00
|
|
|
|
return xRs;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adBoolean,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adTinyInt,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adDBDate,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adDBTime,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adDBTimeStamp,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adDouble,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adSingle,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adInteger,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adBigInt,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2006-06-20 00:14:41 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
|
|
|
|
OLEVariant aVal;
|
|
|
|
|
aVal.setNull();
|
|
|
|
|
setParameter(parameterIndex,adEmpty,0,aVal);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2006-06-20 00:14:41 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
2006-06-20 00:14:41 +00:00
|
|
|
|
::dbtools::throwFeatureNotImplementedException( "XRowUpdate::setClob", *this );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2006-06-20 00:14:41 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
2006-06-20 00:14:41 +00:00
|
|
|
|
::dbtools::throwFeatureNotImplementedException( "XRowUpdate::setBlob", *this );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2006-06-20 00:14:41 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
2006-06-20 00:14:41 +00:00
|
|
|
|
::dbtools::throwFeatureNotImplementedException( "XRowUpdate::setArray", *this );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2006-06-20 00:14:41 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
2006-06-20 00:14:41 +00:00
|
|
|
|
::dbtools::throwFeatureNotImplementedException( "XRowUpdate::setRef", *this );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2008-01-30 06:49:46 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
2008-01-30 06:49:46 +00:00
|
|
|
|
switch(sqlType)
|
|
|
|
|
{
|
|
|
|
|
case DataType::DECIMAL:
|
|
|
|
|
case DataType::NUMERIC:
|
|
|
|
|
setString(parameterIndex,::comphelper::getString(x));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
::dbtools::setObjectWithInfo(this,parameterIndex,x,sqlType,scale);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2006-06-20 00:14:41 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
|
|
|
|
setNull(parameterIndex,sqlType);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2009-04-23 10:42:05 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
2009-04-23 10:42:05 +00:00
|
|
|
|
if(!::dbtools::implSetObject(this,parameterIndex,x))
|
|
|
|
|
{
|
|
|
|
|
const ::rtl::OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
|
|
|
|
|
STR_UNKNOWN_PARA_TYPE,
|
|
|
|
|
"$position$", ::rtl::OUString::valueOf(parameterIndex)
|
|
|
|
|
) );
|
|
|
|
|
::dbtools::throwGenericSQLException(sError,*this);
|
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
// setObject (parameterIndex, x, sqlType, 0);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adSmallInt,sizeof(x),x);
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
setParameter(parameterIndex,adVarBinary,sizeof(sal_Int8)*x.getLength(),x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 00:14:41 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 /*parameterIndex*/, const Reference< ::com::sun::star::io::XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
{
|
2006-06-20 00:14:41 +00:00
|
|
|
|
::dbtools::throwFeatureNotImplementedException( "XParameters::setCharacterStream", *this );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
2006-06-20 00:14:41 +00:00
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
2001-04-12 11:33:30 +00:00
|
|
|
|
if(x.is())
|
|
|
|
|
{
|
|
|
|
|
Sequence< sal_Int8 > aData;
|
|
|
|
|
x->readBytes(aData,length);
|
|
|
|
|
setBytes(parameterIndex,aData);
|
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::clearParameters( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2001-05-17 06:30:42 +00:00
|
|
|
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
|
if(m_pParameters)
|
|
|
|
|
{
|
|
|
|
|
sal_Int32 nCount = 0;
|
|
|
|
|
m_pParameters->get_Count(&nCount);
|
2001-12-11 08:10:12 +00:00
|
|
|
|
OLEVariant aVal;
|
|
|
|
|
aVal.setEmpty();
|
|
|
|
|
for(sal_Int32 i=0;i<nCount;++i)
|
|
|
|
|
{
|
|
|
|
|
ADOParameter* pParam = NULL;
|
|
|
|
|
m_pParameters->get_Item(OLEVariant(i),&pParam);
|
|
|
|
|
WpADOParameter aParam(pParam);
|
|
|
|
|
if(pParam)
|
|
|
|
|
{
|
|
|
|
|
::rtl::OUString sParam = aParam.GetName();
|
|
|
|
|
CHECK_RETURN(aParam.PutValue(aVal));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// m_pParameters->Delete(OLEVariant(i));
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
void SAL_CALL OPreparedStatement::clearBatch( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
// clearParameters( );
|
|
|
|
|
// m_aBatchList.erase();
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void SAL_CALL OPreparedStatement::addBatch( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch( ) throw(SQLException, RuntimeException)
|
|
|
|
|
{
|
|
|
|
|
return Sequence< sal_Int32 > ();
|
|
|
|
|
}
|
2001-04-12 11:33:30 +00:00
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-04-30 09:16:19 +00:00
|
|
|
|
// -----------------------------------------------------------------------------
|
2007-03-26 12:57:34 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::acquire() throw()
|
2001-04-30 09:16:19 +00:00
|
|
|
|
{
|
|
|
|
|
OStatement_Base::acquire();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2007-03-26 12:57:34 +00:00
|
|
|
|
void SAL_CALL OPreparedStatement::release() throw()
|
2001-04-30 09:16:19 +00:00
|
|
|
|
{
|
|
|
|
|
OStatement_Base::release();
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-09-28 06:00:09 +00:00
|
|
|
|
void OPreparedStatement::replaceParameterNodeName(OSQLParseNode* _pNode,
|
|
|
|
|
const ::rtl::OUString& _sDefaultName,
|
|
|
|
|
sal_Int32& _rParameterCount)
|
|
|
|
|
{
|
|
|
|
|
sal_Int32 nCount = _pNode->count();
|
|
|
|
|
for(sal_Int32 i=0;i < nCount;++i)
|
|
|
|
|
{
|
|
|
|
|
OSQLParseNode* pChildNode = _pNode->getChild(i);
|
|
|
|
|
if(SQL_ISRULE(pChildNode,parameter) && pChildNode->count() == 1)
|
|
|
|
|
{
|
|
|
|
|
OSQLParseNode* pNewNode = new OSQLParseNode(::rtl::OUString::createFromAscii(":") ,SQL_NODE_PUNCTUATION,0);
|
|
|
|
|
delete pChildNode->replace(pChildNode->getChild(0),pNewNode);
|
|
|
|
|
::rtl::OUString sParameterName = _sDefaultName;
|
|
|
|
|
sParameterName += ::rtl::OUString::valueOf(++_rParameterCount);
|
|
|
|
|
pChildNode->append(new OSQLParseNode( sParameterName,SQL_NODE_NAME,0));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
replaceParameterNodeName(pChildNode,_sDefaultName,_rParameterCount);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-04-12 11:33:30 +00:00
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
|
|