Checking a field for NULL
am 13.02.2006 21:05:26 von subaruwrx88011
So I pressed tab-enter and posted an incomplete topic, sorry.
I have imported information into a database using a file. It is tab
delimited and for NULL fields I have NULL.
example file.txt
1Hello WorldNULL5.56
1) Is this a correct way to make sure that this field will be NULL
2) in C++ after I fetch the field can I say
if( != NULL)
Thanks in advance
Re: Checking a field for NULL
am 13.02.2006 22:40:04 von Thomas Bartkus
wrote in message
news:1139861126.665703.217110@o13g2000cwo.googlegroups.com.. .
> So I pressed tab-enter and posted an incomplete topic, sorry.
>
> I have imported information into a database using a file. It is tab
> delimited and for NULL fields I have NULL.
>
> example file.txt
> 1Hello WorldNULL5.56
>
> 1) Is this a correct way to make sure that this field will be NULL
Yes!
NULL is a keyword in MySQL to be interpreted as Null.
Although 2 successive tabs in a tab delimited text import denotes
a Null , it never hurts to be explicit. Both "" and
"NULL will cause a Null value between the tabs. If you can
arrange to get an explicit "NULL" between the tabs - go for it. Do note,
however, that MySQL doesn't care one way or the other. It just makes it
easier for a human being to troubleshoot.
> 2) in C++ after I fetch the field can I say
> if( != NULL)
You could also test it in your SQL using ISNULL() before it hits your C++.
Why not explicitly test for Null in your SQL?
IsNull(field) will return 1 (True) if the field value is Null or 0 (False)
if it contains a valid value.
You can also use an SQL IF():
IF(IsNull(, {What to show in case of Null}, {What to show if the
field is valid})
You could do:
IF(NOT IsNull(, ....
but my brain has trouble wrapping around the double negative - even if MySQL
has no problem with it.
You can also use:
IFNULL(, {Whatever it is you want to see if the field turns out to
be Null})
That will put forth the normal value of if it *has* a normal value,
or if it is Null you will get whatever else it is you want to specifiy in
that situation.
In general - I would do as much field testing as possible up front in SQL
code.
It's just the kind of thing MySQL does best.
Thomas Bartkus
Re: Checking a field for NULL
am 15.02.2006 20:06:51 von Thomas Bartkus
"subaruwrx88011" wrote in message
news:1139867039.227753.281400@z14g2000cwz.googlegroups.com.. .
> Ya that would be nice but we are trying to limit the calls to MySQL.
> After i do a query I fetch a row and store it into a local structure to
> limit calls to the database. The place the field value is set to is a
> char*. So if it is NULL in the database shouldn't this char* also be
> NULL.
I neither know (nor care!) why you might want to limit the calls to MySQL
But
There is nothing in what I suggested that would increase the database
traffic.
Post processing for Nulls does nothing to limit calls to the database and
frankly -
- it would seem to be silly waste of coding effort.
Thomas Bartkus
Re: Checking a field for NULL
am 15.02.2006 20:49:15 von Thomas Bartkus
"subaruwrx88011" wrote in message
news:1139867039.227753.281400@z14g2000cwz.googlegroups.com.. .
> Ya that would be nice but we are trying to limit the calls to MySQL.
> After i do a query I fetch a row and store it into a local structure to
> limit calls to the database. The place the field value is set to is a
> char*. So if it is NULL in the database shouldn't this char* also be
> NULL.
I neither know (nor care!) why you might want to limit the calls to MySQL
But
There is nothing in what I suggested that would increase the database
traffic. Post processing for Nulls does nothing to limit calls to the
database and
frankly -
- it would seem to be silly waste of coding effort.
Thomas Bartkus