List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:March 17 2008 5:18am
Subject:Re: Problem Handling Null Values
View as plain text  
Dustin Moore wrote:
> 	mysqlpp::Null<int, mysqlpp::NullisNull> nullIntField = mysqlpp::null;
> 	if (result.at(0)["Unit_id"] != nullIntField) {
> 		// do something with int value
> 	}

1. I don't see the purpose of nullIntField.  You should be able to 
compare any Null<T> to mysqlpp::null directly.

2. There's no need to give NullIsNull as the second argument to Null<T>. 
  It's already the default.

3. Since you're spelling "NullisNull" with a lowercase 'i', either 
you're using MySQL++ 2.x, which doesn't have the SQL null improvements 
in v3, or you haven't read the breakages chapter in the user manual.

4. result.at(0) further argues that this is MySQL++ 2.3 we're talking 
about, so one then wonders why you haven't tried upgrading to v3, which 
allows the much nicer subscripting syntax, even with the zeroth index.

Taken together, the code for v3 should read:

> On compile I receive:
> 	error: ambiguous overload for ‘operator!=’ in
> ‘mysqlpp::Row::operator[](const char*) const(((const char*)"Unit_id")) !
> = nullIntField’
> 	note: candidates are: operator!=(int, int) <built-in>
> 	note:                 operator!=(unsigned int, int) <built-in>
> 	note:                 operator!=(long int, int) <built-in>
> 	note:                 operator!=(long unsigned int, int) <built-in>
> 	note:                 operator!=(mysqlpp::longlong, int) <built-in>
> 	note:                 operator!=(mysqlpp::ulonglong, int) <built-in>
> 	note:                 operator!=(float, int) <built-in>
> 	note:                 operator!=(double, int) <built-in>
> 
> If I type cast "result.at(0)["Unit_id"]" to int then I get run time
> errors about convert Null to int.  How do I clear the ambiguity?
> 
> Also, if there is no fixing my code, what is a good simple example of
> handling nulls?
> 
> Thanks,
> Dustin Moore
> me@stripped
> 
> 

Thread
Problem Handling Null ValuesDustin Moore17 Mar
  • Re: Problem Handling Null ValuesWarren Young17 Mar
  • Re: Problem Handling Null ValuesWarren Young17 Mar
    • Re: Problem Handling Null ValuesDustin Moore18 Mar
      • Re: Problem Handling Null ValuesWarren Young18 Mar
        • Re: Problem Handling Null ValuesDustin Moore19 Mar
          • Re: Problem Handling Null ValuesWarren Young19 Mar