Author: wyoung
Date: Fri Dec 28 11:37:00 2007
New Revision: 2039
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2039&view=rev
Log:
quote_q() method in SQLTypeAdapter and String classes now returns true
if the object was default-initted on the theory that it represents an
empty string; if the object is being asked if it should be quoted, it
means it's being used to build a SQL query, and the only way to
represent an empty string in SQL is ''. So yes, it needs quotes.
Modified:
trunk/lib/mystring.cpp
trunk/lib/stadapter.cpp
trunk/test/test_string.cpp
Modified: trunk/lib/mystring.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/mystring.cpp?rev=2039&r1=2038&r2=2039&view=diff
==============================================================================
--- trunk/lib/mystring.cpp (original)
+++ trunk/lib/mystring.cpp Fri Dec 28 11:37:00 2007
@@ -198,7 +198,9 @@
bool
String::quote_q() const
{
- return buffer_ ? buffer_->type().quote_q() : false;
+ // If no buffer, it means we're an empty string, so we need to be
+ // quoted to be expressed properly in SQL.
+ return buffer_ ? buffer_->type().quote_q() : true;
}
Modified: trunk/lib/stadapter.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/stadapter.cpp?rev=2039&r1=2038&r2=2039&view=diff
==============================================================================
--- trunk/lib/stadapter.cpp (original)
+++ trunk/lib/stadapter.cpp Fri Dec 28 11:37:00 2007
@@ -438,7 +438,9 @@
bool
SQLTypeAdapter::quote_q() const
{
- return buffer_ ? buffer_->quote_q() : false;
+ // If no buffer, it means we're an empty string, so we need to be
+ // quoted to be expressed properly in SQL.
+ return buffer_ ? buffer_->quote_q() : true;
}
int
Modified: trunk/test/test_string.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/test/test_string.cpp?rev=2039&r1=2038&r2=2039&view=diff
==============================================================================
--- trunk/test/test_string.cpp (original)
+++ trunk/test/test_string.cpp Fri Dec 28 11:37:00 2007
@@ -72,6 +72,20 @@
}
+static bool
+test_quote_q(const mysqlpp::String& s, bool expected)
+{
+ if (s.quote_q() == expected) {
+ return true;
+ }
+ else {
+ std::cerr << s.type().name() << " should" <<
+ (expected ? "" : " NOT") << " be quoted." <<
std::endl;
+ return false;
+ }
+}
+
+
int
main(int, char* argv[])
{
@@ -90,6 +104,9 @@
failures += test_numeric(empty, 0) == false;
failures += test_numeric(zero, 0) == false;
failures += test_numeric(nonzero, 42) == false;
+ failures += test_quote_q(empty, true) == false;
+ failures += test_quote_q(mysqlpp::String("1", typeid(int)),
+ false) == false;
return failures;
}
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits