List:MySQL++« Previous MessageNext Message »
From:Joseph Hesse Date:September 20 2010 7:46pm
Subject:Need help with NULL
View as plain text  
  Hi,

I would appreciate help on testing if a query returns a MySQL NULL.
I am having trouble understanding the MySQL++ documentation on NULL.
Any pointers to code fragments would be much appreciated.

Here is the structure of my table.
=============================================================
mysql> describe Test;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Name  | varchar(40) | YES  |     | NULL    |       |
| Age   | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
=============================================================

Here is a fragment of my code.
How can I test if res[i]["Age"] is a MySQL NULL in the code below?
=============================================================
   // correct code appears before this line

   // create query object
   Query query = conn.query();
   query << "SELECT * FROM Test";
   StoreQueryResult res = query.store();

   for (size_t i = 0; i < res.num_rows(); ++i)
   {
     cout << "Name = " << res[i]["Name"] << endl;
     cout << "Age = " << res[i]["Age"] << endl;

    // How can I test if res[i]["Age"] is NULL <== NEED HELP HERE
   }

   // more code
=============================================================

Thank you,
Joe
Thread
Need help with NULLJoseph Hesse20 Sep
  • Re: Need help with NULLWarren Young22 Sep