Database Manager and Decimal fields

This is driving me crazy and has effectively stopped me working

How do i use decimal fields with the new database manager?

No type of decimal field is available in the picker

If i set them externally via navicat

image

then type appears blank in the properties

and I get weird errors in server actions when updating

{“code”:“22007”,“file”:“C:\woodburn\woodburnrenewables.co.uk\public_html\dmxConnectLib\lib\db\Connection.php”,“line”:114,“message”:“SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect decimal value: ‘’ for column woodburnrenewables.models.output_min at row 1”,“trace”:"#0 C:\woodburn\woodburnrenewables.co.uk\public_html\dmxConnectLib\lib\db\Connection.php(114): PDOStatement->execute()\n#1 C:\woodburn\woodburnrenewables.co.uk\public_html\dmxConnectLib\modules\dbupdater.php(68): lib\db\Connection->execute(‘UPDATE models…’, Array)\n#2 C:\woodburn\woodburnrenewables.co.uk\public_html\dmxConnectLib\lib\App.php(173): modules\dbupdater->update(Object(stdClass), ‘update_model_by…’)\n#3 C:\woodburn\woodburnrenewables.co.uk\public_html\dmxConnectLib\lib\App.php(137): lib\App->execSteps(Object(stdClass))\n#4 C:\woodburn\woodburnrenewables.co.uk\public_html\dmxConnectLib\lib\App.php(107): lib\App->execSteps(Array)\n#5 C:\woodburn\woodburnrenewables.co.uk\public_html\dmxConnectLib\lib\App.php(72): lib\App->exec(Object(stdClass))\n#6 C:\woodburn\woodburnrenewables.co.uk\public_html\dmxConnect\api\admin\save_model.php(8): lib\App->define(Object(stdClass))\n#7 {main}"}

There is no datetime fields in the table

Decimal is not available in the “Basic” mode of the database manager.
Switch to Advanced mode and you will see the “Advanced” db field types:

Thanks @Teodor, completely missed that, so many changes!

1 Like

We implemented this in some of the previous beta versions.
Seems like some of the more advanced field types confuse a lot of new/inexperienced users, so we only show the most basic ones in the Basic mode.

Still having issues re this error above with database update

the form field
image

the database field
image

the action

1 Like

What was the value posted with output_min, looks like an empty string?

Yes, it would appear that if any numeric field is left blank then an error occurs. Nuls allowed in all table fields

An empty string is not the same as null. Try adding the default formatter {{$_POST.output_min.default(null)}}.

Yes, i appreciate that but i have done this literally hundreds of items and never had to do that. Is there a reason? Am i going to have to add a default to every numeric field in future or more worrying add them to existing sites if I update them?

i also have defaults set at DB level

The form submits an empty string, in the database you have a default set and allow null. What exactly do you expect that it inserts? The default that is set in the database is used when the value was not supplied with the insert or when the DEFAULT keyword is used. When the value is null then null will be inserted in the database. Empty string is not valid for the decimal field, but would be a valid value for a text field. Should it then insert an empty string when there is also a default set in the database? We can’t know this and require you to tell the app what it should do.

I think there is some confusion here @patrick.
When the form is submitted with a numeric field left blank I expect it to either insert Null or the database default depending on the settings which is what has always happened in the past. Now if I I leave numeric form field blank I get an error message. I would never expect an empty string, this thread is about decimal fields

Brian,
An empty form input always sends an empty string on submit. It's always been like that.
Check what the HTML spec defines: HTML Standard

The value attribute, if specified and not empty, must have a value that is a valid floating-point number. The value sanitization algorithm is as follows: If the value of the element is not a valid floating-point number, then set it to the empty string instead.

Yes we can’t just make nulls from any empty string… and what if you want to save an empty string?

Yes i know that.

So what you are saying is that if you have a form input of the type Number and that field is left blank then a database update server action will return an error unless a default is set in the data base update query?

All i want is for there to be no error if a number field in a form is left empty. I could do that until recently. Tomorrow i will make a video to show you exactly what my issue is but at the moment a bottle of red wine takes priority

:+1:

1 Like

Hi Brian,
We understand what your issue is and Patrick already explained how and why it works like that.

The server action receives an empty string from the form and we don't know what do you (or other users) want to do with it - if you want null to be inserted then use the default formatter with a null value.

It's your database which returns an error because it's not allowed to insert empty strings in decimal field type in MySQL.
So yes, you need to use the default formatter if you expect empty strings to be sent to such fields and that's why this formatter exists.

Maybe you want to use the condition option in your insert step for these form fields so their values are only sent to the db when a value is actually entered.
This way the default set in your DB settings will be used on insert.

We found out that the database was in strict mode, that’s why it throws an error on an empty string. When the database is not in strict mode it would convert and empty string to 0 and no error will occur. So fact is that the database handles values different depending on which mode it is running in.

2 Likes