diff --git a/datamodels/2.x/combodo-db-tools/db_analyzer.class.inc.php b/datamodels/2.x/combodo-db-tools/db_analyzer.class.inc.php index 849899f8b..9f545adc3 100644 --- a/datamodels/2.x/combodo-db-tools/db_analyzer.class.inc.php +++ b/datamodels/2.x/combodo-db-tools/db_analyzer.class.inc.php @@ -462,6 +462,11 @@ class DatabaseAnalyzer $aCols = $oAttDef->GetSQLExpressions(); // Workaround a PHP bug: sometimes issuing a Notice if invoking current(somefunc()) $sMyAttributeField = current($aCols); // get the first column for the moment $sFilter = "FROM `$sTable` WHERE `$sTable`.`$sMyAttributeField` NOT IN ($sExpectedValues)"; + if ($oAttDef->IsNullAllowed()) { + $sSearchType = $oAttDef->GetSearchType(); + $sCondition = $this->NotEmptyToSql("`$sTable`.`$sMyAttributeField`", $sSearchType); + $sFilter .= " AND $sCondition"; + } $sDelete = "DELETE `$sTable`"; $sSelect = "SELECT DISTINCT `$sTable`.`$sKeyField` AS id, `$sTable`.`$sMyAttributeField` AS value"; $sSelWrongRecs = "$sSelect $sFilter"; @@ -492,6 +497,19 @@ class DatabaseAnalyzer } } + private function NotEmptyToSql($sRef, $sSearchType) + { + switch ($sSearchType) { + case AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC: + case AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_FIELD: + case AttributeDefinition::SEARCH_WIDGET_TYPE_DATE: + case AttributeDefinition::SEARCH_WIDGET_TYPE_DATE_TIME: + return "ISNULL({$sRef}) = 0"; + } + + return "({$sRef} != '')"; + } + /** * Check user accounts without profile *