Description:
We have problems in escaping BLOB fields if when "sjis" charset is used.
How to repeat:
/etc/my.cnf
[sjis]
default-character-set = sjis
==========
mysql> create table a (a blob);
==========
test.c
#include <stdio.h>
#include <string.h>
#include <mysql/mysql.h>
int main()
{
MYSQL *mysql, *con;
MYSQL_RES *res;
MYSQL_ROW row, end_row;
int r, i;
char buf[1024], *end;
unsigned char val[] = {0x7E, 0x00, 0x7F, 0x00, 0x80, 0x00, 0x81, 0x00, 0x82, 0x00 };
mysql = mysql_init(NULL);
if (NULL == mysql) { goto label1; }
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "sjis");
con = mysql_real_connect(mysql, NULL, "root", NULL, "s", 0, NULL, 0);
if (NULL == con) { goto label1; }
end = buf;
bcopy("INSERT INTO a VALUES (", buf, 22); end = end + 22;
*end = '\''; end++;
end += mysql_real_escape_string(mysql, end, val, 10);
*end = '\''; end++;
*end = ')'; end++;
r = mysql_real_query(mysql, buf, (unsigned int) (end - buf) );
mysql_close(mysql);
return 0;
label1:
return 1;
}
==========
hexdump after exec test.c
root@debian /var/mysql/data/s # hex a.MYD
0x00000000: 03 00 10 00 00 fe 0c 00 - 7e 00 7f 00 80 00 81 5c C@P@@.L@~@?@.@.\
0x00000010: 30 82 5c 30 - 0.\0