MySQL Forums
Forum List  »  Connector/C++

bug 45048 maybe? test code included
Posted by: Dominic Froud
Date: June 23, 2009 05:43AM

The following code faults when I run it unless I pass an argument (which disables the deletion of "pstmt" after it is used to create "res").

I've run this against 1.0.4-beta and it hangs. With 1.0.5 it segfaults after 82 rows. You may need more rows to trigger the problem.

Could this be a duplicate of bug 45048?

The following code closely reflects my original code, including having a constructor for DummyObject which in this case is redundant.

#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <stdlib.h>
#include <string>

class DummyObject {
private:
std::string s;
public:
DummyObject() {
s.clear();
}

void set_s(std::string in) {
s = in;
}
};

int main(int argc, char *argv[]) {
sql::Driver *driver;
sql::Connection *con;
sql::ResultSet *res;
sql::Statement *stmt;
sql::PreparedStatement *pstmt;
std::string sql;

driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "");
con->setSchema("test");

stmt = con->createStatement();
stmt->execute("drop table if exists test123");
stmt->execute("create table test123 ( a varchar(255) )");
for(int i=0; i<100; i++) {
sql = "insert into test123 values (\"";
for(int j=0; j<16; j++) {
char c = (rand() & 0xf) + 'A';
sql += c;
}
sql += "\")";
stmt->execute(sql);
}
delete stmt;

pstmt = con->prepareStatement("select * from test123");
res = pstmt->executeQuery();
if (argc < 2) {
delete pstmt;
}

while(res->next()) {
DummyObject *dummy_obj = new DummyObject();

dummy_obj->set_s( res->getString(1) );
std::cout << res->getString(1) << std::endl;
}
}

Options: ReplyQuote


Subject
Views
Written By
Posted
bug 45048 maybe? test code included
2474
June 23, 2009 05:43AM


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.