custom/replacement function
- dark_lord
- Graduate


- Joined: Jan 14, 2009
- Posts: 162
- Loc: India-Kolkata
- Status: Offline
well i am working with very low version for a company i.e. PHP 2.2 something which is in PHPtriad!
there we cannot use mysql_real_escape_string() ?
solutions can be
1. Replacement of this?
2. What is there inside that function, so that i can make a custom function?
Anyone?
Thanks in advance!
there we cannot use mysql_real_escape_string() ?
solutions can be
1. Replacement of this?
2. What is there inside that function, so that i can make a custom function?
Anyone?
Thanks in advance!
Wrap Up your Big Url | Mariana World Community
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
May 15th, 2009, 9:03 am
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13458
- Loc: Florida
- Status: Offline
The PHP mysql_real_escape_string is just a wrapper around the MySQL APIs function of the same name.
http://dev.mysql.com/doc/refman/5.0/en/ ... tring.html
php_mysql.c:1684
http://dev.mysql.com/doc/refman/5.0/en/ ... tring.html
Code: [ Select ]
joebert@computer:~/php-5.2.9$ grep -n -r 'PHP_FUNCTION(mysql_real_escape_string)' .
./ext/mysql/php_mysql_structs.h:84:PHP_FUNCTION(mysql_real_escape_string);
./ext/mysql/php_mysql.c:1684:PHP_FUNCTION(mysql_real_escape_string)
joebert@computer:~/php-5.2.9$
./ext/mysql/php_mysql_structs.h:84:PHP_FUNCTION(mysql_real_escape_string);
./ext/mysql/php_mysql.c:1684:PHP_FUNCTION(mysql_real_escape_string)
joebert@computer:~/php-5.2.9$
- joebert@computer:~/php-5.2.9$ grep -n -r 'PHP_FUNCTION(mysql_real_escape_string)' .
- ./ext/mysql/php_mysql_structs.h:84:PHP_FUNCTION(mysql_real_escape_string);
- ./ext/mysql/php_mysql.c:1684:PHP_FUNCTION(mysql_real_escape_string)
- joebert@computer:~/php-5.2.9$
php_mysql.c:1684
Code: [ Select ]
PHP_FUNCTION(mysql_real_escape_string)
{
zval *mysql_link = NULL;
char *str;
char *new_str;
int id = -1, str_len, new_str_len;
php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &str, &str_len, &mysql_link) == FAILURE) {
return;
}
if (ZEND_NUM_ARGS() == 1) {
id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
CHECK_LINK(id);
}
ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
new_str = safe_emalloc(str_len, 2, 1);
new_str_len = mysql_real_escape_string(&mysql->conn, new_str, str, str_len);
new_str = erealloc(new_str, new_str_len + 1);
RETURN_STRINGL(new_str, new_str_len, 0);
}
{
zval *mysql_link = NULL;
char *str;
char *new_str;
int id = -1, str_len, new_str_len;
php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &str, &str_len, &mysql_link) == FAILURE) {
return;
}
if (ZEND_NUM_ARGS() == 1) {
id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
CHECK_LINK(id);
}
ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
new_str = safe_emalloc(str_len, 2, 1);
new_str_len = mysql_real_escape_string(&mysql->conn, new_str, str, str_len);
new_str = erealloc(new_str, new_str_len + 1);
RETURN_STRINGL(new_str, new_str_len, 0);
}
- PHP_FUNCTION(mysql_real_escape_string)
- {
- zval *mysql_link = NULL;
- char *str;
- char *new_str;
- int id = -1, str_len, new_str_len;
- php_mysql_conn *mysql;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &str, &str_len, &mysql_link) == FAILURE) {
- return;
- }
- if (ZEND_NUM_ARGS() == 1) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
- }
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
- new_str = safe_emalloc(str_len, 2, 1);
- new_str_len = mysql_real_escape_string(&mysql->conn, new_str, str, str_len);
- new_str = erealloc(new_str, new_str_len + 1);
- RETURN_STRINGL(new_str, new_str_len, 0);
- }
Strong with this one, the sudo is.
- dark_lord
- Graduate


