LibreOffice Module connectivity (master) 1
MacabPreparedStatement.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
22#include "MacabAddressBook.hxx"
23#include <propertyids.hxx>
26#include <strings.hrc>
28
29using namespace connectivity::macab;
30using namespace com::sun::star::uno;
31using namespace com::sun::star::lang;
32using namespace com::sun::star::sdbc;
33using namespace com::sun::star::util;
34
35IMPLEMENT_SERVICE_INFO(MacabPreparedStatement, "com.sun.star.sdbc.drivers.MacabPreparedStatement", "com.sun.star.sdbc.PreparedStatement");
36
37void MacabPreparedStatement::checkAndResizeParameters(sal_Int32 nParams)
38{
39 if ( !m_aParameterRow.is() )
41
42 if (nParams < 1)
44
45 if (nParams >= static_cast<sal_Int32>(m_aParameterRow->size()))
46 m_aParameterRow->resize(nParams);
47}
48
50{
51 ::rtl::Reference<connectivity::OSQLColumns> xColumns; // selected columns
52
53 xColumns = m_aSQLIterator.getSelectColumns();
54 if (!xColumns.is())
55 {
57 const OUString sError( aResources.getResourceString(
58 STR_INVALID_COLUMN_SELECTION
59 ) );
61 }
62 m_xMetaData->setMacabFields(xColumns);
63}
64
66{
68}
69
70void MacabPreparedStatement::getNextParameter(OUString &rParameter) const
71{
72 if (m_nParameterIndex >= static_cast<sal_Int32>(m_aParameterRow->size()))
73 {
75 const OUString sError( aResources.getResourceString(
76 STR_INVALID_PARA_COUNT
77 ) );
79 }
80
81 rParameter = (*m_aParameterRow)[m_nParameterIndex].getString();
82
84}
85
87 MacabConnection* _pConnection,
88 const OUString& sql)
89 : MacabPreparedStatement_BASE(_pConnection),
90 m_sSqlStatement(sql),
91 m_bPrepared(false),
92 m_nParameterIndex(0),
93 m_aParameterRow()
94{
95
96}
97
99{
100}
101
103{
104 MacabPreparedStatement_BASE::disposing();
105
106 if (m_aParameterRow.is())
107 {
108 m_aParameterRow->clear();
109 m_aParameterRow = nullptr;
110 }
111}
112
114{
115 ::osl::MutexGuard aGuard( m_aMutex );
116 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
117
118 if (!m_xMetaData.is())
119 {
120 const OSQLTables& xTabs = m_aSQLIterator.getTables();
121 OUString sTableName = MacabAddressBook::getDefaultTableName();
122
123 if(! xTabs.empty() )
124 {
125
126 // can only deal with one table at a time
127 if(xTabs.size() == 1 && !m_aSQLIterator.hasErrors() )
128 sTableName = xTabs.begin()->first;
129
130 }
131 m_xMetaData = new MacabResultSetMetaData(getOwnConnection(),sTableName);
133 }
135 return xMetaData;
136}
137
139{
140 ::osl::MutexGuard aGuard( m_aMutex );
141 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
142
143 // Reset last warning message
144 try {
145 clearWarnings ();
147 }
148 catch (SQLException &) {
149 // If we get an error, ignore
150 }
151
152 // Remove this Statement object from the Connection object's
153 // list
154}
155
157{
158 ::osl::MutexGuard aGuard( m_aMutex );
159 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
160
162
163 return xRS.is();
164}
165
167{
168 ::osl::MutexGuard aGuard( m_aMutex );
169 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
170
171 // same as in statement with the difference that this statement also can contain parameter
172 return 0;
173}
174
176{
177 ::osl::MutexGuard aGuard( m_aMutex );
178 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
179
180 return m_pConnection;
181}
182
184{
185 ::osl::MutexGuard aGuard( m_aMutex );
186 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
187
189
190 return rs;
191}
192
193void SAL_CALL MacabPreparedStatement::setNull(sal_Int32 parameterIndex, sal_Int32)
194{
195 ::osl::MutexGuard aGuard( m_aMutex );
196 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
197
198 checkAndResizeParameters(parameterIndex);
199
200 (*m_aParameterRow)[parameterIndex - 1].setNull();
201}
202
203void SAL_CALL MacabPreparedStatement::setObjectNull(sal_Int32, sal_Int32, const OUString&)
204{
205 ::dbtools::throwFunctionNotSupportedSQLException("setObjectNull", nullptr);
206}
207
209{
211}
212
214{
216}
217
218void SAL_CALL MacabPreparedStatement::setShort(sal_Int32, sal_Int16)
219{
221}
222
223void SAL_CALL MacabPreparedStatement::setInt(sal_Int32, sal_Int32)
224{
226}
227
228void SAL_CALL MacabPreparedStatement::setLong(sal_Int32, sal_Int64)
229{
231}
232
233void SAL_CALL MacabPreparedStatement::setFloat(sal_Int32, float)
234{
236}
237
238void SAL_CALL MacabPreparedStatement::setDouble(sal_Int32, double)
239{
241}
242
243void SAL_CALL MacabPreparedStatement::setString(sal_Int32 parameterIndex, const OUString &x)
244{
245 ::osl::MutexGuard aGuard( m_aMutex );
246 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
247
248 checkAndResizeParameters(parameterIndex);
249
250 (*m_aParameterRow)[parameterIndex - 1] = x;
251}
252
254{
256}
257
258void SAL_CALL MacabPreparedStatement::setDate(sal_Int32, const Date&)
259{
261}
262
263void SAL_CALL MacabPreparedStatement::setTime(sal_Int32, const css::util::Time&)
264{
265
267}
268
269void SAL_CALL MacabPreparedStatement::setTimestamp(sal_Int32, const DateTime&)
270{
272}
273
275{
276 ::dbtools::throwFunctionNotSupportedSQLException("setBinaryStream", nullptr);
277}
278
280{
281 ::dbtools::throwFunctionNotSupportedSQLException("setCharacterStream", nullptr);
282}
283
284void SAL_CALL MacabPreparedStatement::setObject(sal_Int32 parameterIndex, const Any& x)
285{
286 if(!::dbtools::implSetObject(this,parameterIndex,x))
287 {
288 const OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
289 STR_UNKNOWN_PARA_TYPE,
290 "$position$", OUString::number(parameterIndex)
291 ) );
293 }
294}
295
296void SAL_CALL MacabPreparedStatement::setObjectWithInfo(sal_Int32, const Any&, sal_Int32, sal_Int32)
297{
298 ::dbtools::throwFunctionNotSupportedSQLException("setObjectWithInfo", nullptr);
299}
300
301void SAL_CALL MacabPreparedStatement::setRef(sal_Int32, const Reference< XRef >&)
302{
304}
305
307{
309}
310
312{
314}
315
317{
319}
320
322{
323 ::dbtools::throwFunctionNotSupportedSQLException("clearParameters", nullptr);
324}
325
326void MacabPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
327{
328 switch (nHandle)
329 {
331 break;
333 break;
335 break;
337 break;
338 default:
340 }
341}
342
343/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPLEMENT_SERVICE_INFO(MacabPreparedStatement, "com.sun.star.sdbc.drivers.MacabPreparedStatement", "com.sun.star.sdbc.PreparedStatement")
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceString(TranslateId pResId) const
loads a string from the shared resource file
static const OUString & getDefaultTableName()
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL close() override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery(const OUString &sql) override
virtual void SAL_CALL setCharacterStream(sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
virtual void SAL_CALL setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString &typeName) override
virtual void SAL_CALL setBytes(sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 > &x) override
virtual void SAL_CALL setObjectWithInfo(sal_Int32 parameterIndex, const css::uno::Any &x, sal_Int32 targetSqlType, sal_Int32 scale) override
virtual void SAL_CALL setBoolean(sal_Int32 parameterIndex, sal_Bool x) override
virtual void SAL_CALL setFloat(sal_Int32 parameterIndex, float x) override
virtual void SAL_CALL setTime(sal_Int32 parameterIndex, const css::util::Time &x) override
virtual void SAL_CALL setNull(sal_Int32 parameterIndex, sal_Int32 sqlType) override
virtual void SAL_CALL setShort(sal_Int32 parameterIndex, sal_Int16 x) override
virtual sal_Int32 SAL_CALL executeUpdate() override
virtual sal_Bool SAL_CALL execute() override
virtual void getNextParameter(OUString &rParameter) const override
virtual void SAL_CALL setLong(sal_Int32 parameterIndex, sal_Int64 x) override
virtual void SAL_CALL clearParameters() override
virtual void SAL_CALL setString(sal_Int32 parameterIndex, const OUString &x) override
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
::rtl::Reference< MacabResultSetMetaData > m_xMetaData
virtual void SAL_CALL setClob(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XClob > &x) override
virtual void SAL_CALL setRef(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XRef > &x) override
virtual void SAL_CALL setTimestamp(sal_Int32 parameterIndex, const css::util::DateTime &x) override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery() override
virtual void SAL_CALL setDouble(sal_Int32 parameterIndex, double x) override
virtual void SAL_CALL setInt(sal_Int32 parameterIndex, sal_Int32 x) override
virtual void SAL_CALL setBinaryStream(sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection() override
virtual void SAL_CALL setArray(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XArray > &x) override
virtual void SAL_CALL setBlob(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XBlob > &x) override
MacabPreparedStatement(MacabConnection *_pConnection, const OUString &sql)
virtual void SAL_CALL setByte(sal_Int32 parameterIndex, sal_Int8 x) override
virtual void SAL_CALL setDate(sal_Int32 parameterIndex, const css::util::Date &x) override
virtual void SAL_CALL setObject(sal_Int32 parameterIndex, const css::uno::Any &x) override
float x
std::mutex m_aMutex
::cppu::ImplInheritanceHelper< MacabCommonStatement, css::sdbc::XPreparedStatement, css::sdbc::XParameters, css::sdbc::XResultSetMetaDataSupplier, css::lang::XServiceInfo > MacabPreparedStatement_BASE
std::map< OUString, OSQLTable, comphelper::UStringMixLess > OSQLTables
Definition: CommonTools.hxx:56
ODeleteVector< ORowSetValue > OValueVector
Definition: FValue.hxx:457
void checkDisposed(bool _bThrow)
Definition: dbtools.cxx:1951
void throwInvalidIndexException(const css::uno::Reference< css::uno::XInterface > &Context, const css::uno::Any &Next)
throw an invalid index sqlexception
bool implSetObject(const Reference< XParameters > &_rxParameters, const sal_Int32 _nColumnIndex, const Any &_rValue)
Definition: dbtools.cxx:1516
void throwFunctionNotSupportedSQLException(const OUString &_rFunctionName, const css::uno::Reference< css::uno::XInterface > &_rxContext)
throws an exception with SQL state IM001, saying that a certain function is not supported
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
#define PROPERTY_ID_RESULTSETTYPE
Definition: propertyids.hxx:44
#define PROPERTY_ID_USEBOOKMARKS
Definition: propertyids.hxx:48
#define PROPERTY_ID_RESULTSETCONCURRENCY
Definition: propertyids.hxx:43
#define PROPERTY_ID_FETCHDIRECTION
Definition: propertyids.hxx:45
sal_Int32 nHandle
unsigned char sal_Bool
signed char sal_Int8