Page 1 of 1

How to nullify empty strings before inserting to database

Posted: Wed Jul 08, 2020 8:44 am
by dzikipsiur
First of all I would like to say hello to everyone on this board as it is my first post.
I have got no background in coding and have got basic knowledge on databases but using nuBuilder I am able to set up frontend the way it is working as I designed it to.
It is a fantastic building environment and would like to say big thank you to the makers.
So far I have managed to do all I wanted just by reading tutorials or posts on this forum until now.
Because I would like to use MySQL CONCAT_WS function to skip NULL values while creating VIEWS for nuBuilder Reports fetching all necessary data from, I have got to the point I simply do not know how to manage my little problem to step further.
I would like to know how to change and where to change nuBuilder PHP procedure globally so instead of an empty string it would insert or update record column with NULL allways and everywhere.
I have seen a post regarding doing so for the DATE data type, but mostly what I want to do it for are text input fields.
I would like to kindly ask to point me in the right direction. I know that there can be triggers created in MySQL engine or NULLIF or conditionals put into use on the MySQL sever side but I would like it to be simply changed at the data source.
Any help appreciated.

Re: How to nullify empty strings before inserting to databas

Posted: Wed Jul 08, 2020 9:47 am
by kev1n
Hi,

You could simply modify my fix that sets null for dates and make it more generic to set a NULL value regardless of the column type.

Replace

Code: Select all

if (in_array($type, array('date','datetime','timestamp','year')) && $v == '') {
With

Code: Select all

if ($v == '') {
https://github.com/smalos/nuBuilder4-Bu ... e_types.md

Re: How to nullify empty strings before inserting to databas

Posted: Wed Jul 08, 2020 10:30 am
by dzikipsiur
Hi kev1n ,

That worked absolutely the way I imagined it. Amazing!
Thank you very much.