summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/case.result2
-rw-r--r--mysql-test/r/func_if.result2
-rw-r--r--mysql-test/r/func_in.result2
-rw-r--r--mysql-test/r/func_str.result2
-rw-r--r--mysql-test/r/func_test.result2
-rw-r--r--mysql-test/r/view.result10
-rw-r--r--mysql-test/t/view.test10
-rw-r--r--sql/item_strfunc.cc12
-rw-r--r--sql/item_strfunc.h2
-rw-r--r--sql/sp_head.cc8
-rw-r--r--sql/sql_base.cc1
-rw-r--r--sql/sql_delete.cc4
-rw-r--r--sql/sql_help.cc5
-rw-r--r--sql/sql_load.cc7
-rw-r--r--sql/sql_parse.cc3
-rw-r--r--sql/sql_prepare.cc19
-rw-r--r--sql/sql_show.cc26
-rw-r--r--sql/sql_update.cc4
18 files changed, 79 insertions, 42 deletions
diff --git a/mysql-test/r/case.result b/mysql-test/r/case.result
index dba21877644..75d0c9a7e3b 100644
--- a/mysql-test/r/case.result
+++ b/mysql-test/r/case.result
@@ -141,7 +141,7 @@ COALESCE('a' COLLATE latin1_bin,'b');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 select coalesce(1) AS `COALESCE(1)`,coalesce(1.0) AS `COALESCE(1.0)`,coalesce(_latin1'a') AS `COALESCE('a')`,coalesce(1,1.0) AS `COALESCE(1,1.0)`,coalesce(1,_latin1'1') AS `COALESCE(1,'1')`,coalesce(1.1,_latin1'1') AS `COALESCE(1.1,'1')`,coalesce((_latin1'a' collate _latin1'latin1_bin'),_latin1'b') AS `COALESCE('a' COLLATE latin1_bin,'b')`
+Note 1003 select coalesce(1) AS `COALESCE(1)`,coalesce(1.0) AS `COALESCE(1.0)`,coalesce(_latin1'a') AS `COALESCE('a')`,coalesce(1,1.0) AS `COALESCE(1,1.0)`,coalesce(1,_latin1'1') AS `COALESCE(1,'1')`,coalesce(1.1,_latin1'1') AS `COALESCE(1.1,'1')`,coalesce((_latin1'a' collate latin1_bin),_latin1'b') AS `COALESCE('a' COLLATE latin1_bin,'b')`
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
diff --git a/mysql-test/r/func_if.result b/mysql-test/r/func_if.result
index 36bd9a36d1c..f0445199744 100644
--- a/mysql-test/r/func_if.result
+++ b/mysql-test/r/func_if.result
@@ -43,7 +43,7 @@ explain extended select if(u=1,st,binary st) s from t1 where st like "%a%" order
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where; Using filesort
Warnings:
-Note 1003 select if((`test`.`t1`.`u` = 1),`test`.`t1`.`st`,(`test`.`t1`.`st` collate _latin1'BINARY')) AS `s` from `test`.`t1` where (`test`.`t1`.`st` like _latin1'%a%') order by if((`test`.`t1`.`u` = 1),`test`.`t1`.`st`,(`test`.`t1`.`st` collate _latin1'BINARY'))
+Note 1003 select if((`test`.`t1`.`u` = 1),`test`.`t1`.`st`,(`test`.`t1`.`st` collate BINARY)) AS `s` from `test`.`t1` where (`test`.`t1`.`st` like _latin1'%a%') order by if((`test`.`t1`.`u` = 1),`test`.`t1`.`st`,(`test`.`t1`.`st` collate BINARY))
select nullif(u=0, 'test') from t1;
nullif(u=0, 'test')
NULL
diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result
index 025ea02e454..f264103390d 100644
--- a/mysql-test/r/func_in.result
+++ b/mysql-test/r/func_in.result
@@ -146,7 +146,7 @@ explain extended select * from t1 where 'a' in (a,b,c collate latin1_bin);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (_latin1'a' in (`test`.`t1`.`a`,`test`.`t1`.`b`,(`test`.`t1`.`c` collate _latin1'latin1_bin')))
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (_latin1'a' in (`test`.`t1`.`a`,`test`.`t1`.`b`,(`test`.`t1`.`c` collate latin1_bin)))
drop table t1;
select '1.0' in (1,2);
'1.0' in (1,2)
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index e07ee4f0add..6495b81c195 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -638,7 +638,7 @@ explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'moo
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 select md5(_latin1'hello') AS `md5('hello')`,sha(_latin1'abc') AS `sha('abc')`,sha(_latin1'abc') AS `sha1('abc')`,soundex(_latin1'') AS `soundex('')`,(soundex(_latin1'mood') = soundex(_latin1'mud')) AS `'mood' sounds like 'mud'`,aes_decrypt(aes_encrypt(_latin1'abc',_latin1'1'),_latin1'1') AS `aes_decrypt(aes_encrypt('abc','1'),'1')`,concat(_latin1'*',repeat(_latin1' ',5),_latin1'*') AS `concat('*',space(5),'*')`,reverse(_latin1'abc') AS `reverse('abc')`,rpad(_latin1'a',4,_latin1'1') AS `rpad('a',4,'1')`,lpad(_latin1'a',4,_latin1'1') AS `lpad('a',4,'1')`,concat_ws(_latin1',',_latin1'',NULL,_latin1'a') AS `concat_ws(',','',NULL,'a')`,make_set(255,_latin2'a',_latin2'b',_latin2'c') AS `make_set(255,_latin2'a',_latin2'b',_latin2'c')`,elt(2,1) AS `elt(2,1)`,locate(_latin1'a',_latin1'b',2) AS `locate("a","b",2)`,format(130,10) AS `format(130,10)`,char(0) AS `char(0)`,conv(130,16,10) AS `conv(130,16,10)`,hex(130) AS `hex(130)`,(_latin1'HE' collate _latin1'BINARY') AS `binary 'HE'`,export_set(255,_latin2'y',_latin2'n',_latin2' ') AS `export_set(255,_latin2'y',_latin2'n',_latin2' ')`,field((_latin1'b' collate _latin1'latin1_bin'),_latin1'A',_latin1'B') AS `FIELD('b' COLLATE latin1_bin,'A','B')`,find_in_set(_latin1'B',_latin1'a,b,c,d') AS `FIND_IN_SET(_latin1'B',_latin1'a,b,c,d')`,collation(conv(130,16,10)) AS `collation(conv(130,16,10))`,coercibility(conv(130,16,10)) AS `coercibility(conv(130,16,10))`,length(_latin1'\n \r\0\\_\\%\\') AS `length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,concat(_latin1'monty',_latin1' was here ',_latin1'again') AS `concat('monty',' was here ','again')`,length(_latin1'hello') AS `length('hello')`,char(ascii(_latin1'h')) AS `char(ascii('h'))`,ord(_latin1'h') AS `ord('h')`,quote((1 / 0)) AS `quote(1/0)`,crc32(_latin1'123') AS `crc32("123")`,replace(_latin1'aaaa',_latin1'a',_latin1'b') AS `replace('aaaa','a','b')`,insert(_latin1'txs',2,1,_latin1'hi') AS `insert('txs',2,1,'hi')`,left(_latin2'a',1) AS `left(_latin2'a',1)`,right(_latin2'a',1) AS `right(_latin2'a',1)`,lcase(_latin2'a') AS `lcase(_latin2'a')`,ucase(_latin2'a') AS `ucase(_latin2'a')`,substr(_latin1'abcdefg',3,2) AS `SUBSTR('abcdefg',3,2)`,substr_index(_latin1'1abcd;2abcd;3abcd;4abcd',_latin1';',2) AS `substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2)`,trim(_latin2' a ') AS `trim(_latin2' a ')`,ltrim(_latin2' a ') AS `ltrim(_latin2' a ')`,rtrim(_latin2' a ') AS `rtrim(_latin2' a ')`,decode(encode(repeat(_latin1'a',100000))) AS `decode(encode(repeat("a",100000),"monty"),"monty")`
+Note 1003 select md5(_latin1'hello') AS `md5('hello')`,sha(_latin1'abc') AS `sha('abc')`,sha(_latin1'abc') AS `sha1('abc')`,soundex(_latin1'') AS `soundex('')`,(soundex(_latin1'mood') = soundex(_latin1'mud')) AS `'mood' sounds like 'mud'`,aes_decrypt(aes_encrypt(_latin1'abc',_latin1'1'),_latin1'1') AS `aes_decrypt(aes_encrypt('abc','1'),'1')`,concat(_latin1'*',repeat(_latin1' ',5),_latin1'*') AS `concat('*',space(5),'*')`,reverse(_latin1'abc') AS `reverse('abc')`,rpad(_latin1'a',4,_latin1'1') AS `rpad('a',4,'1')`,lpad(_latin1'a',4,_latin1'1') AS `lpad('a',4,'1')`,concat_ws(_latin1',',_latin1'',NULL,_latin1'a') AS `concat_ws(',','',NULL,'a')`,make_set(255,_latin2'a',_latin2'b',_latin2'c') AS `make_set(255,_latin2'a',_latin2'b',_latin2'c')`,elt(2,1) AS `elt(2,1)`,locate(_latin1'a',_latin1'b',2) AS `locate("a","b",2)`,format(130,10) AS `format(130,10)`,char(0) AS `char(0)`,conv(130,16,10) AS `conv(130,16,10)`,hex(130) AS `hex(130)`,(_latin1'HE' collate BINARY) AS `binary 'HE'`,export_set(255,_latin2'y',_latin2'n',_latin2' ') AS `export_set(255,_latin2'y',_latin2'n',_latin2' ')`,field((_latin1'b' collate latin1_bin),_latin1'A',_latin1'B') AS `FIELD('b' COLLATE latin1_bin,'A','B')`,find_in_set(_latin1'B',_latin1'a,b,c,d') AS `FIND_IN_SET(_latin1'B',_latin1'a,b,c,d')`,collation(conv(130,16,10)) AS `collation(conv(130,16,10))`,coercibility(conv(130,16,10)) AS `coercibility(conv(130,16,10))`,length(_latin1'\n \r\0\\_\\%\\') AS `length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,concat(_latin1'monty',_latin1' was here ',_latin1'again') AS `concat('monty',' was here ','again')`,length(_latin1'hello') AS `length('hello')`,char(ascii(_latin1'h')) AS `char(ascii('h'))`,ord(_latin1'h') AS `ord('h')`,quote((1 / 0)) AS `quote(1/0)`,crc32(_latin1'123') AS `crc32("123")`,replace(_latin1'aaaa',_latin1'a',_latin1'b') AS `replace('aaaa','a','b')`,insert(_latin1'txs',2,1,_latin1'hi') AS `insert('txs',2,1,'hi')`,left(_latin2'a',1) AS `left(_latin2'a',1)`,right(_latin2'a',1) AS `right(_latin2'a',1)`,lcase(_latin2'a') AS `lcase(_latin2'a')`,ucase(_latin2'a') AS `ucase(_latin2'a')`,substr(_latin1'abcdefg',3,2) AS `SUBSTR('abcdefg',3,2)`,substr_index(_latin1'1abcd;2abcd;3abcd;4abcd',_latin1';',2) AS `substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2)`,trim(_latin2' a ') AS `trim(_latin2' a ')`,ltrim(_latin2' a ') AS `ltrim(_latin2' a ')`,rtrim(_latin2' a ') AS `rtrim(_latin2' a ')`,decode(encode(repeat(_latin1'a',100000))) AS `decode(encode(repeat("a",100000),"monty"),"monty")`
SELECT lpad(12345, 5, "#");
lpad(12345, 5, "#")
12345
diff --git a/mysql-test/r/func_test.result b/mysql-test/r/func_test.result
index a969bf390bc..6f8bc702a80 100644
--- a/mysql-test/r/func_test.result
+++ b/mysql-test/r/func_test.result
@@ -108,7 +108,7 @@ explain extended select _koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 select (_koi8r'a' = (_koi8r'A' collate _latin1'koi8r_general_ci')) AS `_koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci`
+Note 1003 select (_koi8r'a' = (_koi8r'A' collate koi8r_general_ci)) AS `_koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci`
select _koi8r'a' = _koi8r'A' COLLATE koi8r_bin;
_koi8r'a' = _koi8r'A' COLLATE koi8r_bin
0
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 193adac7533..14df4f1846d 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -1183,3 +1183,13 @@ x ()
5
drop view v1;
drop function x;
+create table t2 (col1 char collate latin1_german2_ci);
+create view v2 as select col1 collate latin1_german1_ci from t2;
+show create view v2;
+Table Create Table
+v2 CREATE VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2`
+show create view v2;
+Table Create Table
+v2 CREATE VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2`
+drop view v2;
+drop table t2;
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index cc659a59f6d..d4209cc3cb8 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -1125,3 +1125,13 @@ create view v1 as select x ();
select * from v1;
drop view v1;
drop function x;
+
+#
+# VIEW with collation
+#
+create table t2 (col1 char collate latin1_german2_ci);
+create view v2 as select col1 collate latin1_german1_ci from t2;
+show create view v2;
+show create view v2;
+drop view v2;
+drop table t2;
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index d3493e1fad1..5f2c37dd8a7 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2274,6 +2274,18 @@ bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
return 1;
}
+
+void Item_func_set_collation::print(String *str)
+{
+ str->append('(');
+ args[0]->print(str);
+ str->append(" collate ", 9);
+ DBUG_ASSERT(args[1]->basic_const_item() &&
+ args[1]->type() == Item::STRING_ITEM);
+ args[1]->str_value.print(str);
+ str->append(')');
+}
+
String *Item_func_charset::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 08123370bc6..df8861b2ee0 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -635,7 +635,7 @@ public:
void fix_length_and_dec();
bool eq(const Item *item, bool binary_cmp) const;
const char *func_name() const { return "collate"; }
- void print(String *str) { print_op(str); }
+ void print(String *str);
};
class Item_func_charset :public Item_str_func
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index fd95767b7cd..c7cd49d26f5 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -1192,7 +1192,7 @@ sp_instr_set::execute(THD *thd, uint *nextp)
if (tables &&
((res= check_table_access(thd, SELECT_ACL, tables, 0)) ||
(res= open_and_lock_tables(thd, tables))))
- DBUG_RETURN(-1);
+ DBUG_RETURN(res);
it= sp_eval_func_item(thd, m_value, m_type);
if (! it)
@@ -1293,7 +1293,7 @@ sp_instr_jump_if::execute(THD *thd, uint *nextp)
if (tables &&
((res= check_table_access(thd, SELECT_ACL, tables, 0)) ||
(res= open_and_lock_tables(thd, tables))))
- DBUG_RETURN(-1);
+ DBUG_RETURN(res);
it= sp_eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
if (!it)
@@ -1350,7 +1350,7 @@ sp_instr_jump_if_not::execute(THD *thd, uint *nextp)
if (tables &&
((res= check_table_access(thd, SELECT_ACL, tables, 0)) ||
(res= open_and_lock_tables(thd, tables))))
- DBUG_RETURN(-1);
+ DBUG_RETURN(res);
it= sp_eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
if (! it)
@@ -1406,7 +1406,7 @@ sp_instr_freturn::execute(THD *thd, uint *nextp)
if (tables &&
((res= check_table_access(thd, SELECT_ACL, tables, 0)) ||
(res= open_and_lock_tables(thd, tables))))
- DBUG_RETURN(-1);
+ DBUG_RETURN(res);
it= sp_eval_func_item(thd, m_value, m_type);
if (! it)
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index d1fd5fd02cc..5ae385ca313 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1751,6 +1751,7 @@ int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
RETURN
0 - ok
-1 - error
+ 1 - error reported to user
NOTE
The lock will automaticly be freed by close_thread_tables()
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 910b673dc32..00ce016a550 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -39,8 +39,8 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
ha_rows deleted;
DBUG_ENTER("mysql_delete");
- if ((open_and_lock_tables(thd, table_list)))
- DBUG_RETURN(-1);
+ if ((error= open_and_lock_tables(thd, table_list)))
+ DBUG_RETURN(error);
table= table_list->table;
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
thd->proc_info="init";
diff --git a/sql/sql_help.cc b/sql/sql_help.cc
index 85d5271d4c3..8fc0671c808 100644
--- a/sql/sql_help.cc
+++ b/sql/sql_help.cc
@@ -640,11 +640,8 @@ int mysqld_help(THD *thd, const char *mask)
uint mlen= strlen(mask);
MEM_ROOT *mem_root= &thd->mem_root;
- if (open_and_lock_tables(thd, tables))
- {
- res= -1;
+ if (res= open_and_lock_tables(thd, tables))
goto end;
- }
/*
Init tables and fields to be usable from items
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index fa3adf236fe..b629493a692 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -99,8 +99,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
loaded is located
*/
char *tdb= thd->db ? thd->db : db; // Result is never null
- bool transactional_table, log_delayed;
ulong skip_lines= ex->skip_lines;
+ int res;
+ bool transactional_table, log_delayed;
DBUG_ENTER("mysql_load");
#ifdef EMBEDDED_LIBRARY
@@ -114,8 +115,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
DBUG_RETURN(-1);
}
table_list->lock_type= lock_type;
- if (open_and_lock_tables(thd, table_list))
- DBUG_RETURN(-1);
+ if ((res= open_and_lock_tables(thd, table_list)))
+ DBUG_RETURN(res);
/* TODO: add key check when we will support VIEWs in LOAD */
if (!table_list->updatable)
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 58385c67493..3abb2b957bc 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2136,7 +2136,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_DO:
if (all_tables &&
((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) ||
- (res= open_and_lock_tables(thd, all_tables))))
+ (res= open_and_lock_tables(thd, all_tables))))
break;
res= mysql_do(thd, *lex->insert_list);
@@ -2400,7 +2400,6 @@ mysql_execute_command(THD *thd)
if (!(res= open_and_lock_tables(thd, select_tables)))
{
- res= -1; // If error
if ((result= new select_create(create_table,
&lex->create_info,
lex->create_list,
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 452804240b6..a65a8c79daa 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -897,10 +897,10 @@ static int mysql_test_insert(Prepared_statement *stmt,
tables & preparation procedure
*/
thd->allocate_temporary_memory_pool_for_ps_preparing();
- if (open_and_lock_tables(thd, table_list))
+ if ((res= open_and_lock_tables(thd, table_list)))
{
thd->free_temporary_memory_pool_for_ps_preparing();
- DBUG_RETURN(-1);
+ DBUG_RETURN(res);
}
if ((values= its++))
@@ -969,9 +969,7 @@ static int mysql_test_update(Prepared_statement *stmt,
*/
thd->allocate_temporary_memory_pool_for_ps_preparing();
- if (open_and_lock_tables(thd, table_list))
- res= -1;
- else
+ if (!(res= open_and_lock_tables(thd, table_list)))
{
if (!(res= mysql_prepare_update(thd, table_list,
&select->where,
@@ -1030,9 +1028,7 @@ static int mysql_test_delete(Prepared_statement *stmt,
*/
thd->allocate_temporary_memory_pool_for_ps_preparing();
- if (open_and_lock_tables(thd, table_list))
- res= -1;
- else
+ if (!(res= open_and_lock_tables(thd, table_list)))
{
res= mysql_prepare_delete(thd, table_list, &lex->select_lex.where);
lex->unit.cleanup();
@@ -1065,6 +1061,7 @@ static int mysql_test_select(Prepared_statement *stmt,
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
SELECT_LEX_UNIT *unit= &lex->unit;
+ int res;
DBUG_ENTER("mysql_test_select");
@@ -1084,11 +1081,11 @@ static int mysql_test_select(Prepared_statement *stmt,
tables & preparation procedure
*/
thd->allocate_temporary_memory_pool_for_ps_preparing();
- if (open_and_lock_tables(thd, tables))
+ if ((res= open_and_lock_tables(thd, tables)))
{
- send_error(thd);
goto err;
}
+ res= 1;
thd->used_tables= 0; // Updated by setup_fields
@@ -1126,7 +1123,7 @@ err_prep:
unit->cleanup();
err:
thd->free_temporary_memory_pool_for_ps_preparing();
- DBUG_RETURN(1);
+ DBUG_RETURN(res);
}
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index fa8b81f8ea2..7298d1d5249 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -497,6 +497,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
TABLE *table;
Protocol *protocol= thd->protocol;
TIME time;
+ int res;
DBUG_ENTER("mysqld_extend_show_tables");
(void) sprintf(path,"%s/%s",mysql_data_home,db);
@@ -554,13 +555,18 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
table_list.select_lex= &thd->lex->select_lex;
if (lower_case_table_names)
my_casedn_str(files_charset_info, file_name);
- if (open_and_lock_tables(thd, &table_list))
+ if ((res= open_and_lock_tables(thd, &table_list)))
{
for (uint i=2 ; i < field_list.elements ; i++)
protocol->store_null();
- // Send error to Comment field
- protocol->store(thd->net.last_error, system_charset_info);
- thd->clear_error();
+ // Send error to Comment field if possible
+ if (res < 0)
+ {
+ protocol->store(thd->net.last_error, system_charset_info);
+ thd->clear_error();
+ }
+ else
+ DBUG_RETURN(1)
}
else if (table_list.view)
{
@@ -695,14 +701,16 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
char tmp[MAX_FIELD_WIDTH];
Item *item;
Protocol *protocol= thd->protocol;
+ int res;
DBUG_ENTER("mysqld_show_fields");
DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
table_list->real_name));
table_list->lock_type= TL_UNLOCK;
- if (open_and_lock_tables(thd, table_list))
+ if ((res= open_and_lock_tables(thd, table_list)))
{
- send_error(thd);
+ if (res < 0)
+ send_error(thd);
DBUG_RETURN(1);
}
table= table_list->table;
@@ -836,14 +844,16 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
Protocol *protocol= thd->protocol;
char buff[2048];
String buffer(buff, sizeof(buff), system_charset_info);
+ int res;
DBUG_ENTER("mysqld_show_create");
DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
table_list->real_name));
/* Only one table for now, but VIEW can involve several tables */
- if (open_and_lock_tables(thd, table_list))
+ if ((res= open_and_lock_tables(thd, table_list)))
{
- send_error(thd);
+ if (res < 0)
+ send_error(thd);
DBUG_RETURN(1);
}
/* TODO: add environment variables show when it become possible */
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 61fb4b97200..a27244e1055 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -113,8 +113,8 @@ int mysql_update(THD *thd,
LINT_INIT(used_index);
LINT_INIT(timestamp_query_id);
- if ((open_and_lock_tables(thd, table_list)))
- DBUG_RETURN(-1);
+ if ((error= open_and_lock_tables(thd, table_list)))
+ DBUG_RETURN(error);
thd->proc_info="init";
table= table_list->table;
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);