Author: wyoung
Date: Thu Jun 28 07:51:37 2007
New Revision: 1633

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1633&view=rev
Log:
Added another Query::store_if() overload that takes an SSQLS exemplar,
and builds a query string from that.  Using that new overload in the
store_if example.

Modified:
    trunk/doc/userman/userman.dbx
    trunk/examples/store_if.cpp
    trunk/lib/query.h

Modified: trunk/doc/userman/userman.dbx
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/doc/userman/userman.dbx?rev=1633&r1=1632&r2=1633&view=diff
==============================================================================
--- trunk/doc/userman/userman.dbx (original)
+++ trunk/doc/userman/userman.dbx Thu Jun 28 07:51:37 2007
@@ -865,6 +865,13 @@
         you a container full of results meeting a criterion that you
         probably can't express in SQL. You will no doubt have much
         more useful criteria in your own programs.</para>
+
+        <para>If you need a more complex query than the one
+        <methodname>store_if()</methodname> knows how to build when
+        given an SSQLS examplar, there are two overloads that let
+        you use your own query string. One overload takes the query
+        string directly, and the other uses the query string built
+        with <classname>Query</classname>'s stream interface.</para>
     </sect2>
 
 
@@ -895,14 +902,10 @@
         SQL, but we're trying to prevent the complexity of the code
         from getting in the way of the demonstration here.</para>
 
-        <para>If you need a more complex query than the one
-        <methodname>for_each()</methodname> knows how to build,
-        there are two overloads that let you use your own query
-        string. One just takes a functor and uses the query string
-        held within the <classname>Query</classname> object, which
-        you probably built up using <classname>Query</classname>'s
-        stream interface. The other overload just takes the query
-        string directly, along with the functor.</para>
+        <para>Just as with <methodname>store_if()</methodname>,
+        described above, there are two other overloads for
+        <methodname>for_each()</methodname> that let you use your
+        own query string.</para>
     </sect2>
 
 

Modified: trunk/examples/store_if.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/store_if.cpp?rev=1633&r1=1632&r2=1633&view=diff
==============================================================================
--- trunk/examples/store_if.cpp (original)
+++ trunk/examples/store_if.cpp Thu Jun 28 07:51:37 2007
@@ -71,10 +71,10 @@
                        return 1;
                }
 
-               // Pull only the stock items with prime quantities
+               // Collect the stock items with prime quantities
                std::vector<stock> results;
                mysqlpp::Query query = con.query();
-               query.store_if(results, "select * from stock", is_prime());
+               query.store_if(results, stock(), is_prime());
 
                // Show the results
                print_stock_header(results.size());

Modified: trunk/lib/query.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.h?rev=1633&r1=1632&r2=1633&view=diff
==============================================================================
--- trunk/lib/query.h (original)
+++ trunk/lib/query.h Thu Jun 28 07:51:37 2007
@@ -476,6 +476,35 @@
                return fn;
        }
 
+       /// \brief Pulls every row in a table, conditionally storing each
+       /// one in a container
+       ///
+       /// Just like store_if(Sequence&, const SQLString&, Function), but
+       /// it uses the SSQLS instance to construct a "select * from TABLE"
+       /// query, using the table name field in the SSQLS.
+       ///
+       /// \param seq the destination container; needs a push_back() method
+       /// \param ssqls the SSQLS instance to get a table name from
+       /// \param fn the functor called for each row
+       /// \return a copy of the passed functor
+       template <class Sequence, class SSQLS, typename Function>
+       Function store_if(Sequence& seq, const SSQLS& ssqls, Function fn)
+       {       
+               SQLString query("select * from ");
+               query += ssqls._table;
+               mysqlpp::ResUse res = use(query);
+               if (res) {
+                       mysqlpp::NoExceptions ne(res);
+                       while (mysqlpp::Row row = res.fetch_row()) {
+                               if (fn(row)) {
+                                       seq.push_back(row);
+                               }
+                       }
+               }
+
+               return fn;
+       }
+
        /// \brief Execute the query, conditionally storing each row in a
        /// container
        ///


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

Reply via email to