1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "Connection.hxx"
22 #include "ResultSet.hxx"
23 #include "Statement.hxx"
26 #include <comphelper/sequence.hxx>
27 #include <cppuhelper/queryinterface.hxx>
28 #include <osl/diagnose.h>
29 #include <osl/thread.h>
30 #include <rtl/ustrbuf.hxx>
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
34 #include <com/sun/star/sdbc/ResultSetType.hpp>
35 #include <com/sun/star/sdbc/FetchDirection.hpp>
37 using namespace connectivity::firebird
;
39 using namespace com::sun::star
;
40 using namespace com::sun::star::uno
;
41 using namespace com::sun::star::lang
;
42 using namespace com::sun::star::beans
;
43 using namespace com::sun::star::sdbc
;
44 using namespace com::sun::star::sdbcx
;
45 using namespace com::sun::star::container
;
46 using namespace com::sun::star::io
;
47 using namespace com::sun::star::util
;
49 using namespace ::comphelper
;
50 using namespace ::osl
;
51 using namespace ::std
;
53 // ---- XBatchExecution - UNSUPPORTED ----------------------------------------
54 void SAL_CALL
OStatement::addBatch(const OUString
& sql
)
55 throw(SQLException
, RuntimeException
, std::exception
)
60 void SAL_CALL
OStatement::clearBatch() throw(SQLException
, RuntimeException
, std::exception
)
64 Sequence
< sal_Int32
> SAL_CALL
OStatement::executeBatch() throw(SQLException
, RuntimeException
, std::exception
)
66 return Sequence
< sal_Int32
>();
69 IMPLEMENT_SERVICE_INFO(OStatement
,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
71 void SAL_CALL
OStatement::acquire() throw()
73 OStatementCommonBase::acquire();
76 void SAL_CALL
OStatement::release() throw()
78 OStatementCommonBase::release();
81 void OStatement::disposeResultSet()
83 MutexGuard
aGuard(m_aMutex
);
84 checkDisposed(OStatementCommonBase_Base::rBHelper
.bDisposed
);
86 OStatementCommonBase::disposeResultSet();
96 // ---- XStatement -----------------------------------------------------------
97 sal_Int32 SAL_CALL
OStatement::executeUpdate(const OUString
& sql
)
98 throw(SQLException
, RuntimeException
, std::exception
)
101 return getStatementChangeCount();
105 uno::Reference
< XResultSet
> SAL_CALL
OStatement::executeQuery(const OUString
& sql
)
106 throw(SQLException
, RuntimeException
, std::exception
)
108 MutexGuard
aGuard(m_aMutex
);
109 checkDisposed(OStatementCommonBase_Base::rBHelper
.bDisposed
);
111 SAL_INFO("connectivity.firebird", "executeQuery(" << sql
<< ")");
117 prepareAndDescribeStatement(sql
,
120 aErr
= isc_dsql_execute(m_statusVector
,
121 &m_pConnection
->getTransaction(),
126 SAL_WARN("connectivity.firebird", "isc_dsql_execute failed");
128 m_xResultSet
= new OResultSet(m_pConnection
.get(),
130 uno::Reference
< XInterface
>(*this),
134 // TODO: deal with cleanup
136 evaluateStatusVector(m_statusVector
, sql
, *this);
138 if (isDDLStatement())
140 m_pConnection
->commit();
141 m_pConnection
->notifyDatabaseModified();
143 else if (getStatementChangeCount() > 0)
145 m_pConnection
->notifyDatabaseModified();
151 sal_Bool SAL_CALL
OStatement::execute(const OUString
& sql
)
152 throw(SQLException
, RuntimeException
, std::exception
)
154 uno::Reference
< XResultSet
> xResults
= executeQuery(sql
);
155 return xResults
.is();
156 // TODO: what if we have multiple results?
159 uno::Reference
< XConnection
> SAL_CALL
OStatement::getConnection()
160 throw(SQLException
, RuntimeException
, std::exception
)
162 MutexGuard
aGuard(m_aMutex
);
163 checkDisposed(OStatementCommonBase_Base::rBHelper
.bDisposed
);
165 return uno::Reference
<XConnection
>(m_pConnection
.get());
168 Any SAL_CALL
OStatement::queryInterface( const Type
& rType
) throw(RuntimeException
, std::exception
)
170 Any aRet
= OStatement_Base::queryInterface(rType
);
172 aRet
= ::cppu::queryInterface(rType
,static_cast< XBatchExecution
*> (this));
174 aRet
= OStatementCommonBase::queryInterface(rType
);
178 uno::Sequence
< Type
> SAL_CALL
OStatement::getTypes()
179 throw(RuntimeException
, std::exception
)
181 return concatSequences(OStatement_Base::getTypes(),
182 OStatementCommonBase::getTypes());
185 void SAL_CALL
OStatement::close() throw(SQLException
, RuntimeException
, std::exception
)
187 OStatementCommonBase::close();
190 void SAL_CALL
OStatement::disposing()
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */