To: David Hall <DavidH@stripped>
Ok, so I've spent some time trying to figure it out. I know what causes the
problem, but I don't know the reason for it. Here goes:
on creating a mysqlpp::Connection object, it creates a DBDriver object
(class). The constructor of DBDriver initialises options of the mysql_
object (mysql_init(&mysql_)). When you call the disconnect() method,
libmysql zeroes the entire mysql_ object leaving the options unset.
Therefore, when we call the connect() method again, access violation occurs,
because libmysql tries to read the mysql_.options.shared_memory_base_name,
which is pointing at 0x00000000 instead of the "MYSQL" string. A temporary
workaround for me was to add these lines in the DBDriver::connect method and
recompile.
if (!mysql_.options.shared_memory_base_name)
mysql_init(&mysql_);
I don't know what causes such a behaviour, I've tried the 5.1.37 mysql
version. Perhaps it's the version?
Regards
2009/8/14 David Hall <DavidH@stripped>
Hi Warren, it still crashes (access violation at the second connect) when
> your patch is applied (though my original version of simple1.cpp looks a
> little different to yours (from the 3.0.9 release I downloaded.)
>
> (with patch)
> ===============================
> mysqlpp::Connection conn(false);
> if (conn.connect(db, server, user, pass)) {
> conn.disconnect();
> conn.connect(db, server, user, pass);
> // Retrieve a subset of the sample stock table set up by
> resetdb
> // and display it.
> mysqlpp::Query query = conn.query("select item from stock");
> if (mysqlpp::StoreQueryResult res = query.store()) {
> cout << "We have:" << endl;
> mysqlpp::StoreQueryResult::const_iterator it;
> for (it = res.begin(); it != res.end(); ++it) {
> mysqlpp::Row row = *it;
> cout << '\t' << row[0] << endl;
> }
> }
> else {
> cerr << "Failed to get item list: " <<
> query.error()
> << endl;
> return 1;
> }
>
> //return 0;
> }
> else {
> cerr << "DB connection failed: " << conn.error() <<
> endl;
> return 1;
> }
>
> conn.disconnect();
> ===============================
>
> My details:
>
> Using MySQL Server 5.1.
>
> I have the following Visual studio versions:
>
> - Visual studio 2003 version 7.1.6030
>
> - Visual studio 2005 version 8.0.50727.762 (SP.050727-7600)
>
> - Visual studio 2008 version 9.0.30729.1 SP
>
> What other information would you like?
>
> Cheers,
>
> Dave
>
> -----Original Message-----
> From: Warren Young [mailto:mysqlpp@stripped]
> Sent: Friday, 14 August 2009 12:41 AM
> To: MySQL++ Mailing List
> Subject: Re: problem when calling mysqlpp connection object connect
> function after calling disconnect
>
> Wojciech Barski wrote:
> > On May 20, 2009, at 5:04 PM, Warren Young wrote:
> >
> >> Yes, do. I tried modifying one of the examples to bounce the connection
> a
> > few times in a few different places, and it doesn't affect anything. See
> the
> > attached patch.
> >
> > I seem to be having the same problem. The simple code like this brings
> the
> > access violation exception (on a reconnect try). I've traced it to
> > mysql_real_connect line in the dbdriver::connect method.
>
> I still can't reproduce it. I added these two lines to simple1.cpp, and
> it didn't crash:
>
> > Index: examples/simple1.cpp
> > ===================================================================
> > --- examples/simple1.cpp (revision 2561)
> > +++ examples/simple1.cpp (working copy)
> > @@ -48,9 +48,6 @@
> > mysqlpp::Connection conn(false);
> > if (conn.connect(mysqlpp::examples::db_name, cmdline.server(),
> > cmdline.user(), cmdline.pass())) {
> > - conn.disconnect();
> > - conn.connect(mysqlpp::examples::db_name, cmdline.server(),
> > - cmdline.user(), cmdline.pass());
> > // Retrieve a subset of the sample stock table set up by
> resetdb
> > // and display it.
> > mysqlpp::Query query = conn.query("select item from stock");
>
> I tried it on both Linux and Windows. Please apply the same patch to
> your copy of MySQL++. If it crashes, I'll need some details about the
> environment, since it clearly doesn't happen everywhere. If it doesn't
> crash, it's likely that you just didn't follow the README-Visual-C++.txt
> instructions carefully enough.
>
> --
> MySQL++ Mailing List
> For list archives: http://lists.mysql.com/plusplus
> To unsubscribe:
> http://lists.mysql.com/plusplus?unsub=1
>
>
> --
> MySQL++ Mailing List
> For list archives: http://lists.mysql.com/plusplus
> To unsubscribe: http://lists.mysql.com/plusplus?unsub=1
>
>