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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
1530dd73
Commit
1530dd73
authored
Mar 04, 2004
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UNHEX() function
parent
ceacb034
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
11 deletions
+87
-11
mysql-test/r/func_str.result
mysql-test/r/func_str.result
+9
-0
mysql-test/t/func_str.test
mysql-test/t/func_str.test
+3
-0
sql/item_create.cc
sql/item_create.cc
+5
-0
sql/item_create.h
sql/item_create.h
+1
-0
sql/item_strfunc.cc
sql/item_strfunc.cc
+43
-1
sql/item_strfunc.h
sql/item_strfunc.h
+25
-10
sql/lex.h
sql/lex.h
+1
-0
No files found.
mysql-test/r/func_str.result
View file @
1530dd73
...
...
@@ -192,6 +192,15 @@ length(quote(concat(char(0),"test")))
select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235))));
hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235))))
27E0E3E6E7E8EAEB27
select unhex(hex("foobar")), hex(unhex("1234567890ABCDEF")), unhex("345678");
unhex(hex("foobar")) hex(unhex("1234567890ABCDEF")) unhex("345678")
foobar 1234567890ABCDEF 4Vx
select hex(unhex("1")), hex(unhex("12")), hex(unhex("123")), hex(unhex("1234")), hex(unhex("12345")), hex(unhex("123456"));
hex(unhex("1")) hex(unhex("12")) hex(unhex("123")) hex(unhex("1234")) hex(unhex("12345")) hex(unhex("123456"))
01 12 0123 1234 012345 123456
select length(unhex(md5("abrakadabra")));
length(unhex(md5("abrakadabra")))
16
select reverse("");
reverse("")
...
...
mysql-test/t/func_str.test
View file @
1530dd73
...
...
@@ -78,6 +78,9 @@ select quote(concat('abc\'', '\\cba'));
select
quote
(
1
/
0
),
quote
(
'\0\Z'
);
select
length
(
quote
(
concat
(
char
(
0
),
"test"
)));
select
hex
(
quote
(
concat
(
char
(
224
),
char
(
227
),
char
(
230
),
char
(
231
),
char
(
232
),
char
(
234
),
char
(
235
))));
select
unhex
(
hex
(
"foobar"
)),
hex
(
unhex
(
"1234567890ABCDEF"
)),
unhex
(
"345678"
);
select
hex
(
unhex
(
"1"
)),
hex
(
unhex
(
"12"
)),
hex
(
unhex
(
"123"
)),
hex
(
unhex
(
"1234"
)),
hex
(
unhex
(
"12345"
)),
hex
(
unhex
(
"123456"
));
select
length
(
unhex
(
md5
(
"abrakadabra"
)));
#
# Wrong usage of functions
...
...
sql/item_create.cc
View file @
1530dd73
...
...
@@ -426,6 +426,11 @@ Item *create_func_ucase(Item* a)
return
new
Item_func_ucase
(
a
);
}
Item
*
create_func_unhex
(
Item
*
a
)
{
return
new
Item_func_unhex
(
a
);
}
Item
*
create_func_uuid
(
void
)
{
return
new
Item_func_uuid
();
...
...
sql/item_create.h
View file @
1530dd73
...
...
@@ -92,6 +92,7 @@ Item *create_func_time_format(Item *a, Item *b);
Item
*
create_func_time_to_sec
(
Item
*
a
);
Item
*
create_func_to_days
(
Item
*
a
);
Item
*
create_func_ucase
(
Item
*
a
);
Item
*
create_func_unhex
(
Item
*
a
);
Item
*
create_func_uuid
(
void
);
Item
*
create_func_version
(
void
);
Item
*
create_func_weekday
(
Item
*
a
);
...
...
sql/item_strfunc.cc
View file @
1530dd73
...
...
@@ -2231,7 +2231,7 @@ String *Item_func_hex::val_str(String *str)
null_value
=
0
;
tmp_value
.
length
(
res
->
length
()
*
2
);
for
(
from
=
res
->
ptr
(),
end
=
from
+
res
->
length
(),
to
=
(
char
*
)
tmp_value
.
ptr
();
from
!=
end
;
from
<
end
;
from
++
,
to
+=
2
)
{
uint
tmp
=
(
uint
)
(
uchar
)
*
from
;
...
...
@@ -2241,6 +2241,48 @@ String *Item_func_hex::val_str(String *str)
return
&
tmp_value
;
}
int
inline
hexchar_to_int
(
char
c
)
{
if
(
c
<=
'9'
&&
c
>=
'0'
)
return
c
-
'0'
;
c
|=
32
;
if
(
c
<=
'f'
&&
c
>=
'a'
)
return
c
-
'a'
+
10
;
return
-
1
;
}
String
*
Item_func_unhex
::
val_str
(
String
*
str
)
{
/* Convert given hex string to a binary string */
String
*
res
=
args
[
0
]
->
val_str
(
str
);
const
char
*
from
=
res
->
ptr
(),
*
end
;
char
*
to
;
int
r
;
if
(
!
res
||
tmp_value
.
alloc
((
1
+
res
->
length
())
/
2
))
{
null_value
=
1
;
return
0
;
}
null_value
=
0
;
tmp_value
.
length
((
1
+
res
->
length
())
/
2
);
to
=
(
char
*
)
tmp_value
.
ptr
();
if
(
res
->
length
()
%
2
)
{
*
to
++=
r
=
hexchar_to_int
(
*
from
++
);
if
((
null_value
=
(
r
==
-
1
)))
return
0
;
}
for
(
end
=
res
->
ptr
()
+
res
->
length
();
from
<
end
;
from
+=
2
,
to
++
)
{
*
to
=
(
r
=
hexchar_to_int
(
from
[
0
]))
<<
4
;
if
((
null_value
=
(
r
==
-
1
)))
return
0
;
*
to
|=
r
=
hexchar_to_int
(
from
[
1
]);
if
((
null_value
=
(
r
==
-
1
)))
return
0
;
}
return
&
tmp_value
;
}
void
Item_func_binary
::
print
(
String
*
str
)
{
...
...
sql/item_strfunc.h
View file @
1530dd73
...
...
@@ -523,6 +523,21 @@ public:
}
};
class
Item_func_unhex
:
public
Item_str_func
{
String
tmp_value
;
public:
Item_func_unhex
(
Item
*
a
)
:
Item_str_func
(
a
)
{}
const
char
*
func_name
()
const
{
return
"unhex"
;
}
String
*
val_str
(
String
*
);
void
fix_length_and_dec
()
{
collation
.
set
(
&
my_charset_bin
);
decimals
=
0
;
max_length
=
(
1
+
args
[
0
]
->
max_length
)
/
2
;
}
};
class
Item_func_binary
:
public
Item_str_func
{
...
...
sql/lex.h
View file @
1530dd73
...
...
@@ -671,6 +671,7 @@ static SYMBOL sql_functions[] = {
{
"UCASE"
,
F_SYM
(
FUNC_ARG1
),
0
,
CREATE_FUNC
(
create_func_ucase
)},
{
"UNCOMPRESS"
,
F_SYM
(
FUNC_ARG1
),
0
,
CREATE_FUNC
(
create_func_uncompress
)},
{
"UNCOMPRESSED_LENGTH"
,
F_SYM
(
FUNC_ARG1
),
0
,
CREATE_FUNC
(
create_func_uncompressed_length
)},
{
"UNHEX"
,
F_SYM
(
FUNC_ARG1
),
0
,
CREATE_FUNC
(
create_func_unhex
)},
{
"UNIQUE_USERS"
,
SYM
(
UNIQUE_USERS
)},
{
"UNIX_TIMESTAMP"
,
SYM
(
UNIX_TIMESTAMP
)},
{
"UPPER"
,
F_SYM
(
FUNC_ARG1
),
0
,
CREATE_FUNC
(
create_func_ucase
)},
...
...
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