Author: mysqlpp
Date: Tue Mar 30 20:51:42 2010
New Revision: 2627

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2627&view=rev
Log:
Added Query::replace(iter, iter), on the model of existing
insert(iter, iter).  Patch by David Walthour <[email protected]>

Modified:
    trunk/lib/query.h

Modified: trunk/lib/query.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.h?rev=2627&r1=2626&r2=2627&view=diff
==============================================================================
--- trunk/lib/query.h (original)
+++ trunk/lib/query.h Tue Mar 30 20:51:42 2010
@@ -1117,6 +1117,42 @@
                return *this;
        }
 
+       /// \brief Insert multiple new rows, or replace existing ones if
+       /// there are existing rows that match on key fields.
+       ///
+       /// Builds a REPLACE SQL query using items from a range within an
+       /// STL container.  Insert the entire contents of the container by
+       /// using the begin() and end() iterators of the container as
+       /// parameters to this function.
+       ///
+       /// \param first iterator pointing to first element in range to
+       ///    insert/replace
+       /// \param last iterator pointing to one past the last element to
+       ///    insert/replace
+       ///
+       /// \sa insertfrom(), replace(), update()
+       template <class Iter>
+       Query& replace(Iter first, Iter last)
+       {
+               reset();
+               if (first == last) {
+                       return *this;    // empty set!
+               }
+
+               MYSQLPP_QUERY_THISPTR << std::setprecision(16) <<
+                               "REPLACE INTO " << first->table() << " (" <<
+                               first->field_list() << ") VALUES (" <<
+                               first->value_list() << ')';
+
+               Iter it = first + 1;
+               while (it != last) {
+                       MYSQLPP_QUERY_THISPTR << ",(" << it->value_list() << 
')';
+                       ++it;
+               }
+
+               return *this;
+       }       
+
 #if !defined(DOXYGEN_IGNORE)
        // Declare the remaining overloads.  These are hidden down here partly
        // to keep the above code clear, but also so that we may hide them


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

Reply via email to