LibreOffice Module connectivity (master) 1
StatementCommonBase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
21#include "Util.hxx"
22
23#include <sal/log.hxx>
26#include <propertyids.hxx>
27#include <vcl/svapp.hxx>
28#include <TConnection.hxx>
29
30#include <com/sun/star/sdbc/SQLException.hpp>
31
32using namespace ::connectivity::firebird;
33
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::lang;
37using namespace ::com::sun::star::beans;
38using namespace ::com::sun::star::sdbc;
39using namespace ::com::sun::star::sdbcx;
40using namespace ::com::sun::star::container;
41using namespace ::com::sun::star::io;
42using namespace ::com::sun::star::util;
43
44using namespace ::comphelper;
45using namespace ::osl;
46
47OStatementCommonBase::OStatementCommonBase(Connection* _pConnection)
50 m_pConnection(_pConnection),
51#if SAL_TYPES_SIZEOFPOINTER == 8
52 m_aStatementHandle(0)
53#else
54 m_aStatementHandle(nullptr)
55#endif
56{
57}
58
60{
61}
62
64{
65 uno::Reference< XComponent > xComp(m_xResultSet, UNO_QUERY);
66 if (xComp.is())
67 xComp->dispose();
68 m_xResultSet.clear();
69}
70
72{
74 {
75 isc_dsql_free_statement(m_statusVector,
77 DSQL_drop);
79 u"isc_dsql_free_statement",
80 *this);
81 }
82}
83
84
86{
87 Any aRet = OStatementCommonBase_Base::queryInterface(rType);
88 if(!aRet.hasValue())
90 return aRet;
91}
92
93Sequence< Type > SAL_CALL OStatementCommonBase::getTypes( )
94{
99
100 return concatSequences(aTypes.getTypes(),OStatementCommonBase_Base::getTypes());
101}
102
103
105{
106 MutexGuard aGuard(m_aMutex);
107 checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
108 // cancel the current sql statement
109}
110
112{
113 SAL_INFO("connectivity.firebird", "close");
114
115 {
116 MutexGuard aGuard(m_aMutex);
117 checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
120 }
121
122 dispose();
123}
124
125void OStatementCommonBase::prepareAndDescribeStatement(std::u16string_view sql, XSQLDA*& pOutSqlda)
126{
127 SolarMutexGuard g; // tdf#122129
128
130
131 if (!pOutSqlda)
132 {
133 pOutSqlda = static_cast<XSQLDA*>(calloc(1, XSQLDA_LENGTH(10)));
134 pOutSqlda->version = SQLDA_VERSION1;
135 pOutSqlda->sqln = 10;
136 }
137
138 ISC_STATUS aErr = isc_dsql_allocate_statement(m_statusVector,
139 &m_pConnection->getDBHandle(),
141
142 if (aErr)
143 {
145 u"isc_dsql_allocate_statement",
146 *this);
147 }
148 else
149 {
150 aErr = isc_dsql_prepare(m_statusVector,
151 &m_pConnection->getTransaction(),
153 0,
154 OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(),
155 SQL_DIALECT_CURRENT,
156 pOutSqlda);
157
158 if (aErr)
159 {
161 u"isc_dsql_prepare",
162 *this);
163 }
164 else
165 {
166 // Ensure we have enough space in pOutSqlda
167 if (pOutSqlda->sqld > pOutSqlda->sqln)
168 {
169 int n = pOutSqlda->sqld;
170 free(pOutSqlda);
171 pOutSqlda = static_cast<XSQLDA*>(calloc(1, XSQLDA_LENGTH(n)));
172 pOutSqlda->version = SQLDA_VERSION1;
173 pOutSqlda->sqln = n;
174 aErr = isc_dsql_describe(m_statusVector,
176 1,
177 pOutSqlda);
178 }
179
180 // Process each XSQLVAR parameter structure in the output XSQLDA
181 if (aErr)
182 {
184 u"isc_dsql_describe",
185 *this);
186 }
187 else
188 {
189 mallocSQLVAR(pOutSqlda);
190 }
191 }
192 if(aErr)
193 {
195 }
196 }
197 if(aErr)
198 {
199 free(pOutSqlda);
200 pOutSqlda = nullptr;
201 }
202}
203
204// ---- XMultipleResults - UNSUPPORTED ----------------------------------------
205uno::Reference< XResultSet > SAL_CALL OStatementCommonBase::getResultSet()
206{
207 // TODO: verify we really can't support this
208// return uno::Reference< XResultSet >();
209 MutexGuard aGuard(m_aMutex);
210 checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
211
212 return m_xResultSet;
213}
214
216{
217 // TODO: verify we really can't support this
218 return false;
219// MutexGuard aGuard( m_aMutex );
220// checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
221}
222
224{
225 // TODO: verify we really can't support this
226 return -1;
227}
228
229
230// ---- XWarningsSupplier - UNSUPPORTED ----------------------------------------
232{
233 return Any();
234}
235
237{
238}
239
241{
242 // this properties are define by the service statement
243 // they must in alphabetic order
244 return new ::cppu::OPropertyArrayHelper
245 {
246 {
247 {
251 0
252 },
253 {
257 0
258 },
259 {
263 0
264 },
265 {
269 0
270 },
271 {
275 0
276 },
277 {
281 0
282 },
283 {
287 0
288 },
289 {
293 0
294 },
295 {
299 0
300 },
301 {
305 0
306 }
307 }
308 };
309}
310
311
313{
314 return *getArrayHelper();
315}
316
318 Any &,
319 Any &,
320 sal_Int32,
321 const Any& )
322{
323 // here we have to try to convert
324 return false;
325}
326
328{
329 // set the value to whatever is necessary
330 switch(nHandle)
331 {
342 default:
343 ;
344 }
345}
346
347void OStatementCommonBase::getFastPropertyValue(Any&,sal_Int32 nHandle) const
348{
349 switch(nHandle)
350 {
361 default:
362 ;
363 }
364}
365
366void SAL_CALL OStatementCommonBase::acquire() noexcept
367{
368 OStatementCommonBase_Base::acquire();
369}
370
371void SAL_CALL OStatementCommonBase::release() noexcept
372{
373 OStatementCommonBase_Base::release();
374}
375
376uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OStatementCommonBase::getPropertySetInfo( )
377{
378 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
379}
380
382{
383 ISC_STATUS_ARRAY aStatusVector;
384 ISC_STATUS aErr;
385
386 char aInfoItems[] = {aInfoItem};
387 char aResultsBuffer[8];
388
389 aErr = isc_dsql_sql_info(aStatusVector,
391 sizeof(aInfoItems),
392 aInfoItems,
393 sizeof(aResultsBuffer),
394 aResultsBuffer);
395
396 if (!aErr && aResultsBuffer[0] == aInfoItem)
397 {
398 const short aBytes = static_cast<short>(isc_vax_integer(aResultsBuffer+1, 2));
399 return static_cast<short>(isc_vax_integer(aResultsBuffer+3, aBytes));
400 }
401
402 evaluateStatusVector(aStatusVector,
403 u"isc_dsq_sql_info",
404 *this);
405 return 0;
406}
407
409{
410 return getSqlInfoItem(isc_info_sql_stmt_type) == isc_info_sql_stmt_ddl;
411}
412
414{
415 const short aStatementType = getSqlInfoItem(isc_info_sql_stmt_type);
416
417
418 ISC_STATUS_ARRAY aStatusVector;
419 ISC_STATUS aErr;
420
421 // This is somewhat undocumented so I'm just guessing and hoping for the best.
422 char aInfoItems[] = {isc_info_sql_records};
423 char aResultsBuffer[1024];
424
425 aErr = isc_dsql_sql_info(aStatusVector,
427 sizeof(aInfoItems),
428 aInfoItems,
429 sizeof(aResultsBuffer),
430 aResultsBuffer);
431
432 if (aErr)
433 {
434 evaluateStatusVector(aStatusVector,
435 u"isc_dsq_sql_info",
436 *this);
437 return 0;
438 }
439
440 short aDesiredInfoType = 0;
441 switch (aStatementType)
442 {
443 case isc_info_sql_stmt_select:
444 aDesiredInfoType = isc_info_req_select_count;
445 break;
446 case isc_info_sql_stmt_insert:
447 aDesiredInfoType = isc_info_req_insert_count;
448 break;
449 case isc_info_sql_stmt_update:
450 aDesiredInfoType = isc_info_req_update_count;
451 break;
452 case isc_info_sql_stmt_delete:
453 aDesiredInfoType = isc_info_req_delete_count;
454 break;
455 case isc_info_sql_stmt_exec_procedure:
456 case isc_info_sql_stmt_ddl:
457 return 0; // cannot determine
458 default:
459 throw SQLException(); // TODO: better error message?
460 }
461
462 char* pResults = aResultsBuffer;
463 if (static_cast<short>(*pResults++) != isc_info_sql_records)
464 return 0;
465
466// const short aTotalLength = (short) isc_vax_integer(pResults, 2);
467 pResults += 2;
468
469 // Seems to be of form TOKEN (1 byte), LENGTH (2 bytes), DATA (LENGTH bytes)
470 while (*pResults != isc_info_rsb_end)
471 {
472 const char aToken = *pResults;
473 const short aLength = static_cast<short>(isc_vax_integer(pResults+1, 2));
474
475 if (aToken == aDesiredInfoType)
476 {
477 return isc_vax_integer(pResults + 3, aLength);
478 }
479
480 pResults += (3 + aLength);
481 }
482
483 return 0;
484}
485
486/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
::cppu::IPropertyArrayHelper * getArrayHelper()
call this in the getInfoHelper method of your derived class.
virtual void SAL_CALL release() noexcept override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
used to implement the creation of the array helper which is shared amongst all instances of the class...
virtual sal_Bool SAL_CALL getMoreResults() override
css::uno::Reference< css::sdbc::XResultSet > m_xResultSet
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual sal_Int32 SAL_CALL getUpdateCount() override
void prepareAndDescribeStatement(std::u16string_view sqlIn, XSQLDA *&pOutSqlda)
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet() override
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL clearWarnings() override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Type const & get()
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
float u
std::mutex m_aMutex
sal_Int64 n
#define SAL_INFO(area, stream)
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
Type
void checkDisposed(bool _bThrow)
Definition: Driver.cxx:208
void evaluateStatusVector(const ISC_STATUS_ARRAY &rStatusVector, std::u16string_view aCause, const css::uno::Reference< css::uno::XInterface > &_rxContext)
Evaluate a firebird status vector and throw exceptions as necessary.
void mallocSQLVAR(XSQLDA *pSqlda)
::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier, css::util::XCancellable, css::sdbc::XCloseable, css::sdbc::XMultipleResults > OStatementCommonBase_Base
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Definition: pq_tools.cxx:100
void dispose()
#define PROPERTY_ID_RESULTSETTYPE
Definition: propertyids.hxx:44
#define PROPERTY_ID_QUERYTIMEOUT
Definition: propertyids.hxx:39
#define PROPERTY_ID_USEBOOKMARKS
Definition: propertyids.hxx:48
#define PROPERTY_ID_CURSORNAME
Definition: propertyids.hxx:42
#define PROPERTY_ID_RESULTSETCONCURRENCY
Definition: propertyids.hxx:43
#define PROPERTY_ID_MAXFIELDSIZE
Definition: propertyids.hxx:40
#define PROPERTY_ID_FETCHSIZE
Definition: propertyids.hxx:46
#define PROPERTY_ID_MAXROWS
Definition: propertyids.hxx:41
#define PROPERTY_ID_ESCAPEPROCESSING
Definition: propertyids.hxx:47
#define PROPERTY_ID_FETCHDIRECTION
Definition: propertyids.hxx:45
sal_Int32 nHandle
unsigned char sal_Bool
const SvXMLTokenMapEntry aTypes[]