MySQL Forums
Forum List  »  Connector/C++

segmentation fault ./main
Posted by: Brad Corbett
Date: August 10, 2013 10:06PM

I'm Getting this error when it reaches the
"int rowcnt = res -> rowsCount();" line.

My c++ is a little rusty and I can figure it out. Any help would apprecisted.

#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
/* uncomment for applications that use vectors */
#include <vector>

#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 "worlduser"
#define EXAMPLE_PASS "worldpass"
#define EXAMPLE_DB "world"

using namespace std;


class cmysql{

public:
string host;
string user;
string pass;
string database;


vector<string> getdatacolumns(string strsql){
cout << "begin" << endl;
vector<string> verr;
cout << "Connector/C++ tutorial framework..." << endl;
cout << endl;

try {

vector<string> myreturn;
sql::Driver* driver = get_driver_instance();
std::auto_ptr<sql::Connection> con(driver->connect(host, user, pass));
con->setSchema(database);
std::auto_ptr<sql::Statement> stmt(con->createStatement());
stmt->executeQuery("select * from customer");
std::auto_ptr <sql::ResultSet> res;

do {

res.reset(stmt->getResultSet());
//Setup Vector

int rowcnt = res -> rowsCount();

vector<string> vec;

unsigned int i =1;

while (res->next()) {

vec = res->getString("last_name") + "," +res->getString("first_name") ;

i = i + 1;

}
return vec;
} while (stmt->getMoreResults());

//=================================================================================

}
catch (sql::SQLException &e) {
/*
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;
/* what() (derived from std::runtime_error) fetches error message */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
verr[0] = e.getSQLState();
//return EXIT_FAILURE;
}

}

};

Options: ReplyQuote


Subject
Views
Written By
Posted
segmentation fault ./main
3200
August 10, 2013 10:06PM


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.