summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <bar@bar.intranet.mysql.r18.ru>2004-03-26 16:11:46 +0400
committerunknown <bar@bar.intranet.mysql.r18.ru>2004-03-26 16:11:46 +0400
commit3eff43162ba3136ecd305534f1e9d7cc779ce301 (patch)
treec8c034c5ee2087b4b6a01f36456f4ca2bd8d20dc
parentc1e76fc06051f7f061f40d44e2b846ab04fdabfd (diff)
downloadmariadb-git-3eff43162ba3136ecd305534f1e9d7cc779ce301.tar.gz
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.
-rw-r--r--include/mysql_com.h1
-rw-r--r--mysql-test/r/alter_table.result2
-rw-r--r--mysql-test/r/cast.result18
-rw-r--r--mysql-test/r/ctype_utf8.result2
-rw-r--r--mysql-test/r/date_formats.result2
-rw-r--r--mysql-test/r/range.result2
-rw-r--r--mysql-test/r/system_mysql_db.result36
-rw-r--r--mysql-test/r/type_blob.result8
-rw-r--r--mysql-test/r/union.result6
-rw-r--r--mysql-test/t/alter_table.test2
-rw-r--r--mysql-test/t/cast.test4
-rw-r--r--mysql-test/t/range.test2
-rw-r--r--mysql-test/t/type_blob.test4
-rw-r--r--sql/field.cc3
-rw-r--r--sql/field.h6
-rw-r--r--sql/sql_show.cc31
-rw-r--r--sql/sql_table.cc12
-rw-r--r--sql/sql_yacc.yy4
18 files changed, 78 insertions, 67 deletions
diff --git a/include/mysql_com.h b/include/mysql_com.h
index d4c1ac5440a..4b94fc71c0c 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -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 */
diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result
index 571ba7429fc..9b90742762e 100644
--- a/mysql-test/r/alter_table.result
+++ b/mysql-test/r/alter_table.result
@@ -321,7 +321,7 @@ alter table t1 change a a char(10) character set cp1251;
select a,hex(a) from t1;
a hex(a)
ÔÅÓÔ 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)
òåñò F2E5F1F2
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result
index 877a349d188..cdeb5b3dc21 100644
--- a/mysql-test/r/cast.result
+++ b/mysql-test/r/cast.result
@@ -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
diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result
index aacd80f19bb..33a7e91fbeb 100644
--- a/mysql-test/r/ctype_utf8.result
+++ b/mysql-test/r/ctype_utf8.result
@@ -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")
diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result
index f1582707cf5..fba1d9f47e3 100644
--- a/mysql-test/r/date_formats.result
+++ b/mysql-test/r/date_formats.result
@@ -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,
diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result
index ab66d786833..d1a5dd00370 100644
--- a/mysql-test/r/range.result
+++ b/mysql-test/r/range.result
@@ -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 '',
diff --git a/mysql-test/r/system_mysql_db.result b/mysql-test/r/system_mysql_db.result
index 8da46564619..d6d9aa1546b 100644
--- a/mysql-test/r/system_mysql_db.result
+++ b/mysql-test/r/system_mysql_db.result
@@ -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`)
diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result
index d44face6512..e9861266b78 100644
--- a/mysql-test/r/type_blob.result
+++ b/mysql-test/r/type_blob.result
@@ -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
diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result
index ece2970198b..8e288f9725f 100644
--- a/mysql-test/r/union.result
+++ b/mysql-test/r/union.result
@@ -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;
diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test
index 39c84eceb94..9235496b45c 100644
--- a/mysql-test/t/alter_table.test
+++ b/mysql-test/t/alter_table.test
@@ -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;
diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test
index fab35bb334a..e2deb792d47 100644
--- a/mysql-test/t/cast.test
+++ b/mysql-test/t/cast.test
@@ -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
diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test
index 642dac471da..51b1f34ee79 100644
--- a/mysql-test/t/range.test
+++ b/mysql-test/t/range.test
@@ -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 '',
diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test
index cae64b9dd27..8c6cabd997b 100644
--- a/mysql-test/t/type_blob.test
+++ b/mysql-test/t/type_blob.test
@@ -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");
diff --git a/sql/field.cc b/sql/field.cc
index b7362d74c5f..474715f4e26 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -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);
}
diff --git a/sql/field.h b/sql/field.h
index 22d406b339a..e6ed5c2dbb7 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -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; }
};
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 221045c40ca..30adc06fbd0 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -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);
}
}
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 099dab8885b..be3615c71ce 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -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 */
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 8184ea366d9..90dc209f0bc 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -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; }