My code, which works fine in Linux (Ubuntu 10.10) looks like this:
Connection conn(false);
conn.connect(db, server, user, pass)
Transaction trans(conn);
Query query = conn.query("Update blah blah");
query.execute(); // inside try,catch,catch block
query << "Another update";
query.execute(); //try
query << "Yet another";
query.execute; //try
trans.commit();
query << "select this, that and the other thing";
vector<deepskyStruct> resvec; // deepskyStruct is an ssqls structure
query.storein(resvec);
vector<deepskyStruct>::iterator it;
for loop through the vector, creating members of class SessionObject from the data
end for
start another transaction
query << "Update a different table";
query.execute(); //two more of these
trans2.commit();
query << "Select blah, blah blah from a different table";
vector(doubleStarStruct> resvec2;
//Up to here, everything is fine, and I have verified that all the updates took place. I
also know that the first select, storing in resvec, creating the objects, etc. worked,
because when I commented out the stuff for the 2nd table the program completed
successfully with the expected output.
query.storein(resvec2);
Then:
402 query.storein(resvec2);
(gdb) next
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x0000041c
0x93d12a8d in std::string::clear ()
I debugged the process in XCode:
Here is the calling sequence:
query.storein(resvec); // this is in mycode
storein(Container & con); // in the Mysql++ library
storein(con, str(template_defaults) );
storein_sequence(con, s); // s is a const SQLTypeAdapter
UseQueryResult result = use(s);
while(1) {MYSQL_ROW d = result.fetch_raw_row();
the UseQueryResult object result has a private member result_ with these members:
counted_
refs_
The first time I call query.storein(resvec), after use(s), the result object has these
values:
counted_ = 0x5016f0
refs = 0x501cd0
The code works fine.
When, after another query to a different table, I call query.storein(resvec2), after the
use(s), the members counted_ and refs_ are both 0x0. Then, when result.fetch_raw_row is
called, the program gets the EXC_BAD_ACCESS error. The debugger window shows this:
0x98d17a7c <+0000> push ebp
0x98d17a7d <+0001> mov ebp,esp
0x98d17a7f <+0003> sub esp,0x18
0x98d17a82 <+0006> mov eax,DWORD PTR [ebp+0x8]
0x98d17a85 <+0009> mov DWORD PTR [esp+0xc],0x0
0x98d17a8d <+0017> mov edx,DWORD PTR [eax]
the last line is highlighted and a red arrow points to it.
Thanks,
Alan Shank
Woodland, CA