Author: wyoung
Date: Mon Jul 16 20:16:54 2007
New Revision: 1701
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1701&view=rev
Log:
Replaced Query methods that took a SQLQueryParms object for template
query parameters. Turns out that there are valid uses for them
externally after all. Because of that, these methods now have Doxygen
comments; they're not just internal-use-only helper functions any more.
Modified:
trunk/Wishlist
trunk/lib/query.cpp
trunk/lib/query.h
trunk/lib/querydef.pl
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1701&r1=1700&r2=1701&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Mon Jul 16 20:16:54 2007
@@ -12,11 +12,6 @@
The items in this section are those things we definitely want to
get done in v3.0. Most of them break the ABI, so they can't wait
for a future version, because v4 could be years out.
-
- o Restore execute(SQLQueryParams&) et al., make them public,
- and document them in both userman and refman. Needed for the
- uncommon case where you don't know the number of parameters at
- compile time.
o Fix single-parameter template query stuff.
Modified: trunk/lib/query.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.cpp?rev=1701&r1=1700&r2=1701&view=diff
==============================================================================
--- trunk/lib/query.cpp (original)
+++ trunk/lib/query.cpp Mon Jul 16 20:16:54 2007
@@ -99,6 +99,13 @@
ResNSel
+Query::execute(SQLQueryParms& p)
+{
+ return execute(str(p));
+}
+
+
+ResNSel
Query::execute(const SQLString& s)
{
if ((parse_elems_.size() == 2) && !template_defaults.processing_) {
@@ -108,7 +115,7 @@
// query, but the processing_ flag will be reset, allowing us to
// take the 'else' path, avoiding an infinite loop.
AutoFlag<> af(template_defaults.processing_);
- return execute(str(SQLQueryParms() << s));
+ return execute(SQLQueryParms() << s);
}
else {
// Take s to be the entire query string
@@ -379,6 +386,13 @@
}
+Result
+Query::store(SQLQueryParms& p)
+{
+ return store(str(p));
+}
+
+
Result
Query::store(const SQLString& s)
{
@@ -389,7 +403,7 @@
// query, but the processing_ flag will be reset, allowing us to
// take the 'else' path, avoiding an infinite loop.
AutoFlag<> af(template_defaults.processing_);
- return store(str(SQLQueryParms() << s));
+ return store(SQLQueryParms() << s);
}
else {
// Take s to be the entire query string
@@ -514,6 +528,13 @@
ResUse
+Query::use(SQLQueryParms& p)
+{
+ return use(str(p));
+}
+
+
+ResUse
Query::use(const SQLString& s)
{
if ((parse_elems_.size() == 2) && !template_defaults.processing_) {
@@ -523,7 +544,7 @@
// query, but the processing_ flag will be reset, allowing us to
// take the 'else' path, avoiding an infinite loop.
AutoFlag<> af(template_defaults.processing_);
- return use(str(SQLQueryParms() << s));
+ return use(SQLQueryParms() << s);
}
else {
// Take s to be the entire query string
Modified: trunk/lib/query.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.h?rev=1701&r1=1700&r2=1701&view=diff
==============================================================================
--- trunk/lib/query.h (original)
+++ trunk/lib/query.h Mon Jul 16 20:16:54 2007
@@ -202,8 +202,7 @@
///
/// \param arg0 the value to substitute for the first template query
/// parameter
- std::string preview(const SQLString& arg0)
- { return str(SQLQueryParms() << arg0); }
+ std::string preview(const SQLString& arg0) { return str(arg0); }
/// \brief Return the query string currently in the buffer.
std::string preview(SQLQueryParms& p) { return str(p); }
@@ -255,6 +254,16 @@
///
/// \sa exec(), store(), storein(), and use()
ResNSel execute() { return execute(str(template_defaults)); }
+
+ /// \brief Execute template query using given parameters.
+ ///
+ /// This method should only be used by code that doesn't know,
+ /// at compile time, how many parameters it will have. This is
+ /// useful within the library, and also for code that builds
+ /// template queries dynamically, at run time.
+ ///
+ /// \param p parameters to use in the template query.
+ ResNSel execute(SQLQueryParms& p);
/// \brief Execute query in a C++ string, or substitute string into
/// a template query and execute it.
@@ -296,18 +305,28 @@
/// \sa exec(), execute(), store() and storein()
ResUse use() { return use(str(template_defaults)); }
+ /// \brief Get results from a template query using given parameters.
+ ///
+ /// This method should only be used by code that doesn't know,
+ /// at compile time, how many parameters it will have. This is
+ /// useful within the library, and also for code that builds
+ /// template queries dynamically, at run time.
+ ///
+ /// \param p parameters to use in the template query.
+ ResUse use(SQLQueryParms& p);
+
/// \brief Execute query in a C++ string
///
/// Executes the query immediately, and returns an object that
/// lets you walk through the result set one row at a time, in
- /// sequence. This is more memory-efficient than store().
+ /// conuence. This is more memory-efficient than store().
ResUse use(const SQLString& str);
/// \brief Execute query in a known-length C string
///
/// Executes the query immediately, and returns an object that
/// lets you walk through the result set one row at a time, in
- /// sequence. This is more memory-efficient than store().
+ /// conuence. This is more memory-efficient than store().
ResUse use(const char* str, size_t len);
/// \brief Execute a query that can return a result set
@@ -332,6 +351,16 @@
///
/// \sa exec(), execute(), storein(), and use()
Result store() { return store(str(template_defaults)); }
+
+ /// \brief Store results from a template query using given parameters.
+ ///
+ /// This method should only be used by code that doesn't know,
+ /// at compile time, how many parameters it will have. This is
+ /// useful within the library, and also for code that builds
+ /// template queries dynamically, at run time.
+ ///
+ /// \param p parameters to use in the template query.
+ Result store(SQLQueryParms& p);
/// \brief Execute query in a C++ string
///
@@ -423,7 +452,7 @@
///
/// This method wraps a use() query, calling the given functor for
/// every returned row, and storing the results in the given
- /// sequence container if the functor returns true.
+ /// conuence container if the functor returns true.
///
/// This is analogous to the STL copy_if() algorithm, except that
/// the source rows come from a database query instead of another
@@ -433,19 +462,19 @@
/// container is the destination, the query is the source, and the
/// functor is the predicate; it's just like an STL algorithm.
///
- /// \param seq the destination container; needs a push_back() method
+ /// \param con the destination container; needs a push_back() method
/// \param query the query string
/// \param fn the functor called for each row
/// \return a copy of the passed functor
template <class Sequence, typename Function>
- Function store_if(Sequence& seq, const SQLString& query, Function fn)
+ Function store_if(Sequence& con, const SQLString& query, Function fn)
{
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);
+ con.push_back(row);
}
}
}
@@ -460,12 +489,12 @@
/// 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 con 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)
+ Function store_if(Sequence& con, const SSQLS& ssqls, Function fn)
{
SQLString query("select * from ");
query += ssqls._table;
@@ -474,7 +503,7 @@
mysqlpp::NoExceptions ne(res);
while (mysqlpp::Row row = res.fetch_row()) {
if (fn(row)) {
- seq.push_back(row);
+ con.push_back(row);
}
}
}
@@ -488,18 +517,18 @@
/// Just like store_if(Sequence&, const SQLString&, Function), but
/// it uses the query string held by the Query object already
///
- /// \param seq the destination container; needs a push_back() method
+ /// \param con the destination container; needs a push_back() method
/// \param fn the functor called for each row
/// \return a copy of the passed functor
template <class Sequence, typename Function>
- Function store_if(Sequence& seq, Function fn)
+ Function store_if(Sequence& con, Function fn)
{
mysqlpp::ResUse res = use();
if (res) {
mysqlpp::NoExceptions ne(res);
while (mysqlpp::Row row = res.fetch_row()) {
if (fn(row)) {
- seq.push_back(row);
+ con.push_back(row);
}
}
}
@@ -549,7 +578,7 @@
bool more_results();
/// \brief Execute a query, storing the result set in an STL
- /// sequence container.
+ /// conuence container.
///
/// This function works much like store() from the caller's
/// perspective, because it returns the entire result set at once.
@@ -561,19 +590,35 @@
/// the front of the list. So, you can pass a container and a query
/// string, or a container and template query parameters.
///
- /// \param con any STL sequence container, such as \c std::vector
+ /// \param con any STL conuence container, such as \c std::vector
///
/// \sa exec(), execute(), store(), and use()
template <class Sequence>
- void storein_sequence(Sequence& con)
- {
- storein_sequence(con, str(template_defaults));
- }
+ void storein_conuence(Sequence& con)
+ {
+ storein_conuence(con, str(template_defaults));
+ }
+
+ /// \brief Execute template query using given parameters, storing
+ /// the results in a conuence type container.
+ ///
+ /// This method should only be used by code that doesn't know,
+ /// at compile time, how many parameters it will have. This is
+ /// useful within the library, and also for code that builds
+ /// template queries dynamically, at run time.
+ ///
+ /// \param con container that will receive the results
+ /// \param p parameters to use in the template query.
+ template <class Seq>
+ void storein_conuence(Seq& con, SQLQueryParms& p)
+ {
+ storein_conuence(con, str(p));
+ }
/// \brief Execute a query, storing the result set in an STL
/// associative container.
///
- /// The same thing as storein_sequence(), except that it's used with
+ /// The same thing as storein_conuence(), except that it's used with
/// associative STL containers, such as \c std::set. Other than
/// that detail, that method's comments apply equally well to this
/// one.
@@ -583,11 +628,27 @@
storein_set(con, str(template_defaults));
}
+ /// \brief Execute template query using given parameters, storing
+ /// the results in a set type container.
+ ///
+ /// This method should only be used by code that doesn't know,
+ /// at compile time, how many parameters it will have. This is
+ /// useful within the library, and also for code that builds
+ /// template queries dynamically, at run time.
+ ///
+ /// \param con container that will receive the results
+ /// \param p parameters to use in the template query.
+ template <class Set>
+ void storein_set(Set& con, SQLQueryParms& p)
+ {
+ storein_set(con, str(p));
+ }
+
/// \brief Execute a query, and store the entire result set
/// in an STL container.
///
/// This is a set of specialized template functions that call either
- /// storein_sequence() or storein_set(), depending on the type of
+ /// storein_conuence() or storein_set(), depending on the type of
/// container you pass it. It understands \c std::vector, \c deque,
/// \c list, \c slist (a common C++ library extension), \c set,
/// and \c multiset.
@@ -596,7 +657,7 @@
/// of functions. See the other functions' documentation for details.
///
/// Use this function if you think you might someday switch your
- /// program from using a set-associative container to a sequence
+ /// program from using a set-associative container to a conuence
/// container for storing result sets, or vice versa.
///
/// See exec(), execute(), store(), and use() for alternative
@@ -607,37 +668,37 @@
storein(con, str(template_defaults));
}
- /// \brief Specialization of storein_sequence() for \c std::vector
+ /// \brief Specialization of storein_conuence() for \c std::vector
template <class T>
void storein(std::vector<T>& con, const SQLString& s)
{
- storein_sequence(con, s);
- }
-
- /// \brief Specialization of storein_sequence() for \c std::deque
+ storein_conuence(con, s);
+ }
+
+ /// \brief Specialization of storein_conuence() for \c std::deque
template <class T>
void storein(std::deque<T>& con, const SQLString& s)
{
- storein_sequence(con, s);
- }
-
- /// \brief Specialization of storein_sequence() for \c std::list
+ storein_conuence(con, s);
+ }
+
+ /// \brief Specialization of storein_conuence() for \c std::list
template <class T>
void storein(std::list<T>& con, const SQLString& s)
{
- storein_sequence(con, s);
+ storein_conuence(con, s);
}
#if defined(HAVE_EXT_SLIST)
- /// \brief Specialization of storein_sequence() for g++ STL
+ /// \brief Specialization of storein_conuence() for g++ STL
/// extension \c slist
template <class T>
void storein(__gnu_cxx::slist<T>& con, const SQLString& s)
{
- storein_sequence(con, s);
+ storein_conuence(con, s);
}
#elif defined(HAVE_GLOBAL_SLIST)
- /// \brief Specialization of storein_sequence() for STL
+ /// \brief Specialization of storein_conuence() for STL
/// extension \c slist
///
/// This is primarily for older versions of g++, which put \c slist
@@ -646,10 +707,10 @@
template <class T>
void storein(slist<T>& con, const SQLString& s)
{
- storein_sequence(con, s);
+ storein_conuence(con, s);
}
#elif defined(HAVE_STD_SLIST)
- /// \brief Specialization of storein_sequence() for STL
+ /// \brief Specialization of storein_conuence() for STL
/// extension \c slist
///
/// This is for those benighted compilers that include an \c slist
@@ -657,7 +718,7 @@
template <class T>
void storein(std::slist<T>& con, const SQLString& s)
{
- storein_sequence(con, s);
+ storein_conuence(con, s);
}
#endif
@@ -784,7 +845,7 @@
mysql_query_define0(ResNSel, execute)
mysql_query_define0(Result, store)
mysql_query_define0(ResUse, use)
- mysql_query_define1(storein_sequence)
+ mysql_query_define1(storein_conuence)
mysql_query_define1(storein_set)
mysql_query_define1(storein)
#endif // !defined(DOXYGEN_IGNORE)
@@ -837,7 +898,7 @@
// Doxygen will not generate documentation for this section.
template <class Sequence>
-void Query::storein_sequence(Sequence& con, const SQLString& s)
+void Query::storein_conuence(Sequence& con, const SQLString& s)
{
ResUse result = use(s);
while (1) {
Modified: trunk/lib/querydef.pl
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/querydef.pl?rev=1701&r1=1700&r2=1701&view=diff
==============================================================================
--- trunk/lib/querydef.pl (original)
+++ trunk/lib/querydef.pl Mon Jul 16 20:16:54 2007
@@ -63,11 +63,11 @@
}
print OUT ") \\\n";
- print OUT "\t\t{ return FUNC(str(SQLQueryParms()";
+ print OUT "\t\t{ return FUNC(SQLQueryParms()";
for (my $j = 0; $j < $i + 1; ++$j) {
print OUT ' << arg', $j;
}
- print OUT ")); } \\\n";
+ print OUT "); } \\\n";
}
## Add mysql_query_define1 macro
@@ -82,7 +82,7 @@
print OUT ', const SQLString& arg', $j;
}
print OUT ") \\\n";
- print OUT "\t\t{ FUNC(container, str(SQLQueryParms())";
+ print OUT "\t\t{ FUNC(container, SQLQueryParms()";
for (my $j = 0; $j < $i + 1; ++$j) {
print OUT ' << arg', $j;
}
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits