MySQL Forums
Forum List  »  Connector/C++

mysql_connection.h causes "invalid covariant return type for..." during compile
Posted by: alex ekholm
Date: June 04, 2010 02:08PM

****EDIT: Nevermind for some reason I had put "mysql_connection.h" in my working directory. The problem we resolved when I removed it.






I am using Eclipse SDK 3.5.1 in Ubuntu 9.10 to invoke gcc 4.4.1 compile my code. I have compiled/installed boost 1.43.0 and mysql-connector-c++ 1.1.0~r791 (from source, not binary). I have linked to the mysqlcppconn library.

The error is coming from the "mysql_connection.h" file but here is the what I am trying to compile:

---code-------------------------------------------------
/*
* mtest.cpp
*
* Created on: Jun 4, 2010
* Author: aekholm
*/

#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>

#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

#define EXAMPLE_HOST "localhost"
#define EXAMPLE_USER "root"
#define EXAMPLE_PASS "password"
#define EXAMPLE_DB "world"

using namespace std;

int main(int argc, const char **argv) {

string url(argc >= 2 ? argv[1] : EXAMPLE_HOST);
const string user(argc >= 3 ? argv[2] : EXAMPLE_USER);
const string pass(argc >= 4 ? argv[3] : EXAMPLE_PASS);
const string database(argc >= 5 ? argv[4] : EXAMPLE_DB);

cout << "Connector/C++ tutorial framework..." << endl;
cout << endl;

try {

sql::Driver* driver = get_driver_instance();
std::auto_ptr<sql::Connection> con(driver->connect(url, user, pass));
con->setSchema(database);
std::auto_ptr<sql::Statement> stmt(con->createStatement());

stmt->execute("CALL get_pop(\"Uganda\", @pop)");

std::auto_ptr<sql::ResultSet> res(stmt->executeQuery(
"SELECT @pop AS _reply"));
while (res->next())
cout << "Population of Uganda: " << res->getString("_reply")
<< endl;

stmt->execute("CALL get_pop_continent(\"Asia\", @pop)");

res.reset(stmt->executeQuery("SELECT @pop AS _reply"));
while (res->next())
cout << "Population of Asia: " << res->getString("_reply") << endl;

stmt->execute("CALL get_world_pop(@pop)");

res.reset(stmt->executeQuery("SELECT @pop AS _reply"));
while (res->next())
cout << "Population of World: " << res->getString("_reply") << endl;

} catch (sql::SQLException &e) {
/*
The MySQL Connector/C++ throws three different exceptions:

- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
*/
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
/* Use what() (derived from std::runtime_error) to fetch the error message */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;

return EXIT_FAILURE;
}
}

--/code-------------------------------------------------





Here is the console output:

---console-----------------------------------------------

**** Build of configuration Debug for project mysql_test ****

make all
Building file: ../mtest.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/mysql -I/usr/local/src/boost/ -I/usr/local/src/mysql-connector-c++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"mtest.d" -MT"mtest.d" -o"mtest.o" "../mtest.cpp"
In file included from ../mtest.cpp:13:
../mysql_connection.h:34: error: invalid covariant return type for ‘virtual std::string sql::mysql::MySQL_Savepoint::getSavepointName()’
/usr/local/src/mysql-connector-c++/cppconn/connection.h:53: error: overriding ‘virtual sql::SQLString sql::Savepoint::getSavepointName()’
../mysql_connection.h:67: error: invalid covariant return type for ‘virtual std::string sql::mysql::MySQL_Connection::getCatalog()’
/usr/local/src/mysql-connector-c++/cppconn/connection.h:78: error: overriding ‘virtual sql::SQLString sql::Connection::getCatalog()’
../mysql_connection.h:69: error: invalid covariant return type for ‘virtual std::string sql::mysql::MySQL_Connection::getSchema()’
/usr/local/src/mysql-connector-c++/cppconn/connection.h:80: error: overriding ‘virtual sql::SQLString sql::Connection::getSchema()’
../mysql_connection.h:71: error: invalid covariant return type for ‘virtual std::string sql::mysql::MySQL_Connection::getClientInfo()’
/usr/local/src/mysql-connector-c++/cppconn/connection.h:82: error: overriding ‘virtual sql::SQLString sql::Connection::getClientInfo()’
make: *** [mtest.o] Error 1

--/console-----------------------------------------------





I'm not really sure exactly what is going here. If anyone could shed some light on the problem it would be greatly appreciated. Thanks.



Edited 1 time(s). Last edit at 06/04/2010 02:15PM by alex ekholm.

Options: ReplyQuote


Subject
Views
Written By
Posted
mysql_connection.h causes "invalid covariant return type for..." during compile
4273
June 04, 2010 02:08PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.