Tag: cws_src680_dba205b User: fs Date: 2006/08/15 06:45:26 Modified: dba/connectivity/source/commontools/TTableHelper.cxx
Log: lcl_sanitizeColumnDescs: also allow for ordinal positions ranging from 0 to <column_count>-1 (MySQL) File Changes: Directory: /dba/connectivity/source/commontools/ ================================================ File [changed]: TTableHelper.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/commontools/TTableHelper.cxx?r1=1.5.18.1&r2=1.5.18.2 Delta lines: +32 -26 --------------------- --- TTableHelper.cxx 9 Aug 2006 20:00:56 -0000 1.5.18.1 +++ TTableHelper.cxx 15 Aug 2006 13:45:23 -0000 1.5.18.2 @@ -4,9 +4,9 @@ * * $RCSfile: TTableHelper.cxx,v $ * - * $Revision: 1.5.18.1 $ + * $Revision: 1.5.18.2 $ * - * last change: $Author: fs $ $Date: 2006/08/09 20:00:56 $ + * last change: $Author: fs $ $Date: 2006/08/15 13:45:23 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -174,39 +174,45 @@ */ void lcl_sanitizeColumnDescs( ::std::vector< ColumnDesc >& _rColumns ) { + if ( _rColumns.empty() ) + return; + + // collect all used ordinals ::std::set< OrdinalPosition > aUsedOrdinals; - bool bDuplicates = false; - bool bTooSmall = false; - bool bTooLarge = false; - size_t nColumnCount( _rColumns.size() ); - for ( ::std::vector< ColumnDesc >::const_iterator check = _rColumns.begin(); - ( check != _rColumns.end() ) && !bDuplicates && !bTooSmall && !bTooLarge; - ++check + for ( ::std::vector< ColumnDesc >::iterator collect = _rColumns.begin(); + collect != _rColumns.end(); + ++collect ) - { - if ( aUsedOrdinals.find( check->nOrdinalPosition ) != aUsedOrdinals.end() ) - bDuplicates = true; - else if ( check->nOrdinalPosition < 1 ) - bTooSmall = true; - else if ( check->nOrdinalPosition > (OrdinalPosition)nColumnCount ) - bTooLarge = true; - else - aUsedOrdinals.insert( check->nOrdinalPosition ); - } + aUsedOrdinals.insert( collect->nOrdinalPosition ); + + // we need to have as much different ordinals as we have different columns + bool bDuplicates = aUsedOrdinals.size() != _rColumns.size(); + // and it needs to be a continuous range + size_t nOrdinalsRange = *aUsedOrdinals.rbegin() - *aUsedOrdinals.begin() + 1; + bool bGaps = nOrdinalsRange != _rColumns.size(); - if ( bDuplicates || bTooSmall || bTooLarge ) + // if that's not the case, normalize it + if ( bGaps || bDuplicates ) { OSL_ENSURE( false, "lcl_sanitizeColumnDescs: database did provide invalid ORDINAL_POSITION values!" ); OrdinalPosition nNormalizedPosition = 1; - for ( ::std::vector< ColumnDesc >::iterator reset = _rColumns.begin(); - reset != _rColumns.end(); - ++reset, ++nNormalizedPosition + for ( ::std::vector< ColumnDesc >::iterator normalize = _rColumns.begin(); + normalize != _rColumns.end(); + ++normalize ) - { - reset->nOrdinalPosition = nNormalizedPosition; - } + normalize->nOrdinalPosition = nNormalizedPosition++; + return; } + + // what's left is that the range might not be from 1 to <column count>, but for instance + // 0 to <column count>-1. + size_t nOffset = *aUsedOrdinals.begin() - 1; + for ( ::std::vector< ColumnDesc >::iterator offset = _rColumns.begin(); + offset != _rColumns.end(); + ++offset + ) + offset->nOrdinalPosition -= nOffset; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
