Below is the list of changes that have just been committed into a local
5.0 repository of jimw. When jimw does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.2006 05/06/23 18:29:56 jimw@stripped +7 -0
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)
tests/mysql_client_test.c
1.129 05/06/23 18:29:51 jimw@stripped +30 -0
Add new test for sending NO_BACKSLASH_ESCAPES as part of server_status.
sql/sql_class.cc
1.191 05/06/23 18:29:51 jimw@stripped +2 -0
Set SERVER_STATUS_NO_BACKSLASH_ESCAPES when necessary on thread creation.
sql/set_var.cc
1.122 05/06/23 18:29:51 jimw@stripped +9 -0
Set SERVER_STATUS_NO_BACKSLASH_ESCAPES when MODE_NO_BACKSLASH_ESCAPES
changes.
mysys/charset.c
1.139 05/06/23 18:29:50 jimw@stripped +64 -0
Add new escape_quotes_for_mysql() function that only quotes
apostrophes by doubling them up.
libmysql/libmysql.c
1.219 05/06/23 18:29:50 jimw@stripped +8 -1
Use SERVER_STATUS_NO_BACKSLASH_ESCAPES in server_status to determine
how mysql_real_escape_string() should do quoting.
include/mysql_com.h
1.99 05/06/23 18:29:50 jimw@stripped +1 -0
Add SERVER_STATUS_NO_BACKSLASH_ESCAPES
include/my_sys.h
1.159 05/06/23 18:29:50 jimw@stripped +3 -0
Add new escape_quotes_for_mysql() function
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: jimw
# Host: rama.(none)
# Root: /home/jimw/my/mysql-5.0-10214
--- 1.158/include/my_sys.h 2005-06-06 08:30:53 -07:00
+++ 1.159/include/my_sys.h 2005-06-23 18:29:50 -07:00
@@ -865,6 +865,9 @@
extern ulong escape_string_for_mysql(CHARSET_INFO *charset_info,
char *to, ulong to_length,
const char *from, ulong length);
+extern ulong escape_quotes_for_mysql(CHARSET_INFO *charset_info,
+ char *to, ulong to_length,
+ const char *from, ulong length);
extern void thd_increment_bytes_sent(ulong length);
extern void thd_increment_bytes_received(ulong length);
--- 1.98/include/mysql_com.h 2005-06-17 12:26:17 -07:00
+++ 1.99/include/mysql_com.h 2005-06-23 18:29:50 -07:00
@@ -148,6 +148,7 @@
*/
#define SERVER_STATUS_LAST_ROW_SENT 128
#define SERVER_STATUS_DB_DROPPED 256 /* A database was dropped */
+#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
#define MYSQL_ERRMSG_SIZE 512
#define NET_READ_TIMEOUT 30 /* Timeout on read */
--- 1.218/libmysql/libmysql.c 2005-06-17 12:26:17 -07:00
+++ 1.219/libmysql/libmysql.c 2005-06-23 18:29:50 -07:00
@@ -1616,7 +1616,14 @@
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
+ if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
+ {
+ return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
+ }
+ else
+ {
+ return escape_string_for_mysql(mysql->charset, to, 0, from, length);
+ }
}
--- 1.138/mysys/charset.c 2005-06-16 00:17:07 -07:00
+++ 1.139/mysys/charset.c 2005-06-23 18:29:50 -07:00
@@ -656,3 +656,67 @@
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);
+}
--- 1.190/sql/sql_class.cc 2005-06-23 09:22:02 -07:00
+++ 1.191/sql/sql_class.cc 2005-06-23 18:29:51 -07:00
@@ -282,6 +282,8 @@
#endif
pthread_mutex_unlock(&LOCK_global_system_variables);
server_status= SERVER_STATUS_AUTOCOMMIT;
+ if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
+ server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
options= thd_startup_options;
open_options=ha_open_options;
update_lock_default= (variables.low_priority_updates ?
--- 1.121/sql/set_var.cc 2005-06-22 02:08:21 -07:00
+++ 1.122/sql/set_var.cc 2005-06-23 18:29:51 -07:00
@@ -3238,7 +3238,16 @@
global_system_variables.sql_mode=
fix_sql_mode(global_system_variables.sql_mode);
else
+ {
thd->variables.sql_mode= fix_sql_mode(thd->variables.sql_mode);
+ /*
+ Update thd->server_status
+ */
+ if (thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
+ thd->server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
+ else
+ thd->server_status&= ~SERVER_STATUS_NO_BACKSLASH_ESCAPES;
+ }
}
/* Map database specific bits to function bits */
--- 1.128/tests/mysql_client_test.c 2005-06-20 04:38:09 -07:00
+++ 1.129/tests/mysql_client_test.c 2005-06-23 18:29:51 -07:00
@@ -13332,6 +13332,35 @@
mysql_close(mysql1);
}
+
+/*
+ Check that the server signals when NO_BACKSLASH_ESCAPES mode is in effect,
+ and mysql_real_escape_string() does the right thing as a result.
+*/
+
+static void test_bug10214()
+{
+ MYSQL_RES* res ;
+ int len;
+ char out[8];
+
+ myheader("test_bug10214");
+
+ DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES));
+
+ len= mysql_real_escape_string(mysql, out, "a'b\\c", 5);
+ DIE_UNLESS(memcmp(out, "a\\'b\\\\c", len) == 0);
+
+ mysql_query(mysql, "set sql_mode='NO_BACKSLASH_ESCAPES'");
+ DIE_UNLESS(mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES);
+
+ len= mysql_real_escape_string(mysql, out, "a'b\\c", 5);
+ DIE_UNLESS(memcmp(out, "a''b\\c", len) == 0);
+
+ mysql_query(mysql, "set sql_mode=''");
+}
+
+
/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -13567,6 +13596,7 @@
{ "test_bug10729", test_bug10729 },
{ "test_bug11111", test_bug11111 },
{ "test_bug9992", test_bug9992 },
+ { "test_bug10214", test_bug10214 },
{ 0, 0 }
};
| Thread |
|---|
| • bk commit into 5.0 tree (jimw:1.2006) BUG#10214 | Jim Winstead | 24 Jun |