Author: wyoung
Date: Fri Jan 12 07:41:44 2007
New Revision: 1355
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1355&view=rev
Log:
Template queries were broken. Easy symptom was trying to run resetdb.
Was caused by the Query::execute/store/use() call chain reorganization
allowing nulls in query strings. Because the reorg repurposed the
1-parameter template query version of these functions, we now end up
going through this function twice in some cases, and were getting the
cases wrong, causing it to call itself over and over again.
This adds the new AutoFlag<T> template. It's just a utility object
which makes the fixed code simpler.
Added:
trunk/lib/autoflag.h
Modified:
trunk/Wishlist
trunk/lib/qparms.h
trunk/lib/query.cpp
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1355&r1=1354&r2=1355&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Fri Jan 12 07:41:44 2007
@@ -38,9 +38,6 @@
it's linked to the same version. Prevents errors caused
by not using exrun script when running examples with a
different library version installed.
-
- o resetdb is hanging in Query::execute() on RHEL 3 test system.
- Find out why.
o Sort out the localtime_r thing on MinGW.
Added: trunk/lib/autoflag.h
URL: http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/autoflag.h?rev=1355&view=auto
==============================================================================
--- trunk/lib/autoflag.h (added)
+++ trunk/lib/autoflag.h Fri Jan 12 07:41:44 2007
@@ -1,0 +1,54 @@
+/// \file autoflag.h
+/// \brief Defines a template for setting a flag on a variable as long
+/// as the object that set it is in scope. Flag resets when object goes
+/// out of scope. Works on anything that looks like bool.
+
+/***********************************************************************
+ Copyright (c) 2007 by Educational Technology Resources, Inc. Others
+ may also hold copyrights on code in this file. See the CREDITS file in
+ the top directory of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#if !defined(MYSQLPP_AUTOFLAG_H)
+#define MYSQLPP_AUTOFLAG_H
+
+template <class T = bool>
+class AutoFlag
+{
+public:
+ /// \brief Constructor: sets ref to true.
+ AutoFlag(T& ref) :
+ referent_(ref)
+ {
+ referent_ = true;
+ }
+
+ /// \brief Destructor: sets referent passed to ctor to false.
+ ~AutoFlag()
+ {
+ referent_ = false;
+ }
+
+private:
+ T& referent_;
+};
+
+#endif // !defined(MYSQLPP_AUTOFLAG_H)
+
Modified: trunk/lib/qparms.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/qparms.h?rev=1355&r1=1354&r2=1355&view=diff
==============================================================================
--- trunk/lib/qparms.h (original)
+++ trunk/lib/qparms.h Fri Jan 12 07:41:44 2007
@@ -52,7 +52,8 @@
/// \brief Default constructor
SQLQueryParms() :
- parent_(0)
+ parent_(0),
+ processing_(false)
{
}
@@ -61,7 +62,8 @@
/// \param p pointer to the query object these parameters are tied
/// to
SQLQueryParms(Query* p) :
- parent_(p)
+ parent_(p),
+ processing_(false)
{
}
@@ -200,6 +202,7 @@
friend class Query;
Query* parent_;
+ bool processing_; ///< true if we're building a query string
};
Modified: trunk/lib/query.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.cpp?rev=1355&r1=1354&r2=1355&view=diff
==============================================================================
--- trunk/lib/query.cpp (original)
+++ trunk/lib/query.cpp Fri Jan 12 07:41:44 2007
@@ -26,6 +26,7 @@
#include "query.h"
+#include "autoflag.h"
#include "connection.h"
namespace mysqlpp {
@@ -106,8 +107,12 @@
ResNSel
Query::execute(const SQLString& str)
{
- if (def.size()) {
- // Take str to be a template query parameter
+ if ((def.size() == 1) && !def.processing_) {
+ // Take str to be a lone parameter for a template query. The
+ // auto-reset flag is required because we'll end up back in this
+ // function once the query string is built, but we need to take
+ // the 'else' path to avoid an infinite loop.
+ AutoFlag<> af(def.processing_);
return execute(SQLQueryParms() << str);
}
else {
@@ -402,8 +407,12 @@
Result
Query::store(const SQLString& str)
{
- if (def.size()) {
- // Take str to be a template query parameter
+ if ((def.size() == 1) && !def.processing_) {
+ // Take str to be a lone parameter for a template query. The
+ // auto-reset flag is required because we'll end up back in this
+ // function once the query string is built, but we need to take
+ // the 'else' path to avoid an infinite loop.
+ AutoFlag<> af(def.processing_);
return store(SQLQueryParms() << str);
}
else {
@@ -570,8 +579,12 @@
ResUse
Query::use(const SQLString& str)
{
- if (def.size()) {
- // Take str to be a template query parameter
+ if ((def.size() == 1) && !def.processing_) {
+ // Take str to be a lone parameter for a template query. The
+ // auto-reset flag is required because we'll end up back in this
+ // function once the query string is built, but we need to take
+ // the 'else' path to avoid an infinite loop.
+ AutoFlag<> af(def.processing_);
return use(SQLQueryParms() << str);
}
else {
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits