Commit d2a986b0 authored by unknown's avatar unknown

Merge gleb.loc:/home/uchum/work/bk/5.0-opt

into  gleb.loc:/home/uchum/work/bk/5.1-opt


mysql-test/r/select.result:
  Auto merged
mysql-test/r/type_decimal.result:
  Auto merged
mysql-test/t/select.test:
  Auto merged
mysql-test/t/type_decimal.test:
  Auto merged
sql/item.cc:
  Auto merged
sql/sql_class.cc:
  Auto merged
sql/sql_class.h:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
sql/share/errmsg.txt:
  Merge with 5.0-opt
parents 611a8972 3f3e5bac
DROP TABLE IF EXISTS t1, t2;
#
# Bug#31663 FIELDS TERMINATED BY special character
#
CREATE TABLE t1 (i1 int, i2 int, c1 VARCHAR(256), c2 VARCHAR(256));
INSERT INTO t1 VALUES (101, 202, '-r-', '=raker=');
# FIELDS TERMINATED BY 'raker', warning:
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' FIELDS TERMINATED BY 'raker' FROM t1;
Warnings:
Warning 1475 First character of the FIELDS TERMINATED string is ambiguous; please use non-optional and non-empty FIELDS ENCLOSED BY
SELECT LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt');
LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt')
101raker202raker-r-raker=raker=
CREATE TABLE t2 SELECT * FROM t1;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 FIELDS TERMINATED BY 'raker';
Warnings:
Warning 1262 Row 1 was truncated; it contained more data than there were input columns
SELECT * FROM t2;
i1 i2 c1 c2
101 202 -r- =raker=
101 202 -r- =
DROP TABLE t2;
# Only numeric fields, FIELDS TERMINATED BY 'r', no warnings:
SELECT i1, i2 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' FIELDS TERMINATED BY 'r' FROM t1;
SELECT LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt');
LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt')
101r202
CREATE TABLE t2 SELECT i1, i2 FROM t1;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 FIELDS TERMINATED BY 'r';
SELECT i1, i2 FROM t2;
i1 i2
101 202
101 202
DROP TABLE t2;
# FIELDS TERMINATED BY '0', warning:
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' FIELDS TERMINATED BY '0' FROM t1;
Warnings:
Warning 1475 First character of the FIELDS TERMINATED string is ambiguous; please use non-optional and non-empty FIELDS ENCLOSED BY
SELECT LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt');
LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt')
10102020-r-0=raker=
CREATE TABLE t2 SELECT * FROM t1;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 FIELDS TERMINATED BY '0';
Warnings:
Warning 1262 Row 1 was truncated; it contained more data than there were input columns
SELECT * FROM t2;
i1 i2 c1 c2
101 202 -r- =raker=
1 1 2 2
DROP TABLE t2;
# FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '0', warning:
SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '0' FROM t1;
Warnings:
Warning 1475 First character of the FIELDS TERMINATED string is ambiguous; please use non-optional and non-empty FIELDS ENCLOSED BY
SELECT LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt');
LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt')
10102020"-r-"0"=raker="
CREATE TABLE t2 SELECT * FROM t1;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '0';
Warnings:
Warning 1262 Row 1 was truncated; it contained more data than there were input columns
SELECT * FROM t2;
i1 i2 c1 c2
101 202 -r- =raker=
1 1 2 2
DROP TABLE t2;
# Only string fields, FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '0', no warnings:
SELECT c1, c2 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '0' FROM t1;
SELECT LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt');
LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug31663.txt')
"-r-"0"=raker="
CREATE TABLE t2 SELECT c1, c2 FROM t1;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '0';
SELECT c1, c2 FROM t2;
c1 c2
-r- =raker=
-r- =raker=
DROP TABLE t2;
DROP TABLE t1;
# End of 5.0 tests.
......@@ -4062,25 +4062,23 @@ x
1
Warnings:
Warning 1466 Leading spaces are removed from name ' x'
CREATE VIEW v1 AS SELECT 1 AS ``;
ERROR 42000: Incorrect column name ''
CREATE VIEW v1 AS SELECT 1 AS ` `;
Warnings:
Warning 1474 Name ' ' has become ''
SELECT `` FROM v1;
1
CREATE VIEW v2 AS SELECT 1 AS ` `;
Warnings:
Warning 1474 Name ' ' has become ''
SELECT `` FROM v2;
1
CREATE VIEW v3 AS SELECT 1 AS ` x`;
ERROR 42000: Incorrect column name ' '
CREATE VIEW v1 AS SELECT 1 AS ` `;
ERROR 42000: Incorrect column name ' '
CREATE VIEW v1 AS SELECT (SELECT 1 AS ` `);
ERROR 42000: Incorrect column name ' '
CREATE VIEW v1 AS SELECT 1 AS ` x`;
Warnings:
Warning 1466 Leading spaces are removed from name ' x'
SELECT `x` FROM v3;
SELECT `x` FROM v1;
x
1
DROP VIEW v1, v2, v3;
ALTER VIEW v1 AS SELECT 1 AS ` `;
ERROR 42000: Incorrect column name ' '
DROP VIEW v1;
End of 5.0 tests
create table t1(a INT, KEY (a));
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
......
......@@ -812,4 +812,14 @@ select group_concat(f1),group_concat(f2) from t1;
group_concat(f1) group_concat(f2)
-0.123456 0.123456
drop table t1;
create table t1 (
ua_id decimal(22,0) not null,
ua_invited_by_id decimal(22,0) default NULL,
primary key(ua_id)
);
insert into t1 values (123, NULL), (456, NULL);
this must not produce error 1048:
select * from t1 where ua_invited_by_id not in (select ua_id from t1);
ua_id ua_invited_by_id
drop table t1;
End of 5.0 tests
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
--echo #
--echo # Bug#31663 FIELDS TERMINATED BY special character
--echo #
CREATE TABLE t1 (i1 int, i2 int, c1 VARCHAR(256), c2 VARCHAR(256));
INSERT INTO t1 VALUES (101, 202, '-r-', '=raker=');
--let $fields=*
--let $clauses=FIELDS TERMINATED BY 'raker'
--echo # $clauses, warning:
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT $fields INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' $clauses FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT LOAD_FILE('$MYSQLTEST_VARDIR/tmp/bug31663.txt')
--eval CREATE TABLE t2 SELECT $fields FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 $clauses
--eval SELECT $fields FROM t2
--remove_file $MYSQLTEST_VARDIR/tmp/bug31663.txt
DROP TABLE t2;
--let $fields=i1, i2
--let $clauses=FIELDS TERMINATED BY 'r'
--echo # Only numeric fields, $clauses, no warnings:
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT $fields INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' $clauses FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT LOAD_FILE('$MYSQLTEST_VARDIR/tmp/bug31663.txt')
--eval CREATE TABLE t2 SELECT $fields FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 $clauses
--eval SELECT $fields FROM t2
--remove_file $MYSQLTEST_VARDIR/tmp/bug31663.txt
DROP TABLE t2;
--let $fields=*
--let $clauses=FIELDS TERMINATED BY '0'
--echo # $clauses, warning:
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT $fields INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' $clauses FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT LOAD_FILE('$MYSQLTEST_VARDIR/tmp/bug31663.txt')
--eval CREATE TABLE t2 SELECT $fields FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 $clauses
--eval SELECT $fields FROM t2
--remove_file $MYSQLTEST_VARDIR/tmp/bug31663.txt
DROP TABLE t2;
--let $fields=*
--let $clauses=FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '0'
--echo # $clauses, warning:
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT $fields INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' $clauses FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT LOAD_FILE('$MYSQLTEST_VARDIR/tmp/bug31663.txt')
--eval CREATE TABLE t2 SELECT $fields FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 $clauses
--eval SELECT $fields FROM t2
--remove_file $MYSQLTEST_VARDIR/tmp/bug31663.txt
DROP TABLE t2;
--let $fields=c1, c2
--let $clauses=FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '0'
--echo # Only string fields, $clauses, no warnings:
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT $fields INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' $clauses FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval SELECT LOAD_FILE('$MYSQLTEST_VARDIR/tmp/bug31663.txt')
--eval CREATE TABLE t2 SELECT $fields FROM t1
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug31663.txt' INTO TABLE t2 $clauses
--eval SELECT $fields FROM t2
--remove_file $MYSQLTEST_VARDIR/tmp/bug31663.txt
DROP TABLE t2;
DROP TABLE t1;
--echo # End of 5.0 tests.
......@@ -3455,23 +3455,30 @@ DROP TABLE t1;
#
--disable_ps_protocol
SELECT 1 AS ` `;
SELECT 1 AS ` `;
SELECT 1 AS ` x`;
--enable_ps_protocol
--error 1166
CREATE VIEW v1 AS SELECT 1 AS ``;
--error 1166
CREATE VIEW v1 AS SELECT 1 AS ` `;
SELECT `` FROM v1;
CREATE VIEW v2 AS SELECT 1 AS ` `;
SELECT `` FROM v2;
--error 1166
CREATE VIEW v1 AS SELECT 1 AS ` `;
CREATE VIEW v3 AS SELECT 1 AS ` x`;
SELECT `x` FROM v3;
--error 1166
CREATE VIEW v1 AS SELECT (SELECT 1 AS ` `);
DROP VIEW v1, v2, v3;
CREATE VIEW v1 AS SELECT 1 AS ` x`;
SELECT `x` FROM v1;
--enable_ps_protocol
--error 1166
ALTER VIEW v1 AS SELECT 1 AS ` `;
DROP VIEW v1;
--echo End of 5.0 tests
......
......@@ -425,5 +425,20 @@ insert into t1 values (-0.123456,0.123456);
select group_concat(f1),group_concat(f2) from t1;
drop table t1;
#
# BUG#31450 "Query causes error 1048"
#
create table t1 (
ua_id decimal(22,0) not null,
ua_invited_by_id decimal(22,0) default NULL,
primary key(ua_id)
);
insert into t1 values (123, NULL), (456, NULL);
--echo this must not produce error 1048:
select * from t1 where ua_invited_by_id not in (select ua_id from t1);
drop table t1;
--echo End of 5.0 tests
......@@ -4649,7 +4649,7 @@ int Item::save_in_field(Field *field, bool no_conversions)
my_decimal decimal_value;
my_decimal *value= val_decimal(&decimal_value);
if (null_value)
return set_field_to_null(field);
return set_field_to_null_with_conversions(field, no_conversions);
field->set_notnull();
error=field->store_decimal(value);
}
......
......@@ -5658,6 +5658,8 @@ ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT
eng "Too high level of nesting for select"
ER_NAME_BECOMES_EMPTY
eng "Name '%-.64s' has become ''"
ER_AMBIGUOUS_FIELD_TERM
eng "First character of the FIELDS TERMINATED string is ambiguous; please use non-optional and non-empty FIELDS ENCLOSED BY"
ER_FOREIGN_SERVER_EXISTS
eng "The foreign server, %s, you are trying to create already exists."
ER_FOREIGN_SERVER_DOESNT_EXIST
......
......@@ -1540,6 +1540,7 @@ int
select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
{
bool blob_flag=0;
bool string_results= FALSE, non_string_results= FALSE;
unit= u;
if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN)
strmake(path,exchange->file_name,FN_REFLEN-1);
......@@ -1557,13 +1558,18 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
blob_flag=1;
break;
}
if (item->result_type() == STRING_RESULT)
string_results= TRUE;
else
non_string_results= TRUE;
}
}
field_term_length=exchange->field_term->length();
field_term_char= field_term_length ? (*exchange->field_term)[0] : INT_MAX;
if (!exchange->line_term->length())
exchange->line_term=exchange->field_term; // Use this if it exists
field_sep_char= (exchange->enclosed->length() ? (*exchange->enclosed)[0] :
field_term_length ? (*exchange->field_term)[0] : INT_MAX);
field_term_char);
escape_char= (exchange->escaped->length() ? (*exchange->escaped)[0] : -1);
is_ambiguous_field_sep= test(strchr(ESCAPE_CHARS, field_sep_char));
is_unsafe_field_sep= test(strchr(NUMERIC_CHARS, field_sep_char));
......@@ -1575,12 +1581,25 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
exchange->opt_enclosed=1; // A little quicker loop
fixed_row_size= (!field_term_length && !exchange->enclosed->length() &&
!blob_flag);
if ((is_ambiguous_field_sep && exchange->enclosed->is_empty() &&
(string_results || is_unsafe_field_sep)) ||
(exchange->opt_enclosed && non_string_results &&
field_term_length && strchr(NUMERIC_CHARS, field_term_char)))
{
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_AMBIGUOUS_FIELD_TERM, ER(ER_AMBIGUOUS_FIELD_TERM));
is_ambiguous_field_term= TRUE;
}
else
is_ambiguous_field_term= FALSE;
return 0;
}
#define NEED_ESCAPING(x) ((int) (uchar) (x) == escape_char || \
(int) (uchar) (x) == field_sep_char || \
(enclosed ? (int) (uchar) (x) == field_sep_char \
: (int) (uchar) (x) == field_term_char) || \
(int) (uchar) (x) == line_sep_char || \
!(x))
......@@ -1609,8 +1628,10 @@ bool select_export::send_data(List<Item> &items)
while ((item=li++))
{
Item_result result_type=item->result_type();
bool enclosed = (exchange->enclosed->length() &&
(!exchange->opt_enclosed || result_type == STRING_RESULT));
res=item->str_result(&tmp);
if (res && (!exchange->opt_enclosed || result_type == STRING_RESULT))
if (res && enclosed)
{
if (my_b_write(&cache,(uchar*) exchange->enclosed->ptr(),
exchange->enclosed->length()))
......@@ -1701,11 +1722,16 @@ bool select_export::send_data(List<Item> &items)
DBUG_ASSERT before the loop makes that sure.
*/
if (NEED_ESCAPING(*pos) ||
(check_second_byte &&
my_mbcharlen(character_set_client, (uchar) *pos) == 2 &&
pos + 1 < end &&
NEED_ESCAPING(pos[1])))
if ((NEED_ESCAPING(*pos) ||
(check_second_byte &&
my_mbcharlen(character_set_client, (uchar) *pos) == 2 &&
pos + 1 < end &&
NEED_ESCAPING(pos[1]))) &&
/*
Don't escape field_term_char by doubling - doubling is only
valid for ENCLOSED BY characters:
*/
(enclosed || !is_ambiguous_field_term || *pos != field_term_char))
{
char tmp_buff[2];
tmp_buff[0]= ((int) *pos == field_sep_char &&
......@@ -1744,7 +1770,7 @@ bool select_export::send_data(List<Item> &items)
goto err;
}
}
if (res && (!exchange->opt_enclosed || result_type == STRING_RESULT))
if (res && enclosed)
{
if (my_b_write(&cache, (uchar*) exchange->enclosed->ptr(),
exchange->enclosed->length()))
......
......@@ -2070,12 +2070,19 @@ class select_to_file :public select_result_interceptor {
class select_export :public select_to_file {
uint field_term_length;
int field_sep_char,escape_char,line_sep_char;
int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
/*
The is_ambiguous_field_sep field is true if a value of the field_sep_char
field is one of the 'n', 't', 'r' etc characters
(see the READ_INFO::unescape method and the ESCAPE_CHARS constant value).
*/
bool is_ambiguous_field_sep;
/*
The is_ambiguous_field_term is true if field_sep_char contains the first
char of the FIELDS TERMINATED BY (ENCLOSED BY is empty), and items can
contain this character.
*/
bool is_ambiguous_field_term;
/*
The is_unsafe_field_sep field is true if a value of the field_sep_char
field is one of the '0'..'9', '+', '-', '.' and 'e' characters
......
......@@ -6323,6 +6323,12 @@ select_item:
MYSQL_YYABORT;
if ($4.str)
{
if (Lex->sql_command == SQLCOM_CREATE_VIEW &&
check_column_name($4.str))
{
my_error(ER_WRONG_COLUMN_NAME, MYF(0), $4.str);
MYSQL_YYABORT;
}
$2->is_autogenerated_name= FALSE;
$2->set_name($4.str, $4.length, system_charset_info);
}
......
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