xoops forums

luciorota

Module Developer
Posted on: 12/12 15:43
luciorota
luciorota (Show more)
Module Developer
Posts: 186
Since: 2007/4/20
#1

Database: How do I set a column value to NULL

I have a question.

I have to set a database column value to NULL but ...
My object is an extension of XoopsPersistableObject class.
Var 'date' data type is XOBJ_DTYPE_DATE
Database field is defines as
date DATE NULL DEFAULT NULL

Any suggestion?

Mamba

Moderator
Posted on: 12/14 5:05
Mamba
Mamba (Show more)
Moderator
Posts: 10652
Since: 2004/4/23
#2

Re: Database: How do I set a column value to NULL

In NewBB's table "newbb_stats" you have:
`time_update`  DATE                          DEFAULT NULL,


Is this what you were looking for?
Support XOOPS => DONATE
Use 2.5.9 | Docs | Modules | Bugs

luciorota

Module Developer
Posted on: 12/14 22:15
luciorota
luciorota (Show more)
Module Developer
Posts: 186
Since: 2007/4/20
#3

Re: Database: How do I set a column value to NULL

Thanks Mamba
I would like to reset time_update value to NULL
When i use an expression like this:

$itemObj->setVar('myDate'NULL);


does note set 'MyDate' field to NULL but to '0000-00-00'
are there some tips to solve my question?

Thanks again

Mamba

Moderator
Posted on: 12/15 2:44
Mamba
Mamba (Show more)
Moderator
Posts: 10652
Since: 2004/4/23
#4

Re: Database: How do I set a column value to NULL

Are you testing it on Windows? Maybe you need to turn off the "STRICT_MODE" in the MySQL configuration
You might also use "datetime" instead of "date"
See:
https://stackoverflow.com/questions/16 ... -datetime-fields-in-mysql
Support XOOPS => DONATE
Use 2.5.9 | Docs | Modules | Bugs

luciorota

Module Developer
Posted on: 12/15 11:37
luciorota
luciorota (Show more)
Module Developer
Posts: 186
Since: 2007/4/20
#5

Re: Database: How do I set a column value to NULL

Hi Mamba
Everything checked

I think it is a Xoops limit...

geekwright

Quite a regular
Posted on: 12/16 17:54
geekwright
geekwright (Show more)
Quite a regular
Posts: 253
Since: 2010/10/15
#6

Re: Database: How do I set a column value to NULL

Quote:
luciorota wrote:
...
I think it is a Xoops limit...

Sadly, you are correct.

I did a dive into the code when I saw your question, and the XoopsObject family seems to have no direct support for NULLs. Updating a column to NULL presently would require building the update query manually and running it with the database query() method.

Likewise the handling of a NULL value in selects seems to be datatype dependent, more like a side effect.