2013-05-10 18:21:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2013-07-26 20:11:41 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2013-05-10 18:21:30 +00:00
|
|
|
*
|
2013-07-26 20:11:41 +02:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2013-05-10 18:21:30 +00:00
|
|
|
*
|
2013-07-26 20:11:41 +02:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2013-05-10 18:21:30 +00:00
|
|
|
*
|
2013-07-26 20:11:41 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2013-05-10 18:21:30 +00:00
|
|
|
|
2013-07-31 16:03:29 +02:00
|
|
|
#include "Connection.hxx"
|
|
|
|
#include "Driver.hxx"
|
|
|
|
#include "ResultSet.hxx"
|
|
|
|
#include "Statement.hxx"
|
2013-07-22 13:29:02 +02:00
|
|
|
#include "Util.hxx"
|
2013-07-17 17:00:18 +02:00
|
|
|
|
2013-07-23 19:04:33 +02:00
|
|
|
#include <comphelper/sequence.hxx>
|
2013-07-17 17:00:18 +02:00
|
|
|
#include <osl/diagnose.h>
|
2013-05-10 18:21:30 +00:00
|
|
|
#include <osl/thread.h>
|
2013-07-17 17:00:18 +02:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
|
2013-07-31 16:03:29 +02:00
|
|
|
#include <com/sun/star/lang/DisposedException.hpp>
|
2013-05-10 18:21:30 +00:00
|
|
|
#include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
|
|
|
|
#include <com/sun/star/sdbc/ResultSetType.hpp>
|
|
|
|
#include <com/sun/star/sdbc/FetchDirection.hpp>
|
|
|
|
|
|
|
|
using namespace connectivity::firebird;
|
2013-07-17 17:00:18 +02:00
|
|
|
|
|
|
|
using namespace com::sun::star;
|
2013-05-10 18:21:30 +00:00
|
|
|
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::sdbcx;
|
|
|
|
using namespace com::sun::star::container;
|
|
|
|
using namespace com::sun::star::io;
|
|
|
|
using namespace com::sun::star::util;
|
2013-06-04 13:54:48 +00:00
|
|
|
|
2013-07-17 17:00:18 +02:00
|
|
|
using namespace ::comphelper;
|
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::rtl;
|
|
|
|
using namespace ::std;
|
2013-06-04 13:54:48 +00:00
|
|
|
|
2013-07-17 17:00:18 +02:00
|
|
|
// ---- XBatchExecution - UNSUPPORTED ----------------------------------------
|
|
|
|
void SAL_CALL OStatement::addBatch(const OUString& sql)
|
|
|
|
throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
(void) sql;
|
|
|
|
}
|
2013-05-10 18:21:30 +00:00
|
|
|
|
2013-07-17 17:00:18 +02:00
|
|
|
void SAL_CALL OStatement::clearBatch() throw(SQLException, RuntimeException)
|
|
|
|
{
|
2013-05-10 18:21:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 17:00:18 +02:00
|
|
|
Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch() throw(SQLException, RuntimeException)
|
2013-05-10 18:21:30 +00:00
|
|
|
{
|
2013-07-17 17:00:18 +02:00
|
|
|
return Sequence< sal_Int32 >();
|
|
|
|
}
|
2013-05-10 18:21:30 +00:00
|
|
|
|
|
|
|
IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
|
2013-07-17 17:00:18 +02:00
|
|
|
|
2013-05-10 18:21:30 +00:00
|
|
|
void SAL_CALL OStatement::acquire() throw()
|
|
|
|
{
|
2013-07-23 19:04:33 +02:00
|
|
|
OStatementCommonBase::acquire();
|
2013-05-10 18:21:30 +00:00
|
|
|
}
|
2013-07-17 17:00:18 +02:00
|
|
|
|
2013-05-10 18:21:30 +00:00
|
|
|
void SAL_CALL OStatement::release() throw()
|
|
|
|
{
|
2013-07-23 19:04:33 +02:00
|
|
|
OStatementCommonBase::release();
|
2013-05-10 18:21:30 +00:00
|
|
|
}
|
2013-07-23 16:06:54 +02:00
|
|
|
|
2013-07-23 17:24:12 +02:00
|
|
|
// ---- XStatement -----------------------------------------------------------
|
2013-07-24 20:06:32 +02:00
|
|
|
sal_Int32 SAL_CALL OStatement::executeUpdate(const OUString& sql)
|
2013-07-23 17:24:12 +02:00
|
|
|
throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_pConnection->getMutex());
|
2013-07-23 19:04:33 +02:00
|
|
|
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
|
2013-07-23 17:24:12 +02:00
|
|
|
|
|
|
|
int aErr = isc_dsql_execute_immediate(m_statusVector,
|
|
|
|
&m_pConnection->getDBHandle(),
|
|
|
|
&m_pConnection->getTransaction(),
|
|
|
|
0,
|
|
|
|
OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(),
|
2013-07-24 19:23:15 +02:00
|
|
|
FIREBIRD_SQL_DIALECT,
|
2013-07-23 17:24:12 +02:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (aErr)
|
|
|
|
SAL_WARN("connectivity.firebird", "isc_dsql_execute_immediate failed" );
|
|
|
|
|
2013-07-25 16:30:32 +02:00
|
|
|
evaluateStatusVector(m_statusVector, sql, *this);
|
2013-07-23 17:24:12 +02:00
|
|
|
// TODO: get number of changed rows with SELECT ROW_COUNT (use executeQuery)
|
|
|
|
// return getUpdateCount();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-24 20:06:32 +02:00
|
|
|
uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& sql)
|
2013-07-23 17:24:12 +02:00
|
|
|
throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_pConnection->getMutex());
|
2013-07-23 19:04:33 +02:00
|
|
|
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
|
2013-07-23 17:24:12 +02:00
|
|
|
|
|
|
|
XSQLDA* pOutSqlda = 0;
|
|
|
|
isc_stmt_handle aStatementHandle = 0;
|
|
|
|
int aErr = 0;
|
|
|
|
|
|
|
|
|
|
|
|
aErr = prepareAndDescribeStatement(sql,
|
|
|
|
aStatementHandle,
|
|
|
|
pOutSqlda);
|
|
|
|
if (aErr)
|
|
|
|
{
|
|
|
|
SAL_WARN("connectivity.firebird", "prepareAndDescribeStatement failed");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aErr = isc_dsql_execute(m_statusVector,
|
|
|
|
&m_pConnection->getTransaction(),
|
|
|
|
&aStatementHandle,
|
|
|
|
1,
|
|
|
|
NULL);
|
|
|
|
if (aErr)
|
|
|
|
SAL_WARN("connectivity.firebird", "isc_dsql_execute failed" );
|
|
|
|
}
|
|
|
|
|
2013-08-07 18:10:20 +01:00
|
|
|
m_xResultSet = new OResultSet(m_pConnection,
|
|
|
|
uno::Reference< XInterface >(*this),
|
|
|
|
aStatementHandle,
|
|
|
|
pOutSqlda);
|
2013-07-23 17:24:12 +02:00
|
|
|
|
|
|
|
// TODO: deal with cleanup
|
|
|
|
// close();
|
2013-08-07 18:18:09 +01:00
|
|
|
|
2013-07-25 16:30:32 +02:00
|
|
|
evaluateStatusVector(m_statusVector, sql, *this);
|
2013-08-07 18:18:09 +01:00
|
|
|
|
|
|
|
if (isDDLStatement(aStatementHandle))
|
|
|
|
{
|
|
|
|
m_pConnection->commit();
|
|
|
|
}
|
|
|
|
|
2013-07-23 17:24:12 +02:00
|
|
|
return m_xResultSet;
|
|
|
|
}
|
|
|
|
|
2013-07-24 20:06:32 +02:00
|
|
|
sal_Bool SAL_CALL OStatement::execute(const OUString& sql)
|
2013-07-23 17:24:12 +02:00
|
|
|
throw(SQLException, RuntimeException)
|
|
|
|
{
|
2013-08-07 10:39:16 +01:00
|
|
|
uno::Reference< XResultSet > xResults = executeQuery(sql);
|
|
|
|
return xResults.is();
|
|
|
|
// TODO: what if we have multiple results?
|
2013-07-23 17:24:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< XConnection > SAL_CALL OStatement::getConnection()
|
|
|
|
throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_pConnection->getMutex());
|
2013-07-23 19:04:33 +02:00
|
|
|
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
|
2013-07-23 17:24:12 +02:00
|
|
|
|
|
|
|
return (uno::Reference< XConnection >)m_pConnection;
|
|
|
|
}
|
2013-07-23 19:04:33 +02:00
|
|
|
|
|
|
|
Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
Any aRet = OStatement_Base::queryInterface(rType);
|
|
|
|
if(!aRet.hasValue())
|
|
|
|
aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
|
|
|
|
if(!aRet.hasValue())
|
|
|
|
aRet = OStatementCommonBase::queryInterface(rType);
|
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence< Type > SAL_CALL OStatement::getTypes()
|
|
|
|
throw(RuntimeException)
|
|
|
|
{
|
|
|
|
return concatSequences(OStatement_Base::getTypes(),
|
|
|
|
OStatementCommonBase::getTypes());
|
|
|
|
}
|
|
|
|
|
2013-05-10 18:21:30 +00:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|