473,395 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2271
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dariusz | last post by:
I have a small form that on button press submits to a PHP file for further processing into a database. I have to change the script as it allows blank / nothing to be submitted to the database. ...
7
by: - ions | last post by:
I have created a JComboBox with its Items as a list of "M" numbers ie. M1,M2,M3.......throgh too M110 (thes are the messier objects, a catolouge of deep sky objects) the user selects of of these...
4
by: Tom Esker | last post by:
I've got Javascript in a form that adds up all of the numbers in a column of form fields and displays a total. It works great if every field has an initial value of 0, but if any of them are null,...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
2
by: Chris | last post by:
Hi, I have an SQL Query that loads a SQLDataReader object. The returned record has bit datatype columns that I use to provide true/false values. I can't get a definite answer googling on...
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
2
by: fperri | last post by:
Hi, I have a table with over 20 columns. Seven of these of these columns correspond to a filter on a search form. Based on what is selected on the search form, and what is in these seven fields in...
7
by: nospam | last post by:
Hello I need to go through each line of a CSV file, and extract some fields using a regex. Then, I need to check each retrieved field, and if it looks like "", turn this into NULL so that it's...
4
by: barmatt80 | last post by:
I have created an unbound form so that when users enter the information, there is a save button they have to click, checking to make sure a field(txtDocketNo) is not blank. For some reason I cannot...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.