Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Subject: Re: Unhandled exception, even with error handling

Subject: Re: Unhandled exception, even with error handling

2007-09-28       - By David Sevier

 Back
I figured it out.

Turns out the problem was that I had two references to the same data. res,
and RawRes. Basically, it was deconstructing one and then bombing when it
tried to deconstruct the other. Solved it
by just using res and ResUse's attendent functions to figure out the
column names and datatypes.

Sloppy coding was, as usual, the culprit.

Hopefully, though, this will be of some us to someone in the future.

-David

On 9/28/07, David Sevier <latentknowledge@(protected)> wrote:
>
>
> 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.
>



--
David Sevier
Owner
Latent Knowledge
(858) 337-5948