Use for-range loops in dbaccess/KeySet (1st pass)

+ remove an unused var
+ fix a slight indent pb

Change-Id: Ie6e801c9d2b7ce6e7f5d352b2175fa9d7d6b9c7d
Reviewed-on: https://gerrit.libreoffice.org/46995
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
This commit is contained in:
Julien Nabet
2017-12-22 20:36:21 +01:00
parent 101a79cc4d
commit df8623e7ed

View File

@@ -125,12 +125,9 @@ OKeySet::~OKeySet()
{ {
tryDispose(m_xSet); tryDispose(m_xSet);
// m_xStatement is necessarily one of those // m_xStatement is necessarily one of those
const vStatements_t::const_iterator end(m_vStatements.end()); for (auto & statement : m_vStatements)
for(vStatements_t::iterator i(m_vStatements.begin());
i != end;
++i)
{ {
tryDispose(i->second); tryDispose(statement.second);
} }
m_xComposer = nullptr; m_xComposer = nullptr;
@@ -343,10 +340,8 @@ void OKeySet::ensureStatement( )
// of key & foreign columns? // of key & foreign columns?
FilterColumnsNULL_t FilterColumnsNULL; FilterColumnsNULL_t FilterColumnsNULL;
FilterColumnsNULL.reserve(m_aKeyIter->second.first->get().size()); FilterColumnsNULL.reserve(m_aKeyIter->second.first->get().size());
connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aIter = m_aKeyIter->second.first->get().begin(); for (auto const& elem : m_aKeyIter->second.first->get())
const connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aEnd = m_aKeyIter->second.first->get().end(); FilterColumnsNULL.push_back(elem.isNull());
for( ; aIter != aEnd; ++aIter )
FilterColumnsNULL.push_back(aIter->isNull());
vStatements_t::const_iterator pNewStatement(m_vStatements.find(FilterColumnsNULL)); vStatements_t::const_iterator pNewStatement(m_vStatements.find(FilterColumnsNULL));
if(pNewStatement == m_vStatements.end()) if(pNewStatement == m_vStatements.end())
{ {
@@ -480,14 +475,12 @@ void OKeySet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrigi
const sal_Int32 nOldLength = aSql.getLength(); const sal_Int32 nOldLength = aSql.getLength();
sal_Int32 i = 1; sal_Int32 i = 1;
// here we build the condition part for the update statement // here we build the condition part for the update statement
SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); for (auto const& columnName : *m_pColumnNames)
SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end();
for(;aIter != aEnd;++aIter,++i)
{ {
if ( m_pKeyColumnNames->find(aIter->first) != m_pKeyColumnNames->end() ) if ( m_pKeyColumnNames->find(columnName.first) != m_pKeyColumnNames->end() )
{ {
sKeyCondition.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); sKeyCondition.append(::dbtools::quoteName( aQuote,columnName.second.sRealName));
if((_rOriginalRow->get())[aIter->second.nPosition].isNull()) if((_rOriginalRow->get())[columnName.second.nPosition].isNull())
sKeyCondition.append(sIsNull); sKeyCondition.append(sIsNull);
else else
sKeyCondition.append(sParam); sKeyCondition.append(sParam);
@@ -495,29 +488,28 @@ void OKeySet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrigi
} }
else else
{ {
std::vector< Reference<XNameAccess> >::const_iterator aIndexEnd = aAllIndexColumns.end(); for (auto const& indexColumn : aAllIndexColumns)
for( std::vector< Reference<XNameAccess> >::const_iterator aIndexIter = aAllIndexColumns.begin();
aIndexIter != aIndexEnd;++aIndexIter)
{ {
if((*aIndexIter)->hasByName(aIter->first)) if(indexColumn->hasByName(columnName.first))
{ {
sIndexCondition.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); sIndexCondition.append(::dbtools::quoteName( aQuote,columnName.second.sRealName));
if((_rOriginalRow->get())[aIter->second.nPosition].isNull()) if((_rOriginalRow->get())[columnName.second.nPosition].isNull())
sIndexCondition.append(sIsNull); sIndexCondition.append(sIsNull);
else else
{ {
sIndexCondition.append(sParam); sIndexCondition.append(sParam);
aIndexColumnPositions.push_back(aIter->second.nPosition); aIndexColumnPositions.push_back(columnName.second.nPosition);
} }
sIndexCondition.append(aAnd); sIndexCondition.append(aAnd);
break; break;
} }
} }
} }
if((_rInsertRow->get())[aIter->second.nPosition].isModified()) if((_rInsertRow->get())[columnName.second.nPosition].isModified())
{ {
aSql.append(::dbtools::quoteName( aQuote,aIter->second.sRealName) + aPara); aSql.append(::dbtools::quoteName( aQuote,columnName.second.sRealName) + aPara);
} }
++i;
} }
if( aSql.getLength() != nOldLength ) if( aSql.getLength() != nOldLength )
@@ -561,51 +553,43 @@ void OKeySet::executeUpdate(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rO
Reference<XRow> xRow; Reference<XRow> xRow;
sal_Int32 i = 1; sal_Int32 i = 1;
// first the set values // first the set values
SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); for (auto const& columnName : *m_pColumnNames)
SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end();
sal_uInt16 j = 0;
for(;aIter != aEnd;++aIter,++j)
{ {
if ( i_sTableName.isEmpty() || aIter->second.sTableName == i_sTableName ) if ( i_sTableName.isEmpty() || columnName.second.sTableName == i_sTableName )
{ {
sal_Int32 nPos = aIter->second.nPosition; sal_Int32 nPos = columnName.second.nPosition;
if((_rInsertRow->get())[nPos].isModified()) if((_rInsertRow->get())[nPos].isModified())
{ {
if ( bRefetch ) if ( bRefetch )
{ {
bRefetch = std::find(m_aFilterColumns.begin(),m_aFilterColumns.end(),aIter->second.sRealName) == m_aFilterColumns.end(); bRefetch = std::find(m_aFilterColumns.begin(),m_aFilterColumns.end(),columnName.second.sRealName) == m_aFilterColumns.end();
} }
impl_convertValue_throw(_rInsertRow,aIter->second); impl_convertValue_throw(_rInsertRow,columnName.second);
(_rInsertRow->get())[nPos].setSigned((_rOriginalRow->get())[nPos].isSigned()); (_rInsertRow->get())[nPos].setSigned((_rOriginalRow->get())[nPos].isSigned());
setParameter(i++,xParameter,(_rInsertRow->get())[nPos],aIter->second.nType,aIter->second.nScale); setParameter(i++,xParameter,(_rInsertRow->get())[nPos],columnName.second.nType,columnName.second.nScale);
} }
} }
} }
// and then the values of the where condition // and then the values of the where condition
aIter = m_pKeyColumnNames->begin(); for (auto const& keyColumnName : *m_pKeyColumnNames)
aEnd = m_pKeyColumnNames->end();
j = 0;
for(;aIter != aEnd;++aIter,++j)
{ {
if ( i_sTableName.isEmpty() || aIter->second.sTableName == i_sTableName ) if ( i_sTableName.isEmpty() || keyColumnName.second.sTableName == i_sTableName )
{ {
setParameter(i++,xParameter,(_rOriginalRow->get())[aIter->second.nPosition],aIter->second.nType,aIter->second.nScale); setParameter(i++,xParameter,(_rOriginalRow->get())[keyColumnName.second.nPosition],keyColumnName.second.nType,keyColumnName.second.nScale);
} }
} }
if ( !_aIndexColumnPositions.empty() ) if ( !_aIndexColumnPositions.empty() )
{ {
// now we have to set the index values // now we have to set the index values
std::vector<sal_Int32>::const_iterator aIdxColIter = _aIndexColumnPositions.begin(); auto aIter = m_pColumnNames->begin();
std::vector<sal_Int32>::const_iterator aIdxColEnd = _aIndexColumnPositions.end(); for (auto const& indexColumnPosition : _aIndexColumnPositions)
j = 0;
aIter = m_pColumnNames->begin();
for(;aIdxColIter != aIdxColEnd;++aIdxColIter,++i,++j,++aIter)
{ {
setParameter(i,xParameter,(_rOriginalRow->get())[*aIdxColIter],(_rOriginalRow->get())[*aIdxColIter].getTypeKind(),aIter->second.nScale); setParameter(i++,xParameter,(_rOriginalRow->get())[indexColumnPosition],(_rOriginalRow->get())[indexColumnPosition].getTypeKind(),aIter->second.nScale);
++aIter;
} }
} }
const sal_Int32 nRowsUpdated = xPrep->executeUpdate(); const sal_Int32 nRowsUpdated = xPrep->executeUpdate();
m_bUpdated = nRowsUpdated > 0; m_bUpdated = nRowsUpdated > 0;
if(m_bUpdated) if(m_bUpdated)
{ {
const sal_Int32 nBookmark = ::comphelper::getINT32((_rInsertRow->get())[0].getAny()); const sal_Int32 nBookmark = ::comphelper::getINT32((_rInsertRow->get())[0].getAny());
@@ -745,12 +729,10 @@ void OKeySet::executeInsert( const ORowSetRow& _rInsertRow,const OUString& i_sSQ
const OUString sQuote = getIdentifierQuoteString(); const OUString sQuote = getIdentifierQuoteString();
OUString sMaxStmt; OUString sMaxStmt;
aEnd = m_pKeyColumnNames->end(); aEnd = m_pKeyColumnNames->end();
std::vector< OUString >::const_iterator aAutoIter = m_aAutoColumns.begin(); for (auto const& autoColumn : m_aAutoColumns)
std::vector< OUString >::const_iterator aAutoEnd = m_aAutoColumns.end();
for (;aAutoIter != aAutoEnd; ++aAutoIter)
{ {
// we will only fetch values which are keycolumns // we will only fetch values which are keycolumns
SelectColumnsMetaData::const_iterator aFind = m_pKeyColumnNames->find(*aAutoIter); SelectColumnsMetaData::const_iterator aFind = m_pKeyColumnNames->find(autoColumn);
if ( aFind != aEnd ) if ( aFind != aEnd )
{ {
sMaxStmt += sMax + ::dbtools::quoteName( sQuote,aFind->second.sRealName) + sMaxEnd; sMaxStmt += sMax + ::dbtools::quoteName( sQuote,aFind->second.sRealName) + sMaxEnd;
@@ -772,13 +754,13 @@ void OKeySet::executeInsert( const ORowSetRow& _rInsertRow,const OUString& i_sSQ
Reference<XRow> xRow(xRes,UNO_QUERY); Reference<XRow> xRow(xRes,UNO_QUERY);
if(xRow.is() && xRes->next()) if(xRow.is() && xRes->next())
{ {
aAutoIter = m_aAutoColumns.begin(); sal_Int32 i=1;
for (sal_Int32 i=1;aAutoIter != aAutoEnd; ++aAutoIter,++i) for (auto const& autoColumn : m_aAutoColumns)
{ {
// we will only fetch values which are keycolumns // we will only fetch values which are keycolumns
SelectColumnsMetaData::const_iterator aFind = m_pKeyColumnNames->find(*aAutoIter); SelectColumnsMetaData::const_iterator aFind = m_pKeyColumnNames->find(autoColumn);
if ( aFind != aEnd ) if ( aFind != aEnd )
(_rInsertRow->get())[aFind->second.nPosition].fill(i, aFind->second.nType, xRow); (_rInsertRow->get())[aFind->second.nPosition].fill(i++, aFind->second.nType, xRow);
} }
} }
::comphelper::disposeComponent(xStatement); ::comphelper::disposeComponent(xStatement);