Author: mysqlpp
Date: Mon Dec  3 10:53:51 2007
New Revision: 1957

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1957&view=rev
Log:
- Removed Query::preview() overloads.  They were purely parallel
  interfaces to str(), which is more Standard C++-ish.
- Added operator << for Query itself (not to be confused with the
  operator <<'s that insert into Query) which lets you replace
  "os << query.preview()" with "os << query".
- Removed Query::preview_char().  It was an internal method used only
  once, so just put its code inline at the old call site.

Modified:
    trunk/Wishlist
    trunk/examples/custom2.cpp
    trunk/examples/custom3.cpp
    trunk/examples/custom5.cpp
    trunk/examples/dbinfo.cpp
    trunk/examples/multiquery.cpp
    trunk/examples/printdata.cpp
    trunk/lib/query.cpp
    trunk/lib/query.h

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Mon Dec  3 10:53:51 2007
@@ -32,16 +32,6 @@
         operator->() to subscript_iterator.  It can't work with
         value semantics.
 
-    o If Bakefile 0.2.3 (guessing) comes out before we release, change
-      all the msvs2005prj references in mysql++.bkl, Bakefiles.bkgen
-      and rebake.bat to msvs2003prj and remove the section on doing
-      this by hand from README.vc.  If not, we might need to update
-      some of the FAQ items on the MySQL++ home page.
-
-    o Is MYSQLPP_QUERY_THISPTR still needed with VC++2003?  The recent
-      manipulator changes and the removal of all operator<<(Query&,
-      const T&) may make it unnecessary.
-
     o Document that Query::storein() now works with raw Row objects.
       It used to fail because of the Result/Row lifetime issue,
       which didn't apply to SSQLS because of the data copy.
@@ -53,13 +43,15 @@
       allow template functions like Query::insert<T> to become regular
       member functions, taking a reference to the SSQLS base class.
 
-    o Fold Query::preview(void) into str(), and rename all of the
-      multiple-argument forms of preview() to str().
+    o Is MYSQLPP_QUERY_THISPTR still needed with VC++2003?  The recent
+      manipulator changes and the removal of all operator<<(Query&,
+      const T&) may make it unnecessary.
 
-    o A set of Query::str() overloads that take an ostream for the
-      first parameter would be useful.
-
-    o Add operator<< for Query, syntactic sugar for str(ostream&).
+    o If Bakefile 0.2.3 (guessing) comes out before we release, change
+      all the msvs2005prj references in mysql++.bkl, Bakefiles.bkgen
+      and rebake.bat to msvs2003prj and remove the section on doing
+      this by hand from README.vc.  If not, we might need to update
+      some of the FAQ items on the MySQL++ home page.
 
 
 v3.0 "Maybe" Stuff

Modified: trunk/examples/custom2.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom2.cpp?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/examples/custom2.cpp (original)
+++ trunk/examples/custom2.cpp Mon Dec  3 10:53:51 2007
@@ -57,7 +57,7 @@
                query.insert(row);
 
                // Show the query about to be executed.
-               cout << "Query: " << query.preview() << endl;
+               cout << "Query: " << query << endl;
 
                // Execute the query.  We use execute() because INSERT doesn't
                // return a result set.

Modified: trunk/examples/custom3.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom3.cpp?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/examples/custom3.cpp (original)
+++ trunk/examples/custom3.cpp Mon Dec  3 10:53:51 2007
@@ -77,7 +77,7 @@
                query.update(orig_row, row);
 
                // Show the query about to be executed.
-               cout << "Query: " << query.preview() << endl;
+               cout << "Query: " << query << endl;
 
                // Run the query with execute(), since UPDATE doesn't return a
                // result set.

Modified: trunk/examples/custom5.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom5.cpp?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/examples/custom5.cpp (original)
+++ trunk/examples/custom5.cpp Mon Dec  3 10:53:51 2007
@@ -60,7 +60,7 @@
                                        res[0].equal_list(" and ", 
stock_weight, stock_price);
 
                        // Display the finished query.
-                       cout << "Custom query:\n" << query.preview() << endl;
+                       cout << "Custom query:\n" << query << endl;
                }
        }
        catch (const mysqlpp::BadQuery& er) {

Modified: trunk/examples/dbinfo.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/dbinfo.cpp?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/examples/dbinfo.cpp (original)
+++ trunk/examples/dbinfo.cpp Mon Dec  3 10:53:51 2007
@@ -74,7 +74,7 @@
 show_databases(mysqlpp::Connection& con)
 {
     mysqlpp::Query query = con.query("show databases");
-       separator(cout, query.preview());
+       separator(cout, query.str());
     mysqlpp::Result res = query.store();
 
     cout << "Databases found: " << res.size();
@@ -94,7 +94,7 @@
        for (it = tables.begin(); it != tables.end(); ++it) {
                mysqlpp::Query query = con.query();
                query << "describe " << *it;
-               separator(cout, query.preview());
+               separator(cout, query.str());
                mysqlpp::Result res = query.store();
 
                unsigned int columns = res.num_fields();
@@ -146,7 +146,7 @@
 show_tables(mysqlpp::Connection& con)
 {
     mysqlpp::Query query = con.query("show tables");
-       separator(cout, query.preview());
+       separator(cout, query.str());
        mysqlpp::Result res = query.store();
 
        cout << "Tables found: " << res.size();

Modified: trunk/examples/multiquery.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/multiquery.cpp?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/examples/multiquery.cpp (original)
+++ trunk/examples/multiquery.cpp Mon Dec  3 10:53:51 2007
@@ -169,7 +169,7 @@
                                "UPDATE test_table SET id=20 WHERE id=10; " <<
                                "SELECT * FROM test_table; " <<
                                "DROP TABLE test_table";
-               cout << "Multi-query: " << endl << query.preview() << endl;
+               cout << "Multi-query: " << endl << query << endl;
 
                // Execute statement and display all result sets.
                print_multiple_results(query);
@@ -184,14 +184,14 @@
                                "SET i_item = concat('%', i_item, '%'); " <<
                                "SELECT * FROM stock WHERE lower(item) like 
lower(i_item); " <<
                                "END;";
-               cout << "Stored procedure query: " << endl << query.preview() 
<< endl;
+               cout << "Stored procedure query: " << endl << query << endl;
 
                // Create the stored procedure.
                print_multiple_results(query);
 
                // Call the stored procedure and display its results.
                query << "CALL get_stock('relish')";
-               cout << "Query: " << query.preview() << endl;
+               cout << "Query: " << query << endl;
                print_multiple_results(query);
 #endif
 

Modified: trunk/examples/printdata.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/printdata.cpp?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/examples/printdata.cpp (original)
+++ trunk/examples/printdata.cpp Mon Dec  3 10:53:51 2007
@@ -109,7 +109,7 @@
 
        // Build the query itself, and show it to the user
        query << "select * from stock";
-       cout << "Query: " << query.preview() << endl;
+       cout << "Query: " << query << endl;
 
        // Execute it, and display the results
        mysqlpp::Result res = query.store();

Modified: trunk/lib/query.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.cpp?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/lib/query.cpp (original)
+++ trunk/lib/query.cpp Mon Dec  3 10:53:51 2007
@@ -248,8 +248,12 @@
        std::string str = "";
        char num[4];
        std::string name;
-       char *s, *s0;
-       s0 = s = preview_char();
+
+       char* s = new char[sbuffer_.str().size() + 1];
+       memcpy(s, sbuffer_.str().data(), sbuffer_.str().size()); 
+       s[sbuffer_.str().size()] = '\0';
+       const char* s0 = s;
+
        while (*s) {
                if (*s == '%') {
                        // Following might be a template parameter 
declaration...
@@ -398,17 +402,6 @@
 }
 
 
-char*
-Query::preview_char()
-{
-       const std::string& str(sbuffer_.str());
-       char* s = new char[str.size() + 1];
-       memcpy(s, str.data(), str.size()); 
-       s[str.size()] = '\0';
-       return s;
-}
-
-
 void
 Query::proc(SQLQueryParms& p)
 {

Modified: trunk/lib/query.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.h?rev=1957&r1=1956&r2=1957&view=diff
==============================================================================
--- trunk/lib/query.h (original)
+++ trunk/lib/query.h Mon Dec  3 10:53:51 2007
@@ -268,19 +268,6 @@
        /// information.
        void parse();
 
-       /// \brief Return the query string currently in the buffer.
-       std::string preview() { return str(template_defaults); }
-
-       /// \brief Return the query string currently in the buffer with
-       /// template query parameter substitution.
-       ///
-       /// \param arg0 the value to substitute for the first template query
-       /// parameter
-       std::string preview(const SQLTypeAdapter& arg0) { return str(arg0); }
-
-       /// \brief Return the query string currently in the buffer.
-       std::string preview(SQLQueryParms& p) { return str(p); }
-
        /// \brief Reset the query object so that it can be reused.
        ///
        /// As of v3.0, Query objects auto-reset upon query execution unless
@@ -937,7 +924,6 @@
        // to keep the above code clear, but also so that we may hide them
        // from Doxygen, which gets confused by macro instantiations that look
        // like method declarations.
-       mysql_query_define0(std::string, preview)
        mysql_query_define0(std::string, str)
        mysql_query_define0(ResNSel, execute)
        mysql_query_define0(Result, store)
@@ -974,14 +960,20 @@
        /// \brief String buffer for storing assembled query
        std::stringbuf sbuffer_;
 
-       //// Internal support functions
-       char* preview_char();
-
        /// \brief Process a parameterized query list.
        void proc(SQLQueryParms& p);
 
        SQLTypeAdapter* pprepare(char option, SQLTypeAdapter& S, bool replace = 
true);
 };
+
+
+/// \brief Insert raw query string into the given stream.
+///
+/// This is just syntactic sugar for Query::str(void)
+inline std::ostream& operator <<(std::ostream& os, Query& q)
+{
+       return os << q.str();
+}
 
 
 #if !defined(DOXYGEN_IGNORE)


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

Reply via email to