dbTalk Databases Forums  

Problems handling column element of Row object returned as NULL

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


Discuss Problems handling column element of Row object returned as NULL in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Brandmeyer, Jo Ellen
 
Posts: n/a

Default Problems handling column element of Row object returned as NULL - 03-29-2005 , 06:50 PM






------_=_NextPart_001_01C534BA.219D604E
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

I am using MySQL++ 1.7.27 on Windows with Visual C++ 7.1 (Visual Studio
..NET 2003). This same problem occurs with both MySQL 4.1 and 5.0 beta.
=20
I have queries of the form:
=20
<Query_object> << "select sum(field_value) where <where_clause>";
try{
<Result_object> =3D <Query_object>.store();
} catch (BadQuery er) {
// code here
}
=20
// other checking to be certain got 1 and only 1 row
<Result::iterator_object> =3D <Result_object>.begin();
<Row_object> =3D *<Result::iterator_object>;
float_value =3D <Row_object>[0]; // <Row_object>[0] contains value
returned for sum(field_value)
=20
My problem is that sometimes the sum() returns NULL (not 0.0). If I
directly assign the value to float_value, the program crashes with a
Microsoft Visual C++ Runtime Library abnormal program termination.
=20
I need to be able to test the value of <Row_object>[0] before the
assignment and appropriately handle a NULL value. I tried:
=20
if(!<Row_object>[0].is_null())
{ // handle successful one here
}
=20
The program still abnormally terminates. Does the is_null() function
work properly? I looked in the MySQL++ source code and did not see where
the value of _null in coldata.h is being set.
=20
Please let me know how to successfully test for NULL in a column of a
Row object. Thank you.
=20
Jo Ellen=20

------_=_NextPart_001_01C534BA.219D604E--

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

Default Re: Problems handling column element of Row object returned as NULL - 03-31-2005 , 09:06 AM






Brandmeyer, Jo Ellen wrote:
Quote:
Query_object> << "select sum(field_value) where <where_clause>";
try{
Result_object> = <Query_object>.store();
} catch (BadQuery er) {
// code here
}
All this "names removed to protect the innocent" stuff makes it hard to
understand the problem you're trying to present. Instead of neutering
your existing program, distilling the essence of the problem down to a
separate, small program would have been better.

Also, you should catch that exception by reference, to prevent an
unnecessary object copy.

Quote:
My problem is that sometimes the sum() returns NULL (not 0.0).
Do you mean C++ language "NULL", or SQL "NULL"? They're not the same thing.

Quote:
directly assign the value to float_value, the program crashes with a
Microsoft Visual C++ Runtime Library abnormal program termination.
This is one reason why it would be nice to have a program to compile.
It's easier to debug something you can run.

Quote:
Does the is_null() function work properly?
Your guess is as good as mine. The original creators of MySQL++ have
moved on, leaving no one who knows the internals deeply. Some of us are
building that knowledge back up again, but it'll take time. Meanwhile,
if you find code that seemingly has no purpose, bring it up here and
we'll see what should be done about it.

Quote:
I looked in the MySQL++ source code and did not see where
the value of _null in coldata.h is being set.
A simple grep turns up at least three places.

Quote:
Please let me know how to successfully test for NULL in a column of a
Row object. Thank you.
Look at lib/null.h.

--
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   
Chris Frey
 
Posts: n/a

Default Re: Problems handling column element of Row object returned as NULL - 03-31-2005 , 04:04 PM



On Thu, Mar 31, 2005 at 07:06:35AM -0700, Warren Young wrote:
Quote:
Does the is_null() function work properly?

Your guess is as good as mine. The original creators of MySQL++ have
moved on, leaving no one who knows the internals deeply. Some of us are
building that knowledge back up again, but it'll take time. Meanwhile,
if you find code that seemingly has no purpose, bring it up here and
we'll see what should be done about it.
Yes, it works for me. One of my programs uses it regularly.

- Chris


--
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.