summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorbell@sanja.is.com.ua <>2004-08-31 10:06:38 +0300
committerbell@sanja.is.com.ua <>2004-08-31 10:06:38 +0300
commit392c306969d8d07b9d3f5d0f1a77d531752f7371 (patch)
tree5f2f79152aa536016bbf28ae6e6b0e70d5087d25 /sql
parent7682b10ee84461f03a33cacbcec1bbe36f6e3f87 (diff)
downloadmariadb-git-392c306969d8d07b9d3f5d0f1a77d531752f7371.tar.gz
fixed open_and_lock_tables result processing (all open_and_lock_tables revision)
fixed printing of COLLATE operation (BUG#5155)
Diffstat (limited to 'sql')
-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
11 files changed, 54 insertions, 37 deletions
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);