dbTalk Databases Forums  

Exception flags not working as described in the manual (patch attached)

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Exception flags not working as described in the manual (patch attached) in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Byrial Jensen
 
Posts: n/a

Default Exception flags not working as described in the manual (patch attached) - 05-29-2005 , 12:29 PM






--------------000109090003030903040503
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

As a new user of mysql++, I have been surprised by the way the exception
flags works.

The User Manual says:

The state of the object's exception enabling flag is passed down to
child objects. For example, if you create a Connection object with
exceptions disabled and then call its query() method to get a Query
object, that object will also have exceptions disabled.

However that does not seem to be entirely true:
* Connection::store() and Query::store() always returns Result
objects with exceptions disabled.
* Connection::use() and Query::use() always returns ResUse objects
with exceptions disabled.
* Query::exec(), Query::store(), Query::use() and Query::execute()
does not use the exception flag of the Query object, but instead the
exception flag of its Connection object. (And the Reference Manual seems
to interchange true and false in the descriptions of parameter te for
these functions).

I have tried to make the things work as described in the manual in the
attached patch. Warning: It may of course break programs relaying on the
current behavior.

Best reagards
Byrial


--------------000109090003030903040503
Content-Type: text/x-patch;
name="exceptions.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="exceptions.patch"

diff -upr mysql++-1.7.40.orig/lib/connection.cpp mysql++-1.7.40/lib/connection.cpp
--- mysql++-1.7.40.orig/lib/connection.cpp 2005-05-20 08:43:59.000000000 +0200
+++ mysql++-1.7.40/lib/connection.cpp 2005-05-28 17:27:14.011695267 +0200
@@ -232,10 +232,10 @@ ResNSel Connection::execute(const string
}
}

-bool Connection::exec(const string& str)
+bool Connection::exec(const string& str, bool throw_excptns)
{
Success = !mysql_query(&mysql, str.c_str());
- if (!Success && throw_exceptions)
+ if (!Success && throw_excptns)
throw BadQuery(error());
return Success;
}
@@ -258,7 +258,7 @@ Result Connection::store(const string& s
MYSQL_RES* res = mysql_store_result(&mysql);
if (res) {
unlock();
- return Result(res);
+ return Result(res, throw_excptns);
}
}
unlock();
@@ -289,7 +289,7 @@ ResUse Connection::use(const string& str
MYSQL_RES* res = mysql_use_result(&mysql);
if (res) {
unlock();
- return ResUse(res, this);
+ return ResUse(res, this, throw_excptns);
}
}
unlock();
diff -upr mysql++-1.7.40.orig/lib/connection.h mysql++-1.7.40/lib/connection.h
--- mysql++-1.7.40.orig/lib/connection.h 2005-05-26 12:08:22.000000000 +0200
+++ mysql++-1.7.40/lib/connection.h 2005-05-28 17:26:03.323591123 +0200
@@ -404,29 +404,43 @@ public:
/// \return true if query was executed successfully
///
/// \sa execute(), store(), storein(), and use()
- bool exec(const std::string& str);
+ bool exec(const std::string& str)
+ {
+ return exec(str, throw_exceptions);
+ }

/// \brief Same as store(str) except that it allows you to turn off
/// exceptions for this query
///
/// \param str query to execute
- /// \param te if true, no exceptions will be thrown on errors.
+ /// \param te if false, no exceptions will be thrown on errors.
Result store(const std::string& str, bool te);

/// \brief Same as use(str) except that it allows you to turn off
/// exceptions for this query
///
/// \param str query to execute
- /// \param te if true, no exceptions will be thrown on errors.
+ /// \param te if false, no exceptions will be thrown on errors.
ResUse use(const std::string& str, bool te);

/// \brief Same as execute(str) except that it allows you to turn off
/// exceptions for this query
///
/// \param str query to execute
- /// \param te if true, no exceptions will be thrown on errors.
+ /// \param te if false, no exceptions will be thrown on errors.
+ ///
+ /// \return ResNSel status information about the query
ResNSel execute(const std::string& str, bool te);

+ /// \brief Same as exec(str) except that it allows you to turn off
+ /// exceptions for this query
+ ///
+ /// \param str query to execute
+ /// \param te if false, no exceptions will be thrown on errors.
+ ///
+ /// \return true if query was executed successfully
+ bool exec(const std::string& str, bool te);
+
/// \brief Create a database
///
/// \param db name of database to create
diff -upr mysql++-1.7.40.orig/lib/query.cpp mysql++-1.7.40/lib/query.cpp
--- mysql++-1.7.40.orig/lib/query.cpp 2005-05-10 21:20:45.000000000 +0200
+++ mysql++-1.7.40/lib/query.cpp 2005-05-28 18:11:33.182574272 +0200
@@ -37,7 +37,7 @@ throw_exceptions(q.throw_exceptions)

bool Query::exec(const std::string& str)
{
- return mysql->exec(str);
+ return mysql->exec(str, throw_exceptions);
}

bool Query::success()
@@ -55,35 +55,35 @@ bool Query::success()

ResNSel Query::execute(const char* str)
{
- return mysql->execute(str);
+ return mysql->execute(str, throw_exceptions);
}

ResNSel Query::execute(parms& p)
{
query_reset r = parsed.size() ? DONT_RESET : RESET_QUERY;
- return mysql->execute(str(p, r));
+ return mysql->execute(str(p, r), throw_exceptions);
}

ResUse Query::use(const char* str)
{
- return mysql->use(str);
+ return mysql->use(str, throw_exceptions);
}

ResUse Query::use(parms& p)
{
query_reset r = parsed.size() ? DONT_RESET : RESET_QUERY;
- return mysql->use(str(p, r));
+ return mysql->use(str(p, r), throw_exceptions);
}

Result Query::store(const char* str)
{
- return mysql->store(str);
+ return mysql->store(str, throw_exceptions);
}

Result Query::store(parms& p)
{
query_reset r = parsed.size() ? DONT_RESET : RESET_QUERY;
- return mysql->store(str(p, r));
+ return mysql->store(str(p, r), throw_exceptions);
}

/// \endif






--------------000109090003030903040503
Content-Type: text/plain; charset=us-ascii

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw
--------------000109090003030903040503--

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.