dbTalk Databases Forums  

NULL field comparison

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss NULL field comparison in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Orton, Steve
 
Posts: n/a

Default NULL field comparison - 04-07-2006 , 12:22 PM







Hello,
I'm fairly new to mysql and I have a question about finding out if a =
particular field is NULL for type int and varchar. Using the quick =
example in the "User's Guide", I tried comparing the contents returned =
by row.at to the Null object and to mysqpp::null and get a "using =3D=3D =
produces an ambiguous comparison" or something to that effect for both.

I tried this:

mysqlpp::Null<int, mysqlpp:NulIsZero> myfield
myfield =3D mysqlpp::null;
if (_row.at(0) =3D=3D myfield)
retVal =3D 0;
else
retVal =3D -999;

Which produces the following compile error:
=20
"ambiguous overload for=20
'const mysqlpp:ColData =3D=3D mysqlpp::Null<int, =
mysqlpp::NullIsZero>&' operator"

I then tried this:
=20
if (_row.at(0) =3D=3D mysqlpp::null)
retVal =3D 0;
else
retVal =3D -999;

which produces:

"no match for 'const mysqlpp::ColData =3D=3D const =
mysqlpp::null_type&' operator"

Section 3.8 of the "User's Guide" doesn't go into any more detail and =
I could not find any examples on this type of NULL usage. It's probably =
simple, but I can't see it.

Any insight on this would be greatly appreciated...steve---

=20
Steven J Orton
Software Engineer
Northrop Grumman Mission Systems
[email] steve.orton (AT) ngc (DOT) com



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsub=3Dmysql-plusplus (AT) freebsd (DOT) csie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Warren Young
 
Posts: n/a

Default Re: NULL field comparison - 04-07-2006 , 04:39 PM






Orton, Steve wrote:
Quote:
Which produces the following compile error:

"ambiguous overload for
'const mysqlpp:ColData == mysqlpp::Null<int, mysqlpp::NullIsZero>&' operator"
Did the compiler not tell you what the alternatives were that it was
forced to choose from? That would help me to understand where the
ambiguity is. As far as I can see, there's only one conversion path:
there's a template operator Null<T, B> in coldata.h which should be able
to convert ColData objects to Null-wrapped ColData objects.

One sticky point I see is that there is no operator== for the Null
template. Maybe the compiler wants to see one?

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Orton, Steve
 
Posts: n/a

Default RE: NULL field comparison - 04-10-2006 , 09:21 AM



------_=_NextPart_001_01C65CAA.0A074D43
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Sorry for the delay...the weekend got my attention

I wanted to keep the first post simple, so I purposely left the rest of =
the compile error out.
Here's the full output from the compile.

"ambiguous overload for
'const mysqlpp:ColData =3D=3D mysqlpp::Null<int, =
mysqlpp::NullIsZero>&' operator"
candidates are: operator=3D=3D(int, int) <built-in>
operator=3D=3D(double, int) <built-in>
operator=3D=3D(float, int) <built-in>
operator=3D=3D(ulonglong, int)<built-in>
operator=3D=3D(longlong, int)<built-in>
operator=3D=3D(long unsigned int, int)<built-in>
operator=3D=3D(long int, int)<built-in>
operator=3D=3D(unsigned int, int)<built-in>
Error code 1

I should add the reason why I want to have this sort of code is that I =
want to distinguish between a stored NULL entry in the DB and a bad =
conversion when assigning a value obtained from the DB. So the code =
snippet I gave is in my "BadConversion" catch block. Is there a better =
way of doing this?

HTH...steve---



-----Original Message-----
From: Warren Young [mailto:mysqlpp (AT) etr-usa (DOT) com]
Sent: Fri 4/7/2006 5:39 PM
To: MySQL++ Mailing List
Subject: Re: NULL field comparison
=20
Orton, Steve wrote:
Quote:
Which produces the following compile error:
=20
"ambiguous overload for=20
'const mysqlpp:ColData =3D=3D mysqlpp::Null<int, =
mysqlpp::NullIsZero>&' operator"

