22#include <osl/diagnose.h>
25#include <com/sun/star/io/IOException.hpp>
26#include <com/sun/star/sdbc/DataType.hpp>
57 const bool bUseWChar =
false;
60OPreparedStatement::OPreparedStatement(
OConnection* _pConnection,
const OUString&
sql)
96 ::osl::MutexGuard aGuard(
m_aMutex );
110 ::osl::MutexGuard aGuard(
m_aMutex );
124 catch (SQLException &) {
135 ::osl::MutexGuard aGuard(
m_aMutex );
155 bool needData = nReturn == SQL_NEED_DATA;
165 sal_Int32* paramIndex =
nullptr;
171 if ( !paramIndex || ( *paramIndex == -1 ) )
183 catch (
const SQLWarning&)
198 ::osl::MutexGuard aGuard(
m_aMutex );
201 sal_Int32 numRows = -1;
213 m_pConnection->throwGenericSQLException(STR_NO_ROWCOUNT,*
this);
227 ::osl::MutexGuard aGuard(
m_aMutex );
236 ::osl::MutexGuard aGuard(
m_aMutex );
248 m_pConnection->throwGenericSQLException(STR_NO_RESULTSET,*
this);
257 setInt (parameterIndex,
x ? 1 : 0 );
278 ::osl::MutexGuard aGuard(
m_aMutex );
283 TnoRef *bindBuf =
static_cast< TnoRef*
>(
allocBindBuf(parameterIndex,
sizeof(i_Value)) );
286 setParameter(parameterIndex, i_nType, i_nColSize, i_nScale, bindBuf,
sizeof(i_Value),
sizeof(i_Value));
292 ::osl::MutexGuard aGuard(
m_aMutex );
295 assert (_nType == DataType::VARCHAR || _nType == DataType::CHAR || _nType == DataType::DECIMAL || _nType == DataType::NUMERIC);
319 static_assert(
sizeof (SQLWCHAR) == 2 ||
sizeof (SQLWCHAR) == 4,
"must be 2 or 4");
320 if (
sizeof (SQLWCHAR) == 2)
322 nCharLen = _sData.getLength();
323 nByteLen = 2 * nCharLen;
325 memcpy(
pData, _sData.getStr(), nByteLen);
330 sal_uInt32* pCursor =
static_cast<sal_uInt32*
>(
pData);
332 for (sal_Int32
i = 0;
i != _sData.getLength();)
334 *pCursor++ = _sData.iterateCodePoints(&
i);
337 nByteLen = 4 * nCharLen;
346 nCharLen = nByteLen = sOData.getLength();
348 memcpy(
pData, sOData.getStr(), nByteLen);
351 setParameter( parameterIndex, _nType, nCharLen, _nScale,
pData, nByteLen, nByteLen );
356 ::osl::MutexGuard aGuard(
m_aMutex );
359 assert(_nType == DataType::BINARY || _nType == DataType::VARBINARY);
369void OPreparedStatement::setParameter(
const sal_Int32 parameterIndex,
const sal_Int32 _nType,
const SQLULEN _nColumnSize,
const sal_Int32 _nScale,
const void*
const _pData,
const SQLULEN _nDataLen,
const SQLLEN _nDataAllocLen)
371 SQLSMALLINT fCType, fSqlType;
374 SQLLEN& rDataLen =
boundParams[parameterIndex-1].getBindLengthBuffer();
375 rDataLen = _nDataLen;
381 static_cast<SQLUSMALLINT
>(parameterIndex),
388 const_cast<void*
>(_pData),
403 setScalarParameter<DATE_STRUCT&>(parameterIndex, DataType::DATE, 10, x);
409 if(aVal.NanoSeconds == 0)
411 else if(aVal.NanoSeconds % 100000000 == 0)
413 else if(aVal.NanoSeconds % 10000000 == 0)
415 else if(aVal.NanoSeconds % 1000000 == 0)
417 else if(aVal.NanoSeconds % 100000 == 0)
419 else if(aVal.NanoSeconds % 10000 == 0)
421 else if(aVal.NanoSeconds % 1000 == 0)
423 else if(aVal.NanoSeconds % 100 == 0)
425 else if(aVal.NanoSeconds % 10 == 0)
430 setScalarParameter<TIME_STRUCT&>(parameterIndex, DataType::TIME, nColSize, (nColSize == 8)? 0 : nColSize-9,
x);
437 if(aVal.NanoSeconds == 0)
439 if (aVal.Seconds == 0)
444 else if(aVal.NanoSeconds % 100000000 == 0)
446 else if(aVal.NanoSeconds % 10000000 == 0)
448 else if(aVal.NanoSeconds % 1000000 == 0)
450 else if(aVal.NanoSeconds % 100000 == 0)
452 else if(aVal.NanoSeconds % 10000 == 0)
454 else if(aVal.NanoSeconds % 1000 == 0)
456 else if(aVal.NanoSeconds % 100 == 0)
458 else if(aVal.NanoSeconds % 10 == 0)
464 setScalarParameter<TIMESTAMP_STRUCT&>(parameterIndex, DataType::TIMESTAMP, nColSize, (nColSize <= 19)? 0 : nColSize-20, x);
501 ::osl::MutexGuard aGuard(
m_aMutex );
506 *lenBuf = SQL_NULL_DATA;
510 SQLSMALLINT fSqlType;
519 static_cast<SQLUSMALLINT
>(parameterIndex),
536 setStream(parameterIndex,
x->getCharacterStream(),
x->length(), DataType::LONGVARCHAR);
543 setStream(parameterIndex,
x->getBinaryStream(),
x->length(), DataType::LONGVARBINARY);
561 ::osl::MutexGuard aGuard(
m_aMutex );
570 case DataType::VARCHAR:
571 case DataType::LONGVARCHAR:
579 setNull(parameterIndex,sqlType);
581 case DataType::DECIMAL:
582 case DataType::NUMERIC:
590 setNull(parameterIndex,sqlType);
600 setNull(parameterIndex,sqlType);
608 throw SQLException();
629 setStream(parameterIndex, x, length, DataType::LONGVARCHAR);
635 setStream(parameterIndex, x, length, DataType::LONGVARBINARY);
641 ::osl::MutexGuard aGuard(
m_aMutex );
752 if ( !inputStream.is() )
756 throw SQLException (sError, *
this,OUString(),0,
Any());
762 sal_Int32 haveRead = 0;
771 haveRead = inputStream->readBytes( buf, toReadThisRound );
772 OSL_ENSURE( haveRead == buf.getLength(),
"OPreparedStatement::putParamData: inconsistency!" );
780 OSL_ENSURE(
m_aStatementHandle,
"OPreparedStatement::putParamData: StatementHandle is null!" );
784 maxBytesLeft -= haveRead;
786 while ( maxBytesLeft > 0 );
794 throw SQLException(
ex.Message,*
this,OUString(),0,
Any());
801 sal_Int32 ParameterIndex,
806 ::osl::MutexGuard aGuard(
m_aMutex );
821 sal_Int32* dataBuf =
static_cast<sal_Int32*
>(
allocBindBuf(ParameterIndex,
sizeof(ParameterIndex)) );
822 *dataBuf = ParameterIndex;
825 *lenBuf = SQL_LEN_DATA_AT_EXEC (
length);
827 SQLSMALLINT fCType, fSqlType;
833 static_cast<SQLUSMALLINT
>(ParameterIndex),
840 sizeof(ParameterIndex),
880 catch(
const SQLException&)
902 _parameterIndex < 1 ||
903 _parameterIndex > std::numeric_limits<SQLUSMALLINT>::max() )
907 "$pos$", OUString::number(_parameterIndex),
910 SQLException aNext(sError,*
this, OUString(),0,
Any());
#define N3SQLNumParams(a, b)
#define N3SQLBindParameter(a, b, c, d, e, f, g, h, i, j)
#define N3SQLPutData(a, b, c)
#define N3SQLParamData(a, b)
#define N3SQLPrepare(a, b, c)
#define N3SQLFreeStmt(a, b)
IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.OPreparedStatement","com.sun.star.sdbc.PreparedStatement")
OUString getString() const
void fill(sal_Int32 _nPos, sal_Int32 _nType, const css::uno::Reference< css::sdbc::XRow > &_xRow)
fetches a single value out of the row
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
OUString getResourceStringWithSubstitution(TranslateId pResId, const char *_pAsciiPatternToReplace, const OUString &_rStringToSubstitute) const
loads a string from the shared resource file, and replaces a given ASCII pattern with a given string
void setParameter(sal_Int32 parameterIndex, sal_Int32 _nType, SQLULEN _nColumnSize, sal_Int32 _nScale, const void *_pData, SQLULEN _nDataLen, SQLLEN _nDataAllocLen)
virtual void SAL_CALL release() noexcept override
virtual ~OPreparedStatement() override
virtual void SAL_CALL setDate(sal_Int32 parameterIndex, const css::util::Date &x) override
virtual rtl::Reference< OResultSet > createResultSet() override
creates the driver specific resultset (factory)
void * allocBindBuf(sal_Int32 index, sal_Int32 bufLen)
void putParamData(sal_Int32 index)
void setParameterPre(sal_Int32 parameterIndex)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL setTimestamp(sal_Int32 parameterIndex, const css::util::DateTime &x) override
static const short invalid_scale
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery() override
virtual void SAL_CALL setNull(sal_Int32 parameterIndex, sal_Int32 sqlType) override
virtual void SAL_CALL setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString &typeName) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL setByte(sal_Int32 parameterIndex, sal_Int8 x) override
virtual void SAL_CALL setTime(sal_Int32 parameterIndex, const css::util::Time &x) override
virtual void SAL_CALL setBlob(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XBlob > &x) override
virtual void SAL_CALL setRef(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XRef > &x) 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 setBoolean(sal_Int32 parameterIndex, sal_Bool x) override
virtual void SAL_CALL setClob(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XClob > &x) override
virtual void SAL_CALL setDouble(sal_Int32 parameterIndex, double x) override
virtual void SAL_CALL setShort(sal_Int32 parameterIndex, sal_Int16 x) override
virtual void SAL_CALL addBatch() override
virtual void SAL_CALL setString(sal_Int32 parameterIndex, const OUString &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 setInt(sal_Int32 parameterIndex, sal_Int32 x) override
virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch() override
virtual sal_Int32 SAL_CALL executeUpdate() override
virtual void SAL_CALL clearBatch() override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL setArray(sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XArray > &x) override
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection() override
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData
void setScalarParameter(sal_Int32 parameterIndex, sal_Int32 _nType, SQLULEN _nColumnSize, const T i_Value)
std::unique_ptr< OBoundParam[]> boundParams
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
virtual sal_Bool SAL_CALL execute() override
virtual void SAL_CALL clearParameters() 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 setObject(sal_Int32 parameterIndex, const css::uno::Any &x) override
void setStream(sal_Int32 ParameterIndex, const css::uno::Reference< css::io::XInputStream > &x, SQLLEN length, sal_Int32 SQLtype)
virtual void SAL_CALL setBytes(sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 > &x) override
virtual void SAL_CALL close() override
SQLLEN * getLengthBuf(sal_Int32 index)
virtual void SAL_CALL setFloat(sal_Int32 parameterIndex, float x) override
virtual void SAL_CALL setLong(sal_Int32 parameterIndex, sal_Int64 x) override
void checkParameterIndex(sal_Int32 _parameterIndex)
virtual void SAL_CALL acquire() noexcept override
void setUsingBookmarks(bool _bUseBookmark)
sal_Int32 getColumnCount()
virtual void SAL_CALL acquire() noexcept override
void setResultSetType(sal_Int32 _par0)
virtual sal_Int32 SAL_CALL getUpdateCount() override
void setResultSetConcurrency(sal_Int32 _par0)
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL close() override
virtual void SAL_CALL clearWarnings() override
void setFetchDirection(sal_Int32 _par0)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
SQLHANDLE m_aStatementHandle
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet() override
rtl::Reference< OConnection > m_pConnection
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
OConnection * getOwnConnection() const
virtual void SAL_CALL release() noexcept override
mutable::osl::Mutex m_aMutex
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
std::unique_ptr< sal_Int32[]> pData
bool getBOOL(const Any &_rAny)
sal_Int32 getINT32(const Any &_rAny)
OUString getString(const Any &_rAny)
const sal_Int32 MAX_PUT_DATA_LENGTH
SQLRETURN(SQL_API * T3SQLBindParameter)(SQLHSTMT StatementHandle, SQLUSMALLINT ParameterNumber, SQLSMALLINT InputOutputType, SQLSMALLINT ValueType, SQLSMALLINT ParameterType, SQLULEN ColumnSize, SQLSMALLINT DecimalDigits, SQLPOINTER ParameterValuePtr, SQLLEN BufferLength, SQLLEN *StrLen_or_IndPtr)
void checkDisposed(bool _bThrow)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
#define PROPERTY_ID_RESULTSETTYPE
#define PROPERTY_ID_USEBOOKMARKS
#define PROPERTY_ID_RESULTSETCONCURRENCY
#define PROPERTY_ID_FETCHDIRECTION