Author: wyoung
Date: Sat Oct 27 07:00:52 2007
New Revision: 1797
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1797&view=rev
Log:
Query objects now auto-reset upon query execution unless it's a template
query. Thus, Query::reset() still exists and is public for cases where
reusing a Query object used for template queries. Both resetdb and the
tquery examples already do this. It's also still safe to call reset()
after each execution, just wasteful.
Modified:
trunk/Wishlist
trunk/lib/query.cpp
trunk/lib/query.h
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1797&r1=1796&r2=1797&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Sat Oct 27 07:00:52 2007
@@ -180,10 +180,6 @@
o Replace Query::preview() with operator<<, for easy debugging?
If one really wants a std::string, they can still call str(),
which is currently the same thing.
-
- o Does Query::reset() provide any benefit? Why doesn't it reset
- automatically for all queries? I guess if you were to re-run
- the same query multiple times, but who does that?
o Define operator<< for Fields, Row, ResUse, etc. In other
words, there should be a way to get a user-readable version
Modified: trunk/lib/query.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.cpp?rev=1797&r1=1796&r2=1797&view=diff
==============================================================================
--- trunk/lib/query.cpp (original)
+++ trunk/lib/query.cpp Sat Oct 27 07:00:52 2007
@@ -89,6 +89,12 @@
{
copacetic_ = !mysql_real_query(&conn_->mysql_, str.data(),
static_cast<unsigned long>(str.length()));
+
+ if (parse_elems_.size() == 0) {
+ // not a template query, so auto-reset
+ reset();
+ }
+
if (!copacetic_ && throw_exceptions()) {
throw BadQuery(error(), errnum());
}
@@ -127,7 +133,14 @@
ResNSel
Query::execute(const char* str, size_t len)
{
- if (copacetic_ = !mysql_real_query(&conn_->mysql_, str, len)) {
+ copacetic_ = !mysql_real_query(&conn_->mysql_, str, len);
+
+ if (parse_elems_.size() == 0) {
+ // Not a template query, so auto-reset
+ reset();
+ }
+
+ if (copacetic_) {
return ResNSel(conn_);
}
else if (throw_exceptions()) {
@@ -354,6 +367,7 @@
}
}
+
void
Query::reset()
{
@@ -395,8 +409,15 @@
Result
Query::store(const char* str, size_t len)
{
+ copacetic_ = !mysql_real_query(&conn_->mysql_, str, len);
+
+ if (parse_elems_.size() == 0) {
+ // Not a template query, so auto-reset
+ reset();
+ }
+
MYSQL_RES* res = 0;
- if (copacetic_ = !mysql_real_query(&conn_->mysql_, str, len)) {
+ if (copacetic_) {
res = mysql_store_result(&conn_->mysql_);
}
@@ -501,8 +522,15 @@
ResUse
Query::use(const char* str, size_t len)
{
+ copacetic_ = !mysql_real_query(&conn_->mysql_, str, len);
+
+ if (parse_elems_.size() == 0) {
+ // Not a template query, so auto-reset
+ reset();
+ }
+
MYSQL_RES* res = 0;
- if (copacetic_ = !mysql_real_query(&conn_->mysql_, str, len)) {
+ if (copacetic_) {
res = mysql_use_result(&conn_->mysql_);
}
Modified: trunk/lib/query.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.h?rev=1797&r1=1796&r2=1797&view=diff
==============================================================================
--- trunk/lib/query.h (original)
+++ trunk/lib/query.h Sat Oct 27 07:00:52 2007
@@ -197,8 +197,13 @@
/// \brief Reset the query object so that it can be reused.
///
- /// This erases the query string and the contents of the parameterized
- /// query element list.
+ /// As of v3.0, Query objects auto-reset upon query execution unless
+ /// you've set it up for making template queries. (It can't auto-reset
+ /// in that situation, because it would forget the template info.)
+ /// Therefore, the only time you must call this is if you have a Query
+ /// object set up for making template queries, then want to build
+ /// queries using one of the other methods. (Static strings, SSQLS,
+ /// or the stream interface.)
void reset();
/// \brief Return the query string currently in the buffer.
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits