21#include <osl/diagnose.h>
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>
35#include <rtl/strbuf.hxx>
43 OTools::ThrowException(m_pConnection.get(),x,m_aStatementHandle,SQL_HANDLE_STMT,*this)
60 ,m_pConnection(_pConnection)
61 ,m_aStatementHandle(SQL_NULL_HANDLE)
62 ,m_pRowStatusArray(nullptr)
101 OSL_ENSURE(
m_aStatementHandle,
"OStatement_BASE2::disposing: StatementHandle is null!");
109 OStatement_BASE::disposing();
114 ::osl::MutexGuard aGuard1(
m_aMutex);
122 Any aRet = OStatement_BASE::queryInterface(rType);
134 auto [
begin,
end] = asNonConstRange(aOldTypes);
135 auto newEnd = std::remove(
begin,
end,
137 aOldTypes.realloc(std::distance(
begin, newEnd));
140 return ::comphelper::concatSequences(
aTypes.getTypes(),aOldTypes);
145 OSL_ENSURE(
m_pConnection.is() &&
m_pConnection->isAutoRetrievingEnabled(),
"Illegal call here. isAutoRetrievingEnabled is false!");
150 if ( !sStmt.isEmpty() )
162 ::osl::MutexGuard aGuard(
m_aMutex );
173 ::osl::MutexGuard aGuard(
m_aMutex );
188 ::osl::MutexGuard aGuard(
m_aMutex );
208 ::osl::MutexGuard aGuard(
m_aMutex );
215 if ( xCloseable.is() )
218 catch(
const DisposedException& ) { }
225 ::osl::MutexGuard aGuard(
m_aMutex );
234 catch (
const SQLException&)
250 OUString sqlStatement =
sql.toAsciiUpperCase ();
255 sal_Int32
index = sqlStatement.indexOf(
" FOR UPDATE");
265 THROW_SQL((setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CONCURRENCY, SQL_CONCUR_LOCK)));
267 catch (
const SQLWarning& warn)
284 ::osl::MutexGuard aGuard(
m_aMutex );
296 ::osl::MutexGuard aGuard(
m_aMutex );
300 sal_Int16 numCols = 0;
306 catch (
const SQLException&)
315 ::osl::MutexGuard aGuard(
m_aMutex );
322 bool hasResultSet =
false;
339 catch (
const SQLWarning&) {
363 ::osl::MutexGuard aGuard(
m_aMutex );
374 sal_Int32 numCols = 1;
415 SQLPOINTER sv =
reinterpret_cast<SQLPOINTER
>(
value);
422 ::osl::MutexGuard aGuard(
m_aMutex );
439 m_pConnection->throwGenericSQLException(STR_NO_RESULTSET,*
this);
447 ::osl::MutexGuard aGuard(
m_aMutex );
456 Any aRet = ::cppu::queryInterface(rType,
static_cast< XBatchExecution*
> (
this));
463 ::osl::MutexGuard aGuard(
m_aMutex );
472 ::osl::MutexGuard aGuard(
m_aMutex );
475 OStringBuffer aBatchSql;
485 auto s = aBatchSql.makeStringAndClear();
489 sal_Int32* pArray = aRet.getArray();
490 for(sal_Int32 j=0;j<nLen;++j)
493 if(nError == SQL_SUCCESS)
497 pArray[j] = nRowCount;
506 ::osl::MutexGuard aGuard(
m_aMutex );
510 sal_Int32 numRows = -1;
525 throw SQLException (sError, *
this,OUString(),0,
Any());
534 ::osl::MutexGuard aGuard(
m_aMutex );
545 ::osl::MutexGuard aGuard(
m_aMutex );
549 sal_Int32 rowCount = -1;
563 ::osl::MutexGuard aGuard(
m_aMutex );
568 bool hasResultSet =
false;
580 catch (
const SQLWarning &
ex) {
599 hasResultSet =
false;
614 ::osl::MutexGuard aGuard(
m_aMutex );
624 ::osl::MutexGuard aGuard(
m_aMutex );
634 return getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_QUERY_TIMEOUT);
639 return getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_MAX_ROWS);
645 SQLULEN
nValue (getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CONCURRENCY));
646 if(
nValue == SQL_CONCUR_READ_ONLY)
647 nValue = ResultSetConcurrency::READ_ONLY;
649 nValue = ResultSetConcurrency::UPDATABLE;
656 SQLULEN
nValue (getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE));
659 case SQL_CURSOR_FORWARD_ONLY:
660 nValue = ResultSetType::FORWARD_ONLY;
662 case SQL_CURSOR_KEYSET_DRIVEN:
663 case SQL_CURSOR_STATIC:
664 nValue = ResultSetType::SCROLL_INSENSITIVE;
666 case SQL_CURSOR_DYNAMIC:
667 nValue = ResultSetType::SCROLL_SENSITIVE;
670 OSL_FAIL(
"Unknown ODBC Cursor Type");
679 SQLULEN
nValue (getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SCROLLABLE));
683 nValue = FetchDirection::REVERSE;
686 nValue = FetchDirection::FORWARD;
696 return getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_ARRAY_SIZE);
701 return getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_MAX_LENGTH);
708 SQLSMALLINT nRealLen = 0;
710 return OUString::createFromAscii(
reinterpret_cast<char*
>(
pName));
716 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_QUERY_TIMEOUT,seconds);
722 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_MAX_ROWS, _par0);
728 if(_par0 == ResultSetConcurrency::READ_ONLY)
729 nSet = SQL_CONCUR_READ_ONLY;
731 nSet = SQL_CONCUR_VALUES;
734 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CONCURRENCY, nSet);
741 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN);
744 SQLULEN nSet( SQL_UNSPECIFIED );
747 case ResultSetType::FORWARD_ONLY:
748 nSet = SQL_UNSPECIFIED;
750 case ResultSetType::SCROLL_INSENSITIVE:
751 nSet = SQL_INSENSITIVE;
752 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_KEYSET_DRIVEN);
754 case ResultSetType::SCROLL_SENSITIVE:
758 if((nCurProp & SQL_CA1_BOOKMARK) != SQL_CA1_BOOKMARK)
761 bool bNotBookmarks = ((nCurProp & SQL_CA1_BOOKMARK) != SQL_CA1_BOOKMARK);
763 nSet = SQL_CURSOR_KEYSET_DRIVEN;
765 ((nCurProp & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS) ||
766 ((nCurProp & SQL_CA2_SENSITIVITY_ADDITIONS) != SQL_CA2_SENSITIVITY_ADDITIONS))
770 nSet = SQL_CURSOR_DYNAMIC;
774 nSet = SQL_CURSOR_DYNAMIC;
777 nSet = SQL_CURSOR_DYNAMIC;
778 if( setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE, nSet) != SQL_SUCCESS )
780 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_KEYSET_DRIVEN);
782 nSet = SQL_SENSITIVE;
785 OSL_FAIL(
"OStatement_Base::setResultSetType: invalid result set type!" );
790 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SENSITIVITY, nSet);
796 SQLULEN nEscapeProc( _bEscapeProc ? SQL_NOSCAN_OFF : SQL_NOSCAN_ON );
797 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_NOSCAN, nEscapeProc);
804 if(_par0 == FetchDirection::FORWARD)
806 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SCROLLABLE, SQL_NONSCROLLABLE);
808 else if(_par0 == FetchDirection::REVERSE)
810 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_SCROLLABLE, SQL_SCROLLABLE);
817 OSL_ENSURE(_par0>0,
"Illegal fetch size!");
820 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_ROW_ARRAY_SIZE, _par0);
824 setStmtOption<SQLUSMALLINT*, SQL_IS_POINTER>(SQL_ATTR_ROW_STATUS_PTR,
m_pRowStatusArray);
831 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_MAX_LENGTH, _par0);
844 return SQL_UB_OFF != getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS);
850 return SQL_NOSCAN_OFF == getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS);
856 SQLULEN
nValue = _bUseBookmark ? SQL_UB_VARIABLE : SQL_UB_OFF;
857 setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_USE_BOOKMARKS,
nValue);
862 return new ::cppu::OPropertyArrayHelper
936 Any & rConvertedValue,
941 bool bConverted =
false;
947 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue,
getQueryTimeOut());
951 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue,
getMaxFieldSize());
955 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue,
getMaxRows());
959 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue,
getCursorName());
967 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue,
getResultSetType());
971 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue,
getFetchDirection());
975 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue,
getFetchSize());
979 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue,
isUsingBookmarks());
983 bConverted = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue,
getEscapeProcessing() );
988 catch(
const SQLException&)
1032 OSL_FAIL(
"OStatement_Base::setFastPropertyValue_NoBroadcast: what property?" );
1036 catch(
const SQLException& )
1077 OSL_FAIL(
"OStatement_Base::getFastPropertyValue: what property?" );
1086 OStatement_BASE::acquire();
1091 OStatement_BASE::release();
1111 return ::cppu::OPropertySetHelper::createPropertySetInfo(
getInfoHelper());
1116 SQLUINTEGER nValueLen = 0;
1119 SQLUSMALLINT nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2;
1120 if(SQL_CURSOR_KEYSET_DRIVEN == _nCursorType)
1121 nAskFor = bFirst ? SQL_KEYSET_CURSOR_ATTRIBUTES1 : SQL_KEYSET_CURSOR_ATTRIBUTES2;
1122 else if(SQL_CURSOR_STATIC == _nCursorType)
1123 nAskFor = bFirst ? SQL_STATIC_CURSOR_ATTRIBUTES1 : SQL_STATIC_CURSOR_ATTRIBUTES2;
1124 else if(SQL_CURSOR_FORWARD_ONLY == _nCursorType)
1125 nAskFor = bFirst ? SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1 : SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2;
1126 else if(SQL_CURSOR_DYNAMIC == _nCursorType)
1127 nAskFor = bFirst ? SQL_DYNAMIC_CURSOR_ATTRIBUTES1 : SQL_DYNAMIC_CURSOR_ATTRIBUTES2;
#define N3SQLRowCount(a, b)
#define N3SQLMoreResults(a)
#define N3SQLExecDirect(a, b, c)
#define N3SQLGetStmtAttr(a, b, c, d, e)
#define N3SQLSetCursorName(a, b, c)
#define N3SQLSetStmtAttr(a, b, c, d)
#define N3SQLNumResultCols(a, b)
#define N3SQLFreeStmt(a, b)
#define N3SQLGetCursorName(a, b, c, d)
IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement")
::cppu::IPropertyArrayHelper * getArrayHelper()
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
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
virtual void SAL_CALL disposing() override
bool lockIfNecessary(const OUString &sql)
virtual void SAL_CALL cancel() override
void setUsingBookmarks(bool _bUseBookmark)
SQLHANDLE getConnectionHandle()
SQLRETURN setStmtOption(SQLINTEGER fOption, T value) const
sal_Int32 getColumnCount()
sal_Int32 getResultSetConcurrency() const
void setMaxFieldSize(sal_Int64 _par0)
virtual void SAL_CALL acquire() noexcept override
void setCursorName(std::u16string_view _par0)
OUString getCursorName() const
sal_Int32 getFetchDirection() const
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
void setResultSetType(sal_Int32 _par0)
sal_Int32 getFetchSize() const
SQLUINTEGER getCursorProperties(SQLINTEGER _nCursorType, bool bFirst)
getCursorProperties return the properties for a specific cursor type
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection() override
void setQueryTimeOut(sal_Int64 _par0)
virtual sal_Bool SAL_CALL execute(const OUString &sql) override
virtual sal_Int32 SAL_CALL executeUpdate(const OUString &sql) override
virtual sal_Int32 SAL_CALL getUpdateCount() override
bool getEscapeProcessing() const
void setResultSetConcurrency(sal_Int32 _par0)
sal_Int64 getQueryTimeOut() const
sal_Int64 getMaxFieldSize() const
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL close() override
void setMaxRows(sal_Int64 _par0)
virtual void SAL_CALL clearWarnings() override
virtual css::uno::Any SAL_CALL getWarnings() override
css::uno::WeakReference< css::sdbc::XResultSet > m_xResultSet
void setWarning(const css::sdbc::SQLWarning &ex)
void setFetchDirection(sal_Int32 _par0)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual rtl::Reference< OResultSet > createResultSet()
creates the driver specific resultset (factory)
SQLHANDLE m_aStatementHandle
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
bool isUsingBookmarks() const
sal_Int64 getMaxRows() const
css::uno::Reference< css::sdbc::XStatement > m_xGeneratedStatement
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet() override
virtual sal_Bool SAL_CALL getMoreResults() override
std::vector< OUString > m_aBatchVector
SQLUSMALLINT * m_pRowStatusArray
virtual ~OStatement_Base() override
sal_Int32 getResultSetType() const
virtual void SAL_CALL disposing() override
rtl::Reference< OConnection > m_pConnection
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getGeneratedValues() override
OConnection * getOwnConnection() const
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
void setEscapeProcessing(const bool _bEscapeProc)
T getStmtOption(SQLINTEGER fOption) const
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery(const OUString &sql) override
css::sdbc::SQLWarning m_aLastWarning
void setFetchSize(sal_Int32 _par0)
virtual void SAL_CALL release() noexcept 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 addBatch(const OUString &sql) override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL clearBatch() override
virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch() override
mutable::osl::Mutex m_aMutex
css::uno::Type const & get()
bool getBOOL(const Any &_rAny)
sal_Int64 getINT64(const Any &_rAny)
sal_Int32 getINT32(const Any &_rAny)
OUString getString(const Any &_rAny)
::cppu::ImplHelper1< css::sdbc::XStatement > OStatement_Base
::cppu::WeakComponentImplHelper< css::sdbc::XStatement, css::sdbc::XWarningsSupplier, css::util::XCancellable, css::sdbc::XCloseable, css::sdbc::XGeneratedResultSet, css::sdbc::XMultipleResults > OStatement_BASE
void checkDisposed(bool _bThrow)
enumrange< T >::Iterator begin(enumrange< T >)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
#define PROPERTY_ID_RESULTSETTYPE
#define PROPERTY_ID_QUERYTIMEOUT
#define PROPERTY_ID_USEBOOKMARKS
#define PROPERTY_ID_CURSORNAME
#define PROPERTY_ID_RESULTSETCONCURRENCY
#define PROPERTY_ID_MAXFIELDSIZE
#define PROPERTY_ID_FETCHSIZE
#define PROPERTY_ID_MAXROWS
#define PROPERTY_ID_ESCAPEPROCESSING
#define PROPERTY_ID_FETCHDIRECTION