dbTalk Databases Forums  

Problem with NULL values in integer fields

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


Discuss Problem with NULL values in integer fields in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ece Karli
 
Posts: n/a

Default Problem with NULL values in integer fields - 01-20-2006 , 04:49 PM






--0-1051200756-1137797110=:18023
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hi all,

I am getting conversion error when I try to read data into SSQLS structure and value of an integer field is null. I modified example stock table to have NULL values for num field and customX examples fail with the same error:

Conversion error: Tried to convert "NULL" to a "__int64
retrieved data size: 0, actual size: 4

How do you get around this problem.

Thanks.



---------------------------------
Yahoo! Photos
Got holiday prints? See all the ways to get quality prints in your hands ASAP.
--0-1051200756-1137797110=:18023--

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

Default Re: Problem with NULL values in integer fields - 01-23-2006 , 04:21 PM






Ece Karli wrote:
Quote:
I am getting conversion error when I try to read data into SSQLS
structure and value of an integer field is null.

Read the user manual. There is a whole section on nulls (3.8), and why
you have to treat them specially.

--
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   
Ece Karli
 
Posts: n/a

Default Re: Problem with NULL values in integer fields - 01-25-2006 , 12:08 PM



--0-958694988-1138211496=:45530
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

I have already read that section but could not get Null template compile if the type in the sql_create macro is one of those. I have copied my modified version of custom1.cpp file below. I am getting this compile error:

d:\mysql++\include\coldata.h(300) : error C2666: 'mysqlpp::const_string:perator`[]'' : 2 overloads have similar conversions
d:\mysql++\include\const_string.h(137): could be 'mysqlpp::const_string::const_reference mysqlpp::const_string:perator [](mysqlpp::const_string::size_type) const'
or 'built-in C++ operator[(mysqlpp::cchar, int)'
while trying to match the argument list '(const mysqlpp::ColData_Tmpl<Str>, int)'
with
[
Str=mysqlpp::const_string
]
d:\Test\TestMySQL\TestMySQL.cpp(57) : see reference to function template instantiation 'mysqlpp::ColData_Tmpl<Str>:perator`mysqlpp::Nul l<Type,Behavior>'(void) const' being compiled
with
[
Str=mysqlpp::const_string,
Type=double,
Behavior=mysqlpp::NullisZero
]


How am I supposed to use the template in that macro? Here is the code, I am trying to define weight as nullable field:

typedef mysqlpp::Null<double, mysqlpp::NullisZero> MyNull;

sql_create_5(stock,
1, 5, // explained in the user manual
string, item,
mysqlpp::longlong, num,
MyNull, weight,
double, price,
mysqlpp:ate, sdate)

int
main(int argc, char *argv[])
{
// Wrap all MySQL++ interactions in one big try block, so any
// errors are handled gracefully.
try {
// Establish the connection to the database server.
mysqlpp::Connection con(mysqlpp::use_exceptions);
if (!connect_to_db(argc, argv, con)) {
return 1;
}
// Retrieve the entire contents of the stock table, and store
// the data in a vector of 'stock' SSQLS structures.
mysqlpp::Query query = con.query();
query << "select * from stock";
vector<stock> res;
query.storein(res);
// Display the result set
print_stock_header(res.size());
vector<stock>::iterator it;
for (it = res.begin(); it != res.end(); ++it) {
print_stock_row(it->item, it->num, it->weight, it->price,
it->sdate);
}
}
catch (const mysqlpp::BadQuery& er) {
// Handle any query errors
cerr << "Query error: " << er.what() << endl;
return -1;
}
catch (const mysqlpp::BadConversion& er) {
// Handle bad conversions; e.g. type mismatch populating 'stock'
cerr << "Conversion error: " << er.what() << endl <<
"\tretrieved data size: " << er.retrieved <<
", actual size: " << er.actual_size << endl;
return -1;
}
catch (const mysqlpp::Exception& er) {
// Catch-all for any other MySQL++ exceptions
cerr << "Error: " << er.what() << endl;
return -1;
}
return 0;
}


Warren Young <mysqlpp (AT) etr-usa (DOT) com> wrote:
Ece Karli wrote:
Quote:
I am getting conversion error when I try to read data into SSQLS
structure and value of an integer field is null.

Read the user manual. There is a whole section on nulls (3.8), and why
you have to treat them specially.


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






---------------------------------
Do you Yahoo!?
With a free 1 GB, there's more in store with Yahoo! Mail.
--0-958694988-1138211496=:45530--


Reply With Quote
  #4  
Old   
M.K. tenNapel
 
Posts: n/a

Default Re: Problem with NULL values in integer fields - 04-20-2006 , 09:39 AM



Thanks for the reply. However, I don't see myself writing a patch yet,
I'm just not that skilled with my C++ programming But I'm learning
and maybe, some day, I will be usefull
Does someone know where I can find some information, where I can learn
what is causing the problem and how I can avoid it? Maybe I can work
around it to avoid the problem.

Op do, 20-04-2006 te 06:22 -0600, schreef Warren Young:
Quote:
M.K. tenNapel wrote:
Is there any solution to this?

Read this thread:

http://lists.mysql.com/plusplus/5433

You're welcome to apply the patch yourself. Please report back on
whether it works or not, if you do. As I replied in that thread, we
won't be applying this patch until v3.0.

--
If Linux doesn't have the solution, you have the wrong problem


--
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
  #5  
Old   
Warren Young
 
Posts: n/a

Default Re: Problem with NULL values in integer fields - 04-20-2006 , 02:07 PM



M.K. tenNapel wrote:
Quote:
I don't see myself writing a patch yet,
You misunderstand: the thread I pointed you to _contains_ a patch,
already written.

--
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
  #6  
Old   
M.K. tenNapel
 
Posts: n/a

Default Re: Problem with NULL values in integer fields - 04-21-2006 , 05:31 AM



I saw that just after I send my mail. Sorry for that
I'll see if I can get it to work. Thanks!

Op do, 20-04-2006 te 13:07 -0600, schreef Warren Young:
Quote:
M.K. tenNapel wrote:
I don't see myself writing a patch yet,

You misunderstand: the thread I pointed you to _contains_ a patch,
already written.

--
If Linux doesn't have the solution, you have the wrong problem


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