Hi,
my database table has a column "size" of type integer (nullable).
When I save into this table from chronoforms and the optional field "size" is filled with an integer, everything works fine. If the field "size" is left blank, the database won't accept the empty string for this column. To handle this, I added a PHP action before the save_data:
if (empty($this->data['size'])) {
$this->data['size'] = null;
}
In the debugger, I can see the result, as in the data-Array: [size] => NULL
But the SQL-Update is nevertheless using an empty string instead of the NULL-Value:
[sql] => UPDATE `product` SET `product` = 'Test Product', `size` = '', `price` = '1.00' WHERE product_id='427090'
How can I handle it to write Null-Values to the DB under some conditions?
to save null you need to unset this field from the data array:
if (empty($this->data['size'])) {
unset($this->data['size']);
}
Hi Max,
thank you for your very quick reply. I might be wrong, but I think with unsetting the field I cannot update the database field to be null?
In case the 'size' in the db has the value 4 and I delete this value in the form field. When I unset the {data:size}, then the database won't be updated with null?
you are correct, this is a bug, but I have fixed it for the next update.
When do you need a working patch ?