Author: wyoung
Date: Thu Nov 29 17:40:18 2007
New Revision: 1928
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1928&view=rev
Log:
Changes made in 2.3.0 to allow strings with embedded null characters to
be used in Query streams also broke formatted output to non-Query
streams, e.g. the columnar output of received data in the examples that
dump the stock table contents. All of these operator<<()'s now detect
Query streams and keep on using the same efficient methods we introduced
in 2.3.0 (unformatted output) but switch back to inefficient formatted
output otherwise. Regenerated bmark.txt to pick up these whitespace
changes even though dtest doesn't care about whitespace.
Modified:
trunk/Wishlist
trunk/bmark.txt
trunk/lib/manip.cpp
trunk/lib/manip.h
trunk/lib/mystring.cpp
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1928&r1=1927&r2=1928&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Thu Nov 29 17:40:18 2007
@@ -12,10 +12,6 @@
The items in this section are those things we currently expect
to get done for v3.0. Most of them break the ABI, so they can't
wait for a future version, because v4 could be years out.
-
- o The manipulator changes sometime during 2.3 broke the column
- formatting of the examples that dump tables. A setw(x) call
- results in x spaces, not x - strlen(whatevercamebefore).
o Create examples/vstudio/threads to test new thread-related
features. Only VC++ since every other platform has the
Modified: trunk/bmark.txt
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/bmark.txt?rev=1928&r1=1927&r2=1928&view=diff
==============================================================================
--- trunk/bmark.txt (original)
+++ trunk/bmark.txt Thu Nov 29 17:40:18 2007
@@ -20,19 +20,19 @@
---------------- BEGIN simple2 OUTPUT ----------------
Item Num Weight Price Date
-Nürnberger Brats 97 1.5 8.79
2005-03-10
-Pickle Relish 87 1.5 1.75
1998-09-04
-Hot Mustard 73 0.95 0.97
1998-05-25
-Hotdog Buns 65 1.1 1.1
1998-04-23
+Nürnberger Brats 97 1.5 8.79 2005-03-10
+Pickle Relish 87 1.5 1.75 1998-09-04
+Hot Mustard 73 0.95 0.97 1998-05-25
+Hotdog Buns 65 1.1 1.1 1998-04-23
================ END simple2 OUTPUT ================
---------------- BEGIN simple3 OUTPUT ----------------
Item Num Weight Price Date
-Nürnberger Brats 97 1.5 8.79
2005-03-10
-Pickle Relish 87 1.5 1.75
1998-09-04
-Hot Mustard 73 0.95 0.97
1998-05-25
-Hotdog Buns 65 1.1 1.1
1998-04-23
+Nürnberger Brats 97 1.5 8.79 2005-03-10
+Pickle Relish 87 1.5 1.75 1998-09-04
+Hot Mustard 73 0.95 0.97 1998-05-25
+Hotdog Buns 65 1.1 1.1 1998-04-23
================ END simple3 OUTPUT ================
---------------- BEGIN store_if OUTPUT ----------------
@@ -71,7 +71,7 @@
+---------------+-----+--------+-------+------------+-------------+
| item | num | weight | price | sdate | description |
+---------------+-----+--------+-------+------------+-------------+
- | Pickle Relish | 87 | 1.5 | 1.75 | 1998-09-04 |
NULL |
+ | Pickle Relish | 87 | 1.5 | 1.75 | 1998-09-04 | NULL |
+---------------+-----+--------+-------+------------+-------------+
Result set 1 is empty.
================ END multiquery OUTPUT ================
Modified: trunk/lib/manip.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/manip.cpp?rev=1928&r1=1927&r2=1928&view=diff
==============================================================================
--- trunk/lib/manip.cpp (original)
+++ trunk/lib/manip.cpp Thu Nov 29 17:40:18 2007
@@ -33,7 +33,8 @@
namespace mysqlpp {
-SQLQueryParms& operator <<(quote_type2 p, SQLTypeAdapter& in)
+SQLQueryParms&
+operator <<(quote_type2 p, SQLTypeAdapter& in)
{
if (in.quote_q()) {
string temp("'", 1), escaped;
@@ -50,22 +51,57 @@
}
-ostream& operator <<(quote_type1 o, const SQLTypeAdapter& in)
-{
- Query* pq = dynamic_cast<Query*>(o.ostr);
-
- if (pq && in.quote_q()) o.ostr->write("'", 1);
-
- if (pq && in.escape_q()) {
- string escaped;
- pq->escape_string(&escaped, in.data(), in.length());
- o.ostr->write(escaped.data(), escaped.length());
- }
- else {
+ostream&
+operator <<(quote_type1 o, const SQLTypeAdapter& in)
+{
+ Query* pq = dynamic_cast<Query*>(o.ostr);
+
+ if (pq && in.quote_q()) o.ostr->put('\'');
+
+ if (pq) {
+ // It's a Query stream, so we'll be using unformatted output.
+ // Now, is escaping appropriate for source data type of 'in'?
+ if (in.escape_q()) {
+ string escaped;
+ pq->escape_string(&escaped, in.data(), in.length());
+ o.ostr->write(escaped.data(), escaped.length());
+ }
+ else {
+ o.ostr->write(in.data(), in.length());
+ }
+ }
+ else {
+ // Some other stream type, so use formatted output. User
+ // shouldn't be trying to use the quote manipulator, but
+ // that's no reason to break their formatting.
+ *o.ostr << string(in.data(), in.length());
+ }
+
+ if (pq && in.quote_q()) o.ostr->put('\'');
+
+ return *o.ostr;
+}
+
+
+ostream&
+operator <<(quote_only_type1 o, const SQLTypeAdapter& in)
+{
+ Query* pq = dynamic_cast<Query*>(o.ostr);
+
+ if (pq && in.quote_q()) o.ostr->put('\'');
+
+ if (pq) {
+ // It's a Query stream, so use unformatted output
o.ostr->write(in.data(), in.length());
}
-
- if (pq && in.quote_q()) o.ostr->write("'", 1);
+ else {
+ // Some other stream type, so use formatted output. User
+ // shouldn't be trying to use this manipulator on a non-Query
+ // stream, but that's no reason to break their formatting.
+ *o.ostr << '\'' << in << '\'';
+ }
+
+ if (pq && in.quote_q()) o.ostr->put('\'');
return *o.ostr;
}
@@ -74,12 +110,20 @@
ostream&
operator <<(ostream& o, const SQLTypeAdapter& in)
{
- o.write(in.data(), in.length());
- return o;
-}
-
-
-SQLQueryParms& operator <<(quote_only_type2 p, SQLTypeAdapter& in)
+ if (dynamic_cast<Query*>(&o)) {
+ // It's a Query stream, so use unformatted output.
+ return o.write(in.data(), in.length());
+ }
+ else {
+ // Some other stream type, so use formatted output. We do this
+ // through the temporary so we remain null-friendly.
+ return o << string(in.data(), in.length());
+ }
+}
+
+
+SQLQueryParms&
+operator <<(quote_only_type2 p, SQLTypeAdapter& in)
{
if (in.quote_q()) {
string temp("'", 1);
@@ -94,7 +138,8 @@
}
-SQLQueryParms& operator <<(quote_double_only_type2 p, SQLTypeAdapter& in)
+SQLQueryParms&
+operator <<(quote_double_only_type2 p, SQLTypeAdapter& in)
{
if (in.quote_q()) {
string temp("\"", 1);
@@ -109,7 +154,32 @@
}
-SQLQueryParms& operator <<(escape_type2 p, SQLTypeAdapter& in)
+ostream&
+operator <<(quote_double_only_type1 o, const SQLTypeAdapter& in)
+{
+ Query* pq = dynamic_cast<Query*>(o.ostr);
+
+ if (pq && in.quote_q()) o.ostr->put('"');
+
+ if (pq) {
+ // It's a Query stream, so use unformatted output
+ o.ostr->write(in.data(), in.length());
+ }
+ else {
+ // Some other stream type, so use formatted output. User
+ // shouldn't be trying to use this manipulator on a non-Query
+ // stream, but that's no reason to break their formatting.
+ *o.ostr << '"' << in << '"';
+ }
+
+ if (pq && in.quote_q()) o.ostr->put('"');
+
+ return *o.ostr;
+}
+
+
+SQLQueryParms&
+operator <<(escape_type2 p, SQLTypeAdapter& in)
{
if (in.escape_q()) {
string escaped;
@@ -124,31 +194,57 @@
}
-std::ostream& operator <<(escape_type1 o, const SQLTypeAdapter& in)
-{
- Query* pq = dynamic_cast<Query*>(o.ostr);
-
- if (pq && in.escape_q()) {
- string escaped;
- pq->escape_string(&escaped, in.data(), in.length());
- o.ostr->write(escaped.data(), escaped.length());
- }
- else {
- o.ostr->write(in.data(), in.length());
- }
-
- return *o.ostr;
-}
-
-
-SQLQueryParms& operator <<(do_nothing_type2 p, SQLTypeAdapter& in)
+ostream&
+operator <<(escape_type1 o, const SQLTypeAdapter& in)
+{
+ Query* pq = dynamic_cast<Query*>(o.ostr);
+ if (pq) {
+ // It's a Query stream, so we'll be using unformatted output.
+ // Now, is escaping appropriate for source data type of 'in'?
+ if (in.escape_q()) {
+ string escaped;
+ pq->escape_string(&escaped, in.data(), in.length());
+ return o.ostr->write(escaped.data(), escaped.length());
+ }
+ else {
+ return o.ostr->write(in.data(), in.length());
+ }
+ }
+ else {
+ // Some other stream type, so use formatted output. User
+ // shouldn't be trying to use the escape manipulator, but
+ // that's no reason to break their formatting.
+ return *o.ostr << string(in.data(), in.length());
+ }
+}
+
+
+SQLQueryParms&
+operator <<(do_nothing_type2 p, SQLTypeAdapter& in)
{
in.set_processed();
return *p.qparms << in;
}
-SQLQueryParms& operator <<(ignore_type2 p, SQLTypeAdapter& in)
+ostream&
+operator <<(do_nothing_type1 o, const SQLTypeAdapter& in)
+{
+ if (dynamic_cast<Query*>(o.ostr)) {
+ // It's a Query stream, so use unformatted output
+ return o.ostr->write(in.data(), in.length());
+ }
+ else {
+ // Some other stream type, so use formatted output. User
+ // shouldn't be trying to use this manipulator on a non-Query
+ // stream, but that's no reason to break their formatting.
+ return *o.ostr << in;
+ }
+}
+
+
+SQLQueryParms&
+operator <<(ignore_type2 p, SQLTypeAdapter& in)
{
return *p.qparms << in;
}
Modified: trunk/lib/manip.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/manip.h?rev=1928&r1=1927&r2=1928&view=diff
==============================================================================
--- trunk/lib/manip.h (original)
+++ trunk/lib/manip.h Thu Nov 29 17:40:18 2007
@@ -207,16 +207,7 @@
SQLTypeAdapter& in);
-inline std::ostream&
-operator <<(quote_only_type1 o, const SQLTypeAdapter& in)
-{
- if (in.quote_q()) {
- return *o.ostr << '\'' << in << '\'';
- }
- else {
- return *o.ostr << in;
- }
-}
+std::ostream& operator <<(quote_only_type1 o, const SQLTypeAdapter& in);
template <class ST>
@@ -296,16 +287,8 @@
operator <<(quote_double_only_type2 p, SQLTypeAdapter& in);
-inline std::ostream&
-operator <<(quote_double_only_type1 o, const SQLTypeAdapter& in)
-{
- if (in.quote_q()) {
- return *o.ostr << '"' << in << '"';
- }
- else {
- return *o.ostr << in;
- }
-}
+std::ostream&
+operator <<(quote_double_only_type1 o, const SQLTypeAdapter& in);
template <class ST>
@@ -426,12 +409,8 @@
}
-template <class T>
-inline std::ostream&
-operator <<(do_nothing_type1 o, const T& in)
-{
- return *o.ostr << in;
-}
+std::ostream&
+operator <<(do_nothing_type1 o, const SQLTypeAdapter& in);
struct do_nothing_type2
Modified: trunk/lib/mystring.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/mystring.cpp?rev=1928&r1=1927&r2=1928&view=diff
==============================================================================
--- trunk/lib/mystring.cpp (original)
+++ trunk/lib/mystring.cpp Thu Nov 29 17:40:18 2007
@@ -25,6 +25,7 @@
***********************************************************************/
#include "mystring.h"
+#include "query.h"
#include <stdexcept>
#include <string>
@@ -209,7 +210,20 @@
std::ostream&
operator <<(std::ostream& o, const String& in)
{
- o.write(in.data(), in.length());
+ if (dynamic_cast<Query*>(&o)) {
+ // We can just insert the raw data into the stream
+ o.write(in.data(), in.length());
+ }
+ else {
+ // Can't guess what sort of stream it is, so convert the String
+ // to a std::string so we can use the formatted output method.
+ // To see why this is necessary, change it to use write() only
+ // (unformatted output) and then run simple2: notice that the
+ // columnar output formatting is wrecked.
+ std::string temp;
+ in.to_string(temp);
+ o << temp;
+ }
return o;
}
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits