View Issue Details

IDProjectCategoryView StatusLast Update
0002434OXID eShop (all versions)4.07. Source code, Testpublic2012-12-10 13:44
Reportertjungcl Assigned To 
PriorityurgentSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version4.4.5 revision 31315 
Fixed in Version4.6.0_beta3 
Summary0002434: oxbase::_insert ignores database-default-values
DescriptionAdd a new column to some table, lets say
"mytest, tinyint(1) not null default '1'" to oxarticles.
Generate Views, then add a new article
=> the default of '1' is ignored, instead the field has the value '0'.

Cause:
An insert-statement is called in oxbase that tries to set mytest = '', what is interpreted by the database as 0(false).

The _getUpdateFieldValue function should respect default-values when generating values for insert-statements!



Additional InformationWorkaround:

extend oxarticle and override:

protected function _getUpdateFieldValue($sFieldName, $oField){
$value = parent::_getUpdateFieldValue($sFieldName, $oField);
if ($sFieldName == 'mytest' and $value == '\'\'') $value = '\'1\'';
return $value;
}
TagsNo tags attached.
ThemeBoth
BrowserAll
PHP Versionany
Database Versionany

Relationships

related to 0001989 resolveddainius.bigelis oxBase::_getUpdateFieldValue() does not respect database default value 

Activities

dominik_ziegler

2011-01-21 17:28

reporter   ~0004007

I have reported that long time ago, does not get fixed until OXID 5 or major system change.

tjungcl

2011-01-24 11:03

reporter   ~0004008

oh, come on ^^

Here you go: Its just one line to add (i even marked it ;) )

protected function _getUpdateFieldValue($sFieldName, $oField)
    {
        $blPassNullValue = false;
        if ($oField instanceof oxField) {
            $value = $oField->getRawValue();
        } else {
            $value = $oField->value;
        }
        // R. check if this field value is null AND it can be null according to table description
        if (null === $value) {
            $aMetaData = $this->_getAllFields();
            foreach ($aMetaData as $oMetaInfo) {
                if (!strcasecmp($oMetaInfo->name, $sFieldName)) {
                    $blPassNullValue = !$oMetaInfo->not_null;
                    if ($oMetaInfo->has_default && !$blPassNullValue) $value = $oMetaInfo->default_value; // <-- ADD THIS LINE
                    break;
                }
            }
        }
        if ($blPassNullValue){
            return 'null';
        } else {
            return oxDb::getDb()->quote( $value );
        }
        
    }

dominik_ziegler

2011-01-24 11:17

reporter   ~0004009

Please also see: https://bugs.oxid-esales.com/view.php?id=1989

dainius.bigelis

2012-03-04 23:59

reporter   ~0005878

Last edited: 2012-03-04 23:59

@Developers: please check the comment with the suggested fix from tjungcl. If fix really would by like changing of few lines of code (and it would solve properly these problems) - would be good to implement that in version 4.6.
If more changes are needed - please describe here in more details why the fix not fits (see also the comments on entry 0001989).

Linas Kukulskis

2012-03-20 17:00

reporter   ~0006047

added fix to get default values