Warren Young wrote:
> Earl Miles wrote:
>
>> Hmm. In the instance I was toying with, the db already existed from a
>> previous run, and I was using the default user, who didn't have
>> permission with the database, so that's exactly what was happening in
>> my runs of resetdb.
>
>
> I think you need to debug that more closely. If the first select_db()
> fails, it will try to create_db, which _doesn't throw exceptions_ when
> it fails. It just returns true (!) so the program ends.
>
I think you are mistaken. create_db calls execute() which can, in fact,
throw exceptions. And does. At the bottom is my stepping through with
gdb, starting from a breakpoint at the catch() statement in resetdb.cpp
As I see it there are two possible solutions. The first being the one
you suggested--disable exceptions at will. I'm not sure how I feel about
that one. I have concerns over the safety of disabling exceptions and
ending up in a state where the program forgets to turn them back on. But
I'm not sure those concerns are well-founded, they are merely concerns.
The second would be to set a flag in the catch block, and once the catch
block is exited, check that flag and execute the code that is currently
in the catch block. Possibly a bit kludgy, but possibly safer than
simply disabling exceptions entirely, depending on whether or not my
concerns are valid.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program:
/home/emiles/downloads/mysql++-1.7.31/examples/.libs/resetdb
Breakpoint 1, main (argc=1, argv=0xbffff1b4) at resetdb.cpp:27
27 catch (mysqlpp::BadQuery &) {
(gdb) s
154 {
(gdb)
664 allocator() throw() {}
(gdb)
145 ResNSel execute(const std::string& str) {
(gdb)
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
std::operator+<char, std::char_traits<char>, std::allocator<char> >(char
const*, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&) (
__lhs=0x807b7e1 "CREATE DATABASE ", __rhs=@0xbfffed70) at
char_traits.h:135
135 { return strlen(__s); }
(gdb)
614 {
(gdb)
135 { return strlen(__s); }
(gdb)
50 {
(gdb)
51 __asm__ __volatile__ ("lock; addl %0,%1"
(gdb)
208 : _Alloc(__a), _M_p(__dat) { }
(gdb)
229 { return _M_dataplus._M_p; }
(gdb)
388 size() const { return _M_rep()->_M_length; }
(gdb)
229 { return _M_dataplus._M_p; }
(gdb)
726 { return __lhs.base() - __rhs.base(); }
(gdb)
621 __str.append(__rhs);
(gdb)
622 return __str;
(gdb)
mysqlpp::Connection::execute(std::string const&, bool) (this=0xbfffed80,
str=@0x0, throw_excptns=true) at connection.h:90
90 if (locked) {
(gdb)
175 {
(gdb)
176 Success = false;
(gdb)
90 if (locked) {
(gdb)
93 locked = true;
(gdb)
89 {
(gdb)
229 { return _M_dataplus._M_p; }
(gdb)
119 { __c1 = __c2; }
(gdb)
781 {
(gdb)
119 { __c1 = __c2; }
(gdb)
781 {
(gdb)
188 if (Success) {
(gdb)
781 {
(gdb)
96 void unlock() { locked = false; }
(gdb)
188 if (Success) {
(gdb)
192 if (throw_excptns) {
(gdb)
106 const char *error() { return mysql_error(&mysql); }
(gdb)
664 allocator() throw() {}
(gdb)
106 const char *error() { return mysql_error(&mysql); }
(gdb)
12 BadQuery(const std::string &er = "") : error(er) {}
(gdb)
229 { return _M_dataplus._M_p; }
(gdb)
668 ~allocator() throw() {}
(gdb)
229 { return _M_dataplus._M_p; }
(gdb)
665 allocator(const allocator&) throw() {}
(gdb)
38 {
(gdb)
40 __asm__ __volatile__ ("lock; xaddl %0,%2"
(gdb)
38 {
(gdb)
193 throw BadQuery(error());
(gdb)
249 if (throw_exceptions) throw
BadQuery("ROW or RES is NULL");
(gdb)
193 throw BadQuery(error());
(gdb)
Program received signal SIGABRT, Aborted.
0x4018cda1 in kill () from /lib/libc.so.6
(gdb)
Single stepping until exit from function kill,
which has no line number information.
Program terminated with signal SIGABRT, Aborted.
The program no longer exists.
(gdb)