View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002434 | OXID eShop (all versions) | 4.07. Source code, Test | public | 2011-01-21 17:12 | 2012-12-10 13:44 |
Reporter | tjungcl | Assigned To | |||
Priority | urgent | Severity | major | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | 4.4.5 revision 31315 | ||||
Fixed in Version | 4.6.0_beta3 | ||||
Summary | 0002434: oxbase::_insert ignores database-default-values | ||||
Description | Add 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 Information | Workaround: extend oxarticle and override: protected function _getUpdateFieldValue($sFieldName, $oField){ $value = parent::_getUpdateFieldValue($sFieldName, $oField); if ($sFieldName == 'mytest' and $value == '\'\'') $value = '\'1\''; return $value; } | ||||
Tags | No tags attached. | ||||
Theme | Both | ||||
Browser | All | ||||
PHP Version | any | ||||
Database Version | any | ||||
related to | 0001989 | resolved | dainius.bigelis | oxBase::_getUpdateFieldValue() does not respect database default value |
|
I have reported that long time ago, does not get fixed until OXID 5 or major system change. |
|
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 ); } } |
|
Please also see: https://bugs.oxid-esales.com/view.php?id=1989 |
|
@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). |
|
added fix to get default values |