Did the compiler not tell you what the alternatives were that it was=20
forced to choose from? That would help me to understand where the=20
ambiguity is. As far as I can see, there's only one conversion path:=20
there's a template operator Null<T, B> in coldata.h which should be able =

to convert ColData objects to Null-wrapped ColData objects.

One sticky point I see is that there is no operator=3D=3D for the Null=20
template. Maybe the compiler wants to see one?

--=20
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: =
http://lists.mysql.com/plusplus?unsu... ngc (DOT) com




------_=_NextPart_001_01C65CAA.0A074D43
Content-Type: text/plain; charset=us-ascii


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw
------_=_NextPart_001_01C65CAA.0A074D43--


Reply With Quote
  #4  
Old   
Orton, Steve
 
Posts: n/a

Default RE: NULL field comparison - 04-10-2006 , 09:38 AM




Sorry, I just noticed the code snippet I gave earlier is no longer in =
the thread. I'll add more to it to give it a better context.

try {
int retVal =3D _row.at(col_num) // col_num is passed in as 'long int'
}
catch (BadConversion& bc) {=20
mysqlpp::Null<int, mysqlpp:NulIsZero> myfield
myfield =3D mysqlpp::null;
if (_row.at(0) =3D=3D myfield)
retVal =3D 0;
else
retVal =3D -999;
}
catch (Exception& er) {
// output
}
return retVal;

Hope this amplification helps...steve---



-----Original Message-----
From: Orton, Steve [mailto:steve.orton (AT) ngc (DOT) com]
Sent: Mon 4/10/2006 10:19 AM
To: plusplus (AT) lists (DOT) mysql.com
Subject: RE: NULL field comparison
=20

Sorry for the delay...the weekend got my attention

I wanted to keep the first post simple, so I purposely left the rest of =
the compile error out.
Here's the full output from the compile.

"ambiguous overload for
'const mysqlpp:ColData =3D=3D mysqlpp::Null<int, =
mysqlpp::NullIsZero>&' operator"
candidates are: operator=3D=3D(int, int) <built-in>
operator=3D=3D(double, int) <built-in>
operator=3D=3D(float, int) <built-in>
operator=3D=3D(ulonglong, int)<built-in>
operator=3D=3D(longlong, int)<built-in>
operator=3D=3D(long unsigned int, int)<built-in>
operator=3D=3D(long int, int)<built-in>
operator=3D=3D(unsigned int, int)<built-in>
Error code 1

I should add the reason why I want to have this sort of code is that I =
want to distinguish between a stored NULL entry in the DB and a bad =
conversion when assigning a value obtained from the DB. So the code =
snippet I gave is in my "BadConversion" catch block. Is there a better =
way of doing this?

HTH...steve---



-----Original Message-----
From: Warren Young [mailto:mysqlpp (AT) etr-usa (DOT) com]
Sent: Fri 4/7/2006 5:39 PM
To: MySQL++ Mailing List
Subject: Re: NULL field comparison
=20
Orton, Steve wrote:
Quote:
Which produces the following compile error:
=20
"ambiguous overload for=20
'const mysqlpp:ColData =3D=3D mysqlpp::Null<int, =
mysqlpp::NullIsZero>&' operator"

Did the compiler not tell you what the alternatives were that it was=20
forced to choose from? That would help me to understand where the=20
ambiguity is. As far as I can see, there's only one conversion path:=20
there's a template operator Null<T, B> in coldata.h which should be able =

to convert ColData objects to Null-wrapped ColData objects.

One sticky point I see is that there is no operator=3D=3D for the Null=20
template. Maybe the compiler wants to see one?

--=20
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: =
http://lists.mysql.com/plusplus?unsu... ngc (DOT) com





--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.