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
5fa6c458
Commit
5fa6c458
authored
May 28, 2003
by
bar@bar.mysql.r18.ru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CAST(expr AS char) now supports character set with conversion:
SELECT CAST(_latin1'string' AS CHAR CHARACTER SET latin2)
parent
8254666d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
14 deletions
+41
-14
mysql-test/r/cast.result
mysql-test/r/cast.result
+13
-0
mysql-test/t/cast.test
mysql-test/t/cast.test
+9
-0
sql/item_create.cc
sql/item_create.cc
+5
-2
sql/item_create.h
sql/item_create.h
+1
-1
sql/sql_yacc.yy
sql/sql_yacc.yy
+13
-11
No files found.
mysql-test/r/cast.result
View file @
5fa6c458
...
@@ -28,6 +28,19 @@ cast("2001-1-1" as DATE) cast("2001-1-1" as DATETIME)
...
@@ -28,6 +28,19 @@ cast("2001-1-1" as DATE) cast("2001-1-1" as DATETIME)
select cast("1:2:3" as TIME);
select cast("1:2:3" as TIME);
cast("1:2:3" as TIME)
cast("1:2:3" as TIME)
01:02:03
01:02:03
select cast(_latin1'test' as char character set latin2);
cast(_latin1'test' as char character set latin2)
test
select cast(_koi8r'' as char character set cp1251);
cast(_koi8r'' as char character set cp1251)
create table t1 select cast(_koi8r'' as char character set cp1251) as t;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`t` char(4) character set cp1251 NOT NULL default ''
) TYPE=MyISAM CHARSET=latin1
drop table t1;
select cast("2001-1-1" as date) = "2001-01-01";
select cast("2001-1-1" as date) = "2001-01-01";
cast("2001-1-1" as date) = "2001-01-01"
cast("2001-1-1" as date) = "2001-01-01"
0
0
...
...
mysql-test/t/cast.test
View file @
5fa6c458
...
@@ -13,6 +13,15 @@ select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
...
@@ -13,6 +13,15 @@ select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
select
cast
(
"2001-1-1"
as
DATE
),
cast
(
"2001-1-1"
as
DATETIME
);
select
cast
(
"2001-1-1"
as
DATE
),
cast
(
"2001-1-1"
as
DATETIME
);
select
cast
(
"1:2:3"
as
TIME
);
select
cast
(
"1:2:3"
as
TIME
);
#
# Character set convertion
#
select
cast
(
_latin1
'test'
as
char
character
set
latin2
);
select
cast
(
_koi8r
''
as
char
character
set
cp1251
);
create
table
t1
select
cast
(
_koi8r
''
as
char
character
set
cp1251
)
as
t
;
show
create
table
t1
;
drop
table
t1
;
#
#
# The following should be fixed in 4.1
# The following should be fixed in 4.1
#
#
...
...
sql/item_create.cc
View file @
5fa6c458
...
@@ -457,13 +457,16 @@ Item *create_load_file(Item* a)
...
@@ -457,13 +457,16 @@ Item *create_load_file(Item* a)
}
}
Item
*
create_func_cast
(
Item
*
a
,
Item_cast
cast_type
)
Item
*
create_func_cast
(
Item
*
a
,
Item_cast
cast_type
,
CHARSET_INFO
*
cs
)
{
{
Item
*
res
;
Item
*
res
;
LINT_INIT
(
res
);
LINT_INIT
(
res
);
switch
(
cast_type
)
{
switch
(
cast_type
)
{
case
ITEM_CAST_BINARY
:
res
=
new
Item_func_binary
(
a
);
break
;
case
ITEM_CAST_BINARY
:
res
=
new
Item_func_binary
(
a
);
break
;
case
ITEM_CAST_CHAR
:
res
=
new
Item_char_typecast
(
a
);
break
;
case
ITEM_CAST_CHAR
:
res
=
(
cs
==
NULL
)
?
new
Item_char_typecast
(
a
)
:
new
Item_func_conv_charset
(
a
,
cs
);
break
;
case
ITEM_CAST_SIGNED_INT
:
res
=
new
Item_func_signed
(
a
);
break
;
case
ITEM_CAST_SIGNED_INT
:
res
=
new
Item_func_signed
(
a
);
break
;
case
ITEM_CAST_UNSIGNED_INT
:
res
=
new
Item_func_unsigned
(
a
);
break
;
case
ITEM_CAST_UNSIGNED_INT
:
res
=
new
Item_func_unsigned
(
a
);
break
;
case
ITEM_CAST_DATE
:
res
=
new
Item_date_typecast
(
a
);
break
;
case
ITEM_CAST_DATE
:
res
=
new
Item_date_typecast
(
a
);
break
;
...
...
sql/item_create.h
View file @
5fa6c458
...
@@ -28,7 +28,7 @@ Item *create_func_bit_length(Item* a);
...
@@ -28,7 +28,7 @@ Item *create_func_bit_length(Item* a);
Item
*
create_func_coercibility
(
Item
*
a
);
Item
*
create_func_coercibility
(
Item
*
a
);
Item
*
create_func_ceiling
(
Item
*
a
);
Item
*
create_func_ceiling
(
Item
*
a
);
Item
*
create_func_char_length
(
Item
*
a
);
Item
*
create_func_char_length
(
Item
*
a
);
Item
*
create_func_cast
(
Item
*
a
,
Item_cast
cast_type
);
Item
*
create_func_cast
(
Item
*
a
,
Item_cast
cast_type
,
CHARSET_INFO
*
cs
);
Item
*
create_func_connection_id
(
void
);
Item
*
create_func_connection_id
(
void
);
Item
*
create_func_conv
(
Item
*
a
,
Item
*
b
,
Item
*
c
);
Item
*
create_func_conv
(
Item
*
a
,
Item
*
b
,
Item
*
c
);
Item
*
create_func_cos
(
Item
*
a
);
Item
*
create_func_cos
(
Item
*
a
);
...
...
sql/sql_yacc.yy
View file @
5fa6c458
...
@@ -2233,10 +2233,12 @@ simple_expr:
...
@@ -2233,10 +2233,12 @@ simple_expr:
$$= new Item_func_set_collation($2,new Item_string(binary_keyword,
$$= new Item_func_set_collation($2,new Item_string(binary_keyword,
6, &my_charset_latin1));
6, &my_charset_latin1));
}
}
| CAST_SYM '(' expr AS cast_type ')' { $$= create_func_cast($3, $5); }
| CAST_SYM '(' expr AS cast_type ')'
{ $$= create_func_cast($3, $5, Lex->charset); }
| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
{ $$= new Item_func_case(* $4, $2, $5 ); }
{ $$= new Item_func_case(* $4, $2, $5 ); }
| CONVERT_SYM '(' expr ',' cast_type ')' { $$= create_func_cast($3, $5); }
| CONVERT_SYM '(' expr ',' cast_type ')'
{ $$= create_func_cast($3, $5, Lex->charset); }
| CONVERT_SYM '(' expr USING charset_name ')'
| CONVERT_SYM '(' expr USING charset_name ')'
{ $$= new Item_func_conv_charset($3,$5); }
{ $$= new Item_func_conv_charset($3,$5); }
| CONVERT_SYM '(' expr ',' expr ',' expr ')'
| CONVERT_SYM '(' expr ',' expr ',' expr ')'
...
@@ -2645,15 +2647,15 @@ in_sum_expr:
...
@@ -2645,15 +2647,15 @@ in_sum_expr:
};
};
cast_type:
cast_type:
BINARY { $$=ITEM_CAST_BINARY; }
BINARY { $$=ITEM_CAST_BINARY;
Lex->charset= NULL;
}
| CHAR_SYM
{ $$=ITEM_CAST_CHAR; }
| CHAR_SYM
opt_binary
{ $$=ITEM_CAST_CHAR; }
| SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; }
| SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT;
Lex->charset= NULL;
}
| SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; }
| SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT;
Lex->charset= NULL;
}
| UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; }
| UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT;
Lex->charset= NULL;
}
| UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT; }
| UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT;
Lex->charset= NULL;
}
| DATE_SYM { $$=ITEM_CAST_DATE; }
| DATE_SYM { $$=ITEM_CAST_DATE;
Lex->charset= NULL;
}
| TIME_SYM { $$=ITEM_CAST_TIME; }
| TIME_SYM { $$=ITEM_CAST_TIME;
Lex->charset= NULL;
}
| DATETIME { $$=ITEM_CAST_DATETIME; }
| DATETIME { $$=ITEM_CAST_DATETIME;
Lex->charset= NULL;
}
;
;
expr_list:
expr_list:
...
...
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