1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

1. New data types, from the user point of view:

BINARY(N) and VARBIBARY(N)
2. More 4.0 compatibility and more BINARY keyword consistency:
2a. CREATE TABLE a (a CHAR(N) BINARY) 
    is now synonym for
    CREATE TABLE a (a CHAR(N) COLLATE xxxx_bin)
2b. SELECT BINARY x
    is still synonin for
    SELECT x COLLATE xxxxx_bin.
This commit is contained in:
bar@bar.intranet.mysql.r18.ru
2004-03-26 16:11:46 +04:00
parent 9bf7e07b75
commit 3aea3e92ce
18 changed files with 78 additions and 67 deletions

View File

@ -78,6 +78,7 @@ enum enum_server_command
#define PART_KEY_FLAG 16384 /* Intern; Part of some key */
#define GROUP_FLAG 32768 /* Intern: Group field */
#define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */
#define BINCMP_FLAG 131072 /* Intern: Used by sql_yacc */
#define REFRESH_GRANT 1 /* Refresh grant tables */
#define REFRESH_LOG 2 /* Start on new log file */

View File

@ -321,7 +321,7 @@ alter table t1 change a a char(10) character set cp1251;
select a,hex(a) from t1;
a hex(a)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> F2E5F1F2
alter table t1 change a a char(10) binary;
alter table t1 change a a binary(10);
select a,hex(a) from t1;
a hex(a)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> F2E5F1F2

View File

