mysql connector c++

Hello. First please forgive me my bad language second...please help me resolve my problem. My code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* INSERT TUTORIAL CODE HERE! */
sql::Driver *driver = get_driver_instance();
std::auto_ptr<sql::Connection> con(driver->connect("tcp://127.0.0.1:3307", "root", "pass"));
con->setSchema("mybase");
std::auto_ptr<sql::Statement> stmt(con->createStatement());

//example from dev/mysql site

stmt->execute("DROP TABLE IF EXISTS mcountry");
stmt->execute("DROP PROCEDURE IF EXISTS add_ctry");
stmt->execute("DROP PROCEDURE IF EXISTS getdata");

stmt->execute("CREATE TABLE mcountry(country_id INT)");
stmt->execute("CREATE PROCEDURE add_ctry(IN cname INT) BEGIN INSERT INTO mcountry(country_name) VALUES (cname); END;");
stmt->execute("CREATE PROCEDURE getdata() BEGIN SELECT * FROM mcountry; END;");

stmt->execute("CALL add_ctry(112)");
stmt->execute("CALL add_ctry(323)");

stmt->execute("CALL getdata()");

std::auto_ptr<sql::ResultSet> res;

do{
res.reset(stmt->getResultSet());
while(res->next())
{
cout << "ID: " << res->getInt(1);
}
} while(stmt->getMoreResults());


This works fine, I get result as expected but when i change type from INT
to CHAR - nothing works. I need fetch string data from my table but instead of
good results I get only strange garbage data. Please help me and thanks for any answers..code for fetching string data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
sql::Driver *driver = get_driver_instance();
std::auto_ptr<sql::Connection> con(driver->connect("tcp://127.0.0.1:3307", "root", "pass"));
con->setSchema("mybase");
std::auto_ptr<sql::Statement> stmt(con->createStatement());

//example from dev/mysql site

stmt->execute("DROP TABLE IF EXISTS mcountry");
stmt->execute("DROP PROCEDURE IF EXISTS add_ctry");
stmt->execute("DROP PROCEDURE IF EXISTS getdata");

stmt->execute("CREATE TABLE mcountry(country_name CHAR(3))");
stmt->execute("CREATE PROCEDURE add_ctry(IN cname CHAR(3)) BEGIN INSERT INTO mcountry(country_name) VALUES (cname); END;");
stmt->execute("CREATE PROCEDURE getdata() BEGIN SELECT * FROM mcountry; END;");

stmt->execute("CALL add_ctry('abc')");
stmt->execute("CALL add_ctry('def')");

stmt->execute("CALL getdata()");

std::auto_ptr<sql::ResultSet> res;

do{
res.reset(stmt->getResultSet());
while(res->next())
{
cout << "Name: " << res->getString(1);
}
} while(stmt->getMoreResults());


Error: Unhandled exception at 0x70481174 in tstproj.exe: 0xC0000005: Access violation reading location 0x00774000.

Moreover Visual studio 2010 redirect me to the string standard header and there incicate on:
1
2
3
if (_State == ios_base::goodbit
			&& _Ostr.rdbuf()->sputn(_Str.c_str(), _Size) != (streamsize)_Size)
				_State |= ios_base::badbit;
Last edited on
We are going to need to know what your error is. Re-pasting your code inside of code tags would also be helpful, and will likely get you an answer faster.
Topic archived. No new replies allowed.