List:MySQL++« Previous MessageNext Message »
From:David Sevier Date:September 28 2007 7:11pm
Subject:Unhandled exception, even with error handling
View as plain text  
Sorry for all the questions lately, I'm pretty new to c++ and much
more of a database guy then a pure programmer.

Anyway, I have a new problem that I'm struggling with.

I created a wrapper to run a passed query and return a result set that
converts all of the values to strings. It seems to work pretty well for the
most part.

However, I'm running into a problem when it gets to the end of the result
set. Here is the error I get:
Unhandled exception at 0x00454c15 in MemoryWebTest.exe: 0xC0000005: Access
violation reading location 0xfeef02a2.

MemoryWeb test pretty much just passes this function a query and grabs the
result set. I'm not even doing anything with the results at this point.

I know the query is good.
I actually get data out of it. But when I do a return, it's giving me
the error. It does this even if I don't actually effect my return
value at all. I can return the same blank pointer I started with
before I do the
res.fetch_row
() and everything is fine. No data, but it works. As soon as I do even
one fetch, it dies on the return.

I copied the exception handling code out of usequery.cpp
, but it doesn't seem to be catching the errors.

Any ideas?


ResultSet* MySQLDBI::RunQuery(String QueryString)
{
ResultSet* RSet = new ResultSet();
try
{
Query RunQuery = DBC->DBConnection.query();
RunQuery << QueryString.cString();

mysqlpp::ResUse res = RunQuery.use();
if (!res)
{
lprintf(" ERROR: Result set is empty\n");
return 0;
}
Result RawRes = res.raw_result();

for (unsigned int i = 0; i < RawRes.names().size(); i++)
{
String FieldName = RawRes.names(i).c_str();
String SQLType = RawRes.types (i).sql_name();

RSet->ColumnName.append(FieldName);
RSet->ColumnType.append(SQLType);
}

mysqlpp::Row row;

while (row = res.fetch_row())
{
int Cols = res.num_fields ();
Array<String> RowVal;
RowVal = Array<String>(0);
for (int r = 0; r < Cols; r++)
{
String Output = row[r];
RowVal.append(Output);
}
RSet-> Values.append(RowVal);
}
}
catch (const mysqlpp::BadQuery& e)
{
// Something went wrong with the SQL query.
String ErrorMsg = "ERROR: Query failed:";
ErrorMsg += e.what ();
lprintf(" %s\n", ErrorMsg);
return NULL;
}
catch (const mysqlpp::EndOfResults&)
{
// Last query result received. Exit normally.
return RSet;
}
catch (const mysqlpp::Exception& er)
{
// Catch-all for any other MySQL++ exceptions
String ErrorMsg = "ERROR: Query failed:";
ErrorMsg += er.what();
lprintf(" %s\n", ErrorMsg);
return NULL;
}

// Shouldn't happen! Program should either error out through one of
// the "return 1" cases above, or successfully walk off the end of
// the result set and go through the EndOfResults path above.
return NULL;
}




As a further test, I added in this debug code before the loop:

mysqlpp::Row row;
int RowNum = 0;
lprintf("Trying to grab one row\n");
row = res.fetch_row();
int Cols = res.num_fields();

for (int r = 0; r < Cols; r++)
{
String Output = row[r];
lprintf(" DEBUG: Row: %d Col: %d value %s\n", RowNum, r, Output);
}
lprintf("Ok...that worked. Let's try destroying the ResUse and Row.\n");
row.~Row();
res.~ResUse();
lprintf("Now let's try to do a return.\n");
return RSet;

This nicly prints out the first row of data. Which works fine. Still errors
out on the return.

My only guess is that somewhere internally there is some error going on when
some local structure is being deconstructed. But I have no idea where that
would be. Deconstructing the Row and ResUse didn't seem to do anything.

Any help would be appreciated.

Thread
Unhandled exception, even with error handlingDavid Sevier28 Sep
  • Re: Unhandled exception, even with error handlingDavid Sevier29 Sep