Hi All,
This is the error which I get:
./examples/ssqls1.cpp:65: error: 'struct stock' has no member named
'm_description'
where m_description is the C++ names which I want to use for field name
"description" in my code.
I am trying to use sql_create_complete_#. As per the user manual this can be
used to provided different names in C++ and SQL. That is what I was
searching for. Generally when a column name in the database table changes we
have to modify our code at all the places to use the new field name. By
using the sql_create_complete I may need to just update the code only at one
place rather than at all the places in the code. That would be kool.
sql_create_complete_6(stock,
1, 6, // The meaning of these values is covered in the user manual
mysqlpp::sql_char, item, "m_item",
mysqlpp::sql_bigint, num, "m_num",
mysqlpp::sql_double, weight, "m_weight",
mysqlpp::sql_double, price, "m_price",
mysqlpp::sql_date, sdate, "m_sdate",
mysqlpp::Null<mysqlpp::sql_mediumtext>, description, "m_description")
I just added the C++ names which I wanted to use to the already provided
structure in stock.h
But now when I try to use any of the names I get compilation errors. But
using the SQL field names works fine.
I am using the make file provided with the examples. What I did was modified
the ssqls1.cpp to use the C++ names in place of SQL fields.
Please let me know if I am missing something.
stock.h
#include <mysql++.h>
#include <ssqls.h>
sql_create_complete_6(stock,
1, 6, // The meaning of these values is covered in the user manual
mysqlpp::sql_char, item, "m_item",
mysqlpp::sql_bigint, num, "m_num",
mysqlpp::sql_double, weight, "m_weight",
mysqlpp::sql_double, price, "m_price",
mysqlpp::sql_date, sdate, "m_sdate",
mysqlpp::Null<mysqlpp::sql_mediumtext>, description, "m_description")
ssqls1.cpp
#include "cmdline.h"
#include "printdata.h"
#include "stock.h"
#include <iostream>
#include <vector>
using namespace std;
int
main(int argc, char *argv[])
{
// Get database access parameters from command line
const char* db = 0, *server = 0, *user = 0, *pass = "";
if (!parse_command_line(argc, argv, &db, &server, &user, &pass)) {
return 1;
}
try {
// Establish the connection to the database server.
mysqlpp::Connection con(db, server, user, pass);
mysqlpp::Query query = con.query("select item,description from
stock");
vector<stock> res;
query.storein(res);
// Display the items
cout << "We have:" << endl;
vector<stock>::iterator it;
for (it = res.begin(); it != res.end(); ++it) {
cout << '\t' << it->item;
if (it->description != mysqlpp::null) {
cout << " (" << it->m_description << ")";
}
cout << endl;
}
}
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;
}
Thanks & Regards,
Jay.