473,574 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2294
<su************ @gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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(<fiel d>, {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.goo glegroups.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.goo glegroups.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
1953
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. The intention is that if any of the two form fields are blank (empty) then the page is resent stating that they have to fill in all the fields to post...
7
7565
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 and views it aswell as infomation. The program also has a JTextFiels which allows the user to enter the M number. The problem i have is checking that...
4
11774
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, "NaN" displays as the total. I tried to add a test for a null value with the intent to skip adding that field to the accumulator for one...
99
5077
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
2
3400
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 how to test if this field is null. I get casting errors, and can't check for null on a null data value errors
4
2367
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 exceptions?
2
1426
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 the table, it indicates whether or not I pull the record. Thing is....is that not all the records use the same combination of these seven fields. One...
7
1822
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 correct SQL. I tried a few things, but still can't it working: ======== #Second field might be empty -"" #"Col1",""
4
2744
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 get it to work. I want the data to save if that field is not blank and if it is blank just close. I think it is a conflicting with my WITH...
0
7832
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7747
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8093
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7843
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8129
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6498
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5331
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.