Author: wyoung
Date: Tue Jul 17 17:07:10 2007
New Revision: 1706
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1706&view=rev
Log:
Added feature to Connection and Query allowing creation of a Query
object that starts out populated with a query string. This is useful
when the query string (or a template for the query string) is static,
allowing you to avoid a two-step creation.
Modified:
trunk/examples/custom1.cpp
trunk/examples/custom3.cpp
trunk/examples/custom4.cpp
trunk/examples/custom5.cpp
trunk/examples/custom6.cpp
trunk/examples/dbinfo.cpp
trunk/examples/fieldinf1.cpp
trunk/examples/simple1.cpp
trunk/examples/simple2.cpp
trunk/examples/simple3.cpp
trunk/examples/tquery1.cpp
trunk/examples/tquery2.cpp
trunk/examples/usequery.cpp
trunk/lib/connection.cpp
trunk/lib/connection.h
trunk/lib/query.cpp
trunk/lib/query.h
Modified: trunk/examples/custom1.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom1.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/custom1.cpp (original)
+++ trunk/examples/custom1.cpp Tue Jul 17 17:07:10 2007
@@ -4,7 +4,7 @@
MySQL++ Result object.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-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.
@@ -48,8 +48,7 @@
// Retrieve the entire contents of the stock table, and store
// the data in a vector of 'stock' SSQLS structures.
- mysqlpp::Query query = con.query();
- query << "select * from stock";
+ mysqlpp::Query query = con.query("select * from stock");
vector<stock> res;
query.storein(res);
Modified: trunk/examples/custom3.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom3.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/custom3.cpp (original)
+++ trunk/examples/custom3.cpp Tue Jul 17 17:07:10 2007
@@ -44,8 +44,8 @@
// Build a query to retrieve the stock item that has Unicode
// characters encoded in UTF-8 form.
- mysqlpp::Query query = con.query();
- query << "select * from stock where item = \"Nürnberger
Brats\"";
+ mysqlpp::Query query = con.query(
+ "select * from stock where item = \"Nürnberger
Brats\"");
// Retrieve the row, throwing an exception if it fails.
mysqlpp::Result res = query.store();
Modified: trunk/examples/custom4.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom4.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/custom4.cpp (original)
+++ trunk/examples/custom4.cpp Tue Jul 17 17:07:10 2007
@@ -5,7 +5,7 @@
style.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-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.
@@ -48,8 +48,7 @@
// STL set. Notice that this works just as well as storing them
// in a vector, which we did in custom1.cpp. It works because
// SSQLS objects are less-than comparable.
- mysqlpp::Query query = con.query();
- query << "select * from stock";
+ mysqlpp::Query query = con.query("select * from stock");
set<stock> res;
query.storein(res);
Modified: trunk/examples/custom5.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom5.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/custom5.cpp (original)
+++ trunk/examples/custom5.cpp Tue Jul 17 17:07:10 2007
@@ -3,7 +3,7 @@
some SSQLS types to build SELECT queries with custom WHERE clauses.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, (c) 2004, 2005 by Educational Technology Resources, Inc., and
+ MySQL AB, (c) 2004-2007 by Educational Technology Resources, Inc., and
(c) 2005 by Chris Frey. Others may also hold copyrights on code in
this file. See the CREDITS file in the top directory of the
distribution for details.
@@ -44,8 +44,7 @@
}
// Get all the rows in the stock table.
- mysqlpp::Query query = con.query();
- query << "select * from stock";
+ mysqlpp::Query query = con.query("select * from stock");
vector<stock> res;
query.storein(res);
@@ -54,7 +53,7 @@
// returned by our previous query.
query.reset();
query << "select * from stock where " <<
- res[0].equal_list(" and ", stock_weight,
stock_price);
+ res[0].equal_list(" and ",
stock_weight, stock_price);
// Display the finished query.
cout << "Custom query:\n" << query.preview() << endl;
Modified: trunk/examples/custom6.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom6.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/custom6.cpp (original)
+++ trunk/examples/custom6.cpp Tue Jul 17 17:07:10 2007
@@ -4,7 +4,7 @@
the same thing, without using SSQLS.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-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.
@@ -56,8 +56,7 @@
// Retrieve a subset of the stock table, and store the data in
// a vector of 'stock_subset' SSQLS structures.
- mysqlpp::Query query = con.query();
- query << "select item from stock";
+ mysqlpp::Query query = con.query("select item from stock");
vector<stock_subset> res;
query.storein(res);
Modified: trunk/examples/dbinfo.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/dbinfo.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/dbinfo.cpp (original)
+++ trunk/examples/dbinfo.cpp Tue Jul 17 17:07:10 2007
@@ -52,10 +52,9 @@
// Show MySQL version
cout << "MySQL version: " << con.client_info() << separator;
- mysqlpp::Query query = con.query();
// Show all the databases we can see
- query << "show databases";
+ mysqlpp::Query query = con.query("show databases");
cout << "Query: " << query.preview() << endl;
mysqlpp::Result res = query.store();
Modified: trunk/examples/fieldinf1.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/fieldinf1.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/fieldinf1.cpp (original)
+++ trunk/examples/fieldinf1.cpp Tue Jul 17 17:07:10 2007
@@ -4,7 +4,7 @@
MySQL++ sees it.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-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.
@@ -45,8 +45,7 @@
return 1;
}
- Query query = con.query();
- query << "select * from stock";
+ Query query = con.query("select * from stock");
cout << "Query: " << query.preview() << endl;
Result res = query.store();
Modified: trunk/examples/simple1.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/simple1.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/simple1.cpp (original)
+++ trunk/examples/simple1.cpp Tue Jul 17 17:07:10 2007
@@ -44,8 +44,7 @@
}
// Retrieve a subset of the sample stock table set up by resetdb
- mysqlpp::Query query = con.query();
- query << "select item from stock";
+ mysqlpp::Query query = con.query("select item from stock");
mysqlpp::Result res = query.store();
// Display the result set
Modified: trunk/examples/simple2.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/simple2.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/simple2.cpp (original)
+++ trunk/examples/simple2.cpp Tue Jul 17 17:07:10 2007
@@ -44,8 +44,7 @@
}
// Retrieve the sample stock table set up by resetdb
- mysqlpp::Query query = con.query();
- query << "select * from stock";
+ mysqlpp::Query query = con.query("select * from stock");
mysqlpp::Result res = query.store();
// Display results
Modified: trunk/examples/simple3.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/simple3.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/simple3.cpp (original)
+++ trunk/examples/simple3.cpp Tue Jul 17 17:07:10 2007
@@ -3,7 +3,7 @@
a table, as opposed to the more common 'store' method illustrated
by the simple2 example.
- Copyright (c) 2005 by Educational Technology Resources, Inc.
+ Copyright (c) 2005-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.
@@ -45,8 +45,7 @@
// Ask for all rows from the sample stock table set up by resetdb.
// Unlike simple2 example, we don't store result set in memory.
- mysqlpp::Query query = con.query();
- query << "select * from stock";
+ mysqlpp::Query query = con.query("select * from stock");
mysqlpp::ResUse res = query.use();
// Retreive result rows one by one, and display them.
Modified: trunk/examples/tquery1.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/tquery1.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/tquery1.cpp (original)
+++ trunk/examples/tquery1.cpp Tue Jul 17 17:07:10 2007
@@ -43,8 +43,8 @@
// Build a template query to retrieve a stock item given by
// item name.
- mysqlpp::Query query = con.query();
- query << "select * from stock where item = %0q";
+ mysqlpp::Query query = con.query(
+ "select * from stock where item = %0q");
query.parse();
// Retrieve an item added by resetdb; it won't be there if
Modified: trunk/examples/tquery2.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/tquery2.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/tquery2.cpp (original)
+++ trunk/examples/tquery2.cpp Tue Jul 17 17:07:10 2007
@@ -46,8 +46,8 @@
// Build a template query to retrieve a stock item given by
// item name.
- mysqlpp::Query query = con.query();
- query << "select * from stock where item = %0q";
+ mysqlpp::Query query = con.query(
+ "select * from stock where item = %0q");
query.parse();
// Retrieve an item added by resetdb; it won't be there if
Modified: trunk/examples/usequery.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/usequery.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/examples/usequery.cpp (original)
+++ trunk/examples/usequery.cpp Tue Jul 17 17:07:10 2007
@@ -2,7 +2,7 @@
usequery.cpp - Same as simple3 example, only with exceptions enabled.
The end of the result set is signalled differently in this case.
- Copyright (c) 2005 by Educational Technology Resources, Inc.
+ Copyright (c) 2005-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.
@@ -41,8 +41,7 @@
}
// Build query to retrieve the entire stock table
- mysqlpp::Query query = con.query();
- query << "select * from stock";
+ mysqlpp::Query query = con.query("select * from stock");
// Execute the query, but don't save results in memory
mysqlpp::ResUse res = query.use();
Modified: trunk/lib/connection.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/lib/connection.cpp (original)
+++ trunk/lib/connection.cpp Tue Jul 17 17:07:10 2007
@@ -2,7 +2,7 @@
connection.cpp - Implements the Connection class.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004-2006 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-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.
@@ -410,9 +410,9 @@
Query
-Connection::query()
-{
- return Query(this, throw_exceptions());
+Connection::query(const char* qstr)
+{
+ return Query(this, throw_exceptions(), qstr);
}
Modified: trunk/lib/connection.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.h?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/lib/connection.h (original)
+++ trunk/lib/connection.h Tue Jul 17 17:07:10 2007
@@ -232,7 +232,10 @@
/// \link mysqlpp::Query::execute() execute() \endlink
/// on that object, the query is sent to the server this object
/// is connected to.
- Query query();
+ ///
+ /// \param qstr an optional query string for populating the
+ /// new Query object
+ Query query(const char* qstr = 0);
/// \brief Test whether the connection has experienced an error
/// condition.
Modified: trunk/lib/query.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.cpp?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/lib/query.cpp (original)
+++ trunk/lib/query.cpp Tue Jul 17 17:07:10 2007
@@ -31,7 +31,7 @@
namespace mysqlpp {
-Query::Query(Connection* c, bool te) :
+Query::Query(Connection* c, bool te, const char* qstr) :
#if defined(_MSC_VER) && !defined(_STLP_VERSION) && !defined(_STLP_VERSION_STR)
// prevents a double-init memory leak in native VC++ RTL (not STLport!)
std::ostream(std::_Noinit),
@@ -45,6 +45,9 @@
copacetic_(true)
{
init(&sbuffer_);
+ if (qstr) {
+ sbuffer_.str(qstr);
+ }
}
Query::Query(const Query& q) :
Modified: trunk/lib/query.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.h?rev=1706&r1=1705&r2=1706&view=diff
==============================================================================
--- trunk/lib/query.h (original)
+++ trunk/lib/query.h Tue Jul 17 17:07:10 2007
@@ -3,7 +3,7 @@
/***********************************************************************
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004-2006 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-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.
@@ -133,7 +133,8 @@
///
/// \param c connection the finished query should be sent out on
/// \param te if true, throw exceptions on errors
- Query(Connection* c, bool te = true);
+ /// \param qstr an optional initial query string
+ Query(Connection* c, bool te = true, const char* qstr = 0);
/// \brief Create a new query object as a copy of another.
///
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits