I have an integer value. It can be NULL (actually NULL is the default value).
When I set it to some value in the edit form, save it, and then want to clean this field it doesn't allow me to do so with the following error:
===PDO MESSAGE===
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'reg_payment' at row 1
===SQL===========
UPDATE registration SET `reg_payment` = '' WHERE `reg_id` = '10';
How may I change the value of reg_payment field that I send to DB from empty string to NULL if it's empty?
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
How to pass NULL to SQL query
Re: How to pass NULL to SQL query
Hi potap,
Try
UPDATE registration SET `reg_payment` = NULL WHERE `reg_id` = '10';
Steven
Try
UPDATE registration SET `reg_payment` = NULL WHERE `reg_id` = '10';
Steven
A short post is a good post.
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: How to pass NULL to SQL query
Presently, only date types are nulled out when a field is cleared and saved. Actually, this should also apply to numeric fields.
Here's an updated nudata.php : Please test it and let me know if it works as expected.
Here's an updated nudata.php : Please test it and let me know if it works as expected.
You do not have the required permissions to view the files attached to this post.
Re: How to pass NULL to SQL query
BTW, an idea for future is to put the array of NULLable types to the settings. For example I needed this functionality for INT type only, but not tinyint (I use it as boolean without nulls). I corrected nullableTypes array in nudata.php, it was pretty easy, thanks to Kevin. But as an idea for future it may be part of settings.
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: How to pass NULL to SQL query
This makes perfect sense to me. The following types are now set to NULL when the nuBuilder's object value is blank.potap wrote: ↑Thu Dec 22, 2022 8:13 pm BTW, an idea for future is to put the array of NULLable types to the settings. For example I needed this functionality for INT type only, but not tinyint (I use it as boolean without nulls). I corrected nullableTypes array in nudata.php, it was pretty easy, thanks to Kevin. But as an idea for future it may be part of settings.
Define an array $nuConfigDBTypesSetNullWhenEmpty in nuconfig.php to overwrite the default.
Code: Select all
$nuConfigDBTypesSetNullWhenEmpty = [
"integer",
"int",
"mediumint",
"longint",
"decimal",
"float",
"real",
"double",
"serial",
"date",
"datetime",
"timestamp",
"year",
];