summaryrefslogtreecommitdiff
path: root/mysys/charset.c
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2005-06-23 18:29:56 -0700
committerunknown <jimw@mysql.com>2005-06-23 18:29:56 -0700
commit86d8abdb26e35a5920eea0e55fadd89295f05df6 (patch)
treeb5f6e8ddaa771fd03ce4b741cc2723ea99b358ca /mysys/charset.c
parentd34e2ccb3ea51811552f3e87ad68ee8673804da1 (diff)
downloadmariadb-git-86d8abdb26e35a5920eea0e55fadd89295f05df6.tar.gz
Make status of NO_BACKSLASH_ESCAPES mode known to the client so
it can use it to switch to only quoting apostrophes by doubling them when it is in effect. (Bug #10214) include/my_sys.h: Add new escape_quotes_for_mysql() function include/mysql_com.h: Add SERVER_STATUS_NO_BACKSLASH_ESCAPES libmysql/libmysql.c: Use SERVER_STATUS_NO_BACKSLASH_ESCAPES in server_status to determine how mysql_real_escape_string() should do quoting. mysys/charset.c: Add new escape_quotes_for_mysql() function that only quotes apostrophes by doubling them up. sql/set_var.cc: Set SERVER_STATUS_NO_BACKSLASH_ESCAPES when MODE_NO_BACKSLASH_ESCAPES changes. sql/sql_class.cc: Set SERVER_STATUS_NO_BACKSLASH_ESCAPES when necessary on thread creation. tests/mysql_client_test.c: Add new test for sending NO_BACKSLASH_ESCAPES as part of server_status.
Diffstat (limited to 'mysys/charset.c')
-rw-r--r--mysys/charset.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/mysys/charset.c b/mysys/charset.c
index cbd9ba16b4c..53d9c4a72a4 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -656,3 +656,67 @@ ulong escape_string_for_mysql(CHARSET_INFO *charset_info,
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
+
+/*
+ NOTE
+ to be consistent with escape_string_for_mysql(), to_length may be 0 to
+ mean "big enough"
+ RETURN
+ the length of the escaped string or ~0 if it did not fit.
+*/
+ulong escape_quotes_for_mysql(CHARSET_INFO *charset_info,
+ char *to, ulong to_length,
+ const char *from, ulong length)
+{
+ const char *to_start= to;
+ const char *end, *to_end=to_start + (to_length ? to_length-1 : 2*length);
+ my_bool overflow=0;
+#ifdef USE_MB
+ my_bool use_mb_flag= use_mb(charset_info);
+#endif
+ for (end= from + length; from < end; from++)
+ {
+ char escape=0;
+#ifdef USE_MB
+ int tmp_length;
+ if (use_mb_flag && (tmp_length= my_ismbchar(charset_info, from, end)))
+ {
+ if (to + tmp_length > to_end)
+ {
+ overflow=1;
+ break;
+ }
+ while (tmp_length--)
+ *to++= *from++;
+ from--;
+ continue;
+ }
+ /*
+ We don't have the same issue here with a non-multi-byte character being
+ turned into a multi-byte character by the addition of an escaping
+ character, because we are only escaping the ' character with itself.
+ */
+#endif
+ if (*from == '\'')
+ {
+ if (to + 2 > to_end)
+ {
+ overflow=1;
+ break;
+ }
+ *to++= '\'';
+ *to++= '\'';
+ }
+ else
+ {
+ if (to + 1 > to_end)
+ {
+ overflow=1;
+ break;
+ }
+ *to++= *from;
+ }
+ }
+ *to= 0;
+ return overflow ? (ulong)~0 : (ulong) (to - to_start);
+}