Skip to content

Commit cbcd2ba

Browse files
committed
Implement escape quotes function for SERVER_STATUS_NO_BACKSLASH_ESCAPES properly
Fixes failing test t/45bind_no_backslash_escapes.t See: #164
1 parent 9e9b5f9 commit cbcd2ba

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

dbdimp.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,25 @@ static char **fill_out_embedded_options(char *options,
627627
return options_list;
628628
}
629629

630+
#if MYSQL_VERSION_ID < 50001
631+
/* MySQL client prior to version 5.0.1 does not implement mysql_real_escape_string() for SERVER_STATUS_NO_BACKSLASH_ESCAPES */
632+
static unsigned long string_escape_quotes(char *to, const char *from, unsigned long len)
633+
{
634+
const char *to_start = to;
635+
const char *end = from + len;
636+
637+
while (from < end)
638+
{
639+
if (*from == '\'')
640+
*to++ = '\'';
641+
*to++ = *from++;
642+
}
643+
644+
*to = '\0';
645+
return to - to_start;
646+
}
647+
#endif
648+
630649
/*
631650
constructs an SQL statement previously prepared with
632651
actual values replacing placeholders
@@ -838,9 +857,8 @@ static char *parse_params(
838857
#if MYSQL_VERSION_ID < 50001
839858
if (sock->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
840859
{
841-
*ptr++ = 'X';
842860
*ptr++ = '\'';
843-
ptr += mysql_hex_string(ptr, ph->value, ph->len);
861+
ptr += string_escape_quotes(ptr, ph->value, ph->len);
844862
*ptr++ = '\'';
845863
}
846864
else
@@ -6411,9 +6429,8 @@ SV* mariadb_db_quote(SV *dbh, SV *str, SV *type)
64116429
#if MYSQL_VERSION_ID < 50001
64126430
if (imp_dbh->pmysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
64136431
{
6414-
*sptr++ = 'X';
64156432
*sptr++ = '\'';
6416-
sptr += mysql_hex_string(sptr, ptr, len);
6433+
sptr += string_escape_quotes(sptr, ptr, len);
64176434
*sptr++ = '\'';
64186435
}
64196436
else

t/45bind_no_backslash_escapes.t

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ if ($dbh->{mariadb_serverversion} < 50001) {
1818
plan skip_all => "Servers < 5.0.1 do not support sql_mode NO_BACKSLASH_ESCAPES";
1919
}
2020

21-
if ($dbh->{mariadb_clientversion} < 50001) {
22-
$id2_quoted_no_backslash = q(X'737472696E675C737472696E6722737472696E6727737472696E67');
23-
}
24-
2521
plan tests => 20;
2622

2723
ok $dbh->do('CREATE TEMPORARY TABLE t(id VARCHAR(255), value TEXT)');

0 commit comments

Comments
 (0)