slimdump
slimdump copied to clipboard
replace NULL fields with value does not work
I am exporting a user which has a NULL value within a DATE field.
I added this to my config:
<column name="fieldnamexy" dump="replace" replacement="2017-03-18" />
And it just stays NULL in export. When exporting another user (with filled fieldnamexy) everything works as expected.
Might be because first if statement in Table::getStringForInsertStatement :thinking:
Quick workaround:
public function getStringForInsertStatement($columnName, $value, $isBlobColumn, Connection $db)
{
$column = $this->findColumn($columnName);
$replacementColumn = false;
if ($column && $column->dump === Config::REPLACE) {
$replacementColumn = true;
}
if ($value === null && !$replacementColumn) {
return 'NULL';
} else if ($value === '') {
return '""';
} else {
if ($column = $this->findColumn($columnName)) {
return $db->quote($column->processRowValue($value));
}
if ($isBlobColumn) {
return $value;
}
return $db->quote($value);
}
}
Yes, that method seems to be the culprit.
The problem is that ''
and null
get special handling without ever looking at what is configured for that column.
Do you think we can find a way to push the value for processing into processRowValue
no matter what? Of course, when there is no Column
explicitly configured, we'd need to have a fallback (default) column type.
To me it seems that the fact that we also need to quote the value under certain conditions (not for NULL
and for blobs) is getting in our way here.
Also, the fact that Table
is aware of the Connection
only for quoting indicates that we need to shift responsibilities between classes a little.
Do you have any idea how we could improve this?
@franziskahahn i see this as a feature currently ... null values should stay null
@mpdude maybe this can be setup with an extra param, so that the current behaviour stays as it is. and @franziskahahn can have a valid export.