Author: wyoung
Date: Fri Dec  4 17:46:51 2009
New Revision: 2590

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2590&view=rev
Log:
- Better handling of 1-parameter template queries
- Restored support for repeating query parameters.  Apparently you could
  say things like "stuff %0 morestuff %0" in v2.1, but this was broken
  by initial 1-parameter fixes in v2.2.  This patch reportedly lets us
  have both things at once.  (This and previous fix by Martin Gallwey
  <[email protected]>)
- Added tquery4 example based on test code from Martin

Added:
    trunk/examples/tquery4.cpp
Modified:
    trunk/Wishlist
    trunk/lib/query.cpp
    trunk/lib/query.h
    trunk/mysql++.bkl

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=2590&r1=2589&r2=2590&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Fri Dec  4 17:46:51 2009
@@ -31,13 +31,6 @@
     o Need to link statically to connect to MySQL Embedded?
 
       
http://stackoverflow.com/questions/672451/howto-communicate-with-mysql-embedded-server-from-mysql-dll
-
-    o Got a report that tqueries no longer support repeated
-      placeholders in v3.  Can you say "stuff %0 morestuff %0" still?
-
-    o Look for better way to handle single string parameter for
-      tqueries, which allows that to be disambiguated relative to the
-      raw query string case.
 
 
 v3.1 Tentative Plan

Added: trunk/examples/tquery4.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/tquery4.cpp?rev=2590&view=auto
==============================================================================
--- trunk/examples/tquery4.cpp (added)
+++ trunk/examples/tquery4.cpp Fri Dec  4 17:46:51 2009
@@ -1,0 +1,80 @@
+/***********************************************************************
+ tquery4.cpp - Tests other details about template queries, like unquoted
+       parameters and multiple parameters.  This exists more for code
+       coverage than to demonstrate the library.
+
+ Copyright (c) 2009 by Martin Gallwey and (c) 2009 by Educational
+ Technology Resources, Inc.  Others may also hold copyrights on code
+ in this file.  See the CREDITS.txt 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
+***********************************************************************/
+
+#include "cmdline.h"
+#include "printdata.h"
+
+#include <iostream>
+
+using namespace std;
+
+int
+main(int argc, char *argv[])
+{
+       // Get database access parameters from command line
+       mysqlpp::examples::CommandLine cmdline(argc, argv);
+       if (!cmdline) {
+               return 1;
+       }
+
+       try {
+               // Establish the connection to the database server.
+               mysqlpp::Connection con(mysqlpp::examples::db_name,
+                               cmdline.server(), cmdline.user(), 
cmdline.pass());
+
+               // Modify an item using two named template query parameters
+               mysqlpp::Query query = con.query("update stock "
+                               "set num = %0:quantity where num < 
%0:quantity");
+               query.parse();
+               query.template_defaults["quantity"] = 70;
+               cout << "Query: " << query << endl;
+               mysqlpp::SimpleResult result = query.execute();
+
+               // Print the new table contents.
+               print_stock_table(query);
+       }
+       catch (const mysqlpp::BadQuery& er) {
+               // Handle any query errors
+               cerr << "Query error: " << er.what() << endl;
+               return -1;
+       }
+       catch (const mysqlpp::BadConversion& er) {
+               // Handle bad conversions
+               cerr << "Conversion error: " << er.what() << endl <<
+                               "\tretrieved data size: " << er.retrieved <<
+                               ", actual size: " << er.actual_size << endl;
+               return -1;
+       }
+       catch (const mysqlpp::Exception& er) {
+               // Catch-all for any other MySQL++ exceptions
+               cerr << "Error: " << er.what() << endl;
+               return -1;
+       }
+
+       return 0;
+}

Modified: trunk/lib/query.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.cpp?rev=2590&r1=2589&r2=2590&view=diff
==============================================================================
--- trunk/lib/query.cpp (original)
+++ trunk/lib/query.cpp Fri Dec  4 17:46:51 2009
@@ -160,6 +160,14 @@
 }
 
 