@ -51,11 +51,11 @@ CONVERT(DATE "2004-01-22 21:45:33",CHAR)
select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4));
CONVERT(DATE "2004-01-22 21:45:33",CHAR(4))
2004
select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4) BINARY);
CONVERT(DATE "2004-01-22 21:45:33",CHAR(4) BINARY)
select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4));
CONVERT(DATE "2004-01-22 21:45:33",BINARY(4))
2004
select CAST(DATE "2004-01-22 21:45:33" AS CHAR(4) BINARY);
CAST(DATE "2004-01-22 21:45:33" AS CHAR(4) BINARY)
select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));
CAST(DATE "2004-01-22 21:45:33" AS BINARY(4))
2004
set names binary;
select cast(_latin1'test' as char character set latin2);
@ -91,11 +91,11 @@ ab a ab a a
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` char(2) binary NOT NULL default '',
`c2` char(2) binary NOT NULL default '',
`c3` char(2) binary NOT NULL default '',
`c4` char(2) binary NOT NULL default '',
`c5` char(2) binary NOT NULL default ''
`c1` binary(2) NOT NULL default '',
`c2` binary(2) NOT NULL default '',
`c3` binary(2) NOT NULL default '',
`c4` binary(2) NOT NULL default '',
`c5` binary(2) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
select

View File

@ -73,7 +73,7 @@ create table t1 select date_format("2004-01-19 10:10:10", "%Y-%m-%d");
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`date_format("2004-01-19 10:10:10", "%Y-%m-%d")` char(10) binary default NULL
`date_format("2004-01-19 10:10:10", "%Y-%m-%d")` binary(10) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from t1;
date_format("2004-01-19 10:10:10", "%Y-%m-%d")

View File

@ -364,7 +364,7 @@ str_to_date(a,b)
create table t2 select str_to_date(a,b) from t1;
describe t2;
Field Type Null Key Default Extra
str_to_date(a,b) char(29) YES NULL
str_to_date(a,b) binary(29) YES NULL
select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S") as f2,
str_to_date("2003-01-02", "%Y-%m-%d") as f3,

View File

@ -150,7 +150,7 @@ believe in myself
drop table t1;
CREATE TABLE t1 (
t1ID int(10) unsigned NOT NULL auto_increment,
art char(1) binary NOT NULL default '',
art binary(1) NOT NULL default '',
KNR char(5) NOT NULL default '',
RECHNR char(6) NOT NULL default '',
POSNR char(2) NOT NULL default '',

View File

@ -13,9 +13,9 @@ user
show create table db;
Table Create Table
db CREATE TABLE `db` (
`Host` char(60) binary NOT NULL default '',
`Db` char(64) binary NOT NULL default '',
`User` char(16) binary NOT NULL default '',
`Host` char(60) character set latin1 collate latin1_bin NOT NULL default '',
`Db` char(64) character set latin1 collate latin1_bin NOT NULL default '',
`User` char(16) character set latin1 collate latin1_bin NOT NULL default '',
`Select_priv` enum('N','Y') NOT NULL default 'N',
`Insert_priv` enum('N','Y') NOT NULL default 'N',
`Update_priv` enum('N','Y') NOT NULL default 'N',
@ -34,8 +34,8 @@ db CREATE TABLE `db` (
show create table host;
Table Create Table
host CREATE TABLE `host` (
`Host` char(60) binary NOT NULL default '',
`Db` char(64) binary NOT NULL default '',
`Host` char(60) character set latin1 collate latin1_bin NOT NULL default '',
`Db` char(64) character set latin1 collate latin1_bin NOT NULL default '',
`Select_priv` enum('N','Y') NOT NULL default 'N',
`Insert_priv` enum('N','Y') NOT NULL default 'N',
`Update_priv` enum('N','Y') NOT NULL default 'N',
@ -53,9 +53,9 @@ host CREATE TABLE `host` (
show create table user;
Table Create Table
user CREATE TABLE `user` (
`Host` varchar(60) binary NOT NULL default '',
`User` varchar(16) binary NOT NULL default '',
`Password` varchar(41) binary NOT NULL default '',
`Host` varchar(60) character set latin1 collate latin1_bin NOT NULL default '',
`User` varchar(16) character set latin1 collate latin1_bin NOT NULL default '',
`Password` varchar(41) character set latin1 collate latin1_bin NOT NULL default '',
`Select_priv` enum('N','Y') NOT NULL default 'N',
`Insert_priv` enum('N','Y') NOT NULL default 'N',
`Update_priv` enum('N','Y') NOT NULL default 'N',
@ -89,7 +89,7 @@ user CREATE TABLE `user` (
show create table func;
Table Create Table
func CREATE TABLE `func` (
`name` char(64) binary NOT NULL default '',
`name` char(64) character set latin1 collate latin1_bin NOT NULL default '',
`ret` tinyint(1) NOT NULL default '0',
`dl` char(128) NOT NULL default '',
`type` enum('function','aggregate') NOT NULL default 'function',
@ -98,10 +98,10 @@ func CREATE TABLE `func` (
show create table tables_priv;
Table Create Table
tables_priv CREATE TABLE `tables_priv` (
`Host` char(60) binary NOT NULL default '',
`Db` char(64) binary NOT NULL default '',
`User` char(16) binary NOT NULL default '',
`Table_name` char(64) binary NOT NULL default '',
`Host` char(60) character set latin1 collate latin1_bin NOT NULL default '',
`Db` char(64) character set latin1 collate latin1_bin NOT NULL default '',
`User` char(16) character set latin1 collate latin1_bin NOT NULL default '',
`Table_name` char(64) character set latin1 collate latin1_bin NOT NULL default '',
`Grantor` char(77) NOT NULL default '',
`Timestamp` timestamp NOT NULL,
`Table_priv` set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') NOT NULL default '',
@ -112,11 +112,11 @@ tables_priv CREATE TABLE `tables_priv` (
show create table columns_priv;
Table Create Table
columns_priv CREATE TABLE `columns_priv` (
`Host` char(60) binary NOT NULL default '',
`Db` char(64) binary NOT NULL default '',
`User` char(16) binary NOT NULL default '',
`Table_name` char(64) binary NOT NULL default '',
`Column_name` char(64) binary NOT NULL default '',
`Host` char(60) character set latin1 collate latin1_bin NOT NULL default '',
`Db` char(64) character set latin1 collate latin1_bin NOT NULL default '',
`User` char(16) character set latin1 collate latin1_bin NOT NULL default '',
`Table_name` char(64) character set latin1 collate latin1_bin NOT NULL default '',
`Column_name` char(64) character set latin1 collate latin1_bin NOT NULL default '',
`Timestamp` timestamp NOT NULL,
`Column_priv` set('Select','Insert','Update','References') NOT NULL default '',
PRIMARY KEY (`Host`,`Db`,`User`,`Table_name`,`Column_name`)

View File

@ -7,7 +7,7 @@ b text YES NULL
c blob YES NULL
d mediumtext YES NULL
e longtext YES NULL
CREATE TABLE t2 (a char(257), b varchar(70000) binary, c varchar(70000000));
CREATE TABLE t2 (a char(257), b varbinary(70000), c varchar(70000000));
Warnings:
Warning 1246 Converting column 'a' from CHAR to TEXT
Warning 1246 Converting column 'b' from CHAR to BLOB
@ -57,7 +57,7 @@ select * from t1;
a
Where
drop table t1;
create table t1 (t text,c char(10),b blob, d char(10) binary);
create table t1 (t text,c char(10),b blob, d binary(10));
insert into t1 values (NULL,NULL,NULL,NULL);
insert into t1 values ("","","","");
insert into t1 values ("hello","hello","hello","hello");
@ -73,14 +73,14 @@ Field Type Collation Null Key Default Extra Privileges Comment
t text latin1_swedish_ci YES NULL select,insert,update,references
c varchar(10) latin1_swedish_ci YES NULL select,insert,update,references
b blob NULL YES NULL select,insert,update,references
d varchar(10) binary YES NULL select,insert,update,references
d varbinary(10) NULL YES NULL select,insert,update,references
lock tables t1 WRITE;
show full fields from t1;
Field Type Collation Null Key Default Extra Privileges Comment
t text latin1_swedish_ci YES NULL select,insert,update,references
c varchar(10) latin1_swedish_ci YES NULL select,insert,update,references
b blob NULL YES NULL select,insert,update,references
d varchar(10) binary YES NULL select,insert,update,references
d varbinary(10) NULL YES NULL select,insert,update,references
unlock tables;
select t from t1 where t like "hello";
t

View File

@ -649,7 +649,7 @@ f
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f` char(12) binary default NULL
`f` binary(12) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT y from t2 UNION select da from t2;
@ -660,7 +660,7 @@ y
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`y` char(10) binary default NULL
`y` binary(10) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT y from t2 UNION select dt from t2;
@ -671,7 +671,7 @@ y
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`y` char(19) binary default NULL
`y` binary(19) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT da from t2 UNION select dt from t2;

