Commit 158b0603 authored by unknown's avatar unknown

Merge mysql.com:/nfsdisk1/lars/bkroot/mysql-4.1-rpl

into  mysql.com:/nfsdisk1/lars/MERGE/mysql-4.1-merge


sql/mysql_priv.h:
  Auto merged
sql/sql_parse.cc:
  Auto merged
parents f7e41bae 6dc02026
......@@ -2589,6 +2589,8 @@ static char *primary_key_fields(const char *table_name)
char show_keys_buff[15 + 64 * 2 + 3];
uint result_length = 0;
char *result = 0;
char buff[NAME_LEN * 2 + 3];
char *quoted_field;
my_snprintf(show_keys_buff, sizeof(show_keys_buff),
"SHOW KEYS FROM %s", table_name);
......@@ -2612,8 +2614,10 @@ static char *primary_key_fields(const char *table_name)
{
/* Key is unique */
do
result_length += strlen(row[4]) + 1; /* + 1 for ',' or \0 */
while ((row = mysql_fetch_row(res)) && atoi(row[3]) > 1);
{
quoted_field= quote_name(row[4], buff, 0);
result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
} while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1);
}
/* Build the ORDER BY clause result */
......@@ -2627,9 +2631,13 @@ static char *primary_key_fields(const char *table_name)
}
mysql_data_seek(res, 0);
row = mysql_fetch_row(res);
end = strmov(result, row[4]);
while ((row = mysql_fetch_row(res)) && atoi(row[3]) > 1)
end = strxmov(end, ",", row[4], NullS);
quoted_field= quote_name(row[4], buff, 0);
end= strmov(result, quoted_field);
while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1)
{
quoted_field= quote_name(row[4], buff, 0);
end= strxmov(end, ",", quoted_field, NullS);
}
}
cleanup:
......
......@@ -124,12 +124,34 @@ 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")` binary(10) default NULL
`date_format("2004-01-19 10:10:10", "%Y-%m-%d")` char(10) character set utf8 default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from t1;
date_format("2004-01-19 10:10:10", "%Y-%m-%d")
2004-01-19
drop table t1;
set names utf8;
set LC_TIME_NAMES='fr_FR';
create table t1 (s1 char(20) character set latin1);
insert into t1 values (date_format('2004-02-02','%M'));
select hex(s1) from t1;
hex(s1)
66E97672696572
drop table t1;
create table t1 (s1 char(20) character set koi8r);
set LC_TIME_NAMES='ru_RU';
insert into t1 values (date_format('2004-02-02','%M'));
insert into t1 values (date_format('2004-02-02','%b'));
insert into t1 values (date_format('2004-02-02','%W'));
insert into t1 values (date_format('2004-02-02','%a'));
select hex(s1), s1 from t1;
hex(s1) s1
E6C5D7D2C1CCD1 Февраля
E6C5D7 Фев
F0CFCEC5C4C5CCD8CEC9CB Понедельник
F0CEC4 Пнд
drop table t1;
set LC_TIME_NAMES='en_US';
set names koi8r;
create table t1 (s1 char(1) character set utf8);
insert into t1 values (_koi8r'');
......
......@@ -1584,4 +1584,66 @@ CREATE TABLE `t1` (
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
drop table t1;
CREATE TABLE `t1` (
`a b` INT,
`c"d` INT,
`e``f` INT,
PRIMARY KEY (`a b`, `c"d`, `e``f`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
insert into t1 values (0815, 4711, 2006);
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO,ANSI' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS "t1";
CREATE TABLE "t1" (
"a b" int(11) NOT NULL default '0',
"c""d" int(11) NOT NULL default '0',
"e`f" int(11) NOT NULL default '0',
PRIMARY KEY ("a b","c""d","e`f")
);
LOCK TABLES "t1" WRITE;
/*!40000 ALTER TABLE "t1" DISABLE KEYS */;
INSERT INTO "t1" VALUES (815,4711,2006);
/*!40000 ALTER TABLE "t1" ENABLE KEYS */;
UNLOCK TABLES;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS `t1`;
CREATE TABLE `t1` (
`a b` int(11) NOT NULL default '0',
`c"d` int(11) NOT NULL default '0',
`e``f` int(11) NOT NULL default '0',
PRIMARY KEY (`a b`,`c"d`,`e``f`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
LOCK TABLES `t1` WRITE;
/*!40000 ALTER TABLE `t1` DISABLE KEYS */;
INSERT INTO `t1` VALUES (815,4711,2006);
/*!40000 ALTER TABLE `t1` ENABLE KEYS */;
UNLOCK TABLES;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
DROP TABLE `t1`;
End of 4.1 tests
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
create table t1 (s1 char(10));
set lc_time_names= 'de_DE';
insert into t1 values (date_format('2001-01-01','%W'));
select * from t1;
s1
Montag
select * from t1;
s1
Montag
drop table t1;
......@@ -499,6 +499,63 @@ set names latin1;
select @@have_innodb;
@@have_innodb
#
*** Various tests with LC_TIME_NAMES
*** LC_TIME_NAMES: testing case insensitivity
set @@lc_time_names='ru_ru';
select @@lc_time_names;
@@lc_time_names
ru_RU
*** LC_TIME_NAMES: testing with a user variable
set @lc='JA_JP';
set @@lc_time_names=@lc;
select @@lc_time_names;
@@lc_time_names
ja_JP
*** LC_TIME_NAMES: testing with string expressions
set lc_time_names=concat('de','_','DE');
select @@lc_time_names;
@@lc_time_names
de_DE
set lc_time_names=concat('de','+','DE');
ERROR HY000: Unknown locale: 'de+DE'
select @@lc_time_names;
@@lc_time_names
de_DE
LC_TIME_NAMES: testing with numeric expressions
set @@lc_time_names=1+2;
select @@lc_time_names;
@@lc_time_names
sv_SE
set @@lc_time_names=1/0;
ERROR 42000: Incorrect argument type to variable 'lc_time_names'
select @@lc_time_names;
@@lc_time_names
sv_SE
set lc_time_names=en_US;
LC_TIME_NAMES: testing NULL and a negative number:
set lc_time_names=NULL;
ERROR 42000: Variable 'lc_time_names' can't be set to the value of 'NULL'
set lc_time_names=-1;
ERROR HY000: Unknown locale: '-1'
select @@lc_time_names;
@@lc_time_names
en_US
LC_TIME_NAMES: testing locale with the last ID:
set lc_time_names=108;
select @@lc_time_names;
@@lc_time_names
zh_HK
LC_TIME_NAMES: testing a number beyond the valid ID range:
set lc_time_names=109;
ERROR HY000: Unknown locale: '109'
select @@lc_time_names;
@@lc_time_names
zh_HK
LC_TIME_NAMES: testing that 0 is en_US:
set lc_time_names=0;
select @@lc_time_names;
@@lc_time_names
en_US
set @test = @@query_prealloc_size;
set @@query_prealloc_size = @test;
select @@query_prealloc_size = @test;
......
......@@ -93,6 +93,26 @@ show create table t1;
select * from t1;
drop table t1;
#
# Bug#22646 LC_TIME_NAMES: Assignment to non-UTF8 target fails
#
set names utf8;
set LC_TIME_NAMES='fr_FR';
create table t1 (s1 char(20) character set latin1);
insert into t1 values (date_format('2004-02-02','%M'));
select hex(s1) from t1;
drop table t1;
create table t1 (s1 char(20) character set koi8r);
set LC_TIME_NAMES='ru_RU';
insert into t1 values (date_format('2004-02-02','%M'));
insert into t1 values (date_format('2004-02-02','%b'));
insert into t1 values (date_format('2004-02-02','%W'));
insert into t1 values (date_format('2004-02-02','%a'));
select hex(s1), s1 from t1;
drop table t1;
set LC_TIME_NAMES='en_US';
#
# Bug #2366 Wrong utf8 behaviour when data is truncated
#
......
......@@ -702,4 +702,19 @@ create table t1 (a int);
--exec $MYSQL_DUMP --skip-comments --force test t1 --where='xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 2>&1
drop table t1;
#
# BUG#13926: --order-by-primary fails if PKEY contains quote character
#
CREATE TABLE `t1` (
`a b` INT,
`c"d` INT,
`e``f` INT,
PRIMARY KEY (`a b`, `c"d`, `e``f`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
insert into t1 values (0815, 4711, 2006);
--exec $MYSQL_DUMP --skip-comments --compatible=ansi --order-by-primary test t1
--exec $MYSQL_DUMP --skip-comments --order-by-primary test t1
DROP TABLE `t1`;
--echo End of 4.1 tests
# Replication of locale variables
source include/master-slave.inc;
#
# Bug#22645 LC_TIME_NAMES: Statement not replicated
#
connection master;
create table t1 (s1 char(10));
set lc_time_names= 'de_DE';
insert into t1 values (date_format('2001-01-01','%W'));
select * from t1;
sync_slave_with_master;
connection slave;
select * from t1;
connection master;
drop table t1;
sync_slave_with_master;
# End of 4.1 tests
......@@ -396,6 +396,50 @@ set names latin1;
--replace_column 1 #
select @@have_innodb;
#
# Tests for lc_time_names
# Note, when adding new locales, please fix ID accordingly:
# - to test the last ID (currently 108)
# - and the next after the last (currently 109)
#
--echo *** Various tests with LC_TIME_NAMES
--echo *** LC_TIME_NAMES: testing case insensitivity
set @@lc_time_names='ru_ru';
select @@lc_time_names;
--echo *** LC_TIME_NAMES: testing with a user variable
set @lc='JA_JP';
set @@lc_time_names=@lc;
select @@lc_time_names;
--echo *** LC_TIME_NAMES: testing with string expressions
set lc_time_names=concat('de','_','DE');
select @@lc_time_names;
--error 1105
set lc_time_names=concat('de','+','DE');
select @@lc_time_names;
--echo LC_TIME_NAMES: testing with numeric expressions
set @@lc_time_names=1+2;
select @@lc_time_names;
--error 1232
set @@lc_time_names=1/0;
select @@lc_time_names;
set lc_time_names=en_US;
--echo LC_TIME_NAMES: testing NULL and a negative number:
--error 1231
set lc_time_names=NULL;
--error 1105
set lc_time_names=-1;
select @@lc_time_names;
--echo LC_TIME_NAMES: testing locale with the last ID:
set lc_time_names=108;
select @@lc_time_names;
--echo LC_TIME_NAMES: testing a number beyond the valid ID range:
--error 1105
set lc_time_names=109;
select @@lc_time_names;
--echo LC_TIME_NAMES: testing that 0 is en_US:
set lc_time_names=0;
select @@lc_time_names;
#
# Bug #13334: query_prealloc_size default less than minimum
#
......
......@@ -595,16 +595,10 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time,
uint weekday;
ulong length;
const char *ptr, *end;
MY_LOCALE *locale;
THD *thd= current_thd;
char buf[128];
String tmp(buf, sizeof(buf), thd->variables.character_set_results);
uint errors= 0;
MY_LOCALE *locale= thd->variables.lc_time_names;
tmp.length(0);
str->length(0);
str->set_charset(&my_charset_bin);
locale = thd->variables.lc_time_names;
if (l_time->neg)
str->append("-", 1);
......@@ -620,38 +614,34 @@ bool make_date_time(DATE_TIME_FORMAT *format, TIME *l_time,
case 'M':
if (!l_time->month)
return 1;
tmp.copy(locale->month_names->type_names[l_time->month-1],
str->append(locale->month_names->type_names[l_time->month-1],
strlen(locale->month_names->type_names[l_time->month-1]),
system_charset_info, tmp.charset(), &errors);
str->append(tmp.ptr(), tmp.length());
system_charset_info);
break;
case 'b':
if (!l_time->month)
return 1;
tmp.copy(locale->ab_month_names->type_names[l_time->month-1],
str->append(locale->ab_month_names->type_names[l_time->month-1],
strlen(locale->ab_month_names->type_names[l_time->month-1]),
system_charset_info, tmp.charset(), &errors);
str->append(tmp.ptr(), tmp.length());
system_charset_info);
break;
case 'W':
if (type == MYSQL_TIMESTAMP_TIME)
return 1;
weekday= calc_weekday(calc_daynr(l_time->year,l_time->month,
l_time->day),0);
tmp.copy(locale->day_names->type_names[weekday],
str->append(locale->day_names->type_names[weekday],
strlen(locale->day_names->type_names[weekday]),
system_charset_info, tmp.charset(), &errors);
str->append(tmp.ptr(), tmp.length());
system_charset_info);
break;
case 'a':
if (type == MYSQL_TIMESTAMP_TIME)
return 1;
weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
l_time->day),0);
tmp.copy(locale->ab_day_names->type_names[weekday],
str->append(locale->ab_day_names->type_names[weekday],
strlen(locale->ab_day_names->type_names[weekday]),
system_charset_info, tmp.charset(), &errors);
str->append(tmp.ptr(), tmp.length());
system_charset_info);
break;
case 'D':
if (type == MYSQL_TIMESTAMP_TIME)
......@@ -1638,8 +1628,9 @@ longlong Item_func_sec_to_time::val_int()
void Item_func_date_format::fix_length_and_dec()
{
THD* thd= current_thd;
decimals=0;
collation.set(&my_charset_bin);
collation.set(thd->variables.collation_connection);
if (args[1]->type() == STRING_ITEM)
{ // Optimize the normal case
fixed_length=1;
......@@ -1653,17 +1644,14 @@ void Item_func_date_format::fix_length_and_dec()
args[1]->collation.set(
get_charset_by_csname(args[1]->collation.collation->csname,
MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE);
/*
The result is a binary string (no reason to use collation->mbmaxlen
This is becasue make_date_time() only returns binary strings
*/
max_length= format_length(((Item_string*) args[1])->const_string());
max_length= format_length(((Item_string*) args[1])->const_string()) *
collation.collation->mbmaxlen;
}
else
{
fixed_length=0;
/* The result is a binary string (no reason to use collation->mbmaxlen */
max_length=min(args[1]->max_length,MAX_BLOB_WIDTH) * 10;
max_length= min(args[1]->max_length,MAX_BLOB_WIDTH) * 10 *
collation.collation->mbmaxlen;
set_if_smaller(max_length,MAX_BLOB_WIDTH);
}
maybe_null=1; // If wrong date
......@@ -1783,6 +1771,7 @@ String *Item_func_date_format::val_str(String *str)
date_time_format.format.length= format->length();
/* Create the result string */
str->set_charset(collation.collation);
if (!make_date_time(&date_time_format, &l_time,
is_time_format ? MYSQL_TIMESTAMP_TIME :
MYSQL_TIMESTAMP_DATE,
......
......@@ -1350,6 +1350,21 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u",
if (e.write(file))
goto err;
}
/*
Use the same ONE_SHOT trick for making replication of lc_time_names.
*/
if (thd->variables.lc_time_names->number) // Not en_US
{
char buf[32];
uint length= my_snprintf(buf, sizeof(buf),
"SET ONE_SHOT LC_TIME_NAMES=%u",
(uint) thd->variables.lc_time_names->number);
Query_log_event e(thd, buf, length, 0, FALSE);
e.set_log_pos(this);
e.error_code= 0; // This statement cannot fail (see [1]).
if (e.write(file))
goto err;
}
#endif
if (thd->last_insert_id_used)
......
......@@ -71,6 +71,7 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
typedef struct my_locale_st
{
uint number;
const char *name;
const char *description;
const bool is_ascii;
......@@ -84,6 +85,7 @@ extern MY_LOCALE my_locale_en_US;
extern MY_LOCALE *my_locales[];
MY_LOCALE *my_locale_by_name(const char *name);
MY_LOCALE *my_locale_by_number(uint number);
/***************************************************************************
Configuration parameters
......
......@@ -2570,19 +2570,38 @@ void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
bool sys_var_thd_lc_time_names::check(THD *thd, set_var *var)
{
char *locale_str =var->value->str_value.c_ptr();
MY_LOCALE *locale_match= my_locale_by_name(locale_str);
MY_LOCALE *locale_match;
if(locale_match == NULL)
if (var->value->result_type() == INT_RESULT)
{
my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), locale_str);
if (!(locale_match= my_locale_by_number((uint) var->value->val_int())))
{
char buf[20];
int10_to_str((int) var->value->val_int(), buf, -10);
my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
return 1;
}
else
}
else // STRING_RESULT
{
char buff[6];
String str(buff, sizeof(buff), &my_charset_latin1), *res;
if (!(res=var->value->val_str(&str)))
{
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
return 1;
}
const char *locale_str= res->c_ptr();
if (!(locale_match= my_locale_by_name(locale_str)))
{
my_printf_error(ER_UNKNOWN_ERROR,
"Unknown locale: '%s'", MYF(0), locale_str);
return 1;
}
}
var->save_result.locale_value= locale_match;
return 0;
}
}
......
......@@ -764,12 +764,16 @@ class sys_var_thd_lc_time_names :public sys_var_thd
public:
sys_var_thd_lc_time_names(const char *name_arg):
sys_var_thd(name_arg)
{}
{
#if MYSQL_VERSION_ID < 50000
no_support_one_shot= 0;
#endif
}
bool check(THD *thd, set_var *var);
SHOW_TYPE type() { return SHOW_CHAR; }
bool check_update_type(Item_result type)
{
return type != STRING_RESULT; /* Only accept strings */
return ((type != STRING_RESULT) && (type != INT_RESULT));
}
bool check_default(enum_var_type type) { return 0; }
bool update(THD *thd, set_var *var);
......
This diff is collapsed.
......@@ -1958,6 +1958,7 @@ static void reset_one_shot_variables(THD *thd)
thd->update_charset();
thd->variables.time_zone=
global_system_variables.time_zone;
thd->variables.lc_time_names= &my_locale_en_US;
thd->one_shot_set= 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment