Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Default values for validation

Quote Reply
Default values for validation
Hi. I've been trying to modify some data with fields that are DECIMAL (12,2) and NOT NULL. However, if these are left blank, they automatically have a value of 0.00. Is there a way to leave these fields blank? I've set them to NOT NULL and they always seem to be given a value.

Thanks,

Kevin
Quote Reply
Re: Default values for validation In reply to
The reason they are set to 0.00 is that you
have set them as "Not Null" that means they
MUST contain a value, and it can't be Null.

The logical default value is 0.00 (or nothing, the closest equivalent for Null).

You can set the default value to be -1 if you want, then test for it... if it's less than 0 it's 'null' if it's 0 or greater, it's a real value.

The other option is to allow the field to be
null -- if some values are blank then Null
should be an allowed value anyway.

------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/









[This message has been edited by pugdog (edited December 19, 1999).]
Quote Reply
Re: Default values for validation In reply to
Whoops! I meant to say that they were set to NULL and are still given values when using DBSQL.pm - $db->modify_record ($links);

I guess I will have to use straight SQL.

Thanks
Quote Reply
Re: Default values for validation In reply to
I think it's the same problem...

But I don't know how to get around that. Alex will probably have to address that. You might have to do a check before the modify command to reset it to null.

Because of the way the .def files are used to make database access faster, some oddities like this are introduced. I think that's what is happening. There's no value, so the "zero" value is chose, rather than null.



[This message has been edited by pugdog (edited December 19, 1999).]
Quote Reply
Re: Default values for validation In reply to
When creating the table, did you define the field NOT NULL (i.e. in the create table SQL)?

If so, then you can't insert a NULL value into the table, mysql won't let you. It will instead insert 0.00. You'll need to recreate the table without the NOT NULL statement to do what you want.

Cheers,

Alex
Quote Reply
Re: Default values for validation In reply to
You can also ALTER the table to make that field NOT NULL. You don't have to recreate or drop it.
Quote Reply
Re: Default values for validation In reply to
All the fields were NULL, but when modifying the records, it puts in values. Adding does not. I am using dbsql.pm

I think it has something to do with the sub modify_record in DBSQL.pm . Everything up until it is gone through DBSQL.pm returns a null value if null but when modifying the actual database, it puts in 0.00 .

Thanks Alex and pugdog.

Kevin
Quote Reply
Re: Default values for validation In reply to
Hello Alex!

Quote:
You'll need to recreate the table without the NOT NULL statement to do what you want.

I have done many times a change in the property fields like NULL to NOT NULL or UNIQUE KEY to None or PRIMARY KEY to None etc with phpMyAdmin utility from www.phpwizard.net!

It is for sure not necessary to recreate the table. One can simply change the property of the field with the help of this utility and later edit defs values from '1' to '0'!!!
Quote Reply
Re: Default values for validation In reply to
Type 'DESCRIBE TableName' into the SQL monitor to see if Mysql thinks the field should be not null, this is the only thing I can think of.

Cheers,

Alex