List:MySQL++« Previous MessageNext Message »
From:Andrew Sayers Date:July 2 2007 12:55am
Subject:Bug: char[]s not escaped
View as plain text  
Tested against 2.2.3, mysqlpp::quote and mysqlpp::escape don't escape
text passed as an array of characters:

#include <mysql++.h>
#include <iostream>

using namespace std;
using namespace mysqlpp;

int main() {
	string s1 = "Frank's Brand Hotdog Buns";
	std::cout << quote << s1 << std::endl;
	// Output: 'Frank\'s Brand Hotdog Buns'

	char s2[] = "Frank's Brand Hotdog Buns";
	std::cout << quote << s2 << std::endl;
	// Output: Frank's Brand Hotdog Buns

}


C++ prefers to use the template functions rather than converting a
char[] to a char*.  Here's a patch:


--- manip-old.h	2007-05-08 00:49:32.000000000 +0100
+++ manip.h	2007-07-02 01:35:45.000000000 +0100
@@ -170,6 +170,18 @@
 	return operator <<(o, const_cast<const char* const&>(in));
 }
 
+inline std::ostream& operator <<(quote_type1 o,
+		char in[])
+{
+	return operator <<(o, const_cast<const char* const&>(in));
+}
+
+inline std::ostream& operator <<(quote_type1 o,
+		const char in[])
+{
+	return operator <<(o, const_cast<const char* const&>(in));
+}
+
 
 template <>
 inline std::ostream& operator <<(quote_type1 o,
@@ -540,6 +552,18 @@
 	return operator <<(o, const_cast<const char* const&>(in));
 }
 
+inline std::ostream& operator <<(escape_type1 o,
+		char in[])
+{
+	return operator <<(o, const_cast<const char* const&>(in));
+}
+
+inline std::ostream& operator <<(escape_type1 o,
+		const char in[])
+{
+	return operator <<(o, const_cast<const char* const&>(in));
+}
+
 
 /// \enum do_nothing_type0
 /// \anchor do_nothing_manip

Thread
Bug: char[]s not escapedAndrew Sayers2 Jul
  • Re: Bug: char[]s not escapedAndrew Sayers2 Jul
    • Re: Bug: char[]s not escapedWarren Young2 Jul
    • Re: Bug: char[]s not escapedJonathan Wakely4 Jul
      • Re: Bug: char[]s not escapedWarren Young6 Jul
        • Re: Bug: char[]s not escapedJonathan Wakely7 Jul