469,632 Members | 1,600 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

Checking a field for NULL

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
1<tab>Hello World<tab>NULL<tab>5.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(<field> != NULL)

Thanks in advance

Feb 13 '06 #1
4 2090
<su************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.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
1<tab>Hello World<tab>NULL<tab>5.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 <tab><tab> in a tab delimited text import denotes
a Null , it never hurts to be explicit. Both "<tab><tab>" and
"<tab>NULL<tab> 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(<field> != 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(<field>, {What to show in case of Null}, {What to show if the
field is valid})

You could do:
IF(NOT IsNull(<fiield>, ....
but my brain has trouble wrapping around the double negative - even if MySQL
has no problem with it.

You can also use:
IFNULL(<field>, {Whatever it is you want to see if the field turns out to
be Null})
That will put forth the normal value of <field> 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
Feb 13 '06 #2
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.

Feb 13 '06 #3
"subaruwrx88011" <su************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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
Feb 15 '06 #4
"subaruwrx88011" <su************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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
Feb 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by - ions | last post: by
4 posts views Thread by Tom Esker | last post: by
99 posts views Thread by Mikhail Teterin | last post: by
4 posts views Thread by Patient Guy | last post: by
7 posts views Thread by nospam | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.