summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/mysqldump.c28
-rw-r--r--libmysql/libmysql.c3
-rw-r--r--libmysql/libmysql.def1
-rw-r--r--mysql-test/r/ctype_ucs.result7
-rw-r--r--mysql-test/r/ps.result6
-rw-r--r--mysql-test/t/ctype_ucs.test8
-rw-r--r--mysql-test/t/ps.test4
7 files changed, 34 insertions, 23 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 1686278096b..a8db8ab440b 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -124,7 +124,7 @@ const char *compatible_mode_names[]=
(1<<10) /* ANSI */\
)
TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
- "", compatible_mode_names};
+ "", compatible_mode_names, NULL};
static struct my_option my_long_options[] =
@@ -317,7 +317,7 @@ static struct my_option my_long_options[] =
{"comments", 'i', "Write additional information.",
(gptr*) &opt_comments, (gptr*) &opt_comments, 0, GET_BOOL, NO_ARG,
1, 0, 0, 0, 0, 0},
- {"hex-blob", OPT_HEXBLOB, "Dump BLOBs in HEX. this mode does not work with extended-insert",
+ {"hex-blob", OPT_HEXBLOB, "Dump BLOBs in HEX.",
(gptr*) &opt_hex_blob, (gptr*) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -1523,10 +1523,11 @@ static void dumpTable(uint numFields, char *table)
/*
63 is my_charset_bin. If charsetnr is not 63,
we have not a BLOB but a TEXT column.
- we'll dump it in hex only BLOB columns.
+ we'll dump in hex only BLOB columns.
*/
is_blob= (opt_hex_blob && field->charsetnr == 63 &&
- (field->type == FIELD_TYPE_BLOB ||
+ (field->type == FIELD_TYPE_STRING ||
+ field->type == FIELD_TYPE_BLOB ||
field->type == FIELD_TYPE_LONG_BLOB ||
field->type == FIELD_TYPE_MEDIUM_BLOB ||
field->type == FIELD_TYPE_TINY_BLOB)) ? 1 : 0;
@@ -1544,6 +1545,13 @@ static void dumpTable(uint numFields, char *table)
{
if (!IS_NUM_FIELD(field))
{
+ /*
+ "length * 2 + 2" is OK for both HEX and non-HEX modes:
+ - In HEX mode we need exactly 2 bytes per character
+ plus 2 bytes for '0x' prefix.
+ - In non-HEX mode we need up to 2 bytes per character,
+ plus 2 bytes for leading and trailing '\'' characters.
+ */
if (dynstr_realloc(&extended_row,length * 2+2))
{
fputs("Aborting dump (out of memory)",stderr);
@@ -1552,15 +1560,11 @@ static void dumpTable(uint numFields, char *table)
}
if (opt_hex_blob && is_blob)
{
- ulong counter;
- unsigned char *ptr= row[i];
dynstr_append(&extended_row, "0x");
- for (counter = 0; counter < lengths[i]; counter++)
- {
- char xx[3];
- sprintf(xx, "%02X", ptr[counter]);
- dynstr_append(&extended_row, xx);
- }
+ extended_row.length+= mysql_hex_string(extended_row.str +
+ extended_row.length,
+ row[i], length);
+ extended_row.str[extended_row.length]= '\0';
}
else
{
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 88f46ce19e7..a57c82e6424 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -1563,7 +1563,8 @@ void my_net_local_init(NET *net)
trailing '. The caller must supply whichever of those is desired.
*/
-ulong mysql_hex_string(char *to, const char *from, ulong length)
+ulong STDCALL
+mysql_hex_string(char *to, const char *from, ulong length)
{
char *to0= to;
const char *end;
diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def
index bc91e90a41c..c9ff70f208d 100644
--- a/libmysql/libmysql.def
+++ b/libmysql/libmysql.def
@@ -47,6 +47,7 @@ EXPORTS
mysql_errno
mysql_error
mysql_escape_string
+ mysql_hex_string
mysql_stmt_execute
mysql_stmt_fetch
mysql_stmt_fetch_column
diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result
index 1d3deb0b09a..0e36b00a670 100644
--- a/mysql-test/r/ctype_ucs.result
+++ b/mysql-test/r/ctype_ucs.result
@@ -480,3 +480,10 @@ a 0061
b 0062
c 0063
drop table t1;
+set @ivar= 1234;
+set @str1 = 'select ?';
+set @str2 = convert(@str1 using ucs2);
+prepare stmt1 from @str2;
+execute stmt1 using @ivar;
+?
+1234
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 6cad58282a2..6d9cfabb5a7 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -106,12 +106,6 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
set @fvar= 123.4567;
prepare stmt1 from @fvar;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '123.4567' at line 1
-set @str1 = 'select ?';
-set @str2 = convert(@str1 using ucs2);
-prepare stmt1 from @str2;
-execute stmt1 using @ivar;
-?
-1234
drop table t1,t2;
PREPARE stmt1 FROM "select _utf8 'A' collate utf8_bin = ?";
set @var='A';
diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test
index d9ef91496e9..4c6d1bbebef 100644
--- a/mysql-test/t/ctype_ucs.test
+++ b/mysql-test/t/ctype_ucs.test
@@ -315,3 +315,11 @@ alter table t1 modify a char(5);
select a, hex(a) from t1;
drop table t1;
+#
+# Check prepare statement from an UCS2 string
+#
+set @ivar= 1234;
+set @str1 = 'select ?';
+set @str2 = convert(@str1 using ucs2);
+prepare stmt1 from @str2;
+execute stmt1 using @ivar;
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index 978ce2bc2c3..2b3e961fc28 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -110,10 +110,6 @@ set @fvar= 123.4567;
--error 1064
prepare stmt1 from @fvar;
-set @str1 = 'select ?';
-set @str2 = convert(@str1 using ucs2);
-prepare stmt1 from @str2;
-execute stmt1 using @ivar;
drop table t1,t2;
#