8 messages in com.mysql.lists.plusplusRe: compiling mysql++ examples (fwd)
FromSent OnAttachments
Enrique Farfan05 Oct 2004 09:51 
Warren Young05 Oct 2004 13:08 
Don Thompson08 Oct 2004 10:22.txt
Warren Young08 Oct 2004 10:59 
Don Thompson08 Oct 2004 11:40 
Warren Young08 Oct 2004 12:59 
Don Thompson08 Oct 2004 18:22 
Chris Frey09 Oct 2004 11:07 
Subject:Re: compiling mysql++ examples (fwd)
From:Don Thompson (dtho@dcu.org)
Date:10/08/2004 06:22:58 PM
List:com.mysql.lists.plusplus

I'm not trying to insert the c++ class. This code uses the template insert function Query::insert() which uses SQLQuery::insert(). This function uses the class functions table(), field_list() and value_list() from the class supplied as the template class (CLdata). See query1.hh and sql_query1.hh which define these template classes.

<...from sql_query1.hh...> template <class T> SQLQuery& insert(const T &v) { reset(); *this << "INSERT INTO " << v.table() << " (" << v.field_list() << ") VALUES (" << v.value_list() << ")"; return *this; } //: my example is not complete, in that it does not show the value_list implementation, but this usage of insert() simply performs the db INSERT as show above, getting table, fields and values from the classes functions.

this template function is instantiated as: template <class CLdata> Query& Query::insert(const CLdata &v)

the compiler error messsage are: /usr/local/mysql++-1.7.15/sqlplusint/sql_query1.hh: In member function ` SQLQuery& SQLQuery::insert(const T&) [with T = CLdata]': /usr/local/mysql++-1.7.15/sqlplusint/query1.hh:83: instantiated from `MysqlQuery& MysqlQuery::insert(const CLdata&) [with T = CLdata]' cudb.cc:21: instantiated from here /usr/local/mysql++-1.7.15/sqlplusint/sql_query1.hh:178: error: passing `const CLdata' as `this' argument of `std::string& CLdata::value_list()' discards qualifiers /usr/local/mysql++-1.7.15/sqlplusint/sql_query1.hh:178: error: passing `const CLdata' as `this' argument of `std::string& CLdata::field_list()' discards qualifiers /usr/local/mysql++-1.7.15/sqlplusint/sql_query1.hh:178: error: passing `const CLdata' as `this' argument of `SQLString& CLdata::table()' discards qualifiers make[3]: *** [cudb.o] Error 1

Why does is it complaining about 'discards qualifiers'?

Don Thompson wrote:

You're right, the junk was test code with const qualifier, but it should be removed for my example, ie query.insert(*this). Using this change, I get the complaint about const: I know we're getting into c++ issues here.

Wait just a minute....it seems that you're trying to insert an arbitrary C++ class into the database. That cannot work. This is not Java and, and MySQL is not an OODB!

You need to use the SQLSS mechanism; in order to copy the data from your C++ class to the SQLSS structure, you will create a non-const object on the stack, so constness won't be a problem. See the custom* examples.