View File

@ -193,7 +193,7 @@ insert into t1 values ('
select a,hex(a) from t1;
alter table t1 change a a char(10) character set cp1251;
select a,hex(a) from t1;
alter table t1 change a a char(10) binary;
alter table t1 change a a binary(10);
select a,hex(a) from t1;
alter table t1 change a a char(10) character set cp1251;
select a,hex(a) from t1;

View File

@ -19,8 +19,8 @@ select CONVERT("2004-01-22 21:45:33",DATE);
select CONVERT(DATE "2004-01-22 21:45:33" USING latin1);
select CONVERT(DATE "2004-01-22 21:45:33",CHAR);
select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4));
select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4) BINARY);
select CAST(DATE "2004-01-22 21:45:33" AS CHAR(4) BINARY);
select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4));
select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));
#
# Character set convertion

View File

@ -118,7 +118,7 @@ drop table t1;
CREATE TABLE t1 (
t1ID int(10) unsigned NOT NULL auto_increment,
art char(1) binary NOT NULL default '',
art binary(1) NOT NULL default '',
KNR char(5) NOT NULL default '',
RECHNR char(6) NOT NULL default '',
POSNR char(2) NOT NULL default '',

View File

@ -16,7 +16,7 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7;
CREATE TABLE t1 (a blob, b text, c blob(250), d text(70000), e text(70000000));
show columns from t1;
CREATE TABLE t2 (a char(257), b varchar(70000) binary, c varchar(70000000));
CREATE TABLE t2 (a char(257), b varbinary(70000), c varchar(70000000));
show columns from t2;
create table t3 (a long, b long byte);
show create TABLE t3;
@ -62,7 +62,7 @@ drop table t1;
#
# test of blob, text, char and char binary
#
create table t1 (t text,c char(10),b blob, d char(10) binary);
create table t1 (t text,c char(10),b blob, d binary(10));
insert into t1 values (NULL,NULL,NULL,NULL);
insert into t1 values ("","","","");
insert into t1 values ("hello","hello","hello","hello");

View File

@ -4224,7 +4224,8 @@ void Field_string::sql_type(String &res) const
(field_length > 3 &&
(table->db_options_in_use &
HA_OPTION_PACK_RECORD) ?
"varchar" : "char"),
(has_charset() ? "varchar" : "varbinary") :
(has_charset() ? "char" : "binary")),
(int) field_length / charset()->mbmaxlen);
res.length(length);
}

