<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