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 .
21 #include <osl/diagnose.h>
22 #include <odbc/OStatement.hxx>
23 #include <odbc/OConnection.hxx>
24 #include <odbc/OResultSet.hxx>
25 #include <comphelper/property.hxx>
26 #include <odbc/OTools.hxx>
27 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
28 #include <com/sun/star/sdbc/ResultSetType.hpp>
29 #include <com/sun/star/sdbc/FetchDirection.hpp>
30 #include <com/sun/star/lang/DisposedException.hpp>
31 #include <comphelper/sequence.hxx>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <cppuhelper/queryinterface.hxx>
34 #include <comphelper/types.hxx>
35 #include <rtl/strbuf.hxx>
37 #include <strings.hrc>
38 #include <connectivity/dbexception.hxx>
40 using namespace ::comphelper
;
42 #define THROW_SQL(x) \
43 OTools::ThrowException(m_pConnection.get(),x,m_aStatementHandle,SQL_HANDLE_STMT,*this)
46 using namespace connectivity::odbc
;
48 using namespace com::sun::star::uno
;
49 using namespace com::sun::star::lang
;
50 using namespace com::sun::star::beans
;
51 using namespace com::sun::star::sdbc
;
52 using namespace com::sun::star::sdbcx
;
53 using namespace com::sun::star::container
;
54 using namespace com::sun::star::io
;
55 using namespace com::sun::star::util
;
57 OStatement_Base::OStatement_Base(OConnection
* _pConnection
)
58 :OStatement_BASE(m_aMutex
)
59 ,OPropertySetHelper(OStatement_BASE::rBHelper
)
60 ,m_pConnection(_pConnection
)
61 ,m_aStatementHandle(SQL_NULL_HANDLE
)
62 ,m_pRowStatusArray(nullptr)
64 osl_atomic_increment( &m_refCount
);
65 m_aStatementHandle
= m_pConnection
->createStatementHandle();
68 // Don't do this. By ODBC spec, "0" is the default for the SQL_ATTR_MAX_LENGTH attribute. We once introduced
69 // this line since a PostgreSQL ODBC driver had a default other than 0. However, current drivers (at least 8.3
70 // and later) have a proper default of 0, so there should be no need anymore.
71 // On the other hand, the NotesSQL driver (IBM's ODBC driver for the Lotus Notes series) wrongly interprets
72 // "0" as "0", whereas the ODBC spec says it should in fact mean "unlimited".
73 // So, removing this line seems to be the best option for now.
74 // If we ever again encounter an ODBC driver which needs this option, then we should introduce a data source
75 // setting for it, instead of unconditionally doing it.
77 osl_atomic_decrement( &m_refCount
);
80 OStatement_Base::~OStatement_Base()
82 OSL_ENSURE(!m_aStatementHandle
,"Sohould ne null here!");
85 void OStatement_Base::disposeResultSet()
87 // free the cursor if alive
88 Reference
< XComponent
> xComp(m_xResultSet
.get(), UNO_QUERY
);
94 void SAL_CALL
OStatement_Base::disposing()
96 ::osl::MutexGuard
aGuard(m_aMutex
);
99 ::comphelper::disposeComponent(m_xGeneratedStatement
);
101 OSL_ENSURE(m_aStatementHandle
,"OStatement_BASE2::disposing: StatementHandle is null!");
102 if (m_pConnection
.is())
104 m_pConnection
->freeStatementHandle(m_aStatementHandle
);
105 m_pConnection
.clear();
107 OSL_ENSURE(!m_aStatementHandle
,"Sohould ne null here!");
109 OStatement_BASE::disposing();
112 void OStatement_BASE2::disposing()
114 ::osl::MutexGuard
aGuard1(m_aMutex
);
115 OStatement_Base::disposing();
118 Any SAL_CALL
OStatement_Base::queryInterface( const Type
& rType
)
120 if ( m_pConnection
.is() && !m_pConnection
->isAutoRetrievingEnabled() && rType
== cppu::UnoType
<XGeneratedResultSet
>::get())
122 Any aRet
= OStatement_BASE::queryInterface(rType
);
123 return aRet
.hasValue() ? aRet
: OPropertySetHelper::queryInterface(rType
);
126 Sequence
< Type
> SAL_CALL
OStatement_Base::getTypes( )
128 ::cppu::OTypeCollection
aTypes( cppu::UnoType
<XMultiPropertySet
>::get(),
129 cppu::UnoType
<XFastPropertySet
>::get(),
130 cppu::UnoType
<XPropertySet
>::get());
131 Sequence
< Type
> aOldTypes
= OStatement_BASE::getTypes();
132 if ( m_pConnection
.is() && !m_pConnection
->isAutoRetrievingEnabled() )
134 auto newEnd
= std::remove(aOldTypes
.begin(), aOldTypes
.end(),
135 cppu::UnoType
<XGeneratedResultSet
>::get());
136 aOldTypes
.realloc(std::distance(aOldTypes
.begin(), newEnd
));
139 return ::comphelper::concatSequences(aTypes
.getTypes(),aOldTypes
);
142 Reference
< XResultSet
> SAL_CALL
OStatement_Base::getGeneratedValues( )
144 OSL_ENSURE( m_pConnection
.is() && m_pConnection
->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!");
145 Reference
< XResultSet
> xRes
;
146 if ( m_pConnection
.is() )
148 OUString sStmt
= m_pConnection
->getTransformedGeneratedStatement(m_sSqlStatement
);
149 if ( !sStmt
.isEmpty() )
151 ::comphelper::disposeComponent(m_xGeneratedStatement
);
152 m_xGeneratedStatement
= m_pConnection
->createStatement();
153 xRes
= m_xGeneratedStatement
->executeQuery(sStmt
);
159 void SAL_CALL
OStatement_Base::cancel( )
161 ::osl::MutexGuard
aGuard( m_aMutex
);
162 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
164 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
165 N3SQLCancel(m_aStatementHandle
);
169 void SAL_CALL
OStatement_Base::close( )
172 ::osl::MutexGuard
aGuard( m_aMutex
);
173 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
180 void SAL_CALL
OStatement::clearBatch( )
185 void OStatement_Base::reset()
187 ::osl::MutexGuard
aGuard( m_aMutex
);
188 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
193 if (m_xResultSet
.get().is())
197 if(m_aStatementHandle
)
199 THROW_SQL(N3SQLFreeStmt(m_aStatementHandle
, SQL_CLOSE
));
204 // If a ResultSet was created for this Statement, close it
205 void OStatement_Base::clearMyResultSet()
207 ::osl::MutexGuard
aGuard( m_aMutex
);
208 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
212 Reference
<XCloseable
> xCloseable(
213 m_xResultSet
.get(), css::uno::UNO_QUERY
);
214 if ( xCloseable
.is() )
217 catch( const DisposedException
& ) { }
219 m_xResultSet
.clear();
222 SQLLEN
OStatement_Base::getRowCount()
224 ::osl::MutexGuard
aGuard( m_aMutex
);
225 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
231 THROW_SQL(N3SQLRowCount(m_aStatementHandle
,&numRows
));
233 catch (const SQLException
&)
240 // If the given SQL statement contains a 'FOR UPDATE' clause, change
241 // the concurrency to lock so that the row can then be updated. Returns
242 // true if the concurrency has been changed
243 bool OStatement_Base::lockIfNecessary (const OUString
& sql
)
247 // First, convert the statement to upper case
249 OUString sqlStatement
= sql
.toAsciiUpperCase ();
251 // Now, look for the FOR UPDATE keywords. If there is any extra white
252 // space between the FOR and UPDATE, this will fail.
254 sal_Int32 index
= sqlStatement
.indexOf(" FOR UPDATE");
256 // We found it. Change our concurrency level to ensure that the
257 // row can be updated.
261 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
264 THROW_SQL((setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CONCURRENCY
, SQL_CONCUR_LOCK
)));
266 catch (const SQLWarning
& warn
)
268 // Catch any warnings and place on the warning stack
281 void OStatement_Base::setWarning (const SQLWarning
&ex
)
283 ::osl::MutexGuard
aGuard( m_aMutex
);
284 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
292 // Return the number of columns in the ResultSet
293 sal_Int32
OStatement_Base::getColumnCount()
295 ::osl::MutexGuard
aGuard( m_aMutex
);
296 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
299 sal_Int16 numCols
= 0;
300 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
303 THROW_SQL(N3SQLNumResultCols(m_aStatementHandle
,&numCols
));
305 catch (const SQLException
&)
312 sal_Bool SAL_CALL
OStatement_Base::execute( const OUString
& sql
)
314 ::osl::MutexGuard
aGuard( m_aMutex
);
315 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
316 m_sSqlStatement
= sql
;
319 OString
aSql(OUStringToOString(sql
,getOwnConnection()->getTextEncoding()));
321 bool hasResultSet
= false;
323 // Reset the statement handle and warning
327 // Check for a 'FOR UPDATE' statement. If present, change
328 // the concurrency to lock
330 lockIfNecessary (sql
);
332 // Call SQLExecDirect
333 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
336 THROW_SQL(N3SQLExecDirect(m_aStatementHandle
, reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(aSql
.getStr())), aSql
.getLength()));
338 catch (const SQLWarning
&) {
340 //TODO: Save pointer to warning and save with ResultSet
341 // object once it is created.
344 // Now determine if there is a result set associated with
345 // the SQL statement that was executed. Get the column
346 // count, and if it is not zero, there is a result set.
348 if (getColumnCount () > 0)
357 // getResultSet returns the current result as a ResultSet. It
358 // returns NULL if the current result is not a ResultSet.
360 Reference
< XResultSet
> OStatement_Base::getResultSet(bool checkCount
)
362 ::osl::MutexGuard
aGuard( m_aMutex
);
363 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
366 if (m_xResultSet
.get().is()) // if resultset already retrieved,
368 // throw exception to avoid sequence error
369 ::dbtools::throwFunctionSequenceException(*this);
372 rtl::Reference
<OResultSet
> pRs
;
373 sal_Int32 numCols
= 1;
375 // If we already know we have result columns, checkCount
376 // is false. This is an optimization to prevent unneeded
377 // calls to getColumnCount
380 numCols
= getColumnCount ();
382 // Only return a result set if there are result columns
386 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
387 pRs
= createResultSet();
390 // Save a copy of our last result set
391 // Changed to save copy at getResultSet.
401 // Invoke SQLGetStmtOption with the given option.
404 template < typename T
, SQLINTEGER BufferLength
> T
OStatement_Base::getStmtOption (SQLINTEGER fOption
) const
407 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
408 N3SQLGetStmtAttr(m_aStatementHandle
, fOption
, &result
, BufferLength
, nullptr);
411 template < typename T
, SQLINTEGER BufferLength
> SQLRETURN
OStatement_Base::setStmtOption (SQLINTEGER fOption
, T value
) const
413 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
414 SQLPOINTER sv
= reinterpret_cast<SQLPOINTER
>(value
);
415 return N3SQLSetStmtAttr(m_aStatementHandle
, fOption
, sv
, BufferLength
);
419 Reference
< XResultSet
> SAL_CALL
OStatement_Base::executeQuery( const OUString
& sql
)
421 ::osl::MutexGuard
aGuard( m_aMutex
);
422 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
425 Reference
< XResultSet
> xRS
;
427 // Execute the statement. If execute returns true, a result
432 xRS
= getResultSet (false);
437 // No ResultSet was produced. Raise an exception
438 m_pConnection
->throwGenericSQLException(STR_NO_RESULTSET
,*this);
444 Reference
< XConnection
> SAL_CALL
OStatement_Base::getConnection( )
446 ::osl::MutexGuard
aGuard( m_aMutex
);
447 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
449 return m_pConnection
;
453 Any SAL_CALL
OStatement::queryInterface( const Type
& rType
)
455 Any aRet
= ::cppu::queryInterface(rType
,static_cast< XBatchExecution
*> (this));
456 return aRet
.hasValue() ? aRet
: OStatement_Base::queryInterface(rType
);
460 void SAL_CALL
OStatement::addBatch( const OUString
& sql
)
462 ::osl::MutexGuard
aGuard( m_aMutex
);
463 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
466 m_aBatchVector
.push_back(sql
);
469 Sequence
< sal_Int32
> SAL_CALL
OStatement::executeBatch( )
471 ::osl::MutexGuard
aGuard( m_aMutex
);
472 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
474 OStringBuffer aBatchSql
;
475 sal_Int32 nLen
= m_aBatchVector
.size();
477 for (auto const& elem
: m_aBatchVector
)
479 aBatchSql
.append(OUStringToOString(elem
,getOwnConnection()->getTextEncoding()));
480 aBatchSql
.append(";");
483 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
484 auto s
= aBatchSql
.makeStringAndClear();
485 THROW_SQL(N3SQLExecDirect(m_aStatementHandle
, reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(s
.getStr())), s
.getLength()));
487 Sequence
< sal_Int32
> aRet(nLen
);
488 sal_Int32
* pArray
= aRet
.getArray();
489 for(sal_Int32 j
=0;j
<nLen
;++j
)
491 SQLRETURN nError
= N3SQLMoreResults(m_aStatementHandle
);
492 if(nError
== SQL_SUCCESS
)
495 N3SQLRowCount(m_aStatementHandle
,&nRowCount
);
496 pArray
[j
] = nRowCount
;
503 sal_Int32 SAL_CALL
OStatement_Base::executeUpdate( const OUString
& sql
)
505 ::osl::MutexGuard
aGuard( m_aMutex
);
506 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
509 sal_Int32 numRows
= -1;
511 // Execute the statement. If execute returns false, a
514 if (!execute (sql
)) {
515 numRows
= getUpdateCount();
519 // No update count was produced (a ResultSet was). Raise
522 ::connectivity::SharedResources aResources
;
523 const OUString
sError( aResources
.getResourceString(STR_NO_ROWCOUNT
));
524 throw SQLException (sError
, *this,OUString(),0,Any());
531 Reference
< XResultSet
> SAL_CALL
OStatement_Base::getResultSet( )
533 ::osl::MutexGuard
aGuard( m_aMutex
);
534 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
537 m_xResultSet
= getResultSet(true);
542 sal_Int32 SAL_CALL
OStatement_Base::getUpdateCount( )
544 ::osl::MutexGuard
aGuard( m_aMutex
);
545 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
548 sal_Int32 rowCount
= -1;
550 // Only return a row count for SQL statements that did not
551 // return a result set.
553 if (getColumnCount () == 0)
554 rowCount
= getRowCount ();
560 sal_Bool SAL_CALL
OStatement_Base::getMoreResults( )
562 ::osl::MutexGuard
aGuard( m_aMutex
);
563 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
567 bool hasResultSet
= false;
569 // clear previous warnings
573 // Call SQLMoreResults
574 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
577 hasResultSet
= N3SQLMoreResults(m_aStatementHandle
) == SQL_SUCCESS
;
579 catch (const SQLWarning
&ex
) {
581 // Save pointer to warning and save with ResultSet
582 // object once it is created.
587 // There are more results (it may not be a result set, though)
592 // Now determine if there is a result set associated
593 // with the SQL statement that was executed. Get the
594 // column count, and if it is zero, there is not a
597 if (getColumnCount () == 0)
598 hasResultSet
= false;
601 // Set the warning for the statement, if one was generated
603 setWarning (warning
);
605 // Return the result set indicator
611 Any SAL_CALL
OStatement_Base::getWarnings( )
613 ::osl::MutexGuard
aGuard( m_aMutex
);
614 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
617 return makeAny(m_aLastWarning
);
621 void SAL_CALL
OStatement_Base::clearWarnings( )
623 ::osl::MutexGuard
aGuard( m_aMutex
);
624 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
627 m_aLastWarning
= SQLWarning();
631 sal_Int64
OStatement_Base::getQueryTimeOut() const
633 return getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_QUERY_TIMEOUT
);
636 sal_Int64
OStatement_Base::getMaxRows() const
638 return getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_MAX_ROWS
);
641 sal_Int32
OStatement_Base::getResultSetConcurrency() const
643 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
644 SQLULEN
nValue (getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CONCURRENCY
));
645 if(nValue
== SQL_CONCUR_READ_ONLY
)
646 nValue
= ResultSetConcurrency::READ_ONLY
;
648 nValue
= ResultSetConcurrency::UPDATABLE
;
652 sal_Int32
OStatement_Base::getResultSetType() const
654 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
655 SQLULEN
nValue (getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CURSOR_TYPE
));
658 case SQL_CURSOR_FORWARD_ONLY
:
659 nValue
= ResultSetType::FORWARD_ONLY
;
661 case SQL_CURSOR_KEYSET_DRIVEN
:
662 case SQL_CURSOR_STATIC
:
663 nValue
= ResultSetType::SCROLL_INSENSITIVE
;
665 case SQL_CURSOR_DYNAMIC
:
666 nValue
= ResultSetType::SCROLL_SENSITIVE
;
669 OSL_FAIL("Unknown ODBC Cursor Type");
675 sal_Int32
OStatement_Base::getFetchDirection() const
677 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
678 SQLULEN
nValue (getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CURSOR_SCROLLABLE
));
682 nValue
= FetchDirection::REVERSE
;
685 nValue
= FetchDirection::FORWARD
;
692 sal_Int32
OStatement_Base::getFetchSize() const
694 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
695 return getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_ROW_ARRAY_SIZE
);
698 sal_Int64
OStatement_Base::getMaxFieldSize() const
700 return getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_MAX_LENGTH
);
703 OUString
OStatement_Base::getCursorName() const
705 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
707 SQLSMALLINT nRealLen
= 0;
708 N3SQLGetCursorName(m_aStatementHandle
,pName
,256,&nRealLen
);
709 return OUString::createFromAscii(reinterpret_cast<char*>(pName
));
712 void OStatement_Base::setQueryTimeOut(sal_Int64 seconds
)
714 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
715 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_QUERY_TIMEOUT
,seconds
);
718 void OStatement_Base::setMaxRows(sal_Int64 _par0
)
720 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
721 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_MAX_ROWS
, _par0
);
724 void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0
)
727 if(_par0
== ResultSetConcurrency::READ_ONLY
)
728 nSet
= SQL_CONCUR_READ_ONLY
;
730 nSet
= SQL_CONCUR_VALUES
;
732 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
733 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CONCURRENCY
, nSet
);
736 void OStatement_Base::setResultSetType(sal_Int32 _par0
)
739 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
740 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_ROW_BIND_TYPE
, SQL_BIND_BY_COLUMN
);
742 bool bUseBookmark
= isUsingBookmarks();
743 SQLULEN
nSet( SQL_UNSPECIFIED
);
746 case ResultSetType::FORWARD_ONLY
:
747 nSet
= SQL_UNSPECIFIED
;
749 case ResultSetType::SCROLL_INSENSITIVE
:
750 nSet
= SQL_INSENSITIVE
;
751 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CURSOR_TYPE
, SQL_CURSOR_KEYSET_DRIVEN
);
753 case ResultSetType::SCROLL_SENSITIVE
:
756 SQLUINTEGER nCurProp
= getCursorProperties(SQL_CURSOR_DYNAMIC
,true);
757 if((nCurProp
& SQL_CA1_BOOKMARK
) != SQL_CA1_BOOKMARK
) // check if bookmark for this type isn't supported
758 { // we have to test the next one
759 nCurProp
= getCursorProperties(SQL_CURSOR_KEYSET_DRIVEN
,true);
760 bool bNotBookmarks
= ((nCurProp
& SQL_CA1_BOOKMARK
) != SQL_CA1_BOOKMARK
);
761 nCurProp
= getCursorProperties(SQL_CURSOR_KEYSET_DRIVEN
,false);
762 nSet
= SQL_CURSOR_KEYSET_DRIVEN
;
764 ((nCurProp
& SQL_CA2_SENSITIVITY_DELETIONS
) != SQL_CA2_SENSITIVITY_DELETIONS
) ||
765 ((nCurProp
& SQL_CA2_SENSITIVITY_ADDITIONS
) != SQL_CA2_SENSITIVITY_ADDITIONS
))
767 // bookmarks for keyset isn't supported so reset bookmark setting
768 setUsingBookmarks(false);
769 nSet
= SQL_CURSOR_DYNAMIC
;
773 nSet
= SQL_CURSOR_DYNAMIC
;
776 nSet
= SQL_CURSOR_DYNAMIC
;
777 if( setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CURSOR_TYPE
, nSet
) != SQL_SUCCESS
)
779 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CURSOR_TYPE
, SQL_CURSOR_KEYSET_DRIVEN
);
781 nSet
= SQL_SENSITIVE
;
784 OSL_FAIL( "OStatement_Base::setResultSetType: invalid result set type!" );
789 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CURSOR_SENSITIVITY
, nSet
);
792 void OStatement_Base::setEscapeProcessing( const bool _bEscapeProc
)
794 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
795 SQLULEN
nEscapeProc( _bEscapeProc
? SQL_NOSCAN_OFF
: SQL_NOSCAN_ON
);
796 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_NOSCAN
, nEscapeProc
);
800 void OStatement_Base::setFetchDirection(sal_Int32 _par0
)
802 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
803 if(_par0
== FetchDirection::FORWARD
)
805 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CURSOR_SCROLLABLE
, SQL_NONSCROLLABLE
);
807 else if(_par0
== FetchDirection::REVERSE
)
809 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_CURSOR_SCROLLABLE
, SQL_SCROLLABLE
);
813 void OStatement_Base::setFetchSize(sal_Int32 _par0
)
815 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
816 OSL_ENSURE(_par0
>0,"Illegal fetch size!");
819 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_ROW_ARRAY_SIZE
, _par0
);
821 delete[] m_pRowStatusArray
;
822 m_pRowStatusArray
= new SQLUSMALLINT
[_par0
];
823 setStmtOption
<SQLUSMALLINT
*, SQL_IS_POINTER
>(SQL_ATTR_ROW_STATUS_PTR
, m_pRowStatusArray
);
827 void OStatement_Base::setMaxFieldSize(sal_Int64 _par0
)
829 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
830 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_MAX_LENGTH
, _par0
);
833 void OStatement_Base::setCursorName(std::u16string_view _par0
)
835 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
836 OString
aName(OUStringToOString(_par0
,getOwnConnection()->getTextEncoding()));
837 N3SQLSetCursorName(m_aStatementHandle
, reinterpret_cast<SDB_ODBC_CHAR
*>(const_cast<char *>(aName
.getStr())), static_cast<SQLSMALLINT
>(aName
.getLength()));
840 bool OStatement_Base::isUsingBookmarks() const
842 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
843 return SQL_UB_OFF
!= getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_USE_BOOKMARKS
);
846 bool OStatement_Base::getEscapeProcessing() const
848 OSL_ENSURE( m_aStatementHandle
, "StatementHandle is null!" );
849 return SQL_NOSCAN_OFF
== getStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_USE_BOOKMARKS
);
852 void OStatement_Base::setUsingBookmarks(bool _bUseBookmark
)
854 OSL_ENSURE(m_aStatementHandle
,"StatementHandle is null!");
855 SQLULEN nValue
= _bUseBookmark
? SQL_UB_VARIABLE
: SQL_UB_OFF
;
856 setStmtOption
<SQLULEN
, SQL_IS_UINTEGER
>(SQL_ATTR_USE_BOOKMARKS
, nValue
);
859 ::cppu::IPropertyArrayHelper
* OStatement_Base::createArrayHelper( ) const
861 Sequence
< Property
> aProps(10);
862 Property
* pProperties
= aProps
.getArray();
864 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME
),
865 PROPERTY_ID_CURSORNAME
, cppu::UnoType
<OUString
>::get(), 0);
866 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING
),
867 PROPERTY_ID_ESCAPEPROCESSING
, cppu::UnoType
<bool>::get(), 0);
868 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION
),
869 PROPERTY_ID_FETCHDIRECTION
, cppu::UnoType
<sal_Int32
>::get(), 0);
870 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE
),
871 PROPERTY_ID_FETCHSIZE
, cppu::UnoType
<sal_Int32
>::get(), 0);
872 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE
),
873 PROPERTY_ID_MAXFIELDSIZE
, cppu::UnoType
<sal_Int32
>::get(), 0);
874 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS
),
875 PROPERTY_ID_MAXROWS
, cppu::UnoType
<sal_Int32
>::get(), 0);
876 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT
),
877 PROPERTY_ID_QUERYTIMEOUT
, cppu::UnoType
<sal_Int32
>::get(), 0);
878 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY
),
879 PROPERTY_ID_RESULTSETCONCURRENCY
, cppu::UnoType
<sal_Int32
>::get(), 0);
880 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE
),
881 PROPERTY_ID_RESULTSETTYPE
, cppu::UnoType
<sal_Int32
>::get(), 0);
882 pProperties
[nPos
++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS
),
883 PROPERTY_ID_USEBOOKMARKS
, cppu::UnoType
<bool>::get(), 0);
885 return new ::cppu::OPropertyArrayHelper(aProps
);
889 ::cppu::IPropertyArrayHelper
& OStatement_Base::getInfoHelper()
891 return *getArrayHelper();
894 sal_Bool
OStatement_Base::convertFastPropertyValue(
895 Any
& rConvertedValue
,
900 bool bConverted
= false;
905 case PROPERTY_ID_QUERYTIMEOUT
:
906 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getQueryTimeOut());
909 case PROPERTY_ID_MAXFIELDSIZE
:
910 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getMaxFieldSize());
913 case PROPERTY_ID_MAXROWS
:
914 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getMaxRows());
917 case PROPERTY_ID_CURSORNAME
:
918 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getCursorName());
921 case PROPERTY_ID_RESULTSETCONCURRENCY
:
922 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getResultSetConcurrency());
925 case PROPERTY_ID_RESULTSETTYPE
:
926 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getResultSetType());
929 case PROPERTY_ID_FETCHDIRECTION
:
930 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchDirection());
933 case PROPERTY_ID_FETCHSIZE
:
934 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchSize());
937 case PROPERTY_ID_USEBOOKMARKS
:
938 bConverted
= ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, isUsingBookmarks());
941 case PROPERTY_ID_ESCAPEPROCESSING
:
942 bConverted
= ::comphelper::tryPropertyValue( rConvertedValue
, rOldValue
, rValue
, getEscapeProcessing() );
947 catch(const SQLException
&)
949 // throw Exception(e.Message,*this);
954 void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)
960 case PROPERTY_ID_QUERYTIMEOUT
:
961 setQueryTimeOut(comphelper::getINT64(rValue
));
963 case PROPERTY_ID_MAXFIELDSIZE
:
964 setMaxFieldSize(comphelper::getINT64(rValue
));
966 case PROPERTY_ID_MAXROWS
:
967 setMaxRows(comphelper::getINT64(rValue
));
969 case PROPERTY_ID_CURSORNAME
:
970 setCursorName(comphelper::getString(rValue
));
972 case PROPERTY_ID_RESULTSETCONCURRENCY
:
973 setResultSetConcurrency(comphelper::getINT32(rValue
));
975 case PROPERTY_ID_RESULTSETTYPE
:
976 setResultSetType(comphelper::getINT32(rValue
));
978 case PROPERTY_ID_FETCHDIRECTION
:
979 setFetchDirection(comphelper::getINT32(rValue
));
981 case PROPERTY_ID_FETCHSIZE
:
982 setFetchSize(comphelper::getINT32(rValue
));
984 case PROPERTY_ID_USEBOOKMARKS
:
985 setUsingBookmarks(comphelper::getBOOL(rValue
));
987 case PROPERTY_ID_ESCAPEPROCESSING
:
988 setEscapeProcessing( ::comphelper::getBOOL( rValue
) );
991 OSL_FAIL( "OStatement_Base::setFastPropertyValue_NoBroadcast: what property?" );
995 catch(const SQLException
& )
997 // throw Exception(e.Message,*this);
1001 void OStatement_Base::getFastPropertyValue(Any
& rValue
,sal_Int32 nHandle
) const
1005 case PROPERTY_ID_QUERYTIMEOUT
:
1006 rValue
<<= getQueryTimeOut();
1008 case PROPERTY_ID_MAXFIELDSIZE
:
1009 rValue
<<= getMaxFieldSize();
1011 case PROPERTY_ID_MAXROWS
:
1012 rValue
<<= getMaxRows();
1014 case PROPERTY_ID_CURSORNAME
:
1015 rValue
<<= getCursorName();
1017 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1018 rValue
<<= getResultSetConcurrency();
1020 case PROPERTY_ID_RESULTSETTYPE
:
1021 rValue
<<= getResultSetType();
1023 case PROPERTY_ID_FETCHDIRECTION
:
1024 rValue
<<= getFetchDirection();
1026 case PROPERTY_ID_FETCHSIZE
:
1027 rValue
<<= getFetchSize();
1029 case PROPERTY_ID_USEBOOKMARKS
:
1030 rValue
<<= isUsingBookmarks();
1032 case PROPERTY_ID_ESCAPEPROCESSING
:
1033 rValue
<<= getEscapeProcessing();
1036 OSL_FAIL( "OStatement_Base::getFastPropertyValue: what property?" );
1041 IMPLEMENT_SERVICE_INFO(OStatement
,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
1043 void SAL_CALL
OStatement_Base::acquire() noexcept
1045 OStatement_BASE::acquire();
1048 void SAL_CALL
OStatement_Base::release() noexcept
1050 OStatement_BASE::release();
1053 void SAL_CALL
OStatement::acquire() noexcept
1055 OStatement_BASE2::acquire();
1058 void SAL_CALL
OStatement::release() noexcept
1060 OStatement_BASE2::release();
1063 rtl::Reference
<OResultSet
> OStatement_Base::createResultSet()
1065 return new OResultSet(m_aStatementHandle
,this);
1068 Reference
< css::beans::XPropertySetInfo
> SAL_CALL
OStatement_Base::getPropertySetInfo( )
1070 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1073 SQLUINTEGER
OStatement_Base::getCursorProperties(SQLINTEGER _nCursorType
, bool bFirst
)
1075 SQLUINTEGER nValueLen
= 0;
1078 SQLUSMALLINT nAskFor
= SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2
;
1079 if(SQL_CURSOR_KEYSET_DRIVEN
== _nCursorType
)
1080 nAskFor
= bFirst
? SQL_KEYSET_CURSOR_ATTRIBUTES1
: SQL_KEYSET_CURSOR_ATTRIBUTES2
;
1081 else if(SQL_CURSOR_STATIC
== _nCursorType
)
1082 nAskFor
= bFirst
? SQL_STATIC_CURSOR_ATTRIBUTES1
: SQL_STATIC_CURSOR_ATTRIBUTES2
;
1083 else if(SQL_CURSOR_FORWARD_ONLY
== _nCursorType
)
1084 nAskFor
= bFirst
? SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1
: SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2
;
1085 else if(SQL_CURSOR_DYNAMIC
== _nCursorType
)
1086 nAskFor
= bFirst
? SQL_DYNAMIC_CURSOR_ATTRIBUTES1
: SQL_DYNAMIC_CURSOR_ATTRIBUTES2
;
1089 OTools::GetInfo(getOwnConnection(),getConnectionHandle(),nAskFor
,nValueLen
,nullptr);
1091 catch(const Exception
&)
1092 { // we don't want our result destroy here
1099 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */