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::operator`[]''
: 2 overloads have similar conversions
d:\mysql++\include\const_string.h(137): could be 'mysqlpp::const_string::const_reference
mysqlpp::const_string::operator [](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>::operator`mysqlpp::Null<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::Date, 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@stripped> wrote:
Ece Karli wrote:
>
> 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?unsub=1
---------------------------------
Do you Yahoo!?
With a free 1 GB, there's more in store with Yahoo! Mail.