21#include <core_resource.hxx>
24#include <com/sun/star/container/XIndexAccess.hpp>
25#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
28#include <com/sun/star/sdbc/XPreparedStatement.hpp>
29#include <com/sun/star/sdbc/ColumnValue.hpp>
30#include <com/sun/star/sdbc/XParameters.hpp>
31#include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
34#include <com/sun/star/io/XInputStream.hpp>
36#include <rtl/ustrbuf.hxx>
38#include <osl/diagnose.h>
56OCacheSet::OCacheSet(sal_Int32 i_nMaxRows)
57 :m_nMaxRows(i_nMaxRows)
70 sQuote = xMeta->getIdentifierQuoteString();
76 OSL_ENSURE(_xDriverSet.is(),
"Invalid resultSet");
85 m_xSetMetaData = Reference<XResultSetMetaDataSupplier>(_xDriverSet,UNO_QUERY_THROW)->getMetaData();
95 for (sal_Int32
i=1;
i <=
nCount; ++
i,++pSignedIter,++pColumnIter,++pNullableIter)
97 *pNullableIter =
m_xSetMetaData->isNullable(
i) != ColumnValue::NO_NULLS;
102 Reference< XStatement> xStmt(
m_xDriverSet->getStatement(),UNO_QUERY);
107 Reference< XPreparedStatement> xPrepStmt(
m_xDriverSet->getStatement(),UNO_QUERY);
108 if ( xPrepStmt.is() )
128 SAL_WARN(
"dbaccess",
"Unknown Exception occurred");
135 OSL_ENSURE(_xTable.is(),
"OCacheSet::fillTableName: PropertySet is empty!");
138 Reference<XDatabaseMetaData> xMeta(
m_xConnection->getMetaData());
144 ,::dbtools::EComposeRule::InDataManipulation);
150 Reference<XPropertySet> xSet(_xTable,UNO_QUERY);
156 OUStringBuffer aValues(
" VALUES ( ");
161 for(; aIter != aEnd;++aIter)
163 aSql.append(::dbtools::quoteName( aQuote,
m_xSetMetaData->getColumnName(
i++)) +
",");
164 aValues.append(
"?,");
167 aSql[aSql.getLength() - 1] =
')';
168 aValues[aValues.getLength() - 1] =
')';
170 aSql.append(aValues);
173 Reference< XPreparedStatement > xPrep(
m_xConnection->prepareStatement(aSql.makeStringAndClear()));
174 Reference< XParameters > xParameter(xPrep,UNO_QUERY);
176 for(aIter = _rInsertRow->begin()+1; aIter != aEnd;++aIter,++
i)
179 xParameter->setNull(
i,aIter->getTypeKind());
192 ,OUStringBuffer& _sCondition
193 ,OUStringBuffer& _sParameter
194 ,std::vector< sal_Int32>& _rOrgValues)
198 Reference<XPropertySet> xSet(_xTable,UNO_QUERY);
201 Reference<XIndexesSupplier> xIndexSup(_xTable,UNO_QUERY);
202 Reference<XIndexAccess> xIndexes;
204 xIndexes.set(xIndexSup->getIndexes(),UNO_QUERY);
206 Reference<XPropertySet> xIndexColsSup;
207 std::vector< Reference<XNameAccess> > aAllIndexColumns;
210 for(sal_Int32 j=0;j<xIndexes->getCount();++j)
212 xIndexColsSup.set(xIndexes->getByIndex(j),UNO_QUERY);
213 if( xIndexColsSup.is()
217 aAllIndexColumns.push_back(Reference<XColumnsSupplier>(xIndexColsSup,UNO_QUERY_THROW)->getColumns());
221 OUString aColumnName;
223 static const char aAnd[] =
" AND ";
227 sal_Int32 nCheckCount = 1;
230 OUString sIsNull(
" IS NULL");
231 OUString sParam(
" = ?");
234 for(; aIter != aEnd;++aIter,++nCheckCount,++
i)
237 if(xPrimaryKeyColumns.is() && xPrimaryKeyColumns->hasByName(aColumnName))
239 _sCondition.append(::dbtools::quoteName( aQuote,aColumnName));
241 _sCondition.append(sIsNull);
243 _sCondition.append(sParam);
244 _sCondition.append(aAnd);
245 _rOrgValues.push_back(nCheckCount);
248 for (
auto const& indexColumn : aAllIndexColumns)
250 if(indexColumn->hasByName(aColumnName))
252 _sCondition.append(::dbtools::quoteName( aQuote,aColumnName));
254 _sCondition.append(sIsNull);
256 _sCondition.append(sParam);
257 _sCondition.append(aAnd);
258 _rOrgValues.push_back(nCheckCount);
262 if(aIter->isModified())
264 _sParameter.append(::dbtools::quoteName( aQuote,aColumnName) +
"?,");
271 Reference<XPropertySet> xSet(_xTable,UNO_QUERY);
277 OUStringBuffer aCondition;
278 std::vector< sal_Int32> aOrgValues;
280 aSql[aSql.getLength() - 1] =
' ';
281 if ( !aCondition.isEmpty() )
283 aCondition.setLength(aCondition.getLength()-5);
285 aSql.append(
" WHERE " + aCondition);
288 ::dbtools::throwSQLException(
289 DBA_RES( RID_STR_NO_UPDATE_MISSING_CONDITION ), StandardSQLState::GENERAL_ERROR, *
this );
292 Reference< XPreparedStatement > xPrep(
m_xConnection->prepareStatement(aSql.makeStringAndClear()));
293 Reference< XParameters > xParameter(xPrep,UNO_QUERY);
298 if(aIter->isModified())
304 for (
auto const& orgValue : aOrgValues)
315 Reference<XPropertySet> xSet(_xTable,UNO_QUERY);
321 Reference<XIndexesSupplier> xIndexSup(_xTable,UNO_QUERY);
322 Reference<XIndexAccess> xIndexes;
324 xIndexes.set(xIndexSup->getIndexes(),UNO_QUERY);
327 Reference<XPropertySet> xIndexColsSup;
328 std::vector< Reference<XNameAccess> > aAllIndexColumns;
331 for(sal_Int32 j=0;j<xIndexes->getCount();++j)
333 xIndexColsSup.set(xIndexes->getByIndex(j),UNO_QUERY);
334 if( xIndexColsSup.is()
338 aAllIndexColumns.push_back(Reference<XColumnsSupplier>(xIndexColsSup,UNO_QUERY_THROW)->getColumns());
342 OUStringBuffer aColumnName;
343 std::vector< sal_Int32> aOrgValues;
346 aSql.setLength(aSql.getLength()-5);
349 Reference< XPreparedStatement > xPrep(
m_xConnection->prepareStatement(aSql.makeStringAndClear()));
350 Reference< XParameters > xParameter(xPrep,UNO_QUERY);
352 for (
auto const& orgValue : aOrgValues)
362 ,
const Reference< XParameters >& _xParameter
367 sal_Int32
nType = ( _nType != DataType::OTHER ) ? _nType : _rValue.
getTypeKind();
368 ::dbtools::setObjectWithInfo(_xParameter,
nPos,_rValue,
nType,_nScale);
374 if(!aBookmark.hasValue())
375 aBookmark <<= _nPosition;
379 (*aIter) = aBookmark;
381 for(sal_Int32
i=1;aIter != aEnd;++aIter,++
i)
563 o_aChangedColumns.push_back(i_nColumnIndex);
std::vector< VectorVal > Vector
sal_Int32 getTypeKind() const
std::vector< bool > m_aNullable
virtual sal_Bool SAL_CALL getBoolean(sal_Int32 columnIndex) override
virtual css::uno::Any getBookmark()=0
virtual css::util::DateTime SAL_CALL getTimestamp(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 columnIndex) override
virtual sal_Int8 SAL_CALL getByte(sal_Int32 columnIndex) override
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xSetMetaData
css::uno::Reference< css::sdbc::XResultSet > m_xDriverSet
virtual bool updateColumnValues(const ORowSetValueVector::Vector &io_aCachedRow, ORowSetValueVector::Vector &io_aRow, const std::vector< sal_Int32 > &i_aChangedColumns)
virtual void mergeColumnValues(sal_Int32 i_nColumnIndex, ORowSetValueVector::Vector &io_aInsertRow, ORowSetValueVector::Vector &io_aRow, std::vector< sal_Int32 > &o_aChangedColumns)
OUString m_aComposedTableName
css::uno::Reference< css::sdbc::XConnection > m_xConnection
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
virtual sal_Int64 SAL_CALL getLong(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 columnIndex) override
virtual bool rowInserted()
virtual void fillValueRow(ORowSetRow &_rRow, sal_Int32 _nPosition)
std::vector< bool > m_aSignedFlags
virtual void insertRow(const ORowSetRow &_rInsertRow, const connectivity::OSQLTable &_xTable)
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 columnIndex) override
virtual void beforeFirst()
virtual sal_Int32 SAL_CALL getInt(sal_Int32 columnIndex) override
virtual css::uno::Any SAL_CALL getObject(sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
css::uno::Reference< css::sdbc::XRow > m_xDriverRow
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 columnIndex) override
virtual css::util::Date SAL_CALL getDate(sal_Int32 columnIndex) override
void fillParameters(const ORowSetRow &_rRow, const connectivity::OSQLTable &_xTable, OUStringBuffer &_sCondition, OUStringBuffer &_sParameter, std::vector< sal_Int32 > &_rOrgValues)
virtual bool rowDeleted()
std::vector< sal_Int32 > m_aColumnTypes
virtual void refreshRow()
virtual bool columnValuesUpdated(ORowSetValueVector::Vector &o_aCachedRow, const ORowSetValueVector::Vector &i_aRow)
virtual void fillMissingValues(ORowSetValueVector::Vector &io_aRow) const
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 columnIndex) override
virtual float SAL_CALL getFloat(sal_Int32 columnIndex) override
virtual sal_Int32 getRow()
virtual void deleteRow(const ORowSetRow &_rDeleteRow, const connectivity::OSQLTable &_xTable)=0
virtual bool rowUpdated()
virtual sal_Int16 SAL_CALL getShort(sal_Int32 columnIndex) override
virtual double SAL_CALL getDouble(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 columnIndex) override
static void setParameter(sal_Int32 nPos, const css::uno::Reference< css::sdbc::XParameters > &_xParameter, const connectivity::ORowSetValue &_rValue, sal_Int32 _nType, sal_Int32 _nScale)
virtual sal_Bool SAL_CALL wasNull() override
virtual bool absolute(sal_Int32 row)
virtual void construct(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet, const OUString &i_sRowSetFilter)
virtual css::util::Time SAL_CALL getTime(sal_Int32 columnIndex) override
virtual void updateRow(const ORowSetRow &_rInsertRow, const ORowSetRow &_rOriginalRow, const connectivity::OSQLTable &_xTable)
OUString getIdentifierQuoteString() const
virtual bool isResultSetChanged() const
virtual ~OCacheSet() override
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 columnIndex) override
void fillTableName(const css::uno::Reference< css::beans::XPropertySet > &_xTable)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
bool getBOOL(const Any &_rAny)
OUString getString(const Any &_rAny)
css::uno::Reference< css::sdbcx::XColumnsSupplier > OSQLTable
constexpr OUStringLiteral PROPERTY_SCHEMANAME(u"SchemaName")
constexpr OUStringLiteral PROPERTY_CATALOGNAME(u"CatalogName")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
constexpr OUStringLiteral PROPERTY_ISUNIQUE(u"IsUnique")
constexpr OUStringLiteral PROPERTY_ISPRIMARYKEYINDEX(u"IsPrimaryKeyIndex")