View File

@ -864,7 +864,8 @@ public:
uint max_packed_col_length(uint max_length);
uint size_of() const { return sizeof(*this); }
enum_field_types real_type() const { return FIELD_TYPE_STRING; }
bool has_charset(void) const { return TRUE; }
bool has_charset(void) const
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
field_cast_enum field_cast_type() { return FIELD_CAST_STRING; }
};
@ -911,7 +912,8 @@ public:
uint max_packed_col_length(uint max_length);
uint size_of() const { return sizeof(*this); }
enum_field_types real_type() const { return FIELD_TYPE_VAR_STRING; }
bool has_charset(void) const { return TRUE; }
bool has_charset(void) const
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
field_cast_enum field_cast_type() { return FIELD_CAST_VARSTRING; }
};

View File

@ -1247,26 +1247,21 @@ store_create_info(THD *thd, TABLE *table, String *packet)
field->sql_type(type);
packet->append(type.ptr(),type.length());
if (field->has_charset())
if (field->has_charset() && !limited_mysql_mode && !foreign_db_mode)
{
if (field->charset() == &my_charset_bin)
packet->append(" binary", 7);
else if (!limited_mysql_mode && !foreign_db_mode)
if (field->charset() != table->table_charset)
{
if (field->charset() != table->table_charset)
{
packet->append(" character set ", 15);
packet->append(field->charset()->csname);
}
/*
For string types dump collation name only if
collation is not primary for the given charset
*/
if (!(field->charset()->state & MY_CS_PRIMARY))
{
packet->append(" collate ", 9);
packet->append(field->charset()->name);
}
packet->append(" character set ", 15);
packet->append(field->charset()->csname);
}
/*
For string types dump collation name only if
collation is not primary for the given charset
*/
if (!(field->charset()->state & MY_CS_PRIMARY))
{
packet->append(" collate ", 9);
packet->append(field->charset()->name);
}
}

View File

@ -476,6 +476,18 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
*/
if (create_info->table_charset && sql_field->charset != &my_charset_bin)
sql_field->charset= create_info->table_charset;
CHARSET_INFO *savecs= sql_field->charset;
if ((sql_field->flags & BINCMP_FLAG) &&
!(sql_field->charset= get_charset_by_csname(sql_field->charset->csname,
MY_CS_BINSORT,MYF(0))))
{
char tmp[64];
strmake(strmake(tmp, savecs->csname, sizeof(tmp)-4), "_bin", 4);
my_error(ER_UNKNOWN_COLLATION, MYF(0), tmp);
DBUG_RETURN(-1);
}
sql_field->create_length_to_internal_length();
/* Don't pack keys in old tables if the user has requested this */

View File

@ -1450,6 +1450,7 @@ attribute:
| UNIQUE_SYM { Lex->type|= UNIQUE_FLAG; }
| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
| COMMENT_SYM TEXT_STRING_sys { Lex->comment= &$2; }
| BINARY { Lex->type|= BINCMP_FLAG; }
| COLLATE_SYM collation_name
{
if (Lex->charset && !my_charset_same(Lex->charset,$2))
@ -1531,7 +1532,6 @@ opt_binary:
/* empty */ { Lex->charset=NULL; }
| ASCII_SYM { Lex->charset=&my_charset_latin1; }
| BYTE_SYM { Lex->charset=&my_charset_bin; }
| BINARY { Lex->charset=&my_charset_bin; }
| UNICODE_SYM
{
if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0))))
@ -3089,7 +3089,7 @@ in_sum_expr:
};
cast_type:
BINARY { $$=ITEM_CAST_BINARY; Lex->charset= NULL; Lex->length= (char*)0; }
BINARY opt_len { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; }
| CHAR_SYM opt_len opt_binary { $$=ITEM_CAST_CHAR; }
| NCHAR_SYM opt_len { $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; }
| SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }