dbTalk Databases Forums  

Can connect but get seg fault as soon as i try to get a Result Set

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Can connect but get seg fault as soon as i try to get a Result Set in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris Gagnon
 
Posts: n/a

Default Can connect but get seg fault as soon as i try to get a Result Set - 02-19-2005 , 01:49 PM






Hi i can get the program to connect to the database but as soon as i
attempt to retrieve a result set it Seg Faults and i can't figure out
why. As you can see i've added extra catch( ...)'s to ensure i'm not
missing any exceptions.

Here is the code:

//declaired private in the class containing this code block
Connection *dbCon;

//initialize database
try
{
dbCon = new Connection(use_exceptions);
if(dbCon->real_connect(DB,HOST,USERNAME,PASSWORD,3306,0,60, "/tmp/mysql.sock")
!= true)
{
cerr << "ERROR::" << "Database connection Error" << endl;
}
}
catch(BadQuery er)
{
cerr << "ERROR::" << er.error << endl;
}catch(...){
cerr << "ERROR::" << " unhandled database connection exception" << endl;
}
cerr << "database connection initialized" << endl;

//initialize universe
someclass->Load(dbCon);


//loadfunction
int SomeClass::Load(Connection *dbCon)
{
try{
//create query object
Query query = dbCon->query();

query << "select * from sometable";
cerr << "added query string : " << query.preview() << endl;

Result res = query.store();
//segfaults on this line ... never see the following output
cerr << "ran select query" << endl;

//loops through all worlds returned from query
Row world;
Result::iterator i;
for (i = res.begin(); i != res.end(); i++) {
//cdo stuff
}
return 0;
} catch (BadQuery er) { // handle bad querys
cerr << "ERROR:: " << er.error << endl;
} catch (BadConversion er) { // handle bad conversions
cerr << "ERROR:: " << "bad conversion in Load Universe" << endl;
} catch(...){
cerr << "ERROR:: " << "unhandled exception" << endl;
}
}

--
Thanks for your time,
Chris Gagnon

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Chris Frey
 
Posts: n/a

Default Re: Can connect but get seg fault as soon as i try to get a Result Set - 02-19-2005 , 03:33 PM






On Sat, Feb 19, 2005 at 02:42:08PM -0500, Chris Gagnon wrote:
Quote:
Hi i can get the program to connect to the database but as soon as i
attempt to retrieve a result set it Seg Faults and i can't figure out
why. As you can see i've added extra catch( ...)'s to ensure i'm not
missing any exceptions.
Please post a backtrace of the segfault.

Quote:
Here is the code:

//declaired private in the class containing this code block
Connection *dbCon;

//initialize database
try
{
dbCon = new Connection(use_exceptions);
This is unrelated, but you don't have to allocate this on the heap.
Allocating on the heap without at least using auto_ptr<> means there
can be memory leaks when exceptions happen.

- Chris


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
dienw
 
Posts: n/a

Default RE: Can connect but get seg fault as soon as i try to get a Result Set - 02-21-2005 , 02:11 AM




I was having the same problem, but only in a particular application.
When so, it always happenned at query.store(). Any query.store().

The specific err is after:

std::string SQLQuery::str(SQLQueryParms& p, query_reset r) {
std::string tmp = str(p);
if (r == RESET_QUERY) {
reset();
}
return tmp;
}

When deleting the tmp variable, at std::string destruction.
it asserts about freeing an invalid heap.

I'm using MSVC 7.

It could be a compiler problem. Maybe related with STL or some linking
problems.
But since somebody else raising the same issue, so, I'm getting curious
whether
it is a known problem before.

For now, I could fix it by just recreating the project. I've tried to narrow
down my code until several lines only with as few library linked as
possible,
but it still didn't worked.




-Dien.



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.