+SimpleResult 
+Query::execute() 
+{ 
+       AutoFlag<> af(template_defaults.processing_);
+       return execute(str(template_defaults)); 
+}
+
+
 SimpleResult
 Query::execute(SQLQueryParms& p)
 {
@@ -171,7 +179,7 @@
 SimpleResult
 Query::execute(const SQLTypeAdapter& s)
 {
-       if ((parse_elems_.size() == 2) && !template_defaults.processing_) {
+       if (!parse_elems_.empty() && !template_defaults.processing_) {
                // We're a template query and this isn't a recursive call, so
                // take s to be a lone parameter for the query.  We will come
                // back in here with a completed query, but the processing_
@@ -189,6 +197,14 @@
 SimpleResult
 Query::execute(const char* str, size_t len)
 {
+       if (!parse_elems_.empty() && !template_defaults.processing_) {
+               // We're a template query and this isn't a recursive call, so
+               // take s to be a lone parameter for the query.  We will come
+               // back in here with a completed query, but the processing_
+               // flag will be set, allowing us to avoid an infinite loop.
+               AutoFlag<> af(template_defaults.processing_);
+               return execute(SQLQueryParms() << str << len );
+       }
        if ((copacetic_ = conn_->driver()->execute(str, len)) == true) {
                if (parse_elems_.size() == 0) {
                        // Not a template query, so auto-reset
@@ -456,6 +472,14 @@
 }
 
 
+StoreQueryResult 
+Query::store() 
+{ 
+       AutoFlag<> af(template_defaults.processing_);
+       return store(str(template_defaults)); 
+}
+
+
 StoreQueryResult
 Query::store(SQLQueryParms& p)
 {
@@ -467,7 +491,7 @@
 StoreQueryResult
 Query::store(const SQLTypeAdapter& s)
 {
-       if ((parse_elems_.size() == 2) && !template_defaults.processing_) {
+       if (!parse_elems_.empty() && !template_defaults.processing_) {
                // We're a template query and this isn't a recursive call, so
                // take s to be a lone parameter for the query.  We will come
                // back in here with a completed query, but the processing_
@@ -485,6 +509,14 @@
 StoreQueryResult
 Query::store(const char* str, size_t len)
 {
+       if (!parse_elems_.empty() && !template_defaults.processing_) {
+               // We're a template query and this isn't a recursive call, so
+               // take s to be a lone parameter for the query.  We will come
+               // back in here with a completed query, but the processing_
+               // flag will be set, allowing us to avoid an infinite loop.
+               AutoFlag<> af(template_defaults.processing_);
+               return store(SQLQueryParms() << str << len );
+       }
        MYSQL_RES* res = 0;
        if ((copacetic_ = conn_->driver()->execute(str, len)) == true) {
                res = conn_->driver()->store_result();
@@ -577,6 +609,14 @@
 }
 
 
+UseQueryResult 
+Query::use() 
+{ 
+       AutoFlag<> af(template_defaults.processing_);
+       return use(str(template_defaults)); 
+}
+
+
 UseQueryResult
 Query::use(SQLQueryParms& p)
 {
@@ -588,7 +628,7 @@
 UseQueryResult
 Query::use(const SQLTypeAdapter& s)
 {
-       if ((parse_elems_.size() == 2) && !template_defaults.processing_) {
+       if (!parse_elems_.empty()  && !template_defaults.processing_) {
                // We're a template query and this isn't a recursive call, so
                // take s to be a lone parameter for the query.  We will come
                // back in here with a completed query, but the processing_
@@ -606,6 +646,14 @@
 UseQueryResult
 Query::use(const char* str, size_t len)
 {
+       if (!parse_elems_.empty() && !template_defaults.processing_) {
+               // We're a template query and this isn't a recursive call, so
+               // take s to be a lone parameter for the query.  We will come
+               // back in here with a completed query, but the processing_
+               // flag will be set, allowing us to avoid an infinite loop.
+               AutoFlag<> af(template_defaults.processing_);
+               return use(SQLQueryParms() << str << len );
+       }
        MYSQL_RES* res = 0;
        if ((copacetic_ = conn_->driver()->execute(str, len)) == true) {
                res = conn_->driver()->use_result();

Modified: trunk/lib/query.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.h?rev=2590&r1=2589&r2=2590&view=diff
==============================================================================
--- trunk/lib/query.h (original)
+++ trunk/lib/query.h Fri Dec  4 17:46:51 2009
@@ -331,7 +331,7 @@
        /// \return SimpleResult status information about the query
        ///
        /// \sa exec(), store(), storein(), and use()
-       SimpleResult execute() { return execute(str(template_defaults)); }
+       SimpleResult execute(); 
 
        /// \brief Execute template query using given parameters.
        ///
@@ -392,7 +392,7 @@
        /// \return UseQueryResult object that can walk through result set 
serially
        ///
        /// \sa exec(), execute(), store() and storein()
-       UseQueryResult use() { return use(str(template_defaults)); }
+       UseQueryResult use();
 
        /// \brief Execute a template query that can return rows, with
        /// access to the rows in sequence
@@ -456,7 +456,7 @@
        /// \return StoreQueryResult object containing entire result set
        ///
        /// \sa exec(), execute(), storein(), and use()
-       StoreQueryResult store() { return store(str(template_defaults)); }
+       StoreQueryResult store();
 
        /// \brief Store results from a template query using given parameters.
        ///

Modified: trunk/mysql++.bkl
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/mysql%2B%2B.bkl?rev=2590&r1=2589&r2=2590&view=diff
==============================================================================
--- trunk/mysql++.bkl (original)
+++ trunk/mysql++.bkl Fri Dec  4 17:46:51 2009
@@ -362,6 +362,9 @@
     <exe id="tquery3" template="libexcommon-user,programs">
       <sources>examples/tquery3.cpp</sources>
     </exe>
+    <exe id="tquery4" template="libexcommon-user,programs">
+      <sources>examples/tquery4.cpp</sources>
+    </exe>
     <if cond="FORMAT!='msvs2003prj'">
       <!-- VC++ 2003 can't compile current SSQLS code -->
       <exe id="transaction" template="libexcommon-user,programs">


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to