connectivity/source/commontools/DriversConfig.cxx | 72 +- connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx | 170 ++--- connectivity/source/commontools/FValue.cxx | 206 +++--- connectivity/source/commontools/TColumnsHelper.cxx | 28 connectivity/source/commontools/TIndexes.cxx | 44 - connectivity/source/commontools/TKeys.cxx | 62 - connectivity/source/commontools/TTableHelper.cxx | 86 +- connectivity/source/commontools/conncleanup.cxx | 77 +- connectivity/source/commontools/dbtools.cxx | 130 +-- connectivity/source/drivers/calc/CTable.cxx | 300 ++++---- connectivity/source/drivers/dbase/DIndex.cxx | 40 - connectivity/source/drivers/dbase/DTable.cxx | 96 +- connectivity/source/drivers/dbase/dindexnode.cxx | 32 connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx | 72 +- connectivity/source/drivers/file/FPreparedStatement.cxx | 66 - connectivity/source/drivers/file/FResultSet.cxx | 58 - connectivity/source/drivers/file/FStatement.cxx | 30 connectivity/source/drivers/firebird/Blob.cxx | 22 connectivity/source/drivers/firebird/Connection.cxx | 75 +- connectivity/source/drivers/firebird/Keys.cxx | 22 connectivity/source/drivers/firebird/Table.cxx | 36 - connectivity/source/drivers/firebird/Tables.cxx | 20 connectivity/source/drivers/flat/ETable.cxx | 20 connectivity/source/drivers/hsqldb/HDriver.cxx | 62 - connectivity/source/drivers/hsqldb/HStorageAccess.cxx | 76 +- connectivity/source/drivers/hsqldb/HStorageMap.cxx | 30 connectivity/source/drivers/hsqldb/HTables.cxx | 56 - connectivity/source/drivers/hsqldb/HUser.cxx | 134 ++-- connectivity/source/drivers/hsqldb/StorageFileAccess.cxx | 68 +- connectivity/source/drivers/jdbc/CallableStatement.cxx | 56 - connectivity/source/drivers/jdbc/JConnection.cxx | 26 connectivity/source/drivers/jdbc/JStatement.cxx | 51 - connectivity/source/drivers/jdbc/PreparedStatement.cxx | 65 - connectivity/source/drivers/mork/MPreparedStatement.cxx | 18 connectivity/source/drivers/mork/MStatement.cxx | 30 connectivity/source/drivers/mysql_jdbc/YTables.cxx | 73 +- connectivity/source/drivers/mysql_jdbc/YUser.cxx | 186 ++--- connectivity/source/drivers/mysql_jdbc/YViews.cxx | 22 connectivity/source/drivers/odbc/OResultSet.cxx | 68 +- connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx | 99 +- connectivity/source/drivers/postgresql/pq_tools.cxx | 142 ++-- connectivity/source/drivers/postgresql/pq_xcontainer.cxx | 36 - connectivity/source/drivers/postgresql/pq_xtables.cxx | 124 +-- connectivity/source/manager/mdrivermanager.cxx | 98 +- connectivity/source/parse/sqlnode.cxx | 334 +++++----- 45 files changed, 1809 insertions(+), 1809 deletions(-)
New commits: commit 2d0bdcc586af71dae665646b37177fa104c50906 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sat Apr 18 10:51:27 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Apr 18 20:35:49 2020 +0200 loplugin:flatten connectivity Change-Id: Ic1d9eb84b64ebde99e15704a10b27f21447df4d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92469 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/connectivity/source/commontools/DriversConfig.cxx b/connectivity/source/commontools/DriversConfig.cxx index e165763d5e5e..9d2ab8a475d7 100644 --- a/connectivity/source/commontools/DriversConfig.cxx +++ b/connectivity/source/commontools/DriversConfig.cxx @@ -41,48 +41,48 @@ namespace void lcl_fillValues(const ::utl::OConfigurationNode& _aURLPatternNode,const OUString& _sNode,::comphelper::NamedValueCollection& _rValues) { const ::utl::OConfigurationNode aPropertiesNode = _aURLPatternNode.openNode(_sNode); - if ( aPropertiesNode.isValid() ) + if ( !aPropertiesNode.isValid() ) + return; + + uno::Sequence< OUString > aStringSeq; + const uno::Sequence< OUString > aProperties = aPropertiesNode.getNodeNames(); + const OUString* pPropertiesIter = aProperties.getConstArray(); + const OUString* pPropertiesEnd = pPropertiesIter + aProperties.getLength(); + for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter) { - uno::Sequence< OUString > aStringSeq; - const uno::Sequence< OUString > aProperties = aPropertiesNode.getNodeNames(); - const OUString* pPropertiesIter = aProperties.getConstArray(); - const OUString* pPropertiesEnd = pPropertiesIter + aProperties.getLength(); - for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter) + uno::Any aValue = aPropertiesNode.getNodeValue(*pPropertiesIter + "/Value"); + if ( aValue >>= aStringSeq ) { - uno::Any aValue = aPropertiesNode.getNodeValue(*pPropertiesIter + "/Value"); - if ( aValue >>= aStringSeq ) - { - lcl_convert(aStringSeq,aValue); - } - _rValues.put(*pPropertiesIter,aValue); - } // for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter,++pNamedIter) - } // if ( aPropertiesNode.isValid() ) + lcl_convert(aStringSeq,aValue); + } + _rValues.put(*pPropertiesIter,aValue); + } // for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter,++pNamedIter) } void lcl_readURLPatternNode(const ::utl::OConfigurationTreeRoot& _aInstalled,const OUString& _sEntry,TInstalledDriver& _rInstalledDriver) { const ::utl::OConfigurationNode aURLPatternNode = _aInstalled.openNode(_sEntry); - if ( aURLPatternNode.isValid() ) - { - OUString sParentURLPattern; - aURLPatternNode.getNodeValue("ParentURLPattern") >>= sParentURLPattern; - if ( !sParentURLPattern.isEmpty() ) - lcl_readURLPatternNode(_aInstalled,sParentURLPattern,_rInstalledDriver); - - OUString sDriverFactory; - aURLPatternNode.getNodeValue("Driver") >>= sDriverFactory; - if ( !sDriverFactory.isEmpty() ) - _rInstalledDriver.sDriverFactory = sDriverFactory; - - OUString sDriverTypeDisplayName; - aURLPatternNode.getNodeValue("DriverTypeDisplayName") >>= sDriverTypeDisplayName; - OSL_ENSURE(!sDriverTypeDisplayName.isEmpty(),"No valid DriverTypeDisplayName property!"); - if ( !sDriverTypeDisplayName.isEmpty() ) - _rInstalledDriver.sDriverTypeDisplayName = sDriverTypeDisplayName; - - lcl_fillValues(aURLPatternNode,"Properties",_rInstalledDriver.aProperties); - lcl_fillValues(aURLPatternNode,"Features",_rInstalledDriver.aFeatures); - lcl_fillValues(aURLPatternNode,"MetaData",_rInstalledDriver.aMetaData); - } + if ( !aURLPatternNode.isValid() ) + return; + + OUString sParentURLPattern; + aURLPatternNode.getNodeValue("ParentURLPattern") >>= sParentURLPattern; + if ( !sParentURLPattern.isEmpty() ) + lcl_readURLPatternNode(_aInstalled,sParentURLPattern,_rInstalledDriver); + + OUString sDriverFactory; + aURLPatternNode.getNodeValue("Driver") >>= sDriverFactory; + if ( !sDriverFactory.isEmpty() ) + _rInstalledDriver.sDriverFactory = sDriverFactory; + + OUString sDriverTypeDisplayName; + aURLPatternNode.getNodeValue("DriverTypeDisplayName") >>= sDriverTypeDisplayName; + OSL_ENSURE(!sDriverTypeDisplayName.isEmpty(),"No valid DriverTypeDisplayName property!"); + if ( !sDriverTypeDisplayName.isEmpty() ) + _rInstalledDriver.sDriverTypeDisplayName = sDriverTypeDisplayName; + + lcl_fillValues(aURLPatternNode,"Properties",_rInstalledDriver.aProperties); + lcl_fillValues(aURLPatternNode,"Features",_rInstalledDriver.aFeatures); + lcl_fillValues(aURLPatternNode,"MetaData",_rInstalledDriver.aMetaData); } } diff --git a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx index d30bd85b4fab..7d3d34891783 100644 --- a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx +++ b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx @@ -737,98 +737,98 @@ ORowSetValueDecoratorRef const & ODatabaseMetaDataResultSet::getQuoteValue() void SAL_CALL ODatabaseMetaDataResultSet::initialize( const Sequence< Any >& _aArguments ) { - if ( _aArguments.getLength() == 2 ) + if ( _aArguments.getLength() != 2 ) + return; + + sal_Int32 nResultSetType = 0; + if ( !(_aArguments[0] >>= nResultSetType)) + return; + + setType(static_cast<MetaDataResultSetType>(nResultSetType)); + Sequence< Sequence<Any> > aRows; + if ( !(_aArguments[1] >>= aRows) ) + return; + + ORows aRowsToSet; + const Sequence<Any>* pRowsIter = aRows.getConstArray(); + const Sequence<Any>* pRowsEnd = pRowsIter + aRows.getLength(); + for (; pRowsIter != pRowsEnd;++pRowsIter) { - sal_Int32 nResultSetType = 0; - if ( _aArguments[0] >>= nResultSetType) + ORow aRowToSet; + const Any* pRowIter = pRowsIter->getConstArray(); + const Any* pRowEnd = pRowIter + pRowsIter->getLength(); + for (; pRowIter != pRowEnd;++pRowIter) { - setType(static_cast<MetaDataResultSetType>(nResultSetType)); - Sequence< Sequence<Any> > aRows; - if ( _aArguments[1] >>= aRows ) + ORowSetValueDecoratorRef aValue; + switch( pRowIter->getValueTypeClass() ) { - ORows aRowsToSet; - const Sequence<Any>* pRowsIter = aRows.getConstArray(); - const Sequence<Any>* pRowsEnd = pRowsIter + aRows.getLength(); - for (; pRowsIter != pRowsEnd;++pRowsIter) - { - ORow aRowToSet; - const Any* pRowIter = pRowsIter->getConstArray(); - const Any* pRowEnd = pRowIter + pRowsIter->getLength(); - for (; pRowIter != pRowEnd;++pRowIter) + case TypeClass_BOOLEAN: { - ORowSetValueDecoratorRef aValue; - switch( pRowIter->getValueTypeClass() ) - { - case TypeClass_BOOLEAN: - { - bool bValue = false; - *pRowIter >>= bValue; - aValue = new ORowSetValueDecorator(ORowSetValue(bValue)); - } - break; - case TypeClass_BYTE: - { - sal_Int8 nValue(0); - *pRowIter >>= nValue; - aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); - } - break; - case TypeClass_SHORT: - case TypeClass_UNSIGNED_SHORT: - { - sal_Int16 nValue(0); - *pRowIter >>= nValue; - aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); - } - break; - case TypeClass_LONG: - case TypeClass_UNSIGNED_LONG: - { - sal_Int32 nValue(0); - *pRowIter >>= nValue; - aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); - } - break; - case TypeClass_HYPER: - case TypeClass_UNSIGNED_HYPER: - { - sal_Int64 nValue(0); - *pRowIter >>= nValue; - aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); - } - break; - case TypeClass_FLOAT: - { - float nValue(0.0); - *pRowIter >>= nValue; - aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); - } - break; - case TypeClass_DOUBLE: - { - double nValue(0.0); - *pRowIter >>= nValue; - aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); - } - break; - case TypeClass_STRING: - { - OUString sValue; - *pRowIter >>= sValue; - aValue = new ORowSetValueDecorator(ORowSetValue(sValue)); - } - break; - default: - break; - } - aRowToSet.push_back(aValue); + bool bValue = false; + *pRowIter >>= bValue; + aValue = new ORowSetValueDecorator(ORowSetValue(bValue)); } - aRowsToSet.push_back(aRowToSet); - } // for (; pRowsIter != pRowsEnd;++pRowsIter - setRows(aRowsToSet); + break; + case TypeClass_BYTE: + { + sal_Int8 nValue(0); + *pRowIter >>= nValue; + aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); + } + break; + case TypeClass_SHORT: + case TypeClass_UNSIGNED_SHORT: + { + sal_Int16 nValue(0); + *pRowIter >>= nValue; + aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); + } + break; + case TypeClass_LONG: + case TypeClass_UNSIGNED_LONG: + { + sal_Int32 nValue(0); + *pRowIter >>= nValue; + aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); + } + break; + case TypeClass_HYPER: + case TypeClass_UNSIGNED_HYPER: + { + sal_Int64 nValue(0); + *pRowIter >>= nValue; + aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); + } + break; + case TypeClass_FLOAT: + { + float nValue(0.0); + *pRowIter >>= nValue; + aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); + } + break; + case TypeClass_DOUBLE: + { + double nValue(0.0); + *pRowIter >>= nValue; + aValue = new ORowSetValueDecorator(ORowSetValue(nValue)); + } + break; + case TypeClass_STRING: + { + OUString sValue; + *pRowIter >>= sValue; + aValue = new ORowSetValueDecorator(ORowSetValue(sValue)); + } + break; + default: + break; } + aRowToSet.push_back(aValue); } - } + aRowsToSet.push_back(aRowToSet); + } // for (; pRowsIter != pRowsEnd;++pRowsIter + setRows(aRowsToSet); } // XServiceInfo diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index 828419b3efff..2f1cabbd4520 100644 --- a/connectivity/source/commontools/FValue.cxx +++ b/connectivity/source/commontools/FValue.cxx @@ -260,64 +260,64 @@ void ORowSetValue::setTypeKind(sal_Int32 _eType) void ORowSetValue::free() noexcept { - if(!m_bNull) + if(m_bNull) + return; + + switch(m_eTypeKind) { - switch(m_eTypeKind) - { - case DataType::CHAR: - case DataType::VARCHAR: - case DataType::DECIMAL: - case DataType::NUMERIC: - case DataType::LONGVARCHAR: - OSL_ENSURE(m_aValue.m_pString,"String pointer is null!"); - rtl_uString_release(m_aValue.m_pString); - m_aValue.m_pString = nullptr; - break; - case DataType::DATE: - delete static_cast<css::util::Date*>(m_aValue.m_pValue); - m_aValue.m_pValue = nullptr; - break; - case DataType::TIME: - delete static_cast<css::util::Time*>(m_aValue.m_pValue); - m_aValue.m_pValue = nullptr; - break; - case DataType::TIMESTAMP: - delete static_cast<css::util::DateTime*>(m_aValue.m_pValue); - m_aValue.m_pValue = nullptr; - break; - case DataType::BINARY: - case DataType::VARBINARY: - case DataType::LONGVARBINARY: - delete static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue); - m_aValue.m_pValue = nullptr; - break; - case DataType::BLOB: - case DataType::CLOB: - case DataType::OBJECT: + case DataType::CHAR: + case DataType::VARCHAR: + case DataType::DECIMAL: + case DataType::NUMERIC: + case DataType::LONGVARCHAR: + OSL_ENSURE(m_aValue.m_pString,"String pointer is null!"); + rtl_uString_release(m_aValue.m_pString); + m_aValue.m_pString = nullptr; + break; + case DataType::DATE: + delete static_cast<css::util::Date*>(m_aValue.m_pValue); + m_aValue.m_pValue = nullptr; + break; + case DataType::TIME: + delete static_cast<css::util::Time*>(m_aValue.m_pValue); + m_aValue.m_pValue = nullptr; + break; + case DataType::TIMESTAMP: + delete static_cast<css::util::DateTime*>(m_aValue.m_pValue); + m_aValue.m_pValue = nullptr; + break; + case DataType::BINARY: + case DataType::VARBINARY: + case DataType::LONGVARBINARY: + delete static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue); + m_aValue.m_pValue = nullptr; + break; + case DataType::BLOB: + case DataType::CLOB: + case DataType::OBJECT: + delete static_cast<Any*>(m_aValue.m_pValue); + m_aValue.m_pValue = nullptr; + break; + case DataType::BIT: + case DataType::TINYINT: + case DataType::SMALLINT: + case DataType::INTEGER: + case DataType::BIGINT: + case DataType::BOOLEAN: + case DataType::FLOAT: + case DataType::DOUBLE: + case DataType::REAL: + break; + default: + if ( m_aValue.m_pValue ) + { delete static_cast<Any*>(m_aValue.m_pValue); m_aValue.m_pValue = nullptr; - break; - case DataType::BIT: - case DataType::TINYINT: - case DataType::SMALLINT: - case DataType::INTEGER: - case DataType::BIGINT: - case DataType::BOOLEAN: - case DataType::FLOAT: - case DataType::DOUBLE: - case DataType::REAL: - break; - default: - if ( m_aValue.m_pValue ) - { - delete static_cast<Any*>(m_aValue.m_pValue); - m_aValue.m_pValue = nullptr; - } - break; + } + break; - } - m_bNull = true; } + m_bNull = true; } ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH) @@ -2046,62 +2046,62 @@ css::util::DateTime ORowSetValue::getDateTime() const void ORowSetValue::setSigned(bool _bMod) { - if ( m_bSigned != _bMod ) + if ( m_bSigned == _bMod ) + return; + + m_bSigned = _bMod; + if ( m_bNull ) + return; + + sal_Int32 nType = m_eTypeKind; + switch(m_eTypeKind) { - m_bSigned = _bMod; - if ( !m_bNull ) + case DataType::TINYINT: + if ( m_bSigned ) + (*this) = getInt8(); + else + { + m_bSigned = !m_bSigned; + (*this) = getInt16(); + m_bSigned = !m_bSigned; + } + break; + case DataType::SMALLINT: + if ( m_bSigned ) + (*this) = getInt16(); + else + { + m_bSigned = !m_bSigned; + (*this) = getInt32(); + m_bSigned = !m_bSigned; + } + break; + case DataType::INTEGER: + if ( m_bSigned ) + (*this) = getInt32(); + else + { + m_bSigned = !m_bSigned; + (*this) = getLong(); + m_bSigned = !m_bSigned; + } + break; + case DataType::BIGINT: { - sal_Int32 nType = m_eTypeKind; - switch(m_eTypeKind) + if ( m_bSigned ) { - case DataType::TINYINT: - if ( m_bSigned ) - (*this) = getInt8(); - else - { - m_bSigned = !m_bSigned; - (*this) = getInt16(); - m_bSigned = !m_bSigned; - } - break; - case DataType::SMALLINT: - if ( m_bSigned ) - (*this) = getInt16(); - else - { - m_bSigned = !m_bSigned; - (*this) = getInt32(); - m_bSigned = !m_bSigned; - } - break; - case DataType::INTEGER: - if ( m_bSigned ) - (*this) = getInt32(); - else - { - m_bSigned = !m_bSigned; - (*this) = getLong(); - m_bSigned = !m_bSigned; - } - break; - case DataType::BIGINT: - { - if ( m_bSigned ) - { - auto nTmp = static_cast<sal_Int64>(m_aValue.m_uInt64); - m_aValue.m_nInt64 = nTmp; - } - else - { - auto nTmp = static_cast<sal_uInt64>(m_aValue.m_nInt64); - m_aValue.m_uInt64 = nTmp; - } - break; - } + auto nTmp = static_cast<sal_Int64>(m_aValue.m_uInt64); + m_aValue.m_nInt64 = nTmp; } - m_eTypeKind = nType; + else + { + auto nTmp = static_cast<sal_uInt64>(m_aValue.m_nInt64); + m_aValue.m_uInt64 = nTmp; + } + break; } } + m_eTypeKind = nType; } diff --git a/connectivity/source/commontools/TColumnsHelper.cxx b/connectivity/source/commontools/TColumnsHelper.cxx index 36061dc2fe3d..a97faeeb8b4e 100644 --- a/connectivity/source/commontools/TColumnsHelper.cxx +++ b/connectivity/source/commontools/TColumnsHelper.cxx @@ -186,21 +186,21 @@ sdbcx::ObjectType OColumnsHelper::appendObject( const OUString& _rForName, const void OColumnsHelper::dropObject(sal_Int32 /*_nPos*/, const OUString& _sElementName) { OSL_ENSURE(m_pTable,"OColumnsHelper::dropByName: Table is null!"); - if ( m_pTable && !m_pTable->isNew() ) + if ( !(m_pTable && !m_pTable->isNew()) ) + return; + + Reference<XDatabaseMetaData> xMetaData = m_pTable->getConnection()->getMetaData(); + OUString aQuote = xMetaData->getIdentifierQuoteString( ); + OUString aSql = "ALTER TABLE " + + ::dbtools::composeTableName( xMetaData, m_pTable, ::dbtools::EComposeRule::InTableDefinitions, true ) + + " DROP " + + ::dbtools::quoteName( aQuote,_sElementName); + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + if ( xStmt.is() ) { - Reference<XDatabaseMetaData> xMetaData = m_pTable->getConnection()->getMetaData(); - OUString aQuote = xMetaData->getIdentifierQuoteString( ); - OUString aSql = "ALTER TABLE " + - ::dbtools::composeTableName( xMetaData, m_pTable, ::dbtools::EComposeRule::InTableDefinitions, true ) + - " DROP " + - ::dbtools::quoteName( aQuote,_sElementName); - - Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); - if ( xStmt.is() ) - { - xStmt->execute(aSql); - ::comphelper::disposeComponent(xStmt); - } + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); } } diff --git a/connectivity/source/commontools/TIndexes.cxx b/connectivity/source/commontools/TIndexes.cxx index aeb9253b0885..f5cff00ec835 100644 --- a/connectivity/source/commontools/TIndexes.cxx +++ b/connectivity/source/commontools/TIndexes.cxx @@ -213,33 +213,33 @@ sdbcx::ObjectType OIndexesHelper::appendObject( const OUString& _rForName, const void OIndexesHelper::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName) { Reference< XConnection> xConnection = m_pTable->getConnection(); - if( xConnection.is() && !m_pTable->isNew()) + if( !(xConnection.is() && !m_pTable->isNew())) + return; + + if ( m_pTable->getIndexService().is() ) { - if ( m_pTable->getIndexService().is() ) - { - m_pTable->getIndexService()->dropIndex(m_pTable,_sElementName); - } - else - { - OUString aName,aSchema; - sal_Int32 nLen = _sElementName.indexOf('.'); - if(nLen != -1) - aSchema = _sElementName.copy(0,nLen); - aName = _sElementName.copy(nLen+1); + m_pTable->getIndexService()->dropIndex(m_pTable,_sElementName); + } + else + { + OUString aName,aSchema; + sal_Int32 nLen = _sElementName.indexOf('.'); + if(nLen != -1) + aSchema = _sElementName.copy(0,nLen); + aName = _sElementName.copy(nLen+1); - OUString aSql( "DROP INDEX " ); + OUString aSql( "DROP INDEX " ); - OUString aComposedName = dbtools::composeTableName( m_pTable->getMetaData(), m_pTable, ::dbtools::EComposeRule::InIndexDefinitions, true ); - OUString sIndexName = dbtools::composeTableName( m_pTable->getMetaData(), OUString(), aSchema, aName, true, ::dbtools::EComposeRule::InIndexDefinitions ); + OUString aComposedName = dbtools::composeTableName( m_pTable->getMetaData(), m_pTable, ::dbtools::EComposeRule::InIndexDefinitions, true ); + OUString sIndexName = dbtools::composeTableName( m_pTable->getMetaData(), OUString(), aSchema, aName, true, ::dbtools::EComposeRule::InIndexDefinitions ); - aSql += sIndexName + " ON " + aComposedName; + aSql += sIndexName + " ON " + aComposedName; - Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); - if ( xStmt.is() ) - { - xStmt->execute(aSql); - ::comphelper::disposeComponent(xStmt); - } + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); } } } diff --git a/connectivity/source/commontools/TKeys.cxx b/connectivity/source/commontools/TKeys.cxx index 57b49b6e8416..742a1832049a 100644 --- a/connectivity/source/commontools/TKeys.cxx +++ b/connectivity/source/commontools/TKeys.cxx @@ -264,43 +264,43 @@ OUString OKeysHelper::getDropForeignKey() const void OKeysHelper::dropObject(sal_Int32 _nPos, const OUString& _sElementName) { Reference< XConnection> xConnection = m_pTable->getConnection(); - if ( xConnection.is() && !m_pTable->isNew() ) + if ( !(xConnection.is() && !m_pTable->isNew()) ) + return; + + Reference<XPropertySet> xKey(getObject(_nPos),UNO_QUERY); + if ( m_pTable->getKeyService().is() ) + { + m_pTable->getKeyService()->dropKey(m_pTable,xKey); + } + else { - Reference<XPropertySet> xKey(getObject(_nPos),UNO_QUERY); - if ( m_pTable->getKeyService().is() ) + OUStringBuffer aSql; + aSql.append("ALTER TABLE "); + + aSql.append( composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable,::dbtools::EComposeRule::InTableDefinitions, true )); + + sal_Int32 nKeyType = KeyType::PRIMARY; + if ( xKey.is() ) { - m_pTable->getKeyService()->dropKey(m_pTable,xKey); + ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); + xKey->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPE)) >>= nKeyType; + } + if ( KeyType::PRIMARY == nKeyType ) + { + aSql.append(" DROP PRIMARY KEY"); } else { - OUStringBuffer aSql; - aSql.append("ALTER TABLE "); - - aSql.append( composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable,::dbtools::EComposeRule::InTableDefinitions, true )); - - sal_Int32 nKeyType = KeyType::PRIMARY; - if ( xKey.is() ) - { - ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); - xKey->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPE)) >>= nKeyType; - } - if ( KeyType::PRIMARY == nKeyType ) - { - aSql.append(" DROP PRIMARY KEY"); - } - else - { - aSql.append(getDropForeignKey()); - const OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString(); - aSql.append( ::dbtools::quoteName( aQuote,_sElementName) ); - } + aSql.append(getDropForeignKey()); + const OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString(); + aSql.append( ::dbtools::quoteName( aQuote,_sElementName) ); + } - Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); - if ( xStmt.is() ) - { - xStmt->execute(aSql.makeStringAndClear()); - ::comphelper::disposeComponent(xStmt); - } + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(aSql.makeStringAndClear()); + ::comphelper::disposeComponent(xStmt); } } } diff --git a/connectivity/source/commontools/TTableHelper.cxx b/connectivity/source/commontools/TTableHelper.cxx index 246becfa6ae0..e22740144316 100644 --- a/connectivity/source/commontools/TTableHelper.cxx +++ b/connectivity/source/commontools/TTableHelper.cxx @@ -348,54 +348,54 @@ void OTableHelper::refreshForeignKeys(::std::vector< OUString>& _rNames) Reference< XResultSet > xResult = getMetaData()->getImportedKeys(aCatalog,m_SchemaName,m_Name); Reference< XRow > xRow(xResult,UNO_QUERY); - if ( xRow.is() ) + if ( !xRow.is() ) + return; + + std::shared_ptr<sdbcx::KeyProperties> pKeyProps; + OUString aName,sCatalog,aSchema,sOldFKName; + while( xResult->next() ) { - std::shared_ptr<sdbcx::KeyProperties> pKeyProps; - OUString aName,sCatalog,aSchema,sOldFKName; - while( xResult->next() ) + // this must be outside the "if" because we have to call in a right order + sCatalog = xRow->getString(1); + if ( xRow->wasNull() ) + sCatalog.clear(); + aSchema = xRow->getString(2); + aName = xRow->getString(3); + + const OUString sForeignKeyColumn = xRow->getString(8); + const sal_Int32 nUpdateRule = xRow->getInt(10); + const sal_Int32 nDeleteRule = xRow->getInt(11); + const OUString sFkName = xRow->getString(12); + + if ( !sFkName.isEmpty() && !xRow->wasNull() ) { - // this must be outside the "if" because we have to call in a right order - sCatalog = xRow->getString(1); - if ( xRow->wasNull() ) - sCatalog.clear(); - aSchema = xRow->getString(2); - aName = xRow->getString(3); - - const OUString sForeignKeyColumn = xRow->getString(8); - const sal_Int32 nUpdateRule = xRow->getInt(10); - const sal_Int32 nDeleteRule = xRow->getInt(11); - const OUString sFkName = xRow->getString(12); - - if ( !sFkName.isEmpty() && !xRow->wasNull() ) + if ( sOldFKName != sFkName ) { - if ( sOldFKName != sFkName ) + if ( pKeyProps.get() ) + m_pImpl->m_aKeys.emplace(sOldFKName,pKeyProps); + + const OUString sReferencedName = ::dbtools::composeTableName(getMetaData(),sCatalog,aSchema,aName,false,::dbtools::EComposeRule::InDataManipulation); + pKeyProps = std::make_shared<sdbcx::KeyProperties>(sReferencedName,KeyType::FOREIGN,nUpdateRule,nDeleteRule); + pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn); + _rNames.push_back(sFkName); + if ( m_pTables->hasByName(sReferencedName) ) { - if ( pKeyProps.get() ) - m_pImpl->m_aKeys.emplace(sOldFKName,pKeyProps); - - const OUString sReferencedName = ::dbtools::composeTableName(getMetaData(),sCatalog,aSchema,aName,false,::dbtools::EComposeRule::InDataManipulation); - pKeyProps = std::make_shared<sdbcx::KeyProperties>(sReferencedName,KeyType::FOREIGN,nUpdateRule,nDeleteRule); - pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn); - _rNames.push_back(sFkName); - if ( m_pTables->hasByName(sReferencedName) ) - { - if ( !m_pImpl->m_xTablePropertyListener.is() ) - m_pImpl->m_xTablePropertyListener = new OTableContainerListener(this); - m_pTables->addContainerListener(m_pImpl->m_xTablePropertyListener.get()); - m_pImpl->m_xTablePropertyListener->add(sReferencedName); - } // if ( m_pTables->hasByName(sReferencedName) ) - sOldFKName = sFkName; - } // if ( sOldFKName != sFkName ) - else if ( pKeyProps.get() ) - { - pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn); - } + if ( !m_pImpl->m_xTablePropertyListener.is() ) + m_pImpl->m_xTablePropertyListener = new OTableContainerListener(this); + m_pTables->addContainerListener(m_pImpl->m_xTablePropertyListener.get()); + m_pImpl->m_xTablePropertyListener->add(sReferencedName); + } // if ( m_pTables->hasByName(sReferencedName) ) + sOldFKName = sFkName; + } // if ( sOldFKName != sFkName ) + else if ( pKeyProps.get() ) + { + pKeyProps->m_aKeyColumnNames.push_back(sForeignKeyColumn); } - } // while( xResult->next() ) - if ( pKeyProps.get() ) - m_pImpl->m_aKeys.emplace(sOldFKName,pKeyProps); - ::comphelper::disposeComponent(xResult); - } + } + } // while( xResult->next() ) + if ( pKeyProps.get() ) + m_pImpl->m_aKeys.emplace(sOldFKName,pKeyProps); + ::comphelper::disposeComponent(xResult); } void OTableHelper::refreshKeys() diff --git a/connectivity/source/commontools/conncleanup.cxx b/connectivity/source/commontools/conncleanup.cxx index 922551c470af..d0198df5f494 100644 --- a/connectivity/source/commontools/conncleanup.cxx +++ b/connectivity/source/commontools/conncleanup.cxx @@ -129,51 +129,52 @@ namespace dbtools void SAL_CALL OAutoConnectionDisposer::propertyChange( const PropertyChangeEvent& _rEvent ) { - if ( _rEvent.PropertyName == ACTIVE_CONNECTION_PROPERTY_NAME ) - { // somebody set a new ActiveConnection + if ( _rEvent.PropertyName != ACTIVE_CONNECTION_PROPERTY_NAME ) + return; + +// somebody set a new ActiveConnection - Reference< XConnection > xNewConnection; - _rEvent.NewValue >>= xNewConnection; + Reference< XConnection > xNewConnection; + _rEvent.NewValue >>= xNewConnection; - if ( isRowSetListening() ) + if ( isRowSetListening() ) + { + // we're listening at the row set, this means that the row set does not have our + // m_xOriginalConnection as active connection anymore + // So there are two possibilities + // a. somebody sets a new connection which is not our original one + // b. somebody sets a new connection, which is exactly the original one + // a. we're not interested in a, but in b: In this case, we simply need to move to the state + // we had originally: listen for property changes, do not listen for row set changes, and + // do not dispose the connection until the row set does not need it anymore + if ( xNewConnection.get() == m_xOriginalConnection.get() ) { - // we're listening at the row set, this means that the row set does not have our - // m_xOriginalConnection as active connection anymore - // So there are two possibilities - // a. somebody sets a new connection which is not our original one - // b. somebody sets a new connection, which is exactly the original one - // a. we're not interested in a, but in b: In this case, we simply need to move to the state - // we had originally: listen for property changes, do not listen for row set changes, and - // do not dispose the connection until the row set does not need it anymore - if ( xNewConnection.get() == m_xOriginalConnection.get() ) - { - stopRowSetListening(); - } + stopRowSetListening(); } - else + } + else + { + // start listening at the row set. We're allowed to dispose the old connection as soon + // as the RowSet changed + + // Unfortunately, the our database form implementations sometimes fire the change of their + // ActiveConnection twice. This is an error in forms/source/component/DatabaseForm.cxx, but + // changing this would require incompatible changes we can't do for a while. + // So for the moment, we have to live with it here. + // + // The only scenario where this doubled notification causes problems is when the connection + // of the form is reset to the one we're responsible for (m_xOriginalConnection), so we + // check this here. + // + // Yes, this is a HACK :( + if ( xNewConnection.get() != m_xOriginalConnection.get() ) { - // start listening at the row set. We're allowed to dispose the old connection as soon - // as the RowSet changed - - // Unfortunately, the our database form implementations sometimes fire the change of their - // ActiveConnection twice. This is an error in forms/source/component/DatabaseForm.cxx, but - // changing this would require incompatible changes we can't do for a while. - // So for the moment, we have to live with it here. - // - // The only scenario where this doubled notification causes problems is when the connection - // of the form is reset to the one we're responsible for (m_xOriginalConnection), so we - // check this here. - // - // Yes, this is a HACK :( - if ( xNewConnection.get() != m_xOriginalConnection.get() ) - { #if OSL_DEBUG_LEVEL > 0 - Reference< XConnection > xOldConnection; - _rEvent.OldValue >>= xOldConnection; - OSL_ENSURE( xOldConnection.get() == m_xOriginalConnection.get(), "OAutoConnectionDisposer::propertyChange: unexpected (original) property value!" ); + Reference< XConnection > xOldConnection; + _rEvent.OldValue >>= xOldConnection; + OSL_ENSURE( xOldConnection.get() == m_xOriginalConnection.get(), "OAutoConnectionDisposer::propertyChange: unexpected (original) property value!" ); #endif - startRowSetListening(); - } + startRowSetListening(); } } } diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx index c0b88f1c7ba1..36161735ebb2 100644 --- a/connectivity/source/commontools/dbtools.cxx +++ b/connectivity/source/commontools/dbtools.cxx @@ -1696,76 +1696,76 @@ void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer, Reference<XIndexAccess> xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference<XIndexAccess>(); sal_Int32 nParamCount = xParamsAsIndicies.is() ? xParamsAsIndicies->getCount() : 0; std::vector<bool, std::allocator<bool> > aNewParameterSet( _aParametersSet ); - if ( nParamCount && std::count(aNewParameterSet.begin(),aNewParameterSet.end(),true) != nParamCount ) - { - static const OUString PROPERTY_NAME(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)); - aNewParameterSet.resize(nParamCount ,false); - typedef std::map< OUString, std::vector<sal_Int32> > TParameterPositions; - TParameterPositions aParameterNames; - for(sal_Int32 i = 0; i < nParamCount; ++i) - { - Reference<XPropertySet> xParam(xParamsAsIndicies->getByIndex(i),UNO_QUERY); - OUString sName; - xParam->getPropertyValue(PROPERTY_NAME) >>= sName; + if ( !(nParamCount && std::count(aNewParameterSet.begin(),aNewParameterSet.end(),true) != nParamCount) ) + return; - TParameterPositions::const_iterator aFind = aParameterNames.find(sName); - if ( aFind != aParameterNames.end() ) - aNewParameterSet[i] = true; - aParameterNames[sName].push_back(i+1); - } - // build an interaction request - // two continuations (Ok and Cancel) - OInteractionAbort* pAbort = new OInteractionAbort; - OParameterContinuation* pParams = new OParameterContinuation; - // the request - ParametersRequest aRequest; - Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(aNewParameterSet,xParamsAsIndicies); - aRequest.Parameters = xWrappedParameters; - aRequest.Connection = _xConnection; - OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); - Reference< XInteractionRequest > xRequest(pRequest); - // some knittings - pRequest->addContinuation(pAbort); - pRequest->addContinuation(pParams); - - // execute the request - _rxHandler->handle(xRequest); - - if (!pParams->wasSelected()) - { - // canceled by the user (i.e. (s)he canceled the dialog) - RowSetVetoException e; - e.ErrorCode = ParameterInteractionCancelled; - throw e; - } + static const OUString PROPERTY_NAME(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)); + aNewParameterSet.resize(nParamCount ,false); + typedef std::map< OUString, std::vector<sal_Int32> > TParameterPositions; + TParameterPositions aParameterNames; + for(sal_Int32 i = 0; i < nParamCount; ++i) + { + Reference<XPropertySet> xParam(xParamsAsIndicies->getByIndex(i),UNO_QUERY); + OUString sName; + xParam->getPropertyValue(PROPERTY_NAME) >>= sName; + + TParameterPositions::const_iterator aFind = aParameterNames.find(sName); + if ( aFind != aParameterNames.end() ) + aNewParameterSet[i] = true; + aParameterNames[sName].push_back(i+1); + } + // build an interaction request + // two continuations (Ok and Cancel) + OInteractionAbort* pAbort = new OInteractionAbort; + OParameterContinuation* pParams = new OParameterContinuation; + // the request + ParametersRequest aRequest; + Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(aNewParameterSet,xParamsAsIndicies); + aRequest.Parameters = xWrappedParameters; + aRequest.Connection = _xConnection; + OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); + Reference< XInteractionRequest > xRequest(pRequest); + // some knittings + pRequest->addContinuation(pAbort); + pRequest->addContinuation(pParams); + + // execute the request + _rxHandler->handle(xRequest); + + if (!pParams->wasSelected()) + { + // canceled by the user (i.e. (s)he canceled the dialog) + RowSetVetoException e; + e.ErrorCode = ParameterInteractionCancelled; + throw e; + } - // now transfer the values from the continuation object to the parameter columns - Sequence< PropertyValue > aFinalValues = pParams->getValues(); - const PropertyValue* pFinalValues = aFinalValues.getConstArray(); - for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues) + // now transfer the values from the continuation object to the parameter columns + Sequence< PropertyValue > aFinalValues = pParams->getValues(); + const PropertyValue* pFinalValues = aFinalValues.getConstArray(); + for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues) + { + Reference< XPropertySet > xParamColumn(xWrappedParameters->getByIndex(i),UNO_QUERY); + if (xParamColumn.is()) { - Reference< XPropertySet > xParamColumn(xWrappedParameters->getByIndex(i),UNO_QUERY); - if (xParamColumn.is()) + OUString sName; + xParamColumn->getPropertyValue(PROPERTY_NAME) >>= sName; + OSL_ENSURE(sName == pFinalValues->Name, "::dbaui::askForParameters: inconsistent parameter names!"); + + // determine the field type and ... + sal_Int32 nParamType = 0; + xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nParamType; + // ... the scale of the parameter column + sal_Int32 nScale = 0; + if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE), xParamColumn)) + xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale; + // (the index of the parameters is one-based) + TParameterPositions::const_iterator aFind = aParameterNames.find(pFinalValues->Name); + for(const auto& rItem : aFind->second) { - OUString sName; - xParamColumn->getPropertyValue(PROPERTY_NAME) >>= sName; - OSL_ENSURE(sName == pFinalValues->Name, "::dbaui::askForParameters: inconsistent parameter names!"); - - // determine the field type and ... - sal_Int32 nParamType = 0; - xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nParamType; - // ... the scale of the parameter column - sal_Int32 nScale = 0; - if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE), xParamColumn)) - xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale; - // (the index of the parameters is one-based) - TParameterPositions::const_iterator aFind = aParameterNames.find(pFinalValues->Name); - for(const auto& rItem : aFind->second) + if ( _aParametersSet.empty() || !_aParametersSet[rItem-1] ) { - if ( _aParametersSet.empty() || !_aParametersSet[rItem-1] ) - { - _xParameters->setObjectWithInfo(rItem, pFinalValues->Value, nParamType, nScale); - } + _xParameters->setObjectWithInfo(rItem, pFinalValues->Value, nParamType, nScale); } } } diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx index 1d905aa73ea8..045ea54190ac 100644 --- a/connectivity/source/drivers/calc/CTable.cxx +++ b/connectivity/source/drivers/calc/CTable.cxx @@ -65,21 +65,21 @@ static void lcl_UpdateArea( const Reference<XCellRange>& xUsedRange, sal_Int32& // update rEndCol, rEndRow if any non-empty cell in xUsedRange is right/below const Reference<XCellRangesQuery> xUsedQuery( xUsedRange, UNO_QUERY ); - if ( xUsedQuery.is() ) - { - const sal_Int16 nContentFlags = - CellFlags::STRING | CellFlags::VALUE | CellFlags::DATETIME | CellFlags::FORMULA | CellFlags::ANNOTATION; + if ( !xUsedQuery.is() ) + return; - const Reference<XSheetCellRanges> xUsedRanges = xUsedQuery->queryContentCells( nContentFlags ); - const Sequence<CellRangeAddress> aAddresses = xUsedRanges->getRangeAddresses(); + const sal_Int16 nContentFlags = + CellFlags::STRING | CellFlags::VALUE | CellFlags::DATETIME | CellFlags::FORMULA | CellFlags::ANNOTATION; - const sal_Int32 nCount = aAddresses.getLength(); - const CellRangeAddress* pData = aAddresses.getConstArray(); - for ( sal_Int32 i=0; i<nCount; i++ ) - { - rEndCol = std::max(pData[i].EndColumn, rEndCol); - rEndRow = std::max(pData[i].EndRow, rEndRow); - } + const Reference<XSheetCellRanges> xUsedRanges = xUsedQuery->queryContentCells( nContentFlags ); + const Sequence<CellRangeAddress> aAddresses = xUsedRanges->getRangeAddresses(); + + const sal_Int32 nCount = aAddresses.getLength(); + const CellRangeAddress* pData = aAddresses.getConstArray(); + for ( sal_Int32 i=0; i<nCount; i++ ) + { + rEndCol = std::max(pData[i].EndColumn, rEndCol); + rEndRow = std::max(pData[i].EndRow, rEndRow); } } @@ -237,64 +237,64 @@ static void lcl_GetColumnInfo( const Reference<XSpreadsheet>& xSheet, const Refe Reference<XCell> xDataCell = lcl_GetUsedCell( xSheet, nDocColumn, nDataRow ); Reference<XPropertySet> xProp( xDataCell, UNO_QUERY ); - if ( xProp.is() ) + if ( !xProp.is() ) + return; + + rCurrency = false; // set to true for currency below + + const CellContentType eCellType = lcl_GetContentOrResultType( xDataCell ); + // #i35178# use "text" type if there is any text cell in the column + if ( eCellType == CellContentType_TEXT || lcl_HasTextInColumn( xSheet, nDocColumn, nDataRow ) ) + rDataType = DataType::VARCHAR; + else if ( eCellType == CellContentType_VALUE ) { - rCurrency = false; // set to true for currency below + // get number format to distinguish between different types - const CellContentType eCellType = lcl_GetContentOrResultType( xDataCell ); - // #i35178# use "text" type if there is any text cell in the column - if ( eCellType == CellContentType_TEXT || lcl_HasTextInColumn( xSheet, nDocColumn, nDataRow ) ) - rDataType = DataType::VARCHAR; - else if ( eCellType == CellContentType_VALUE ) + sal_Int16 nNumType = NumberFormat::NUMBER; + try { - // get number format to distinguish between different types + sal_Int32 nKey = 0; - sal_Int16 nNumType = NumberFormat::NUMBER; - try + if ( xProp->getPropertyValue( "NumberFormat" ) >>= nKey ) { - sal_Int32 nKey = 0; - - if ( xProp->getPropertyValue( "NumberFormat" ) >>= nKey ) + const Reference<XPropertySet> xFormat = xFormats->getByKey( nKey ); + if ( xFormat.is() ) { - const Reference<XPropertySet> xFormat = xFormats->getByKey( nKey ); - if ( xFormat.is() ) - { - xFormat->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE) ) >>= nNumType; - } + xFormat->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE) ) >>= nNumType; } } - catch ( Exception& ) - { - } - - if ( nNumType & NumberFormat::TEXT ) - rDataType = DataType::VARCHAR; - else if ( nNumType & NumberFormat::NUMBER ) - rDataType = DataType::DECIMAL; - else if ( nNumType & NumberFormat::CURRENCY ) - { - rCurrency = true; - rDataType = DataType::DECIMAL; - } - else if ( ( nNumType & NumberFormat::DATETIME ) == NumberFormat::DATETIME ) - { - // NumberFormat::DATETIME is DATE | TIME - rDataType = DataType::TIMESTAMP; - } - else if ( nNumType & NumberFormat::DATE ) - rDataType = DataType::DATE; - else if ( nNumType & NumberFormat::TIME ) - rDataType = DataType::TIME; - else if ( nNumType & NumberFormat::LOGICAL ) - rDataType = DataType::BIT; - else - rDataType = DataType::DECIMAL; } - else + catch ( Exception& ) { - // whole column empty + } + + if ( nNumType & NumberFormat::TEXT ) rDataType = DataType::VARCHAR; + else if ( nNumType & NumberFormat::NUMBER ) + rDataType = DataType::DECIMAL; + else if ( nNumType & NumberFormat::CURRENCY ) + { + rCurrency = true; + rDataType = DataType::DECIMAL; } + else if ( ( nNumType & NumberFormat::DATETIME ) == NumberFormat::DATETIME ) + { + // NumberFormat::DATETIME is DATE | TIME + rDataType = DataType::TIMESTAMP; + } + else if ( nNumType & NumberFormat::DATE ) + rDataType = DataType::DATE; + else if ( nNumType & NumberFormat::TIME ) + rDataType = DataType::TIME; + else if ( nNumType & NumberFormat::LOGICAL ) + rDataType = DataType::BIT; + else + rDataType = DataType::DECIMAL; + } + else + { + // whole column empty + rDataType = DataType::VARCHAR; } } @@ -310,104 +310,104 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference<XSpreadsheet>& x ++nDocRow; const Reference<XCell> xCell = xSheet->getCellByPosition( nDocColumn, nDocRow ); - if ( xCell.is() ) + if ( !xCell.is() ) + return; + + CellContentType eCellType = lcl_GetContentOrResultType( xCell ); + switch (nType) { - CellContentType eCellType = lcl_GetContentOrResultType( xCell ); - switch (nType) - { - case DataType::VARCHAR: - if ( eCellType == CellContentType_EMPTY ) - rValue.setNull(); - else - { - // #i25840# still let Calc convert numbers to text - const Reference<XText> xText( xCell, UNO_QUERY ); - if ( xText.is() ) - rValue = xText->getString(); - } - break; - case DataType::DECIMAL: - if ( eCellType == CellContentType_VALUE ) - rValue = xCell->getValue(); // double - else - rValue.setNull(); - break; - case DataType::BIT: - if ( eCellType == CellContentType_VALUE ) - rValue = xCell->getValue() != 0.0; - else - rValue.setNull(); - break; - case DataType::DATE: - if ( eCellType == CellContentType_VALUE ) - { - ::Date aDate( rNullDate ); - aDate.AddDays(::rtl::math::approxFloor( xCell->getValue() )); - rValue = aDate.GetUNODate(); - } - else - rValue.setNull(); - break; - case DataType::TIME: - if ( eCellType == CellContentType_VALUE ) + case DataType::VARCHAR: + if ( eCellType == CellContentType_EMPTY ) + rValue.setNull(); + else + { + // #i25840# still let Calc convert numbers to text + const Reference<XText> xText( xCell, UNO_QUERY ); + if ( xText.is() ) + rValue = xText->getString(); + } + break; + case DataType::DECIMAL: + if ( eCellType == CellContentType_VALUE ) + rValue = xCell->getValue(); // double + else + rValue.setNull(); + break; + case DataType::BIT: + if ( eCellType == CellContentType_VALUE ) + rValue = xCell->getValue() != 0.0; + else + rValue.setNull(); + break; + case DataType::DATE: + if ( eCellType == CellContentType_VALUE ) + { + ::Date aDate( rNullDate ); + aDate.AddDays(::rtl::math::approxFloor( xCell->getValue() )); + rValue = aDate.GetUNODate(); + } + else + rValue.setNull(); + break; + case DataType::TIME: + if ( eCellType == CellContentType_VALUE ) + { + double fCellVal = xCell->getValue(); + double fTime = fCellVal - rtl::math::approxFloor( fCellVal ); + sal_Int64 nIntTime = static_cast<sal_Int64>(rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) )); + if ( nIntTime == ::tools::Time::nanoSecPerDay) + nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 + css::util::Time aTime; + aTime.NanoSeconds = static_cast<sal_uInt32>( nIntTime % ::tools::Time::nanoSecPerSec ); + nIntTime /= ::tools::Time::nanoSecPerSec; + aTime.Seconds = static_cast<sal_uInt16>( nIntTime % 60 ); + nIntTime /= 60; + aTime.Minutes = static_cast<sal_uInt16>( nIntTime % 60 ); + nIntTime /= 60; + OSL_ENSURE( nIntTime < 24, "error in time calculation" ); + aTime.Hours = static_cast<sal_uInt16>(nIntTime); + rValue = aTime; + } + else + rValue.setNull(); + break; + case DataType::TIMESTAMP: + if ( eCellType == CellContentType_VALUE ) + { + double fCellVal = xCell->getValue(); + double fDays = ::rtl::math::approxFloor( fCellVal ); + double fTime = fCellVal - fDays; + long nIntDays = static_cast<long>(fDays); + sal_Int64 nIntTime = ::rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) ); + if ( nIntTime == ::tools::Time::nanoSecPerDay ) { - double fCellVal = xCell->getValue(); - double fTime = fCellVal - rtl::math::approxFloor( fCellVal ); - sal_Int64 nIntTime = static_cast<sal_Int64>(rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) )); - if ( nIntTime == ::tools::Time::nanoSecPerDay) - nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 - css::util::Time aTime; - aTime.NanoSeconds = static_cast<sal_uInt32>( nIntTime % ::tools::Time::nanoSecPerSec ); - nIntTime /= ::tools::Time::nanoSecPerSec; - aTime.Seconds = static_cast<sal_uInt16>( nIntTime % 60 ); - nIntTime /= 60; - aTime.Minutes = static_cast<sal_uInt16>( nIntTime % 60 ); - nIntTime /= 60; - OSL_ENSURE( nIntTime < 24, "error in time calculation" ); - aTime.Hours = static_cast<sal_uInt16>(nIntTime); - rValue = aTime; + nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 + ++nIntDays; // (next day) } - else - rValue.setNull(); - break; - case DataType::TIMESTAMP: - if ( eCellType == CellContentType_VALUE ) - { - double fCellVal = xCell->getValue(); - double fDays = ::rtl::math::approxFloor( fCellVal ); - double fTime = fCellVal - fDays; - long nIntDays = static_cast<long>(fDays); - sal_Int64 nIntTime = ::rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) ); - if ( nIntTime == ::tools::Time::nanoSecPerDay ) - { - nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 - ++nIntDays; // (next day) - } - css::util::DateTime aDateTime; + css::util::DateTime aDateTime; - aDateTime.NanoSeconds = static_cast<sal_uInt16>( nIntTime % ::tools::Time::nanoSecPerSec ); - nIntTime /= ::tools::Time::nanoSecPerSec; - aDateTime.Seconds = static_cast<sal_uInt16>( nIntTime % 60 ); - nIntTime /= 60; - aDateTime.Minutes = static_cast<sal_uInt16>( nIntTime % 60 ); - nIntTime /= 60; - OSL_ENSURE( nIntTime < 24, "error in time calculation" ); - aDateTime.Hours = static_cast<sal_uInt16>(nIntTime); + aDateTime.NanoSeconds = static_cast<sal_uInt16>( nIntTime % ::tools::Time::nanoSecPerSec ); + nIntTime /= ::tools::Time::nanoSecPerSec; + aDateTime.Seconds = static_cast<sal_uInt16>( nIntTime % 60 ); + nIntTime /= 60; + aDateTime.Minutes = static_cast<sal_uInt16>( nIntTime % 60 ); + nIntTime /= 60; + OSL_ENSURE( nIntTime < 24, "error in time calculation" ); + aDateTime.Hours = static_cast<sal_uInt16>(nIntTime); - ::Date aDate( rNullDate ); - aDate.AddDays( nIntDays ); - aDateTime.Day = aDate.GetDay(); - aDateTime.Month = aDate.GetMonth(); - aDateTime.Year = aDate.GetYear(); + ::Date aDate( rNullDate ); + aDate.AddDays( nIntDays ); + aDateTime.Day = aDate.GetDay(); + aDateTime.Month = aDate.GetMonth(); + aDateTime.Year = aDate.GetYear(); - rValue = aDateTime; - } - else - rValue.setNull(); - break; - } // switch (nType) - } + rValue = aDateTime; + } + else + rValue.setNull(); + break; + } // switch (nType) // rValue.setTypeKind(nType); } diff --git a/connectivity/source/drivers/dbase/DIndex.cxx b/connectivity/source/drivers/dbase/DIndex.cxx index fdb782174412..d168de39eb77 100644 --- a/connectivity/source/drivers/dbase/DIndex.cxx +++ b/connectivity/source/drivers/dbase/DIndex.cxx @@ -130,30 +130,30 @@ ONDXPagePtr const & ODbaseIndex::getRoot() void ODbaseIndex::openIndexFile() { - if(!m_pFileStream) + if(m_pFileStream) + return; + + OUString sFile = getCompletePath(); + if(UCBContentHelper::Exists(sFile)) { - OUString sFile = getCompletePath(); - if(UCBContentHelper::Exists(sFile)) - { - m_pFileStream = OFileTable::createStream_simpleError(sFile, StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); - if (!m_pFileStream) - m_pFileStream = OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); - if(m_pFileStream) - { - m_pFileStream->SetEndian(SvStreamEndian::LITTLE); - m_pFileStream->SetBufferSize(DINDEX_PAGE_SIZE); - (*m_pFileStream) >> *this; - } - } - if(!m_pFileStream) + m_pFileStream = OFileTable::createStream_simpleError(sFile, StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); + if (!m_pFileStream) + m_pFileStream = OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); + if(m_pFileStream) { - const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution( - STR_COULD_NOT_LOAD_FILE, - "$filename$", sFile - ) ); - ::dbtools::throwGenericSQLException( sError, *this ); + m_pFileStream->SetEndian(SvStreamEndian::LITTLE); + m_pFileStream->SetBufferSize(DINDEX_PAGE_SIZE); + (*m_pFileStream) >> *this; } } + if(!m_pFileStream) + { + const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution( + STR_COULD_NOT_LOAD_FILE, + "$filename$", sFile + ) ); + ::dbtools::throwGenericSQLException( sError, *this ); + } } std::unique_ptr<OIndexIterator> ODbaseIndex::createIterator() diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index bf2036b2ca19..ff01f3b6ba37 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -482,63 +482,63 @@ void ODbaseTable::construct() m_pFileStream = createStream_simpleError( sFileName, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); } - if(m_pFileStream) - { - readHeader(); - if (HasMemoFields()) - { - // Create Memo-Filename (.DBT): - // nyi: Ugly for Unix and Mac! + if(!m_pFileStream) + return; - if ( m_aHeader.type == FoxProMemo || m_aHeader.type == VisualFoxPro || m_aHeader.type == VisualFoxProAuto) // foxpro uses another extension - aURL.SetExtension("fpt"); - else - aURL.SetExtension("dbt"); + readHeader(); + if (HasMemoFields()) + { + // Create Memo-Filename (.DBT): + // nyi: Ugly for Unix and Mac! - // If the memo file isn't found, the data will be displayed anyhow. - // However, updates can't be done - // but the operation is executed - m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); - if ( !m_pMemoStream ) - { - m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); - } - if (m_pMemoStream) - ReadMemoHeader(); - } - fillColumns(); + if ( m_aHeader.type == FoxProMemo || m_aHeader.type == VisualFoxPro || m_aHeader.type == VisualFoxProAuto) // foxpro uses another extension + aURL.SetExtension("fpt"); + else + aURL.SetExtension("dbt"); - std::size_t nFileSize = lcl_getFileSize(*m_pFileStream); - m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); - // seems to be empty or someone wrote bullshit into the dbase file - // try and recover if m_aHeader.db_slng is sane - if (m_aHeader.nbRecords == 0 && m_aHeader.recordLength) + // If the memo file isn't found, the data will be displayed anyhow. + // However, updates can't be done + // but the operation is executed + m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); + if ( !m_pMemoStream ) { - std::size_t nRecords = (nFileSize-m_aHeader.headerLength)/m_aHeader.recordLength; - if (nRecords > 0) - m_aHeader.nbRecords = nRecords; + m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); } + if (m_pMemoStream) + ReadMemoHeader(); + } + fillColumns(); - // Buffersize dependent on the file size - m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 : - nFileSize > 100000 ? 16384 : - nFileSize > 10000 ? 4096 : 1024); + std::size_t nFileSize = lcl_getFileSize(*m_pFileStream); + m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); + // seems to be empty or someone wrote bullshit into the dbase file + // try and recover if m_aHeader.db_slng is sane + if (m_aHeader.nbRecords == 0 && m_aHeader.recordLength) + { + std::size_t nRecords = (nFileSize-m_aHeader.headerLength)/m_aHeader.recordLength; + if (nRecords > 0) + m_aHeader.nbRecords = nRecords; + } - if (m_pMemoStream) - { - // set the buffer exactly to the length of a record - nFileSize = m_pMemoStream->TellEnd(); - m_pMemoStream->Seek(STREAM_SEEK_TO_BEGIN); - - // Buffersize dependent on the file size - m_pMemoStream->SetBufferSize(nFileSize > 1000000 ? 32768 : - nFileSize > 100000 ? 16384 : - nFileSize > 10000 ? 4096 : - m_aMemoHeader.db_size); - } + // Buffersize dependent on the file size + m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 : + nFileSize > 100000 ? 16384 : + nFileSize > 10000 ? 4096 : 1024); + + if (m_pMemoStream) + { + // set the buffer exactly to the length of a record + nFileSize = m_pMemoStream->TellEnd(); + m_pMemoStream->Seek(STREAM_SEEK_TO_BEGIN); - AllocBuffer(); + // Buffersize dependent on the file size + m_pMemoStream->SetBufferSize(nFileSize > 1000000 ? 32768 : + nFileSize > 100000 ? 16384 : + nFileSize > 10000 ? 4096 : + m_aMemoHeader.db_size); } + + AllocBuffer(); } void ODbaseTable::ReadMemoHeader() diff --git a/connectivity/source/drivers/dbase/dindexnode.cxx b/connectivity/source/drivers/dbase/dindexnode.cxx index ae105b8be512..1ac10800f0a9 100644 --- a/connectivity/source/drivers/dbase/dindexnode.cxx +++ b/connectivity/source/drivers/dbase/dindexnode.cxx @@ -997,24 +997,24 @@ void ONDXPage::SearchAndReplace(const ONDXKey& rSearch, ONDXKey const & rReplace) { OSL_ENSURE(rSearch != rReplace,"Invalid here:rSearch == rReplace"); - if (rSearch != rReplace) - { - sal_uInt16 nPos = NODE_NOTFOUND; - ONDXPage* pPage = this; + if (rSearch == rReplace) + return; - while (pPage) - { - nPos = pPage->Search(rSearch); - if (nPos != NODE_NOTFOUND) - break; - pPage = pPage->aParent; - } + sal_uInt16 nPos = NODE_NOTFOUND; + ONDXPage* pPage = this; - if (pPage) - { - (*pPage)[nPos].GetKey() = rReplace; - pPage->SetModified(true); - } + while (pPage) + { + nPos = pPage->Search(rSearch); + if (nPos != NODE_NOTFOUND) + break; + pPage = pPage->aParent; + } + + if (pPage) + { + (*pPage)[nPos].GetKey() = rReplace; + pPage->SetModified(true); } } diff --git a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx index a5efdd2a0e6a..9eb6f1d34862 100644 --- a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx +++ b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx @@ -90,53 +90,53 @@ namespace connectivity::evoab static void initFields() { - if( !pFields ) + if( pFields ) + return; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( pFields ) + return; + + guint nProps; + ColumnProperty **pToBeFields; + GParamSpec **pProps; + nFields = 0; + pProps = g_object_class_list_properties + ( static_cast<GObjectClass *>(g_type_class_ref( E_TYPE_CONTACT )), + &nProps ); + pToBeFields = g_new0(ColumnProperty *, (nProps + OTHER_ZIP)/* new column(s)*/ ); + for ( guint i = 0; i < nProps; i++ ) { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if( !pFields ) + switch (pProps[i]->value_type) { - guint nProps; - ColumnProperty **pToBeFields; - GParamSpec **pProps; - nFields = 0; - pProps = g_object_class_list_properties - ( static_cast<GObjectClass *>(g_type_class_ref( E_TYPE_CONTACT )), - &nProps ); - pToBeFields = g_new0(ColumnProperty *, (nProps + OTHER_ZIP)/* new column(s)*/ ); - for ( guint i = 0; i < nProps; i++ ) + case G_TYPE_STRING: + case G_TYPE_BOOLEAN: { - switch (pProps[i]->value_type) + bool bAdd = true; + const char *pName = g_param_spec_get_name( pProps[i] ); + for (unsigned int j = 0; j < G_N_ELEMENTS( pBlackList ); j++ ) { - case G_TYPE_STRING: - case G_TYPE_BOOLEAN: + if( !strcmp( pBlackList[j], pName ) ) { - bool bAdd = true; - const char *pName = g_param_spec_get_name( pProps[i] ); - for (unsigned int j = 0; j < G_N_ELEMENTS( pBlackList ); j++ ) - { - if( !strcmp( pBlackList[j], pName ) ) - { - bAdd = false; - break; - } - } - if( bAdd ) - { - pToBeFields[nFields]= g_new0(ColumnProperty,1); - pToBeFields[nFields]->bIsSplittedValue=false; - pToBeFields[ nFields++ ]->pField = g_param_spec_ref( pProps[i] ); - } + bAdd = false; break; } - default: - break; } + if( bAdd ) + { + pToBeFields[nFields]= g_new0(ColumnProperty,1); + pToBeFields[nFields]->bIsSplittedValue=false; + pToBeFields[ nFields++ ]->pField = g_param_spec_ref( pProps[i] ); + } + break; } - - splitColumn(pToBeFields); - pFields = pToBeFields; + default: + break; } } + + splitColumn(pToBeFields); + pFields = pToBeFields; } diff --git a/connectivity/source/drivers/file/FPreparedStatement.cxx b/connectivity/source/drivers/file/FPreparedStatement.cxx index 6d74583935ca..fc5b81923cb4 100644 --- a/connectivity/source/drivers/file/FPreparedStatement.cxx +++ b/connectivity/source/drivers/file/FPreparedStatement.cxx @@ -482,17 +482,17 @@ void OPreparedStatement::describeParameter() { std::vector< OSQLParseNode*> aParseNodes; scanParameter(m_pParseTree,aParseNodes); - if ( !aParseNodes.empty() ) + if ( aParseNodes.empty() ) + return; + + // m_xParamColumns = new OSQLColumns(); + const OSQLTables& rTabs = m_aSQLIterator.getTables(); + if( !rTabs.empty() ) { - // m_xParamColumns = new OSQLColumns(); - const OSQLTables& rTabs = m_aSQLIterator.getTables(); - if( !rTabs.empty() ) + OSQLTable xTable = rTabs.begin()->second; + for (auto const& parseNode : aParseNodes) { - OSQLTable xTable = rTabs.begin()->second; - for (auto const& parseNode : aParseNodes) - { - describeColumn(parseNode,parseNode->getParent()->getChild(0),xTable); - } + describeColumn(parseNode,parseNode->getParent()->getChild(0),xTable); } } } @@ -501,36 +501,36 @@ void OPreparedStatement::initializeResultSet(OResultSet* pRS) OStatement_Base::initializeResultSet(pRS); // Substitute parameter (AssignValues and criteria): - if (!m_xParamColumns->empty()) - { - // begin with AssignValues - sal_uInt16 nParaCount=0; // gives the current number of previously set Parameters + if (m_xParamColumns->empty()) + return; - // search for parameters to be substituted: - size_t nCount = m_aAssignValues.is() ? m_aAssignValues->size() : 1; // 1 is important for the Criteria - for (size_t j = 1; j < nCount; j++) - { - sal_uInt32 nParameter = (*m_aAssignValues).getParameterIndex(j); - if (nParameter == SQL_NO_PARAMETER) - continue; // this AssignValue is no Parameter + // begin with AssignValues + sal_uInt16 nParaCount=0; // gives the current number of previously set Parameters - ++nParaCount; // now the Parameter is valid - } + // search for parameters to be substituted: + size_t nCount = m_aAssignValues.is() ? m_aAssignValues->size() : 1; // 1 is important for the Criteria + for (size_t j = 1; j < nCount; j++) + { + sal_uInt32 nParameter = (*m_aAssignValues).getParameterIndex(j); + if (nParameter == SQL_NO_PARAMETER) + continue; // this AssignValue is no Parameter - if (m_aParameterRow.is() && (m_xParamColumns->size()+1) != m_aParameterRow->size() ) + ++nParaCount; // now the Parameter is valid + } + + if (m_aParameterRow.is() && (m_xParamColumns->size()+1) != m_aParameterRow->size() ) + { + sal_Int32 i = m_aParameterRow->size(); + sal_Int32 nParamColumns = m_xParamColumns->size()+1; + m_aParameterRow->resize(nParamColumns); + for ( ;i < nParamColumns; ++i ) { - sal_Int32 i = m_aParameterRow->size(); - sal_Int32 nParamColumns = m_xParamColumns->size()+1; - m_aParameterRow->resize(nParamColumns); - for ( ;i < nParamColumns; ++i ) - { - if ( !(*m_aParameterRow)[i].is() ) - (*m_aParameterRow)[i] = new ORowSetValueDecorator; - } + if ( !(*m_aParameterRow)[i].is() ) + (*m_aParameterRow)[i] = new ORowSetValueDecorator; } - if (m_aParameterRow.is() && nParaCount < m_aParameterRow->size() ) - m_pSQLAnalyzer->bindParameterRow(m_aParameterRow); } + if (m_aParameterRow.is() && nParaCount < m_aParameterRow->size() ) + m_pSQLAnalyzer->bindParameterRow(m_aParameterRow); } void OPreparedStatement::parseParamterElem(const OUString& _sColumnName, OSQLParseNode* pRow_Value_Constructor_Elem) diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx index 3b8f69d6ab6e..d7f3d6bd2090 100644 --- a/connectivity/source/drivers/file/FResultSet.cxx +++ b/connectivity/source/drivers/file/FResultSet.cxx @@ -1472,40 +1472,40 @@ void OResultSet::setBoundedColumns(const OValueRefRow& _rRow, } } // in this case we got more select columns as columns exist in the table - if ( _bSetColumnMapping && aSelectIters.size() != _rColMapping.size() ) - { - Reference<XNameAccess> xNameAccess(_xNames,UNO_QUERY); - Sequence< OUString > aSelectColumns = xNameAccess->getElementNames(); + if ( !(_bSetColumnMapping && aSelectIters.size() != _rColMapping.size()) ) + return; - for ( OSQLColumns::iterator aIter = _rxColumns->begin(); - aIter != _rxColumns->end(); - ++aIter - ) + Reference<XNameAccess> xNameAccess(_xNames,UNO_QUERY); + Sequence< OUString > aSelectColumns = xNameAccess->getElementNames(); + + for ( OSQLColumns::iterator aIter = _rxColumns->begin(); + aIter != _rxColumns->end(); + ++aIter + ) + { + if ( aSelectIters.end() == aSelectIters.find(aIter) ) { - if ( aSelectIters.end() == aSelectIters.find(aIter) ) - { - if ( (*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName) ) - (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName; - else - (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName; + if ( (*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName) ) + (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName; + else + (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName; - if ( xNameAccess->hasByName( sSelectColumnRealName ) ) + if ( xNameAccess->hasByName( sSelectColumnRealName ) ) + { + aSelectIters.emplace(aIter,true); + sal_Int32 nSelectColumnPos = aIter - _rxColumns->begin() + 1; + const OUString* pBegin = aSelectColumns.getConstArray(); + const OUString* pEnd = pBegin + aSelectColumns.getLength(); + for(sal_Int32 i=0;pBegin != pEnd;++pBegin,++i) { - aSelectIters.emplace(aIter,true); - sal_Int32 nSelectColumnPos = aIter - _rxColumns->begin() + 1; - const OUString* pBegin = aSelectColumns.getConstArray(); - const OUString* pEnd = pBegin + aSelectColumns.getLength(); - for(sal_Int32 i=0;pBegin != pEnd;++pBegin,++i) + if ( aCase(*pBegin, sSelectColumnRealName) ) { - if ( aCase(*pBegin, sSelectColumnRealName) ) - { - // the getXXX methods are 1-based ... - sal_Int32 nTableColumnPos = i + 1; - // get first table column is the bookmark column ... - _rColMapping[nSelectColumnPos] = nTableColumnPos; - (*_rSelectRow)[nSelectColumnPos] = (*_rRow)[nTableColumnPos]; - break; - } + // the getXXX methods are 1-based ... + sal_Int32 nTableColumnPos = i + 1; + // get first table column is the bookmark column ... + _rColMapping[nSelectColumnPos] = nTableColumnPos; + (*_rSelectRow)[nSelectColumnPos] = (*_rRow)[nTableColumnPos]; + break; } } } diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx index 28eef44ff71e..08c4f7fdd844 100644 --- a/connectivity/source/drivers/file/FStatement.cxx +++ b/connectivity/source/drivers/file/FStatement.cxx @@ -310,25 +310,25 @@ void OStatement_Base::anylizeSQL() m_pSQLAnalyzer->start(m_pParseTree); const OSQLParseNode* pOrderbyClause = m_aSQLIterator.getOrderTree(); - if(pOrderbyClause) + if(!pOrderbyClause) + return; + + OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2); + OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Error in Parse Tree"); + + for (size_t m = 0; m < pOrderingSpecCommalist->count(); m++) { - OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2); - OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Error in Parse Tree"); + OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m); + OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Error in Parse Tree"); + OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Error in Parse Tree"); - for (size_t m = 0; m < pOrderingSpecCommalist->count(); m++) + OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0); + if(!SQL_ISRULE(pColumnRef,column_ref)) { - OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m); - OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Error in Parse Tree"); - OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Error in Parse Tree"); - - OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0); - if(!SQL_ISRULE(pColumnRef,column_ref)) - { - throw SQLException(); - } - OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1); - setOrderbyColumn(pColumnRef,pAscendingDescending); + throw SQLException(); } + OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1); + setOrderbyColumn(pColumnRef,pAscendingDescending); } } diff --git a/connectivity/source/drivers/firebird/Blob.cxx b/connectivity/source/drivers/firebird/Blob.cxx index 3468a50ce3f4..8ed9fc4a8ac7 100644 --- a/connectivity/source/drivers/firebird/Blob.cxx +++ b/connectivity/source/drivers/firebird/Blob.cxx @@ -153,21 +153,21 @@ void Blob::closeBlob() { MutexGuard aGuard(m_aMutex); - if (m_bBlobOpened) - { - ISC_STATUS aErr; - aErr = isc_close_blob(m_statusVector, - &m_blobHandle); - if (aErr) - evaluateStatusVector(m_statusVector, "isc_close_blob", *this); + if (!m_bBlobOpened) + return; - m_bBlobOpened = false; + ISC_STATUS aErr; + aErr = isc_close_blob(m_statusVector, + &m_blobHandle); + if (aErr) + evaluateStatusVector(m_statusVector, "isc_close_blob", *this); + + m_bBlobOpened = false; #if SAL_TYPES_SIZEOFPOINTER == 8 - m_blobHandle = 0; + m_blobHandle = 0; #else - m_blobHandle = nullptr; + m_blobHandle = nullptr; #endif - } } void SAL_CALL Blob::disposing() diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index 58aad4e1939e..b5a3c4ce748a 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -791,49 +791,48 @@ void SAL_CALL Connection::documentEventOccured( const DocumentEvent& Event ) if (!m_bIsEmbedded) return; - if (Event.EventName == "OnSave" || Event.EventName == "OnSaveAs") - { - commit(); // Commit and close transaction - if ( m_bIsEmbedded && m_xEmbeddedStorage.is() ) - { - SAL_INFO("connectivity.firebird", "Writing .fbk from running db"); - try - { - runBackupService(isc_action_svc_backup); - } - catch (const SQLException& e) - { - auto a = cppu::getCaughtException(); - throw WrappedTargetRuntimeException(e.Message, e.Context, a); - } + if (!(Event.EventName == "OnSave" || Event.EventName == "OnSaveAs")) + return; + commit(); // Commit and close transaction + if ( !(m_bIsEmbedded && m_xEmbeddedStorage.is()) ) + return; + + SAL_INFO("connectivity.firebird", "Writing .fbk from running db"); + try + { + runBackupService(isc_action_svc_backup); + } + catch (const SQLException& e) + { + auto a = cppu::getCaughtException(); + throw WrappedTargetRuntimeException(e.Message, e.Context, a); + } - Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sFBKLocation, - ElementModes::WRITE)); - // TODO: verify the backup actually exists -- the backup service - // can fail without giving any sane error messages / telling us - // that it failed. - using namespace ::comphelper; - Reference< XComponentContext > xContext = comphelper::getProcessComponentContext(); - Reference< XInputStream > xInputStream; - if (xContext.is()) - { - xInputStream = - OStorageHelper::GetInputStreamFromURL(m_sFBKPath, xContext); - if (xInputStream.is()) - OStorageHelper::CopyInputToOutput( xInputStream, - xDBStream->getOutputStream()); + Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sFBKLocation, + ElementModes::WRITE)); - // remove old fdb file if exists - uno::Reference< ucb::XSimpleFileAccess > xFileAccess = - ucb::SimpleFileAccess::create(xContext); - if (xFileAccess->exists(m_sFirebirdURL)) - xFileAccess->kill(m_sFirebirdURL); - } - } + // TODO: verify the backup actually exists -- the backup service + // can fail without giving any sane error messages / telling us + // that it failed. + using namespace ::comphelper; + Reference< XComponentContext > xContext = comphelper::getProcessComponentContext(); + Reference< XInputStream > xInputStream; + if (!xContext.is()) + return; - } + xInputStream = + OStorageHelper::GetInputStreamFromURL(m_sFBKPath, xContext); + if (xInputStream.is()) + OStorageHelper::CopyInputToOutput( xInputStream, + xDBStream->getOutputStream()); + + // remove old fdb file if exists + uno::Reference< ucb::XSimpleFileAccess > xFileAccess = + ucb::SimpleFileAccess::create(xContext); + if (xFileAccess->exists(m_sFirebirdURL)) + xFileAccess->kill(m_sFirebirdURL); } // XEventListener void SAL_CALL Connection::disposing(const EventObject& /*rSource*/) diff --git a/connectivity/source/drivers/firebird/Keys.cxx b/connectivity/source/drivers/firebird/Keys.cxx index 90f3966efad7..dd4cca47fb20 100644 --- a/connectivity/source/drivers/firebird/Keys.cxx +++ b/connectivity/source/drivers/firebird/Keys.cxx @@ -34,20 +34,20 @@ Keys::Keys(Table* pTable, Mutex& rMutex, const ::std::vector< OUString>& rNames) //----- XDrop ---------------------------------------------------------------- void Keys::dropObject(sal_Int32 nPosition, const OUString& sName) { - if (!m_pTable->isNew()) - { - uno::Reference<XPropertySet> xKey(getObject(nPosition), UNO_QUERY); + if (m_pTable->isNew()) + return; + + uno::Reference<XPropertySet> xKey(getObject(nPosition), UNO_QUERY); - if (xKey.is()) - { - const OUString sQuote = m_pTable->getConnection()->getMetaData() - ->getIdentifierQuoteString(); + if (xKey.is()) + { + const OUString sQuote = m_pTable->getConnection()->getMetaData() + ->getIdentifierQuoteString(); - OUString sSql("ALTER TABLE " + quoteName(sQuote, m_pTable->getName()) - + " DROP CONSTRAINT " + quoteName(sQuote, sName)); + OUString sSql("ALTER TABLE " + quoteName(sQuote, m_pTable->getName()) + + " DROP CONSTRAINT " + quoteName(sQuote, sName)); - m_pTable->getConnection()->createStatement()->execute(sSql); - } + m_pTable->getConnection()->createStatement()->execute(sSql); } } diff --git a/connectivity/source/drivers/firebird/Table.cxx b/connectivity/source/drivers/firebird/Table.cxx index 0220a8458264..e0eba9d7e264 100644 --- a/connectivity/source/drivers/firebird/Table.cxx +++ b/connectivity/source/drivers/firebird/Table.cxx @@ -70,24 +70,24 @@ Table::Table(Tables* pTables, void Table::construct() { OTableHelper::construct(); - if (!isNew()) - { - // TODO: get privileges when in non-embedded mode. - m_nPrivileges = Privilege::DROP | - Privilege::REFERENCE | - Privilege::ALTER | - Privilege::CREATE | - Privilege::READ | - Privilege::DELETE | - Privilege::UPDATE | - Privilege::INSERT | - Privilege::SELECT; - registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRIVILEGES), - PROPERTY_ID_PRIVILEGES, - PropertyAttribute::READONLY, - &m_nPrivileges, - cppu::UnoType<decltype(m_nPrivileges)>::get()); - } + if (isNew()) + return; + + // TODO: get privileges when in non-embedded mode. + m_nPrivileges = Privilege::DROP | + Privilege::REFERENCE | + Privilege::ALTER | + Privilege::CREATE | + Privilege::READ | + Privilege::DELETE | + Privilege::UPDATE | + Privilege::INSERT | + Privilege::SELECT; + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRIVILEGES), + PROPERTY_ID_PRIVILEGES, + PropertyAttribute::READONLY, + &m_nPrivileges, + cppu::UnoType<decltype(m_nPrivileges)>::get()); } //----- OTableHelper --------------------------------------------------------- OCollection* Table::createColumns(const ::std::vector< OUString>& rNames) diff --git a/connectivity/source/drivers/firebird/Tables.cxx b/connectivity/source/drivers/firebird/Tables.cxx index 7be79b5a2d4a..34907418abf8 100644 --- a/connectivity/source/drivers/firebird/Tables.cxx +++ b/connectivity/source/drivers/firebird/Tables.cxx @@ -207,19 +207,19 @@ void Tables::dropObject(sal_Int32 nPosition, const OUString& sName) { uno::Reference< XPropertySet > xTable(getObject(nPosition)); - if (!ODescriptor::isNew(xTable)) - { - OUStringBuffer sSql("DROP "); + if (ODescriptor::isNew(xTable)) + return; - OUString sType; - xTable->getPropertyValue("Type") >>= sType; - sSql.append(sType); + OUStringBuffer sSql("DROP "); - const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString(); - sSql.append(::dbtools::quoteName(sQuoteString,sName)); + OUString sType; + xTable->getPropertyValue("Type") >>= sType; + sSql.append(sType); - m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear()); - } + const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString(); + sSql.append(::dbtools::quoteName(sQuoteString,sName)); + + m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/flat/ETable.cxx b/connectivity/source/drivers/flat/ETable.cxx index 670fe46dffb0..43bc75225b1d 100644 --- a/connectivity/source/drivers/flat/ETable.cxx +++ b/connectivity/source/drivers/flat/ETable.cxx @@ -430,19 +430,19 @@ void OFlatTable::construct() if(!m_pFileStream) m_pFileStream = createStream_simpleError( aFileName, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); - if(m_pFileStream) - { - sal_uInt64 const nSize = m_pFileStream->remainingSize(); + if(!m_pFileStream) + return; - // Buffersize is dependent on the file-size - m_pFileStream->SetBufferSize(nSize > 1000000 ? 32768 : - nSize > 100000 ? 16384 : - nSize > 10000 ? 4096 : 1024); + sal_uInt64 const nSize = m_pFileStream->remainingSize(); - fillColumns(aAppLocale); + // Buffersize is dependent on the file-size + m_pFileStream->SetBufferSize(nSize > 1000000 ? 32768 : + nSize > 100000 ? 16384 : + nSize > 10000 ? 4096 : 1024); - refreshColumns(); - } + fillColumns(aAppLocale); + + refreshColumns(); } OUString OFlatTable::getEntry() const diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx index 7e006ecb61a2..05b9478a9f12 100644 --- a/connectivity/source/drivers/hsqldb/HDriver.cxx +++ b/connectivity/source/drivers/hsqldb/HDriver.cxx @@ -611,41 +611,41 @@ namespace connectivity Reference< XStorage> xStorage(aEvent.Source,UNO_QUERY); OUString sKey = StorageContainer::getRegisteredKey(xStorage); - if ( !sKey.isEmpty() ) - { - TWeakPairVector::const_iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), - [&sKey] (const TWeakPairVector::value_type& conn) { - return conn.second.first == sKey; - }); + if ( sKey.isEmpty() ) + return; + + TWeakPairVector::const_iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&sKey] (const TWeakPairVector::value_type& conn) { + return conn.second.first == sKey; + }); + + OSL_ENSURE( i != m_aConnections.end(), "ODriverDelegator::preCommit: they're committing a storage which I do not know!" ); + if ( i == m_aConnections.end() ) + return; - OSL_ENSURE( i != m_aConnections.end(), "ODriverDelegator::preCommit: they're committing a storage which I do not know!" ); - if ( i != m_aConnections.end() ) + try + { + Reference<XConnection> xConnection(i->first,UNO_QUERY); + if ( xConnection.is() ) { - try - { - Reference<XConnection> xConnection(i->first,UNO_QUERY); - if ( xConnection.is() ) - { - Reference< XStatement> xStmt = xConnection->createStatement(); - OSL_ENSURE( xStmt.is(), "ODriverDelegator::preCommit: no statement!" ); - if ( xStmt.is() ) - xStmt->execute( "SET WRITE_DELAY 0" ); - - bool bPreviousAutoCommit = xConnection->getAutoCommit(); - xConnection->setAutoCommit( false ); - xConnection->commit(); - xConnection->setAutoCommit( bPreviousAutoCommit ); - - if ( xStmt.is() ) ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits