diff options
author | Ocke Janssen <oj@openoffice.org> | 2002-11-14 06:58:31 +0000 |
---|---|---|
committer | Ocke Janssen <oj@openoffice.org> | 2002-11-14 06:58:31 +0000 |
commit | 935c95d3e40c920de25463f265aa5afda9f63d2f (patch) | |
tree | 521ddbb6a2a821aa8febfcab2870d62eec44b579 /dbaccess/source/ui/tabledesign | |
parent | 842c79ed6674d0dd7640bb0567475dbe0431bad0 (diff) |
#105110# some reorg and code movements
Diffstat (limited to 'dbaccess/source/ui/tabledesign')
-rw-r--r-- | dbaccess/source/ui/tabledesign/FieldDescriptions.cxx | 64 | ||||
-rw-r--r-- | dbaccess/source/ui/tabledesign/TableController.cxx | 38 | ||||
-rw-r--r-- | dbaccess/source/ui/tabledesign/TableRow.cxx | 51 |
3 files changed, 71 insertions, 82 deletions
diff --git a/dbaccess/source/ui/tabledesign/FieldDescriptions.cxx b/dbaccess/source/ui/tabledesign/FieldDescriptions.cxx index 88b0d891a3e3..2dc467114b05 100644 --- a/dbaccess/source/ui/tabledesign/FieldDescriptions.cxx +++ b/dbaccess/source/ui/tabledesign/FieldDescriptions.cxx @@ -2,9 +2,9 @@ * * $RCSfile: FieldDescriptions.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: oj $ $Date: 2002-09-24 09:48:19 $ + * last change: $Author: oj $ $Date: 2002-11-14 07:55:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,6 +87,12 @@ #include "UITools.hxx" #endif +#define DEFAULT_VARCHAR_PRECSION 50 +#define DEFAULT_OTHER_PRECSION 16 +#define DEFAULT_NUMERIC_PRECSION 5 +#define DEFAULT_NUMERIC_SCALE 0 + + using namespace dbaui; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; @@ -219,6 +225,60 @@ OFieldDescription::OFieldDescription(const Reference< XPropertySet >& xAffectedC } } // ----------------------------------------------------------------------------- +void OFieldDescription::FillFromTypeInfo(const OTypeInfo* _pType,sal_Bool _bForce,sal_Bool _bReset) +{ + const OTypeInfo* pOldType = getTypeInfo(); + if ( _pType != pOldType ) + { + // reset type depending information + if ( _bReset ) + { + SetFormatKey(0); + SetControlDefault(Any()); + } + + sal_Bool bForce = _bForce || pOldType == NULL || pOldType->nType != _pType->nType; + switch ( _pType->nType ) + { + case DataType::CHAR: + case DataType::VARCHAR: + if ( bForce ) + { + sal_Int32 nPrec = DEFAULT_VARCHAR_PRECSION; + if ( GetPrecision() ) + nPrec = GetPrecision(); + SetPrecision(::std::min<sal_Int32>(nPrec,_pType->nPrecision)); + } + break; + default: + if ( bForce ) + { + sal_Int32 nPrec = DEFAULT_OTHER_PRECSION; + if ( GetPrecision() ) + nPrec = GetPrecision(); + if ( _pType->nPrecision && _pType->nMaximumScale ) + { + SetPrecision(nPrec ? nPrec : DEFAULT_NUMERIC_PRECSION); + SetScale(::std::min<sal_Int32>(GetScale() ? GetScale() : DEFAULT_NUMERIC_SCALE,_pType->nMaximumScale)); + } + else if ( _pType->nPrecision ) + SetPrecision(::std::min<sal_Int32>(nPrec,_pType->nPrecision)); + } + } + if ( !_pType->aCreateParams.getLength() ) + { + SetPrecision(_pType->nPrecision); + SetScale(_pType->nMinimumScale); + } + if ( !_pType->bNullable && IsNullable() ) + SetIsNullable(ColumnValue::NO_NULLS); + if ( !_pType->bAutoIncrement && IsAutoIncrement() ) + SetAutoIncrement(sal_False); + SetCurrency( _pType->bCurrency ); + SetType(_pType); + } +} +// ----------------------------------------------------------------------------- diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx index 582e5c94aeaf..ae1f66cc7b06 100644 --- a/dbaccess/source/ui/tabledesign/TableController.cxx +++ b/dbaccess/source/ui/tabledesign/TableController.cxx @@ -2,9 +2,9 @@ * * $RCSfile: TableController.cxx,v $ * - * $Revision: 1.84 $ + * $Revision: 1.85 $ * - * last change: $Author: oj $ $Date: 2002-11-12 13:20:11 $ + * last change: $Author: oj $ $Date: 2002-11-14 07:55:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -890,11 +890,7 @@ void OTableController::reconnect(sal_Bool _bUI) // ----------------------------------------------------------------------------- const OTypeInfo* OTableController::getTypeInfoByType(sal_Int32 _nDataType) const { - OTypeInfoMap::const_iterator aIter = m_aTypeInfo.find(_nDataType); - if(aIter != m_aTypeInfo.end()) - return aIter->second; - OSL_ENSURE(0,"Wrong DataType supplied!"); - return NULL; + return queryTypeInfoByType(_nDataType,m_aTypeInfo); } // ----------------------------------------------------------------------------- void OTableController::appendColumns(Reference<XColumnsSupplier>& _rxColSup,sal_Bool _bNew,sal_Bool _bKeyColumns) @@ -1203,33 +1199,9 @@ sal_Bool OTableController::checkColumns(sal_Bool _bNew) throw(::com::sun::star:: if (nReturn == RET_YES) { OTableRow* pNewRow = new OTableRow(); - const OTypeInfo* pTypeInfo = NULL; - // first we search for a type which supports autoIncrement - OTypeInfoMap::const_iterator aIter = m_aTypeInfo.begin(); - for(;aIter != m_aTypeInfo.end();++aIter) - { - // OJ: we don't want to set an autoincrement column to be key - // because we don't have the possiblity to know how to create - // such auto increment column later on - // so until we know how to do it, we create a column without autoincrement - // if ( !aIter->second->bAutoIncrement ) - { // therefor we have searched - if(aIter->second->nType == DataType::INTEGER) - { - pTypeInfo = aIter->second; // alternative - break; - } - else if(!pTypeInfo && aIter->second->nType == DataType::DOUBLE) - pTypeInfo = aIter->second; // alternative - else if(!pTypeInfo && aIter->second->nType == DataType::REAL) - pTypeInfo = aIter->second; // alternative - } - } - if(!pTypeInfo) // just a fallback - pTypeInfo = getTypeInfoByType(DataType::VARCHAR); + const OTypeInfo* pTypeInfo = ::dbaui::queryPrimaryKeyType(m_aTypeInfo); - OSL_ENSURE(pTypeInfo,"checkColumns: cann't find a type which is useable as a key!"); - if(pTypeInfo) + if ( pTypeInfo ) { pNewRow->SetFieldType( pTypeInfo ); OFieldDescription* pActFieldDescr = pNewRow->GetActFieldDescr(); diff --git a/dbaccess/source/ui/tabledesign/TableRow.cxx b/dbaccess/source/ui/tabledesign/TableRow.cxx index 23e133887c36..8104b83c5ba1 100644 --- a/dbaccess/source/ui/tabledesign/TableRow.cxx +++ b/dbaccess/source/ui/tabledesign/TableRow.cxx @@ -2,9 +2,9 @@ * * $RCSfile: TableRow.cxx,v $ * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * - * last change: $Author: oj $ $Date: 2002-09-24 09:19:06 $ + * last change: $Author: oj $ $Date: 2002-11-14 07:55:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,10 +75,6 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -#define DEFAULT_VARCHAR_PRECSION 50 -#define DEFAULT_OTHER_PRECSION 16 -#define DEFAULT_NUMERIC_PRECSION 5 -#define DEFAULT_NUMERIC_SCALE 0 //======================================================================== // class OTableRow //======================================================================== @@ -144,53 +140,14 @@ sal_Bool OTableRow::IsPrimaryKey() const void OTableRow::SetFieldType( const OTypeInfo* _pType, sal_Bool _bForce ) { DBG_CHKTHIS(OTableRow,NULL); - if(_pType) + if ( _pType ) { if( !m_pActFieldDescr ) { m_pActFieldDescr = new OFieldDescription(); m_bOwnsDescriptions = true; } - - const OTypeInfo* pOldType = m_pActFieldDescr->getTypeInfo(); - if(_pType != pOldType) - { - // reset type depending information - m_pActFieldDescr->SetFormatKey(0); - m_pActFieldDescr->SetControlDefault(Any()); - - sal_Bool bForce = _bForce || pOldType == NULL || pOldType->nType != _pType->nType; - switch(_pType->nType) - { - case DataType::CHAR: - case DataType::VARCHAR: - if(bForce) - m_pActFieldDescr->SetPrecision(::std::min<sal_Int32>(sal_Int32(DEFAULT_VARCHAR_PRECSION),_pType->nPrecision)); - break; - default: - if(bForce) - { - if(_pType->nPrecision && _pType->nMaximumScale) - { - m_pActFieldDescr->SetPrecision(DEFAULT_NUMERIC_PRECSION); - m_pActFieldDescr->SetScale(DEFAULT_NUMERIC_SCALE); - } - else if(_pType->nPrecision) - m_pActFieldDescr->SetPrecision(::std::min<sal_Int32>(sal_Int32(DEFAULT_OTHER_PRECSION),_pType->nPrecision)); - } - } - if(!_pType->aCreateParams.getLength()) - { - m_pActFieldDescr->SetPrecision(_pType->nPrecision); - m_pActFieldDescr->SetScale(_pType->nMinimumScale); - } - if(!_pType->bNullable && m_pActFieldDescr->IsNullable()) - m_pActFieldDescr->SetIsNullable(ColumnValue::NO_NULLS); - if(!_pType->bAutoIncrement && m_pActFieldDescr->IsAutoIncrement()) - m_pActFieldDescr->SetAutoIncrement(sal_False); - m_pActFieldDescr->SetCurrency( _pType->bCurrency ); - m_pActFieldDescr->SetType(_pType); - } + m_pActFieldDescr->FillFromTypeInfo(_pType,_bForce,sal_True); } else { |