summaryrefslogtreecommitdiff
path: root/connectivity/source/commontools
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-04-18 10:51:27 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-04-18 20:35:49 +0200
commit2d0bdcc586af71dae665646b37177fa104c50906 (patch)
treea4c0fafefd366b2840365a3e0ee83ed0ad314bbd /connectivity/source/commontools
parent02f7d20f14dffcb3832264eeab5bb97acc4977f3 (diff)
loplugin:flatten connectivity
Change-Id: Ic1d9eb84b64ebde99e15704a10b27f21447df4d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92469 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'connectivity/source/commontools')
-rw-r--r--connectivity/source/commontools/DriversConfig.cxx72
-rw-r--r--connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx170
-rw-r--r--connectivity/source/commontools/FValue.cxx206
-rw-r--r--connectivity/source/commontools/TColumnsHelper.cxx28
-rw-r--r--connectivity/source/commontools/TIndexes.cxx44
-rw-r--r--connectivity/source/commontools/TKeys.cxx62
-rw-r--r--connectivity/source/commontools/TTableHelper.cxx86
-rw-r--r--connectivity/source/commontools/conncleanup.cxx77
-rw-r--r--connectivity/source/commontools/dbtools.cxx130
9 files changed, 438 insertions, 437 deletions
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);
}
}
}