- Joined: Jan 14, 2009
- Posts: 162
- Loc: India-Kolkata
- Status: Offline
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13458
- Loc: Florida
- Status: Offline
Does PHP 2.2 even support extensions ?
The MySQL extension you have doesn't support mysql_real_escape_string ?
Does the server even have MySQL support for PHP in PHP 2.2 ?
Did you read that manual page at MySQL.com ?
Do you have any way to request the character set in use by the MySQL server that wouldn't require you to escape any user input ? (an SQL query maybe)
Have you looked at the MySQL server source code to see if you can find the definition of the mysql_real_escape_string function in there ?
The MySQL extension you have doesn't support mysql_real_escape_string ?
Does the server even have MySQL support for PHP in PHP 2.2 ?
Did you read that manual page at MySQL.com ?
Do you have any way to request the character set in use by the MySQL server that wouldn't require you to escape any user input ? (an SQL query maybe)
Have you looked at the MySQL server source code to see if you can find the definition of the mysql_real_escape_string function in there ?
Strong with this one, the sudo is.
- dark_lord
- Graduate


- Joined: Jan 14, 2009
- Posts: 162
- Loc: India-Kolkata
- Status: Offline
1. probably yes
2. maybe
3. sort of
4. more or less
5. that was a tangent to my head
6. No, i found it bit complicated for me?!
I got the point, I will have to develop a function to validate the user inputs
that's why i was saying, any custom function...
Wrap Up your Big Url | Mariana World Community
- SpooF
- ٩๏̯͡๏۶


- Joined: May 22, 2004
- Posts: 3415
- Loc: Richland, WA
- Status: Offline
- SpooF
- ٩๏̯͡๏۶


- Joined: May 22, 2004
- Posts: 3415
- Loc: Richland, WA
- Status: Offline
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13458
- Loc: Florida
- Status: Offline
It's not as simple as escaping certain characters. You have to check configuration values of the MySQL server and also determine which character set is in use so you don't screw up multi-byte characters.
From the MySQL source.
./libmysqld/libmysql.c:1608
Notice how two different functions are called depending on the status of the MySQL server being queried ?
One function doubles up quotes and the other escapes them with backslashes.
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
./mysys/charset.c:618
From the MySQL source.
./libmysqld/libmysql.c:1608
Notice how two different functions are called depending on the status of the MySQL server being queried ?
One function doubles up quotes and the other escapes them with backslashes.
Code: [ Select ]
ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
- ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
Code: [ Select ]
/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
- /*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Code: [ Select ]
ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
- ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
Code: [ Select ]
/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
- /*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Code: [ Select ]
ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
- ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
Code: [ Select ]
/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
- /*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Code: [ Select ]
ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
- ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
Code: [ Select ]
/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
- /*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Code: [ Select ]
ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
- ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
Code: [ Select ]
/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
- /*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into
Code: [ Select ]
ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}
- ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
Code: [ Select ]
/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
- /*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
./mysys/charset.c:618
Code: [ Select ]
/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code][/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]/*
Escape string with backslashes (\)
SYNOPSIS
escape_string_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by adding backslashes before special
characters, and turning others into specific escape sequences, such as
turning newlines into \n and null bytes into [code]ulong STDCALL
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
ulong length)
{
if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
return escape_string_for_mysql(mysql->charset, to, 0, from, length);
}[/code]
Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
./mysys/charset.c:758
[code]/*
Escape apostrophes by doubling them up
SYNOPSIS
escape_quotes_for_mysql()
charset_info Charset of the strings
to Buffer for escaped string
to_length Length of destination buffer, or 0
from The string to escape
length The length of the string to escape
DESCRIPTION
This escapes the contents of a string by doubling up any apostrophes that
it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
effect on the server.
NOTE
To be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
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= FALSE;
#ifdef USE_MB
my_bool use_mb_flag= use_mb(charset_info);
#endif
for (end= from + length; from < end; from++)
{
#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= TRUE;
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= TRUE;
break;
}
*to++= '\'';
*to++= '\'';
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code]
./mysys/charset.c:618
[code]
- /*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into \0.
- NOTE
- To maintain compatibility with the old C API, to_length may be 0 to mean
- "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- ulong escape_string_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= FALSE;
- #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= TRUE;
- break;
- }
- while (tmp_length--)
- *to++= *from++;
- from--;
- continue;
- }
- /*
- If the next character appears to begin a multi-byte character, we
- escape that first byte of that apparent multi-byte character. (The
- character just looks like a multi-byte character -- if it were actually
- a multi-byte character, it would have been passed through in the test
- above.)
- Without this check, we can create a problem by converting an invalid
- multi-byte character into a valid one. For example, 0xbf27 is not
- a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
- */
- if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
- escape= *from;
- else
- #endif
- switch (*from) {
- case 0: /* Must be escaped for 'mysql' */
- escape= '0';
- break;
- case '\n': /* Must be escaped for logs */
- escape= 'n';
- break;
- case '\r':
- escape= 'r';
- break;
- case '\\':
- escape= '\\';
- break;
- case '\'':
- escape= '\'';
- break;
- case '"': /* Better safe than sorry */
- escape= '"';
- break;
- case '\032': /* This gives problems on Win32 */
- escape= 'Z';
- break;
- }
- if (escape)
- {
- if (to + 2 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= '\\';
- *to++= escape;
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}[/code].
NOTE
To maintain compatibility with the old C API, to_length may be 0 to mean
"big enough"
RETURN VALUES
~0 The escaped string did not fit in the to buffer
>=0 The length of the escaped string
*/
ulong escape_string_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= FALSE;
#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= TRUE;
break;
}
while (tmp_length--)
*to++= *from++;
from--;
continue;
}
/*
If the next character appears to begin a multi-byte character, we
escape that first byte of that apparent multi-byte character. (The
character just looks like a multi-byte character -- if it were actually
a multi-byte character, it would have been passed through in the test
above.)
Without this check, we can create a problem by converting an invalid
multi-byte character into a valid one. For example, 0xbf27 is not
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
*/
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
escape= *from;
else
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
escape= '0';
break;
case '\n': /* Must be escaped for logs */
escape= 'n';
break;
case '\r':
escape= 'r';
break;
case '\':
escape= '\';
break;
case '\'':
escape= '\'';
break;
case '"': /* Better safe than sorry */
escape= '"';
break;
case '2': /* This gives problems on Win32 */
escape= 'Z';
break;
}
if (escape)
{
if (to + 2 > to_end)
{
overflow= TRUE;
break;
}
*to++= '\';
*to++= escape;
}
else
{
if (to + 1 > to_end)
{
overflow= TRUE;
break;
}
*to++= *from;
}
}
*to= 0;
return overflow ? (ulong)~0 : (ulong) (to - to_start);
}
- /*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code]/*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into [code]ulong STDCALL
- mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
- ulong length)
- {
- if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
- return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
- return escape_string_for_mysql(mysql->charset, to, 0, from, length);
- }[/code]
- Here's the two functions, a quick glance at these looks like they could be rewritten in PHP for the most part.
- ./mysys/charset.c:758
- [code]/*
- Escape apostrophes by doubling them up
- SYNOPSIS
- escape_quotes_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by doubling up any apostrophes that
- it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
- effect on the server.
- NOTE
- To be consistent with escape_string_for_mysql(), to_length may be 0 to
- mean "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- 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= FALSE;
- #ifdef USE_MB
- my_bool use_mb_flag= use_mb(charset_info);
- #endif
- for (end= from + length; from < end; from++)
- {
- #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= TRUE;
- 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= TRUE;
- break;
- }
- *to++= '\'';
- *to++= '\'';
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code]
- ./mysys/charset.c:618
- [code][/code].
- /*
- Escape string with backslashes (\)
- SYNOPSIS
- escape_string_for_mysql()
- charset_info Charset of the strings
- to Buffer for escaped string
- to_length Length of destination buffer, or 0
- from The string to escape
- length The length of the string to escape
- DESCRIPTION
- This escapes the contents of a string by adding backslashes before special
- characters, and turning others into specific escape sequences, such as
- turning newlines into \n and null bytes into \0.
- NOTE
- To maintain compatibility with the old C API, to_length may be 0 to mean
- "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- ulong escape_string_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= FALSE;
- #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= TRUE;
- break;
- }
- while (tmp_length--)
- *to++= *from++;
- from--;
- continue;
- }
- /*
- If the next character appears to begin a multi-byte character, we
- escape that first byte of that apparent multi-byte character. (The
- character just looks like a multi-byte character -- if it were actually
- a multi-byte character, it would have been passed through in the test
- above.)
- Without this check, we can create a problem by converting an invalid
- multi-byte character into a valid one. For example, 0xbf27 is not
- a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
- */
- if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
- escape= *from;
- else
- #endif
- switch (*from) {
- case 0: /* Must be escaped for 'mysql' */
- escape= '0';
- break;
- case '\n': /* Must be escaped for logs */
- escape= 'n';
- break;
- case '\r':
- escape= 'r';
- break;
- case '\\':
- escape= '\\';
- break;
- case '\'':
- escape= '\'';
- break;
- case '"': /* Better safe than sorry */
- escape= '"';
- break;
- case '\032': /* This gives problems on Win32 */
- escape= 'Z';
- break;
- }
- if (escape)
- {
- if (to + 2 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= '\\';
- *to++= escape;
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
- NOTE
- To maintain compatibility with the old C API, to_length may be 0 to mean
- "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- ulong escape_string_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= FALSE;
- #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= TRUE;
- break;
- }
- while (tmp_length--)
- *to++= *from++;
- from--;
- continue;
- }
- /*
- If the next character appears to begin a multi-byte character, we
- escape that first byte of that apparent multi-byte character. (The
- character just looks like a multi-byte character -- if it were actually
- a multi-byte character, it would have been passed through in the test
- above.)
- Without this check, we can create a problem by converting an invalid
- multi-byte character into a valid one. For example, 0xbf27 is not
- a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
- */
- if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
- escape= *from;
- else
- #endif
- switch (*from) {
- case 0: /* Must be escaped for 'mysql' */
- escape= '0';
- break;
- case '\n': /* Must be escaped for logs */
- escape= 'n';
- break;
- case '\r':
- escape= 'r';
- break;
- case '\':
- escape= '\';
- break;
- case '\'':
- escape= '\'';
- break;
- case '"': /* Better safe than sorry */
- escape= '"';
- break;
- case '2': /* This gives problems on Win32 */
- escape= 'Z';
- break;
- }
- if (escape)
- {
- if (to + 2 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= '\';
- *to++= escape;
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code].
- NOTE
- To maintain compatibility with the old C API, to_length may be 0 to mean
- "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- ulong escape_string_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= FALSE;
- #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= TRUE;
- break;
- }
- while (tmp_length--)
- *to++= *from++;
- from--;
- continue;
- }
- /*
- If the next character appears to begin a multi-byte character, we
- escape that first byte of that apparent multi-byte character. (The
- character just looks like a multi-byte character -- if it were actually
- a multi-byte character, it would have been passed through in the test
- above.)
- Without this check, we can create a problem by converting an invalid
- multi-byte character into a valid one. For example, 0xbf27 is not
- a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
- */
- if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
- escape= *from;
- else
- #endif
- switch (*from) {
- case 0: /* Must be escaped for 'mysql' */
- escape= '0';
- break;
- case '\n': /* Must be escaped for logs */
- escape= 'n';
- break;
- case '\r':
- escape= 'r';
- break;
- case '\':
- escape= '\';
- break;
- case '\'':
- escape= '\'';
- break;
- case '"': /* Better safe than sorry */
- escape= '"';
- break;
- case '2': /* This gives problems on Win32 */
- escape= 'Z';
- break;
- }
- if (escape)
- {
- if (to + 2 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= '\';
- *to++= escape;
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code].
- NOTE
- To maintain compatibility with the old C API, to_length may be 0 to mean
- "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- ulong escape_string_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= FALSE;
- #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= TRUE;
- break;
- }
- while (tmp_length--)
- *to++= *from++;
- from--;
- continue;
- }
- /*
- If the next character appears to begin a multi-byte character, we
- escape that first byte of that apparent multi-byte character. (The
- character just looks like a multi-byte character -- if it were actually
- a multi-byte character, it would have been passed through in the test
- above.)
- Without this check, we can create a problem by converting an invalid
- multi-byte character into a valid one. For example, 0xbf27 is not
- a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
- */
- if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
- escape= *from;
- else
- #endif
- switch (*from) {
- case 0: /* Must be escaped for 'mysql' */
- escape= '0';
- break;
- case '\n': /* Must be escaped for logs */
- escape= 'n';
- break;
- case '\r':
- escape= 'r';
- break;
- case '\':
- escape= '\';
- break;
- case '\'':
- escape= '\'';
- break;
- case '"': /* Better safe than sorry */
- escape= '"';
- break;
- case '2': /* This gives problems on Win32 */
- escape= 'Z';
- break;
- }
- if (escape)
- {
- if (to + 2 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= '\';
- *to++= escape;
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code].
- NOTE
- To maintain compatibility with the old C API, to_length may be 0 to mean
- "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- ulong escape_string_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= FALSE;
- #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= TRUE;
- break;
- }
- while (tmp_length--)
- *to++= *from++;
- from--;
- continue;
- }
- /*
- If the next character appears to begin a multi-byte character, we
- escape that first byte of that apparent multi-byte character. (The
- character just looks like a multi-byte character -- if it were actually
- a multi-byte character, it would have been passed through in the test
- above.)
- Without this check, we can create a problem by converting an invalid
- multi-byte character into a valid one. For example, 0xbf27 is not
- a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
- */
- if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
- escape= *from;
- else
- #endif
- switch (*from) {
- case 0: /* Must be escaped for 'mysql' */
- escape= '0';
- break;
- case '\n': /* Must be escaped for logs */
- escape= 'n';
- break;
- case '\r':
- escape= 'r';
- break;
- case '\':
- escape= '\';
- break;
- case '\'':
- escape= '\'';
- break;
- case '"': /* Better safe than sorry */
- escape= '"';
- break;
- case '2': /* This gives problems on Win32 */
- escape= 'Z';
- break;
- }
- if (escape)
- {
- if (to + 2 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= '\';
- *to++= escape;
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }[/code].
- NOTE
- To maintain compatibility with the old C API, to_length may be 0 to mean
- "big enough"
- RETURN VALUES
- ~0 The escaped string did not fit in the to buffer
- >=0 The length of the escaped string
- */
- ulong escape_string_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= FALSE;
- #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= TRUE;
- break;
- }
- while (tmp_length--)
- *to++= *from++;
- from--;
- continue;
- }
- /*
- If the next character appears to begin a multi-byte character, we
- escape that first byte of that apparent multi-byte character. (The
- character just looks like a multi-byte character -- if it were actually
- a multi-byte character, it would have been passed through in the test
- above.)
- Without this check, we can create a problem by converting an invalid
- multi-byte character into a valid one. For example, 0xbf27 is not
- a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
- */
- if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
- escape= *from;
- else
- #endif
- switch (*from) {
- case 0: /* Must be escaped for 'mysql' */
- escape= '0';
- break;
- case '\n': /* Must be escaped for logs */
- escape= 'n';
- break;
- case '\r':
- escape= 'r';
- break;
- case '\':
- escape= '\';
- break;
- case '\'':
- escape= '\'';
- break;
- case '"': /* Better safe than sorry */
- escape= '"';
- break;
- case '2': /* This gives problems on Win32 */
- escape= 'Z';
- break;
- }
- if (escape)
- {
- if (to + 2 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= '\';
- *to++= escape;
- }
- else
- {
- if (to + 1 > to_end)
- {
- overflow= TRUE;
- break;
- }
- *to++= *from;
- }
- }
- *to= 0;
- return overflow ? (ulong)~0 : (ulong) (to - to_start);
- }
Strong with this one, the sudo is.
- SpooF
- ٩๏̯͡๏۶


- Joined: May 22, 2004
- Posts: 3415
- Loc: Richland, WA
- Status: Offline
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13458
- Loc: Florida
- Status: Offline
- dark_lord
- Graduate


- Joined: Jan 14, 2009
- Posts: 162
- Loc: India-Kolkata
- Status: Offline
SpooF wrote:
Any particular reason they are still using PHP 2.2?
i don't know either. It's a NON-IT company and I'm just working on contract basis.
I told them to upgrade but no use.
And Thanks I'll take care of what you guys told, specially about how it is done part!
Wrap Up your Big Url | Mariana World Community
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 11 posts
- Users browsing this forum: No registered users and 215 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
