diff options
author | Rüdiger Timm <rt@openoffice.org> | 2008-06-06 12:17:41 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2008-06-06 12:17:41 +0000 |
commit | 9ca05a3813bf8a2288dab44ca44dadb4c8db10bb (patch) | |
tree | d63e367f74f3a72ca41d287e151136227224fb8c /connectivity | |
parent | ade96124e0b7c68cba690050902b53499584b0b8 (diff) |
INTEGRATION: CWS dba30c (1.9.10); FILE MERGED
2008/05/09 07:07:16 oj 1.9.10.6: #i87131# collect keys only once, getKeys always refetch the keys
2008/05/08 12:58:58 oj 1.9.10.5: eol aded
2008/05/08 12:55:10 oj 1.9.10.4: #i64472# use of create pattern
2008/05/08 07:15:27 oj 1.9.10.3: #i87131# collect keys only once, getKeys always refetch keys
2008/05/06 09:05:13 oj 1.9.10.2: shadow var
2008/05/05 10:57:50 oj 1.9.10.1: #i87131# collect keys only once, getKeys always refetch the keys
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/commontools/TTableHelper.cxx | 86 |
1 files changed, 66 insertions, 20 deletions
diff --git a/connectivity/source/commontools/TTableHelper.cxx b/connectivity/source/commontools/TTableHelper.cxx index 9bb0298c8673..ecec91aa6f32 100644 --- a/connectivity/source/commontools/TTableHelper.cxx +++ b/connectivity/source/commontools/TTableHelper.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: TTableHelper.cxx,v $ - * $Revision: 1.9 $ + * $Revision: 1.10 $ * * This file is part of OpenOffice.org. * @@ -230,26 +230,24 @@ void OTableHelper::refreshColumns() m_pColumns = createColumns(aVector); } // ------------------------------------------------------------------------- -void OTableHelper::refreshPrimaryKeys(std::vector< ::rtl::OUString>& _rKeys) +void OTableHelper::refreshPrimaryKeys(TStringVector& _rNames) { Any aCatalog; if ( m_CatalogName.getLength() ) aCatalog <<= m_CatalogName; Reference< XResultSet > xResult = getMetaData()->getPrimaryKeys(aCatalog,m_SchemaName,m_Name); - if(xResult.is()) + if ( xResult.is() && xResult->next() ) { Reference< XRow > xRow(xResult,UNO_QUERY); - if(xResult->next()) // there can be only one primary key - { - ::rtl::OUString aPkName = xRow->getString(6); - _rKeys.push_back(aPkName); - } + const ::rtl::OUString aPkName = xRow->getString(6); + m_aKeys.insert(TKeyMap::value_type(aPkName,sdbcx::TKeyProperties(new sdbcx::KeyProperties(::rtl::OUString(),KeyType::PRIMARY,0,0)))); + _rNames.push_back(aPkName); ::comphelper::disposeComponent(xResult); } } // ------------------------------------------------------------------------- -void OTableHelper::refreshForgeinKeys(std::vector< ::rtl::OUString>& _rKeys) +void OTableHelper::refreshForgeinKeys(TStringVector& _rNames) { Any aCatalog; if ( m_CatalogName.getLength() ) @@ -259,14 +257,30 @@ void OTableHelper::refreshForgeinKeys(std::vector< ::rtl::OUString>& _rKeys) if ( xRow.is() ) { + ::rtl::OUString aName,sCatalog,aSchema; while( xResult->next() ) { - sal_Int32 nKeySeq = xRow->getInt(9); + // this must be outsid the "if" because we have to call in a right order + sCatalog = xRow->getString(1); + if ( xRow->wasNull() ) + sCatalog = ::rtl::OUString(); + aSchema = xRow->getString(2); + aName = xRow->getString(3); + + const sal_Int32 nKeySeq = xRow->getInt(9); + const sal_Int32 nUpdateRule = xRow->getInt(10); + const sal_Int32 nDeleteRule = xRow->getInt(11); + if ( nKeySeq == 1 ) { // only append when the sequnce number is 1 to forbid serveral inserting the same key name - ::rtl::OUString sFkName = xRow->getString(12); - if ( !xRow->wasNull() && sFkName.getLength() ) - _rKeys.push_back(sFkName); + const ::rtl::OUString sFkName = xRow->getString(12); + if ( sFkName.getLength() && !xRow->wasNull() ) + { + ::rtl::OUString sReferencedName; + sReferencedName = ::dbtools::composeTableName(getMetaData(),sCatalog,aSchema,aName,sal_False,::dbtools::eInDataManipulation); + m_aKeys.insert(TKeyMap::value_type(sFkName,sdbcx::TKeyProperties(new sdbcx::KeyProperties(sReferencedName,KeyType::FOREIGN,nUpdateRule,nDeleteRule)))); + _rNames.push_back(sFkName); + } } } ::comphelper::disposeComponent(xResult); @@ -275,17 +289,22 @@ void OTableHelper::refreshForgeinKeys(std::vector< ::rtl::OUString>& _rKeys) // ------------------------------------------------------------------------- void OTableHelper::refreshKeys() { - TStringVector aVector; + m_aKeys.clear(); + + TStringVector aNames; if(!isNew()) { - refreshPrimaryKeys(aVector); - refreshForgeinKeys(aVector); - } - if(m_pKeys) + refreshPrimaryKeys(aNames); + refreshForgeinKeys(aNames); + m_pKeys = createKeys(aNames); + } // if(!isNew()) + else if (!m_pKeys ) + m_pKeys = createKeys(aNames); + /*if(m_pKeys) m_pKeys->reFill(aVector); - else - m_pKeys = createKeys(aVector); + else*/ + } // ------------------------------------------------------------------------- void OTableHelper::refreshIndexes() @@ -419,4 +438,31 @@ void SAL_CALL OTableHelper::release() throw() OTable_TYPEDEF::release(); } // ----------------------------------------------------------------------------- +sdbcx::TKeyProperties OTableHelper::getKeyProperties(const ::rtl::OUString& _sName) const +{ + sdbcx::TKeyProperties pKeyProps; + TKeyMap::const_iterator aFind = m_aKeys.find(_sName); + if ( aFind != m_aKeys.end() ) + { + pKeyProps = aFind->second; + } + else // only a fall back + { + OSL_ENSURE(0,"No key with the given name found"); + pKeyProps.reset(new sdbcx::KeyProperties()); + } + + return pKeyProps; +} +// ----------------------------------------------------------------------------- +void OTableHelper::addKey(const ::rtl::OUString& _sName,const sdbcx::TKeyProperties& _aKeyProperties) +{ + m_aKeys.insert(TKeyMap::value_type(_sName,_aKeyProperties)); +} +// ----------------------------------------------------------------------------- +::rtl::OUString OTableHelper::getTypeCreatePattern() const +{ + return ::rtl::OUString(); +} +// ----------------------------------------------------------------------------- |