Use correct object
[LibreOffice.git] / connectivity / source / drivers / macab / MacabPreparedStatement.cxx
blob6d72345b6021ec4951054df816266382bd5a6b42
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include "MacabPreparedStatement.hxx"
22 #include "MacabAddressBook.hxx"
23 #include <propertyids.hxx>
24 #include <connectivity/dbexception.hxx>
25 #include <connectivity/dbtools.hxx>
26 #include <strings.hrc>
27 #include <resource/sharedresources.hxx>
29 using namespace connectivity::macab;
30 using namespace com::sun::star::uno;
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::sdbc;
33 using namespace com::sun::star::util;
35 IMPLEMENT_SERVICE_INFO(MacabPreparedStatement, "com.sun.star.sdbc.drivers.MacabPreparedStatement", "com.sun.star.sdbc.PreparedStatement");
37 void MacabPreparedStatement::checkAndResizeParameters(sal_Int32 nParams)
39 if ( !m_aParameterRow.is() )
40 m_aParameterRow = new OValueVector();
42 if (nParams < 1)
43 ::dbtools::throwInvalidIndexException(*this);
45 if (nParams >= static_cast<sal_Int32>(m_aParameterRow->size()))
46 m_aParameterRow->resize(nParams);
49 void MacabPreparedStatement::setMacabFields() const
51 ::rtl::Reference<connectivity::OSQLColumns> xColumns; // selected columns
53 xColumns = m_aSQLIterator.getSelectColumns();
54 if (!xColumns.is())
56 ::connectivity::SharedResources aResources;
57 const OUString sError( aResources.getResourceString(
58 STR_INVALID_COLUMN_SELECTION
59 ) );
60 ::dbtools::throwGenericSQLException(sError,nullptr);
62 m_xMetaData->setMacabFields(xColumns);
65 void MacabPreparedStatement::resetParameters() const
67 m_nParameterIndex = 0;
70 void MacabPreparedStatement::getNextParameter(OUString &rParameter) const
72 if (m_nParameterIndex >= static_cast<sal_Int32>(m_aParameterRow->size()))
74 ::connectivity::SharedResources aResources;
75 const OUString sError( aResources.getResourceString(
76 STR_INVALID_PARA_COUNT
77 ) );
78 ::dbtools::throwGenericSQLException(sError,*const_cast<MacabPreparedStatement *>(this));
81 rParameter = (*m_aParameterRow)[m_nParameterIndex].getString();
83 m_nParameterIndex++;
86 MacabPreparedStatement::MacabPreparedStatement(
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()
98 MacabPreparedStatement::~MacabPreparedStatement()
102 void MacabPreparedStatement::disposing()
104 MacabPreparedStatement_BASE::disposing();
106 if (m_aParameterRow.is())
108 m_aParameterRow->clear();
109 m_aParameterRow = nullptr;
113 Reference< XResultSetMetaData > SAL_CALL MacabPreparedStatement::getMetaData()
115 ::osl::MutexGuard aGuard( m_aMutex );
116 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
118 if (!m_xMetaData.is())
120 const OSQLTables& xTabs = m_aSQLIterator.getTables();
121 OUString sTableName = MacabAddressBook::getDefaultTableName();
123 if(! xTabs.empty() )
126 // can only deal with one table at a time
127 if(xTabs.size() == 1 && !m_aSQLIterator.hasErrors() )
128 sTableName = xTabs.begin()->first;
131 m_xMetaData = new MacabResultSetMetaData(getOwnConnection(),sTableName);
132 setMacabFields();
134 Reference< XResultSetMetaData > xMetaData = m_xMetaData;
135 return xMetaData;
138 void SAL_CALL MacabPreparedStatement::close()
140 ::osl::MutexGuard aGuard( m_aMutex );
141 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
143 // Reset last warning message
144 try {
145 clearWarnings ();
146 MacabCommonStatement::close();
148 catch (SQLException &) {
149 // If we get an error, ignore
152 // Remove this Statement object from the Connection object's
153 // list
156 sal_Bool SAL_CALL MacabPreparedStatement::execute()
158 ::osl::MutexGuard aGuard( m_aMutex );
159 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
161 Reference< XResultSet> xRS = MacabCommonStatement::executeQuery(m_sSqlStatement);
163 return xRS.is();
166 sal_Int32 SAL_CALL MacabPreparedStatement::executeUpdate()
168 ::osl::MutexGuard aGuard( m_aMutex );
169 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
171 // same as in statement with the difference that this statement also can contain parameter
172 return 0;
175 Reference< XConnection > SAL_CALL MacabPreparedStatement::getConnection()
177 ::osl::MutexGuard aGuard( m_aMutex );
178 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
180 return m_pConnection;
183 Reference< XResultSet > SAL_CALL MacabPreparedStatement::executeQuery()
185 ::osl::MutexGuard aGuard( m_aMutex );
186 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
188 Reference< XResultSet > rs = MacabCommonStatement::executeQuery(m_sSqlStatement);
190 return rs;
193 void SAL_CALL MacabPreparedStatement::setNull(sal_Int32 parameterIndex, sal_Int32)
195 ::osl::MutexGuard aGuard( m_aMutex );
196 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
198 checkAndResizeParameters(parameterIndex);
200 (*m_aParameterRow)[parameterIndex - 1].setNull();
203 void SAL_CALL MacabPreparedStatement::setObjectNull(sal_Int32, sal_Int32, const OUString&)
205 ::dbtools::throwFunctionNotSupportedSQLException("setObjectNull", nullptr);
208 void SAL_CALL MacabPreparedStatement::setBoolean(sal_Int32, sal_Bool)
210 ::dbtools::throwFunctionNotSupportedSQLException("setBoolean", nullptr);
213 void SAL_CALL MacabPreparedStatement::setByte(sal_Int32, sal_Int8)
215 ::dbtools::throwFunctionNotSupportedSQLException("setByte", nullptr);
218 void SAL_CALL MacabPreparedStatement::setShort(sal_Int32, sal_Int16)
220 ::dbtools::throwFunctionNotSupportedSQLException("setShort", nullptr);
223 void SAL_CALL MacabPreparedStatement::setInt(sal_Int32, sal_Int32)
225 ::dbtools::throwFunctionNotSupportedSQLException("setInt", nullptr);
228 void SAL_CALL MacabPreparedStatement::setLong(sal_Int32, sal_Int64)
230 ::dbtools::throwFunctionNotSupportedSQLException("setLong", nullptr);
233 void SAL_CALL MacabPreparedStatement::setFloat(sal_Int32, float)
235 ::dbtools::throwFunctionNotSupportedSQLException("setFloat", nullptr);
238 void SAL_CALL MacabPreparedStatement::setDouble(sal_Int32, double)
240 ::dbtools::throwFunctionNotSupportedSQLException("setDouble", nullptr);
243 void SAL_CALL MacabPreparedStatement::setString(sal_Int32 parameterIndex, const OUString &x)
245 ::osl::MutexGuard aGuard( m_aMutex );
246 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
248 checkAndResizeParameters(parameterIndex);
250 (*m_aParameterRow)[parameterIndex - 1] = x;
253 void SAL_CALL MacabPreparedStatement::setBytes(sal_Int32, const Sequence< sal_Int8 >&)
255 ::dbtools::throwFunctionNotSupportedSQLException("setBytes", nullptr);
258 void SAL_CALL MacabPreparedStatement::setDate(sal_Int32, const Date&)
260 ::dbtools::throwFunctionNotSupportedSQLException("setDate", nullptr);
263 void SAL_CALL MacabPreparedStatement::setTime(sal_Int32, const css::util::Time&)
266 ::dbtools::throwFunctionNotSupportedSQLException("setTime", nullptr);
269 void SAL_CALL MacabPreparedStatement::setTimestamp(sal_Int32, const DateTime&)
271 ::dbtools::throwFunctionNotSupportedSQLException("setTimestamp", nullptr);
274 void SAL_CALL MacabPreparedStatement::setBinaryStream(sal_Int32, const Reference< css::io::XInputStream >&, sal_Int32)
276 ::dbtools::throwFunctionNotSupportedSQLException("setBinaryStream", nullptr);
279 void SAL_CALL MacabPreparedStatement::setCharacterStream(sal_Int32, const Reference< css::io::XInputStream >&, sal_Int32)
281 ::dbtools::throwFunctionNotSupportedSQLException("setCharacterStream", nullptr);
284 void SAL_CALL MacabPreparedStatement::setObject(sal_Int32 parameterIndex, const Any& x)
286 if(!::dbtools::implSetObject(this,parameterIndex,x))
288 const OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
289 STR_UNKNOWN_PARA_TYPE,
290 "$position$", OUString::number(parameterIndex)
291 ) );
292 ::dbtools::throwGenericSQLException(sError,*this);
296 void SAL_CALL MacabPreparedStatement::setObjectWithInfo(sal_Int32, const Any&, sal_Int32, sal_Int32)
298 ::dbtools::throwFunctionNotSupportedSQLException("setObjectWithInfo", nullptr);
301 void SAL_CALL MacabPreparedStatement::setRef(sal_Int32, const Reference< XRef >&)
303 ::dbtools::throwFunctionNotSupportedSQLException("setRef", nullptr);
306 void SAL_CALL MacabPreparedStatement::setBlob(sal_Int32, const Reference< XBlob >&)
308 ::dbtools::throwFunctionNotSupportedSQLException("setBlob", nullptr);
311 void SAL_CALL MacabPreparedStatement::setClob(sal_Int32, const Reference< XClob >&)
313 ::dbtools::throwFunctionNotSupportedSQLException("setClob", nullptr);
316 void SAL_CALL MacabPreparedStatement::setArray(sal_Int32, const Reference< XArray >&)
318 ::dbtools::throwFunctionNotSupportedSQLException("setArray", nullptr);
321 void SAL_CALL MacabPreparedStatement::clearParameters()
323 ::dbtools::throwFunctionNotSupportedSQLException("clearParameters", nullptr);
326 void MacabPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
328 switch (nHandle)
330 case PROPERTY_ID_RESULTSETCONCURRENCY:
331 break;
332 case PROPERTY_ID_RESULTSETTYPE:
333 break;
334 case PROPERTY_ID_FETCHDIRECTION:
335 break;
336 case PROPERTY_ID_USEBOOKMARKS:
337 break;
338 default:
339 MacabCommonStatement::setFastPropertyValue_NoBroadcast(nHandle,rValue);
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */