Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
de559604
Commit
de559604
authored
Jul 05, 2005
by
jimw@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add documentation to the escape_*() functions in mysys.
parent
3ccb90c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
16 deletions
+52
-16
mysys/charset.c
mysys/charset.c
+52
-16
No files found.
mysys/charset.c
View file @
de559604
...
...
@@ -561,11 +561,30 @@ CHARSET_INFO *get_charset_by_csname(const char *cs_name,
DBUG_RETURN
(
cs
);
}
/*
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 keep old C API, to_length may be 0 to mean "big enough"
RETURN
the length of the escaped string or ~0 if it did not fit.
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
,
...
...
@@ -573,20 +592,20 @@ ulong escape_string_for_mysql(CHARSET_INFO *charset_info,
{
const
char
*
to_start
=
to
;
const
char
*
end
,
*
to_end
=
to_start
+
(
to_length
?
to_length
-
1
:
2
*
length
);
my_bool
overflow
=
0
;
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
;
char
escape
=
0
;
#ifdef USE_MB
int
tmp_length
;
if
(
use_mb_flag
&&
(
tmp_length
=
my_ismbchar
(
charset_info
,
from
,
end
)))
{
if
(
to
+
tmp_length
>
to_end
)
{
overflow
=
1
;
overflow
=
TRUE
;
break
;
}
while
(
tmp_length
--
)
...
...
@@ -636,7 +655,7 @@ ulong escape_string_for_mysql(CHARSET_INFO *charset_info,
{
if
(
to
+
2
>
to_end
)
{
overflow
=
1
;
overflow
=
TRUE
;
break
;
}
*
to
++=
'\\'
;
...
...
@@ -646,7 +665,7 @@ ulong escape_string_for_mysql(CHARSET_INFO *charset_info,
{
if
(
to
+
1
>
to_end
)
{
overflow
=
1
;
overflow
=
TRUE
;
break
;
}
*
to
++=
*
from
;
...
...
@@ -658,11 +677,28 @@ ulong escape_string_for_mysql(CHARSET_INFO *charset_info,
/*
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
t
o be consistent with escape_string_for_mysql(), to_length may be 0 to
T
o be consistent with escape_string_for_mysql(), to_length may be 0 to
mean "big enough"
RETURN
the length of the escaped string or ~0 if it did not fit.
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
,
...
...
@@ -670,20 +706,20 @@ ulong escape_quotes_for_mysql(CHARSET_INFO *charset_info,
{
const
char
*
to_start
=
to
;
const
char
*
end
,
*
to_end
=
to_start
+
(
to_length
?
to_length
-
1
:
2
*
length
);
my_bool
overflow
=
0
;
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
;
char
escape
=
0
;
#ifdef USE_MB
int
tmp_length
;
if
(
use_mb_flag
&&
(
tmp_length
=
my_ismbchar
(
charset_info
,
from
,
end
)))
{
if
(
to
+
tmp_length
>
to_end
)
{
overflow
=
1
;
overflow
=
TRUE
;
break
;
}
while
(
tmp_length
--
)
...
...
@@ -701,7 +737,7 @@ ulong escape_quotes_for_mysql(CHARSET_INFO *charset_info,
{
if
(
to
+
2
>
to_end
)
{
overflow
=
1
;
overflow
=
TRUE
;
break
;
}
*
to
++=
'\''
;
...
...
@@ -711,7 +747,7 @@ ulong escape_quotes_for_mysql(CHARSET_INFO *charset_info,
{
if
(
to
+
1
>
to_end
)
{
overflow
=
1
;
overflow
=
TRUE
;
break
;
}
*
to
++=
*
from
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment