473,699 Members | 2,181 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 2299
<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 (to a database). If I deliberately leave the fields blank and submit the form, querying the...
7
7580
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 what the user has entered is valid, that being an M followed by 1 - 110 Nothing else, i thought of...
4
11784
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 iteration of the "for" loop, but it doesn't work. Can anyone tell me what I'm doing wrong? Below is the...
99
5150
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
2
3403
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
2381
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
1427
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 might only use the first two and the other five will be null, or one might use the middle three and...
7
1826
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
2750
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 statement. I keep getting an error on the .Update line. Error is: Index or primary key cannot be null. ...
0
8706
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8631
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7787
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4392
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4641
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.