• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

mysql null

this is my code:

                MYSQL *conn;
      MYSQL_RES *res;
      MYSQL_ROW  row;
      
      query = query1 + me->id;

      conn = mysql_init(NULL);
      mysql_real_connect(conn, "", "", "", "", 0, NULL, 0);
      mysql_query(conn, query.c_str());
      res = mysql_store_result(conn);
      
      while(row = mysql_fetch_row(res))
      {
            user.id = row[0];
            user.name = "";
            user.session = "";
            user.socket = -1;
            user.sequence = row[1];
            me->q.push_back(user);
      }

I want to check if row[1] is a mysql null, how do I do that?
0
Buffon
Asked:
Buffon
  • 2
1 Solution
 
Jaime OlivaresCommented:
just have to check if empty:

if (!strlen(row[1])) {
   // it is empty or null
}
0
 
BuffonAuthor Commented:
and what if I want to distinguish between empty and null?
0
 
Jaime OlivaresCommented:
According with MySql documentation:
http://sunsite.mff.cuni.cz/MIRRORS/ftp.mysql.com/doc/en/mysql_fetch_row.html
null values are returned as null pointers, so this will be different to my first code:

if (row[1]==NULL) {
   // it is null
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now