diff options
author | Ocke Janssen <oj@openoffice.org> | 2002-12-10 08:19:22 +0000 |
---|---|---|
committer | Ocke Janssen <oj@openoffice.org> | 2002-12-10 08:19:22 +0000 |
commit | 6912006750fc543e4f0bc3e8e8ed5c3199c1b668 (patch) | |
tree | 5562ccf23b88e9260fd030980c2c091f2d6afbc3 /dbaccess/source/ui/misc | |
parent | a84ac55f3208f677320554dc2765a3d1ba9a015a (diff) |
#106092# check column names
Diffstat (limited to 'dbaccess/source/ui/misc')
-rw-r--r-- | dbaccess/source/ui/misc/DExport.cxx | 6 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/WCPage.cxx | 8 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/WCopyTable.cxx | 24 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/WTypeSelect.cxx | 51 |
4 files changed, 72 insertions, 17 deletions
diff --git a/dbaccess/source/ui/misc/DExport.cxx b/dbaccess/source/ui/misc/DExport.cxx index 27ab834f6d09..86f981123492 100644 --- a/dbaccess/source/ui/misc/DExport.cxx +++ b/dbaccess/source/ui/misc/DExport.cxx @@ -2,9 +2,9 @@ * * $RCSfile: DExport.cxx,v $ * - * $Revision: 1.18 $ + * $Revision: 1.19 $ * - * last change: $Author: oj $ $Date: 2002-11-14 07:57:00 $ + * last change: $Author: oj $ $Date: 2002-12-10 09:17:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -604,7 +604,7 @@ void ODatabaseExport::CreateDefaultColumn(const ::rtl::OUString& _rColumnName) { aAlias = aAlias.copy(0,::std::min<sal_Int32>( nMaxNameLen-1, aAlias.getLength() )); - sal_Int32 nPos = 1; + sal_Int32 nPos = 0; sal_Int32 nCount = 2; while(m_aDestColumns.find(sName) != m_aDestColumns.end()) { diff --git a/dbaccess/source/ui/misc/WCPage.cxx b/dbaccess/source/ui/misc/WCPage.cxx index bfe2b20890a9..410c4d810429 100644 --- a/dbaccess/source/ui/misc/WCPage.cxx +++ b/dbaccess/source/ui/misc/WCPage.cxx @@ -2,9 +2,9 @@ * * $RCSfile: WCPage.cxx,v $ * - * $Revision: 1.18 $ + * $Revision: 1.19 $ * - * last change: $Author: oj $ $Date: 2002-11-14 07:57:01 $ + * last change: $Author: oj $ $Date: 2002-12-10 09:17:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -216,7 +216,7 @@ OCopyTable::OCopyTable( Window * pParent, EImportMode atWhat, sal_Bool bIsView, m_edKeyName.Enable(sal_False); ::rtl::OUString sKeyName(::rtl::OUString::createFromAscii("ID")); - sKeyName = ::dbtools::createUniqueName(m_pParent->m_xSourceColumns,sKeyName,sal_False); + sKeyName = m_pParent->createUniqueName(sKeyName); m_edKeyName.SetText(sKeyName); sal_Int32 nMaxLen = m_pParent->getMaxColumnNameLength(); @@ -320,7 +320,7 @@ sal_Bool OCopyTable::LeavePage() // now we have to check if the name of the primary key already exists if ( m_pParent->m_bCreatePrimaryColumn - && m_pParent->m_aKeyName != ::dbtools::createUniqueName(m_pParent->m_xSourceColumns,m_pParent->m_aKeyName,sal_False) ) + && m_pParent->m_aKeyName != m_pParent->createUniqueName(m_pParent->m_aKeyName) ) { String aInfoString( ModuleRes(STR_WIZ_PKEY_ALREADY_DEFINED) ); aInfoString += String(' '); diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx index c0a24cd9a4cd..18e64d537f24 100644 --- a/dbaccess/source/ui/misc/WCopyTable.cxx +++ b/dbaccess/source/ui/misc/WCopyTable.cxx @@ -2,9 +2,9 @@ * * $RCSfile: WCopyTable.cxx,v $ * - * $Revision: 1.28 $ + * $Revision: 1.29 $ * - * last change: $Author: oj $ $Date: 2002-11-14 07:57:01 $ + * last change: $Author: oj $ $Date: 2002-12-10 09:17:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1061,3 +1061,23 @@ const OTypeInfo* OCopyTableWizard::convertType(const OTypeInfo* _pType) return pType; } // ----------------------------------------------------------------------------- +::rtl::OUString OCopyTableWizard::createUniqueName(const ::rtl::OUString& _sName) +{ + ::rtl::OUString sName = _sName; + if ( m_xSourceColumns.is() ) + sName = ::dbtools::createUniqueName(m_xSourceColumns,sName,sal_False); + else + { + if ( m_vSourceColumns.find(sName) != m_vSourceColumns.end()) + { + sal_Int32 nPos = 0; + while(m_vSourceColumns.find(sName) != m_vSourceColumns.end()) + { + sName = _sName; + sName += ::rtl::OUString::valueOf(++nPos); + } + } + } + return sName; +} +// ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/misc/WTypeSelect.cxx b/dbaccess/source/ui/misc/WTypeSelect.cxx index ba4f1a00a4e0..e5683d6e2adb 100644 --- a/dbaccess/source/ui/misc/WTypeSelect.cxx +++ b/dbaccess/source/ui/misc/WTypeSelect.cxx @@ -2,9 +2,9 @@ * * $RCSfile: WTypeSelect.cxx,v $ * - * $Revision: 1.16 $ + * $Revision: 1.17 $ * - * last change: $Author: oj $ $Date: 2002-11-14 07:57:01 $ + * last change: $Author: oj $ $Date: 2002-12-10 09:17:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -97,6 +97,9 @@ #ifndef _DBAUI_SQLMESSAGE_HXX_ #include "sqlmessage.hxx" #endif +#ifndef DBAUI_FIELDCONTROLS_HXX +#include "FieldControls.hxx" +#endif using namespace ::dbaui; using namespace ::com::sun::star::uno; @@ -156,36 +159,67 @@ void OWizTypeSelectControl::CellModified(long nRow, sal_uInt16 nColId ) MultiListBox &aListBox = ((OWizTypeSelect*)GetParent())->m_lbColumnNames; sal_uInt16 nPos = aListBox.GetEntryPos(String(pActFieldDescr->GetName())); + OSL_ENSURE(nPos != LISTBOX_ENTRY_NOTFOUND,"Columnname could not be found in the listbox"); pActFieldDescr = static_cast<OFieldDescription*>(aListBox.GetEntryData(nPos)); + if ( !pActFieldDescr ) + return; ::rtl::OUString sName = pActFieldDescr->GetName(); - SaveData(pActFieldDescr); + ::rtl::OUString sNewName; + const OPropColumnEditCtrl* pColumnName = getColumnCtrl(); + if ( pColumnName ) + sNewName = pColumnName->GetText(); + switch(nColId) { case FIELD_PRPOERTY_COLUMNNAME: { + OCopyTableWizard* pWiz = static_cast<OCopyTableWizard*>(GetParent()->GetParent()); // first we have to check if this name already exists - if ( aListBox.GetEntryPos(String(pActFieldDescr->GetName())) != LISTBOX_ENTRY_NOTFOUND ) + sal_Bool bDoubleName = sal_False; + sal_Bool bCase = sal_True; + if ( getMetaData().is() && !getMetaData()->storesMixedCaseQuotedIdentifiers() ) + { + bCase = sal_False; + sal_Int32 nCount = aListBox.GetEntryCount(); + for (sal_Int32 i=0 ; !bDoubleName && i < nCount ; ++i) + { + ::rtl::OUString sEntry(aListBox.GetEntry(i)); + bDoubleName = sNewName.equalsIgnoreAsciiCase(sEntry); + } + if ( !bDoubleName && pWiz->isAutoincrementEnabled() ) + bDoubleName = sNewName.equalsIgnoreAsciiCase(pWiz->getPrimaryKeyName()); + + } + else + bDoubleName = ((aListBox.GetEntryPos(String(pActFieldDescr->GetName())) != LISTBOX_ENTRY_NOTFOUND) + || ( pWiz->isAutoincrementEnabled() + && pWiz->getPrimaryKeyName() == pActFieldDescr->GetName()) ); + + if ( bDoubleName ) { String strMessage = String(ModuleRes(STR_TABLEDESIGN_DUPLICATE_NAME)); - strMessage.SearchAndReplaceAscii("$column$", pActFieldDescr->GetName()); + strMessage.SearchAndReplaceAscii("$column$", sNewName); String sTitle(ModuleRes(STR_STAT_WARNING)); OSQLMessageBox aMsg(this,sTitle,strMessage,WB_OK | WB_DEF_OK,OSQLMessageBox::Error); aMsg.Execute(); pActFieldDescr->SetName(sName); DisplayData(pActFieldDescr); - break; + return; } + pActFieldDescr->SetName(sNewName); + // now we change the name OCopyTableWizard::TNameMapping::iterator aIter = ((OWizTypeSelect*)GetParent())->m_pParent->m_mNameMapping.begin(); OCopyTableWizard::TNameMapping::iterator aEnd = ((OWizTypeSelect*)GetParent())->m_pParent->m_mNameMapping.end(); + ::comphelper::UStringMixEqual aCase(bCase); for(;aIter != aEnd;++aIter) { - if ( aIter->second == sName ) + if ( aCase(aIter->second,sName) ) { - aIter->second = pActFieldDescr->GetName(); + aIter->second = sNewName; break; } } @@ -196,6 +230,7 @@ void OWizTypeSelectControl::CellModified(long nRow, sal_uInt16 nColId ) } break; } + SaveData(pActFieldDescr); } // ----------------------------------------------------------------------- void OWizTypeSelectControl::SetModified(sal_Bool bModified) {} |