summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2004-11-15 19:27:06 +0100
committerunknown <serg@serg.mylan>2004-11-15 19:27:06 +0100
commit03d82a4652c82fb1930e0e515877e8fffbb0e5b0 (patch)
treef8bc0b4f9899e5b4a5f848426d4568de1213e64b /sql
parentf3f73a48df66247e8c155fa429aeb1c42b2e7a55 (diff)
parenta59b0fbfd6b7627a4fdf2233482e732480dbe437 (diff)
downloadmariadb-git-03d82a4652c82fb1930e0e515877e8fffbb0e5b0.tar.gz
Merge bk-internal:/home/bk/mysql-5.0
into serg.mylan:/usr/home/serg/Abk/mysql-5.0 BitKeeper/etc/ignore: auto-union configure.in: Auto merged dbug/dbug.c: Auto merged include/my_dbug.h: Auto merged include/my_sys.h: Auto merged sql/filesort.cc: Auto merged sql/ha_isam.cc: Auto merged sql/ha_isammrg.cc: Auto merged sql/ha_myisam.cc: Auto merged sql/ha_myisammrg.cc: Auto merged sql/sql_select.cc: Auto merged
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc26
-rw-r--r--sql/field_conv.cc8
-rw-r--r--sql/filesort.cc5
-rw-r--r--sql/ha_heap.cc33
-rw-r--r--sql/ha_innodb.cc117
-rw-r--r--sql/ha_innodb.h3
-rw-r--r--sql/ha_isam.cc27
-rw-r--r--sql/ha_isammrg.cc9
-rw-r--r--sql/ha_myisam.cc38
-rw-r--r--sql/ha_myisammrg.cc34
-rw-r--r--sql/ha_ndbcluster.cc46
-rw-r--r--sql/handler.cc111
-rw-r--r--sql/handler.h10
-rw-r--r--sql/item.cc880
-rw-r--r--sql/item.h43
-rw-r--r--sql/item_buff.cc2
-rw-r--r--sql/item_cmpfunc.cc98
-rw-r--r--sql/item_cmpfunc.h14
-rw-r--r--sql/item_func.cc240
-rw-r--r--sql/item_func.h95
-rw-r--r--sql/item_geofunc.cc12
-rw-r--r--sql/item_geofunc.h8
-rw-r--r--sql/item_row.cc4
-rw-r--r--sql/item_row.h2
-rw-r--r--sql/item_strfunc.cc34
-rw-r--r--sql/item_strfunc.h4
-rw-r--r--sql/item_subselect.cc41
-rw-r--r--sql/item_subselect.h14
-rw-r--r--sql/item_sum.cc95
-rw-r--r--sql/item_sum.h50
-rw-r--r--sql/item_timefunc.cc17
-rw-r--r--sql/item_timefunc.h18
-rw-r--r--sql/item_uniq.h6
-rw-r--r--sql/lex.h2
-rw-r--r--sql/lock.cc5
-rw-r--r--sql/log.cc49
-rw-r--r--sql/log_event.cc35
-rw-r--r--sql/mysql_priv.h282
-rw-r--r--sql/mysqld.cc33
-rw-r--r--sql/net_serv.cc2
-rw-r--r--sql/opt_sum.cc2
-rw-r--r--sql/parse_file.cc13
-rw-r--r--sql/procedure.cc3
-rw-r--r--sql/procedure.h6
-rw-r--r--sql/protocol.cc19
-rw-r--r--sql/protocol.h3
-rw-r--r--sql/protocol_cursor.cc3
-rw-r--r--sql/repl_failsafe.cc51
-rw-r--r--sql/repl_failsafe.h6
-rw-r--r--sql/set_var.cc42
-rw-r--r--sql/share/czech/errmsg.txt21
-rw-r--r--sql/share/danish/errmsg.txt21
-rw-r--r--sql/share/dutch/errmsg.txt21
-rw-r--r--sql/share/english/errmsg.txt21
-rw-r--r--sql/share/estonian/errmsg.txt21
-rw-r--r--sql/share/french/errmsg.txt23
-rw-r--r--sql/share/german/errmsg.txt21
-rw-r--r--sql/share/greek/errmsg.txt23
-rw-r--r--sql/share/hungarian/errmsg.txt21
-rw-r--r--sql/share/italian/errmsg.txt21
-rw-r--r--sql/share/japanese/errmsg.txt21
-rw-r--r--sql/share/korean/errmsg.txt21
-rw-r--r--sql/share/norwegian-ny/errmsg.txt21
-rw-r--r--sql/share/norwegian/errmsg.txt21
-rw-r--r--sql/share/polish/errmsg.txt21
-rw-r--r--sql/share/portuguese/errmsg.txt23
-rw-r--r--sql/share/romanian/errmsg.txt23
-rw-r--r--sql/share/russian/errmsg.txt21
-rw-r--r--sql/share/serbian/errmsg.txt23
-rw-r--r--sql/share/slovak/errmsg.txt21
-rw-r--r--sql/share/spanish/errmsg.txt27
-rw-r--r--sql/share/swedish/errmsg.txt25
-rw-r--r--sql/share/ukrainian/errmsg.txt21
-rw-r--r--sql/slave.cc34
-rw-r--r--sql/slave.h8
-rw-r--r--sql/sp.cc17
-rw-r--r--sql/sp_head.cc34
-rw-r--r--sql/sp_rcontext.cc15
-rw-r--r--sql/sql_acl.cc437
-rw-r--r--sql/sql_acl.h16
-rw-r--r--sql/sql_analyse.cc8
-rw-r--r--sql/sql_base.cc235
-rw-r--r--sql/sql_class.cc17
-rw-r--r--sql/sql_class.h9
-rw-r--r--sql/sql_db.cc48
-rw-r--r--sql/sql_delete.cc119
-rw-r--r--sql/sql_do.cc6
-rw-r--r--sql/sql_error.cc14
-rw-r--r--sql/sql_handler.cc65
-rw-r--r--sql/sql_help.cc70
-rw-r--r--sql/sql_insert.cc97
-rw-r--r--sql/sql_lex.cc3
-rw-r--r--sql/sql_lex.h16
-rw-r--r--sql/sql_load.cc28
-rw-r--r--sql/sql_map.cc8
-rw-r--r--sql/sql_parse.cc866
-rw-r--r--sql/sql_prepare.cc261
-rw-r--r--sql/sql_rename.cc5
-rw-r--r--sql/sql_repl.cc98
-rw-r--r--sql/sql_repl.h10
-rw-r--r--sql/sql_select.cc232
-rw-r--r--sql/sql_select.h2
-rw-r--r--sql/sql_show.cc2330
-rw-r--r--sql/sql_string.h28
-rw-r--r--sql/sql_table.cc312
-rw-r--r--sql/sql_trigger.cc37
-rw-r--r--sql/sql_trigger.h6
-rw-r--r--sql/sql_udf.cc22
-rw-r--r--sql/sql_union.cc72
-rw-r--r--sql/sql_update.cc154
-rw-r--r--sql/sql_view.cc88
-rw-r--r--sql/sql_view.h6
-rw-r--r--sql/sql_yacc.yy439
-rw-r--r--sql/table.cc15
-rw-r--r--sql/table.h54
-rw-r--r--sql/unireg.cc4
116 files changed, 6094 insertions, 3454 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 1275e1bbb8e..5332607c6d5 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -4418,6 +4418,8 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)),
int Field_string::cmp(const char *a_ptr, const char *b_ptr)
{
+ uint a_len, b_len;
+
if (field_charset->strxfrm_multiply > 1)
{
/*
@@ -4429,10 +4431,19 @@ int Field_string::cmp(const char *a_ptr, const char *b_ptr)
(const uchar*) b_ptr,
field_length);
}
- return my_strnncoll(field_charset,(const uchar*) a_ptr, field_length,
- (const uchar*) b_ptr, field_length);
+ if (field_charset->mbmaxlen != 1)
+ {
+ uint char_len= field_length/field_charset->mbmaxlen;
+ a_len= my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len);
+ b_len= my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len);
+ }
+ else
+ a_len= b_len= field_length;
+ return my_strnncoll(field_charset,(const uchar*) a_ptr, a_len,
+ (const uchar*) b_ptr, b_len);
}
+
void Field_string::sort_string(char *to,uint length)
{
uint tmp=my_strnxfrm(field_charset,
@@ -5958,8 +5969,15 @@ Field *make_field(char *ptr, uint32 field_length,
if (f_is_alpha(pack_flag))
{
if (!f_is_packed(pack_flag))
- return new Field_string(ptr,field_length,null_pos,null_bit,
- unireg_check, field_name, table, field_charset);
+ {
+ if (field_type == FIELD_TYPE_STRING ||
+ field_type == FIELD_TYPE_DECIMAL || // 3.23 or 4.0 string
+ field_type == FIELD_TYPE_VAR_STRING)
+ return new Field_string(ptr,field_length,null_pos,null_bit,
+ unireg_check, field_name, table,
+ field_charset);
+ return 0; // Error
+ }
uint pack_length=calc_pack_length((enum_field_types)
f_packtype(pack_flag),
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 890687fc925..336408c5aa9 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -126,8 +126,7 @@ set_field_to_null(Field *field)
return 0;
}
if (!current_thd->no_errors)
- my_printf_error(ER_BAD_NULL_ERROR,ER(ER_BAD_NULL_ERROR),MYF(0),
- field->field_name);
+ my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
return -1;
}
@@ -185,8 +184,7 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions)
return 0;
}
if (!current_thd->no_errors)
- my_printf_error(ER_BAD_NULL_ERROR,ER(ER_BAD_NULL_ERROR),MYF(0),
- field->field_name);
+ my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
return -1;
}
@@ -473,7 +471,7 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
{
if (to->flags & BLOB_FLAG)
{
- if (!(from->flags & BLOB_FLAG))
+ if (!(from->flags & BLOB_FLAG) || from->charset() != to->charset())
return do_conv_blob;
if (from_length != to_length ||
to->table->db_low_byte_first != from->table->db_low_byte_first)
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 4ca8a2f418c..569ae3da357 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -284,7 +284,8 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
}
}
if (error)
- my_error(ER_FILSORT_ABORT,MYF(ME_ERROR+ME_WAITTANG));
+ my_message(ER_FILSORT_ABORT, ER(ER_FILSORT_ABORT),
+ MYF(ME_ERROR+ME_WAITTANG));
else
statistic_add(thd->status_var.filesort_rows,
(ulong) records, &LOCK_status);
@@ -707,7 +708,7 @@ static void make_sortkey(register SORTPARAM *param,
}
case REAL_RESULT:
{
- double value=item->val();
+ double value= item->val_real();
if ((maybe_null=item->null_value))
{
bzero((char*) to,sort_field->length+1);
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc
index 3bb8383e488..1c8967c1a34 100644
--- a/sql/ha_heap.cc
+++ b/sql/ha_heap.cc
@@ -86,7 +86,7 @@ void ha_heap::set_keys_for_scanning(void)
int ha_heap::write_row(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_write_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
table->timestamp_field->set_time();
if (table->next_number_field && buf == table->record[0])
@@ -96,7 +96,7 @@ int ha_heap::write_row(byte * buf)
int ha_heap::update_row(const byte * old_data, byte * new_data)
{
- statistic_increment(current_thd->status_var.ha_update_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
table->timestamp_field->set_time();
return heap_update(file,old_data,new_data);
@@ -104,7 +104,7 @@ int ha_heap::update_row(const byte * old_data, byte * new_data)
int ha_heap::delete_row(const byte * buf)
{
- statistic_increment(current_thd->status_var.ha_delete_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
return heap_delete(file,buf);
}
@@ -112,7 +112,8 @@ int ha_heap::index_read(byte * buf, const byte * key, uint key_len,
enum ha_rkey_function find_flag)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error = heap_rkey(file,buf,active_index, key, key_len, find_flag);
table->status = error ? STATUS_NOT_FOUND : 0;
return error;
@@ -121,7 +122,8 @@ int ha_heap::index_read(byte * buf, const byte * key, uint key_len,
int ha_heap::index_read_last(byte *buf, const byte *key, uint key_len)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error= heap_rkey(file, buf, active_index, key, key_len,
HA_READ_PREFIX_LAST);
table->status= error ? STATUS_NOT_FOUND : 0;
@@ -131,7 +133,8 @@ int ha_heap::index_read_last(byte *buf, const byte *key, uint key_len)
int ha_heap::index_read_idx(byte * buf, uint index, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
- statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error = heap_rkey(file, buf, index, key, key_len, find_flag);
table->status = error ? STATUS_NOT_FOUND : 0;
return error;
@@ -140,7 +143,8 @@ int ha_heap::index_read_idx(byte * buf, uint index, const byte * key,
int ha_heap::index_next(byte * buf)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_next_count,
+ &LOCK_status);
int error=heap_rnext(file,buf);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -149,7 +153,8 @@ int ha_heap::index_next(byte * buf)
int ha_heap::index_prev(byte * buf)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_prev_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_prev_count,
+ &LOCK_status);
int error=heap_rprev(file,buf);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -158,7 +163,7 @@ int ha_heap::index_prev(byte * buf)
int ha_heap::index_first(byte * buf)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_first_count,
+ statistic_increment(table->in_use->status_var.ha_read_first_count,
&LOCK_status);
int error=heap_rfirst(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -168,7 +173,8 @@ int ha_heap::index_first(byte * buf)
int ha_heap::index_last(byte * buf)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_last_count,
+ &LOCK_status);
int error=heap_rlast(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -181,7 +187,7 @@ int ha_heap::rnd_init(bool scan)
int ha_heap::rnd_next(byte *buf)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
+ statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
&LOCK_status);
int error=heap_scan(file, buf);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -192,7 +198,8 @@ int ha_heap::rnd_pos(byte * buf, byte *pos)
{
int error;
HEAP_PTR position;
- statistic_increment(current_thd->status_var.ha_read_rnd_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_rnd_count,
+ &LOCK_status);
memcpy_fixed((char*) &position,pos,sizeof(HEAP_PTR));
error=heap_rrnd(file, buf, position);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -456,7 +463,7 @@ int ha_heap::create(const char *name, TABLE *table_arg,
}
}
mem_per_row+= MY_ALIGN(table_arg->reclength + 1, sizeof(char*));
- max_rows = (ha_rows) (current_thd->variables.max_heap_table_size /
+ max_rows = (ha_rows) (table->in_use->variables.max_heap_table_size /
mem_per_row);
HP_CREATE_INFO hp_create_info;
hp_create_info.auto_key= auto_key;
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 370458c6e01..650cb86e253 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -495,9 +495,10 @@ innobase_mysql_tmpfile(void)
if (fd2 < 0) {
DBUG_PRINT("error",("Got error %d on dup",fd2));
my_errno=errno;
- my_error(EE_OUT_OF_FILERESOURCES,
- MYF(ME_BELL+ME_WAITTANG), filename, my_errno);
- }
+ my_error(EE_OUT_OF_FILERESOURCES,
+ MYF(ME_BELL+ME_WAITTANG),
+ filename, my_errno);
+ }
my_close(fd, MYF(MY_WME));
}
return(fd2);
@@ -4674,6 +4675,104 @@ ha_innobase::get_foreign_key_create_info(void)
return(str);
}
+
+int
+ha_innobase::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
+{
+ dict_foreign_t* foreign;
+
+ DBUG_ENTER("get_foreign_key_list");
+ row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt;
+ ut_a(prebuilt != NULL);
+ update_thd(current_thd);
+ prebuilt->trx->op_info = (char*)"getting list of foreign keys";
+ trx_search_latch_release_if_reserved(prebuilt->trx);
+ mutex_enter(&(dict_sys->mutex));
+ foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
+
+ while (foreign != NULL)
+ {
+ uint i;
+ FOREIGN_KEY_INFO f_key_info;
+ LEX_STRING *name= 0;
+ const char *tmp_buff;
+
+ tmp_buff= foreign->id;
+ i= 0;
+ while (tmp_buff[i] != '/')
+ i++;
+ tmp_buff+= i + 1;
+ f_key_info.forein_id= make_lex_string(thd, f_key_info.forein_id,
+ tmp_buff, strlen(tmp_buff), 1);
+ tmp_buff= foreign->referenced_table_name;
+ i= 0;
+ while (tmp_buff[i] != '/')
+ i++;
+ f_key_info.referenced_db= make_lex_string(thd, f_key_info.referenced_db,
+ tmp_buff, i, 1);
+ tmp_buff+= i + 1;
+ f_key_info.referenced_table= make_lex_string(thd,
+ f_key_info.referenced_table,
+ tmp_buff, strlen(tmp_buff), 1);
+
+ for (i= 0;;)
+ {
+ tmp_buff= foreign->foreign_col_names[i];
+ name= make_lex_string(thd, name, tmp_buff, strlen(tmp_buff), 1);
+ f_key_info.foreign_fields.push_back(name);
+ tmp_buff= foreign->referenced_col_names[i];
+ name= make_lex_string(thd, name, tmp_buff, strlen(tmp_buff), 1);
+ f_key_info.referenced_fields.push_back(name);
+ if (++i >= foreign->n_fields)
+ break;
+ }
+
+ ulong length= 0;
+ if (foreign->type == DICT_FOREIGN_ON_DELETE_CASCADE)
+ {
+ length=17;
+ tmp_buff= "ON DELETE CASCADE";
+ }
+ else if (foreign->type == DICT_FOREIGN_ON_DELETE_SET_NULL)
+ {
+ length=18;
+ tmp_buff= "ON DELETE SET NULL";
+ }
+ else if (foreign->type == DICT_FOREIGN_ON_DELETE_NO_ACTION)
+ {
+ length=19;
+ tmp_buff= "ON DELETE NO ACTION";
+ }
+ else if (foreign->type == DICT_FOREIGN_ON_UPDATE_CASCADE)
+ {
+ length=17;
+ tmp_buff= "ON UPDATE CASCADE";
+ }
+ else if (foreign->type == DICT_FOREIGN_ON_UPDATE_SET_NULL)
+ {
+ length=18;
+ tmp_buff= "ON UPDATE SET NULL";
+ }
+ else if (foreign->type == DICT_FOREIGN_ON_UPDATE_NO_ACTION)
+ {
+ length=19;
+ tmp_buff= "ON UPDATE NO ACTION";
+ }
+ f_key_info.constraint_method= make_lex_string(thd,
+ f_key_info.constraint_method,
+ tmp_buff, length, 1);
+
+ FOREIGN_KEY_INFO *pf_key_info= ((FOREIGN_KEY_INFO *)
+ thd->memdup((gptr) &f_key_info,
+ sizeof(FOREIGN_KEY_INFO)));
+ f_key_list->push_back(pf_key_info);
+ foreign = UT_LIST_GET_NEXT(foreign_list, foreign);
+ }
+ mutex_exit(&(dict_sys->mutex));
+ prebuilt->trx->op_info = (char*)"";
+ DBUG_RETURN(0);
+}
+
/***********************************************************************
Checks if a table is referenced by a foreign key. The MySQL manual states that
a REPLACE is either equivalent to an INSERT, or DELETE(s) + INSERT. Only a
@@ -5028,7 +5127,7 @@ ha_innobase::external_lock(
Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
Monitor to the client. */
-int
+bool
innodb_show_status(
/*===============*/
THD* thd) /* in: the MySQL query thread of the caller */
@@ -5042,7 +5141,7 @@ innodb_show_status(
my_message(ER_NOT_SUPPORTED_YET,
"Cannot call SHOW INNODB STATUS because skip-innodb is defined",
MYF(0));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
trx = check_trx_exists(thd);
@@ -5071,7 +5170,7 @@ innodb_show_status(
if (!(str = my_malloc(flen + 1, MYF(0))))
{
mutex_exit_noninline(&srv_monitor_file_mutex);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
rewind(srv_monitor_file);
@@ -5088,7 +5187,7 @@ innodb_show_status(
my_free(str, MYF(0));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
protocol->prepare_for_resend();
@@ -5096,10 +5195,10 @@ innodb_show_status(
my_free(str, MYF(0));
if (protocol->write())
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
/****************************************************************************
diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h
index 7e337afed0e..5ec5c207456 100644
--- a/sql/ha_innodb.h
+++ b/sql/ha_innodb.h
@@ -162,6 +162,7 @@ class ha_innobase: public handler
int check(THD* thd, HA_CHECK_OPT* check_opt);
char* update_table_comment(const char* comment);
char* get_foreign_key_create_info();
+ int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list);
uint referenced_by_foreign_key();
void free_foreign_key_create_info(char* str);
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
@@ -233,7 +234,7 @@ int innobase_savepoint(
my_off_t binlog_cache_pos);
int innobase_close_connection(THD *thd);
int innobase_drop_database(char *path);
-int innodb_show_status(THD* thd);
+bool innodb_show_status(THD* thd);
my_bool innobase_query_caching_of_table_permitted(THD* thd, char* full_name,
uint full_name_len);
diff --git a/sql/ha_isam.cc b/sql/ha_isam.cc
index 903f9c46002..e1fd17f4399 100644
--- a/sql/ha_isam.cc
+++ b/sql/ha_isam.cc
@@ -69,7 +69,7 @@ uint ha_isam::min_record_length(uint options) const
int ha_isam::write_row(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_write_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
table->timestamp_field->set_time();
if (table->next_number_field && buf == table->record[0])
@@ -79,7 +79,7 @@ int ha_isam::write_row(byte * buf)
int ha_isam::update_row(const byte * old_data, byte * new_data)
{
- statistic_increment(current_thd->status_var.ha_update_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_update_count, &LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
table->timestamp_field->set_time();
return !nisam_update(file,old_data,new_data) ? 0 : my_errno ? my_errno : -1;
@@ -87,14 +87,15 @@ int ha_isam::update_row(const byte * old_data, byte * new_data)
int ha_isam::delete_row(const byte * buf)
{
- statistic_increment(current_thd->status_var.ha_delete_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_delete_count, &LOCK_status);
return !nisam_delete(file,buf) ? 0 : my_errno ? my_errno : -1;
}
int ha_isam::index_read(byte * buf, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
- statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=nisam_rkey(file, buf, active_index, key, key_len, find_flag);
table->status=error ? STATUS_NOT_FOUND: 0;
return !error ? 0 : my_errno ? my_errno : -1;
@@ -103,7 +104,8 @@ int ha_isam::index_read(byte * buf, const byte * key,
int ha_isam::index_read_idx(byte * buf, uint index, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
- statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=nisam_rkey(file, buf, index, key, key_len, find_flag);
table->status=error ? STATUS_NOT_FOUND: 0;
return !error ? 0 : my_errno ? my_errno : -1;
@@ -111,7 +113,8 @@ int ha_isam::index_read_idx(byte * buf, uint index, const byte * key,
int ha_isam::index_read_last(byte * buf, const byte * key, uint key_len)
{
- statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=nisam_rkey(file, buf, active_index, key, key_len,
HA_READ_PREFIX_LAST);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -120,7 +123,7 @@ int ha_isam::index_read_last(byte * buf, const byte * key, uint key_len)
int ha_isam::index_next(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_read_next_count,
+ statistic_increment(table->in_use->status_var.ha_read_next_count,
&LOCK_status);
int error=nisam_rnext(file,buf,active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -129,7 +132,7 @@ int ha_isam::index_next(byte * buf)
int ha_isam::index_prev(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_read_prev_count,
+ statistic_increment(table->in_use->status_var.ha_read_prev_count,
&LOCK_status);
int error=nisam_rprev(file,buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -138,7 +141,7 @@ int ha_isam::index_prev(byte * buf)
int ha_isam::index_first(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_read_first_count,
+ statistic_increment(table->in_use->status_var.ha_read_first_count,
&LOCK_status);
int error=nisam_rfirst(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -147,7 +150,7 @@ int ha_isam::index_first(byte * buf)
int ha_isam::index_last(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_read_last_count,
+ statistic_increment(table->in_use->status_var.ha_read_last_count,
&LOCK_status);
int error=nisam_rlast(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -161,7 +164,7 @@ int ha_isam::rnd_init(bool scan)
int ha_isam::rnd_next(byte *buf)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
+ statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
&LOCK_status);
int error=nisam_rrnd(file, buf, NI_POS_ERROR);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -170,7 +173,7 @@ int ha_isam::rnd_next(byte *buf)
int ha_isam::rnd_pos(byte * buf, byte *pos)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_count,
+ statistic_increment(table->in_use->status_var.ha_read_rnd_count,
&LOCK_status);
int error=nisam_rrnd(file, buf, (ulong) my_get_ptr(pos,ref_length));
table->status=error ? STATUS_NOT_FOUND: 0;
diff --git a/sql/ha_isammrg.cc b/sql/ha_isammrg.cc
index 3d28b7aa4e2..c63548ec5cf 100644
--- a/sql/ha_isammrg.cc
+++ b/sql/ha_isammrg.cc
@@ -77,7 +77,7 @@ int ha_isammrg::write_row(byte * buf)
int ha_isammrg::update_row(const byte * old_data, byte * new_data)
{
- statistic_increment(current_thd->status_var.ha_update_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_update_count, &LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
table->timestamp_field->set_time();
return !mrg_update(file,old_data,new_data) ? 0 : my_errno ? my_errno : -1;
@@ -85,7 +85,7 @@ int ha_isammrg::update_row(const byte * old_data, byte * new_data)
int ha_isammrg::delete_row(const byte * buf)
{
- statistic_increment(current_thd->status_var.ha_delete_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_delete_count, &LOCK_status);
return !mrg_delete(file,buf) ? 0 : my_errno ? my_errno : -1;
}
@@ -128,7 +128,7 @@ int ha_isammrg::rnd_init(bool scan)
int ha_isammrg::rnd_next(byte *buf)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
+ statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
&LOCK_status);
int error=mrg_rrnd(file, buf, ~(mrg_off_t) 0);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -137,7 +137,8 @@ int ha_isammrg::rnd_next(byte *buf)
int ha_isammrg::rnd_pos(byte * buf, byte *pos)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_count, &LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_rnd_count,
+ &LOCK_status);
int error=mrg_rrnd(file, buf, (ulong) my_get_ptr(pos,ref_length));
table->status=error ? STATUS_NOT_FOUND: 0;
return !error ? 0 : my_errno ? my_errno : -1;
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 8ff67fe95ab..8b8824448ba 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -249,7 +249,7 @@ int ha_myisam::close(void)
int ha_myisam::write_row(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_write_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status);
/* If we have a timestamp column, update it to the current time */
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
@@ -602,7 +602,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
local_testflag|= T_STATISTICS;
param.testflag|= T_STATISTICS; // We get this for free
statistics_done=1;
- if (current_thd->variables.myisam_repair_threads>1)
+ if (thd->variables.myisam_repair_threads>1)
{
char buf[40];
/* TODO: respect myisam_repair_threads variable */
@@ -1084,7 +1084,7 @@ bool ha_myisam::is_crashed() const
int ha_myisam::update_row(const byte * old_data, byte * new_data)
{
- statistic_increment(current_thd->status_var.ha_update_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
table->timestamp_field->set_time();
return mi_update(file,old_data,new_data);
@@ -1092,7 +1092,7 @@ int ha_myisam::update_row(const byte * old_data, byte * new_data)
int ha_myisam::delete_row(const byte * buf)
{
- statistic_increment(current_thd->status_var.ha_delete_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
return mi_delete(file,buf);
}
@@ -1100,7 +1100,8 @@ int ha_myisam::index_read(byte * buf, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=mi_rkey(file,buf,active_index, key, key_len, find_flag);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -1109,7 +1110,8 @@ int ha_myisam::index_read(byte * buf, const byte * key,
int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
- statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=mi_rkey(file,buf,index, key, key_len, find_flag);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -1118,7 +1120,8 @@ int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key,
int ha_myisam::index_read_last(byte * buf, const byte * key, uint key_len)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=mi_rkey(file,buf,active_index, key, key_len, HA_READ_PREFIX_LAST);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -1127,7 +1130,8 @@ int ha_myisam::index_read_last(byte * buf, const byte * key, uint key_len)
int ha_myisam::index_next(byte * buf)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_next_count,
+ &LOCK_status);
int error=mi_rnext(file,buf,active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -1136,7 +1140,8 @@ int ha_myisam::index_next(byte * buf)
int ha_myisam::index_prev(byte * buf)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_prev_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_prev_count,
+ &LOCK_status);
int error=mi_rprev(file,buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -1145,7 +1150,7 @@ int ha_myisam::index_prev(byte * buf)
int ha_myisam::index_first(byte * buf)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_first_count,
+ statistic_increment(table->in_use->status_var.ha_read_first_count,
&LOCK_status);
int error=mi_rfirst(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -1155,7 +1160,8 @@ int ha_myisam::index_first(byte * buf)
int ha_myisam::index_last(byte * buf)
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_last_count,
+ &LOCK_status);
int error=mi_rlast(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -1166,7 +1172,8 @@ int ha_myisam::index_next_same(byte * buf,
uint length __attribute__((unused)))
{
DBUG_ASSERT(inited==INDEX);
- statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_next_count,
+ &LOCK_status);
int error=mi_rnext_same(file,buf);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -1182,7 +1189,7 @@ int ha_myisam::rnd_init(bool scan)
int ha_myisam::rnd_next(byte *buf)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
+ statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
&LOCK_status);
int error=mi_scan(file, buf);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -1196,7 +1203,8 @@ int ha_myisam::restart_rnd_next(byte *buf, byte *pos)
int ha_myisam::rnd_pos(byte * buf, byte *pos)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_rnd_count,
+ &LOCK_status);
int error=mi_rrnd(file, buf, my_get_ptr(pos,ref_length));
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -1606,7 +1614,7 @@ int ha_myisam::ft_read(byte * buf)
if (!ft_handler)
return -1;
- thread_safe_increment(current_thd->status_var.ha_read_next_count,
+ thread_safe_increment(table->in_use->status_var.ha_read_next_count,
&LOCK_status); // why ?
error=ft_handler->please->read_next(ft_handler,(char*) buf);
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index 3eadd94bb93..2574892b1fe 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -81,7 +81,7 @@ int ha_myisammrg::close(void)
int ha_myisammrg::write_row(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_write_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
table->timestamp_field->set_time();
if (table->next_number_field && buf == table->record[0])
@@ -91,7 +91,7 @@ int ha_myisammrg::write_row(byte * buf)
int ha_myisammrg::update_row(const byte * old_data, byte * new_data)
{
- statistic_increment(current_thd->status_var.ha_update_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
table->timestamp_field->set_time();
return myrg_update(file,old_data,new_data);
@@ -99,14 +99,15 @@ int ha_myisammrg::update_row(const byte * old_data, byte * new_data)
int ha_myisammrg::delete_row(const byte * buf)
{
- statistic_increment(current_thd->status_var.ha_delete_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
return myrg_delete(file,buf);
}
int ha_myisammrg::index_read(byte * buf, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
- statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=myrg_rkey(file,buf,active_index, key, key_len, find_flag);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -115,7 +116,8 @@ int ha_myisammrg::index_read(byte * buf, const byte * key,
int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
- statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=myrg_rkey(file,buf,index, key, key_len, find_flag);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -123,7 +125,8 @@ int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key,
int ha_myisammrg::index_read_last(byte * buf, const byte * key, uint key_len)
{
- statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_key_count,
+ &LOCK_status);
int error=myrg_rkey(file,buf,active_index, key, key_len,
HA_READ_PREFIX_LAST);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -132,7 +135,8 @@ int ha_myisammrg::index_read_last(byte * buf, const byte * key, uint key_len)
int ha_myisammrg::index_next(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_next_count,
+ &LOCK_status);
int error=myrg_rnext(file,buf,active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -140,7 +144,8 @@ int ha_myisammrg::index_next(byte * buf)
int ha_myisammrg::index_prev(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_read_prev_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_prev_count,
+ &LOCK_status);
int error=myrg_rprev(file,buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -148,7 +153,7 @@ int ha_myisammrg::index_prev(byte * buf)
int ha_myisammrg::index_first(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_read_first_count,
+ statistic_increment(table->in_use->status_var.ha_read_first_count,
&LOCK_status);
int error=myrg_rfirst(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -157,7 +162,8 @@ int ha_myisammrg::index_first(byte * buf)
int ha_myisammrg::index_last(byte * buf)
{
- statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_last_count,
+ &LOCK_status);
int error=myrg_rlast(file, buf, active_index);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -167,7 +173,8 @@ int ha_myisammrg::index_next_same(byte * buf,
const byte *key __attribute__((unused)),
uint length __attribute__((unused)))
{
- statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_next_count,
+ &LOCK_status);
int error=myrg_rnext_same(file,buf);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
@@ -180,7 +187,7 @@ int ha_myisammrg::rnd_init(bool scan)
int ha_myisammrg::rnd_next(byte *buf)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
+ statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
&LOCK_status);
int error=myrg_rrnd(file, buf, HA_OFFSET_ERROR);
table->status=error ? STATUS_NOT_FOUND: 0;
@@ -189,7 +196,8 @@ int ha_myisammrg::rnd_next(byte *buf)
int ha_myisammrg::rnd_pos(byte * buf, byte *pos)
{
- statistic_increment(current_thd->status_var.ha_read_rnd_count,&LOCK_status);
+ statistic_increment(table->in_use->status_var.ha_read_rnd_count,
+ &LOCK_status);
int error=myrg_rrnd(file, buf, my_get_ptr(pos,ref_length));
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index b2e115e9779..17aaaf20fa2 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -1290,7 +1290,6 @@ int ha_ndbcluster::set_bounds(NdbIndexScanOperation *op,
Field *field= key_part->field;
uint part_len= key_part->length;
uint part_store_len= key_part->store_length;
- bool part_nullable= (bool) key_part->null_bit;
// Info about each key part
struct part_st {
bool part_last;
@@ -1312,9 +1311,9 @@ int ha_ndbcluster::set_bounds(NdbIndexScanOperation *op,
p.part_last= (tot_len + part_store_len >= key_tot_len[j]);
p.key= keys[j];
p.part_ptr= &p.key->key[tot_len];
- p.part_null= (field->maybe_null() && *p.part_ptr);
+ p.part_null= key_part->null_bit && *p.part_ptr;
p.bound_ptr= (const char *)
- p.part_null ? 0 : part_nullable ? p.part_ptr + 1 : p.part_ptr;
+ p.part_null ? 0 : key_part->null_bit ? p.part_ptr + 1 : p.part_ptr;
if (j == 0)
{
@@ -2325,7 +2324,7 @@ int ha_ndbcluster::index_last(byte *buf)
DBUG_RETURN(0);
}
}
- DBUG_RETURN(1);
+ DBUG_RETURN(res);
}
@@ -2788,7 +2787,7 @@ int ha_ndbcluster::reset()
const char **ha_ndbcluster::bas_ext() const
-{ static const char *ext[]= { ".ndb", NullS }; return ext; }
+{ static const char *ext[]= { ha_ndb_ext, NullS }; return ext; }
/*
@@ -3322,7 +3321,7 @@ int ha_ndbcluster::create(const char *name,
{
NDBTAB tab;
NDBCOL col;
- uint pack_length, length, i;
+ uint pack_length, length, i, pk_length= 0;
const void *data, *pack_data;
const char **key_names= form->keynames.type_names;
char name2[FN_HEADLEN];
@@ -3369,6 +3368,8 @@ int ha_ndbcluster::create(const char *name,
if ((my_errno= create_ndb_column(col, field, info)))
DBUG_RETURN(my_errno);
tab.addColumn(col);
+ if(col.getPrimaryKey())
+ pk_length += (field->pack_length() + 3) / 4;
}
// No primary key, create shadow key as 64 bit, auto increment
@@ -3382,6 +3383,39 @@ int ha_ndbcluster::create(const char *name,
col.setPrimaryKey(TRUE);
col.setAutoIncrement(TRUE);
tab.addColumn(col);
+ pk_length += 2;
+ }
+
+ // Make sure that blob tables don't have to big part size
+ for (i= 0; i < form->fields; i++)
+ {
+ /**
+ * The extra +7 concists
+ * 2 - words from pk in blob table
+ * 5 - from extra words added by tup/dict??
+ */
+ switch (form->field[i]->real_type()) {
+ case MYSQL_TYPE_BLOB:
+ case MYSQL_TYPE_MEDIUM_BLOB:
+ case MYSQL_TYPE_LONG_BLOB:
+ {
+ NdbDictionary::Column * col = tab.getColumn(i);
+ int size = pk_length + (col->getPartSize()+3)/4 + 7;
+ if(size > NDB_MAX_TUPLE_SIZE_IN_WORDS &&
+ (pk_length+7) < NDB_MAX_TUPLE_SIZE_IN_WORDS)
+ {
+ size = NDB_MAX_TUPLE_SIZE_IN_WORDS - pk_length - 7;
+ col->setPartSize(4*size);
+ }
+ /**
+ * If size > NDB_MAX and pk_length+7 >= NDB_MAX
+ * then the table can't be created anyway, so skip
+ * changing part size, and have error later
+ */
+ }
+ default:
+ break;
+ }
}
if ((my_errno= check_ndb_connection()))
diff --git a/sql/handler.cc b/sql/handler.cc
index bb5e980f7bf..12820a66cb9 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -105,6 +105,9 @@ const char *tx_isolation_names[] =
TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names)-1,"",
tx_isolation_names, NULL};
+static TYPELIB known_extensions= {0,"known_exts", NULL, NULL};
+uint known_extensions_id= 0;
+
enum db_type ha_resolve_by_name(const char *name, uint namelen)
{
THD *thd= current_thd;
@@ -514,7 +517,8 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans)
if ((error=ndbcluster_commit(thd,trans->ndb_tid)))
{
if (error == -1)
- my_error(ER_ERROR_DURING_COMMIT, MYF(0));
+ my_message(ER_ERROR_DURING_COMMIT, ER(ER_ERROR_DURING_COMMIT),
+ MYF(0));
error=1;
}
if (trans == &thd->transaction.all)
@@ -577,13 +581,20 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans)
if (opt_using_transactions)
{
bool operation_done=0;
+ /*
+ As rollback can be 30 times slower than insert in InnoDB, and user may
+ not know there's rollback (if it's because of a dupl row), better warn.
+ */
+ const char *save_proc_info= thd->proc_info;
+ thd->proc_info= "Rolling back";
#ifdef HAVE_NDBCLUSTER_DB
if (trans->ndb_tid)
{
if ((error=ndbcluster_rollback(thd, trans->ndb_tid)))
{
if (error == -1)
- my_error(ER_ERROR_DURING_ROLLBACK, MYF(0));
+ my_message(ER_ERROR_DURING_ROLLBACK, ER(ER_ERROR_DURING_ROLLBACK),
+ MYF(0));
error=1;
}
trans->ndb_tid = 0;
@@ -648,6 +659,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans)
thd->variables.tx_isolation=thd->session_tx_isolation;
if (operation_done)
statistic_increment(thd->status_var.ha_rollback_count,&LOCK_status);
+ thd->proc_info= save_proc_info;
}
#endif /* USING_TRANSACTIONS */
DBUG_RETURN(error);
@@ -760,6 +772,25 @@ int ha_savepoint(THD *thd, char *savepoint_name)
DBUG_RETURN(error);
}
+
+int ha_start_consistent_snapshot(THD *thd)
+{
+#ifdef HAVE_INNOBASE_DB
+ if ((have_innodb == SHOW_OPTION_YES) &&
+ !innobase_start_trx_and_assign_read_view(thd))
+ return 0;
+#endif
+ /*
+ Same idea as when one wants to CREATE TABLE in one engine which does not
+ exist:
+ */
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
+ "This MySQL server does not support any "
+ "consistent-read capable storage engine");
+ return 0;
+}
+
+
bool ha_flush_logs()
{
bool result=0;
@@ -1169,7 +1200,7 @@ void handler::print_error(int error, myf errflag)
str.length(max_length-4);
str.append("...");
}
- my_error(ER_DUP_ENTRY,MYF(0),str.c_ptr(),key_nr+1);
+ my_error(ER_DUP_ENTRY, MYF(0), str.c_ptr(), key_nr+1);
DBUG_VOID_RETURN;
}
textno=ER_DUP_KEY;
@@ -1191,7 +1222,7 @@ void handler::print_error(int error, myf errflag)
textno=ER_CRASHED_ON_REPAIR;
break;
case HA_ERR_OUT_OF_MEM:
- my_error(ER_OUT_OF_RESOURCES,errflag);
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), errflag);
DBUG_VOID_RETURN;
case HA_ERR_WRONG_COMMAND:
textno=ER_ILLEGAL_HA;
@@ -1238,7 +1269,7 @@ void handler::print_error(int error, myf errflag)
uint length=dirname_part(buff,table->path);
buff[length-1]=0;
db=buff+dirname_length(buff);
- my_error(ER_NO_SUCH_TABLE,MYF(0),db,table->table_name);
+ my_error(ER_NO_SUCH_TABLE, MYF(0), db, table->table_name);
break;
}
default:
@@ -1252,16 +1283,16 @@ void handler::print_error(int error, myf errflag)
{
const char* engine= table_type();
if (temporary)
- my_error(ER_GET_TEMPORARY_ERRMSG,MYF(0),error,str.ptr(),engine);
+ my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(), engine);
else
- my_error(ER_GET_ERRMSG,MYF(0),error,str.ptr(),engine);
+ my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine);
}
else
my_error(ER_GET_ERRNO,errflag,error);
DBUG_VOID_RETURN;
}
}
- my_error(textno,errflag,table->table_name,error);
+ my_error(textno, errflag, table->table_name, error);
DBUG_VOID_RETURN;
}
@@ -1383,7 +1414,7 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info,
error=table.file->create(name,&table,create_info);
VOID(closefrm(&table));
if (error)
- my_error(ER_CANT_CREATE_TABLE,MYF(ME_BELL+ME_WAITTANG),name,error);
+ my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name,error);
DBUG_RETURN(error != 0);
}
@@ -1755,3 +1786,65 @@ int handler::index_read_idx(byte * buf, uint index, const byte * key,
error= ha_index_end();
return error;
}
+
+
+/*
+ Returns a list of all known extensions.
+
+ SYNOPSIS
+ ha_known_exts()
+
+ NOTES
+ No mutexes, worst case race is a minor surplus memory allocation
+ We have to recreate the extension map if mysqld is restarted (for example
+ within libmysqld)
+
+ RETURN VALUE
+ pointer pointer to TYPELIB structure
+*/
+
+TYPELIB *ha_known_exts(void)
+{
+ if (!known_extensions.type_names || mysys_usage_id != known_extensions_id)
+ {
+ show_table_type_st *types;
+ List<char> found_exts;
+ List_iterator_fast<char> it(found_exts);
+ const char **ext, *old_ext;
+
+ known_extensions_id= mysys_usage_id;
+ found_exts.push_back((char*) ".db");
+ for (types= sys_table_types; types->type; types++)
+ {
+ if (*types->value == SHOW_OPTION_YES)
+ {
+ handler *file= get_new_handler(0,(enum db_type) types->db_type);
+ for (ext= file->bas_ext(); *ext; ext++)
+ {
+ while ((old_ext= it++))
+ {
+ if (!strcmp(old_ext, *ext))
+ break;
+ }
+ if (!old_ext)
+ found_exts.push_back((char *) *ext);
+
+ it.rewind();
+ }
+ delete file;
+ }
+ }
+ ext= (const char **) my_once_alloc(sizeof(char *)*
+ (found_exts.elements+1),
+ MYF(MY_WME | MY_FAE));
+
+ DBUG_ASSERT(ext);
+ known_extensions.count= found_exts.elements;
+ known_extensions.type_names= ext;
+
+ while ((old_ext= it++))
+ *ext++= old_ext;
+ *ext= 0;
+ }
+ return &known_extensions;
+}
diff --git a/sql/handler.h b/sql/handler.h
index c408425ed60..31c6e2f902b 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -138,6 +138,8 @@
#define HA_CACHE_TBL_ASKTRANSACT 2
#define HA_CACHE_TBL_TRANSACT 4
+/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
+#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
enum db_type
{
@@ -221,6 +223,8 @@ typedef struct st_ha_create_information
struct st_table;
typedef struct st_table TABLE;
+struct st_foreign_key_info;
+typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
typedef struct st_ha_check_opt
{
@@ -463,6 +467,8 @@ public:
virtual char* get_foreign_key_create_info()
{ return(NULL);} /* gets foreign key create string from InnoDB */
/* used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
+ virtual int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
+ { return 0; }
virtual uint referenced_by_foreign_key() { return 0;}
virtual void init_table_handle_for_HANDLER()
{ return; } /* prepare InnoDB for HANDLER */
@@ -590,5 +596,5 @@ int ha_discover(THD* thd, const char* dbname, const char* name,
int ha_find_files(THD *thd,const char *db,const char *path,
const char *wild, bool dir,List<char>* files);
int ha_table_exists(THD* thd, const char* db, const char* name);
-
-
+TYPELIB *ha_known_exts(void);
+int ha_start_consistent_snapshot(THD *thd);
diff --git a/sql/item.cc b/sql/item.cc
index 9e28793493d..ea721eea831 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -26,6 +26,7 @@
#include "sql_acl.h"
#include "sp_head.h"
#include "sql_trigger.h"
+#include "sql_select.h"
static void mark_as_dependent(THD *thd,
SELECT_LEX *last, SELECT_LEX *current,
@@ -489,13 +490,13 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags)
}
else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
derivation < dt.derivation &&
- dt.derivation == DERIVATION_COERCIBLE)
+ dt.derivation >= DERIVATION_COERCIBLE)
{
// Do nothing;
}
else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
dt.derivation < derivation &&
- derivation == DERIVATION_COERCIBLE)
+ derivation >= DERIVATION_COERCIBLE)
{
set(dt);
strong= nagg;
@@ -710,7 +711,7 @@ String *Item_field::val_str(String *str)
return field->val_str(str,&str_value);
}
-double Item_field::val()
+double Item_field::val_real()
{
DBUG_ASSERT(fixed == 1);
if ((null_value=field->is_null()))
@@ -903,7 +904,7 @@ void Item_string::print(String *str)
bool Item_null::eq(const Item *item, bool binary_cmp) const
{ return item->type() == type(); }
-double Item_null::val()
+double Item_null::val_real()
{
// following assert is redundant, because fixed=1 assigned in constructor
DBUG_ASSERT(fixed == 1);
@@ -1220,7 +1221,7 @@ bool Item_param::get_date(TIME *res, uint fuzzydate)
}
-double Item_param::val()
+double Item_param::val_real()
{
switch (state) {
case REAL_VALUE:
@@ -1465,10 +1466,10 @@ bool Item::fix_fields(THD *thd,
// We do not check fields which are fixed during construction
DBUG_ASSERT(fixed == 0 || basic_const_item());
fixed= 1;
- return 0;
+ return FALSE;
}
-double Item_ref_null_helper::val()
+double Item_ref_null_helper::val_real()
{
DBUG_ASSERT(fixed == 1);
double tmp= (*ref)->val_result();
@@ -1532,170 +1533,415 @@ static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
}
-bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
+
+
+/*
+ Search a GROUP BY clause for a field with a certain name.
+
+ SYNOPSIS
+ find_field_in_group_list()
+ find_item the item being searched for
+ group_list GROUP BY clause
+
+ DESCRIPTION
+ Search the GROUP BY list for a column named as find_item. When searching
+ preference is given to columns that are qualified with the same table (and
+ database) name as the one being searched for.
+
+ RETURN
+ - the found item on success
+ - NULL if find_item is not in group_list
+*/
+
+static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
+{
+ const char *db_name;
+ const char *table_name;
+ const char *field_name;
+ ORDER *found_group= NULL;
+ int found_match_degree= 0;
+ Item_field *cur_field;
+ int cur_match_degree= 0;
+
+ if (find_item->type() == Item::FIELD_ITEM ||
+ find_item->type() == Item::REF_ITEM)
+ {
+ db_name= ((Item_ident*) find_item)->db_name;
+ table_name= ((Item_ident*) find_item)->table_name;
+ field_name= ((Item_ident*) find_item)->field_name;
+ }
+ else
+ return NULL;
+
+ DBUG_ASSERT(field_name);
+
+ for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
+ {
+ if ((*(cur_group->item))->type() == Item::FIELD_ITEM)
+ {
+ cur_field= (Item_field*) *cur_group->item;
+ cur_match_degree= 0;
+
+ DBUG_ASSERT(cur_field->field_name);
+
+ if (!my_strcasecmp(system_charset_info,
+ cur_field->field_name, field_name))
+ ++cur_match_degree;
+ else
+ continue;
+
+ if (cur_field->table_name && table_name)
+ {
+ /* If field_name is qualified by a table name. */
+ if (strcmp(cur_field->table_name, table_name))
+ /* Same field names, different tables. */
+ return NULL;
+
+ ++cur_match_degree;
+ if (cur_field->db_name && db_name)
+ {
+ /* If field_name is also qualified by a database name. */
+ if (strcmp(cur_field->db_name, db_name))
+ /* Same field names, different databases. */
+ return NULL;
+ ++cur_match_degree;
+ }
+ }
+
+ if (cur_match_degree > found_match_degree)
+ {
+ found_match_degree= cur_match_degree;
+ found_group= cur_group;
+ }
+ else if (found_group && (cur_match_degree == found_match_degree) &&
+ ! (*(found_group->item))->eq(cur_field, 0))
+ {
+ /*
+ If the current resolve candidate matches equally well as the current
+ best match, they must reference the same column, otherwise the field
+ is ambiguous.
+ */
+ my_error(ER_NON_UNIQ_ERROR, MYF(0),
+ find_item->full_name(), current_thd->where);
+ return NULL;
+ }
+ }
+ }
+
+ if (found_group)
+ return found_group->item;
+ else
+ return NULL;
+}
+
+
+/*
+ Resolve a column reference in a sub-select.
+
+ SYNOPSIS
+ resolve_ref_in_select_and_group()
+ thd current thread
+ ref column reference being resolved
+ select the sub-select that ref is resolved against
+
+ DESCRIPTION
+ Resolve a column reference (usually inside a HAVING clause) against the
+ SELECT and GROUP BY clauses of the query described by 'select'. The name
+ resolution algorithm searches both the SELECT and GROUP BY clauses, and in
+ case of a name conflict prefers GROUP BY column names over SELECT names. If
+ both clauses contain different fields with the same names, a warning is
+ issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no
+ GROUP BY column is found, then a HAVING name is resolved as a possibly
+ derived SELECT column.
+
+ NOTES
+ The resolution procedure is:
+ - Search for a column or derived column named col_ref_i [in table T_j]
+ in the SELECT clause of Q.
+ - Search for a column named col_ref_i [in table T_j]
+ in the GROUP BY clause of Q.
+ - If found different columns with the same name in GROUP BY and SELECT
+ - issue a warning and return the GROUP BY column,
+ - otherwise return the found SELECT column.
+
+
+ RETURN
+ NULL - there was an error, and the error was already reported
+ not_found_item - the item was not resolved, no error was reported
+ resolved item - if the item was resolved
+*/
+
+static Item**
+resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
+{
+ Item **group_by_ref= NULL;
+ Item **select_ref= NULL;
+ ORDER *group_list= (ORDER*) select->group_list.first;
+ bool ambiguous_fields= FALSE;
+ uint counter;
+ bool not_used;
+
+ /*
+ Search for a column or derived column named as 'ref' in the SELECT
+ clause of the current select.
+ */
+ if (!(select_ref= find_item_in_list(ref, *(select->get_item_list()), &counter,
+ REPORT_EXCEPT_NOT_FOUND, &not_used)))
+ return NULL; /* Some error occurred. */
+
+ /* If this is a non-aggregated field inside HAVING, search in GROUP BY. */
+ if (select->having_fix_field && !ref->with_sum_func && group_list)
+ {
+ group_by_ref= find_field_in_group_list(ref, group_list);
+
+ /* Check if the fields found in SELECT and GROUP BY are the same field. */
+ if (group_by_ref && (select_ref != not_found_item) &&
+ !((*group_by_ref)->eq(*select_ref, 0)))
+ {
+ ambiguous_fields= TRUE;
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
+ ER(ER_NON_UNIQ_ERROR), ref->full_name(),
+ current_thd->where);
+
+ }
+ }
+
+ if (select_ref != not_found_item || group_by_ref)
+ {
+ if (select_ref != not_found_item && !ambiguous_fields)
+ {
+ DBUG_ASSERT(*select_ref);
+ if (! (*select_ref)->fixed)
+ {
+ my_error(ER_ILLEGAL_REFERENCE, MYF(0),
+ ref->name, "forward reference in item list");
+ return NULL;
+ }
+ return (select->ref_pointer_array + counter);
+ }
+ else if (group_by_ref)
+ return group_by_ref;
+ else
+ DBUG_ASSERT(FALSE);
+ }
+ else
+ return (Item**) not_found_item;
+}
+
+
+/*
+ Resolve the name of a column reference.
+
+ SYNOPSIS
+ Item_field::fix_fields()
+ thd [in] current thread
+ tables [in] the tables in a FROM clause
+ reference [in/out] view column if this item was resolved to a view column
+
+ DESCRIPTION
+ The method resolves the column reference represented by 'this' as a column
+ present in one of: FROM clause, SELECT clause, GROUP BY clause of a query
+ Q, or in outer queries that contain Q.
+
+ NOTES
+ The name resolution algorithm used is (where [T_j] is an optional table
+ name that qualifies the column name):
+
+ resolve_column_reference([T_j].col_ref_i)
+ {
+ search for a column or derived column named col_ref_i
+ [in table T_j] in the FROM clause of Q;
+
+ if such a column is NOT found AND // Lookup in outer queries.
+ there are outer queries
+ {
+ for each outer query Q_k beginning from the inner-most one
+ {
+ if - Q_k is not a group query AND
+ - Q_k is not inside an aggregate function
+ OR
+ - Q_(k-1) is not in a HAVING or SELECT clause of Q_k
+ {
+ search for a column or derived column named col_ref_i
+ [in table T_j] in the FROM clause of Q_k;
+ }
+
+ if such a column is not found
+ Search for a column or derived column named col_ref_i
+ [in table T_j] in the SELECT and GROUP clauses of Q_k.
+ }
+ }
+ }
+
+ Notice that compared to Item_ref::fix_fields, here we first search the FROM
+ clause, and then we search the SELECT and GROUP BY clauses.
+
+ RETURN
+ TRUE if error
+ FALSE on success
+*/
+
+bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference)
{
DBUG_ASSERT(fixed == 0);
if (!field) // If field is not checked
{
- bool upward_lookup= 0;
- Field *tmp= (Field *)not_found_field;
- if ((tmp= find_field_in_tables(thd, this, tables, ref, 0,
+ bool upward_lookup= FALSE;
+ Field *from_field= (Field *)not_found_field;
+ if ((from_field= find_field_in_tables(thd, this, tables, reference,
+ IGNORE_EXCEPT_NON_UNIQUE,
!any_privileges)) ==
not_found_field)
{
- /*
- We can't find table field in table list of current select,
- consequently we have to find it in outer subselect(s).
- We can't join lists of outer & current select, because of scope
- of view rules. For example if both tables (outer & current) have
- field 'field' it is not mistake to refer to this field without
- mention of table name, but if we join tables in one list it will
- cause error ER_NON_UNIQ_ERROR in find_field_in_tables.
- */
SELECT_LEX *last= 0;
-#ifdef EMBEDDED_LIBRARY
- thd->net.last_errno= 0;
-#endif
TABLE_LIST *table_list;
- Item **refer= (Item **)not_found_item;
- uint counter;
- bool not_used;
- // Prevent using outer fields in subselects, that is not supported now
- SELECT_LEX *cursel= (SELECT_LEX *) thd->lex->current_select;
- if (cursel->master_unit()->first_select()->linkage != DERIVED_TABLE_TYPE)
+ Item **ref= (Item **) not_found_item;
+ SELECT_LEX *current_sel= (SELECT_LEX *) thd->lex->current_select;
+ /*
+ If there is an outer select, and it is not a derived table (which do
+ not support the use of outer fields for now), try to resolve this
+ reference in the outer select(s).
+
+ We treat each subselect as a separate namespace, so that different
+ subselects may contain columns with the same names. The subselects are
+ searched starting from the innermost.
+ */
+ if (current_sel->master_unit()->first_select()->linkage !=
+ DERIVED_TABLE_TYPE)
{
- SELECT_LEX_UNIT *prev_unit= cursel->master_unit();
- for (SELECT_LEX *sl= prev_unit->outer_select();
- sl;
- sl= (prev_unit= sl->master_unit())->outer_select())
+ SELECT_LEX_UNIT *prev_unit= current_sel->master_unit();
+ SELECT_LEX *outer_sel= prev_unit->outer_select();
+ for ( ; outer_sel ;
+ outer_sel= (prev_unit= outer_sel->master_unit())->outer_select())
{
- upward_lookup= 1;
- table_list= (last= sl)->get_table_list();
- if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list)
- {
+ last= outer_sel;
+ Item_subselect *prev_subselect_item= prev_unit->item;
+ upward_lookup= TRUE;
+
+ /* Search in the tables of the FROM clause of the outer select. */
+ table_list= outer_sel->get_table_list();
+ if (outer_sel->resolve_mode == SELECT_LEX::INSERT_MODE && table_list)
/*
- it is primary INSERT st_select_lex => skip first table
- resolving
+ It is a primary INSERT st_select_lex => do not resolve against the
+ first table.
*/
table_list= table_list->next_local;
- }
- Item_subselect *prev_subselect_item= prev_unit->item;
enum_parsing_place place= prev_subselect_item->parsing_place;
/*
- check table fields only if subquery used somewhere out of HAVING
- or outer SELECT do not use groupping (i.e. tables are accessable)
+ Check table fields only if the subquery is used somewhere out of
+ HAVING, or the outer SELECT does not use grouping (i.e. tables are
+ accessible).
*/
if ((place != IN_HAVING ||
- (sl->with_sum_func == 0 && sl->group_list.elements == 0)) &&
- (tmp= find_field_in_tables(thd, this,
- table_list, ref,
- 0, 1)) != not_found_field)
+ (outer_sel->with_sum_func == 0 &&
+ outer_sel->group_list.elements == 0)) &&
+ (from_field= find_field_in_tables(thd, this, table_list,
+ reference,
+ IGNORE_EXCEPT_NON_UNIQUE,
+ TRUE)) !=
+ not_found_field)
{
- if (tmp)
+ if (from_field)
{
- if (tmp != view_ref_found)
+ if (from_field != view_ref_found)
{
- prev_subselect_item->used_tables_cache|= tmp->table->map;
+ prev_subselect_item->used_tables_cache|= from_field->table->map;
prev_subselect_item->const_item_cache= 0;
}
else
{
prev_subselect_item->used_tables_cache|=
- (*ref)->used_tables();
+ (*reference)->used_tables();
prev_subselect_item->const_item_cache&=
- (*ref)->const_item();
+ (*reference)->const_item();
}
}
break;
}
- if (sl->resolve_mode == SELECT_LEX::SELECT_MODE &&
- (refer= find_item_in_list(this, sl->item_list, &counter,
- REPORT_EXCEPT_NOT_FOUND,
- &not_used)) !=
- (Item **) not_found_item)
+
+ /* Search in the SELECT and GROUP lists of the outer select. */
+ if (outer_sel->resolve_mode == SELECT_LEX::SELECT_MODE)
{
- if (*refer && (*refer)->fixed) // Avoid crash in case of error
- {
- prev_subselect_item->used_tables_cache|= (*refer)->used_tables();
- prev_subselect_item->const_item_cache&= (*refer)->const_item();
- }
- break;
+ if (!(ref= resolve_ref_in_select_and_group(thd, this, outer_sel)))
+ return TRUE; /* Some error occured (e.g. ambigous names). */
+ if (ref != not_found_item)
+ {
+ DBUG_ASSERT(*ref && (*ref)->fixed);
+ prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
+ prev_subselect_item->const_item_cache&= (*ref)->const_item();
+ break;
+ }
}
// Reference is not found => depend from outer (or just error)
prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
prev_subselect_item->const_item_cache= 0;
- if (sl->master_unit()->first_select()->linkage ==
+ if (outer_sel->master_unit()->first_select()->linkage ==
DERIVED_TABLE_TYPE)
break; // do not look over derived table
}
}
- if (!tmp)
- return -1;
- if (!refer)
- return 1;
- if (tmp == not_found_field && refer == (Item **)not_found_item)
+
+ DBUG_ASSERT(ref);
+ if (!from_field)
+ return TRUE;
+ if (ref == not_found_item && from_field == not_found_field)
{
if (upward_lookup)
{
- // We can't say exactly what absend table or field
- my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0),
- full_name(), thd->where);
+ // We can't say exactly what absent table or field
+ my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), thd->where);
}
else
{
// Call to report error
- find_field_in_tables(thd, this, tables, ref, 1, 1);
+ find_field_in_tables(thd, this, tables, reference, REPORT_ALL_ERRORS,
+ TRUE);
}
- return -1;
+ return TRUE;
}
- else if (refer != (Item **)not_found_item)
+ else if (ref != not_found_item)
{
- if (!(*refer)->fixed)
- {
- my_error(ER_ILLEGAL_REFERENCE, MYF(0), name,
- "forward reference in item list");
- return -1;
- }
+ /* Should have been checked in resolve_ref_in_select_and_group(). */
+ DBUG_ASSERT(*ref && (*ref)->fixed);
- Item_ref *rf= new Item_ref(last->ref_pointer_array + counter,
- (char *)table_name, (char *)field_name);
+ Item_ref *rf= new Item_ref(ref, (char *)table_name, (char *)field_name);
if (!rf)
- return 1;
- thd->change_item_tree(ref, rf);
+ return TRUE;
+ thd->change_item_tree(reference, rf);
/*
rf is Item_ref => never substitute other items (in this case)
during fix_fields() => we can use rf after fix_fields()
*/
- if (rf->fix_fields(thd, tables, ref) || rf->check_cols(1))
- return 1;
+ if (rf->fix_fields(thd, tables, reference) || rf->check_cols(1))
+ return TRUE;
- mark_as_dependent(thd, last, cursel, rf);
- return 0;
+ mark_as_dependent(thd, last, current_sel, rf);
+ return FALSE;
}
else
{
- mark_as_dependent(thd, last, cursel, this);
+ mark_as_dependent(thd, last, current_sel, this);
if (last->having_fix_field)
{
Item_ref *rf;
rf= new Item_ref((cached_table->db[0] ? cached_table->db : 0),
(char*) cached_table->alias, (char*) field_name);
if (!rf)
- return 1;
- thd->change_item_tree(ref, rf);
+ return TRUE;
+ thd->change_item_tree(reference, rf);
/*
rf is Item_ref => never substitute other items (in this case)
during fix_fields() => we can use rf after fix_fields()
*/
- return rf->fix_fields(thd, tables, ref) || rf->check_cols(1);
+ return rf->fix_fields(thd, tables, reference) || rf->check_cols(1);
}
}
}
- else if (!tmp)
- return -1;
+ else if (!from_field)
+ return TRUE;
/*
if it is not expression from merged VIEW we will set this field.
@@ -1709,8 +1955,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
Also we suppose that view can't be changed during PS/SP life.
*/
- if (tmp != view_ref_found)
- set_field(tmp);
+ if (from_field != view_ref_found)
+ set_field(from_field);
}
else if (thd->set_query_id && field->query_id != thd->query_id)
{
@@ -1738,22 +1984,18 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
db, tab, field_name) &
VIEW_ANY_ACL)))
{
- my_printf_error(ER_COLUMNACCESS_DENIED_ERROR,
- ER(ER_COLUMNACCESS_DENIED_ERROR),
- MYF(0),
- "ANY",
- thd->priv_user,
- thd->host_or_ip,
- field_name,
- tab);
- return 1;
+ my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
+ "ANY", thd->priv_user, thd->host_or_ip,
+ field_name, tab);
+ return TRUE;
}
}
#endif
fixed= 1;
- return 0;
+ return FALSE;
}
+
Item *Item_field::safe_charset_converter(CHARSET_INFO *tocs)
{
no_const_subst= 1;
@@ -2134,7 +2376,7 @@ int Item::save_in_field(Field *field, bool no_conversions)
}
else if (result_type() == REAL_RESULT)
{
- double nr=val();
+ double nr= val_real();
if (null_value)
return set_field_to_null(field);
field->set_notnull();
@@ -2204,8 +2446,7 @@ Item_real::Item_real(const char *str_arg, uint length)
when we are in the parser
*/
DBUG_ASSERT(str_arg[length] == 0);
- my_printf_error(ER_ILLEGAL_VALUE_FOR_TYPE, ER(ER_ILLEGAL_VALUE_FOR_TYPE),
- MYF(0), "double", (char*) str_arg);
+ my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg);
}
presentation= name=(char*) str_arg;
decimals=(uint8) nr_of_decimals(str_arg);
@@ -2216,7 +2457,7 @@ Item_real::Item_real(const char *str_arg, uint length)
int Item_real::save_in_field(Field *field, bool no_conversions)
{
- double nr=val();
+ double nr= val_real();
if (null_value)
return set_field_to_null(field);
field->set_notnull();
@@ -2378,15 +2619,14 @@ bool Item::send(Protocol *protocol, String *buffer)
case MYSQL_TYPE_FLOAT:
{
float nr;
- nr= (float) val();
+ nr= (float) val_real();
if (!null_value)
result= protocol->store(nr, decimals, buffer);
break;
}
case MYSQL_TYPE_DOUBLE:
{
- double nr;
- nr= val();
+ double nr= val_real();
if (!null_value)
result= protocol->store(nr, decimals, buffer);
break;
@@ -2428,207 +2668,240 @@ bool Item_field::send(Protocol *protocol, String *buffer)
/*
- This is used for HAVING clause
- Find field in select list having the same name
+ Resolve the name of a reference to a column reference.
+
+ SYNOPSIS
+ Item_ref::fix_fields()
+ thd [in] current thread
+ tables [in] the tables in a FROM clause
+ reference [in/out] view column if this item was resolved to a view column
+
+ DESCRIPTION
+ The method resolves the column reference represented by 'this' as a column
+ present in one of: GROUP BY clause, SELECT clause, outer queries. It is
+ used typically for columns in the HAVING clause which are not under
+ aggregate functions.
+
+ NOTES
+ The name resolution algorithm used is (where [T_j] is an optional table
+ name that qualifies the column name):
+
+ resolve_extended([T_j].col_ref_i)
+ {
+ Search for a column or derived column named col_ref_i [in table T_j]
+ in the SELECT and GROUP clauses of Q.
+
+ if such a column is NOT found AND // Lookup in outer queries.
+ there are outer queries
+ {
+ for each outer query Q_k beginning from the inner-most one
+ {
+ Search for a column or derived column named col_ref_i
+ [in table T_j] in the SELECT and GROUP clauses of Q_k.
+
+ if such a column is not found AND
+ - Q_k is not a group query AND
+ - Q_k is not inside an aggregate function
+ OR
+ - Q_(k-1) is not in a HAVING or SELECT clause of Q_k
+ {
+ search for a column or derived column named col_ref_i
+ [in table T_j] in the FROM clause of Q_k;
+ }
+ }
+ }
+ }
+
+ This procedure treats GROUP BY and SELECT clauses as one namespace for
+ column references in HAVING. Notice that compared to
+ Item_field::fix_fields, here we first search the SELECT and GROUP BY
+ clauses, and then we search the FROM clause.
+
+ RETURN
+ TRUE if error
+ FALSE on success
*/
bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference)
{
DBUG_ASSERT(fixed == 0);
- uint counter;
- bool not_used;
+ SELECT_LEX *current_sel= thd->lex->current_select;
+
if (!ref)
{
- TABLE_LIST *table_list;
- bool upward_lookup= 0;
- SELECT_LEX_UNIT *prev_unit= thd->lex->current_select->master_unit();
- SELECT_LEX *sl= prev_unit->outer_select();
- /*
- Finding only in current select will be performed for selects that have
- not outer one and for derived tables (which not support using outer
- fields for now)
- */
- if ((ref= find_item_in_list(this,
- *(thd->lex->current_select->get_item_list()),
- &counter,
- ((sl &&
- thd->lex->current_select->master_unit()->
- first_select()->linkage !=
- DERIVED_TABLE_TYPE) ?
- REPORT_EXCEPT_NOT_FOUND :
- REPORT_ALL_ERRORS), &not_used)) ==
- (Item **)not_found_item)
+ SELECT_LEX_UNIT *prev_unit= current_sel->master_unit();
+ SELECT_LEX *outer_sel= prev_unit->outer_select();
+ ORDER *group_list= (ORDER*) current_sel->group_list.first;
+ bool ambiguous_fields= FALSE;
+ Item **group_by_ref= NULL;
+
+ if (!(ref= resolve_ref_in_select_and_group(thd, this, current_sel)))
+ return TRUE; /* Some error occured (e.g. ambigous names). */
+
+ if (ref == not_found_item) /* This reference was not resolved. */
{
- Field *tmp= (Field*) not_found_field;
- SELECT_LEX *last= 0;
- upward_lookup= 1;
/*
- We can't find table field in select list of current select,
- consequently we have to find it in outer subselect(s).
- We can't join lists of outer & current select, because of scope
- of view rules. For example if both tables (outer & current) have
- field 'field' it is not mistake to refer to this field without
- mention of table name, but if we join tables in one list it will
- cause error ER_NON_UNIQ_ERROR in find_item_in_list.
+ If there is an outer select, and it is not a derived table (which do
+ not support the use of outer fields for now), try to resolve this
+ reference in the outer select(s).
+
+ We treat each subselect as a separate namespace, so that different
+ subselects may contain columns with the same names. The subselects are
+ searched starting from the innermost.
*/
- for ( ; sl ; sl= (prev_unit= sl->master_unit())->outer_select())
+ if (outer_sel && (current_sel->master_unit()->first_select()->linkage !=
+ DERIVED_TABLE_TYPE))
{
- last= sl;
- Item_subselect *prev_subselect_item= prev_unit->item;
- if (sl->resolve_mode == SELECT_LEX::SELECT_MODE &&
- (ref= find_item_in_list(this, sl->item_list,
- &counter, REPORT_EXCEPT_NOT_FOUND,
- &not_used)) !=
- (Item **)not_found_item)
- {
- if (*ref && (*ref)->fixed) // Avoid crash in case of error
- {
- prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
- prev_subselect_item->const_item_cache&= (*ref)->const_item();
- }
- break;
- }
- table_list= sl->get_table_list();
- if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list)
- {
- // it is primary INSERT st_select_lex => skip first table resolving
- table_list= table_list->next_local;
- }
- enum_parsing_place place= prev_subselect_item->parsing_place;
- /*
- Check table fields only if subquery used somewhere out of HAVING
- or SELECT list or outer SELECT do not use groupping (i.e. tables
- are accessable)
- */
- if ((place != IN_HAVING ||
- (sl->with_sum_func == 0 && sl->group_list.elements == 0)) &&
- (tmp= find_field_in_tables(thd, this,
- table_list, reference,
- 0, 1)) != not_found_field)
- {
- if (tmp)
+ TABLE_LIST *table_list;
+ Field *from_field= (Field*) not_found_field;
+ SELECT_LEX *last= 0;
+
+ for ( ; outer_sel ;
+ outer_sel= (prev_unit= outer_sel->master_unit())->outer_select())
+ {
+ last= outer_sel;
+ Item_subselect *prev_subselect_item= prev_unit->item;
+
+ /* Search in the SELECT and GROUP lists of the outer select. */
+ if (outer_sel->resolve_mode == SELECT_LEX::SELECT_MODE)
{
- if (tmp != view_ref_found)
+ if (!(ref= resolve_ref_in_select_and_group(thd, this, outer_sel)))
+ return TRUE; /* Some error occured (e.g. ambigous names). */
+ if (ref != not_found_item)
{
- prev_subselect_item->used_tables_cache|= tmp->table->map;
- prev_subselect_item->const_item_cache= 0;
+ DBUG_ASSERT(*ref && (*ref)->fixed);
+ prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
+ prev_subselect_item->const_item_cache&= (*ref)->const_item();
+ break;
}
- else
+ }
+
+ /* Search in the tables of the FROM clause of the outer select. */
+ table_list= outer_sel->get_table_list();
+ if (outer_sel->resolve_mode == SELECT_LEX::INSERT_MODE && table_list)
+ /*
+ It is a primary INSERT st_select_lex => do not resolve against the
+ first table.
+ */
+ table_list= table_list->next_local;
+
+ enum_parsing_place place= prev_subselect_item->parsing_place;
+ /*
+ Check table fields only if the subquery is used somewhere out of
+ HAVING or the outer SELECT does not use grouping (i.e. tables are
+ accessible).
+ TODO:
+ Here we could first find the field anyway, and then test this
+ condition, so that we can give a better error message -
+ ER_WRONG_FIELD_WITH_GROUP, instead of the less informative
+ ER_BAD_FIELD_ERROR which we produce now.
+ */
+ if ((place != IN_HAVING ||
+ (!outer_sel->with_sum_func &&
+ outer_sel->group_list.elements == 0)))
+ {
+ if ((from_field= find_field_in_tables(thd, this, table_list,
+ reference,
+ IGNORE_EXCEPT_NON_UNIQUE,
+ TRUE)) !=
+ not_found_field)
{
- prev_subselect_item->used_tables_cache|=
- (*reference)->used_tables();
- prev_subselect_item->const_item_cache&=
- (*reference)->const_item();
+ if (from_field != view_ref_found)
+ {
+ prev_subselect_item->used_tables_cache|= from_field->table->map;
+ prev_subselect_item->const_item_cache= 0;
+ }
+ else
+ {
+ prev_subselect_item->used_tables_cache|=
+ (*reference)->used_tables();
+ prev_subselect_item->const_item_cache&=
+ (*reference)->const_item();
+ }
+ break;
}
}
- break;
- }
- // Reference is not found => depend from outer (or just error)
- prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
- prev_subselect_item->const_item_cache= 0;
+ /* Reference is not found => depend on outer (or just error). */
+ prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
+ prev_subselect_item->const_item_cache= 0;
- if (sl->master_unit()->first_select()->linkage ==
- DERIVED_TABLE_TYPE)
- break; // do not look over derived table
- }
+ if (outer_sel->master_unit()->first_select()->linkage ==
+ DERIVED_TABLE_TYPE)
+ break; /* Do not consider derived tables. */
+ }
- if (!ref)
- return 1;
- if (!tmp)
- return -1;
- if (ref == (Item **)not_found_item && tmp == not_found_field)
- {
- if (upward_lookup)
- {
- // We can't say exactly what absend (table or field)
- my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0),
- full_name(), thd->where);
- }
- else
- {
- // Call to report error
- find_item_in_list(this,
- *(thd->lex->current_select->get_item_list()),
- &counter, REPORT_ALL_ERRORS, &not_used);
- }
- ref= 0; // Safety
- return 1;
- }
- if (tmp != not_found_field)
- {
- /*
- Set ref to 0 as we are replacing this item with the found item
- and this will ensure we get an error if this item would be
- used elsewhere
- */
- ref= 0; // Safety
- if (tmp != view_ref_found)
- {
- Item_field* fld;
- if (!(fld= new Item_field(tmp)))
- return 1;
- thd->change_item_tree(reference, fld);
- mark_as_dependent(thd, last, thd->lex->current_select, fld);
- return 0;
- }
- /*
- We can leave expression substituted from view for next PS/SP
- rexecution (i.e. do not register this substitution for reverting
- on cleupup() (register_item_tree_changing())), because this
- subtree will be fix_field'ed during
- setup_tables()->setup_ancestor() (i.e. before all other
- expressions of query, and references on tables which do not
- present in query will not make problems.
-
- Also we suppose that view can't be changed during PS/SP life.
- */
- }
- else
- {
- if (!(*ref)->fixed)
+ DBUG_ASSERT(ref);
+ if (!from_field)
+ return TRUE;
+ if (ref == not_found_item && from_field == not_found_field)
+ {
+ my_error(ER_BAD_FIELD_ERROR, MYF(0),
+ this->full_name(), current_thd->where);
+ ref= 0; // Safety
+ return TRUE;
+ }
+ if (from_field != not_found_field)
{
- my_error(ER_ILLEGAL_REFERENCE, MYF(0), name,
- "forward reference in item list");
- return -1;
+ /*
+ Set ref to 0 as we are replacing this item with the found item and
+ this will ensure we get an error if this item would be used
+ elsewhere
+ */
+ ref= 0; // Safety
+ if (from_field != view_ref_found)
+ {
+ Item_field* fld;
+ if (!(fld= new Item_field(from_field)))
+ return TRUE;
+ thd->change_item_tree(reference, fld);
+ mark_as_dependent(thd, last, thd->lex->current_select, fld);
+ return FALSE;
+ }
+ /*
+ We can leave expression substituted from view for next PS/SP
+ re-execution (i.e. do not register this substitution for reverting
+ on cleanup() (register_item_tree_changing())), because this subtree
+ will be fix_field'ed during setup_tables()->setup_ancestor()
+ (i.e. before all other expressions of query, and references on
+ tables which do not present in query will not make problems.
+
+ Also we suppose that view can't be changed during PS/SP life.
+ */
+ }
+ else
+ {
+ /* Should be checked in resolve_ref_in_select_and_group(). */
+ DBUG_ASSERT(*ref && (*ref)->fixed);
+ mark_as_dependent(thd, last, current_sel, this);
}
- mark_as_dependent(thd, last, thd->lex->current_select,
- this);
- ref= last->ref_pointer_array + counter;
}
- }
- else if (!ref)
- return 1;
- else
- {
- if (!(*ref)->fixed)
+ else
{
- my_error(ER_ILLEGAL_REFERENCE, MYF(0), name,
- "forward reference in item list");
- return -1;
+ /* The current reference cannot be resolved in this query. */
+ my_error(ER_BAD_FIELD_ERROR,MYF(0),
+ this->full_name(), current_thd->where);
+ return TRUE;
}
- ref= thd->lex->current_select->ref_pointer_array + counter;
}
}
/*
- The following conditional is changed as to correctly identify
- incorrect references in group functions or forward references
- with sub-select's / derived tables, while it prevents this
- check when Item_ref is created in an expression involving
- summing function, which is to be placed in the user variable.
+ Check if this is an incorrect reference in a group function or forward
+ reference. Do not issue an error if this is an unnamed reference inside an
+ aggregate function.
*/
if (((*ref)->with_sum_func && name &&
(depended_from ||
- !(thd->lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
- thd->lex->current_select->having_fix_field))) ||
+ !(current_sel->linkage != GLOBAL_OPTIONS_TYPE &&
+ current_sel->having_fix_field))) ||
!(*ref)->fixed)
{
- my_error(ER_ILLEGAL_REFERENCE, MYF(0), name,
- ((*ref)->with_sum_func?
- "reference on group function":
- "forward reference in item list"));
- return 1;
+ my_error(ER_ILLEGAL_REFERENCE, MYF(0),
+ name, ((*ref)->with_sum_func?
+ "reference to group function":
+ "forward reference in item list"));
+ return TRUE;
}
max_length= (*ref)->max_length;
maybe_null= (*ref)->maybe_null;
@@ -2638,8 +2911,8 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference)
fixed= 1;
if (ref && (*ref)->check_cols(1))
- return 1;
- return 0;
+ return TRUE;
+ return FALSE;
}
@@ -2677,7 +2950,7 @@ double Item_ref::val_result()
return 0.0;
return result_field->val_real();
}
- return val();
+ return val_real();
}
@@ -2743,34 +3016,33 @@ bool Item_default_value::fix_fields(THD *thd,
if (!arg)
{
fixed= 1;
- return 0;
+ return FALSE;
}
if (arg->fix_fields(thd, table_list, &arg))
- return 1;
+ return TRUE;
if (arg->type() == REF_ITEM)
{
Item_ref *ref= (Item_ref *)arg;
if (ref->ref[0]->type() != FIELD_ITEM)
{
- return 1;
+ return TRUE;
}
arg= ref->ref[0];
}
field_arg= (Item_field *)arg;
if (field_arg->field->flags & NO_DEFAULT_VALUE_FLAG)
{
- my_printf_error(ER_NO_DEFAULT_FOR_FIELD, ER(ER_NO_DEFAULT_FOR_FIELD),
- MYF(0), field_arg->field->field_name);
- return 1;
+ my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), field_arg->field->field_name);
+ return TRUE;
}
if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of())))
- return 1;
+ return TRUE;
memcpy(def_field, field_arg->field, field_arg->field->size_of());
def_field->move_field(def_field->table->default_values -
def_field->table->record[0]);
set_field(def_field);
- return 0;
+ return FALSE;
}
void Item_default_value::print(String *str)
@@ -2798,14 +3070,14 @@ bool Item_insert_value::fix_fields(THD *thd,
{
DBUG_ASSERT(fixed == 0);
if (arg->fix_fields(thd, table_list, &arg))
- return 1;
+ return TRUE;
if (arg->type() == REF_ITEM)
{
Item_ref *ref= (Item_ref *)arg;
if (ref->ref[0]->type() != FIELD_ITEM)
{
- return 1;
+ return TRUE;
}
arg= ref->ref[0];
}
@@ -2814,7 +3086,7 @@ bool Item_insert_value::fix_fields(THD *thd,
{
Field *def_field= (Field*) sql_alloc(field_arg->field->size_of());
if (!def_field)
- return 1;
+ return TRUE;
memcpy(def_field, field_arg->field, field_arg->field->size_of());
def_field->move_field(def_field->table->insert_values -
def_field->table->record[0]);
@@ -2827,7 +3099,7 @@ bool Item_insert_value::fix_fields(THD *thd,
set_field(new Field_null(0, 0, Field::NONE, tmp_field->field_name,
tmp_field->table, &my_charset_bin));
}
- return 0;
+ return FALSE;
}
void Item_insert_value::print(String *str)
@@ -2979,7 +3251,7 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item)
}
else
{ // It must REAL_RESULT
- double result=item->val();
+ double result= item->val_real();
uint length=item->max_length,decimals=item->decimals;
bool null_value=item->null_value;
new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
@@ -3014,7 +3286,7 @@ bool field_is_equal_to_item(Field *field,Item *item)
}
if (res_type == INT_RESULT)
return 1; // Both where of type int
- double result=item->val();
+ double result= item->val_real();
if (item->null_value)
return 1;
return result == field->val_real();
@@ -3087,7 +3359,7 @@ void Item_cache_str::store(Item *item)
}
-double Item_cache_str::val()
+double Item_cache_str::val_real()
{
DBUG_ASSERT(fixed == 1);
int err;
@@ -3318,10 +3590,10 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
if (item_type == STRING_RESULT && collation.aggregate(item->collation))
{
my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0),
- old_cs, old_derivation,
- item->collation.collation->name,
- item->collation.derivation_name(),
- "UNION");
+ old_cs, old_derivation,
+ item->collation.collation->name,
+ item->collation.derivation_name(),
+ "UNION");
return 1;
}
@@ -3355,7 +3627,7 @@ uint32 Item_type_holder::real_length(Item *item)
}
}
-double Item_type_holder::val()
+double Item_type_holder::val_real()
{
DBUG_ASSERT(0); // should never be called
return 0.0;
diff --git a/sql/item.h b/sql/item.h
index 93c396b95b0..9c036c28408 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -32,6 +32,7 @@ class Item_field;
enum Derivation
{
+ DERIVATION_IGNORABLE= 4,
DERIVATION_COERCIBLE= 3,
DERIVATION_IMPLICIT= 2,
DERIVATION_NONE= 1,
@@ -99,6 +100,7 @@ public:
{
switch(derivation)
{
+ case DERIVATION_IGNORABLE: return "IGNORABLE";
case DERIVATION_COERCIBLE: return "COERCIBLE";
case DERIVATION_IMPLICIT: return "IMPLICIT";
case DERIVATION_EXPLICIT: return "EXPLICIT";
@@ -186,7 +188,7 @@ public:
virtual enum_field_types field_type() const;
virtual enum Type type() const =0;
/* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
- virtual double val()=0;
+ virtual double val_real()=0;
virtual longlong val_int()=0;
/*
Return string representation of this item object.
@@ -217,7 +219,7 @@ public:
virtual Field *get_tmp_table_field() { return 0; }
virtual Field *tmp_table_field(TABLE *t_arg) { return 0; }
virtual const char *full_name() const { return name ? name : "???"; }
- virtual double val_result() { return val(); }
+ virtual double val_result() { return val_real(); }
virtual longlong val_int_result() { return val_int(); }
virtual String *str_result(String* tmp) { return val_str(tmp); }
/* bit map of tables used by item */
@@ -362,10 +364,10 @@ public:
// the item in the frame
enum Type type() const;
- inline double val()
+ inline double val_real()
{
Item *it= this_item();
- double ret= it->val();
+ double ret= it->val_real();
Item::null_value= it->null_value;
return ret;
}
@@ -526,7 +528,7 @@ public:
Item_field(Field *field);
enum Type type() const { return FIELD_ITEM; }
bool eq(const Item *item, bool binary_cmp) const;
- double val();
+ double val_real();
longlong val_int();
String *val_str(String*);
double val_result();
@@ -577,10 +579,11 @@ public:
max_length= 0;
name= name_par ? name_par : (char*) "NULL";
fixed= 1;
+ collation.set(&my_charset_bin, DERIVATION_IGNORABLE);
}
enum Type type() const { return NULL_ITEM; }
bool eq(const Item *item, bool binary_cmp) const;
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *str);
int save_in_field(Field *field, bool no_conversions);
@@ -669,7 +672,7 @@ public:
enum Type type() const { return item_type; }
enum_field_types field_type() const { return param_type; }
- double val();
+ double val_real();
longlong val_int();
String *val_str(String*);
bool get_time(TIME *tm);
@@ -726,7 +729,7 @@ public:
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
- double val() { DBUG_ASSERT(fixed == 1); return (double) value; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
String *val_str(String*);
int save_in_field(Field *field, bool no_conversions);
bool basic_const_item() const { return 1; }
@@ -755,7 +758,7 @@ public:
Item_uint(const char *str_arg, uint length);
Item_uint(uint32 i) :Item_int((longlong) i, 10)
{ unsigned_flag= 1; }
- double val()
+ double val_real()
{ DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); }
String *val_str(String*);
Item *new_item() { return new Item_uint(name,max_length); }
@@ -784,7 +787,7 @@ public:
int save_in_field(Field *field, bool no_conversions);
enum Type type() const { return REAL_ITEM; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
- double val() { DBUG_ASSERT(fixed == 1); return value; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return value; }
longlong val_int()
{
DBUG_ASSERT(fixed == 1);
@@ -855,7 +858,7 @@ public:
fixed= 1;
}
enum Type type() const { return STRING_ITEM; }
- double val()
+ double val_real()
{
DBUG_ASSERT(fixed == 1);
int err;
@@ -945,7 +948,7 @@ class Item_varbinary :public Item
public:
Item_varbinary(const char *str,uint str_length);
enum Type type() const { return VARBIN_ITEM; }
- double val()
+ double val_real()
{ DBUG_ASSERT(fixed == 1); return (double) Item_varbinary::val_int(); }
longlong val_int();
bool basic_const_item() const { return 1; }
@@ -997,7 +1000,7 @@ public:
enum Type type() const { return REF_ITEM; }
bool eq(const Item *item, bool binary_cmp) const
{ return ref && (*ref)->eq(item, binary_cmp); }
- double val()
+ double val_real()
{
double tmp=(*ref)->val_result();
null_value=(*ref)->null_value;
@@ -1062,7 +1065,7 @@ public:
Item_ref_null_helper(Item_in_subselect* master, Item **item,
const char *table_name_par, const char *field_name_par):
Item_ref(item, table_name_par, field_name_par), owner(master) {}
- double val();
+ double val_real();
longlong val_int();
String* val_str(String* s);
bool get_date(TIME *ltime, uint fuzzydate);
@@ -1130,7 +1133,7 @@ public:
enum Type type() const { return COPY_STR_ITEM; }
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return cached_field_type; }
- double val()
+ double val_real()
{
int err;
return (null_value ? 0.0 :
@@ -1358,7 +1361,7 @@ public:
Item_cache_int(): Item_cache() {}
void store(Item *item);
- double val() { DBUG_ASSERT(fixed == 1); return (double) value; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
String* val_str(String *str)
{
@@ -1376,7 +1379,7 @@ public:
Item_cache_real(): Item_cache() {}
void store(Item *item);
- double val() { DBUG_ASSERT(fixed == 1); return value; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return value; }
longlong val_int()
{
DBUG_ASSERT(fixed == 1);
@@ -1398,7 +1401,7 @@ public:
Item_cache_str(): Item_cache() { }
void store(Item *item);
- double val();
+ double val_real();
longlong val_int();
String* val_str(String *) { DBUG_ASSERT(fixed == 1); return value; }
enum Item_result result_type() const { return STRING_RESULT; }
@@ -1430,7 +1433,7 @@ public:
{
illegal_method_call((const char*)"make_field");
};
- double val()
+ double val_real()
{
illegal_method_call((const char*)"val");
return 0;
@@ -1481,7 +1484,7 @@ public:
Item_result result_type () const { return item_type; }
enum Type type() const { return TYPE_HOLDER; }
- double val();
+ double val_real();
longlong val_int();
String *val_str(String*);
bool join_types(THD *thd, Item *);
diff --git a/sql/item_buff.cc b/sql/item_buff.cc
index 1559cfe958e..66de26dba9a 100644
--- a/sql/item_buff.cc
+++ b/sql/item_buff.cc
@@ -70,7 +70,7 @@ Item_str_buff::~Item_str_buff()
bool Item_real_buff::cmp(void)
{
- double nr=item->val();
+ double nr= item->val_real();
if (null_value != item->null_value || nr != value)
{
null_value= item->null_value;
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 905250ed96f..4a4485ba2da 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -53,10 +53,10 @@ static void agg_cmp_type(Item_result *type, Item **items, uint nitems)
static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname)
{
- my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
- c1.collation->name,c1.derivation_name(),
- c2.collation->name,c2.derivation_name(),
- fname);
+ my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0),
+ c1.collation->name,c1.derivation_name(),
+ c2.collation->name,c2.derivation_name(),
+ fname);
}
@@ -104,7 +104,7 @@ Item_bool_func2* Le_creator::create(Item *a, Item *b) const
longlong Item_func_not::val_int()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
null_value=args[0]->null_value;
return !null_value && value == 0 ? 1 : 0;
}
@@ -116,7 +116,7 @@ longlong Item_func_not::val_int()
longlong Item_func_not_all::val_int()
{
DBUG_ASSERT(fixed == 1);
- double value= args[0]->val();
+ double value= args[0]->val_real();
if (abort_on_null)
{
null_value= 0;
@@ -384,10 +384,10 @@ int Arg_comparator::compare_e_binary_string()
int Arg_comparator::compare_real()
{
- double val1= (*a)->val();
+ double val1= (*a)->val_real();
if (!(*a)->null_value)
{
- double val2= (*b)->val();
+ double val2= (*b)->val_real();
if (!(*b)->null_value)
{
owner->null_value= 0;
@@ -402,8 +402,8 @@ int Arg_comparator::compare_real()
int Arg_comparator::compare_e_real()
{
- double val1= (*a)->val();
- double val2= (*b)->val();
+ double val1= (*a)->val_real();
+ double val2= (*b)->val_real();
if ((*a)->null_value || (*b)->null_value)
return test((*a)->null_value && (*b)->null_value);
return test(val1 == val2);
@@ -600,17 +600,17 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables,
{
DBUG_ASSERT(fixed == 0);
if (fix_left(thd, tables, ref))
- return 1;
+ return TRUE;
if (args[0]->maybe_null)
maybe_null=1;
if (!args[1]->fixed && args[1]->fix_fields(thd, tables, args+1))
- return 1;
+ return TRUE;
Item_in_subselect * sub= (Item_in_subselect *)args[1];
if (args[0]->cols() != sub->engine->cols())
{
my_error(ER_OPERAND_COLUMNS, MYF(0), args[0]->cols());
- return 1;
+ return TRUE;
}
if (args[1]->maybe_null)
maybe_null=1;
@@ -619,7 +619,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables,
not_null_tables_cache|= args[1]->not_null_tables();
const_item_cache&= args[1]->const_item();
fixed= 1;
- return 0;
+ return FALSE;
}
@@ -754,7 +754,7 @@ void Item_func_interval::fix_length_and_dec()
(intervals=(double*) sql_alloc(sizeof(double)*(row->cols()-1))))
{
for (uint i=1 ; i < row->cols(); i++)
- intervals[i-1]=row->el(i)->val();
+ intervals[i-1]= row->el(i)->val_real();
}
}
maybe_null= 0;
@@ -776,7 +776,7 @@ void Item_func_interval::fix_length_and_dec()
longlong Item_func_interval::val_int()
{
DBUG_ASSERT(fixed == 1);
- double value= row->el(0)->val();
+ double value= row->el(0)->val_real();
uint i;
if (row->el(0)->null_value)
@@ -799,7 +799,7 @@ longlong Item_func_interval::val_int()
for (i=1 ; i < row->cols() ; i++)
{
- if (row->el(i)->val() > value)
+ if (row->el(i)->val_real() > value)
return i-1;
}
return i-1;
@@ -873,7 +873,7 @@ longlong Item_func_between::val_int()
}
else if (cmp_type == INT_RESULT)
{
- longlong value=args[0]->val_int(),a,b;
+ longlong value=args[0]->val_int(), a, b;
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
a=args[1]->val_int();
@@ -893,11 +893,11 @@ longlong Item_func_between::val_int()
}
else
{
- double value=args[0]->val(),a,b;
+ double value= args[0]->val_real(),a,b;
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
- a=args[1]->val();
- b=args[2]->val();
+ a= args[1]->val_real();
+ b= args[2]->val_real();
if (!args[1]->null_value && !args[2]->null_value)
return (value >= a && value <= b) ? 1 : 0;
if (args[1]->null_value && args[2]->null_value)
@@ -954,16 +954,16 @@ Field *Item_func_ifnull::tmp_table_field(TABLE *table)
}
double
-Item_func_ifnull::val()
+Item_func_ifnull::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if (!args[0]->null_value)
{
null_value=0;
return value;
}
- value=args[1]->val();
+ value= args[1]->val_real();
if ((null_value=args[1]->null_value))
return 0.0;
return value;
@@ -1042,11 +1042,11 @@ Item_func_if::fix_length_and_dec()
double
-Item_func_if::val()
+Item_func_if::val_real()
{
DBUG_ASSERT(fixed == 1);
Item *arg= args[0]->val_int() ? args[1] : args[2];
- double value=arg->val();
+ double value= arg->val_real();
null_value=arg->null_value;
return value;
}
@@ -1095,7 +1095,7 @@ Item_func_nullif::fix_length_and_dec()
*/
double
-Item_func_nullif::val()
+Item_func_nullif::val_real()
{
DBUG_ASSERT(fixed == 1);
double value;
@@ -1104,7 +1104,7 @@ Item_func_nullif::val()
null_value=1;
return 0.0;
}
- value=args[0]->val();
+ value= args[0]->val_real();
null_value=args[0]->null_value;
return value;
}
@@ -1179,7 +1179,7 @@ Item *Item_func_case::find_item(String *str)
return else_expr_num != -1 ? args[else_expr_num] : 0;
break;
case REAL_RESULT:
- first_expr_real= args[first_expr_num]->val();
+ first_expr_real= args[first_expr_num]->val_real();
if (args[first_expr_num]->null_value)
return else_expr_num != -1 ? args[else_expr_num] : 0;
break;
@@ -1212,7 +1212,7 @@ Item *Item_func_case::find_item(String *str)
return args[i+1];
break;
case REAL_RESULT:
- if (args[i]->val()==first_expr_real && !args[i]->null_value)
+ if (args[i]->val_real() == first_expr_real && !args[i]->null_value)
return args[i+1];
break;
case ROW_RESULT:
@@ -1264,7 +1264,7 @@ longlong Item_func_case::val_int()
return res;
}
-double Item_func_case::val()
+double Item_func_case::val_real()
{
DBUG_ASSERT(fixed == 1);
char buff[MAX_FIELD_WIDTH];
@@ -1277,7 +1277,7 @@ double Item_func_case::val()
null_value=1;
return 0;
}
- res=item->val();
+ res= item->val_real();
null_value=item->null_value;
return res;
}
@@ -1400,13 +1400,13 @@ longlong Item_func_coalesce::val_int()
return 0;
}
-double Item_func_coalesce::val()
+double Item_func_coalesce::val_real()
{
DBUG_ASSERT(fixed == 1);
null_value=0;
for (uint i=0 ; i < arg_count ; i++)
{
- double res=args[i]->val();
+ double res= args[i]->val_real();
if (!args[i]->null_value)
return res;
}
@@ -1559,12 +1559,12 @@ in_double::in_double(uint elements)
void in_double::set(uint pos,Item *item)
{
- ((double*) base)[pos]=item->val();
+ ((double*) base)[pos]= item->val_real();
}
byte *in_double::get_value(Item *item)
{
- tmp= item->val();
+ tmp= item->val_real();
if (item->null_value)
return 0; /* purecov: inspected */
return (byte*) &tmp;
@@ -1956,7 +1956,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
and_tables_cache= ~(table_map) 0;
if (check_stack_overrun(thd, buff))
- return 1; // Fatal error flag is set!
+ return TRUE; // Fatal error flag is set!
while ((item=li++))
{
table_map tmp_table_map;
@@ -1974,7 +1974,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if ((!item->fixed &&
item->fix_fields(thd, tables, li.ref())) ||
(item= *li.ref())->check_cols(1))
- return 1; /* purecov: inspected */
+ return TRUE; /* purecov: inspected */
used_tables_cache|= item->used_tables();
tmp_table_map= item->not_null_tables();
not_null_tables_cache|= tmp_table_map;
@@ -1987,7 +1987,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
thd->lex->current_select->cond_count+= list.elements;
fix_length_and_dec();
fixed= 1;
- return 0;
+ return FALSE;
}
bool Item_cond::walk(Item_processor processor, byte *arg)
@@ -2339,12 +2339,12 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref)
DBUG_ASSERT(fixed == 0);
if (Item_bool_func2::fix_fields(thd, tlist, ref) ||
escape_item->fix_fields(thd, tlist, &escape_item))
- return 1;
+ return TRUE;
if (!escape_item->const_during_execution())
{
my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
- return 1;
+ return TRUE;
}
if (escape_item->const_item())
@@ -2362,7 +2362,7 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref)
{
String* res2 = args[1]->val_str(&tmp_value2);
if (!res2)
- return 0; // Null argument
+ return FALSE; // Null argument
const size_t len = res2->length();
const char* first = res2->ptr();
@@ -2395,7 +2395,7 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref)
}
}
}
- return 0;
+ return FALSE;
}
#ifdef USE_REGEX
@@ -2406,13 +2406,13 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
DBUG_ASSERT(fixed == 0);
if (args[0]->fix_fields(thd, tables, args) || args[0]->check_cols(1) ||
args[1]->fix_fields(thd,tables, args + 1) || args[1]->check_cols(1))
- return 1; /* purecov: inspected */
+ return TRUE; /* purecov: inspected */
with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func;
max_length= 1;
decimals= 0;
if (agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV))
- return 1;
+ return TRUE;
used_tables_cache=args[0]->used_tables() | args[1]->used_tables();
not_null_tables_cache= (args[0]->not_null_tables() |
@@ -2426,7 +2426,7 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if (args[1]->null_value)
{ // Will always return NULL
maybe_null=1;
- return 0;
+ return FALSE;
}
int error;
if ((error=regcomp(&preg,res->c_ptr(),
@@ -2436,8 +2436,8 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
cmp_collation.collation)))
{
(void) regerror(error,&preg,buff,sizeof(buff));
- my_printf_error(ER_REGEXP_ERROR,ER(ER_REGEXP_ERROR),MYF(0),buff);
- return 1;
+ my_error(ER_REGEXP_ERROR, MYF(0), buff);
+ return TRUE;
}
regex_compiled=regex_is_const=1;
maybe_null=args[0]->maybe_null;
@@ -2445,7 +2445,7 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
else
maybe_null=1;
fixed= 1;
- return 0;
+ return FALSE;
}
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index af2c385b296..02d5f6a1f7a 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -420,7 +420,7 @@ public:
Item_func_ifnull(Item *a,Item *b)
:Item_func(a,b), cached_result_type(INT_RESULT)
{}
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *str);
enum Item_result result_type () const { return cached_result_type; }
@@ -439,7 +439,7 @@ public:
Item_func_if(Item *a,Item *b,Item *c)
:Item_func(a,b,c), cached_result_type(INT_RESULT)
{}
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *str);
enum Item_result result_type () const { return cached_result_type; }
@@ -462,7 +462,7 @@ public:
Item_func_nullif(Item *a,Item *b)
:Item_bool_func2(a,b), cached_result_type(INT_RESULT)
{}
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *str);
enum Item_result result_type () const { return cached_result_type; }
@@ -481,7 +481,7 @@ public:
Item_func_coalesce(List<Item> &list)
:Item_func(list),cached_result_type(INT_RESULT)
{}
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *);
void fix_length_and_dec();
@@ -517,7 +517,7 @@ public:
}
set_arguments(list);
}
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *);
void fix_length_and_dec();
@@ -674,11 +674,11 @@ class cmp_item_real :public cmp_item
public:
void store_value(Item *item)
{
- value= item->val();
+ value= item->val_real();
}
int cmp(Item *arg)
{
- return value != arg->val();
+ return value != arg->val_real();
}
int compare(cmp_item *c)
{
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 185d4f115ad..8d4ad54b511 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -45,10 +45,10 @@ bool check_reserved_words(LEX_STRING *name)
static void my_coll_agg_error(DTCollation &c1, DTCollation &c2,
const char *fname)
{
- my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
- c1.collation->name,c1.derivation_name(),
- c2.collation->name,c2.derivation_name(),
- fname);
+ my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0),
+ c1.collation->name, c1.derivation_name(),
+ c2.collation->name, c2.derivation_name(),
+ fname);
}
static void my_coll_agg_error(DTCollation &c1,
@@ -56,11 +56,11 @@ static void my_coll_agg_error(DTCollation &c1,
DTCollation &c3,
const char *fname)
{
- my_error(ER_CANT_AGGREGATE_3COLLATIONS,MYF(0),
- c1.collation->name,c1.derivation_name(),
- c2.collation->name,c2.derivation_name(),
- c3.collation->name,c3.derivation_name(),
- fname);
+ my_error(ER_CANT_AGGREGATE_3COLLATIONS, MYF(0),
+ c1.collation->name, c1.derivation_name(),
+ c2.collation->name, c2.derivation_name(),
+ c3.collation->name, c3.derivation_name(),
+ fname);
}
@@ -74,7 +74,7 @@ static void my_coll_agg_error(Item** args, uint count, const char *fname)
args[2]->collation,
fname);
else
- my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),fname);
+ my_error(ER_CANT_AGGREGATE_NCOLLATIONS, MYF(0), fname);
}
@@ -281,8 +281,8 @@ Item_func::Item_func(THD *thd, Item_func *item)
item.
RETURN VALUES
- 0 ok
- 1 Got error. Stored with my_error().
+ FALSE ok
+ TRUE Got error. Stored with my_error().
*/
bool
@@ -298,7 +298,7 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
const_item_cache=1;
if (check_stack_overrun(thd, buff))
- return 1; // Fatal error if flag is set!
+ return TRUE; // Fatal error if flag is set!
if (arg_count)
{ // Print purify happy
for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++)
@@ -310,7 +310,7 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
*/
if ((!(*arg)->fixed && (*arg)->fix_fields(thd, tables, arg)) ||
(*arg)->check_cols(allowed_arg_cols))
- return 1; /* purecov: inspected */
+ return TRUE; /* purecov: inspected */
item= *arg;
if (item->maybe_null)
maybe_null=1;
@@ -322,10 +322,10 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
}
}
fix_length_and_dec();
- if (thd->net.last_errno) // An error inside fix_length_and_dec occured
- return 1;
+ if (thd->net.report_error) // An error inside fix_length_and_dec occured
+ return TRUE;
fixed= 1;
- return 0;
+ return FALSE;
}
bool Item_func::walk (Item_processor processor, byte *argument)
@@ -516,7 +516,7 @@ Field *Item_func::tmp_table_field(TABLE *t_arg)
String *Item_real_func::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- double nr=val();
+ double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals, &my_charset_bin);
@@ -539,7 +539,7 @@ String *Item_num_func::val_str(String *str)
}
else
{
- double nr=val();
+ double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals,&my_charset_bin);
@@ -616,7 +616,7 @@ String *Item_num_op::val_str(String *str)
}
else
{
- double nr=val();
+ double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals,&my_charset_bin);
@@ -643,10 +643,10 @@ void Item_func_unsigned::print(String *str)
}
-double Item_func_plus::val()
+double Item_func_plus::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val()+args[1]->val();
+ double value= args[0]->val_real() + args[1]->val_real();
if ((null_value=args[0]->null_value || args[1]->null_value))
return 0.0;
return value;
@@ -662,7 +662,7 @@ longlong Item_func_plus::val_int()
return 0;
return value;
}
- return (longlong) Item_func_plus::val();
+ return (longlong) Item_func_plus::val_real();
}
@@ -680,10 +680,10 @@ void Item_func_minus::fix_length_and_dec()
}
-double Item_func_minus::val()
+double Item_func_minus::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val() - args[1]->val();
+ double value= args[0]->val_real() - args[1]->val_real();
if ((null_value=args[0]->null_value || args[1]->null_value))
return 0.0;
return value;
@@ -699,14 +699,14 @@ longlong Item_func_minus::val_int()
return 0;
return value;
}
- return (longlong) Item_func_minus::val();
+ return (longlong) Item_func_minus::val_real();
}
-double Item_func_mul::val()
+double Item_func_mul::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val()*args[1]->val();
+ double value= args[0]->val_real() * args[1]->val_real();
if ((null_value=args[0]->null_value || args[1]->null_value))
return 0.0; /* purecov: inspected */
return value;
@@ -722,15 +722,15 @@ longlong Item_func_mul::val_int()
return 0; /* purecov: inspected */
return value;
}
- return (longlong) Item_func_mul::val();
+ return (longlong) Item_func_mul::val_real();
}
-double Item_func_div::val()
+double Item_func_div::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
- double val2=args[1]->val();
+ double value= args[0]->val_real();
+ double val2= args[1]->val_real();
if ((null_value= args[0]->null_value || args[1]->null_value))
return 0.0;
if (val2 == 0.0)
@@ -758,7 +758,7 @@ longlong Item_func_div::val_int()
}
return value/val2;
}
- return (longlong) Item_func_div::val();
+ return (longlong) Item_func_div::val_real();
}
@@ -800,11 +800,11 @@ void Item_func_int_div::fix_length_and_dec()
}
-double Item_func_mod::val()
+double Item_func_mod::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value= args[0]->val();
- double val2= args[1]->val();
+ double value= args[0]->val_real();
+ double val2= args[1]->val_real();
if ((null_value= args[0]->null_value || args[1]->null_value))
return 0.0; /* purecov: inspected */
if (val2 == 0.0)
@@ -836,10 +836,10 @@ void Item_func_mod::fix_length_and_dec()
}
-double Item_func_neg::val()
+double Item_func_neg::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
null_value=args[0]->null_value;
return -value;
}
@@ -879,10 +879,10 @@ void Item_func_neg::fix_length_and_dec()
}
-double Item_func_abs::val()
+double Item_func_abs::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
null_value=args[0]->null_value;
return fabs(value);
}
@@ -911,10 +911,10 @@ void Item_func_abs::fix_length_and_dec()
/* Gateway to natural LOG function */
-double Item_func_ln::val()
+double Item_func_ln::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=(args[0]->null_value || value <= 0.0)))
return 0.0;
return log(value);
@@ -925,15 +925,15 @@ double Item_func_ln::val()
We have to check if all values are > zero and first one is not one
as these are the cases then result is not a number.
*/
-double Item_func_log::val()
+double Item_func_log::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=(args[0]->null_value || value <= 0.0)))
return 0.0;
if (arg_count == 2)
{
- double value2= args[1]->val();
+ double value2= args[1]->val_real();
if ((null_value=(args[1]->null_value || value2 <= 0.0 || value == 1.0)))
return 0.0;
return log(value2) / log(value);
@@ -941,47 +941,47 @@ double Item_func_log::val()
return log(value);
}
-double Item_func_log2::val()
+double Item_func_log2::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=(args[0]->null_value || value <= 0.0)))
return 0.0;
return log(value) / M_LN2;
}
-double Item_func_log10::val()
+double Item_func_log10::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=(args[0]->null_value || value <= 0.0)))
return 0.0; /* purecov: inspected */
return log10(value);
}
-double Item_func_exp::val()
+double Item_func_exp::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=args[0]->null_value))
return 0.0; /* purecov: inspected */
return exp(value);
}
-double Item_func_sqrt::val()
+double Item_func_sqrt::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=(args[0]->null_value || value < 0)))
return 0.0; /* purecov: inspected */
return sqrt(value);
}
-double Item_func_pow::val()
+double Item_func_pow::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
- double val2=args[1]->val();
+ double value= args[0]->val_real();
+ double val2= args[1]->val_real();
if ((null_value=(args[0]->null_value || args[1]->null_value)))
return 0.0; /* purecov: inspected */
return pow(value,val2);
@@ -989,35 +989,35 @@ double Item_func_pow::val()
// Trigonometric functions
-double Item_func_acos::val()
+double Item_func_acos::val_real()
{
DBUG_ASSERT(fixed == 1);
// the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug)
- volatile double value=args[0]->val();
+ volatile double value= args[0]->val_real();
if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0))))
return 0.0;
return fix_result(acos(value));
}
-double Item_func_asin::val()
+double Item_func_asin::val_real()
{
DBUG_ASSERT(fixed == 1);
// the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug)
- volatile double value=args[0]->val();
+ volatile double value= args[0]->val_real();
if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0))))
return 0.0;
return fix_result(asin(value));
}
-double Item_func_atan::val()
+double Item_func_atan::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=args[0]->null_value))
return 0.0;
if (arg_count == 2)
{
- double val2= args[1]->val();
+ double val2= args[1]->val_real();
if ((null_value=args[1]->null_value))
return 0.0;
return fix_result(atan2(value,val2));
@@ -1025,28 +1025,28 @@ double Item_func_atan::val()
return fix_result(atan(value));
}
-double Item_func_cos::val()
+double Item_func_cos::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=args[0]->null_value))
return 0.0;
return fix_result(cos(value));
}
-double Item_func_sin::val()
+double Item_func_sin::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=args[0]->null_value))
return 0.0;
return fix_result(sin(value));
}
-double Item_func_tan::val()
+double Item_func_tan::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=args[0]->null_value))
return 0.0;
return fix_result(tan(value));
@@ -1110,7 +1110,7 @@ void Item_func_integer::fix_length_and_dec()
longlong Item_func_ceiling::val_int()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
null_value=args[0]->null_value;
return (longlong) ceil(value);
}
@@ -1119,7 +1119,7 @@ longlong Item_func_floor::val_int()
{
DBUG_ASSERT(fixed == 1);
// the volatile's for BUG #3051 to calm optimizer down (because of gcc's bug)
- volatile double value=args[0]->val();
+ volatile double value= args[0]->val_real();
null_value=args[0]->null_value;
return (longlong) floor(value);
}
@@ -1138,10 +1138,10 @@ void Item_func_round::fix_length_and_dec()
}
}
-double Item_func_round::val()
+double Item_func_round::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
int dec=(int) args[1]->val_int();
uint abs_dec=abs(dec);
double tmp;
@@ -1224,7 +1224,7 @@ void Item_func_rand::update_used_tables()
}
-double Item_func_rand::val()
+double Item_func_rand::val_real()
{
DBUG_ASSERT(fixed == 1);
return my_rnd(rand);
@@ -1233,16 +1233,16 @@ double Item_func_rand::val()
longlong Item_func_sign::val_int()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
null_value=args[0]->null_value;
return value < 0.0 ? -1 : (value > 0 ? 1 : 0);
}
-double Item_func_units::val()
+double Item_func_units::val_real()
{
DBUG_ASSERT(fixed == 1);
- double value=args[0]->val();
+ double value= args[0]->val_real();
if ((null_value=args[0]->null_value))
return 0;
return value*mul+add;
@@ -1288,7 +1288,7 @@ String *Item_func_min_max::val_str(String *str)
}
case REAL_RESULT:
{
- double nr=val();
+ double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals,&my_charset_bin);
@@ -1332,7 +1332,7 @@ String *Item_func_min_max::val_str(String *str)
}
-double Item_func_min_max::val()
+double Item_func_min_max::val_real()
{
DBUG_ASSERT(fixed == 1);
double value=0.0;
@@ -1341,12 +1341,12 @@ double Item_func_min_max::val()
{
if (null_value)
{
- value=args[i]->val();
+ value= args[i]->val_real();
null_value=args[i]->null_value;
}
else
{
- double tmp=args[i]->val();
+ double tmp= args[i]->val_real();
if (!args[i]->null_value && (tmp < value ? cmp_sign : -cmp_sign) > 0)
value=tmp;
}
@@ -1502,10 +1502,10 @@ longlong Item_func_field::val_int()
}
else
{
- double val= args[0]->val();
+ double val= args[0]->val_real();
for (uint i=1; i < arg_count ; i++)
{
- if (val == args[i]->val())
+ if (val == args[i]->val_real())
return (longlong) (i);
}
}
@@ -1708,15 +1708,14 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
DBUG_ENTER("Item_udf_func::fix_fields");
if (check_stack_overrun(thd, buff))
- DBUG_RETURN(1); // Fatal error flag is set!
+ DBUG_RETURN(TRUE); // Fatal error flag is set!
udf_func *tmp_udf=find_udf(u_d->name.str,(uint) u_d->name.length,1);
if (!tmp_udf)
{
- my_printf_error(ER_CANT_FIND_UDF,ER(ER_CANT_FIND_UDF),MYF(0),u_d->name.str,
- errno);
- DBUG_RETURN(1);
+ my_error(ER_CANT_FIND_UDF, MYF(0), u_d->name.str, errno);
+ DBUG_RETURN(TRUE);
}
u_d=tmp_udf;
args=arguments;
@@ -1733,7 +1732,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
{
free_udf(u_d);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
uint i;
Item **arg,**arg_end;
@@ -1746,7 +1745,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
// we can't assign 'item' before, because fix_fields() can change arg
Item *item= *arg;
if (item->check_cols(1))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
/*
TODO: We should think about this. It is not always
right way just to set an UDF result to return my_charset_bin
@@ -1779,7 +1778,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
sizeof(long))))
{
free_udf(u_d);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
}
func->fix_length_and_dec();
@@ -1818,7 +1817,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
}
break;
case Item::REAL_ITEM:
- *((double*) to) = arguments[i]->val();
+ *((double*) to)= arguments[i]->val_real();
if (!arguments[i]->null_value)
{
f_args.args[i]=to;
@@ -1835,10 +1834,10 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
u_d->func_init;
if ((error=(uchar) init(&initid, &f_args, thd->net.last_error)))
{
- my_printf_error(ER_CANT_INITIALIZE_UDF,ER(ER_CANT_INITIALIZE_UDF),MYF(0),
- u_d->name.str, thd->net.last_error);
+ my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
+ u_d->name.str, thd->net.last_error);
free_udf(u_d);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
func->max_length=min(initid.max_length,MAX_BLOB_WIDTH);
func->maybe_null=initid.maybe_null;
@@ -1848,11 +1847,11 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
initialized=1;
if (error)
{
- my_printf_error(ER_CANT_INITIALIZE_UDF,ER(ER_CANT_INITIALIZE_UDF),MYF(0),
- u_d->name.str, ER(ER_UNKNOWN_ERROR));
- DBUG_RETURN(1);
+ my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
+ u_d->name.str, ER(ER_UNKNOWN_ERROR));
+ DBUG_RETURN(TRUE);
}
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -1885,7 +1884,7 @@ bool udf_handler::get_arguments()
}
break;
case REAL_RESULT:
- *((double*) to) = args[i]->val();
+ *((double*) to)= args[i]->val_real();
if (!args[i]->null_value)
{
f_args.args[i]=to;
@@ -1940,7 +1939,7 @@ String *udf_handler::val_str(String *str,String *save_str)
-double Item_func_udf_float::val()
+double Item_func_udf_float::val_real()
{
DBUG_ASSERT(fixed == 1);
DBUG_ENTER("Item_func_udf_float::val");
@@ -1953,7 +1952,7 @@ double Item_func_udf_float::val()
String *Item_func_udf_float::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- double nr=val();
+ double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals,&my_charset_bin);
@@ -2374,7 +2373,7 @@ longlong Item_func_benchmark::val_int()
{
switch (args[0]->result_type()) {
case REAL_RESULT:
- (void) args[0]->val();
+ (void) args[0]->val_real();
break;
case INT_RESULT:
(void) args[0]->val_int();
@@ -2463,7 +2462,7 @@ bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables,
/* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
if (Item_func::fix_fields(thd, tables, ref) ||
!(entry= get_variable(&thd->user_vars, name, 1)))
- return 1;
+ return TRUE;
/*
Remember the last query which updated it, this way a query can later know
if this variable is a constant item in the query (it is if update_query_id
@@ -2489,7 +2488,7 @@ bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables,
entry->collation.set(args[0]->collation);
collation.set(entry->collation);
cached_result_type= args[0]->result_type();
- return 0;
+ return FALSE;
}
@@ -2647,7 +2646,7 @@ String *user_var_entry::val_str(my_bool *null_value, String *str,
will be catched by thd->net.report_error check in sql_set_variables().
RETURN
- 0 - OK.
+ FALSE OK.
*/
bool
@@ -2658,7 +2657,7 @@ Item_func_set_user_var::check()
switch (cached_result_type) {
case REAL_RESULT:
{
- save_result.vreal= args[0]->val();
+ save_result.vreal= args[0]->val_real();
break;
}
case INT_RESULT:
@@ -2677,7 +2676,7 @@ Item_func_set_user_var::check()
DBUG_ASSERT(0);
break;
}
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -2739,7 +2738,7 @@ Item_func_set_user_var::update()
}
-double Item_func_set_user_var::val()
+double Item_func_set_user_var::val_real()
{
DBUG_ASSERT(fixed == 1);
check();
@@ -2795,7 +2794,7 @@ Item_func_get_user_var::val_str(String *str)
}
-double Item_func_get_user_var::val()
+double Item_func_get_user_var::val_real()
{
DBUG_ASSERT(fixed == 1);
if (!var_entry)
@@ -3140,7 +3139,7 @@ bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
!args[0]->const_during_execution())
{
my_error(ER_WRONG_ARGUMENTS,MYF(0),"AGAINST");
- return 1;
+ return TRUE;
}
const_item_cache=0;
@@ -3163,7 +3162,7 @@ bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
if (key == NO_SUCH_KEY && !(flags & FT_BOOL))
{
my_error(ER_WRONG_ARGUMENTS,MYF(0),"MATCH");
- return 1;
+ return TRUE;
}
table=((Item_field *)item)->field->table;
table->fulltext_searched=1;
@@ -3245,7 +3244,8 @@ err:
key=NO_SUCH_KEY;
return 0;
}
- my_error(ER_FT_MATCHING_KEY_NOT_FOUND,MYF(0));
+ my_message(ER_FT_MATCHING_KEY_NOT_FOUND,
+ ER(ER_FT_MATCHING_KEY_NOT_FOUND), MYF(0));
return 1;
}
@@ -3266,7 +3266,7 @@ bool Item_func_match::eq(const Item *item, bool binary_cmp) const
}
-double Item_func_match::val()
+double Item_func_match::val_real()
{
DBUG_ASSERT(fixed == 1);
DBUG_ENTER("Item_func_match::val");
@@ -3374,7 +3374,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
{
if (!var->is_struct())
{
- net_printf(thd, ER_VARIABLE_IS_NOT_STRUCT, base_name->str);
+ my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), base_name->str);
return 0;
}
}
@@ -3539,8 +3539,7 @@ Item_func_sp::execute(Item **itp)
m_sp= sp_find_function(thd, m_name);
if (! m_sp)
{
- my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0),
- "FUNCTION", m_name->m_qname);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname);
DBUG_RETURN(-1);
}
@@ -3574,8 +3573,7 @@ Item_func_sp::field_type() const
DBUG_PRINT("info", ("m_returns = %d", m_sp->m_returns));
DBUG_RETURN(m_sp->m_returns);
}
- my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0),
- "FUNCTION", m_name->m_qname);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname);
DBUG_RETURN(MYSQL_TYPE_STRING);
}
@@ -3591,8 +3589,7 @@ Item_func_sp::result_type() const
{
DBUG_RETURN(m_sp->result());
}
- my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0),
- "FUNCTION", m_name->m_qname);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname);
DBUG_RETURN(STRING_RESULT);
}
@@ -3605,8 +3602,7 @@ Item_func_sp::fix_length_and_dec()
m_sp= sp_find_function(current_thd, m_name);
if (! m_sp)
{
- my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0),
- "FUNCTION", m_name->m_qname);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname);
}
else
{
diff --git a/sql/item_func.h b/sql/item_func.h
index 602b77ae956..03df78d721d 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -165,7 +165,8 @@ public:
Item_real_func(Item *a,Item *b) :Item_func(a,b) {}
Item_real_func(List<Item> &list) :Item_func(list) {}
String *val_str(String*str);
- longlong val_int() { DBUG_ASSERT(fixed == 1); return (longlong) val(); }
+ longlong val_int()
+ { DBUG_ASSERT(fixed == 1); return (longlong) val_real(); }
enum Item_result result_type () const { return REAL_RESULT; }
void fix_length_and_dec() { decimals=NOT_FIXED_DEC; max_length=float_length(decimals); }
};
@@ -179,10 +180,11 @@ public:
Item_num_func(Item *a) :Item_func(a),hybrid_type(REAL_RESULT) {}
Item_num_func(Item *a,Item *b) :Item_func(a,b),hybrid_type(REAL_RESULT) {}
String *val_str(String*str);
- longlong val_int() { DBUG_ASSERT(fixed == 1); return (longlong) val(); }
+ longlong val_int()
+ { DBUG_ASSERT(fixed == 1); return (longlong) val_real(); }
enum Item_result result_type () const { return hybrid_type; }
void fix_length_and_dec() { fix_num_length_and_dec(); }
- bool is_null() { (void) val(); return null_value; }
+ bool is_null() { (void) val_real(); return null_value; }
};
@@ -197,7 +199,7 @@ class Item_num_op :public Item_func
enum Item_result result_type () const { return hybrid_type; }
void fix_length_and_dec() { fix_num_length_and_dec(); find_num_type(); }
void find_num_type(void);
- bool is_null() { (void) val(); return null_value; }
+ bool is_null() { (void) val_real(); return null_value; }
};
@@ -210,7 +212,7 @@ public:
Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c) { max_length=21; }
Item_int_func(List<Item> &list) :Item_func(list) { max_length=21; }
Item_int_func(THD *thd, Item_int_func *item) :Item_func(thd, item) {}
- double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
String *val_str(String*str);
enum Item_result result_type () const { return INT_RESULT; }
void fix_length_and_dec() {}
@@ -222,9 +224,9 @@ class Item_func_signed :public Item_int_func
public:
Item_func_signed(Item *a) :Item_int_func(a) {}
const char *func_name() const { return "cast_as_signed"; }
- double val()
+ double val_real()
{
- double tmp= args[0]->val();
+ double tmp= args[0]->val_real();
null_value= args[0]->null_value;
return tmp;
}
@@ -256,7 +258,7 @@ class Item_func_plus :public Item_num_op
public:
Item_func_plus(Item *a,Item *b) :Item_num_op(a,b) {}
const char *func_name() const { return "+"; }
- double val();
+ double val_real();
longlong val_int();
};
@@ -265,7 +267,7 @@ class Item_func_minus :public Item_num_op
public:
Item_func_minus(Item *a,Item *b) :Item_num_op(a,b) {}
const char *func_name() const { return "-"; }
- double val();
+ double val_real();
longlong val_int();
void fix_length_and_dec();
};
@@ -276,7 +278,7 @@ class Item_func_mul :public Item_num_op
public:
Item_func_mul(Item *a,Item *b) :Item_num_op(a,b) {}
const char *func_name() const { return "*"; }
- double val();
+ double val_real();
longlong val_int();
};
@@ -285,7 +287,7 @@ class Item_func_div :public Item_num_op
{
public:
Item_func_div(Item *a,Item *b) :Item_num_op(a,b) {}
- double val();
+ double val_real();
longlong val_int();
const char *func_name() const { return "/"; }
void fix_length_and_dec();
@@ -297,7 +299,7 @@ class Item_func_int_div :public Item_num_op
public:
Item_func_int_div(Item *a,Item *b) :Item_num_op(a,b)
{ hybrid_type=INT_RESULT; }
- double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
longlong val_int();
const char *func_name() const { return "DIV"; }
void fix_length_and_dec();
@@ -308,7 +310,7 @@ class Item_func_mod :public Item_num_op
{
public:
Item_func_mod(Item *a,Item *b) :Item_num_op(a,b) {}
- double val();
+ double val_real();
longlong val_int();
const char *func_name() const { return "%"; }
void fix_length_and_dec();
@@ -319,7 +321,7 @@ class Item_func_neg :public Item_num_func
{
public:
Item_func_neg(Item *a) :Item_num_func(a) {}
- double val();
+ double val_real();
longlong val_int();
const char *func_name() const { return "-"; }
void fix_length_and_dec();
@@ -331,7 +333,7 @@ class Item_func_abs :public Item_num_func
public:
Item_func_abs(Item *a) :Item_num_func(a) {}
const char *func_name() const { return "abs"; }
- double val();
+ double val_real();
longlong val_int();
enum Item_result result_type () const
{ return args[0]->result_type() == INT_RESULT ? INT_RESULT : REAL_RESULT; }
@@ -368,7 +370,7 @@ class Item_func_exp :public Item_dec_func
{
public:
Item_func_exp(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "exp"; }
};
@@ -377,7 +379,7 @@ class Item_func_ln :public Item_dec_func
{
public:
Item_func_ln(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "ln"; }
};
@@ -387,7 +389,7 @@ class Item_func_log :public Item_dec_func
public:
Item_func_log(Item *a) :Item_dec_func(a) {}
Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {}
- double val();
+ double val_real();
const char *func_name() const { return "log"; }
};
@@ -396,7 +398,7 @@ class Item_func_log2 :public Item_dec_func
{
public:
Item_func_log2(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "log2"; }
};
@@ -405,7 +407,7 @@ class Item_func_log10 :public Item_dec_func
{
public:
Item_func_log10(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "log10"; }
};
@@ -414,7 +416,7 @@ class Item_func_sqrt :public Item_dec_func
{
public:
Item_func_sqrt(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "sqrt"; }
};
@@ -423,7 +425,7 @@ class Item_func_pow :public Item_dec_func
{
public:
Item_func_pow(Item *a,Item *b) :Item_dec_func(a,b) {}
- double val();
+ double val_real();
const char *func_name() const { return "pow"; }
};
@@ -432,7 +434,7 @@ class Item_func_acos :public Item_dec_func
{
public:
Item_func_acos(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "acos"; }
};
@@ -440,7 +442,7 @@ class Item_func_asin :public Item_dec_func
{
public:
Item_func_asin(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "asin"; }
};
@@ -449,7 +451,7 @@ class Item_func_atan :public Item_dec_func
public:
Item_func_atan(Item *a) :Item_dec_func(a) {}
Item_func_atan(Item *a,Item *b) :Item_dec_func(a,b) {}
- double val();
+ double val_real();
const char *func_name() const { return "atan"; }
};
@@ -457,7 +459,7 @@ class Item_func_cos :public Item_dec_func
{
public:
Item_func_cos(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "cos"; }
};
@@ -465,7 +467,7 @@ class Item_func_sin :public Item_dec_func
{
public:
Item_func_sin(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "sin"; }
};
@@ -473,7 +475,7 @@ class Item_func_tan :public Item_dec_func
{
public:
Item_func_tan(Item *a) :Item_dec_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "tan"; }
};
@@ -511,7 +513,7 @@ public:
Item_func_round(Item *a,Item *b,bool trunc_arg)
:Item_real_func(a,b),truncate(trunc_arg) {}
const char *func_name() const { return truncate ? "truncate" : "round"; }
- double val();
+ double val_real();
void fix_length_and_dec();
};
@@ -522,7 +524,7 @@ class Item_func_rand :public Item_real_func
public:
Item_func_rand(Item *a) :Item_real_func(a), rand(0) {}
Item_func_rand() :Item_real_func() {}
- double val();
+ double val_real();
const char *func_name() const { return "rand"; }
bool const_item() const { return 0; }
void update_used_tables();
@@ -546,7 +548,7 @@ class Item_func_units :public Item_real_func
public:
Item_func_units(char *name_arg,Item *a,double mul_arg,double add_arg)
:Item_real_func(a),name(name_arg),mul(mul_arg),add(add_arg) {}
- double val();
+ double val_real();
const char *func_name() const { return name; }
void fix_length_and_dec() { decimals=NOT_FIXED_DEC; max_length=float_length(decimals); }
};
@@ -560,7 +562,7 @@ class Item_func_min_max :public Item_func
public:
Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list),
cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg) {}
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *);
void fix_length_and_dec();
@@ -799,8 +801,11 @@ class Item_func_udf_float :public Item_udf_func
Item_func_udf_float(udf_func *udf_arg, List<Item> &list)
:Item_udf_func(udf_arg,list) {}
longlong val_int()
- { DBUG_ASSERT(fixed == 1); return (longlong) Item_func_udf_float::val(); }
- double val();
+ {
+ DBUG_ASSERT(fixed == 1);
+ return (longlong) Item_func_udf_float::val_real();
+ }
+ double val_real();
String *val_str(String *str);
void fix_length_and_dec() { fix_num_length_and_dec(); }
};
@@ -813,7 +818,7 @@ public:
Item_func_udf_int(udf_func *udf_arg, List<Item> &list)
:Item_udf_func(udf_arg,list) {}
longlong val_int();
- double val() { return (double) Item_func_udf_int::val_int(); }
+ double val_real() { return (double) Item_func_udf_int::val_int(); }
String *val_str(String *str);
enum Item_result result_type () const { return INT_RESULT; }
void fix_length_and_dec() { decimals=0; max_length=21; }
@@ -827,7 +832,7 @@ public:
Item_func_udf_str(udf_func *udf_arg, List<Item> &list)
:Item_udf_func(udf_arg,list) {}
String *val_str(String *);
- double val()
+ double val_real()
{
int err;
String *res; res=val_str(&str_value);
@@ -850,7 +855,7 @@ class Item_func_udf_float :public Item_real_func
public:
Item_func_udf_float(udf_func *udf_arg) :Item_real_func() {}
Item_func_udf_float(udf_func *udf_arg, List<Item> &list) :Item_real_func(list) {}
- double val() { DBUG_ASSERT(fixed == 1); return 0.0; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; }
};
@@ -870,7 +875,7 @@ public:
Item_func_udf_str(udf_func *udf_arg, List<Item> &list) :Item_func(list) {}
String *val_str(String *)
{ DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
- double val() { DBUG_ASSERT(fixed == 1); null_value=1; return 0.0; }
+ double val_real() { DBUG_ASSERT(fixed == 1); null_value= 1; return 0.0; }
longlong val_int() { DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
enum Item_result result_type () const { return STRING_RESULT; }
void fix_length_and_dec() { maybe_null=1; max_length=0; }
@@ -945,7 +950,7 @@ public:
Item_func_set_user_var(LEX_STRING a,Item *b)
:Item_func(b), cached_result_type(INT_RESULT), name(a)
{}
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *str);
bool update_hash(void *ptr, uint length, enum Item_result type,
@@ -971,7 +976,7 @@ public:
Item_func(), name(a) {}
enum Functype functype() const { return GUSERVAR_FUNC; }
LEX_STRING get_name() { return name; }
- double val();
+ double val_real();
longlong val_int();
String *val_str(String* str);
void fix_length_and_dec();
@@ -1044,8 +1049,8 @@ public:
bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref);
bool eq(const Item *, bool binary_cmp) const;
/* The following should be safe, even if we compare doubles */
- longlong val_int() { DBUG_ASSERT(fixed == 1); return val()!=0.0; }
- double val();
+ longlong val_int() { DBUG_ASSERT(fixed == 1); return val_real() != 0.0; }
+ double val_real();
void print(String *str);
bool fix_index();
@@ -1134,10 +1139,10 @@ public:
longlong val_int()
{
- return (longlong)Item_func_sp::val();
+ return (longlong)Item_func_sp::val_real();
}
- double val()
+ double val_real()
{
Item *it;
double d;
@@ -1147,7 +1152,7 @@ public:
null_value= 1;
return 0.0;
}
- d= it->val();
+ d= it->val_real();
null_value= it->null_value;
return d;
}
diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc
index 7c3319bbfea..163260f6428 100644
--- a/sql/item_geofunc.cc
+++ b/sql/item_geofunc.cc
@@ -320,8 +320,8 @@ err:
String *Item_func_point::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- double x= args[0]->val();
- double y= args[1]->val();
+ double x= args[0]->val_real();
+ double y= args[1]->val_real();
if ((null_value= (args[0]->null_value ||
args[1]->null_value ||
@@ -628,7 +628,7 @@ longlong Item_func_numpoints::val_int()
}
-double Item_func_x::val()
+double Item_func_x::val_real()
{
DBUG_ASSERT(fixed == 1);
double res= 0.0; // In case of errors
@@ -645,7 +645,7 @@ double Item_func_x::val()
}
-double Item_func_y::val()
+double Item_func_y::val_real()
{
DBUG_ASSERT(fixed == 1);
double res= 0; // In case of errors
@@ -662,7 +662,7 @@ double Item_func_y::val()
}
-double Item_func_area::val()
+double Item_func_area::val_real()
{
DBUG_ASSERT(fixed == 1);
double res= 0; // In case of errors
@@ -679,7 +679,7 @@ double Item_func_area::val()
return res;
}
-double Item_func_glength::val()
+double Item_func_glength::val_real()
{
DBUG_ASSERT(fixed == 1);
double res= 0; // In case of errors
diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h
index 79e4f804a04..e19036cc982 100644
--- a/sql/item_geofunc.h
+++ b/sql/item_geofunc.h
@@ -263,7 +263,7 @@ class Item_func_x: public Item_real_func
String value;
public:
Item_func_x(Item *a): Item_real_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "x"; }
};
@@ -273,7 +273,7 @@ class Item_func_y: public Item_real_func
String value;
public:
Item_func_y(Item *a): Item_real_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "y"; }
};
@@ -316,7 +316,7 @@ class Item_func_area: public Item_real_func
String value;
public:
Item_func_area(Item *a): Item_real_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "area"; }
};
@@ -326,7 +326,7 @@ class Item_func_glength: public Item_real_func
String value;
public:
Item_func_glength(Item *a): Item_real_func(a) {}
- double val();
+ double val_real();
const char *func_name() const { return "glength"; }
};
diff --git a/sql/item_row.cc b/sql/item_row.cc
index 8a020861fef..0c7eae9d920 100644
--- a/sql/item_row.cc
+++ b/sql/item_row.cc
@@ -62,7 +62,7 @@ bool Item_row::fix_fields(THD *thd, TABLE_LIST *tabl, Item **ref)
for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
{
if ((*arg)->fix_fields(thd, tabl, arg))
- return 1;
+ return TRUE;
// we can't assign 'item' before, because fix_fields() can change arg
Item *item= *arg;
used_tables_cache |= item->used_tables();
@@ -81,7 +81,7 @@ bool Item_row::fix_fields(THD *thd, TABLE_LIST *tabl, Item **ref)
with_sum_func= with_sum_func || item->with_sum_func;
}
fixed= 1;
- return 0;
+ return FALSE;
}
void Item_row::split_sum_func(THD *thd, Item **ref_pointer_array,
diff --git a/sql/item_row.h b/sql/item_row.h
index ef5856dcdd3..64bd5cbbb44 100644
--- a/sql/item_row.h
+++ b/sql/item_row.h
@@ -41,7 +41,7 @@ public:
{
illegal_method_call((const char*)"make_field");
};
- double val()
+ double val_real()
{
illegal_method_call((const char*)"val");
return 0;
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 889b00eb6a0..bf172e1744d 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -42,10 +42,10 @@ String my_empty_string("",default_charset_info);
static void my_coll_agg_error(DTCollation &c1, DTCollation &c2,
const char *fname)
{
- my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
- c1.collation->name,c1.derivation_name(),
- c2.collation->name,c2.derivation_name(),
- fname);
+ my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0),
+ c1.collation->name, c1.derivation_name(),
+ c2.collation->name, c2.derivation_name(),
+ fname);
}
uint nr_of_decimals(const char *str)
@@ -59,7 +59,7 @@ uint nr_of_decimals(const char *str)
return 0;
}
-double Item_str_func::val()
+double Item_str_func::val_real()
{
DBUG_ASSERT(fixed == 1);
int err;
@@ -1629,7 +1629,7 @@ Item_func_format::Item_func_format(Item *org,int dec) :Item_str_func(org)
String *Item_func_format::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- double nr =args[0]->val();
+ double nr= args[0]->val_real();
uint32 diff,length,str_length;
uint dec;
if ((null_value=args[0]->null_value))
@@ -1697,14 +1697,14 @@ void Item_func_elt::fix_length_and_dec()
}
-double Item_func_elt::val()
+double Item_func_elt::val_real()
{
DBUG_ASSERT(fixed == 1);
uint tmp;
null_value=1;
if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
return 0.0;
- double result= args[tmp]->val();
+ double result= args[tmp]->val_real();
null_value= args[tmp]->null_value;
return result;
}
@@ -2226,8 +2226,8 @@ void Item_func_set_collation::fix_length_and_dec()
if (!set_collation ||
!my_charset_same(args[0]->collation.collation,set_collation))
{
- my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
- colname,args[0]->collation.collation->csname);
+ my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
+ colname, args[0]->collation.collation->csname);
return;
}
collation.set(set_collation, DERIVATION_EXPLICIT);
@@ -2574,9 +2574,12 @@ String* Item_func_inet_ntoa::val_str(String* str)
This function is very useful when you want to generate SQL statements
- RETURN VALUES
+ NOTE
+ QUOTE(NULL) returns the string 'NULL' (4 letters, without quotes).
+
+ RETURN VALUES
str Quoted string
- NULL Argument to QUOTE() was NULL or out of memory.
+ NULL Out of memory.
*/
#define get_esc_bit(mask, num) (1 & (*((mask) + ((num) >> 3))) >> ((num) & 7))
@@ -2601,7 +2604,12 @@ String *Item_func_quote::val_str(String *str)
String *arg= args[0]->val_str(str);
uint arg_length, new_length;
if (!arg) // Null argument
- goto null;
+ {
+ str->copy("NULL", 4, collation.collation); // Return the string 'NULL'
+ null_value= 0;
+ return str;
+ }
+
arg_length= arg->length();
new_length= arg_length+2; /* for beginning and ending ' signs */
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index afc4b9da0a1..647cf022d79 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -32,7 +32,7 @@ public:
Item_str_func(Item *a,Item *b,Item *c,Item *d, Item* e) :Item_func(a,b,c,d,e) {decimals=NOT_FIXED_DEC; }
Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; }
longlong val_int();
- double val();
+ double val_real();
enum Item_result result_type () const { return STRING_RESULT; }
void left_right_max_length();
};
@@ -377,7 +377,7 @@ class Item_func_elt :public Item_str_func
{
public:
Item_func_elt(List<Item> &list) :Item_str_func(list) {}
- double val();
+ double val_real();
longlong val_int();
String *val_str(String *str);
void fix_length_and_dec();
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index f426f14a25f..f8c5c0aac90 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -66,7 +66,7 @@ void Item_subselect::init(st_select_lex *select_lex,
parsing_place= unit->item->parsing_place;
unit->item->engine= 0;
unit->item= this;
- engine->change_item(this, result);
+ engine->change_result(this, result);
}
else
{
@@ -133,13 +133,13 @@ Item_subselect::select_transformer(JOIN *join)
bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
{
char const *save_where= thd_param->where;
- int res;
+ bool res;
DBUG_ASSERT(fixed == 0);
engine->set_thd((thd= thd_param));
if (check_stack_overrun(thd, (gptr)&res))
- return 1;
+ return TRUE;
res= engine->prepare();
@@ -171,7 +171,7 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
if (engine->cols() > max_columns)
{
my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
- return 1;
+ return TRUE;
}
fix_length_and_dec();
}
@@ -441,13 +441,13 @@ void Item_singlerow_subselect::bring_value()
exec();
}
-double Item_singlerow_subselect::val()
+double Item_singlerow_subselect::val_real()
{
DBUG_ASSERT(fixed == 1);
if (!exec() && !value->null_value)
{
null_value= 0;
- return value->val();
+ return value->val_real();
}
else
{
@@ -565,7 +565,7 @@ void Item_exists_subselect::fix_length_and_dec()
max_columns= engine->cols();
}
-double Item_exists_subselect::val()
+double Item_exists_subselect::val_real()
{
DBUG_ASSERT(fixed == 1);
if (exec())
@@ -599,7 +599,7 @@ String *Item_exists_subselect::val_str(String *str)
return str;
}
-double Item_in_subselect::val()
+double Item_in_subselect::val_real()
{
DBUG_ASSERT(fixed == 1);
if (exec())
@@ -1504,12 +1504,12 @@ void subselect_indexsubquery_engine::print(String *str)
res new select_result object
RETURN
- 0 OK
- -1 error
+ FALSE OK
+ TRUE error
*/
-int subselect_single_select_engine::change_item(Item_subselect *si,
- select_subselect *res)
+bool subselect_single_select_engine::change_result(Item_subselect *si,
+ select_subselect *res)
{
item= si;
result= res;
@@ -1526,12 +1526,12 @@ int subselect_single_select_engine::change_item(Item_subselect *si,
res new select_result object
RETURN
- 0 OK
- -1 error
+ FALSE OK
+ TRUE error
*/
-int subselect_union_engine::change_item(Item_subselect *si,
- select_subselect *res)
+bool subselect_union_engine::change_result(Item_subselect *si,
+ select_subselect *res)
{
item= si;
int rc= unit->change_result(res, result);
@@ -1549,14 +1549,15 @@ int subselect_union_engine::change_item(Item_subselect *si,
res new select_result object
RETURN
- -1 error
+ FALSE OK
+ TRUE error
*/
-int subselect_uniquesubquery_engine::change_item(Item_subselect *si,
- select_subselect *res)
+bool subselect_uniquesubquery_engine::change_result(Item_subselect *si,
+ select_subselect *res)
{
DBUG_ASSERT(0);
- return -1;
+ return TRUE;
}
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 6efb9052115..d0ff3654e48 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -134,7 +134,7 @@ public:
void reset();
trans_res select_transformer(JOIN *join);
void store(uint i, Item* item);
- double val();
+ double val_real();
longlong val_int ();
String *val_str (String *);
enum Item_result result_type() const;
@@ -179,7 +179,7 @@ public:
enum Item_result result_type() const { return INT_RESULT;}
longlong val_int();
- double val();
+ double val_real();
String *val_str(String*);
void fix_length_and_dec();
void print(String *str);
@@ -224,7 +224,7 @@ public:
Comp_creator *func);
trans_res row_value_transformer(JOIN * join);
longlong val_int();
- double val();
+ double val_real();
String *val_str(String*);
void top_level_item() { abort_on_null=1; }
bool test_limit(st_select_lex_unit *unit);
@@ -290,7 +290,7 @@ public:
virtual table_map upper_select_const_tables()= 0;
static table_map calc_const_tables(TABLE_LIST *);
virtual void print(String *str)= 0;
- virtual int change_item(Item_subselect *si, select_subselect *result)= 0;
+ virtual bool change_result(Item_subselect *si, select_subselect *result)= 0;
virtual bool no_tables()= 0;
};
@@ -315,7 +315,7 @@ public:
void exclude();
table_map upper_select_const_tables();
void print (String *str);
- int change_item(Item_subselect *si, select_subselect *result);
+ bool change_result(Item_subselect *si, select_subselect *result);
bool no_tables();
};
@@ -336,7 +336,7 @@ public:
void exclude();
table_map upper_select_const_tables();
void print (String *str);
- int change_item(Item_subselect *si, select_subselect *result);
+ bool change_result(Item_subselect *si, select_subselect *result);
bool no_tables();
};
@@ -366,7 +366,7 @@ public:
void exclude();
table_map upper_select_const_tables() { return 0; }
void print (String *str);
- int change_item(Item_subselect *si, select_subselect *result);
+ bool change_result(Item_subselect *si, select_subselect *result);
bool no_tables();
};
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 72c85e2dd40..cd98a3cc309 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -143,7 +143,7 @@ String *
Item_sum_num::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- double nr=val();
+ double nr= val_real();
if (null_value)
return 0;
str->set(nr,decimals, &my_charset_bin);
@@ -173,8 +173,9 @@ Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if (!thd->allow_sum_func)
{
- my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0));
- return 1;
+ my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE),
+ MYF(0));
+ return TRUE;
}
thd->allow_sum_func=0; // No included group funcs
decimals=0;
@@ -182,7 +183,7 @@ Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
for (uint i=0 ; i < arg_count ; i++)
{
if (args[i]->fix_fields(thd, tables, args + i) || args[i]->check_cols(1))
- return 1;
+ return TRUE;
if (decimals < args[i]->decimals)
decimals=args[i]->decimals;
maybe_null |= args[i]->maybe_null;
@@ -193,7 +194,7 @@ Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
fix_length_and_dec();
thd->allow_sum_func=1; // Allow group functions
fixed= 1;
- return 0;
+ return FALSE;
}
@@ -205,8 +206,9 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
Item *item= args[0];
if (!thd->allow_sum_func)
{
- my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0));
- return 1;
+ my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE),
+ MYF(0));
+ return TRUE;
}
thd->allow_sum_func=0; // No included group funcs
@@ -214,7 +216,7 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if (!item->fixed &&
item->fix_fields(thd, tables, args) ||
(item= args[0])->check_cols(1))
- return 1;
+ return TRUE;
hybrid_type= item->result_type();
if (hybrid_type == INT_RESULT)
@@ -245,7 +247,7 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
else
hybrid_field_type= Item::field_type();
fixed= 1;
- return 0;
+ return FALSE;
}
@@ -267,14 +269,14 @@ void Item_sum_sum::clear()
bool Item_sum_sum::add()
{
- sum+=args[0]->val();
+ sum+= args[0]->val_real();
if (!args[0]->null_value)
null_value= 0;
return 0;
}
-double Item_sum_sum::val()
+double Item_sum_sum::val_real()
{
DBUG_ASSERT(fixed == 1);
return sum;
@@ -359,8 +361,8 @@ void Item_sum_sum_distinct::clear()
bool Item_sum_sum_distinct::add()
{
- /* args[0]->val() may reset args[0]->null_value */
- double val= args[0]->val();
+ /* args[0]->val_real() may reset args[0]->null_value */
+ double val= args[0]->val_real();
if (!args[0]->null_value)
{
DBUG_ASSERT(tree);
@@ -383,7 +385,7 @@ static int sum_sum_distinct(void *element, element_count num_of_dups,
C_MODE_END
-double Item_sum_sum_distinct::val()
+double Item_sum_sum_distinct::val_real()
{
/*
We don't have a tree only if 'setup()' hasn't been called;
@@ -456,7 +458,7 @@ void Item_sum_avg::clear()
bool Item_sum_avg::add()
{
- double nr=args[0]->val();
+ double nr= args[0]->val_real();
if (!args[0]->null_value)
{
sum+=nr;
@@ -465,7 +467,7 @@ bool Item_sum_avg::add()
return 0;
}
-double Item_sum_avg::val()
+double Item_sum_avg::val_real()
{
DBUG_ASSERT(fixed == 1);
if (!count)
@@ -482,10 +484,10 @@ double Item_sum_avg::val()
Standard deviation
*/
-double Item_sum_std::val()
+double Item_sum_std::val_real()
{
DBUG_ASSERT(fixed == 1);
- double tmp= Item_sum_variance::val();
+ double tmp= Item_sum_variance::val_real();
return tmp <= 0.0 ? 0.0 : sqrt(tmp);
}
@@ -513,7 +515,7 @@ void Item_sum_variance::clear()
bool Item_sum_variance::add()
{
- double nr=args[0]->val();
+ double nr= args[0]->val_real();
if (!args[0]->null_value)
{
sum+=nr;
@@ -523,7 +525,7 @@ bool Item_sum_variance::add()
return 0;
}
-double Item_sum_variance::val()
+double Item_sum_variance::val_real()
{
DBUG_ASSERT(fixed == 1);
if (!count)
@@ -540,7 +542,7 @@ double Item_sum_variance::val()
void Item_sum_variance::reset_field()
{
- double nr=args[0]->val();
+ double nr= args[0]->val_real();
char *res=result_field->ptr;
if (args[0]->null_value)
@@ -565,7 +567,7 @@ void Item_sum_variance::update_field()
float8get(old_sqr, res+sizeof(double));
field_count=sint8korr(res+sizeof(double)*2);
- nr=args[0]->val();
+ nr= args[0]->val_real();
if (!args[0]->null_value)
{
old_nr+=nr;
@@ -587,7 +589,7 @@ void Item_sum_hybrid::clear()
null_value= 1;
}
-double Item_sum_hybrid::val()
+double Item_sum_hybrid::val_real()
{
DBUG_ASSERT(fixed == 1);
int err;
@@ -620,7 +622,7 @@ longlong Item_sum_hybrid::val_int()
return 0;
if (hybrid_type == INT_RESULT)
return sum_int;
- return (longlong) Item_sum_hybrid::val();
+ return (longlong) Item_sum_hybrid::val_real();
}
@@ -696,7 +698,7 @@ bool Item_sum_min::add()
break;
case REAL_RESULT:
{
- double nr=args[0]->val();
+ double nr= args[0]->val_real();
if (!args[0]->null_value && (null_value || nr < sum))
{
sum=nr;
@@ -749,7 +751,7 @@ bool Item_sum_max::add()
break;
case REAL_RESULT:
{
- double nr=args[0]->val();
+ double nr= args[0]->val_real();
if (!args[0]->null_value && (null_value || nr > sum))
{
sum=nr;
@@ -829,7 +831,7 @@ bool Item_sum_and::add()
void Item_sum_num::reset_field()
{
- double nr=args[0]->val();
+ double nr= args[0]->val_real();
char *res=result_field->ptr;
if (maybe_null)
@@ -883,7 +885,7 @@ void Item_sum_hybrid::reset_field()
}
else // REAL_RESULT
{
- double nr=args[0]->val();
+ double nr= args[0]->val_real();
if (maybe_null)
{
@@ -902,7 +904,7 @@ void Item_sum_hybrid::reset_field()
void Item_sum_sum::reset_field()
{
- double nr=args[0]->val(); // Nulls also return 0
+ double nr= args[0]->val_real(); // Nulls also return 0
float8store(result_field->ptr,nr);
if (args[0]->null_value)
result_field->set_null();
@@ -930,7 +932,7 @@ void Item_sum_count::reset_field()
void Item_sum_avg::reset_field()
{
- double nr=args[0]->val();
+ double nr= args[0]->val_real();
char *res=result_field->ptr;
if (args[0]->null_value)
@@ -968,7 +970,7 @@ void Item_sum_sum::update_field()
char *res=result_field->ptr;
float8get(old_nr,res);
- nr=args[0]->val();
+ nr= args[0]->val_real();
if (!args[0]->null_value)
{
old_nr+=nr;
@@ -1005,7 +1007,7 @@ void Item_sum_avg::update_field()
float8get(old_nr,res);
field_count=sint8korr(res+sizeof(double));
- nr=args[0]->val();
+ nr= args[0]->val_real();
if (!args[0]->null_value)
{
old_nr+=nr;
@@ -1051,7 +1053,7 @@ Item_sum_hybrid::min_max_update_real_field()
double nr,old_nr;
old_nr=result_field->val_real();
- nr=args[0]->val();
+ nr= args[0]->val_real();
if (!args[0]->null_value)
{
if (result_field->is_null(0) ||
@@ -1103,7 +1105,7 @@ Item_avg_field::Item_avg_field(Item_sum_avg *item)
}
-double Item_avg_field::val()
+double Item_avg_field::val_real()
{
// fix_fields() never calls for this Item
double nr;
@@ -1124,7 +1126,7 @@ double Item_avg_field::val()
String *Item_avg_field::val_str(String *str)
{
// fix_fields() never calls for this Item
- double nr=Item_avg_field::val();
+ double nr= Item_avg_field::val_real();
if (null_value)
return 0;
str->set(nr,decimals, &my_charset_bin);
@@ -1136,10 +1138,10 @@ Item_std_field::Item_std_field(Item_sum_std *item)
{
}
-double Item_std_field::val()
+double Item_std_field::val_real()
{
// fix_fields() never calls for this Item
- double tmp= Item_variance_field::val();
+ double tmp= Item_variance_field::val_real();
return tmp <= 0.0 ? 0.0 : sqrt(tmp);
}
@@ -1152,7 +1154,7 @@ Item_variance_field::Item_variance_field(Item_sum_variance *item)
maybe_null=1;
}
-double Item_variance_field::val()
+double Item_variance_field::val_real()
{
// fix_fields() never calls for this Item
double sum,sum_sqr;
@@ -1175,7 +1177,7 @@ double Item_variance_field::val()
String *Item_variance_field::val_str(String *str)
{
// fix_fields() never calls for this Item
- double nr=val();
+ double nr= val_real();
if (null_value)
return 0;
str->set(nr,decimals, &my_charset_bin);
@@ -1553,7 +1555,7 @@ Item *Item_sum_udf_float::copy_or_same(THD* thd)
return new (thd->mem_root) Item_sum_udf_float(thd, this);
}
-double Item_sum_udf_float::val()
+double Item_sum_udf_float::val_real()
{
DBUG_ASSERT(fixed == 1);
DBUG_ENTER("Item_sum_udf_float::val");
@@ -1565,7 +1567,7 @@ double Item_sum_udf_float::val()
String *Item_sum_udf_float::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- double nr=val();
+ double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals, &my_charset_bin);
@@ -2004,8 +2006,9 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if (!thd->allow_sum_func)
{
- my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0));
- return 1;
+ my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE),
+ MYF(0));
+ return TRUE;
}
thd->allow_sum_func= 0;
@@ -2019,7 +2022,7 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
for (i=0 ; i < arg_count ; i++)
{
if (args[i]->fix_fields(thd, tables, args + i) || args[i]->check_cols(1))
- return 1;
+ return TRUE;
if (i < arg_count_field)
maybe_null|= args[i]->maybe_null;
}
@@ -2029,12 +2032,12 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
max_length= group_concat_max_len;
thd->allow_sum_func= 1;
if (!(tmp_table_param= new TMP_TABLE_PARAM))
- return 1;
+ return TRUE;
/* We'll convert all blobs to varchar fields in the temporary table */
tmp_table_param->convert_blob_length= group_concat_max_len;
tables_list= tables;
fixed= 1;
- return 0;
+ return FALSE;
}
diff --git a/sql/item_sum.h b/sql/item_sum.h
index cede5a1e02e..85651c80288 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -107,7 +107,10 @@ public:
Item_sum_num(THD *thd, Item_sum_num *item) :Item_sum(thd, item) {}
bool fix_fields(THD *, TABLE_LIST *, Item **);
longlong val_int()
- { DBUG_ASSERT(fixed == 1); return (longlong) val(); } /* Real as default */
+ {
+ DBUG_ASSERT(fixed == 1);
+ return (longlong) val_real(); /* Real as default */
+ }
String *val_str(String*str);
void reset_field();
};
@@ -119,7 +122,7 @@ public:
Item_sum_int(Item *item_par) :Item_sum_num(item_par) {}
Item_sum_int(List<Item> &list) :Item_sum_num(list) {}
Item_sum_int(THD *thd, Item_sum_int *item) :Item_sum_num(thd, item) {}
- double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
String *val_str(String*str);
enum Item_result result_type () const { return INT_RESULT; }
void fix_length_and_dec()
@@ -139,7 +142,7 @@ class Item_sum_sum :public Item_sum_num
enum Sumfunctype sum_func () const {return SUM_FUNC;}
void clear();
bool add();
- double val();
+ double val_real();
void reset_field();
void update_field();
void no_rows_in_result() {}
@@ -169,7 +172,7 @@ public:
bool setup(THD *thd);
void clear();
bool add();
- double val();
+ double val_real();
inline void add(double val) { sum+= val; }
enum Sumfunctype sum_func () const { return SUM_DISTINCT_FUNC; }
@@ -302,8 +305,9 @@ public:
Field *field;
Item_avg_field(Item_sum_avg *item);
enum Type type() const { return FIELD_AVG_ITEM; }
- double val();
- longlong val_int() { /* can't be fix_fields()ed */ return (longlong) val(); }
+ double val_real();
+ longlong val_int()
+ { /* can't be fix_fields()ed */ return (longlong) val_real(); }
bool is_null() { (void) val_int(); return null_value; }
String *val_str(String*);
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
@@ -329,7 +333,7 @@ class Item_sum_avg :public Item_sum_num
enum Sumfunctype sum_func () const {return AVG_FUNC;}
void clear();
bool add();
- double val();
+ double val_real();
void reset_field();
void update_field();
Item *result_item(Field *field)
@@ -347,8 +351,9 @@ public:
Field *field;
Item_variance_field(Item_sum_variance *item);
enum Type type() const {return FIELD_VARIANCE_ITEM; }
- double val();
- longlong val_int() { /* can't be fix_fields()ed */ return (longlong) val(); }
+ double val_real();
+ longlong val_int()
+ { /* can't be fix_fields()ed */ return (longlong) val_real(); }
String *val_str(String*);
bool is_null() { (void) val_int(); return null_value; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
@@ -386,7 +391,7 @@ class Item_sum_variance : public Item_sum_num
enum Sumfunctype sum_func () const { return VARIANCE_FUNC; }
void clear();
bool add();
- double val();
+ double val_real();
void reset_field();
void update_field();
Item *result_item(Field *field)
@@ -403,7 +408,7 @@ class Item_std_field :public Item_variance_field
public:
Item_std_field(Item_sum_std *item);
enum Type type() const { return FIELD_STD_ITEM; }
- double val();
+ double val_real();
};
/*
@@ -418,7 +423,7 @@ class Item_sum_std :public Item_sum_variance
:Item_sum_variance(thd, item)
{}
enum Sumfunctype sum_func () const { return STD_FUNC; }
- double val();
+ double val_real();
Item *result_item(Field *field)
{ return new Item_std_field(this); }
const char *func_name() const { return "std"; }
@@ -456,7 +461,7 @@ class Item_sum_hybrid :public Item_sum
bool const_item() const { return !used_table_cache; }
void clear();
- double val();
+ double val_real();
longlong val_int();
void reset_field();
String *val_str(String *);
@@ -594,8 +599,11 @@ class Item_sum_udf_float :public Item_udf_sum
Item_sum_udf_float(THD *thd, Item_sum_udf_float *item)
:Item_udf_sum(thd, item) {}
longlong val_int()
- { DBUG_ASSERT(fixed == 1); return (longlong) Item_sum_udf_float::val(); }
- double val();
+ {
+ DBUG_ASSERT(fixed == 1);
+ return (longlong) Item_sum_udf_float::val_real();
+ }
+ double val_real();
String *val_str(String*str);
void fix_length_and_dec() { fix_num_length_and_dec(); }
Item *copy_or_same(THD* thd);
@@ -611,7 +619,7 @@ public:
Item_sum_udf_int(THD *thd, Item_sum_udf_int *item)
:Item_udf_sum(thd, item) {}
longlong val_int();
- double val()
+ double val_real()
{ DBUG_ASSERT(fixed == 1); return (double) Item_sum_udf_int::val_int(); }
String *val_str(String*str);
enum Item_result result_type () const { return INT_RESULT; }
@@ -629,7 +637,7 @@ public:
Item_sum_udf_str(THD *thd, Item_sum_udf_str *item)
:Item_udf_sum(thd, item) {}
String *val_str(String *);
- double val()
+ double val_real()
{
int err;
String *res; res=val_str(&str_value);
@@ -657,7 +665,7 @@ class Item_sum_udf_float :public Item_sum_num
Item_sum_udf_float(THD *thd, Item_sum_udf_float *item)
:Item_sum_num(thd, item) {}
enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; }
- double val() { DBUG_ASSERT(fixed == 1); return 0.0; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; }
void clear() {}
bool add() { return 0; }
void update_field() {}
@@ -673,7 +681,7 @@ public:
:Item_sum_num(thd, item) {}
enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; }
longlong val_int() { DBUG_ASSERT(fixed == 1); return 0; }
- double val() { DBUG_ASSERT(fixed == 1); return 0; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return 0; }
void clear() {}
bool add() { return 0; }
void update_field() {}
@@ -689,7 +697,7 @@ public:
:Item_sum_num(thd, item) {}
String *val_str(String *)
{ DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
- double val() { DBUG_ASSERT(fixed == 1); null_value=1; return 0.0; }
+ double val_real() { DBUG_ASSERT(fixed == 1); null_value=1; return 0.0; }
longlong val_int() { DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
enum Item_result result_type () const { return STRING_RESULT; }
void fix_length_and_dec() { maybe_null=1; max_length=0; }
@@ -761,7 +769,7 @@ class Item_func_group_concat : public Item_sum
bool setup(THD *thd);
void make_unique();
virtual void update_field() {}
- double val()
+ double val_real()
{
String *res; res=val_str(&str_value);
return res ? my_atof(res->c_ptr()) : 0.0;
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 566cacca487..d1b490008df 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -161,21 +161,24 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
{
int weekday= 0, yearday= 0, daypart= 0;
int week_number= -1;
- CHARSET_INFO *cs= &my_charset_bin;
int error= 0;
- bool usa_time= 0;
- bool sunday_first_n_first_week_non_iso= -2;
- bool strict_week_number;
int strict_week_number_year= -1;
- bool strict_week_number_year_type= -1;
int frac_part;
+ bool usa_time= 0;
+ bool sunday_first_n_first_week_non_iso;
+ bool strict_week_number;
+ bool strict_week_number_year_type;
const char *val_begin= val;
const char *val_end= val + length;
const char *ptr= format->format.str;
const char *end= ptr + format->format.length;
+ CHARSET_INFO *cs= &my_charset_bin;
DBUG_ENTER("extract_date_time");
LINT_INIT(strict_week_number);
+ /* Remove valgrind varnings when using gcc 3.3 and -O1 */
+ PURIFY_OR_LINT_INIT(strict_week_number_year_type);
+ PURIFY_OR_LINT_INIT(sunday_first_n_first_week_non_iso);
if (!sub_pattern_end)
bzero((char*) l_time, sizeof(*l_time));
@@ -1666,7 +1669,7 @@ Item_func_convert_tz::fix_fields(THD *thd_arg, TABLE_LIST *tables_arg, Item **re
{
String str;
if (Item_date_func::fix_fields(thd_arg, tables_arg, ref))
- return 1;
+ return TRUE;
tz_tables= thd_arg->lex->time_zone_tables_used;
@@ -1676,7 +1679,7 @@ Item_func_convert_tz::fix_fields(THD *thd_arg, TABLE_LIST *tables_arg, Item **re
if (args[2]->const_item())
to_tz= my_tz_find(args[2]->val_str(&str), tz_tables);
- return 0;
+ return FALSE;
}
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 694f2dc583c..dccba7f52b1 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -88,7 +88,7 @@ class Item_func_month :public Item_func
public:
Item_func_month(Item *a) :Item_func(a) {}
longlong val_int();
- double val()
+ double val_real()
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
String *val_str(String *str)
{
@@ -250,7 +250,7 @@ public:
Item_func_weekday(Item *a,bool type_arg)
:Item_func(a), odbc_type(type_arg) {}
longlong val_int();
- double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
String *val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
@@ -326,7 +326,7 @@ public:
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
String *val_str(String *str);
longlong val_int();
- double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
const char *func_name() const { return "date"; }
void fix_length_and_dec()
{
@@ -369,7 +369,7 @@ public:
Item_func_curtime(Item *a) :Item_func(a) {}
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
- double val() { DBUG_ASSERT(fixed == 1); return (double) value; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
String *val_str(String *str);
void fix_length_and_dec();
@@ -452,7 +452,7 @@ public:
Item_func_now() :Item_date_func() {}
Item_func_now(Item *a) :Item_date_func(a) {}
enum Item_result result_type () const { return STRING_RESULT; }
- double val() { DBUG_ASSERT(fixed == 1); return (double) value; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
int save_in_field(Field *to, bool no_conversions);
String *val_str(String *str);
@@ -512,7 +512,7 @@ class Item_func_from_unixtime :public Item_date_func
THD *thd;
public:
Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
- double val()
+ double val_real()
{
DBUG_ASSERT(fixed == 1);
return (double) Item_func_from_unixtime::val_int();
@@ -552,7 +552,7 @@ class Item_func_convert_tz :public Item_date_func
Item_func_convert_tz(Item *a, Item *b, Item *c):
Item_date_func(a, b, c) {}
longlong val_int();
- double val() { return (double) val_int(); }
+ double val_real() { return (double) val_int(); }
String *val_str(String *str);
const char *func_name() const { return "convert_tz"; }
bool fix_fields(THD *, struct st_table_list *, Item **);
@@ -565,7 +565,7 @@ class Item_func_sec_to_time :public Item_str_func
{
public:
Item_func_sec_to_time(Item *item) :Item_str_func(item) {}
- double val()
+ double val_real()
{
DBUG_ASSERT(fixed == 1);
return (double) Item_func_sec_to_time::val_int();
@@ -615,7 +615,7 @@ public:
const char *func_name() const { return "date_add_interval"; }
void fix_length_and_dec();
enum_field_types field_type() const { return cached_field_type; }
- double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
+ double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
longlong val_int();
bool get_date(TIME *res, uint fuzzy_date);
void print(String *str);
diff --git a/sql/item_uniq.h b/sql/item_uniq.h
index 5582537bdbb..e74c09ca3c4 100644
--- a/sql/item_uniq.h
+++ b/sql/item_uniq.h
@@ -27,7 +27,7 @@ class Item_func_unique_users :public Item_real_func
public:
Item_func_unique_users(Item *name_arg,int start,int end,List<Item> &list)
:Item_real_func(list) {}
- double val() { DBUG_ASSERT(fixed == 1); return 0.0; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; }
void fix_length_and_dec() { decimals=0; max_length=6; }
void print(String *str) { str->append("0.0", 3); }
};
@@ -40,7 +40,7 @@ public:
:Item_sum_num(item_arg) {}
Item_sum_unique_users(THD *thd, Item_sum_unique_users *item)
:Item_sum_num(thd, item) {}
- double val() { DBUG_ASSERT(fixed == 1); return 0.0; }
+ double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; }
enum Sumfunctype sum_func () const {return UNIQUE_USERS_FUNC;}
void clear() {}
bool add() { return 0; }
@@ -50,7 +50,7 @@ public:
{
DBUG_ASSERT(fixed == 0);
fixed= 1;
- return 0;
+ return FALSE;
}
Item *copy_or_same(THD* thd)
{
diff --git a/sql/lex.h b/sql/lex.h
index 89daf46218c..db31b3af994 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -120,6 +120,7 @@ static SYMBOL symbols[] = {
{ "CONCURRENT", SYM(CONCURRENT)},
{ "CONDITION", SYM(CONDITION_SYM)},
{ "CONNECTION", SYM(CONNECTION_SYM)},
+ { "CONSISTENT", SYM(CONSISTENT_SYM)},
{ "CONSTRAINT", SYM(CONSTRAINT)},
{ "CONTAINS", SYM(CONTAINS_SYM)},
{ "CONTINUE", SYM(CONTINUE_SYM)},
@@ -421,6 +422,7 @@ static SYMBOL symbols[] = {
{ "SIGNED", SYM(SIGNED_SYM)},
{ "SIMPLE", SYM(SIMPLE_SYM)},
{ "SLAVE", SYM(SLAVE)},
+ { "SNAPSHOT", SYM(SNAPSHOT_SYM)},
{ "SMALLINT", SYM(SMALLINT)},
{ "SOME", SYM(ANY_SYM)},
{ "SONAME", SYM(UDF_SONAME_SYM)},
diff --git a/sql/lock.cc b/sql/lock.cc
index 6d5ca5bf6b4..c4f1d681b76 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -430,7 +430,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
*write_lock_used=table;
if (table->db_stat & HA_READ_ONLY)
{
- my_error(ER_OPEN_AS_READONLY,MYF(0),table->table_name);
+ my_error(ER_OPEN_AS_READONLY, MYF(0), table->table_name);
my_free((gptr) sql_lock,MYF(0));
return 0;
}
@@ -795,7 +795,8 @@ bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
if (thd->global_read_lock) // This thread had the read locks
{
if (is_not_commit)
- my_error(ER_CANT_UPDATE_WITH_READLOCK,MYF(0));
+ my_message(ER_CANT_UPDATE_WITH_READLOCK,
+ ER(ER_CANT_UPDATE_WITH_READLOCK), MYF(0));
(void) pthread_mutex_unlock(&LOCK_open);
/*
We allow FLUSHer to COMMIT; we assume FLUSHer knows what it does.
diff --git a/sql/log.cc b/sql/log.cc
index ef538c3b03f..75a1743febc 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1464,7 +1464,8 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u",
if (flush_io_cache(file) || sync_binlog(file))
goto err;
- if (opt_using_transactions && !my_b_tell(&thd->transaction.trans_log))
+ if (opt_using_transactions &&
+ !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
{
/*
LOAD DATA INFILE in AUTOCOMMIT=1 mode writes to the binlog
@@ -1515,7 +1516,7 @@ err:
if (error)
{
if (my_errno == EFBIG)
- my_error(ER_TRANS_CACHE_FULL, MYF(0));
+ my_message(ER_TRANS_CACHE_FULL, ER(ER_TRANS_CACHE_FULL), MYF(0));
else
my_error(ER_ERROR_ON_WRITE, MYF(0), name, errno);
write_error=1;
@@ -1612,6 +1613,14 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback)
{
Query_log_event qinfo(thd, "BEGIN", 5, TRUE);
/*
+ Imagine this is rollback due to net timeout, after all statements of
+ the transaction succeeded. Then we want a zero-error code in BEGIN.
+ In other words, if there was a really serious error code it's already
+ in the statement's events.
+ This is safer than thd->clear_error() against kills at shutdown.
+ */
+ qinfo.error_code= 0;
+ /*
Now this Query_log_event has artificial log_pos 0. It must be adjusted
to reflect the real position in the log. Not doing it would confuse the
slave: it would prevent this one from knowing where he is in the
@@ -1643,6 +1652,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback)
commit_or_rollback ? "COMMIT" : "ROLLBACK",
commit_or_rollback ? 6 : 8,
TRUE);
+ qinfo.error_code= 0;
if (qinfo.write(&log_file) || flush_io_cache(&log_file) ||
sync_binlog(&log_file))
goto err;
@@ -1714,12 +1724,19 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length,
time_t current_time;
if (!is_open())
return 0;
+ DBUG_ENTER("MYSQL_LOG::write");
+
VOID(pthread_mutex_lock(&LOCK_log));
if (is_open())
{ // Safety agains reopen
int tmp_errno=0;
char buff[80],*end;
end=buff;
+ if (!(thd->options & OPTION_UPDATE_LOG))
+ {
+ VOID(pthread_mutex_unlock(&LOCK_log));
+ DBUG_RETURN(0);
+ }
if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT) || query_start_arg)
{
current_time=time(NULL);
@@ -1818,7 +1835,7 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length,
}
}
VOID(pthread_mutex_unlock(&LOCK_log));
- return error;
+ DBUG_RETURN(error);
}
@@ -1838,16 +1855,19 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length,
THD::enter_cond() (see NOTES in sql_class.h).
*/
-void MYSQL_LOG:: wait_for_update(THD* thd, bool master_or_slave)
+void MYSQL_LOG::wait_for_update(THD* thd, bool master_or_slave)
{
- const char* old_msg = thd->enter_cond(&update_cond, &LOCK_log,
- master_or_slave ?
- "Has read all relay log; waiting for \
-the slave I/O thread to update it" :
- "Has sent all binlog to slave; \
-waiting for binlog to be updated");
+ const char *old_msg;
+ DBUG_ENTER("wait_for_update");
+ old_msg= thd->enter_cond(&update_cond, &LOCK_log,
+ master_or_slave ?
+ "Has read all relay log; waiting for the slave I/O "
+ "thread to update it" :
+ "Has sent all binlog to slave; waiting for binlog "
+ "to be updated");
pthread_cond_wait(&update_cond, &LOCK_log);
thd->exit_cond(old_msg);
+ DBUG_VOID_RETURN;
}
@@ -2204,6 +2224,15 @@ void MYSQL_LOG::report_pos_in_innodb()
DBUG_VOID_RETURN;
}
+
+void MYSQL_LOG::signal_update()
+{
+ DBUG_ENTER("MYSQL_LOG::signal_update");
+ pthread_cond_broadcast(&update_cond);
+ DBUG_VOID_RETURN;
+}
+
+
#ifdef __NT__
void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
uint length, int buffLen)
diff --git a/sql/log_event.cc b/sql/log_event.cc
index c7f6f25e74a..ccc563d31ac 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -1362,7 +1362,8 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
Thank you.
*/
thd->catalog= (char*) catalog;
- thd->db= (char*) rewrite_db(db); // thd->db_length is set later if needed
+ thd->db_length= db_len;
+ thd->db= (char*) rewrite_db(db, &thd->db_length);
thd->variables.auto_increment_increment= auto_increment_increment;
thd->variables.auto_increment_offset= auto_increment_offset;
@@ -1384,11 +1385,6 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
if (db_ok(thd->db, replicate_do_db, replicate_ignore_db))
{
thd->set_time((time_t)when);
- /*
- We cannot use db_len from event to fill thd->db_length, because
- rewrite_db() may have changed db.
- */
- thd->db_length= thd->db ? strlen(thd->db) : 0;
thd->query_length= q_len;
thd->query = (char*)query;
VOID(pthread_mutex_lock(&LOCK_thread_count));
@@ -1466,10 +1462,10 @@ START SLAVE; . Query: '%s'", expected_error, thd->query);
Query caused different errors on master and slave. \
Error on master: '%s' (%d), Error on slave: '%s' (%d). \
Default database: '%s'. Query: '%s'",
- ER_SAFE(expected_error),
- expected_error,
- actual_error ? thd->net.last_error: "no error",
- actual_error,
+ ER_SAFE(expected_error),
+ expected_error,
+ actual_error ? thd->net.last_error: "no error",
+ actual_error,
print_slave_db_safe(db), query);
thd->query_error= 1;
}
@@ -1489,9 +1485,9 @@ Default database: '%s'. Query: '%s'",
{
slave_print_error(rli,actual_error,
"Error '%s' on query. Default database: '%s'. Query: '%s'",
- (actual_error ? thd->net.last_error :
- "unexpected success or fatal error"),
- print_slave_db_safe(db), query);
+ (actual_error ? thd->net.last_error :
+ "unexpected success or fatal error"),
+ print_slave_db_safe(thd->db), query);
thd->query_error= 1;
}
@@ -2435,7 +2431,8 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
bool use_rli_only_for_errors)
{
char *load_data_query= 0;
- thd->db= (char*) rewrite_db(db); // thd->db_length is set later if needed
+ thd->db_length= db_len;
+ thd->db= (char*) rewrite_db(db, &thd->db_length);
DBUG_ASSERT(thd->query == 0);
thd->query_length= 0; // Should not be needed
thd->query_error= 0;
@@ -2467,7 +2464,6 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
if (db_ok(thd->db, replicate_do_db, replicate_ignore_db))
{
thd->set_time((time_t)when);
- thd->db_length= thd->db ? strlen(thd->db) : 0;
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_id = query_id++;
VOID(pthread_mutex_unlock(&LOCK_thread_count));
@@ -2573,7 +2569,7 @@ Slave: load data infile on table '%s' at log position %s in log \
(char*) table_name,
llstr(log_pos,llbuff), RPL_LOG_NAME,
(ulong) thd->cuted_fields,
- print_slave_db_safe(db));
+ print_slave_db_safe(thd->db));
}
if (net)
net->pkt_nr= thd->net.pkt_nr;
@@ -2591,6 +2587,7 @@ Slave: load data infile on table '%s' at log position %s in log \
}
thd->net.vio = 0;
+ char *save_db= thd->db;
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->db= thd->catalog= 0;
thd->query= 0;
@@ -2601,7 +2598,7 @@ Slave: load data infile on table '%s' at log position %s in log \
my_afree(load_data_query);
if (thd->query_error)
{
- /* this err/sql_errno code is copy-paste from send_error() */
+ /* this err/sql_errno code is copy-paste from net_send_error() */
const char *err;
int sql_errno;
if ((err=thd->net.last_error)[0])
@@ -2613,7 +2610,7 @@ Slave: load data infile on table '%s' at log position %s in log \
}
slave_print_error(rli,sql_errno,"\
Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'",
- err, (char*)table_name, print_slave_db_safe(db));
+ err, (char*)table_name, print_slave_db_safe(save_db));
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
return 1;
}
@@ -2623,7 +2620,7 @@ Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'",
{
slave_print_error(rli,ER_UNKNOWN_ERROR, "\
Fatal error running LOAD DATA INFILE on table '%s'. Default database: '%s'",
- (char*)table_name, print_slave_db_safe(db));
+ (char*)table_name, print_slave_db_safe(save_db));
return 1;
}
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index b343beaa4e4..7a49799c7cd 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -247,6 +247,7 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
key checks in some cases */
#define OPTION_RELAXED_UNIQUE_CHECKS (1L << 27)
#define SELECT_NO_UNLOCK (1L << 28)
+#define OPTION_SCHEMA_TABLE (1L << 29)
/* The rest of the file is included in the server only */
#ifndef MYSQL_CLIENT
@@ -405,23 +406,24 @@ typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
void free_items(Item *item);
void cleanup_items(Item *item);
class THD;
-void close_thread_tables(THD *thd, bool locked=0, bool skip_derived=0);
+void close_thread_tables(THD *thd, bool locked=0, bool skip_derived=0,
+ TABLE *stopper= 0);
bool check_one_table_access(THD *thd, ulong privilege,
TABLE_LIST *tables);
bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table);
bool check_merge_table_access(THD *thd, char *db,
TABLE_LIST *table_list);
-int multi_update_precheck(THD *thd, TABLE_LIST *tables);
-int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count);
-int mysql_multi_update_prepare(THD *thd);
-int mysql_multi_delete_prepare(THD *thd);
-int mysql_insert_select_prepare(THD *thd);
-int insert_select_precheck(THD *thd, TABLE_LIST *tables);
-int update_precheck(THD *thd, TABLE_LIST *tables);
-int delete_precheck(THD *thd, TABLE_LIST *tables);
-int insert_precheck(THD *thd, TABLE_LIST *tables);
-int create_table_precheck(THD *thd, TABLE_LIST *tables,
- TABLE_LIST *create_table);
+bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
+bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count);
+bool mysql_multi_update_prepare(THD *thd);
+bool mysql_multi_delete_prepare(THD *thd);
+bool mysql_insert_select_prepare(THD *thd);
+bool insert_select_precheck(THD *thd, TABLE_LIST *tables);
+bool update_precheck(THD *thd, TABLE_LIST *tables);
+bool delete_precheck(THD *thd, TABLE_LIST *tables);
+bool insert_precheck(THD *thd, TABLE_LIST *tables);
+bool create_table_precheck(THD *thd, TABLE_LIST *tables,
+ TABLE_LIST *create_table);
Item *negate_expression(THD *thd, Item *expr);
#include "sql_class.h"
#include "opt_range.h"
@@ -471,12 +473,12 @@ struct Query_cache_query_flags
#define prepare_execute(A) ((A)->command == COM_EXECUTE)
-int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
-int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
-int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
+bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
+bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
+bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
-int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
- my_bool drop_temporary);
+bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
+ my_bool drop_temporary);
int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
bool drop_temporary, bool drop_view, bool log_query);
int mysql_rm_table_part2_with_lock(THD *thd, TABLE_LIST *tables,
@@ -504,7 +506,7 @@ extern "C" pthread_handler_decl(handle_one_connection,arg);
extern "C" pthread_handler_decl(handle_bootstrap,arg);
void end_thread(THD *thd,bool put_in_cache);
void flush_thread_cache();
-int mysql_execute_command(THD *thd);
+bool mysql_execute_command(THD *thd);
bool do_command(THD *thd);
bool dispatch_command(enum enum_server_command command, THD *thd,
char* packet, uint packet_length);
@@ -523,22 +525,22 @@ bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables,
bool no_errors);
bool check_global_access(THD *thd, ulong want_access);
-int mysql_backup_table(THD* thd, TABLE_LIST* table_list);
-int mysql_restore_table(THD* thd, TABLE_LIST* table_list);
-
-int mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
- HA_CHECK_OPT* check_opt);
-int mysql_check_table(THD* thd, TABLE_LIST* table_list,
- HA_CHECK_OPT* check_opt);
-int mysql_repair_table(THD* thd, TABLE_LIST* table_list,
- HA_CHECK_OPT* check_opt);
-int mysql_analyze_table(THD* thd, TABLE_LIST* table_list,
- HA_CHECK_OPT* check_opt);
-int mysql_optimize_table(THD* thd, TABLE_LIST* table_list,
- HA_CHECK_OPT* check_opt);
-int mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
- LEX_STRING *key_cache_name);
-int mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
+bool mysql_backup_table(THD* thd, TABLE_LIST* table_list);
+bool mysql_restore_table(THD* thd, TABLE_LIST* table_list);
+
+bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
+ HA_CHECK_OPT* check_opt);
+bool mysql_check_table(THD* thd, TABLE_LIST* table_list,
+ HA_CHECK_OPT* check_opt);
+bool mysql_repair_table(THD* thd, TABLE_LIST* table_list,
+ HA_CHECK_OPT* check_opt);
+bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list,
+ HA_CHECK_OPT* check_opt);
+bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list,
+ HA_CHECK_OPT* check_opt);
+bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
+ LEX_STRING *key_cache_name);
+bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
KEY_CACHE *dst_cache);
@@ -551,23 +553,23 @@ int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List<Item> &all_fields, ORDER *order,
bool *hidden_group_fields);
-int handle_select(THD *thd, LEX *lex, select_result *result);
-int mysql_select(THD *thd, Item ***rref_pointer_array,
- TABLE_LIST *tables, uint wild_num, List<Item> &list,
- COND *conds, uint og_num, ORDER *order, ORDER *group,
- Item *having, ORDER *proc_param, ulong select_type,
- select_result *result, SELECT_LEX_UNIT *unit,
- SELECT_LEX *select_lex);
+bool handle_select(THD *thd, LEX *lex, select_result *result);
+bool mysql_select(THD *thd, Item ***rref_pointer_array,
+ TABLE_LIST *tables, uint wild_num, List<Item> &list,
+ COND *conds, uint og_num, ORDER *order, ORDER *group,
+ Item *having, ORDER *proc_param, ulong select_type,
+ select_result *result, SELECT_LEX_UNIT *unit,
+ SELECT_LEX *select_lex);
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
-int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
- select_result *result);
+bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
+ select_result *result);
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
select_result *result);
-int mysql_union(THD *thd, LEX *lex, select_result *result,
- SELECT_LEX_UNIT *unit);
+bool mysql_union(THD *thd, LEX *lex, select_result *result,
+ SELECT_LEX_UNIT *unit);
int mysql_handle_derived(LEX *lex, int (*processor)(THD *thd,
- st_lex *lex,
- st_table_list *table));
+ LEX *lex,
+ TABLE_LIST *table));
int mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
int mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
@@ -578,61 +580,61 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
List<Key> &keys, uint &db_options,
handler *file, KEY *&key_info_buffer,
uint &key_count, int select_field_count);
-int mysql_create_table(THD *thd,const char *db, const char *table_name,
- HA_CREATE_INFO *create_info,
- List<create_field> &fields, List<Key> &keys,
- bool tmp_table, uint select_field_count);
+bool mysql_create_table(THD *thd,const char *db, const char *table_name,
+ HA_CREATE_INFO *create_info,
+ List<create_field> &fields, List<Key> &keys,
+ bool tmp_table, uint select_field_count);
TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
TABLE_LIST *create_table,
List<create_field> *extra_fields,
List<Key> *keys,
List<Item> *items,
- MYSQL_LOCK **lock);
-int mysql_alter_table(THD *thd, char *new_db, char *new_name,
- HA_CREATE_INFO *create_info,
- TABLE_LIST *table_list,
- List<create_field> &fields,
- List<Key> &keys,
- uint order_num, ORDER *order,
- enum enum_duplicates handle_duplicates,
- ALTER_INFO *alter_info, bool do_send_ok=1);
-int mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool do_send_ok);
-int mysql_create_like_table(THD *thd, TABLE_LIST *table,
- HA_CREATE_INFO *create_info,
- Table_ident *src_table);
+ MYSQL_LOCK **lock);
+bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
+ HA_CREATE_INFO *create_info,
+ TABLE_LIST *table_list,
+ List<create_field> &fields,
+ List<Key> &keys,
+ uint order_num, ORDER *order,
+ enum enum_duplicates handle_duplicates,
+ ALTER_INFO *alter_info, bool do_send_ok=1);
+bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool do_send_ok);
+bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
+ HA_CREATE_INFO *create_info,
+ Table_ident *src_table);
bool mysql_rename_table(enum db_type base,
const char *old_db,
const char * old_name,
const char *new_db,
const char * new_name);
-int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys);
-int mysql_drop_index(THD *thd, TABLE_LIST *table_list,
- ALTER_INFO *alter_info);
-int mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
- Item **conds, uint order_num, ORDER *order);
-int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
- List<Item> &values,COND *conds,
- uint order_num, ORDER *order, ha_rows limit,
- enum enum_duplicates handle_duplicates);
-int mysql_multi_update(THD *thd, TABLE_LIST *table_list,
- List<Item> *fields, List<Item> *values,
- COND *conds, ulong options,
- enum enum_duplicates handle_duplicates,
- SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
-int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
- List<Item> &fields, List_item *values,
- List<Item> &update_fields,
- List<Item> &update_values, enum_duplicates duplic);
-int mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
- List<List_item> &values, List<Item> &update_fields,
- List<Item> &update_values, enum_duplicates flag);
+bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys);
+bool mysql_drop_index(THD *thd, TABLE_LIST *table_list,
+ ALTER_INFO *alter_info);
+bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
+ Item **conds, uint order_num, ORDER *order);
+bool mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
+ List<Item> &values,COND *conds,
+ uint order_num, ORDER *order, ha_rows limit,
+ enum enum_duplicates handle_duplicates);
+bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
+ List<Item> *fields, List<Item> *values,
+ COND *conds, ulong options,
+ enum enum_duplicates handle_duplicates,
+ SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
+bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
+ List<Item> &fields, List_item *values,
+ List<Item> &update_fields,
+ List<Item> &update_values, enum_duplicates duplic);
+bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
+ List<List_item> &values, List<Item> &update_fields,
+ List<Item> &update_values, enum_duplicates flag);
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry);
-int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
-int mysql_delete(THD *thd, TABLE_LIST *table, COND *conds, SQL_LIST *order,
- ha_rows rows, ulong options);
-int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
-int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
+bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
+bool mysql_delete(THD *thd, TABLE_LIST *table, COND *conds, SQL_LIST *order,
+ ha_rows rows, ulong options);
+bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
+bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update);
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
bool *refresh);
@@ -649,10 +651,15 @@ bool drop_locked_tables(THD *thd,const char *db, const char *table_name);
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
void execute_init_command(THD *thd, sys_var_str *init_command_var,
rw_lock_t *var_mutex);
-extern const Field *not_found_field;
-extern const Field *view_ref_found;
+extern Field *not_found_field;
+extern Field *view_ref_found;
+
+enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
+ IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
+ IGNORE_EXCEPT_NON_UNIQUE};
Field *find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
- Item **ref, bool report_error,
+ Item **ref,
+ find_item_error_report_type report_error,
bool check_privileges);
Field *
find_field_in_table(THD *thd, TABLE_LIST *table_list,
@@ -684,46 +691,57 @@ void free_des_key_file();
#endif /* HAVE_OPENSSL */
/* sql_do.cc */
-int mysql_do(THD *thd, List<Item> &values);
+bool mysql_do(THD *thd, List<Item> &values);
/* sql_show.cc */
-int mysqld_show_dbs(THD *thd,const char *wild);
-int mysqld_show_open_tables(THD *thd,const char *wild);
-int mysqld_show_tables(THD *thd, const char *db, const char *wild,
- bool verbose);
-int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild);
-int mysqld_show_fields(THD *thd,TABLE_LIST *table, const char *wild,
- bool verbose);
-int mysqld_show_keys(THD *thd, TABLE_LIST *table);
-int mysqld_show_logs(THD *thd);
+bool mysqld_show_open_tables(THD *thd,const char *wild);
+bool mysqld_show_logs(THD *thd);
void append_identifier(THD *thd, String *packet, const char *name,
uint length);
int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
int mysqld_dump_create_info(THD *thd, TABLE *table, int fd = -1);
-int mysqld_show_create(THD *thd, TABLE_LIST *table_list);
-int mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
+bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
+bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
void mysqld_list_processes(THD *thd,const char *user,bool verbose);
int mysqld_show_status(THD *thd);
int mysqld_show_variables(THD *thd,const char *wild);
-int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
+bool mysqld_show(THD *thd, const char *wild, show_var_st *variables,
enum enum_var_type value_type,
pthread_mutex_t *mutex,
struct system_status_var *status_var);
int mysql_find_files(THD *thd,List<char> *files, const char *db,
const char *path, const char *wild, bool dir);
-int mysqld_show_charsets(THD *thd,const char *wild);
-int mysqld_show_collations(THD *thd,const char *wild);
-int mysqld_show_storage_engines(THD *thd);
-int mysqld_show_privileges(THD *thd);
-int mysqld_show_column_types(THD *thd);
-int mysqld_help (THD *thd, const char *text);
+bool mysqld_show_storage_engines(THD *thd);
+bool mysqld_show_privileges(THD *thd);
+bool mysqld_show_column_types(THD *thd);
+bool mysqld_help (THD *thd, const char *text);
void calc_sum_of_all_status(STATUS_VAR *to);
+
+
+/* information schema */
+extern LEX_STRING information_schema_name;
+LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str,
+ const char* str, uint length,
+ bool allocate_lex_string= 0);
+ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
+ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
+int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
+ enum enum_schema_tables schema_table_idx);
+int make_schema_select(THD *thd, SELECT_LEX *sel,
+ enum enum_schema_tables schema_table_idx);
+int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
+int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
+int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
+int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
+int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
+bool get_schema_tables_result(JOIN *join);
+
/* sql_prepare.cc */
-int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
- LEX_STRING *name=NULL);
+bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
+ LEX_STRING *name=NULL);
void mysql_stmt_execute(THD *thd, char *packet, uint packet_length);
void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name);
void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length);
@@ -738,13 +756,13 @@ MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, uint
void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
uint code, const char *format, ...);
void mysql_reset_errors(THD *thd);
-my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
+bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
/* sql_handler.cc */
-int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen= 0);
-int mysql_ha_close(THD *thd, TABLE_LIST *tables);
-int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
- List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
+bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen= 0);
+bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
+bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
+ List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags);
/* mysql_ha_flush mode_flags bits */
#define MYSQL_HA_CLOSE_FINAL 0x00
@@ -771,9 +789,7 @@ TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find);
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
table_map read_tables, COND *conds, int *error,
bool allow_null_cond= false);
-enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
- IGNORE_ERRORS};
-extern const Item **not_found_item;
+extern Item **not_found_item;
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
find_item_error_report_type report_error,
bool *unaliased);
@@ -786,16 +802,16 @@ bool insert_fields(THD *thd,TABLE_LIST *tables,
bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds);
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
List<Item> *sum_func_list, uint wild_num);
-int setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables,
- List<Item> &item, bool set_query_id,
- List<Item> *sum_func_list, bool allow_sum_func);
+bool setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables,
+ List<Item> &item, bool set_query_id,
+ List<Item> *sum_func_list, bool allow_sum_func);
int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds);
int setup_ftfuncs(SELECT_LEX* select);
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
void wait_for_refresh(THD *thd);
int open_tables(THD *thd, TABLE_LIST *tables, uint *counter);
int simple_open_n_lock_tables(THD *thd,TABLE_LIST *tables);
-int open_and_lock_tables(THD *thd,TABLE_LIST *tables);
+bool open_and_lock_tables(THD *thd,TABLE_LIST *tables);
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter);
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
const char *table_name, bool link_in_list);
@@ -820,8 +836,10 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table,
bool return_if_owned_by_thd=0);
bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables);
void copy_field_from_tmp_record(Field *field,int offset);
-int fill_record(List<Item> &fields,List<Item> &values, bool ignore_errors);
-int fill_record(Field **field,List<Item> &values, bool ignore_errors);
+bool fill_record(THD *thd, List<Item> &fields, List<Item> &values,
+ bool ignore_errors);
+bool fill_record(THD *thd, Field **field, List<Item> &values,
+ bool ignore_errors);
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild);
inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
@@ -845,10 +863,10 @@ inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
bool eval_const_cond(COND *cond);
/* sql_load.cc */
-int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
- List<Item> &fields, enum enum_duplicates handle_duplicates,
- bool local_file, thr_lock_type lock_type,
- bool ignore_check_option_errors);
+bool mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
+ List<Item> &fields, enum enum_duplicates handle_duplicates,
+ bool local_file, thr_lock_type lock_type,
+ bool ignore_check_option_errors);
int write_record(THD *thd, TABLE *table, COPY_INFO *info);
/* sql_manager.cc */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 196b7af46b1..a3a3290565a 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -543,7 +543,7 @@ static void close_connections(void)
struct timespec abstime;
int error;
LINT_INIT(error);
- DBUG_PRINT("info",("Waiting for select_thread"));
+ DBUG_PRINT("info",("Waiting for select thread"));
#ifndef DONT_USE_THR_ALARM
if (pthread_kill(select_thread,THR_CLIENT_ALARM))
@@ -1172,7 +1172,8 @@ static void server_init(void)
WSADATA WsaData;
if (SOCKET_ERROR == WSAStartup (0x0101, &WsaData))
{
- my_message(0,"WSAStartup Failed\n",MYF(0));
+ /* errors are not read yet, so we use test here */
+ my_message(ER_WSAS_FAILED, "WSAStartup Failed", MYF(0));
unireg_abort(1);
}
}
@@ -1334,8 +1335,9 @@ void yyerror(const char *s)
/* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
s=ER(ER_SYNTAX_ERROR);
- net_printf(thd,ER_PARSE_ERROR, s, yytext ? (char*) yytext : "",
- thd->lex->yylineno);
+ my_printf_error(ER_PARSE_ERROR, ER(ER_PARSE_ERROR), MYF(0), s,
+ (yytext ? (char*) yytext : ""),
+ thd->lex->yylineno);
}
@@ -1366,7 +1368,7 @@ void close_connection(THD *thd, uint errcode, bool lock)
if ((vio=thd->net.vio) != 0)
{
if (errcode)
- send_error(thd, errcode, ER(errcode)); /* purecov: inspected */
+ net_send_error(thd, errcode, ER(errcode)); /* purecov: inspected */
vio_close(vio); /* vio is freed in delete thd */
}
if (lock)
@@ -2130,6 +2132,11 @@ extern "C" int my_message_sql(uint error, const char *str, myf MyFlags)
THD *thd;
DBUG_ENTER("my_message_sql");
DBUG_PRINT("error", ("error: %u message: '%s'", error, str));
+ /*
+ Put here following assertion when situation with EE_* error codes
+ will be fixed
+ DBUG_ASSERT(error != 0);
+ */
if ((thd= current_thd))
{
if (thd->spcont &&
@@ -2137,6 +2144,9 @@ extern "C" int my_message_sql(uint error, const char *str, myf MyFlags)
{
DBUG_RETURN(0);
}
+
+ thd->query_error= 1; // needed to catch query errors during replication
+
/*
thd->lex->current_select == 0 if lex structure is not inited
(not query command (COM_QUERY))
@@ -2155,6 +2165,9 @@ extern "C" int my_message_sql(uint error, const char *str, myf MyFlags)
{
NET *net= &thd->net;
net->report_error= 1;
+#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/
+ query_cache_abort(net);
+#endif
if (!net->last_error[0]) // Return only first message
{
strmake(net->last_error, str, sizeof(net->last_error)-1);
@@ -2313,8 +2326,6 @@ bool init_global_datetime_format(timestamp_type format_type,
static int init_common_variables(const char *conf_file_name, int argc,
char **argv, const char **groups)
{
- my_umask=0660; // Default umask for new files
- my_umask_dir=0700; // Default umask for new directories
umask(((~my_umask) & 0666));
tzset(); // Set tzname
@@ -3430,10 +3441,10 @@ static void create_new_thread(THD *thd)
("Can't create thread to handle request (error %d)",
error));
thread_count--;
- thd->killed= THD::KILL_CONNECTION; // Safety
+ thd->killed= THD::KILL_CONNECTION; // Safety
(void) pthread_mutex_unlock(&LOCK_thread_count);
statistic_increment(aborted_connects,&LOCK_status);
- net_printf(thd,ER_CANT_CREATE_THREAD,error);
+ net_printf_error(thd, ER_CANT_CREATE_THREAD, error);
(void) pthread_mutex_lock(&LOCK_thread_count);
close_connection(thd,0,0);
delete thd;
@@ -4337,7 +4348,7 @@ Disable with --skip-innodb (will save memory).",
"Percentage of dirty pages allowed in bufferpool.", (gptr*) &srv_max_buf_pool_modified_pct,
(gptr*) &srv_max_buf_pool_modified_pct, 0, GET_ULONG, REQUIRED_ARG, 90, 0, 100, 0, 0, 0},
{"innodb_max_purge_lag", OPT_INNODB_MAX_PURGE_LAG,
- "",
+ "Desired maximum length of the purge queue (0 = no limit)",
(gptr*) &srv_max_purge_lag,
(gptr*) &srv_max_purge_lag, 0, GET_LONG, REQUIRED_ARG, 0, 0, ~0L,
0, 1L, 0},
@@ -4346,7 +4357,7 @@ Disable with --skip-innodb (will save memory).",
(gptr*) &innobase_create_status_file, (gptr*) &innobase_create_status_file,
0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"innodb_table_locks", OPT_INNODB_TABLE_LOCKS,
- "If Innodb should enforce LOCK TABLE",
+ "Enable InnoDB locking in LOCK TABLES",
(gptr*) &global_system_variables.innodb_table_locks,
(gptr*) &global_system_variables.innodb_table_locks,
0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index bcb1f8634c0..02fc1691b8b 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -96,7 +96,7 @@ extern void query_cache_insert(NET *net, const char *packet, ulong length);
#define update_statistics(A) A
#else
#define update_statistics(A)
-#define thd_increment_bytes_sent()
+#define thd_increment_bytes_sent(N)
#endif
#define TEST_BLOCKING 8
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 30033bc39eb..f9a51a8348f 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -131,7 +131,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
for (table= tables; table; table= table->next_local)
{
if (outer_tables || (table->table->file->table_flags() &
- HA_NOT_EXACT_COUNT))
+ HA_NOT_EXACT_COUNT) || table->schema_table)
{
const_result= 0; // Can't optimize left join
break;
diff --git a/sql/parse_file.cc b/sql/parse_file.cc
index c3043ed2c73..6c3a81384a6 100644
--- a/sql/parse_file.cc
+++ b/sql/parse_file.cc
@@ -668,7 +668,7 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root,
parameter->offset))))
{
my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
- parameter->name.str, line);
+ parameter->name.str, line);
DBUG_RETURN(TRUE);
}
break;
@@ -680,7 +680,7 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root,
(base + parameter->offset))))
{
my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
- parameter->name.str, line);
+ parameter->name.str, line);
DBUG_RETURN(TRUE);
}
break;
@@ -690,7 +690,7 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root,
if (!(eol= strchr(ptr, '\n')))
{
my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
- parameter->name.str, line);
+ parameter->name.str, line);
DBUG_RETURN(TRUE);
}
{
@@ -708,7 +708,7 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root,
if (ptr[PARSE_FILE_TIMESTAMPLENGTH] != '\n')
{
my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
- parameter->name.str, line);
+ parameter->name.str, line);
DBUG_RETURN(TRUE);
}
memcpy(val->str, ptr, PARSE_FILE_TIMESTAMPLENGTH);
@@ -748,7 +748,7 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root,
list_err_w_message:
my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
- parameter->name.str, line);
+ parameter->name.str, line);
list_err:
DBUG_RETURN(TRUE);
}
@@ -761,8 +761,7 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root,
// skip unknown parameter
if (!(ptr= strchr(ptr, '\n')))
{
- my_error(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER, MYF(0),
- line);
+ my_error(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER, MYF(0), line);
DBUG_RETURN(TRUE);
}
ptr++;
diff --git a/sql/procedure.cc b/sql/procedure.cc
index 7779f5ce085..420a4f6262b 100644
--- a/sql/procedure.cc
+++ b/sql/procedure.cc
@@ -65,8 +65,7 @@ setup_procedure(THD *thd,ORDER *param,select_result *result,
DBUG_RETURN(proc);
}
}
- my_printf_error(ER_UNKNOWN_PROCEDURE,ER(ER_UNKNOWN_PROCEDURE),MYF(0),
- (*param->item)->name);
+ my_error(ER_UNKNOWN_PROCEDURE, MYF(0), (*param->item)->name);
*error=1;
DBUG_RETURN(0);
}
diff --git a/sql/procedure.h b/sql/procedure.h
index 5365b2e1102..160777967ff 100644
--- a/sql/procedure.h
+++ b/sql/procedure.h
@@ -60,7 +60,7 @@ public:
void set(longlong nr) { value=(double) nr; }
void set(const char *str,uint length,CHARSET_INFO *cs)
{ int err; value=my_strntod(cs,(char*) str,length,(char**)0,&err); }
- double val() { return value; }
+ double val_real() { return value; }
longlong val_int() { return (longlong) value; }
String *val_str(String *s) { s->set(value,decimals,default_charset()); return s; }
unsigned int size_of() { return sizeof(*this);}
@@ -78,7 +78,7 @@ public:
void set(longlong nr) { value=nr; }
void set(const char *str,uint length, CHARSET_INFO *cs)
{ int err; value=my_strntoll(cs,str,length,10,NULL,&err); }
- double val() { return (double) value; }
+ double val_real() { return (double) value; }
longlong val_int() { return value; }
String *val_str(String *s) { s->set(value, default_charset()); return s; }
unsigned int size_of() { return sizeof(*this);}
@@ -96,7 +96,7 @@ public:
void set(longlong nr) { str_value.set(nr, default_charset()); }
void set(const char *str, uint length, CHARSET_INFO *cs)
{ str_value.copy(str,length,cs); }
- double val()
+ double val_real()
{
int err;
CHARSET_INFO *cs=str_value.charset();
diff --git a/sql/protocol.cc b/sql/protocol.cc
index 2b0ae60f944..88be2710422 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -53,14 +53,14 @@ bool Protocol_prep::net_store_data(const char *from, uint length)
/* Send a error string to client */
-void send_error(THD *thd, uint sql_errno, const char *err)
+void net_send_error(THD *thd, uint sql_errno, const char *err)
{
#ifndef EMBEDDED_LIBRARY
uint length;
char buff[MYSQL_ERRMSG_SIZE+2], *pos;
#endif
NET *net= &thd->net;
- DBUG_ENTER("send_error");
+ DBUG_ENTER("net_send_error");
DBUG_PRINT("enter",("sql_errno: %d err: %s", sql_errno,
err ? err : net->last_error[0] ?
net->last_error : "NULL"));
@@ -70,9 +70,6 @@ void send_error(THD *thd, uint sql_errno, const char *err)
{
DBUG_VOID_RETURN;
}
-#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/
- query_cache_abort(net);
-#endif
thd->query_error= 1; // needed to catch query errors during replication
if (!err)
{
@@ -130,7 +127,6 @@ void send_error(THD *thd, uint sql_errno, const char *err)
thd->net.report_error= 0;
/* Abort multi-result sets */
- thd->lex->found_colon= 0;
thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
DBUG_VOID_RETURN;
}
@@ -172,7 +168,7 @@ void send_warning(THD *thd, uint sql_errno, const char *err)
*/
void
-net_printf(THD *thd, uint errcode, ...)
+net_printf_error(THD *thd, uint errcode, ...)
{
va_list args;
uint length,offset;
@@ -185,7 +181,7 @@ net_printf(THD *thd, uint errcode, ...)
#endif
NET *net= &thd->net;
- DBUG_ENTER("net_printf");
+ DBUG_ENTER("net_printf_error");
DBUG_PRINT("enter",("message: %u",errcode));
if (thd->spcont && thd->spcont->find_handler(errcode,
@@ -199,8 +195,8 @@ net_printf(THD *thd, uint errcode, ...)
#endif
va_start(args,errcode);
/*
- The following is needed to make net_printf() work with 0 argument for
- errorcode and use the argument after that as the format string. This
+ The following is needed to make net_printf_error() work with 0 argument
+ for errorcode and use the argument after that as the format string. This
is useful for rare errors that are not worth the hassle to put in
errmsg.sys, but at the same time, the message is not fixed text
*/
@@ -627,7 +623,8 @@ bool Protocol::send_fields(List<Item> *list, uint flags)
DBUG_RETURN(prepare_for_send(list));
err:
- send_error(thd,ER_OUT_OF_RESOURCES); /* purecov: inspected */
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES),
+ MYF(0)); /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
diff --git a/sql/protocol.h b/sql/protocol.h
index d342af3ee9f..fddd3ceba94 100644
--- a/sql/protocol.h
+++ b/sql/protocol.h
@@ -173,7 +173,8 @@ public:
};
void send_warning(THD *thd, uint sql_errno, const char *err=0);
-void net_printf(THD *thd,uint sql_errno, ...);
+void net_printf_error(THD *thd, uint sql_errno, ...);
+void net_send_error(THD *thd, uint sql_errno=0, const char *err=0);
void send_ok(THD *thd, ha_rows affected_rows=0L, ulonglong id=0L,
const char *info=0);
void send_eof(THD *thd, bool no_flush=0);
diff --git a/sql/protocol_cursor.cc b/sql/protocol_cursor.cc
index 104457b3bcc..a5bf94469e7 100644
--- a/sql/protocol_cursor.cc
+++ b/sql/protocol_cursor.cc
@@ -84,7 +84,8 @@ bool Protocol_cursor::send_fields(List<Item> *list, uint flags)
DBUG_RETURN(FALSE);
err:
- send_error(thd, ER_OUT_OF_RESOURCES); /* purecov: inspected */
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES),
+ MYF(0)); /* purecov: inspected */
DBUG_RETURN(TRUE); /* purecov: inspected */
}
diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 253b2c96545..5f67143065b 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -194,7 +194,6 @@ err:
my_message(ER_UNKNOWN_ERROR, "Wrong parameters to function register_slave",
MYF(0));
err2:
- send_error(thd);
return 1;
}
@@ -438,7 +437,7 @@ static Slave_log_event* find_slave_event(IO_CACHE* log,
This function is broken now. See comment for translate_master().
*/
-int show_new_master(THD* thd)
+bool show_new_master(THD* thd)
{
Protocol *protocol= thd->protocol;
DBUG_ENTER("show_new_master");
@@ -451,8 +450,8 @@ int show_new_master(THD* thd)
{
if (errmsg[0])
my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0),
- "SHOW NEW MASTER", errmsg);
- DBUG_RETURN(-1);
+ "SHOW NEW MASTER", errmsg);
+ DBUG_RETURN(TRUE);
}
else
{
@@ -461,14 +460,14 @@ int show_new_master(THD* thd)
MYSQL_TYPE_LONGLONG));
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
protocol->prepare_for_resend();
protocol->store(lex_mi->log_file_name, &my_charset_bin);
protocol->store((ulonglong) lex_mi->pos);
if (protocol->write())
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
}
@@ -631,7 +630,7 @@ err:
}
-int show_slave_hosts(THD* thd)
+bool show_slave_hosts(THD* thd)
{
List<Item> field_list;
Protocol *protocol= thd->protocol;
@@ -653,7 +652,7 @@ int show_slave_hosts(THD* thd)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
pthread_mutex_lock(&LOCK_slave_list);
@@ -674,12 +673,12 @@ int show_slave_hosts(THD* thd)
if (protocol->write())
{
pthread_mutex_unlock(&LOCK_slave_list);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
}
pthread_mutex_unlock(&LOCK_slave_list);
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -760,7 +759,7 @@ static int fetch_db_tables(THD *thd, MYSQL *mysql, const char *db,
- No active transaction (flush_relay_log_info would not work in this case)
*/
-int load_master_data(THD* thd)
+bool load_master_data(THD* thd)
{
MYSQL mysql;
MYSQL_RES* master_status_res = 0;
@@ -782,16 +781,15 @@ int load_master_data(THD* thd)
(error=terminate_slave_threads(active_mi,restart_thread_mask,
1 /*skip lock*/)))
{
- send_error(thd,error);
+ my_message(error, ER(error), MYF(0));
unlock_slave_threads(active_mi);
pthread_mutex_unlock(&LOCK_active_mi);
- return 1;
+ return TRUE;
}
if (connect_to_master(thd, &mysql, active_mi))
{
- net_printf(thd, error= ER_CONNECT_TO_MASTER,
- mysql_error(&mysql));
+ my_error(error= ER_CONNECT_TO_MASTER, MYF(0), mysql_error(&mysql));
goto err;
}
@@ -803,8 +801,7 @@ int load_master_data(THD* thd)
if (mysql_real_query(&mysql, "SHOW DATABASES", 14) ||
!(db_res = mysql_store_result(&mysql)))
{
- net_printf(thd, error = ER_QUERY_ON_MASTER,
- mysql_error(&mysql));
+ my_error(error= ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql));
goto err;
}
@@ -817,7 +814,7 @@ int load_master_data(THD* thd)
if (!(table_res = (MYSQL_RES**)thd->alloc(num_dbs * sizeof(MYSQL_RES*))))
{
- net_printf(thd, error = ER_OUTOFMEMORY);
+ my_message(error = ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(0));
goto err;
}
@@ -831,8 +828,7 @@ int load_master_data(THD* thd)
mysql_real_query(&mysql, "SHOW MASTER STATUS",18) ||
!(master_status_res = mysql_store_result(&mysql)))
{
- net_printf(thd, error = ER_QUERY_ON_MASTER,
- mysql_error(&mysql));
+ my_error(error= ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql));
goto err;
}
@@ -877,7 +873,6 @@ int load_master_data(THD* thd)
if (mysql_create_db(thd, db, &create_info, 1))
{
- send_error(thd, 0, 0);
cleanup_mysql_results(db_res, cur_table_res - 1, table_res);
goto err;
}
@@ -886,8 +881,7 @@ int load_master_data(THD* thd)
mysql_real_query(&mysql, "SHOW TABLES", 11) ||
!(*cur_table_res = mysql_store_result(&mysql)))
{
- net_printf(thd, error = ER_QUERY_ON_MASTER,
- mysql_error(&mysql));
+ my_error(error= ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql));
cleanup_mysql_results(db_res, cur_table_res - 1, table_res);
goto err;
}
@@ -925,7 +919,7 @@ int load_master_data(THD* thd)
if (init_master_info(active_mi, master_info_file, relay_log_info_file,
0))
- send_error(thd, ER_MASTER_INFO);
+ my_message(ER_MASTER_INFO, ER(ER_MASTER_INFO), MYF(0));
strmake(active_mi->master_log_name, row[0],
sizeof(active_mi->master_log_name));
active_mi->master_log_pos= my_strtoll10(row[1], (char**) 0, &error);
@@ -944,8 +938,7 @@ int load_master_data(THD* thd)
if (mysql_real_query(&mysql, "UNLOCK TABLES", 13))
{
- net_printf(thd, error = ER_QUERY_ON_MASTER,
- mysql_error(&mysql));
+ my_error(error= ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql));
goto err;
}
}
@@ -954,10 +947,10 @@ int load_master_data(THD* thd)
0 /* not only reset, but also reinit */,
&errmsg))
{
- send_error(thd, 0, "Failed purging old relay logs");
+ my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg);
unlock_slave_threads(active_mi);
pthread_mutex_unlock(&LOCK_active_mi);
- return 1;
+ return TRUE;
}
pthread_mutex_lock(&active_mi->rli.data_lock);
active_mi->rli.group_master_log_pos = active_mi->master_log_pos;
diff --git a/sql/repl_failsafe.h b/sql/repl_failsafe.h
index ad0219bb735..dfaacf557e8 100644
--- a/sql/repl_failsafe.h
+++ b/sql/repl_failsafe.h
@@ -38,11 +38,11 @@ int update_slave_list(MYSQL* mysql, MASTER_INFO* mi);
extern HASH slave_list;
-int load_master_data(THD* thd);
+bool load_master_data(THD* thd);
int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi);
-int show_new_master(THD* thd);
-int show_slave_hosts(THD* thd);
+bool show_new_master(THD* thd);
+bool show_slave_hosts(THD* thd);
int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg);
void init_slave_list();
void end_slave_list();
diff --git a/sql/set_var.cc b/sql/set_var.cc
index ccac3082d5b..e5f3e17d17d 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -899,8 +899,8 @@ bool sys_var_str::check(THD *thd, set_var *var)
return 0;
if ((res=(*check_func)(thd, var)) < 0)
- my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name,
- var->value->str_value.ptr());
+ my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
+ name, var->value->str_value.ptr());
return res;
}
@@ -1537,8 +1537,8 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
{
if (var_type != OPT_DEFAULT)
{
- net_printf(thd, ER_INCORRECT_GLOBAL_LOCAL_VAR,
- name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
+ my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
+ name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
return 0;
}
/* As there was no local variable, return the global value */
@@ -1581,7 +1581,7 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
return tmp;
}
default:
- net_printf(thd, ER_VAR_CANT_BE_READ, name);
+ my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
}
return 0;
}
@@ -1967,8 +1967,8 @@ bool sys_var_character_set_server::check(THD *thd, set_var *var)
(mysql_bin_log.is_open() ||
active_mi->slave_running || active_mi->rli.slave_running))
{
- my_printf_error(0, "Binary logging and replication forbid changing \
-the global server character set or collation", MYF(0));
+ my_error(ER_LOGING_PROHIBIT_CHANGING_OF, MYF(0),
+ "character set, collation");
return 1;
}
return sys_var_character_set::check(thd,var);
@@ -2074,8 +2074,8 @@ bool sys_var_collation_server::check(THD *thd, set_var *var)
(mysql_bin_log.is_open() ||
active_mi->slave_running || active_mi->rli.slave_running))
{
- my_printf_error(0, "Binary logging and replication forbid changing \
-the global server character set or collation", MYF(0));
+ my_error(ER_LOGING_PROHIBIT_CHANGING_OF, MYF(0),
+ "character set, collation");
return 1;
}
return sys_var_collation::check(thd,var);
@@ -2353,7 +2353,7 @@ bool sys_var_slave_skip_counter::check(THD *thd, set_var *var)
pthread_mutex_lock(&active_mi->rli.run_lock);
if (active_mi->rli.slave_running)
{
- my_error(ER_SLAVE_MUST_STOP, MYF(0));
+ my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
result=1;
}
pthread_mutex_unlock(&active_mi->rli.run_lock);
@@ -2424,8 +2424,7 @@ bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
(mysql_bin_log.is_open() ||
active_mi->slave_running || active_mi->rli.slave_running))
{
- my_printf_error(0, "Binary logging and replication forbid changing "
- "of the global server time zone", MYF(0));
+ my_error(ER_LOGING_PROHIBIT_CHANGING_OF, MYF(0), "time zone");
return 1;
}
#endif
@@ -2703,9 +2702,6 @@ void set_var_free()
length Length of variable. zero means that we should use strlen()
on the variable
- NOTE
- We have to use net_printf() as this is called during the parsing stage
-
RETURN VALUES
pointer pointer to variable definitions
0 Unknown variable (error message is given)
@@ -2718,7 +2714,7 @@ sys_var *find_sys_var(const char *str, uint length)
length ? length :
strlen(str));
if (!var)
- net_printf(current_thd, ER_UNKNOWN_SYSTEM_VARIABLE, (char*) str);
+ my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
return var;
}
@@ -2804,9 +2800,8 @@ int set_var::check(THD *thd)
{
if (var->check_type(type))
{
- my_error(type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE,
- MYF(0),
- var->name);
+ int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
+ my_error(err, MYF(0), var->name);
return -1;
}
if ((type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL)))
@@ -2849,9 +2844,8 @@ int set_var::light_check(THD *thd)
{
if (var->check_type(type))
{
- my_error(type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE,
- MYF(0),
- var->name);
+ int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
+ my_error(err, MYF(0), var->name);
return -1;
}
if (type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL))
@@ -2917,7 +2911,7 @@ int set_var_user::update(THD *thd)
if (user_var_item->update())
{
/* Give an error if it's not given already */
- my_error(ER_SET_CONSTANTS_ONLY, MYF(0));
+ my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0));
return -1;
}
return 0;
@@ -2979,7 +2973,7 @@ bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
err:
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
- return 1;
+ return 1;
}
diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt
index e3c08eeca89..c6ee78ffbb2 100644
--- a/sql/share/czech/errmsg.txt
+++ b/sql/share/czech/errmsg.txt
@@ -399,3 +399,24 @@ character-set=latin2
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt
index 78610219ade..37b523526ce 100644
--- a/sql/share/danish/errmsg.txt
+++ b/sql/share/danish/errmsg.txt
@@ -390,3 +390,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt
index 051a2a13ab8..7cf441e899d 100644
--- a/sql/share/dutch/errmsg.txt
+++ b/sql/share/dutch/errmsg.txt
@@ -399,3 +399,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt
index bb2a9cb59ba..990e3819053 100644
--- a/sql/share/english/errmsg.txt
+++ b/sql/share/english/errmsg.txt
@@ -387,3 +387,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt
index 14764d764aa..ff2f2a922ce 100644
--- a/sql/share/estonian/errmsg.txt
+++ b/sql/share/estonian/errmsg.txt
@@ -392,3 +392,24 @@ character-set=latin7
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt
index 7c3e833c903..b9062214ecc 100644
--- a/sql/share/french/errmsg.txt
+++ b/sql/share/french/errmsg.txt
@@ -209,7 +209,7 @@ character-set=latin1
"Erreur d'écriture réseau reçue du maître",
"Impossible de trouver un index FULLTEXT correspondant à cette liste de colonnes",
"Impossible d'exécuter la commande car vous avez des tables verrouillées ou une transaction active",
-"Variable système '%-.64' inconnue",
+"Variable système '%-.64s' inconnue",
"La table '%-.64s' est marquée 'crashed' et devrait être réparée",
"La table '%-.64s' est marquée 'crashed' et le dernier 'repair' a échoué",
"Attention: certaines tables ne supportant pas les transactions ont été changées et elles ne pourront pas être restituées",
@@ -387,3 +387,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt
index 7cda8bef089..757274bf1d5 100644
--- a/sql/share/german/errmsg.txt
+++ b/sql/share/german/errmsg.txt
@@ -400,3 +400,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt
index 7b9bf7e967e..883bd0887c9 100644
--- a/sql/share/greek/errmsg.txt
+++ b/sql/share/greek/errmsg.txt
@@ -168,7 +168,7 @@ character-set=greek
"You have an error in your SQL syntax",
"Delayed insert thread couldn't get requested lock for table %-.64s",
"Too many delayed threads in use",
-"Aborted connection %ld to db: '%-.64s' user: '%-32s' (%-.64s)",
+"Aborted connection %ld to db: '%-.64s' user: '%-.32s' (%-.64s)",
"Got a packet bigger than 'max_allowed_packet' bytes",
"Got a read error from the connection pipe",
"Got an error from fcntl()",
@@ -387,3 +387,24 @@ character-set=greek
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt
index d4e5c5c744f..e93970e7eb8 100644
--- a/sql/share/hungarian/errmsg.txt
+++ b/sql/share/hungarian/errmsg.txt
@@ -392,3 +392,24 @@ character-set=latin2
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt
index c697edb4cd7..1745c31f114 100644
--- a/sql/share/italian/errmsg.txt
+++ b/sql/share/italian/errmsg.txt
@@ -387,3 +387,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt
index e1a32f1894b..969bacc8d8f 100644
--- a/sql/share/japanese/errmsg.txt
+++ b/sql/share/japanese/errmsg.txt
@@ -391,3 +391,24 @@ character-set=ujis
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt
index adb08b67474..cdb67ba004c 100644
--- a/sql/share/korean/errmsg.txt
+++ b/sql/share/korean/errmsg.txt
@@ -387,3 +387,24 @@ character-set=euckr
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt
index 057accd3c5b..35b5a3d464b 100644
--- a/sql/share/norwegian-ny/errmsg.txt
+++ b/sql/share/norwegian-ny/errmsg.txt
@@ -389,3 +389,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt
index 5506d95592a..bb34b3d653c 100644
--- a/sql/share/norwegian/errmsg.txt
+++ b/sql/share/norwegian/errmsg.txt
@@ -389,3 +389,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt
index 38cefd45338..e4dfb9442dd 100644
--- a/sql/share/polish/errmsg.txt
+++ b/sql/share/polish/errmsg.txt
@@ -392,3 +392,24 @@ character-set=latin2
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt
index 7689db06451..4f3c73b900b 100644
--- a/sql/share/portuguese/errmsg.txt
+++ b/sql/share/portuguese/errmsg.txt
@@ -211,7 +211,7 @@ character-set=latin1
"Erro de rede gravando no 'master'",
"Não pode encontrar um índice para o texto todo que combine com a lista de colunas",
"Não pode executar o comando dado porque você tem tabelas ativas travadas ou uma transação ativa",
-"Variável de sistema '%-.64' desconhecida",
+"Variável de sistema '%-.64s' desconhecida",
"Tabela '%-.64s' está marcada como danificada e deve ser reparada",
"Tabela '%-.64s' está marcada como danificada e a última reparação (automática?) falhou",
"Aviso: Algumas tabelas não-transacionais alteradas não puderam ser reconstituídas (rolled back)",
@@ -389,3 +389,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt
index ad486367ec9..b96ddc1fe88 100644
--- a/sql/share/romanian/errmsg.txt
+++ b/sql/share/romanian/errmsg.txt
@@ -173,7 +173,7 @@ character-set=latin2
"Aveti o eroare in sintaxa RSQL",
"Thread-ul pentru inserarea aminata nu a putut obtine lacatul (lock) pentru tabela %-.64s",
"Prea multe threaduri aminate care sint in uz",
-"Conectie terminata %ld la baza de date: '%-.64s' utilizator: '%-32s' (%-.64s)",
+"Conectie terminata %ld la baza de date: '%-.64s' utilizator: '%-.32s' (%-.64s)",
"Un packet mai mare decit 'max_allowed_packet' a fost primit",
"Eroare la citire din cauza lui 'connection pipe'",
"Eroare obtinuta de la fcntl()",
@@ -392,3 +392,24 @@ character-set=latin2
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt
index d057ab53256..2da6cbdfc1a 100644
--- a/sql/share/russian/errmsg.txt
+++ b/sql/share/russian/errmsg.txt
@@ -392,3 +392,24 @@ character-set=koi8r
"CHECK OPTION ÄÌÑ ÎÅÏÂÎÏ×ÌÑÅÍÏÇÏ VIEW '%-.64s.%-.64s'"
"ÐÒÏ×ÅÒËÁ CHECK OPTION ÄÌÑ VIEW '%-.64s.%-.64s' ÐÒÏ×ÁÌÉÌÁÓØ"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt
index 6e38b1c3d11..461a4942131 100644
--- a/sql/share/serbian/errmsg.txt
+++ b/sql/share/serbian/errmsg.txt
@@ -202,7 +202,7 @@ character-set=cp1250
"Greška u slanju mrežnih paketa na glavni server u klasteru",
"Ne mogu da pronaðem 'FULLTEXT' indeks koli odgovara listi kolona",
"Ne mogu da izvršim datu komandu zbog toga što su tabele zakljuèane ili je transakcija u toku",
-"Nepoznata sistemska promenljiva '%-.64'",
+"Nepoznata sistemska promenljiva '%-.64s'",
"Tabela '%-.64s' je markirana kao ošteæena i trebala bi biti popravljena",
"Tabela '%-.64s' je markirana kao ošteæena, a zadnja (automatska?) popravka je bila neuspela",
"Upozorenje: Neke izmenjene tabele ne podržavaju komandu 'ROLLBACK'",
@@ -380,3 +380,24 @@ character-set=cp1250
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt
index a9667b8ba62..862ca741640 100644
--- a/sql/share/slovak/errmsg.txt
+++ b/sql/share/slovak/errmsg.txt
@@ -395,3 +395,24 @@ character-set=latin2
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt
index 17600f336c0..64e6da34d2b 100644
--- a/sql/share/spanish/errmsg.txt
+++ b/sql/share/spanish/errmsg.txt
@@ -238,9 +238,9 @@ character-set=latin1
"No puede adicionar clave extranjera constraint",
"No puede adicionar una línea hijo: falla de clave extranjera constraint",
"No puede deletar una línea padre: falla de clave extranjera constraint",
-"Error de coneccion a master: %-128s",
-"Error executando el query en master: %-128%",
-"Error de %s: %-128%",
+"Error de coneccion a master: %-.128s",
+"Error executando el query en master: %-.128s",
+"Error de %s: %-.128s",
"Equivocado uso de %s y %s",
"El comando SELECT usado tiene diferente número de columnas",
"No puedo ejecutar el query porque usted tiene conflicto de traba de lectura",
@@ -391,3 +391,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt
index 8b061ac0eec..bb7cd72f3df 100644
--- a/sql/share/swedish/errmsg.txt
+++ b/sql/share/swedish/errmsg.txt
@@ -101,7 +101,7 @@ character-set=latin1
"Tabellen '%-.64s' har inget index som motsvarar det angivna i CREATE INDEX. Skapa om tabellen",
"Fältseparatorerna är vad som förväntades. Kontrollera mot manualen",
"Man kan inte använda fast radlängd med blobs. Använd 'fields terminated by'",
-"Textfilen '%' måste finnas i databasbiblioteket eller vara läsbar för alla",
+"Textfilen '%.64s' måste finnas i databasbiblioteket eller vara läsbar för alla",
"Filen '%-.64s' existerar redan",
"Rader: %ld Bortagna: %ld Dubletter: %ld Varningar: %ld",
"Rader: %ld Dubletter: %ld",
@@ -200,7 +200,7 @@ character-set=latin1
"Fick fel %d vid ROLLBACK",
"Fick fel %d vid FLUSH_LOGS",
"Fick fel %d vid CHECKPOINT",
-"Avbröt länken för tråd %ld till db '%-.64s', användare '%-.32s', host '%-.64s' (%.-64s)",
+"Avbröt länken för tråd %ld till db '%-.64s', användare '%-.32s', host '%-.64s' (%-.64s)",
"Tabellhanteraren klarar inte en binär kopiering av tabellen",
"Binärloggen stängdes medan FLUSH MASTER utfördes",
"Failed rebuilding the index of dumped table '%-.64s'",
@@ -387,3 +387,24 @@ character-set=latin1
"CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed '%-.64s.%-.64s'"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt
index 317b2d596fa..a7b139bc2c3 100644
--- a/sql/share/ukrainian/errmsg.txt
+++ b/sql/share/ukrainian/errmsg.txt
@@ -393,3 +393,24 @@ character-set=koi8u
"CHECK OPTION ÄÌÑ VIEW '%-.64s.%-.64s' ÝÏ ÎÅ ÍÏÖÅ ÂÕÔÉ ÏÎÏ×ÌÅÎÎÉÍ"
"ÐÅÒÅצÒËÁ CHECK OPTION ÄÌÑ VIEW '%-.64s.%-.64s' ÎÅ ÐÒÏÊÛÌÁ"
"Access denied; you are not the procedure/function definer of '%s'"
+"Failed purging old relay logs: %s"
+"Password hash should be a %d-digit hexadecimal number"
+"Target log not found in binlog index"
+"I/O error reading log index file"
+"Server configuration does not permit binlog purge"
+"Failed on fseek()"
+"Fatal error during log purge"
+"A purgeable log is in use, will not purge"
+"Unknown error during log purge"
+"Failed initializing relay log position: %s"
+"You are not using binary logging"
+"The '%-.64s' syntax is reserved for purposes internal to the MySQL server"
+"WSAStartup Failed"
+"Can't handle procedures with differents groups yet"
+"Select must have a group with this procedure"
+"Can't use ORDER clause with this procedure"
+"Binary logging and replication forbid changing the global server %s"
+"Can't map file: %-.64s, errno: %d"
+"Wrong magic in %-.64s"
+"Prepared statement contains too many placeholders"
+"Key part '%-.64s' length cannot be 0"
diff --git a/sql/slave.cc b/sql/slave.cc
index 88dffbd8411..34785f1a18f 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -1150,7 +1150,7 @@ bool net_request_file(NET* net, const char* fname)
}
-const char *rewrite_db(const char* db)
+const char *rewrite_db(const char* db, uint *new_len)
{
if (replicate_rewrite_db.is_empty() || !db)
return db;
@@ -1160,7 +1160,10 @@ const char *rewrite_db(const char* db)
while ((tmp=it++))
{
if (!strcmp(tmp->key, db))
+ {
+ *new_len= strlen(tmp->val);
return tmp->val;
+ }
}
return db;
}
@@ -1174,7 +1177,7 @@ const char *rewrite_db(const char* db)
const char *print_slave_db_safe(const char* db)
{
- return (db ? rewrite_db(db) : "");
+ return (db ? db : "");
}
/*
@@ -1490,7 +1493,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
packet_len= my_net_read(net); // read create table statement
if (packet_len == packet_error)
{
- send_error(thd, ER_MASTER_NET_READ);
+ my_message(ER_MASTER_NET_READ, ER(ER_MASTER_NET_READ), MYF(0));
DBUG_RETURN(1);
}
if (net->read_pos[0] == 255) // error from master
@@ -1499,7 +1502,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
err_msg= (char*) net->read_pos + ((mysql->server_capabilities &
CLIENT_PROTOCOL_41) ?
3+SQLSTATE_LENGTH+1 : 3);
- net_printf(thd, ER_MASTER, err_msg);
+ my_error(ER_MASTER, MYF(0), err_msg);
DBUG_RETURN(1);
}
thd->command = COM_TABLE_DUMP;
@@ -1508,7 +1511,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
if (!(query = thd->strmake((char*) net->read_pos, packet_len)))
{
sql_print_error("create_table_from_dump: out of memory");
- net_printf(thd, ER_GET_ERRNO, "Out of memory");
+ my_message(ER_GET_ERRNO, "Out of memory", MYF(0));
DBUG_RETURN(1);
}
thd->query= query;
@@ -1522,7 +1525,6 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
/* Drop the table if 'overwrite' is true */
if (overwrite && mysql_rm_table(thd,&tables,1,0)) /* drop if exists */
{
- send_error(thd);
sql_print_error("create_table_from_dump: failed to drop the table");
goto err;
}
@@ -1549,7 +1551,6 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
tables.lock_type = TL_WRITE;
if (!open_ltable(thd, &tables, TL_WRITE))
{
- send_error(thd,0,0); // Send error from open_ltable
sql_print_error("create_table_from_dump: could not open created table");
goto err;
}
@@ -1559,7 +1560,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
/* Copy the data file */
if (file->net_read_dump(net))
{
- net_printf(thd, ER_MASTER_NET_READ);
+ my_message(ER_MASTER_NET_READ, ER(ER_MASTER_NET_READ), MYF(0));
sql_print_error("create_table_from_dump: failed in\
handler::net_read_dump()");
goto err;
@@ -1579,7 +1580,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
error=file->repair(thd,&check_opt) != 0;
thd->net.vio = save_vio;
if (error)
- net_printf(thd, ER_INDEX_REBUILD,tables.table->real_name);
+ my_error(ER_INDEX_REBUILD, MYF(0), tables.table->real_name);
err:
close_thread_tables(thd);
@@ -1602,12 +1603,11 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name,
{
if (!(mysql = mysql_init(NULL)))
{
- send_error(thd); // EOM
DBUG_RETURN(1);
}
if (connect_to_master(thd, mysql, mi))
{
- net_printf(thd, ER_CONNECT_TO_MASTER, mysql_error(mysql));
+ my_error(ER_CONNECT_TO_MASTER, MYF(0), mysql_error(mysql));
mysql_close(mysql);
DBUG_RETURN(1);
}
@@ -1631,7 +1631,7 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name,
if (!called_connected)
mysql_close(mysql);
if (errmsg && thd->vio_ok())
- send_error(thd, error, errmsg);
+ my_message(error, errmsg, MYF(0));
DBUG_RETURN(test(error)); // Return 1 on error
}
@@ -2268,7 +2268,7 @@ void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a)
}
}
-int show_master_info(THD* thd, MASTER_INFO* mi)
+bool show_master_info(THD* thd, MASTER_INFO* mi)
{
// TODO: fix this for multi-master
List<Item> field_list;
@@ -2332,7 +2332,7 @@ int show_master_info(THD* thd, MASTER_INFO* mi)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
if (mi->host[0])
{
@@ -2431,10 +2431,10 @@ int show_master_info(THD* thd, MASTER_INFO* mi)
pthread_mutex_unlock(&mi->data_lock);
if (my_net_write(&thd->net, (char*)thd->packet.ptr(), packet->length()))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -2829,7 +2829,7 @@ static int request_dump(MYSQL* mysql, MASTER_INFO* mi,
DBUG_ENTER("request_dump");
// TODO if big log files: Change next to int8store()
- int4store(buf, (longlong) mi->master_log_pos);
+ int4store(buf, (ulong) mi->master_log_pos);
int2store(buf + 4, binlog_flags);
int4store(buf + 6, server_id);
len = (uint) strlen(logname);
diff --git a/sql/slave.h b/sql/slave.h
index 2a9b96b75a1..34e3e20ce06 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -490,8 +490,8 @@ int fetch_master_table(THD* thd, const char* db_name, const char* table_name,
void table_rule_ent_hash_to_str(String* s, HASH* h);
void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a);
-int show_master_info(THD* thd, MASTER_INFO* mi);
-int show_binlog_info(THD* thd);
+bool show_master_info(THD* thd, MASTER_INFO* mi);
+bool show_binlog_info(THD* thd);
/* See if the query uses any tables that should not be replicated */
int tables_ok(THD* thd, TABLE_LIST* tables);
@@ -508,8 +508,8 @@ int add_table_rule(HASH* h, const char* table_spec);
int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec);
void init_table_rule_hash(HASH* h, bool* h_inited);
void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
-const char *rewrite_db(const char* db);
-const char *print_slave_db_safe(const char* db);
+const char *rewrite_db(const char* db, uint *new_db_len);
+const char *print_slave_db_safe(const char *db);
int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int error_code);
void skip_load_data_infile(NET* net);
void slave_print_error(RELAY_LOG_INFO* rli, int err_code, const char* msg, ...);
diff --git a/sql/sp.cc b/sql/sp.cc
index 96bb8a17a49..5798eedbad9 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -615,7 +615,7 @@ db_show_routine_status(THD *thd, int type, const char *wild)
Item_field *field= new Item_field("mysql", "proc",
used_field->field_name);
if (!(used_field->field= find_field_in_tables(thd, field, &tables,
- 0, TRUE, 1)))
+ 0, REPORT_ALL_ERRORS, 1)))
{
res= SP_INTERNAL_ERROR;
goto err_case1;
@@ -1001,7 +1001,7 @@ sp_cache_functions(THD *thd, LEX *lex)
{
delete newlex;
thd->lex= oldlex;
- net_printf(thd, ER_SP_DOES_NOT_EXIST, "FUNCTION", ls->str);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", ls->str);
ret= 1;
break;
}
@@ -1163,7 +1163,7 @@ sp_change_db(THD *thd, char *name, bool no_access_check)
{
if ((db_length > NAME_LEN) || check_db_name(dbname))
{
- my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), dbname);
+ my_error(ER_WRONG_DB_NAME, MYF(0), dbname);
x_free(dbname);
DBUG_RETURN(1);
}
@@ -1182,11 +1182,10 @@ sp_change_db(THD *thd, char *name, bool no_access_check)
if (!(db_access & DB_ACLS) &&
(!grant_option || check_grant_db(thd,dbname)))
{
- my_printf_error(ER_DBACCESS_DENIED_ERROR, ER(ER_DBACCESS_DENIED_ERROR),
- MYF(0),
- thd->priv_user,
- thd->priv_host,
- dbname);
+ my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
+ thd->priv_user,
+ thd->priv_host,
+ dbname);
mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
thd->priv_user,
thd->priv_host,
@@ -1202,7 +1201,7 @@ sp_change_db(THD *thd, char *name, bool no_access_check)
path[length-1]=0; // remove ending '\'
if (access(path,F_OK))
{
- my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), dbname);
+ my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
my_free(dbname,MYF(0));
DBUG_RETURN(1);
}
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 47e3952bcdd..7db79128bb8 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -134,7 +134,7 @@ sp_eval_func_item(THD *thd, Item *it, enum enum_field_types type)
}
case REAL_RESULT:
{
- double d= it->val();
+ double d= it->val_real();
if (it->null_value)
{
@@ -148,7 +148,7 @@ sp_eval_func_item(THD *thd, Item *it, enum enum_field_types type)
uint8 decimals= it->decimals;
uint32 max_length= it->max_length;
DBUG_PRINT("info", ("REAL_RESULT: %g", d));
- it= new Item_real(it->val());
+ it= new Item_real(it->val_real());
it->decimals= decimals;
it->max_length= max_length;
}
@@ -494,16 +494,17 @@ sp_head::execute(THD *thd)
case SP_HANDLER_CONTINUE:
ctx->save_variables(hf);
ctx->push_hstack(ip);
- // Fall through
+ // Fall through
default:
ip= hip;
ret= 0;
ctx->clear_handler();
ctx->in_handler= TRUE;
+ thd->clear_error();
continue;
}
}
- } while (ret == 0 && !thd->killed && !thd->query_error);
+ } while (ret == 0 && !thd->killed);
cleanup_items(thd->current_arena->free_list);
thd->current_arena= old_arena;
@@ -512,7 +513,7 @@ sp_head::execute(THD *thd)
DBUG_PRINT("info", ("ret=%d killed=%d query_error=%d",
ret, thd->killed, thd->query_error));
- if (thd->killed || thd->query_error)
+ if (thd->killed)
ret= -1;
/* If the DB has changed, the pointer has changed too, but the
original thd->db will then have been freed */
@@ -543,8 +544,8 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp)
{
// Need to use my_printf_error here, or it will not terminate the
// invoking query properly.
- my_printf_error(ER_SP_WRONG_NO_OF_ARGS, ER(ER_SP_WRONG_NO_OF_ARGS), MYF(0),
- "FUNCTION", m_name.str, params, argcount);
+ my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0),
+ "FUNCTION", m_name.str, params, argcount);
DBUG_RETURN(-1);
}
@@ -595,8 +596,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp)
*resp= it;
else
{
- my_printf_error(ER_SP_NORETURNEND, ER(ER_SP_NORETURNEND), MYF(0),
- m_name.str);
+ my_error(ER_SP_NORETURNEND, MYF(0), m_name.str);
ret= -1;
}
}
@@ -622,8 +622,8 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
if (args->elements != params)
{
- net_printf(thd, ER_SP_WRONG_NO_OF_ARGS, "PROCEDURE", m_name.str,
- params, args->elements);
+ my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0), "PROCEDURE",
+ m_name.str, params, args->elements);
DBUG_RETURN(-1);
}
@@ -694,13 +694,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
if (! ret)
ret= execute(thd);
- // Don't copy back OUT values if we got an error
- if (ret)
- {
- if (thd->net.report_error)
- send_error(thd, 0, NullS);
- }
- else if (csize > 0)
+ if (!ret && csize > 0)
{
List_iterator_fast<Item> li(*args);
Item *it;
@@ -898,7 +892,7 @@ sp_head::check_backpatch(THD *thd)
{
if (bp->lab->type == SP_LAB_REF)
{
- net_printf(thd, ER_SP_LILABEL_MISMATCH, "GOTO", bp->lab->name);
+ my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "GOTO", bp->lab->name);
return -1;
}
}
@@ -1791,7 +1785,7 @@ sp_instr_error::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_error::execute");
- my_error(m_errcode, MYF(0));
+ my_message(m_errcode, ER(m_errcode), MYF(0));
*nextp= m_ip+1;
DBUG_RETURN(-1);
}
diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc
index 51a1bb2e550..609882b84c6 100644
--- a/sql/sp_rcontext.cc
+++ b/sql/sp_rcontext.cc
@@ -153,7 +153,8 @@ sp_cursor::pre_open(THD *thd)
{
if (m_isopen)
{
- send_error(thd, ER_SP_CURSOR_ALREADY_OPEN);
+ my_message(ER_SP_CURSOR_ALREADY_OPEN, ER(ER_SP_CURSOR_ALREADY_OPEN),
+ MYF(0));
return NULL;
}
@@ -187,7 +188,7 @@ sp_cursor::close(THD *thd)
{
if (! m_isopen)
{
- send_error(thd, ER_SP_CURSOR_NOT_OPEN);
+ my_message(ER_SP_CURSOR_NOT_OPEN, ER(ER_SP_CURSOR_NOT_OPEN), MYF(0));
return -1;
}
destroy();
@@ -217,12 +218,12 @@ sp_cursor::fetch(THD *thd, List<struct sp_pvar> *vars)
if (! m_isopen)
{
- send_error(thd, ER_SP_CURSOR_NOT_OPEN);
+ my_message(ER_SP_CURSOR_NOT_OPEN, ER(ER_SP_CURSOR_NOT_OPEN), MYF(0));
return -1;
}
if (m_current_row == NULL)
{
- send_error(thd, ER_SP_FETCH_NO_DATA);
+ my_message(ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA), MYF(0));
return -1;
}
@@ -234,7 +235,8 @@ sp_cursor::fetch(THD *thd, List<struct sp_pvar> *vars)
if (fldcount >= m_prot->get_field_count())
{
- send_error(thd, ER_SP_WRONG_NO_OF_FETCH_ARGS);
+ my_message(ER_SP_WRONG_NO_OF_FETCH_ARGS,
+ ER(ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0));
return -1;
}
s= row[fldcount];
@@ -260,7 +262,8 @@ sp_cursor::fetch(THD *thd, List<struct sp_pvar> *vars)
}
if (fldcount < m_prot->get_field_count())
{
- send_error(thd, ER_SP_WRONG_NO_OF_FETCH_ARGS);
+ my_message(ER_SP_WRONG_NO_OF_FETCH_ARGS,
+ ER(ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0));
return -1;
}
m_current_row= m_current_row->next;
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 3e3642dd0bd..8ffba2579f3 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -1057,6 +1057,7 @@ ulong acl_get(const char *host, const char *ip,
db_access=0; host_access= ~0;
char key[ACL_KEY_LENGTH],*tmp_db,*end;
acl_entry *entry;
+ DBUG_ENTER("acl_get");
VOID(pthread_mutex_lock(&acl_cache->lock));
end=strmov((tmp_db=strmov(strmov(key, ip ? ip : "")+1,user)+1),db);
@@ -1070,7 +1071,8 @@ ulong acl_get(const char *host, const char *ip,
{
db_access=entry->access;
VOID(pthread_mutex_unlock(&acl_cache->lock));
- return db_access;
+ DBUG_PRINT("exit", ("access: 0x%lx", db_access));
+ DBUG_RETURN(db_access);
}
/*
@@ -1122,7 +1124,8 @@ exit:
acl_cache->add(entry);
}
VOID(pthread_mutex_unlock(&acl_cache->lock));
- return (db_access & host_access);
+ DBUG_PRINT("exit", ("access: 0x%lx", db_access & host_access));
+ DBUG_RETURN(db_access & host_access);
}
/*
@@ -1225,8 +1228,7 @@ bool check_change_password(THD *thd, const char *host, const char *user,
{
if (!initialized)
{
- net_printf(thd,ER_OPTION_PREVENTS_STATEMENT,
- "--skip-grant-tables");
+ my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables");
return(1);
}
if (!thd->slave_thread &&
@@ -1238,16 +1240,15 @@ bool check_change_password(THD *thd, const char *host, const char *user,
}
if (!thd->slave_thread && !thd->user[0])
{
- send_error(thd, ER_PASSWORD_ANONYMOUS_USER);
+ my_message(ER_PASSWORD_ANONYMOUS_USER, ER(ER_PASSWORD_ANONYMOUS_USER),
+ MYF(0));
return(1);
}
uint len=strlen(new_password);
if (len && len != SCRAMBLED_PASSWORD_CHAR_LENGTH &&
len != SCRAMBLED_PASSWORD_CHAR_LENGTH_323)
{
- net_printf(thd, 0,
- "Password hash should be a %d-digit hexadecimal number",
- SCRAMBLED_PASSWORD_CHAR_LENGTH);
+ my_error(ER_PASSWD_LENGTH, MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH);
return -1;
}
return(0);
@@ -1285,7 +1286,7 @@ bool change_password(THD *thd, const char *host, const char *user,
if (!(acl_user= find_acl_user(host, user)))
{
VOID(pthread_mutex_unlock(&acl_cache->lock));
- send_error(thd, ER_PASSWORD_NO_MATCH);
+ my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0));
DBUG_RETURN(1);
}
/* update loaded acl entry: */
@@ -1298,7 +1299,6 @@ bool change_password(THD *thd, const char *host, const char *user,
new_password, new_password_len))
{
VOID(pthread_mutex_unlock(&acl_cache->lock)); /* purecov: deadcode */
- send_error(thd,0); /* purecov: deadcode */
DBUG_RETURN(1); /* purecov: deadcode */
}
@@ -1471,7 +1471,8 @@ static bool update_user_table(THD *thd, const char *host, const char *user,
(byte*) table->field[0]->ptr,0,
HA_READ_KEY_EXACT))
{
- my_error(ER_PASSWORD_NO_MATCH,MYF(0)); /* purecov: deadcode */
+ my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH),
+ MYF(0)); /* purecov: deadcode */
DBUG_RETURN(1); /* purecov: deadcode */
}
store_record(table,record[1]);
@@ -1528,6 +1529,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
uint password_len= 0;
char what= (revoke_grant) ? 'N' : 'Y';
DBUG_ENTER("replace_user_table");
+ LEX *lex= thd->lex;
safe_mutex_assert_owner(&acl_cache->lock);
if (combo.password.str && combo.password.str[0])
@@ -1535,9 +1537,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
if (combo.password.length != SCRAMBLED_PASSWORD_CHAR_LENGTH &&
combo.password.length != SCRAMBLED_PASSWORD_CHAR_LENGTH_323)
{
- my_printf_error(ER_UNKNOWN_ERROR,
- "Password hash should be a %d-digit hexadecimal number",
- MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH);
+ my_error(ER_PASSWD_LENGTH, MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH);
DBUG_RETURN(-1);
}
password_len= combo.password.length;
@@ -1600,8 +1600,8 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
store_record(table,record[1]); // Save copy for update
if (combo.password.str) // If password given
table->field[2]->store(password, password_len, &my_charset_latin1);
- else if (!rights && !revoke_grant && thd->lex->ssl_type == SSL_TYPE_NOT_SPECIFIED &&
- !thd->lex->mqh.bits)
+ else if (!rights && !revoke_grant &&
+ lex->ssl_type == SSL_TYPE_NOT_SPECIFIED && !lex->mqh.bits)
{
DBUG_RETURN(0);
}
@@ -1624,7 +1624,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
if (table->fields >= 31) /* From 4.0.0 we have more fields */
{
/* We write down SSL related ACL stuff */
- switch (thd->lex->ssl_type) {
+ switch (lex->ssl_type) {
case SSL_TYPE_ANY:
table->field[24]->store("ANY",3, &my_charset_latin1);
table->field[25]->store("", 0, &my_charset_latin1);
@@ -1642,15 +1642,15 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
table->field[25]->store("", 0, &my_charset_latin1);
table->field[26]->store("", 0, &my_charset_latin1);
table->field[27]->store("", 0, &my_charset_latin1);
- if (thd->lex->ssl_cipher)
- table->field[25]->store(thd->lex->ssl_cipher,
- strlen(thd->lex->ssl_cipher), &my_charset_latin1);
- if (thd->lex->x509_issuer)
- table->field[26]->store(thd->lex->x509_issuer,
- strlen(thd->lex->x509_issuer), &my_charset_latin1);
- if (thd->lex->x509_subject)
- table->field[27]->store(thd->lex->x509_subject,
- strlen(thd->lex->x509_subject), &my_charset_latin1);
+ if (lex->ssl_cipher)
+ table->field[25]->store(lex->ssl_cipher,
+ strlen(lex->ssl_cipher), &my_charset_latin1);
+ if (lex->x509_issuer)
+ table->field[26]->store(lex->x509_issuer,
+ strlen(lex->x509_issuer), &my_charset_latin1);
+ if (lex->x509_subject)
+ table->field[27]->store(lex->x509_subject,
+ strlen(lex->x509_subject), &my_charset_latin1);
break;
case SSL_TYPE_NOT_SPECIFIED:
break;
@@ -1662,7 +1662,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
break;
}
- USER_RESOURCES mqh= thd->lex->mqh;
+ USER_RESOURCES mqh= lex->mqh;
if (mqh.bits & 1)
table->field[28]->store((longlong) mqh.questions);
if (mqh.bits & 2)
@@ -1704,19 +1704,19 @@ end:
if (old_row_exists)
acl_update_user(combo.user.str, combo.host.str,
combo.password.str, password_len,
- thd->lex->ssl_type,
- thd->lex->ssl_cipher,
- thd->lex->x509_issuer,
- thd->lex->x509_subject,
- &thd->lex->mqh,
+ lex->ssl_type,
+ lex->ssl_cipher,
+ lex->x509_issuer,
+ lex->x509_subject,
+ &lex->mqh,
rights);
else
acl_insert_user(combo.user.str, combo.host.str, password, password_len,
- thd->lex->ssl_type,
- thd->lex->ssl_cipher,
- thd->lex->x509_issuer,
- thd->lex->x509_subject,
- &thd->lex->mqh,
+ lex->ssl_type,
+ lex->ssl_cipher,
+ lex->x509_issuer,
+ lex->x509_subject,
+ &lex->mqh,
rights);
}
DBUG_RETURN(error);
@@ -1747,7 +1747,7 @@ static int replace_db_table(TABLE *table, const char *db,
/* Check if there is such a user in user table in memory? */
if (!find_acl_user(combo.host.str,combo.user.str))
{
- my_error(ER_PASSWORD_NO_MATCH,MYF(0));
+ my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0));
DBUG_RETURN(-1);
}
@@ -1797,7 +1797,7 @@ static int replace_db_table(TABLE *table, const char *db,
goto table_error; /* purecov: deadcode */
}
}
- else if ((error=table->file->write_row(table->record[0])))
+ else if (rights && (error=table->file->write_row(table->record[0])))
{
if (error && error != HA_ERR_FOUND_DUPP_KEY) /* purecov: inspected */
goto table_error; /* purecov: deadcode */
@@ -1807,6 +1807,7 @@ static int replace_db_table(TABLE *table, const char *db,
if (old_row_exists)
acl_update_db(combo.user.str,combo.host.str,db,rights);
else
+ if (rights)
acl_insert_db(combo.user.str,combo.host.str,db,rights);
DBUG_RETURN(0);
@@ -2067,7 +2068,8 @@ static int replace_column_table(GRANT_TABLE *g_t,
if (revoke_grant)
{
my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0),
- combo.user.str, combo.host.str, table_name); /* purecov: inspected */
+ combo.user.str, combo.host.str,
+ table_name); /* purecov: inspected */
result= -1; /* purecov: inspected */
continue; /* purecov: inspected */
}
@@ -2210,7 +2212,8 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table,
*/
if (!find_acl_user(combo.host.str,combo.user.str))
{
- my_error(ER_PASSWORD_NO_MATCH,MYF(0)); /* purecov: deadcode */
+ my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH),
+ MYF(0)); /* purecov: deadcode */
DBUG_RETURN(-1); /* purecov: deadcode */
}
@@ -2234,7 +2237,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table,
{ // no row, no revoke
my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0),
combo.user.str, combo.host.str,
- table_name); /* purecov: deadcode */
+ table_name); /* purecov: deadcode */
DBUG_RETURN(-1); /* purecov: deadcode */
}
old_row_exists = 0;
@@ -2316,11 +2319,11 @@ table_error:
revoke_grant Set to 1 if this is a REVOKE command
RETURN
- 0 ok
- 1 error
+ FALSE ok
+ TRUE error
*/
-int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
+bool mysql_table_grant(THD *thd, TABLE_LIST *table_list,
List <LEX_USER> &user_list,
List <LEX_COLUMN> &columns, ulong rights,
bool revoke_grant)
@@ -2337,12 +2340,13 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
"--skip-grant-tables"); /* purecov: inspected */
- DBUG_RETURN(-1); /* purecov: inspected */
+ DBUG_RETURN(TRUE); /* purecov: inspected */
}
if (rights & ~TABLE_ACLS)
{
- my_error(ER_ILLEGAL_GRANT_FOR_TABLE,MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE),
+ MYF(0));
+ DBUG_RETURN(TRUE);
}
if (columns.elements && !revoke_grant)
@@ -2351,8 +2355,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
List_iterator <LEX_COLUMN> column_iter(columns);
int res;
- if ((res= open_and_lock_tables(thd, table_list)))
- DBUG_RETURN(res);
+ if (open_and_lock_tables(thd, table_list))
+ DBUG_RETURN(TRUE);
while ((column = column_iter++))
{
@@ -2364,7 +2368,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{
my_error(ER_BAD_FIELD_ERROR, MYF(0),
column->column.c_ptr(), table_list->alias);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
column_priv|= column->rights;
}
@@ -2379,7 +2383,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
if (access(buf,F_OK))
{
my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
}
@@ -2412,19 +2416,19 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
*/
tables[0].updating= tables[1].updating= tables[2].updating= 1;
if (!tables_ok(0, tables))
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
#endif
if (simple_open_n_lock_tables(thd,tables))
{ // Should never happen
close_thread_tables(thd); /* purecov: deadcode */
- DBUG_RETURN(-1); /* purecov: deadcode */
+ DBUG_RETURN(TRUE); /* purecov: deadcode */
}
if (!revoke_grant)
create_new_users= test_if_create_new_users(thd);
- int result=0;
+ bool result= FALSE;
rw_wrlock(&LOCK_grant);
MEM_ROOT *old_root= thd->mem_root;
thd->mem_root= &memex;
@@ -2436,8 +2440,9 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
if (Str->host.length > HOSTNAME_LENGTH ||
Str->user.length > USERNAME_LENGTH)
{
- my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0));
- result= -1;
+ my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER),
+ MYF(0));
+ result= TRUE;
continue;
}
/* Create user if needed */
@@ -2447,7 +2452,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
pthread_mutex_unlock(&acl_cache->lock);
if (error)
{
- result= -1; // Remember error
+ result= TRUE; // Remember error
continue; // Add next user
}
@@ -2467,7 +2472,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{
my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0),
Str->user.str, Str->host.str, table_list->real_name);
- result= -1;
+ result= TRUE;
continue;
}
grant_table = new GRANT_TABLE (Str->host.str, db_name,
@@ -2476,7 +2481,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
column_priv);
if (!grant_table) // end of memory
{
- result= -1; /* purecov: deadcode */
+ result= TRUE; /* purecov: deadcode */
continue; /* purecov: deadcode */
}
my_hash_insert(&column_priv_hash,(byte*) grant_table);
@@ -2521,7 +2526,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
rights, column_priv, revoke_grant))
{
/* Should only happen if table is crashed */
- result= -1; /* purecov: deadcode */
+ result= TRUE; /* purecov: deadcode */
}
else if (tables[2].table)
{
@@ -2530,7 +2535,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
db_name, real_name,
rights, revoke_grant)))
{
- result= -1;
+ result= TRUE;
}
}
}
@@ -2544,8 +2549,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
}
-int mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
- ulong rights, bool revoke_grant)
+bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
+ ulong rights, bool revoke_grant)
{
List_iterator <LEX_USER> str_list (list);
LEX_USER *Str;
@@ -2557,7 +2562,7 @@ int mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
{
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
"--skip-grant-tables"); /* purecov: tested */
- DBUG_RETURN(-1); /* purecov: tested */
+ DBUG_RETURN(TRUE); /* purecov: tested */
}
if (lower_case_table_names && db)
@@ -2588,14 +2593,14 @@ int mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
*/
tables[0].updating= tables[1].updating= 1;
if (!tables_ok(0, tables))
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
#endif
if (simple_open_n_lock_tables(thd,tables))
{ // This should never happen
close_thread_tables(thd); /* purecov: deadcode */
- DBUG_RETURN(-1); /* purecov: deadcode */
+ DBUG_RETURN(TRUE); /* purecov: deadcode */
}
if (!revoke_grant)
@@ -2612,7 +2617,8 @@ int mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
if (Str->host.length > HOSTNAME_LENGTH ||
Str->user.length > USERNAME_LENGTH)
{
- my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0));
+ my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER),
+ MYF(0));
result= -1;
continue;
}
@@ -2846,7 +2852,8 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
for (table= tables; table && number--; table= table->next_global)
{
GRANT_TABLE *grant_table;
- if (!(~table->grant.privilege & want_access) || table->derived)
+ if (!(~table->grant.privilege & want_access) ||
+ table->derived || table->schema_table)
{
/*
It is subquery in the FROM clause. VIEW set table->derived after
@@ -2909,11 +2916,11 @@ err:
command= "create view";
else if (want_access & SHOW_VIEW_ACL)
command= "show create view";
- net_printf(thd,ER_TABLEACCESS_DENIED_ERROR,
- command,
- thd->priv_user,
- thd->host_or_ip,
- table ? table->real_name : "unknown");
+ my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
+ command,
+ thd->priv_user,
+ thd->host_or_ip,
+ table ? table->real_name : "unknown");
}
DBUG_RETURN(1);
}
@@ -2959,21 +2966,18 @@ bool check_grant_column(THD *thd, GRANT_INFO *grant,
}
#endif
- /* We must use my_printf_error() here! */
err:
rw_unlock(&LOCK_grant);
if (!show_tables)
{
char command[128];
get_privilege_desc(command, sizeof(command), want_access);
- my_printf_error(ER_COLUMNACCESS_DENIED_ERROR,
- ER(ER_COLUMNACCESS_DENIED_ERROR),
- MYF(0),
- command,
- thd->priv_user,
- thd->host_or_ip,
- name,
- table_name);
+ my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
+ command,
+ thd->priv_user,
+ thd->host_or_ip,
+ name,
+ table_name);
}
return 1;
}
@@ -3020,7 +3024,6 @@ bool check_grant_all_columns(THD *thd, ulong want_access, GRANT_INFO *grant,
rw_unlock(&LOCK_grant);
return 0;
- /* We must use my_printf_error() here! */
err:
rw_unlock(&LOCK_grant);
err2:
@@ -3029,14 +3032,12 @@ err2:
command= "select";
else if (want_access & INSERT_ACL)
command= "insert";
- my_printf_error(ER_COLUMNACCESS_DENIED_ERROR,
- ER(ER_COLUMNACCESS_DENIED_ERROR),
- MYF(0),
- command,
- thd->priv_user,
- thd->host_or_ip,
- fields->name(),
- table_name);
+ my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
+ command,
+ thd->priv_user,
+ thd->host_or_ip,
+ fields->name(),
+ table_name);
return 1;
}
@@ -3175,7 +3176,7 @@ static uint command_lengths[]=
Send to client grant-like strings depicting user@host privileges
*/
-int mysql_show_grants(THD *thd,LEX_USER *lex_user)
+bool mysql_show_grants(THD *thd,LEX_USER *lex_user)
{
ulong want_access;
uint counter,index;
@@ -3190,7 +3191,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
if (!initialized)
{
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables");
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (!lex_user->host.str)
@@ -3201,8 +3202,9 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
if (lex_user->host.length > HOSTNAME_LENGTH ||
lex_user->user.length > USERNAME_LENGTH)
{
- my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER),
+ MYF(0));
+ DBUG_RETURN(TRUE);
}
for (counter=0 ; counter < acl_users.elements ; counter++)
@@ -3221,7 +3223,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
{
my_error(ER_NONEXISTING_GRANT, MYF(0),
lex_user->user.str, lex_user->host.str);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
Item_string *field=new Item_string("",0,&my_charset_latin1);
@@ -3233,7 +3235,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user)
field_list.push_back(field);
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
rw_wrlock(&LOCK_grant);
VOID(pthread_mutex_lock(&acl_cache->lock));
@@ -3555,7 +3557,7 @@ int open_grant_tables(THD *thd, TABLE_LIST *tables)
if (!initialized)
{
- net_printf(thd,ER_OPTION_PREVENTS_STATEMENT, "--skip-grant-tables");
+ my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables");
DBUG_RETURN(-1);
}
@@ -3624,7 +3626,7 @@ ACL_USER *check_acl_user(LEX_USER *user_name,
}
-int mysql_drop_user(THD *thd, List <LEX_USER> &list)
+bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
{
uint counter, acl_userd;
int result;
@@ -3635,7 +3637,7 @@ int mysql_drop_user(THD *thd, List <LEX_USER> &list)
DBUG_ENTER("mysql_drop_user");
if ((result= open_grant_tables(thd, tables)))
- DBUG_RETURN(result == 1 ? 0 : 1);
+ DBUG_RETURN(result != 1);
rw_wrlock(&LOCK_grant);
VOID(pthread_mutex_lock(&acl_cache->lock));
@@ -3723,7 +3725,7 @@ int mysql_drop_user(THD *thd, List <LEX_USER> &list)
record[0])))
{
tables[0].table->file->print_error(error, MYF(0));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
delete_dynamic_element(&acl_users, acl_userd);
}
@@ -3733,11 +3735,11 @@ int mysql_drop_user(THD *thd, List <LEX_USER> &list)
rw_unlock(&LOCK_grant);
close_thread_tables(thd);
if (result)
- my_error(ER_DROP_USER, MYF(0));
+ my_message(ER_DROP_USER, ER(ER_DROP_USER), MYF(0));
DBUG_RETURN(result);
}
-int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
+bool mysql_revoke_all(THD *thd, List <LEX_USER> &list)
{
uint counter, revoked;
int result;
@@ -3746,7 +3748,7 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
DBUG_ENTER("mysql_revoke_all");
if ((result= open_grant_tables(thd, tables)))
- DBUG_RETURN(result == 1 ? 0 : 1);
+ DBUG_RETURN(result != 1);
rw_wrlock(&LOCK_grant);
VOID(pthread_mutex_lock(&acl_cache->lock));
@@ -3860,7 +3862,7 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
close_thread_tables(thd);
if (result)
- my_error(ER_REVOKE_GRANTS, MYF(0));
+ my_message(ER_REVOKE_GRANTS, ER(ER_REVOKE_GRANTS), MYF(0));
DBUG_RETURN(result);
}
@@ -3923,6 +3925,229 @@ int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr)
DBUG_RETURN (*str != '\0');
}
+
+void update_schema_privilege(TABLE *table, char *buff, const char* db,
+ const char* t_name, const char* column,
+ uint col_length, const char *priv,
+ uint priv_length, const char* is_grantable)
+{
+ int i= 2;
+ CHARSET_INFO *cs= system_charset_info;
+ restore_record(table, default_values);
+ table->field[0]->store(buff, strlen(buff), cs);
+ if (db)
+ table->field[i++]->store(db, strlen(db), cs);
+ if (t_name)
+ table->field[i++]->store(t_name, strlen(t_name), cs);
+ if (column)
+ table->field[i++]->store(column, col_length, cs);
+ table->field[i++]->store(priv, priv_length, cs);
+ table->field[i]->store(is_grantable, strlen(is_grantable), cs);
+ table->file->write_row(table->record[0]);
+}
+
+
+int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ uint counter;
+ ACL_USER *acl_user;
+ ulong want_access;
+
+ char buff[100];
+ TABLE *table= tables->table;
+ DBUG_ENTER("fill_schema_user_privileges");
+ for (counter=0 ; counter < acl_users.elements ; counter++)
+ {
+ const char *user,*host, *is_grantable="YES";
+ acl_user=dynamic_element(&acl_users,counter,ACL_USER*);
+ if (!(user=acl_user->user))
+ user= "";
+ if (!(host=acl_user->host.hostname))
+ host= "";
+ want_access= acl_user->access;
+ if (!(want_access & GRANT_ACL))
+ is_grantable= "NO";
+
+ strxmov(buff,"'",user,"'@'",host,"'",NullS);
+ if (!(want_access & ~GRANT_ACL))
+ update_schema_privilege(table, buff, 0, 0, 0, 0, "USAGE", 5, is_grantable);
+ else
+ {
+ uint priv_id;
+ ulong j,test_access= want_access & ~GRANT_ACL;
+ for (priv_id=0, j = SELECT_ACL;j <= GLOBAL_ACLS; priv_id++,j <<= 1)
+ {
+ if (test_access & j)
+ update_schema_privilege(table, buff, 0, 0, 0, 0,
+ command_array[priv_id],
+ command_lengths[priv_id], is_grantable);
+ }
+ }
+ }
+ DBUG_RETURN(0);
+#else
+ return(0);
+#endif
+}
+
+
+int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ uint counter;
+ ACL_DB *acl_db;
+ ulong want_access;
+ char buff[100];
+ TABLE *table= tables->table;
+ DBUG_ENTER("fill_schema_schema_privileges");
+
+ for (counter=0 ; counter < acl_dbs.elements ; counter++)
+ {
+ const char *user, *host, *is_grantable="YES";
+
+ acl_db=dynamic_element(&acl_dbs,counter,ACL_DB*);
+ if (!(user=acl_db->user))
+ user= "";
+ if (!(host=acl_db->host.hostname))
+ host= "";
+
+ want_access=acl_db->access;
+ if (want_access)
+ {
+ if (!(want_access & GRANT_ACL))
+ {
+ is_grantable= "NO";
+ }
+ strxmov(buff,"'",user,"'@'",host,"'",NullS);
+ if (!(want_access & ~GRANT_ACL))
+ update_schema_privilege(table, buff, acl_db->db, 0, 0,
+ 0, "USAGE", 5, is_grantable);
+ else
+ {
+ int cnt;
+ ulong j,test_access= want_access & ~GRANT_ACL;
+ for (cnt=0, j = SELECT_ACL; j <= DB_ACLS; cnt++,j <<= 1)
+ if (test_access & j)
+ update_schema_privilege(table, buff, acl_db->db, 0, 0, 0,
+ command_array[cnt], command_lengths[cnt],
+ is_grantable);
+ }
+ }
+ }
+ DBUG_RETURN(0);
+#else
+ return (0);
+#endif
+}
+
+
+int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ uint index;
+ char buff[100];
+ TABLE *table= tables->table;
+ DBUG_ENTER("fill_schema_table_privileges");
+
+ for (index=0 ; index < column_priv_hash.records ; index++)
+ {
+ const char *user, *is_grantable= "YES";
+ GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
+ index);
+ if (!(user=grant_table->user))
+ user= "";
+ ulong table_access= grant_table->privs;
+ if (table_access != 0)
+ {
+ ulong test_access= table_access & ~GRANT_ACL;
+ if (!(table_access & GRANT_ACL))
+ is_grantable= "NO";
+
+ strxmov(buff,"'",user,"'@'",grant_table->orig_host,"'",NullS);
+ if (!test_access)
+ update_schema_privilege(table, buff, grant_table->db, grant_table->tname,
+ 0, 0, "USAGE", 5, is_grantable);
+ else
+ {
+ ulong j;
+ int cnt;
+ for (cnt= 0, j= SELECT_ACL; j <= TABLE_ACLS; cnt++, j<<= 1)
+ {
+ if (test_access & j)
+ update_schema_privilege(table, buff, grant_table->db,
+ grant_table->tname, 0, 0, command_array[cnt],
+ command_lengths[cnt], is_grantable);
+ }
+ }
+ }
+ }
+ DBUG_RETURN(0);
+#else
+ return (0);
+#endif
+}
+
+
+int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ uint index;
+ char buff[100];
+ TABLE *table= tables->table;
+ DBUG_ENTER("fill_schema_table_privileges");
+
+ for (index=0 ; index < column_priv_hash.records ; index++)
+ {
+ const char *user, *is_grantable= "YES";
+ GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
+ index);
+ if (!(user=grant_table->user))
+ user= "";
+ ulong table_access= grant_table->cols;
+ if (table_access != 0)
+ {
+ if (!(grant_table->privs & GRANT_ACL))
+ is_grantable= "NO";
+
+ ulong test_access= table_access & ~GRANT_ACL;
+ strxmov(buff,"'",user,"'@'",grant_table->orig_host,"'",NullS);
+ if (!test_access)
+ continue;
+ else
+ {
+ ulong j;
+ int cnt;
+ for (cnt= 0, j= SELECT_ACL; j <= TABLE_ACLS; cnt++, j<<= 1)
+ {
+ if (test_access & j)
+ {
+ for (uint col_index=0 ;
+ col_index < grant_table->hash_columns.records ;
+ col_index++)
+ {
+ GRANT_COLUMN *grant_column = (GRANT_COLUMN*)
+ hash_element(&grant_table->hash_columns,col_index);
+ if ((grant_column->rights & j) && (table_access & j))
+ update_schema_privilege(table, buff, grant_table->db,
+ grant_table->tname,
+ grant_column->column,
+ grant_column->key_length,
+ command_array[cnt],
+ command_lengths[cnt], is_grantable);
+ }
+ }
+ }
+ }
+ }
+ }
+ DBUG_RETURN(0);
+#else
+ return (0);
+#endif
+}
+
+
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/*
fill effective privileges for table
diff --git a/sql/sql_acl.h b/sql/sql_acl.h
index 390106c1546..f6074da5279 100644
--- a/sql/sql_acl.h
+++ b/sql/sql_acl.h
@@ -158,11 +158,11 @@ bool check_change_password(THD *thd, const char *host, const char *user,
char *password);
bool change_password(THD *thd, const char *host, const char *user,
char *password);
-int mysql_grant(THD *thd, const char *db, List <LEX_USER> &user_list,
- ulong rights, bool revoke);
-int mysql_table_grant(THD *thd, TABLE_LIST *table, List <LEX_USER> &user_list,
- List <LEX_COLUMN> &column_list, ulong rights,
- bool revoke);
+bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &user_list,
+ ulong rights, bool revoke);
+bool mysql_table_grant(THD *thd, TABLE_LIST *table, List <LEX_USER> &user_list,
+ List <LEX_COLUMN> &column_list, ulong rights,
+ bool revoke);
my_bool grant_init(THD *thd);
void grant_free(void);
void grant_reload(THD *thd);
@@ -179,11 +179,11 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table);
ulong get_column_grant(THD *thd, GRANT_INFO *grant,
const char *db_name, const char *table_name,
const char *field_name);
-int mysql_show_grants(THD *thd, LEX_USER *user);
+bool mysql_show_grants(THD *thd, LEX_USER *user);
void get_privilege_desc(char *to, uint max_length, ulong access);
void get_mqh(const char *user, const char *host, USER_CONN *uc);
-int mysql_drop_user(THD *thd, List <LEX_USER> &list);
-int mysql_revoke_all(THD *thd, List <LEX_USER> &list);
+bool mysql_drop_user(THD *thd, List <LEX_USER> &list);
+bool mysql_revoke_all(THD *thd, List <LEX_USER> &list);
void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant,
const char *db, const char *table);
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc
index 1e0aebbc1ec..2259d3bead8 100644
--- a/sql/sql_analyse.cc
+++ b/sql/sql_analyse.cc
@@ -78,7 +78,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
{
// first parameter
if ((*param->item)->type() != Item::INT_ITEM ||
- (*param->item)->val() < 0)
+ (*param->item)->val_real() < 0)
{
delete pc;
my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name);
@@ -93,7 +93,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
}
// second parameter
if ((*param->item)->type() != Item::INT_ITEM ||
- (*param->item)->val() < 0)
+ (*param->item)->val_real() < 0)
{
delete pc;
my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name);
@@ -102,7 +102,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
pc->max_treemem = (uint) (*param->item)->val_int();
}
else if ((*param->item)->type() != Item::INT_ITEM ||
- (*param->item)->val() < 0)
+ (*param->item)->val_real() < 0)
{
delete pc;
my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name);
@@ -364,7 +364,7 @@ void field_str::add()
void field_real::add()
{
char buff[MAX_FIELD_WIDTH], *ptr, *end;
- double num = item->val();
+ double num= item->val_real();
uint length, zero_count, decs;
TREE_ELEMENT *element;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 4fae481e5f2..629216249cd 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -370,7 +370,8 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
Put all normal tables used by thread in free list.
*/
-void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived)
+void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived,
+ TABLE *stopper)
{
bool found_old_table;
DBUG_ENTER("close_thread_tables");
@@ -408,7 +409,7 @@ void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived)
DBUG_PRINT("info", ("thd->open_tables: %p", thd->open_tables));
found_old_table= 0;
- while (thd->open_tables)
+ while (thd->open_tables != stopper)
found_old_table|=close_thread_table(thd, &thd->open_tables);
thd->some_tables_deleted=0;
@@ -582,6 +583,7 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
if ((!strcmp(table->db, db_name) &&
!strcmp(table->real_name, table_name)) ||
(table->view &&
+ table->table->table_cache_key && // it is not temporary table
!my_strcasecmp(table_alias_charset,
table->table->table_cache_key, db_name) &&
!my_strcasecmp(table_alias_charset,
@@ -626,6 +628,9 @@ TABLE_LIST* unique_table(TABLE_LIST *table, TABLE_LIST *table_list)
TABLE_LIST *res;
const char *d_name= table->db, *t_name= table->real_name;
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
+ /* temporary table is always unique */
+ if (table->table && table->table->tmp_table != NO_TMP_TABLE)
+ return 0;
if (table->view)
{
/* it is view and table opened */
@@ -643,11 +648,6 @@ TABLE_LIST* unique_table(TABLE_LIST *table, TABLE_LIST *table_list)
d_name= table->table->table_cache_key;
t_name= table->table->table_name;
}
- if (d_name == 0)
- {
- /* it's temporary table => always unique */
- return 0;
- }
}
DBUG_PRINT("info", ("real table: %s.%s", d_name, t_name));
@@ -892,8 +892,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
{
if (table->query_id == thd->query_id)
{
- my_printf_error(ER_CANT_REOPEN_TABLE,
- ER(ER_CANT_REOPEN_TABLE), MYF(0), table->table_name);
+ my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->table_name);
DBUG_RETURN(0);
}
table->query_id= thd->query_id;
@@ -950,7 +949,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
VOID(pthread_mutex_unlock(&LOCK_open));
}
}
- my_printf_error(ER_TABLE_NOT_LOCKED,ER(ER_TABLE_NOT_LOCKED),MYF(0),alias);
+ my_error(ER_TABLE_NOT_LOCKED, MYF(0), alias);
DBUG_RETURN(0);
}
@@ -1263,7 +1262,7 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh)
next=table->next;
if (!tables || (!db_stat && reopen_table(table,1)))
{
- my_error(ER_CANT_REOPEN_TABLE,MYF(0),table->table_name);
+ my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->table_name);
VOID(hash_delete(&open_cache,(byte*) table));
error=1;
}
@@ -1657,6 +1656,12 @@ int open_tables(THD *thd, TABLE_LIST *start, uint *counter)
*/
if (tables->derived)
continue;
+ if (tables->schema_table)
+ {
+ if (!mysql_schema_table(thd, thd->lex, tables))
+ continue;
+ DBUG_RETURN(-1);
+ }
(*counter)++;
if (!tables->table &&
!(tables->table= open_table(thd, tables, &new_frm_mem, &refresh)))
@@ -1741,9 +1746,7 @@ static bool check_lock_and_start_stmt(THD *thd, TABLE *table,
if ((int) lock_type >= (int) TL_WRITE_ALLOW_READ &&
(int) table->reginfo.lock_type < (int) TL_WRITE_ALLOW_READ)
{
- my_printf_error(ER_TABLE_NOT_LOCKED_FOR_WRITE,
- ER(ER_TABLE_NOT_LOCKED_FOR_WRITE),
- MYF(0),table->table_name);
+ my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->table_name);
DBUG_RETURN(1);
}
if ((error=table->file->start_stmt(thd)))
@@ -1854,15 +1857,14 @@ int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
tables - list of tables for open&locking
RETURN
- 0 - ok
- -1 - error
- 1 - error reported to user
+ FALSE - ok
+ TRUE - error
NOTE
The lock will automaticly be freed by close_thread_tables()
*/
-int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
+bool open_and_lock_tables(THD *thd, TABLE_LIST *tables)
{
DBUG_ENTER("open_and_lock_tables");
uint counter;
@@ -1871,7 +1873,7 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
(thd->fill_derived_tables() &&
mysql_handle_derived(thd->lex, &mysql_derived_filling)))
- DBUG_RETURN(thd->net.report_error ? -1 : 1); /* purecov: inspected */
+ DBUG_RETURN(TRUE); /* purecov: inspected */
relink_tables_for_multidelete(thd);
DBUG_RETURN(0);
}
@@ -2046,8 +2048,8 @@ bool rm_temporary_table(enum db_type base, char *path)
******************************************************************************/
/* Special Field pointers for find_field_in_tables returning */
-const Field *not_found_field= (Field*) 0x1;
-const Field *view_ref_found= (Field*) 0x2;
+Field *not_found_field= (Field*) 0x1;
+Field *view_ref_found= (Field*) 0x2;
#define WRONG_GRANT (Field*) -1
@@ -2225,25 +2227,32 @@ Field *find_field_in_real_table(THD *thd, TABLE *table,
find_field_in_tables()
thd Pointer to current thread structure
item Field item that should be found
- tables Tables for scanning
- ref if view field is found, pointer to view item will
- be returned via this parameter
- report_error If FALSE then do not report error if item not found
- and return not_found_field
+ tables Tables to be searched for item
+ ref If 'item' is resolved to a view field, ref is set to
+ point to the found view field
+ report_error Degree of error reporting:
+ - IGNORE_ERRORS then do not report any error
+ - IGNORE_EXCEPT_NON_UNIQUE report only non-unique
+ fields, suppress all other errors
+ - REPORT_EXCEPT_NON_UNIQUE report all other errors
+ except when non-unique fields were found
+ - REPORT_ALL_ERRORS
check_privileges need to check privileges
RETURN VALUES
- 0 Field is not found or field is not unique- error
- message is reported
- not_found_field Function was called with report_error == FALSE and
- field was not found. no error message reported.
- view_ref_found view field is found, item passed through ref parameter
- found field
+ 0 If error: the found field is not unique, or there are
+ no sufficient access priviliges for the found field,
+ or the field is qualified with non-existing table.
+ not_found_field The function was called with report_error ==
+ (IGNORE_ERRORS || IGNORE_EXCEPT_NON_UNIQUE) and a
+ field was not found.
+ view_ref_found View field is found, item passed through ref parameter
+ found field If a item was resolved to some field
*/
Field *
find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
- Item **ref, bool report_error,
+ Item **ref, find_item_error_report_type report_error,
bool check_privileges)
{
Field *found=0;
@@ -2261,8 +2270,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
TABLE_LIST *tables is not changed during query execution (which
is true for all queries except RENAME but luckily RENAME doesn't
use fields...) so we can rely on reusing pointer to its member.
- With this optimisation we also miss case when addition of one more
- field makes some prepared query ambiguous and so erronous, but we
+ With this optimization we also miss case when addition of one more
+ field makes some prepared query ambiguous and so erroneous, but we
accept this trade off.
*/
found= find_field_in_real_table(thd, item->cached_table->table,
@@ -2283,7 +2292,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
if (db && lower_case_table_names)
{
/*
- convert database to lower case for comparision.
+ convert database to lower case for comparison.
We can't do this in Item_field as this would change the
'name' of the item which may be used in the select list
*/
@@ -2320,8 +2329,10 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
return find;
if (found)
{
- my_printf_error(ER_NON_UNIQ_ERROR,ER(ER_NON_UNIQ_ERROR),MYF(0),
- item->full_name(),thd->where);
+ if (report_error == REPORT_ALL_ERRORS ||
+ report_error == IGNORE_EXCEPT_NON_UNIQUE)
+ my_error(ER_NON_UNIQ_ERROR, MYF(0),
+ item->full_name(),thd->where);
return (Field*) 0;
}
found=find;
@@ -2330,7 +2341,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
}
if (found)
return found;
- if (!found_table && report_error)
+ if (!found_table && (report_error == REPORT_ALL_ERRORS ||
+ report_error == REPORT_EXCEPT_NON_UNIQUE))
{
char buff[NAME_LEN*2+1];
if (db && db[0])
@@ -2338,30 +2350,29 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
strxnmov(buff,sizeof(buff)-1,db,".",table_name,NullS);
table_name=buff;
}
- if (report_error)
- {
- my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0),
- table_name, thd->where);
- }
+ if (report_error == REPORT_ALL_ERRORS ||
+ report_error == REPORT_EXCEPT_NON_UNIQUE)
+ my_error(ER_UNKNOWN_TABLE, MYF(0), table_name, thd->where);
else
return (Field*) not_found_field;
}
else
- if (report_error)
- my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0),
- item->full_name(),thd->where);
+ if (report_error == REPORT_ALL_ERRORS ||
+ report_error == REPORT_EXCEPT_NON_UNIQUE)
+ my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(),thd->where);
else
return (Field*) not_found_field;
return (Field*) 0;
}
+
bool allow_rowid= tables && !tables->next_local; // Only one table
for (; tables ; tables= tables->next_local)
{
if (!tables->table)
{
- if (report_error)
- my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0),
- item->full_name(),thd->where);
+ if (report_error == REPORT_ALL_ERRORS ||
+ report_error == REPORT_EXCEPT_NON_UNIQUE)
+ my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(),thd->where);
return (Field*) not_found_field;
}
@@ -2384,8 +2395,9 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
{
if (!thd->where) // Returns first found
break;
- my_printf_error(ER_NON_UNIQ_ERROR,ER(ER_NON_UNIQ_ERROR),MYF(0),
- name,thd->where);
+ if (report_error == REPORT_ALL_ERRORS ||
+ report_error == IGNORE_EXCEPT_NON_UNIQUE)
+ my_error(ER_NON_UNIQ_ERROR, MYF(0), name, thd->where);
return (Field*) 0;
}
found=field;
@@ -2393,9 +2405,9 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
}
if (found)
return found;
- if (report_error)
- my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR),
- MYF(0), item->full_name(), thd->where);
+ if (report_error == REPORT_ALL_ERRORS ||
+ report_error == REPORT_EXCEPT_NON_UNIQUE)
+ my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(), thd->where);
else
return (Field*) not_found_field;
return (Field*) 0;
@@ -2432,8 +2444,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
found field
*/
-// Special Item pointer for find_item_in_list returning
-const Item **not_found_item= (const Item**) 0x1;
+/* Special Item pointer to serve as a return value from find_item_in_list(). */
+Item **not_found_item= (Item**) 0x1;
Item **
@@ -2507,8 +2519,8 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
unaliased names only and will have duplicate error anyway.
*/
if (report_error != IGNORE_ERRORS)
- my_printf_error(ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR),
- MYF(0), find->full_name(), current_thd->where);
+ my_error(ER_NON_UNIQ_ERROR, MYF(0),
+ find->full_name(), current_thd->where);
return (Item**) 0;
}
found_unaliased= li.ref();
@@ -2532,8 +2544,8 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
if ((*found)->eq(item, 0))
continue; // Same field twice
if (report_error != IGNORE_ERRORS)
- my_printf_error(ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR),
- MYF(0), find->full_name(), current_thd->where);
+ my_error(ER_NON_UNIQ_ERROR, MYF(0),
+ find->full_name(), current_thd->where);
return (Item**) 0;
}
found= li.ref();
@@ -2576,8 +2588,8 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
if (found_unaliased_non_uniq)
{
if (report_error != IGNORE_ERRORS)
- my_printf_error(ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR), MYF(0),
- find->full_name(), current_thd->where);
+ my_error(ER_NON_UNIQ_ERROR, MYF(0),
+ find->full_name(), current_thd->where);
return (Item **) 0;
}
if (found_unaliased)
@@ -2592,8 +2604,8 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
if (report_error != REPORT_EXCEPT_NOT_FOUND)
{
if (report_error == REPORT_ALL_ERRORS)
- my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0),
- find->full_name(), current_thd->where);
+ my_error(ER_BAD_FIELD_ERROR, MYF(0),
+ find->full_name(), current_thd->where);
return (Item **) 0;
}
else
@@ -2678,9 +2690,9 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
** Check that all given fields exists and fill struct with current data
****************************************************************************/
-int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
- List<Item> &fields, bool set_query_id,
- List<Item> *sum_func_list, bool allow_sum_func)
+bool setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
+ List<Item> &fields, bool set_query_id,
+ List<Item> *sum_func_list, bool allow_sum_func)
{
reg2 Item *item;
List_iterator<Item> it(fields);
@@ -2698,7 +2710,7 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
(item= *(it.ref()))->check_cols(1))
{
select_lex->no_wrap_view_item= 0;
- DBUG_RETURN(-1); /* purecov: inspected */
+ DBUG_RETURN(TRUE); /* purecov: inspected */
}
if (ref)
*(ref++)= item;
@@ -2806,8 +2818,8 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
(pos= find_type(&table->keynames, name->ptr(), name->length(), 1)) <=
0)
{
- my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), name->c_ptr(),
- table->real_name);
+ my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0),
+ name->c_ptr(), table->real_name);
map->set_all();
return 1;
}
@@ -2830,7 +2842,8 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
any_privileges 0 If we should ensure that we have SELECT privileges
for all columns
1 If any privilege is ok
- allocate_view_names if true view names will be copied to current Item_arena memory (made for SP/PS)
+ allocate_view_names if true view names will be copied to current Item_arena
+ memory (made for SP/PS)
RETURN
0 ok
'it' is updated to point at last inserted
@@ -2889,7 +2902,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
&view_iter))
goto err;
}
- else
+ else if (!tables->schema_table)
{
table_iter.set(tables);
if (check_grant_all_columns(thd, SELECT_ACL, &table->grant,
@@ -2969,21 +2982,20 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
db= tables->db;
tab= tables->real_name;
}
- if (!(fld->have_privileges= (get_column_grant(thd,
+ if (!tables->schema_table &&
+ !(fld->have_privileges= (get_column_grant(thd,
&table->grant,
db,
tab,
fld->field_name) &
VIEW_ANY_ACL)))
{
- my_printf_error(ER_COLUMNACCESS_DENIED_ERROR,
- ER(ER_COLUMNACCESS_DENIED_ERROR),
- MYF(0),
- "ANY",
- thd->priv_user,
- thd->host_or_ip,
- fld->field_name,
- tab);
+ my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
+ "ANY",
+ thd->priv_user,
+ thd->host_or_ip,
+ fld->field_name,
+ tab);
goto err;
}
}
@@ -3022,7 +3034,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
DBUG_RETURN(0);
if (!table_name)
- my_error(ER_NO_TABLES_USED, MYF(0));
+ my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
else
my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name);
@@ -3041,6 +3053,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
SELECT_LEX *select_lex= thd->lex->current_select;
Item_arena *arena= thd->current_arena, backup;
bool save_wrapper= thd->lex->current_select->no_wrap_view_item;
+ TABLE_LIST *table= NULL; // For HP compilers
DBUG_ENTER("setup_conds");
if (select_lex->conds_processed_with_permanent_arena ||
@@ -3060,7 +3073,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
}
/* Check if we are using outer joins */
- for (TABLE_LIST *table= tables; table; table= table->next_local)
+ for (table= tables; table; table= table->next_local)
{
TABLE_LIST *embedded;
TABLE_LIST *embedding= table;
@@ -3245,8 +3258,25 @@ err_no_arena:
** Returns : 1 if some field has wrong type
******************************************************************************/
-int
-fill_record(List<Item> &fields,List<Item> &values, bool ignore_errors)
+
+/*
+ Fill fields with given items.
+
+ SYNOPSIS
+ fill_record()
+ thd thread handler
+ fields Item_fields list to be filled
+ values values to fill with
+ ignore_errors TRUE if we should ignore errors
+
+ RETURN
+ FALSE OK
+ TRUE error occured
+*/
+
+bool
+fill_record(THD * thd, List<Item> &fields, List<Item> &values,
+ bool ignore_errors)
{
List_iterator_fast<Item> f(fields),v(values);
Item *value;
@@ -3261,14 +3291,32 @@ fill_record(List<Item> &fields,List<Item> &values, bool ignore_errors)
if (rfield == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors)
- DBUG_RETURN(1);
+ {
+ my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0));
+ DBUG_RETURN(TRUE);
+ }
}
- DBUG_RETURN(0);
+ DBUG_RETURN(thd->net.report_error);
}
-int
-fill_record(Field **ptr,List<Item> &values, bool ignore_errors)
+/*
+ Fill field buffer with values from Field list
+
+ SYNOPSIS
+ fill_record()
+ thd thread handler
+ ptr pointer on pointer to record
+ values list of fields
+ ignore_errors TRUE if we should ignore errors
+
+ RETURN
+ FALSE OK
+ TRUE error occured
+*/
+
+bool
+fill_record(THD *thd, Field **ptr, List<Item> &values, bool ignore_errors)
{
List_iterator_fast<Item> v(values);
Item *value;
@@ -3282,9 +3330,12 @@ fill_record(Field **ptr,List<Item> &values, bool ignore_errors)
if (field == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
if ((value->save_in_field(field, 0) < 0) && !ignore_errors)
- DBUG_RETURN(1);
+ {
+ my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0));
+ DBUG_RETURN(TRUE);
+ }
}
- DBUG_RETURN(0);
+ DBUG_RETURN(thd->net.report_error);
}
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 15e1cc7e212..e69c0f52c93 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -702,7 +702,7 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, long key_length)
if (!new_table)
{
my_error(EE_OUTOFMEMORY, MYF(ME_BELL),
- ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1);
+ ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1);
killed= KILL_CONNECTION;
return 0;
}
@@ -821,7 +821,7 @@ select_result::select_result()
void select_result::send_error(uint errcode,const char *err)
{
- ::send_error(thd, errcode, err);
+ my_message(errcode, err, MYF(0));
}
@@ -925,7 +925,7 @@ bool select_send::send_eof()
void select_to_file::send_error(uint errcode,const char *err)
{
- ::send_error(thd,errcode,err);
+ my_message(errcode, err, MYF(0));
if (file > 0)
{
(void) end_io_cache(&cache);
@@ -1249,7 +1249,7 @@ bool select_dump::send_data(List<Item> &items)
}
if (row_count++ > 1)
{
- my_error(ER_TOO_MANY_ROWS, MYF(0));
+ my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
goto err;
}
while ((item=li++))
@@ -1262,7 +1262,7 @@ bool select_dump::send_data(List<Item> &items)
}
else if (my_b_write(&cache,(byte*) res->ptr(),res->length()))
{
- my_error(ER_ERROR_ON_WRITE,MYF(0), path, my_errno);
+ my_error(ER_ERROR_ON_WRITE, MYF(0), path, my_errno);
goto err;
}
}
@@ -1345,7 +1345,7 @@ bool select_max_min_finder_subselect::send_data(List<Item> &items)
bool select_max_min_finder_subselect::cmp_real()
{
Item *maxmin= ((Item_singlerow_subselect *)item)->el(0);
- double val1= cache->val(), val2= maxmin->val();
+ double val1= cache->val_real(), val2= maxmin->val_real();
if (fmax)
return (cache->null_value && !maxmin->null_value) ||
(!cache->null_value && !maxmin->null_value &&
@@ -1421,7 +1421,8 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
if (var_list.elements != list.elements)
{
- my_error(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, MYF(0));
+ my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
+ ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0));
return 1;
}
while ((item=li++))
@@ -1722,7 +1723,7 @@ bool select_dumpvar::send_data(List<Item> &items)
}
if (row_count++)
{
- my_error(ER_TOO_MANY_ROWS, MYF(0));
+ my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
DBUG_RETURN(1);
}
while ((zz=my_li++) && (item=it++))
diff --git a/sql/sql_class.h b/sql/sql_class.h
index f820f8b9cb9..41a560d41cf 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -41,6 +41,7 @@ enum enum_check_fields { CHECK_FIELD_IGNORE, CHECK_FIELD_WARN,
CHECK_FIELD_ERROR_FOR_NULL };
extern char internal_table_name[2];
+extern const char **errmesg;
/* log info errors */
#define LOG_INFO_EOF -1
@@ -153,7 +154,7 @@ public:
DBUG_VOID_RETURN;
}
void set_max_size(ulong max_size_arg);
- void signal_update() { pthread_cond_broadcast(&update_cond);}
+ void signal_update();
void wait_for_update(THD* thd, bool master_or_slave);
void set_need_start_event() { need_start_event = 1; }
void init(enum_log_type log_type_arg,
@@ -1157,6 +1158,7 @@ public:
net.last_error[0]= 0;
net.last_errno= 0;
net.report_error= 0;
+ query_error= 0;
}
inline bool vio_ok() const { return net.vio != 0; }
#else
@@ -1209,7 +1211,8 @@ public:
}
inline void send_kill_message() const
{
- my_error(killed_errno(), MYF(0));
+ int err= killed_errno();
+ my_message(err, ER(err), MYF(0));
}
/* return TRUE if we will abort query if we make a warning now */
inline bool really_abort_on_warning()
@@ -1251,8 +1254,6 @@ public:
class JOIN;
-void send_error(THD *thd, uint sql_errno=0, const char *err=0);
-
class select_result :public Sql_alloc {
protected:
THD *thd;
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 7a100d05b93..ad4887146d8 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -31,11 +31,6 @@ const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NullS};
static TYPELIB deletable_extentions=
{array_elements(del_exts)-1,"del_exts", del_exts, NULL};
-const char *known_exts[]=
-{".ISM",".ISD",".ISM",".MRG",".MYI",".MYD",".db", ".ibd", NullS};
-static TYPELIB known_extentions=
-{array_elements(known_exts)-1,"known_exts", known_exts, NULL};
-
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
const char *db, const char *path,
uint level);
@@ -379,13 +374,13 @@ bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
In this case the entry should not be logged.
RETURN VALUES
- 0 ok
- -1 Error
+ FALSE ok
+ TRUE Error
*/
-int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
- bool silent)
+bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
+ bool silent)
{
char path[FN_REFLEN+16];
long result= 1;
@@ -413,7 +408,7 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
{
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
{
- my_error(ER_DB_CREATE_EXISTS,MYF(0),db);
+ my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
error= -1;
goto exit;
}
@@ -423,12 +418,12 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
{
if (my_errno != ENOENT)
{
- my_error(EE_STAT, MYF(0),path,my_errno);
+ my_error(EE_STAT, MYF(0), path, my_errno);
goto exit;
}
if (my_mkdir(path,0777,MYF(0)) < 0)
{
- my_error(ER_CANT_CREATE_DB,MYF(0),db,my_errno);
+ my_error(ER_CANT_CREATE_DB, MYF(0), db, my_errno);
error= -1;
goto exit;
}
@@ -489,7 +484,7 @@ exit2:
/* db-name is already validated when we come here */
-int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
+bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
{
char path[FN_REFLEN+16];
long result=1;
@@ -532,7 +527,7 @@ exit:
start_waiting_global_read_lock(thd);
exit2:
VOID(pthread_mutex_unlock(&LOCK_mysql_create_db));
- DBUG_RETURN(error ? -1 : 0); /* -1 to delegate send_error() */
+ DBUG_RETURN(error);
}
@@ -548,11 +543,11 @@ exit2:
silent Don't generate errors
RETURN
- 0 ok (Database dropped)
- -1 Error generated
+ FALSE ok (Database dropped)
+ ERROR Error
*/
-int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
+bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
{
long deleted=0;
int error= 0;
@@ -582,7 +577,7 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
if (!if_exists)
{
error= -1;
- my_error(ER_DB_DROP_EXISTS,MYF(0),db);
+ my_error(ER_DB_DROP_EXISTS, MYF(0), db);
goto exit;
}
else
@@ -755,7 +750,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
extension= fn_ext(file->name);
if (find_type(extension, &deletable_extentions,1+2) <= 0)
{
- if (find_type(extension, &known_extentions,1+2) <= 0)
+ if (find_type(extension, ha_known_exts(),1+2) <= 0)
found_other_files++;
continue;
}
@@ -990,12 +985,13 @@ bool mysql_change_db(THD *thd, const char *name)
if (!dbname || !(db_length= strlen(dbname)))
{
x_free(dbname); /* purecov: inspected */
- send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */
+ my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR),
+ MYF(0)); /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
if (check_db_name(dbname))
{
- net_printf(thd, ER_WRONG_DB_NAME, dbname);
+ my_error(ER_WRONG_DB_NAME, MYF(0), dbname);
x_free(dbname);
DBUG_RETURN(1);
}
@@ -1008,10 +1004,10 @@ bool mysql_change_db(THD *thd, const char *name)
thd->master_access);
if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname)))
{
- net_printf(thd,ER_DBACCESS_DENIED_ERROR,
- thd->priv_user,
- thd->priv_host,
- dbname);
+ my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
+ thd->priv_user,
+ thd->priv_host,
+ dbname);
mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
thd->priv_user,
thd->priv_host,
@@ -1026,7 +1022,7 @@ bool mysql_change_db(THD *thd, const char *name)
path[length-1]=0; // remove ending '\'
if (access(path,F_OK))
{
- net_printf(thd,ER_BAD_DB_ERROR,dbname);
+ my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
my_free(dbname,MYF(0));
DBUG_RETURN(1);
}
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 8bdf19195f3..e764e957a16 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -29,8 +29,8 @@
#include "sp_head.h"
#include "sql_trigger.h"
-int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
- ha_rows limit, ulong options)
+bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
+ SQL_LIST *order, ha_rows limit, ulong options)
{
int error;
TABLE *table;
@@ -39,32 +39,39 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
bool using_limit=limit != HA_POS_ERROR;
bool transactional_table, log_delayed, safe_update, const_cond;
ha_rows deleted;
+ SELECT_LEX *select_lex= &thd->lex->select_lex;
DBUG_ENTER("mysql_delete");
- if ((error= open_and_lock_tables(thd, table_list)))
- DBUG_RETURN(error);
+ if (open_and_lock_tables(thd, table_list))
+ DBUG_RETURN(TRUE);
table= table_list->table;
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
thd->proc_info="init";
table->map=1;
- if ((error= mysql_prepare_delete(thd, table_list, &conds)))
- DBUG_RETURN(error);
+ if (mysql_prepare_delete(thd, table_list, &conds))
+ DBUG_RETURN(TRUE);
const_cond= (!conds || conds->const_item());
safe_update=test(thd->options & OPTION_SAFE_UPDATES);
if (safe_update && const_cond)
{
- send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE);
- DBUG_RETURN(1);
+ my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
+ ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
+ DBUG_RETURN(TRUE);
}
if (thd->lex->duplicates == DUP_IGNORE)
- thd->lex->select_lex.no_error= 1;
+ select_lex->no_error= 1;
- /* Test if the user wants to delete all rows */
+ /*
+ Test if the user wants to delete all rows and deletion doesn't have
+ any side-effects (because of triggers), so we can use optimized
+ handler::delete_all_rows() method.
+ */
if (!using_limit && const_cond && (!conds || conds->val_int()) &&
- !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)))
+ !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) &&
+ !(table->triggers && table->triggers->has_delete_triggers()))
{
deleted= table->file->records;
if (!(error=table->file->delete_all_rows()))
@@ -85,11 +92,11 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
table->quick_keys.clear_all(); // Can't use 'only index'
select=make_select(table,0,0,conds,&error);
if (error)
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
if ((select && select->check_quick(thd, safe_update, limit)) || !limit)
{
delete select;
- free_underlaid_joins(thd, &thd->lex->select_lex);
+ free_underlaid_joins(thd, select_lex);
thd->row_count_func= 0;
send_ok(thd,0L);
DBUG_RETURN(0); // Nothing to delete
@@ -102,9 +109,10 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
if (safe_update && !using_limit)
{
delete select;
- free_underlaid_joins(thd, &thd->lex->select_lex);
- send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE);
- DBUG_RETURN(1);
+ free_underlaid_joins(thd, select_lex);
+ my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
+ ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
+ DBUG_RETURN(TRUE);
}
}
if (options & OPTION_QUICK)
@@ -124,8 +132,8 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
MYF(MY_FAE | MY_ZEROFILL));
- if (thd->lex->select_lex.setup_ref_array(thd, order->elements) ||
- setup_order(thd, thd->lex->select_lex.ref_pointer_array, &tables,
+ if (select_lex->setup_ref_array(thd, order->elements) ||
+ setup_order(thd, select_lex->ref_pointer_array, &tables,
fields, all_fields, (ORDER*) order->first) ||
!(sortorder=make_unireg_sortorder((ORDER*) order->first, &length)) ||
(table->sort.found_records = filesort(thd, table, sortorder, length,
@@ -134,8 +142,8 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
== HA_POS_ERROR)
{
delete select;
- free_underlaid_joins(thd, &thd->lex->select_lex);
- DBUG_RETURN(-1); // This will force out message
+ free_underlaid_joins(thd, select_lex);
+ DBUG_RETURN(TRUE);
}
/*
Filesort has already found and selected the rows we want to delete,
@@ -149,12 +157,12 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
if (select && select->quick && select->quick->reset())
{
delete select;
- free_underlaid_joins(thd, &thd->lex->select_lex);
- DBUG_RETURN(-1); // This will force out message
+ free_underlaid_joins(thd, select_lex);
+ DBUG_RETURN(TRUE);
}
init_read_record(&info,thd,table,select,1,1);
deleted=0L;
- init_ftfuncs(thd, &thd->lex->select_lex, 1);
+ init_ftfuncs(thd, select_lex, 1);
thd->proc_info="updating";
while (!(error=info.read_record(&info)) && !thd->killed &&
!thd->net.report_error)
@@ -252,16 +260,14 @@ cleanup:
mysql_unlock_tables(thd, thd->lock);
thd->lock=0;
}
- free_underlaid_joins(thd, &thd->lex->select_lex);
- if (error >= 0 || thd->net.report_error)
- send_error(thd,thd->killed_errno());
- else
+ free_underlaid_joins(thd, select_lex);
+ if (error < 0)
{
thd->row_count_func= deleted;
send_ok(thd,deleted);
DBUG_PRINT("info",("%d records deleted",deleted));
}
- DBUG_RETURN(0);
+ DBUG_RETURN(error >= 0 || thd->net.report_error);
}
@@ -275,11 +281,10 @@ cleanup:
conds - conditions
RETURN VALUE
- 0 - OK
- 1 - error (message is sent to user)
- -1 - error (message is not sent to user)
+ FALSE OK
+ TRUE error
*/
-int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds)
+bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds)
{
SELECT_LEX *select_lex= &thd->lex->select_lex;
DBUG_ENTER("mysql_prepare_delete");
@@ -287,19 +292,19 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds)
if (setup_tables(thd, table_list, conds) ||
setup_conds(thd, table_list, conds) ||
setup_ftfuncs(select_lex))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
if (!table_list->updatable || check_key_in_view(thd, table_list))
{
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE");
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (unique_table(table_list, table_list->next_global))
{
my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
select_lex->fix_prepare_information(thd, conds);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -323,16 +328,15 @@ extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b)
thd thread handler
RETURN
- 0 OK
- -1 Error
+ FALSE OK
+ TRUE Error
*/
-int mysql_multi_delete_prepare(THD *thd)
+bool mysql_multi_delete_prepare(THD *thd)
{
LEX *lex= thd->lex;
TABLE_LIST *aux_tables= (TABLE_LIST *)lex->auxilliary_table_list.first;
TABLE_LIST *target_tbl;
- int res= 0;
DBUG_ENTER("mysql_multi_delete_prepare");
/*
@@ -342,7 +346,7 @@ int mysql_multi_delete_prepare(THD *thd)
lex->query_tables also point on local list of DELETE SELECT_LEX
*/
if (setup_tables(thd, lex->query_tables, &lex->select_lex.where))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
/* Fix tables-to-be-deleted-from list to point at opened tables */
for (target_tbl= (TABLE_LIST*) aux_tables;
@@ -353,9 +357,9 @@ int mysql_multi_delete_prepare(THD *thd)
if (!target_tbl->correspondent_table->updatable ||
check_key_in_view(thd, target_tbl->correspondent_table))
{
- my_error(ER_NON_UPDATABLE_TABLE, MYF(0), target_tbl->real_name,
- "DELETE");
- DBUG_RETURN(-1);
+ my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
+ target_tbl->real_name, "DELETE");
+ DBUG_RETURN(TRUE);
}
/*
Check are deleted table used somewhere inside subqueries.
@@ -373,12 +377,11 @@ int mysql_multi_delete_prepare(THD *thd)
{
my_error(ER_UPDATE_TABLE_USED, MYF(0),
target_tbl->correspondent_table->real_name);
- res= -1;
- break;
+ DBUG_RETURN(TRUE);
}
}
}
- DBUG_RETURN(res);
+ DBUG_RETURN(FALSE);
}
@@ -524,7 +527,7 @@ void multi_delete::send_error(uint errcode,const char *err)
DBUG_ENTER("multi_delete::send_error");
/* First send error what ever it is ... */
- ::send_error(thd,errcode,err);
+ my_message(errcode, err, MYF(0));
/* If nothing deleted return */
if (!deleted)
@@ -670,9 +673,7 @@ bool multi_delete::send_eof()
if (ha_autocommit_or_rollback(thd,local_error > 0))
local_error=1;
- if (local_error)
- ::send_error(thd);
- else
+ if (!local_error)
{
thd->row_count_func= deleted;
::send_ok(thd, deleted);
@@ -697,12 +698,12 @@ bool multi_delete::send_eof()
- If we want to have a name lock on the table on exit without errors.
*/
-int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
+bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
{
HA_CREATE_INFO create_info;
char path[FN_REFLEN];
TABLE **table_ptr;
- int error;
+ bool error;
DBUG_ENTER("mysql_truncate");
bzero((char*) &create_info,sizeof(create_info));
@@ -738,9 +739,9 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
db_type table_type;
if ((table_type=get_table_type(path)) == DB_TYPE_UNKNOWN)
{
- my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db,
- table_list->real_name);
- DBUG_RETURN(-1);
+ my_error(ER_NO_SUCH_TABLE, MYF(0),
+ table_list->db, table_list->real_name);
+ DBUG_RETURN(TRUE);
}
if (!ha_supports_generate(table_type))
{
@@ -753,11 +754,11 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
DBUG_RETURN(error);
}
if (lock_and_wait_for_table_name(thd, table_list))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
*fn_ext(path)=0; // Remove the .frm extension
- error= ha_create_table(path,&create_info,1) ? -1 : 0;
+ error= ha_create_table(path,&create_info,1);
query_cache_invalidate3(thd, table_list, 0);
end:
@@ -784,5 +785,5 @@ end:
unlock_table_name(thd, table_list);
VOID(pthread_mutex_unlock(&LOCK_open));
}
- DBUG_RETURN(error ? -1 : 0);
+ DBUG_RETURN(error);
}
diff --git a/sql/sql_do.cc b/sql/sql_do.cc
index 25a8359f3d2..3ca3bea743a 100644
--- a/sql/sql_do.cc
+++ b/sql/sql_do.cc
@@ -20,16 +20,16 @@
#include "mysql_priv.h"
#include "sql_acl.h"
-int mysql_do(THD *thd, List<Item> &values)
+bool mysql_do(THD *thd, List<Item> &values)
{
List_iterator<Item> li(values);
Item *value;
DBUG_ENTER("mysql_do");
if (setup_fields(thd, 0, 0, values, 0, 0, 0))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
while ((value = li++))
value->val_int();
thd->clear_error(); // DO always is OK
send_ok(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_error.cc b/sql/sql_error.cc
index 3fbefdd37ef..adae481d608 100644
--- a/sql/sql_error.cc
+++ b/sql/sql_error.cc
@@ -183,14 +183,14 @@ void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
Takes into account the current LIMIT
RETURN VALUES
- 0 ok
- 1 Error sending data to client
+ FALSE ok
+ TRUE Error sending data to client
*/
static const char *warning_level_names[]= {"Note", "Warning", "Error", "?"};
static int warning_level_length[]= { 4, 7, 5, 1 };
-my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show)
+bool mysqld_show_warnings(THD *thd, ulong levels_to_show)
{
List<Item> field_list;
DBUG_ENTER("mysqld_show_warnings");
@@ -201,7 +201,7 @@ my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show)
if (thd->protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
MYSQL_ERROR *err;
SELECT_LEX *sel= &thd->lex->select_lex;
@@ -225,10 +225,10 @@ my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show)
protocol->store((uint32) err->code);
protocol->store(err->msg, strlen(err->msg), system_charset_info);
if (protocol->write())
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
if (!--limit)
break;
}
- send_eof(thd);
- DBUG_RETURN(0);
+ send_eof(thd);
+ DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index edb895fd24a..853b3dd37c6 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -140,11 +140,11 @@ static void mysql_ha_hash_free(TABLE_LIST *tables)
error messages.
RETURN
- 0 ok
- != 0 error
+ FALSE OK
+ TRUE Error
*/
-int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
+bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
{
TABLE_LIST *hash_tables;
char *db, *name, *alias;
@@ -173,8 +173,7 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
{
DBUG_PRINT("info",("duplicate '%s'", tables->alias));
if (! reopen)
- my_printf_error(ER_NONUNIQ_TABLE, ER(ER_NONUNIQ_TABLE),
- MYF(0), tables->alias);
+ my_error(ER_NONUNIQ_TABLE, MYF(0), tables->alias);
goto err;
}
}
@@ -198,7 +197,7 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
if (! (tables->table->file->table_flags() & HA_CAN_SQL_HANDLER))
{
if (! reopen)
- my_printf_error(ER_ILLEGAL_HA,ER(ER_ILLEGAL_HA),MYF(0), tables->alias);
+ my_error(ER_ILLEGAL_HA, MYF(0), tables->alias);
mysql_ha_close(thd, tables);
goto err;
}
@@ -236,11 +235,11 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
if (! reopen)
send_ok(thd);
DBUG_PRINT("exit",("OK"));
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
err:
DBUG_PRINT("exit",("ERROR"));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
@@ -257,11 +256,11 @@ err:
will be closed. Broadcasts a COND_refresh condition.
RETURN
- 0 ok
- != 0 error
+ FALSE ok
+ TRUE error
*/
-int mysql_ha_close(THD *thd, TABLE_LIST *tables)
+bool mysql_ha_close(THD *thd, TABLE_LIST *tables)
{
TABLE_LIST *hash_tables;
TABLE **table_ptr;
@@ -299,15 +298,14 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables)
}
else
{
- my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0),
- tables->alias, "HANDLER");
+ my_error(ER_UNKNOWN_TABLE, MYF(0), tables->alias, "HANDLER");
DBUG_PRINT("exit",("ERROR"));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
send_ok(thd);
DBUG_PRINT("exit", ("OK"));
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -327,15 +325,15 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables)
offset_limit
RETURN
- 0 ok
- != 0 error
+ FALSE ok
+ TRUE error
*/
-int mysql_ha_read(THD *thd, TABLE_LIST *tables,
- enum enum_ha_read_modes mode, char *keyname,
- List<Item> *key_expr,
- enum ha_rkey_function ha_rkey_mode, Item *cond,
- ha_rows select_limit,ha_rows offset_limit)
+bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
+ enum enum_ha_read_modes mode, char *keyname,
+ List<Item> *key_expr,
+ enum ha_rkey_function ha_rkey_mode, Item *cond,
+ ha_rows select_limit,ha_rows offset_limit)
{
TABLE_LIST *hash_tables;
TABLE *table;
@@ -403,11 +401,9 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
strxnmov(buff, sizeof(buff), tables->db, ".", tables->real_name, NullS);
else
strncpy(buff, tables->alias, sizeof(buff));
- my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0),
- buff, "HANDLER");
+ my_error(ER_UNKNOWN_TABLE, MYF(0), buff, "HANDLER");
#else
- my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0),
- tables->alias, "HANDLER");
+ my_error(ER_UNKNOWN_TABLE, MYF(0), tables->alias, "HANDLER");
#endif
goto err0;
}
@@ -422,8 +418,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
{
if ((keyno=find_type(keyname, &table->keynames, 1+2)-1)<0)
{
- my_printf_error(ER_KEY_DOES_NOT_EXITS,ER(ER_KEY_DOES_NOT_EXITS),MYF(0),
- keyname,tables->alias);
+ my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), keyname, tables->alias);
goto err0;
}
table->file->ha_index_or_rnd_end();
@@ -491,8 +486,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
KEY_PART_INFO *key_part=keyinfo->key_part;
if (key_expr->elements > keyinfo->key_parts)
{
- my_printf_error(ER_TOO_MANY_KEY_PARTS,ER(ER_TOO_MANY_KEY_PARTS),
- MYF(0),keyinfo->key_parts);
+ my_error(ER_TOO_MANY_KEY_PARTS, MYF(0), keyinfo->key_parts);
goto err;
}
List_iterator<Item> it_ke(*key_expr);
@@ -512,10 +506,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
key_len+=key_part->store_length;
}
if (!(key= (byte*) thd->calloc(ALIGN_SIZE(key_len))))
- {
- send_error(thd,ER_OUTOFMEMORY);
goto err;
- }
key_copy(key, table->record[0], table->key_info + keyno, key_len);
error= table->file->index_read(table->record[0],
key,key_len,ha_rkey_mode);
@@ -523,7 +514,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
break;
}
default:
- send_error(thd,ER_ILLEGAL_HA);
+ my_message(ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), MYF(0));
goto err;
}
@@ -552,7 +543,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
if (item->send(thd->protocol, &buffer))
{
protocol->free(); // Free used
- my_error(ER_OUT_OF_RESOURCES,MYF(0));
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
goto err;
}
}
@@ -564,13 +555,13 @@ ok:
mysql_unlock_tables(thd,lock);
send_eof(thd);
DBUG_PRINT("exit",("OK"));
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
err:
mysql_unlock_tables(thd,lock);
err0:
DBUG_PRINT("exit",("ERROR"));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
diff --git a/sql/sql_help.cc b/sql/sql_help.cc
index b3d7bebe96a..33bf4c481a2 100644
--- a/sql/sql_help.cc
+++ b/sql/sql_help.cc
@@ -88,7 +88,7 @@ static bool init_fields(THD *thd, TABLE_LIST *tables,
Item_field *field= new Item_field("mysql", find_fields->table_name,
find_fields->field_name);
if (!(find_fields->field= find_field_in_tables(thd, field, tables,
- 0, TRUE, 1)))
+ 0, REPORT_ALL_ERRORS, 1)))
DBUG_RETURN(1);
}
DBUG_RETURN(0);
@@ -276,7 +276,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations,
(iindex_relations= find_type((char*) primary_key_name,
&relations->keynames, 1+2)-1)<0)
{
- send_error(thd,ER_CORRUPT_HELP_DB);
+ my_message(ER_CORRUPT_HELP_DB, ER(ER_CORRUPT_HELP_DB), MYF(0));
DBUG_RETURN(-1);
}
rtopic_id= find_fields[help_relation_help_topic_id].field;
@@ -607,12 +607,11 @@ SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen,
thd Thread handler
RETURN VALUES
- 0 Success
- 1 Error and send_error already commited
- -1 error && send_error should be issued (normal case)
+ FALSE Success
+ TRUE Error and send_error already commited
*/
-int mysqld_help(THD *thd, const char *mask)
+bool mysqld_help(THD *thd, const char *mask)
{
Protocol *protocol= thd->protocol;
SQL_SELECT *select;
@@ -640,8 +639,8 @@ int mysqld_help(THD *thd, const char *mask)
uint mlen= strlen(mask);
MEM_ROOT *mem_root= thd->mem_root;
- if ((res= open_and_lock_tables(thd, tables)))
- goto end;
+ if (open_and_lock_tables(thd, tables))
+ goto error;
/*
Init tables and fields to be usable from items
@@ -650,10 +649,7 @@ int mysqld_help(THD *thd, const char *mask)
setup_tables(thd, tables, 0);
memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields));
if (init_fields(thd, tables, used_fields, array_elements(used_fields)))
- {
- res= -1;
- goto end;
- }
+ goto error;
size_t i;
for (i=0; i<sizeof(tables)/sizeof(TABLE_LIST); i++)
tables[i].table->file->init_table_handle_for_HANDLER();
@@ -661,12 +657,8 @@ int mysqld_help(THD *thd, const char *mask)
if (!(select=
prepare_select_for_name(thd,mask,mlen,tables,tables[0].table,
used_fields[help_topic_name].field,&error)))
- {
- res= -1;
- goto end;
- }
+ goto error;
- res= 1;
count_topics= search_topics(thd,tables[0].table,used_fields,
select,&topics_list,
&name, &description, &example);
@@ -678,10 +670,8 @@ int mysqld_help(THD *thd, const char *mask)
if (!(select=
prepare_select_for_name(thd,mask,mlen,tables,tables[3].table,
used_fields[help_keyword_name].field,&error)))
- {
- res= -1;
- goto end;
- }
+ goto error;
+
count_topics=search_keyword(thd,tables[3].table,used_fields,select,&key_id);
delete select;
count_topics= (count_topics != 1) ? 0 :
@@ -697,10 +687,7 @@ int mysqld_help(THD *thd, const char *mask)
if (!(select=
prepare_select_for_name(thd,mask,mlen,tables,tables[1].table,
used_fields[help_category_name].field,&error)))
- {
- res= -1;
- goto end;
- }
+ goto error;
count_categories= search_categories(thd, tables[1].table, used_fields,
select,
@@ -709,13 +696,13 @@ int mysqld_help(THD *thd, const char *mask)
if (!count_categories)
{
if (send_header_2(protocol,FALSE))
- goto end;
+ goto error;
}
else if (count_categories > 1)
{
if (send_header_2(protocol,FALSE) ||
send_variant_2_list(mem_root,protocol,&categories_list,"Y",0))
- goto end;
+ goto error;
}
else
{
@@ -728,20 +715,14 @@ int mysqld_help(THD *thd, const char *mask)
new Item_int((int32)category_id));
if (!(select= prepare_simple_select(thd,cond_topic_by_cat,
tables,tables[0].table,&error)))
- {
- res= -1;
- goto end;
- }
+ goto error;
get_all_items_for_category(thd,tables[0].table,
used_fields[help_topic_name].field,
select,&topics_list);
delete select;
if (!(select= prepare_simple_select(thd,cond_cat_by_cat,tables,
tables[1].table,&error)))
- {
- res= -1;
- goto end;
- }
+ goto error;
get_all_items_for_category(thd,tables[1].table,
used_fields[help_category_name].field,
select,&subcategories_list);
@@ -750,39 +731,36 @@ int mysqld_help(THD *thd, const char *mask)
if (send_header_2(protocol, TRUE) ||
send_variant_2_list(mem_root,protocol,&topics_list, "N",cat) ||
send_variant_2_list(mem_root,protocol,&subcategories_list,"Y",cat))
- goto end;
+ goto error;
}
}
else if (count_topics == 1)
{
if (send_answer_1(protocol,&name,&description,&example))
- goto end;
+ goto error;
}
else
{
/* First send header and functions */
if (send_header_2(protocol, FALSE) ||
send_variant_2_list(mem_root,protocol, &topics_list, "N", 0))
- goto end;
+ goto error;
if (!(select=
prepare_select_for_name(thd,mask,mlen,tables,tables[1].table,
used_fields[help_category_name].field,&error)))
- {
- res= -1;
- goto end;
- }
+ goto error;
search_categories(thd, tables[1].table, used_fields,
select,&categories_list, 0);
delete select;
/* Then send categories */
if (send_variant_2_list(mem_root,protocol, &categories_list, "Y", 0))
- goto end;
+ goto error;
}
- res= 0;
-
send_eof(thd);
end:
- DBUG_RETURN(res);
+ DBUG_RETURN(FALSE);
+error:
+ DBUG_RETURN(TRUE);
}
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 6e0260d1acb..2fddaed5f45 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -58,9 +58,7 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List<Item> &fields,
{
if (values.elements != table->fields)
{
- my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW,
- ER(ER_WRONG_VALUE_COUNT_ON_ROW),
- MYF(0),counter);
+ my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
return -1;
}
#ifndef NO_EMBEDDED_ACCESS_CHECKS
@@ -82,9 +80,7 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List<Item> &fields,
int res;
if (fields.elements != values.elements)
{
- my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW,
- ER(ER_WRONG_VALUE_COUNT_ON_ROW),
- MYF(0),counter);
+ my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
return -1;
}
@@ -100,7 +96,7 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List<Item> &fields,
if (check_unique && thd->dupp_field)
{
- my_error(ER_FIELD_SPECIFIED_TWICE,MYF(0), thd->dupp_field->field_name);
+ my_error(ER_FIELD_SPECIFIED_TWICE, MYF(0), thd->dupp_field->field_name);
return -1;
}
if (table->timestamp_field && // Don't set timestamp if used
@@ -115,12 +111,12 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List<Item> &fields,
}
-int mysql_insert(THD *thd,TABLE_LIST *table_list,
- List<Item> &fields,
- List<List_item> &values_list,
- List<Item> &update_fields,
- List<Item> &update_values,
- enum_duplicates duplic)
+bool mysql_insert(THD *thd,TABLE_LIST *table_list,
+ List<Item> &fields,
+ List<List_item> &values_list,
+ List<Item> &update_fields,
+ List<Item> &update_values,
+ enum_duplicates duplic)
{
int error, res;
/*
@@ -171,10 +167,9 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
table_list->db ? table_list->db : thd->db,
table_list->real_name))
{
- my_printf_error(ER_DELAYED_INSERT_TABLE_LOCKED,
- ER(ER_DELAYED_INSERT_TABLE_LOCKED),
- MYF(0), table_list->real_name);
- DBUG_RETURN(-1);
+ my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0),
+ table_list->real_name);
+ DBUG_RETURN(TRUE);
}
}
if ((table= delayed_get_table(thd,table_list)) && !thd->is_fatal_error)
@@ -200,7 +195,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
#endif /* EMBEDDED_LIBRARY */
res= open_and_lock_tables(thd, table_list);
if (res || thd->is_fatal_error)
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
table= table_list->table;
thd->proc_info="init";
@@ -227,9 +222,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
counter++;
if (values->elements != value_count)
{
- my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW,
- ER(ER_WRONG_VALUE_COUNT_ON_ROW),
- MYF(0),counter);
+ my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
goto abort;
}
if (setup_fields(thd, 0, table_list, *values, 0, 0, 0))
@@ -291,13 +284,18 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
if (fields.elements || !value_count)
{
restore_record(table,default_values); // Get empty record
- if (fill_record(fields, *values, 0)|| thd->net.report_error)
+ if (fill_record(thd, fields, *values, 0))
{
if (values_list.elements != 1 && !thd->net.report_error)
{
info.records++;
continue;
}
+ /*
+ TODO: set thd->abort_on_warning if values_list.elements == 1
+ and check that all items return warning in case of problem with
+ storing field.
+ */
error=1;
break;
}
@@ -308,7 +306,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
restore_record(table,default_values); // Get empty record
else
table->record[0][0]=table->default_values[0]; // Fix delete marker
- if (fill_record(table->field,*values, 0) || thd->net.report_error)
+ if (fill_record(thd, table->field, *values, 0))
{
if (values_list.elements != 1 && ! thd->net.report_error)
{
@@ -468,7 +466,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
free_underlaid_joins(thd, &thd->lex->select_lex);
table->insert_values=0;
thd->abort_on_warning= 0;
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
abort:
#ifndef EMBEDDED_LIBRARY
@@ -478,7 +476,7 @@ abort:
free_underlaid_joins(thd, &thd->lex->select_lex);
table->insert_values=0;
thd->abort_on_warning= 0;
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
@@ -612,11 +610,11 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list,
table_list Global/local table list
RETURN VALUE
- 0 OK
- -1 error (message is not sent to user)
+ FALSE OK
+ TRUE error
*/
-int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
+bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
List<Item> &fields, List_item *values,
List<Item> &update_fields, List<Item> &update_values,
enum_duplicates duplic)
@@ -624,7 +622,7 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
bool insert_into_view= (table_list->view != 0);
/* TODO: use this condition for 'WITH CHECK OPTION' */
Item *unused_conds= 0;
- int res;
+ bool res;
DBUG_ENTER("mysql_prepare_insert");
if (mysql_prepare_insert_check_table(thd, table_list, fields, &unused_conds))
@@ -639,15 +637,15 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
thd->lex->select_lex.no_wrap_view_item= 0,
res) ||
setup_fields(thd, 0, table_list, update_values, 0, 0, 0))))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
if (unique_table(table_list, table_list->next_global))
{
my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
thd->lex->select_lex.first_execution= 0;
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -739,7 +737,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
*/
store_record(table,insert_values);
restore_record(table,record[1]);
- if (fill_record(*info->update_fields, *info->update_values, 0))
+ if (fill_record(thd, *info->update_fields, *info->update_values, 0))
goto err;
/* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */
@@ -823,9 +821,7 @@ int check_that_all_fields_are_given_values(THD *thd, TABLE *entry)
if ((*field)->query_id != thd->query_id &&
((*field)->flags & NO_DEFAULT_VALUE_FLAG))
{
- my_printf_error(ER_NO_DEFAULT_FOR_FIELD,
- ER(ER_NO_DEFAULT_FOR_FIELD),MYF(0),
- (*field)->field_name);
+ my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), (*field)->field_name);
return 1;
}
}
@@ -1001,7 +997,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
{
delete tmp;
thd->fatal_error();
- my_error(ER_OUT_OF_RESOURCES,MYF(0));
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
pthread_mutex_unlock(&LOCK_delayed_create);
DBUG_RETURN(0);
}
@@ -1021,7 +1017,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
delete tmp;
thd->fatal_error();
pthread_mutex_unlock(&LOCK_delayed_create);
- net_printf(thd,ER_CANT_CREATE_THREAD,error);
+ my_error(ER_CANT_CREATE_THREAD, MYF(0), error);
DBUG_RETURN(0);
}
@@ -1649,11 +1645,11 @@ bool delayed_insert::handle_inserts(void)
thd thread handler
RETURN
- 0 OK
- -1 Error
+ FALSE OK
+ TRUE Error
*/
-int mysql_insert_select_prepare(THD *thd)
+bool mysql_insert_select_prepare(THD *thd)
{
LEX *lex= thd->lex;
DBUG_ENTER("mysql_insert_select_prepare");
@@ -1665,8 +1661,8 @@ int mysql_insert_select_prepare(THD *thd)
if (mysql_prepare_insert_check_table(thd, lex->query_tables,
lex->field_list,
&lex->select_lex.where))
- DBUG_RETURN(-1);
- DBUG_RETURN(0);
+ DBUG_RETURN(TRUE);
+ DBUG_RETURN(FALSE);
}
@@ -1742,9 +1738,9 @@ bool select_insert::send_data(List<Item> &values)
DBUG_RETURN(0);
}
if (fields->elements)
- fill_record(*fields, values, 1);
+ fill_record(thd, *fields, values, 1);
else
- fill_record(table->field, values, 1);
+ fill_record(thd, table->field, values, 1);
switch (table_list->view_check_option(thd,
thd->lex->duplicates == DUP_IGNORE))
{
@@ -1769,8 +1765,7 @@ void select_insert::send_error(uint errcode,const char *err)
{
DBUG_ENTER("select_insert::send_error");
- /* TODO error should be sent at the query processing end */
- ::send_error(thd,errcode,err);
+ my_message(errcode, err, MYF(0));
if (!table)
{
@@ -1846,8 +1841,6 @@ bool select_insert::send_eof()
if (error)
{
table->file->print_error(error,MYF(0));
- //TODO error should be sent at the query processing end
- ::send_error(thd);
DBUG_RETURN(1);
}
char buff[160];
@@ -1880,9 +1873,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
if (table->fields < values.elements)
{
- my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW,
- ER(ER_WRONG_VALUE_COUNT_ON_ROW),
- MYF(0),1);
+ my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1);
DBUG_RETURN(-1);
}
@@ -1918,7 +1909,7 @@ bool select_create::send_data(List<Item> &values)
unit->offset_limit_cnt--;
return 0;
}
- fill_record(field, values, 1);
+ fill_record(thd, field, values, 1);
if (thd->net.report_error || write_record(thd, table, &info))
return 1;
if (table->next_number_field) // Clear for next record
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 86219abc632..b65d9465b43 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -1057,6 +1057,7 @@ void st_select_lex::init_query()
first_cond_optimization= 1;
parsing_place= NO_MATTER;
no_wrap_view_item= 0;
+ link_next= 0;
}
void st_select_lex::init_select()
@@ -1308,7 +1309,7 @@ bool st_select_lex::test_limit()
if (select_limit != HA_POS_ERROR)
{
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
- "LIMIT & IN/ALL/ANY/SOME subquery");
+ "LIMIT & IN/ALL/ANY/SOME subquery");
return(1);
}
// We need only 1 row to determinate existence
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index c8b4faa47c2..ce22caa13fc 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -56,7 +56,7 @@ enum enum_sql_command {
SQLCOM_SHOW_INNODB_STATUS,
SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
- SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB,
+ SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
SQLCOM_GRANT,
@@ -342,8 +342,8 @@ protected:
TABLE *table; /* temporary table using for appending UNION results */
select_result *result;
- int res;
ulong found_rows_for_union;
+ bool res;
bool prepared, // prepare phase already performed for UNION (unit)
optimized, // optimize phase already performed for UNION (unit)
executed, // already executed
@@ -403,9 +403,9 @@ public:
void exclude_tree();
/* UNION methods */
- int prepare(THD *thd, select_result *result, ulong additional_options);
- int exec();
- int cleanup();
+ bool prepare(THD *thd, select_result *result, ulong additional_options);
+ bool exec();
+ bool cleanup();
inline void unclean() { cleaned= 0; }
void reinit_exec_mechanism();
@@ -413,7 +413,7 @@ public:
void print(String *str);
ulong init_prepare_fake_select_lex(THD *thd);
- int change_result(select_subselect *result, select_subselect *old_result);
+ bool change_result(select_subselect *result, select_subselect *old_result);
void set_limit(st_select_lex *values, st_select_lex *sl);
friend void lex_start(THD *thd, uchar *buf, uint length);
@@ -692,7 +692,7 @@ typedef struct st_lex
LEX_MASTER_INFO mi; // used by CHANGE MASTER
USER_RESOURCES mqh;
ulong thread_id,type;
- enum_sql_command sql_command;
+ enum_sql_command sql_command, orig_sql_command;
thr_lock_type lock_option, multi_lock_option;
enum SSL_type ssl_type; /* defined in violite.h */
enum my_lex_states next_state;
@@ -706,7 +706,7 @@ typedef struct st_lex
uint uint_geom_type;
uint grant, grant_tot_col, which_columns;
uint fk_delete_opt, fk_update_opt, fk_match_option;
- uint slave_thd_opt;
+ uint slave_thd_opt, start_transaction_opt;
uint8 describe;
uint8 derived_tables;
uint8 create_view_algorithm;
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 9c2a025e089..d9e4943f322 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -80,7 +80,7 @@ static int read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
String &enclosed, ulong skip_lines,
bool ignore_check_option_errors);
-int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
+bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
List<Item> &fields, enum enum_duplicates handle_duplicates,
bool read_file_from_client,thr_lock_type lock_type,
bool ignore_check_option_errors)
@@ -116,17 +116,17 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
{
my_message(ER_WRONG_FIELD_TERMINATORS,ER(ER_WRONG_FIELD_TERMINATORS),
MYF(0));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
table_list->lock_type= lock_type;
- if ((res= open_and_lock_tables(thd, table_list)))
- DBUG_RETURN(res);
+ if (open_and_lock_tables(thd, table_list))
+ DBUG_RETURN(TRUE);
if (setup_tables(thd, table_list, &unused_conds))
DBUG_RETURN(-1);
if (!table_list->updatable || check_key_in_view(thd, table_list))
{
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "LOAD");
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
table= table_list->table;
transactional_table= table->file->has_transactions();
@@ -145,14 +145,14 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
Item *unused_conds= 0;
if (setup_tables(thd, table_list, &unused_conds) ||
setup_fields(thd, 0, table_list, fields, 1, 0, 0))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
if (thd->dupp_field)
{
my_error(ER_FIELD_SPECIFIED_TWICE, MYF(0), thd->dupp_field->field_name);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (check_that_all_fields_are_given_values(thd, table))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
uint tot_length=0;
@@ -178,7 +178,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
{
my_message(ER_BLOBS_AND_NO_TERMINATED,ER(ER_BLOBS_AND_NO_TERMINATED),
MYF(0));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
/* We can't give an error in the middle when using LOCAL files */
@@ -210,7 +210,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
#if !defined(__WIN__) && !defined(OS2) && ! defined(__NETWARE__)
MY_STAT stat_info;
if (!my_stat(name,&stat_info,MYF(MY_WME)))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
// if we are not in slave thread, the file must be:
if (!thd->slave_thread &&
@@ -221,15 +221,15 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
((stat_info.st_mode & S_IFREG) == S_IFREG ||
(stat_info.st_mode & S_IFIFO) == S_IFIFO)))
{
- my_error(ER_TEXTFILE_NOT_READABLE,MYF(0),name);
- DBUG_RETURN(-1);
+ my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
+ DBUG_RETURN(TRUE);
}
if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
is_fifo = 1;
#endif
}
if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
COPY_INFO info;
@@ -244,7 +244,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
{
if (file >= 0)
my_close(file,MYF(0)); // no files in net reading
- DBUG_RETURN(-1); // Can't allocate buffers
+ DBUG_RETURN(TRUE); // Can't allocate buffers
}
#ifndef EMBEDDED_LIBRARY
diff --git a/sql/sql_map.cc b/sql/sql_map.cc
index e7e24f957c6..687e60b7c72 100644
--- a/sql/sql_map.cc
+++ b/sql/sql_map.cc
@@ -47,13 +47,12 @@ mapped_files::mapped_files(const my_string filename,byte *magic,uint magic_lengt
0L)))
{
error=errno;
- my_printf_error(0,"Can't map file: %s, errno: %d",MYF(0),
- (my_string) name,error);
+ my_error(ER_NO_FILE_MAPPING, MYF(0), (my_string) name, error);
}
}
if (map && memcmp(map,magic,magic_length))
{
- my_printf_error(0,"Wrong magic in %s",MYF(0),name);
+ my_error(ER_WRONG_MAGIC, MYF(0), name);
VOID(munmap(map,size));
map=0;
}
@@ -112,8 +111,7 @@ mapped_files *map_file(const my_string name,byte *magic,uint magic_length)
{
map->use_count++;
if (!map->map)
- my_printf_error(0,"Can't map file: %s, error: %d",MYF(0),path,
- map->error);
+ my_error(ER_NO_FILE_MAPPING, MYF(0), path, map->error);
}
VOID(pthread_mutex_unlock(&LOCK_mapped_file));
return map;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index a14a3da8391..11c02dacdad 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -166,7 +166,7 @@ static int get_or_create_user_conn(THD *thd, const char *user,
my_malloc(sizeof(struct user_conn) + temp_len+1,
MYF(MY_WME)))))
{
- send_error(thd, 0, NullS); // Out of memory
+ net_send_error(thd, 0, NullS); // Out of memory
return_val=1;
goto end;
}
@@ -184,7 +184,7 @@ static int get_or_create_user_conn(THD *thd, const char *user,
if (my_hash_insert(&hash_user_connections, (byte*) uc))
{
my_free((char*) uc,0);
- send_error(thd, 0, NullS); // Out of memory
+ net_send_error(thd, 0, NullS); // Out of memory
return_val=1;
goto end;
}
@@ -259,7 +259,7 @@ int check_user(THD *thd, enum enum_server_command command,
*/
if (opt_secure_auth_local && passwd_len == SCRAMBLE_LENGTH_323)
{
- net_printf(thd, ER_NOT_SUPPORTED_AUTH_MODE);
+ net_printf_error(thd, ER_NOT_SUPPORTED_AUTH_MODE);
mysql_log.write(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
DBUG_RETURN(-1);
}
@@ -291,8 +291,8 @@ int check_user(THD *thd, enum enum_server_command command,
NET *net= &thd->net;
if (opt_secure_auth_local)
{
- net_printf(thd, ER_SERVER_IS_IN_SECURE_AUTH_MODE,
- thd->user, thd->host_or_ip);
+ net_printf_error(thd, ER_SERVER_IS_IN_SECURE_AUTH_MODE,
+ thd->user, thd->host_or_ip);
mysql_log.write(thd, COM_CONNECT, ER(ER_SERVER_IS_IN_SECURE_AUTH_MODE),
thd->user, thd->host_or_ip);
DBUG_RETURN(-1);
@@ -331,7 +331,7 @@ int check_user(THD *thd, enum enum_server_command command,
VOID(pthread_mutex_unlock(&LOCK_thread_count));
if (!count_ok)
{ // too many connections
- send_error(thd, ER_CON_COUNT_ERROR);
+ net_send_error(thd, ER_CON_COUNT_ERROR);
DBUG_RETURN(-1);
}
}
@@ -381,14 +381,14 @@ int check_user(THD *thd, enum enum_server_command command,
}
else if (res == 2) // client gave short hash, server has long hash
{
- net_printf(thd, ER_NOT_SUPPORTED_AUTH_MODE);
+ net_printf_error(thd, ER_NOT_SUPPORTED_AUTH_MODE);
mysql_log.write(thd,COM_CONNECT,ER(ER_NOT_SUPPORTED_AUTH_MODE));
DBUG_RETURN(-1);
}
- net_printf(thd, ER_ACCESS_DENIED_ERROR,
- thd->user,
- thd->host_or_ip,
- passwd_len ? ER(ER_YES) : ER(ER_NO));
+ net_printf_error(thd, ER_ACCESS_DENIED_ERROR,
+ thd->user,
+ thd->host_or_ip,
+ passwd_len ? ER(ER_YES) : ER(ER_NO));
mysql_log.write(thd, COM_CONNECT, ER(ER_ACCESS_DENIED_ERROR),
thd->user,
thd->host_or_ip,
@@ -451,16 +451,16 @@ static int check_for_max_user_connections(THD *thd, USER_CONN *uc)
if (max_user_connections &&
max_user_connections < (uint) uc->connections)
{
- net_printf(thd,ER_TOO_MANY_USER_CONNECTIONS, uc->user);
+ net_printf_error(thd, ER_TOO_MANY_USER_CONNECTIONS, uc->user);
error=1;
goto end;
}
if (uc->user_resources.connections &&
uc->user_resources.connections <= uc->conn_per_hour)
{
- net_printf(thd, ER_USER_LIMIT_REACHED, uc->user,
- "max_connections",
- (long) uc->user_resources.connections);
+ net_printf_error(thd, ER_USER_LIMIT_REACHED, uc->user,
+ "max_connections",
+ (long) uc->user_resources.connections);
error=1;
goto end;
}
@@ -592,8 +592,8 @@ static bool check_mqh(THD *thd, uint check_command)
if (uc->user_resources.questions &&
uc->questions++ >= uc->user_resources.questions)
{
- net_printf(thd, ER_USER_LIMIT_REACHED, uc->user, "max_questions",
- (long) uc->user_resources.questions);
+ net_printf_error(thd, ER_USER_LIMIT_REACHED, uc->user, "max_questions",
+ (long) uc->user_resources.questions);
error=1;
goto end;
}
@@ -603,8 +603,8 @@ static bool check_mqh(THD *thd, uint check_command)
if (uc->user_resources.updates && uc_update_queries[check_command] &&
uc->updates++ >= uc->user_resources.updates)
{
- net_printf(thd, ER_USER_LIMIT_REACHED, uc->user, "max_updates",
- (long) uc->user_resources.updates);
+ net_printf_error(thd, ER_USER_LIMIT_REACHED, uc->user, "max_updates",
+ (long) uc->user_resources.updates);
error=1;
goto end;
}
@@ -1010,7 +1010,7 @@ pthread_handler_decl(handle_one_connection,arg)
if ((error=check_connection(thd)))
{ // Wrong permissions
if (error > 0)
- net_printf(thd,error,thd->host_or_ip);
+ net_printf_error(thd, error, thd->host_or_ip);
#ifdef __NT__
if (vio_type(net->vio) == VIO_TYPE_NAMEDPIPE)
my_sleep(1000); /* must wait after eof() */
@@ -1028,6 +1028,7 @@ pthread_handler_decl(handle_one_connection,arg)
thd->version= refresh_version;
thd->proc_info= 0;
+ thd->command= COM_SLEEP;
thd->set_time();
thd->init_for_queries();
@@ -1057,7 +1058,7 @@ pthread_handler_decl(handle_one_connection,arg)
thd->host_or_ip,
(net->last_errno ? ER(net->last_errno) :
ER(ER_UNKNOWN_ERROR)));
- send_error(thd,net->last_errno,NullS);
+ net_send_error(thd, net->last_errno, NullS);
statistic_increment(aborted_threads,&LOCK_status);
}
else if (thd->killed)
@@ -1126,8 +1127,8 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
uint length=(uint) strlen(buff);
if (buff[length-1]!='\n' && !feof(file))
{
- send_error(thd,ER_NET_PACKET_TOO_LARGE, NullS);
- thd->is_fatal_error= 1;
+ net_send_error(thd, ER_NET_PACKET_TOO_LARGE, NullS);
+ thd->fatal_error();
break;
}
while (length && (my_isspace(thd->charset(), buff[length-1]) ||
@@ -1204,7 +1205,7 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd)
if (!db || check_db_name(db))
{
- net_printf(thd,ER_WRONG_DB_NAME, db ? db : "NULL");
+ my_error(ER_WRONG_DB_NAME ,MYF(0), db ? db : "NULL");
goto err;
}
if (lower_case_table_names)
@@ -1280,7 +1281,7 @@ bool do_command(THD *thd)
statistic_increment(aborted_threads,&LOCK_status);
DBUG_RETURN(TRUE); // We have to close it.
}
- send_error(thd,net->last_errno,NullS);
+ net_send_error(thd, net->last_errno, NullS);
net->error= 0;
DBUG_RETURN(FALSE);
}
@@ -1383,8 +1384,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
db= thd->alloc(db_len + tbl_len + 2);
tbl_name= strmake(db, packet + 1, db_len)+1;
strmake(tbl_name, packet + db_len + 2, tbl_len);
- if (mysql_table_dump(thd, db, tbl_name, -1))
- send_error(thd); // dump to NET
+ mysql_table_dump(thd, db, tbl_name, -1);
break;
}
case COM_CHANGE_USER:
@@ -1409,7 +1409,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
/* Small check for incoming packet */
if ((uint) ((uchar*) db - net->read_pos) > packet_length)
{
- send_error(thd, ER_UNKNOWN_COM_ERROR);
+ my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
break;
}
#endif
@@ -1432,7 +1432,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if (!(thd->user= my_strdup(user, MYF(0))))
{
thd->user= save_user;
- send_error(thd, ER_OUT_OF_RESOURCES);
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
break;
}
@@ -1444,7 +1444,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
{
/* authentication failure, we shall restore old user */
if (res > 0)
- send_error(thd, ER_UNKNOWN_COM_ERROR);
+ my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
x_free(thd->user);
thd->user= save_user;
thd->priv_user= save_priv_user;
@@ -1502,7 +1502,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
DBUG_PRINT("query",("%-.4096s",thd->query));
mysql_parse(thd,thd->query, thd->query_length);
- while (!thd->killed && !thd->is_fatal_error && thd->lex->found_colon)
+ while (!thd->killed && thd->lex->found_colon && !thd->net.report_error)
{
char *packet= thd->lex->found_colon;
/*
@@ -1552,7 +1552,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
}
case COM_FIELD_LIST: // This isn't actually needed
#ifdef DONT_ALLOW_SHOW_COMMANDS
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
+ my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND),
+ MYF(0)); /* purecov: inspected */
break;
#else
{
@@ -1565,7 +1566,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
bzero((char*) &table_list,sizeof(table_list));
if (!(table_list.db=thd->db))
{
- send_error(thd,ER_NO_DB_ERROR);
+ my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
break;
}
pend= strend(packet);
@@ -1619,7 +1620,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
// null test to handle EOM
if (!db || !(alias= thd->strdup(db)) || check_db_name(db))
{
- net_printf(thd,ER_WRONG_DB_NAME, db ? db : "NULL");
+ my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL");
break;
}
if (check_access(thd,CREATE_ACL,db,0,1,0))
@@ -1628,7 +1629,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
bzero(&create_info, sizeof(create_info));
if (mysql_create_db(thd, (lower_case_table_names == 2 ? alias : db),
&create_info, 0) < 0)
- send_error(thd, thd->killed ? ER_SERVER_SHUTDOWN : 0);
+ error= TRUE;
break;
}
case COM_DROP_DB: // QQ: To be removed
@@ -1639,34 +1640,35 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
/* null test to handle EOM */
if (!db || !(alias= thd->strdup(db)) || check_db_name(db))
{
- net_printf(thd,ER_WRONG_DB_NAME, db ? db : "NULL");
+ my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL");
break;
}
if (check_access(thd,DROP_ACL,db,0,1,0))
break;
if (thd->locked_tables || thd->active_transaction())
{
- send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
+ my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+ ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
break;
}
mysql_log.write(thd,command,db);
if (mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : db),
0, 0) < 0)
- send_error(thd, thd->killed ? ER_SERVER_SHUTDOWN : 0);
+ error= TRUE;
break;
}
#ifndef EMBEDDED_LIBRARY
case COM_BINLOG_DUMP:
{
+ ulong pos;
+ ushort flags;
+ uint32 slave_server_id;
+
statistic_increment(thd->status_var.com_other,&LOCK_status);
thd->slow_command = TRUE;
if (check_global_access(thd, REPL_SLAVE_ACL))
break;
- mysql_log.write(thd,command, 0);
- ulong pos;
- ushort flags;
- uint32 slave_server_id;
/* TODO: The following has to be changed to an 8 byte integer */
pos = uint4korr(packet);
flags = uint2korr(packet + 4);
@@ -1674,6 +1676,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if ((slave_server_id= uint4korr(packet+6))) // mysqlbinlog.server_id==0
kill_zombie_dump_threads(slave_server_id);
thd->server_id = slave_server_id;
+
+ mysql_log.write(thd, command, "Log: '%s' Pos: %ld", packet+10,
+ (long) pos);
mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags);
unregister_slave(thd,1,1);
/* fake COM_QUIT -- if we get here, the thread needs to terminate */
@@ -1690,9 +1695,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if (check_global_access(thd,RELOAD_ACL))
break;
mysql_log.write(thd,command,NullS);
- if (reload_acl_and_cache(thd, options, (TABLE_LIST*) 0, NULL))
- send_error(thd, 0);
- else
+ if (!reload_acl_and_cache(thd, options, (TABLE_LIST*) 0, NULL))
send_ok(thd);
break;
}
@@ -1716,7 +1719,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
else if (level != SHUTDOWN_WAIT_ALL_BUFFERS)
{
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
- send_error(thd);
break;
}
DBUG_PRINT("quit",("Got shutdown command for level %u", level));
@@ -1800,7 +1802,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
send_eof(thd);
break;
default:
- send_error(thd, ER_UNKNOWN_COM_ERROR);
+ my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
break;
}
break;
@@ -1819,7 +1821,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
case COM_DELAYED_INSERT:
case COM_END:
default:
- send_error(thd, ER_UNKNOWN_COM_ERROR);
+ my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
break;
}
if (thd->lock || thd->open_tables || thd->derived_tables)
@@ -1828,8 +1830,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
close_thread_tables(thd); /* Free tables */
}
- if (thd->is_fatal_error)
- send_error(thd,0); // End of memory ?
+ /* report error issued during command execution */
+ if (thd->killed_errno() && !thd->net.report_error)
+ thd->send_kill_message();
+ if (thd->net.report_error)
+ net_send_error(thd);
time_t start_of_query=thd->start_time;
thd->end_time(); // Set start time
@@ -1864,6 +1869,111 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
}
+int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
+ enum enum_schema_tables schema_table_idx)
+{
+ DBUG_ENTER("prepare_schema_table");
+ SELECT_LEX *sel= 0;
+ switch(schema_table_idx) {
+ case SCH_SCHEMATA:
+#if defined(DONT_ALLOW_SHOW_COMMANDS)
+ my_message(ER_NOT_ALLOWED_COMMAND,
+ ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */
+ DBUG_RETURN(1);
+#else
+ if ((specialflag & SPECIAL_SKIP_SHOW_DB) &&
+ check_global_access(thd, SHOW_DB_ACL))
+ DBUG_RETURN(1);
+ break;
+#endif
+ case SCH_TABLE_NAMES:
+ case SCH_TABLES:
+ case SCH_VIEWS:
+#ifdef DONT_ALLOW_SHOW_COMMANDS
+ my_message(ER_NOT_ALLOWED_COMMAND,
+ ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */
+ DBUG_RETURN(1);
+#else
+ {
+ char *db= lex->select_lex.db ? lex->select_lex.db : thd->db;
+ if (!db)
+ {
+ my_message(ER_NO_DB_ERROR,
+ ER(ER_NO_DB_ERROR), MYF(0)); /* purecov: inspected */
+ DBUG_RETURN(1); /* purecov: inspected */
+ }
+ remove_escape(db); // Fix escaped '_'
+ if (check_db_name(db))
+ {
+ my_error(ER_WRONG_DB_NAME, MYF(0), db);
+ DBUG_RETURN(1);
+ }
+ if (check_access(thd,SELECT_ACL,db,&thd->col_access,0,0))
+ DBUG_RETURN(1); /* purecov: inspected */
+ if (!thd->col_access && check_grant_db(thd,db))
+ {
+ my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
+ thd->priv_user, thd->priv_host, db);
+ DBUG_RETURN(1);
+ }
+ lex->select_lex.db= db;
+ break;
+ }
+#endif
+ case SCH_COLUMNS:
+ case SCH_STATISTICS:
+#ifdef DONT_ALLOW_SHOW_COMMANDS
+ my_message(ER_NOT_ALLOWED_COMMAND,
+ ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */
+ DBUG_RETURN(1);
+#else
+ if (table_ident)
+ {
+ TABLE_LIST **query_tables_last= lex->query_tables_last;
+ sel= new SELECT_LEX();
+ sel->init_query();
+ if(!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ,
+ (List<String> *) 0, (List<String> *) 0))
+ DBUG_RETURN(1);
+ lex->query_tables_last= query_tables_last;
+ TABLE_LIST *table_list= (TABLE_LIST*) sel->table_list.first;
+ char *db= table_list->db;
+ remove_escape(db); // Fix escaped '_'
+ remove_escape(table_list->real_name);
+ if (check_access(thd,SELECT_ACL | EXTRA_ACL,db,
+ &table_list->grant.privilege, 0, 0))
+ DBUG_RETURN(1); /* purecov: inspected */
+ if (grant_option && check_grant(thd, SELECT_ACL, table_list, 2,
+ UINT_MAX, 0))
+ DBUG_RETURN(1);
+ break;
+ }
+#endif
+ case SCH_PROCEDURES:
+ case SCH_CHARSETS:
+ case SCH_COLLATIONS:
+ case SCH_COLLATION_CHARACTER_SET_APPLICABILITY:
+ case SCH_USER_PRIVILEGES:
+ case SCH_SCHEMA_PRIVILEGES:
+ case SCH_TABLE_PRIVILEGES:
+ case SCH_COLUMN_PRIVILEGES:
+ case SCH_TABLE_CONSTRAINTS:
+ case SCH_KEY_COLUMN_USAGE:
+ default:
+ break;
+ }
+
+ SELECT_LEX *select_lex= lex->current_select;
+ if (make_schema_select(thd, select_lex, schema_table_idx))
+ {
+ DBUG_RETURN(1);
+ }
+ TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
+ table_list->schema_select_lex= sel;
+ DBUG_RETURN(0);
+}
+
+
/*
Read query from packet and store in thd->query
Used in COM_QUERY and COM_PREPARE
@@ -1874,8 +1984,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
query_length
RETURN VALUES
- 0 ok
- 1 error; In this case thd->fatal_error is set
+ FALSE ok
+ TRUE error; In this case thd->fatal_error is set
*/
bool alloc_query(THD *thd, char *packet, ulong packet_length)
@@ -1900,7 +2010,7 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length)
packet_length,
thd->db_length+ 1 +
QUERY_CACHE_FLAGS_SIZE)))
- return 1;
+ return TRUE;
thd->query[packet_length]=0;
thd->query_length= packet_length;
@@ -1910,7 +2020,7 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length)
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);
- return 0;
+ return FALSE;
}
/****************************************************************************
@@ -1918,10 +2028,10 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length)
** Execute command saved in thd and current_lex->sql_command
****************************************************************************/
-int
+bool
mysql_execute_command(THD *thd)
{
- int res= 0;
+ bool res= FALSE;
LEX *lex= thd->lex;
/* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
SELECT_LEX *select_lex= &lex->select_lex;
@@ -1978,7 +2088,7 @@ mysql_execute_command(THD *thd)
if (all_tables_not_ok(thd, all_tables))
{
/* we warn the slave SQL thread */
- my_error(ER_SLAVE_IGNORED_TABLE, MYF(0));
+ my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
DBUG_RETURN(0);
}
#ifndef TO_BE_DELETED
@@ -2002,7 +2112,6 @@ mysql_execute_command(THD *thd)
if ((tmp= my_tz_get_table_list(thd, &lex->query_tables_last)) ==
&fake_time_zone_tables_list)
{
- send_error(thd, 0);
DBUG_RETURN(-1);
}
lex->time_zone_tables_used= tmp;
@@ -2018,7 +2127,7 @@ mysql_execute_command(THD *thd)
!(thd->slave_thread || (thd->master_access & SUPER_ACL)) &&
(uc_update_queries[lex->sql_command] > 0))
{
- net_printf(thd, ER_OPTION_PREVENTS_STATEMENT, "--read-only");
+ my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
DBUG_RETURN(-1);
}
@@ -2047,20 +2156,14 @@ mysql_execute_command(THD *thd)
lex->exchange ? SELECT_ACL | FILE_ACL : SELECT_ACL,
any_db, 0, 0, 0);
if (res)
- {
- res=0;
- break; // Error message is given
- }
+ goto error;
if (!(res= open_and_lock_tables(thd, all_tables)))
{
if (lex->describe)
{
if (!(result= new select_send()))
- {
- send_error(thd, ER_OUT_OF_RESOURCES);
goto error;
- }
else
thd->send_explain_fields(result);
res= mysql_explain_union(thd, &thd->lex->unit, result);
@@ -2080,10 +2183,7 @@ mysql_execute_command(THD *thd)
else
{
if (!result && !(result= new select_send()))
- {
- res= -1;
- break;
- }
+ goto error;
query_cache_store_query(thd, all_tables);
res= handle_select(thd, lex, result);
if (result != lex->result)
@@ -2124,10 +2224,7 @@ mysql_execute_command(THD *thd)
*/
DBUG_ASSERT(!is_var_null);
if (!pstr)
- {
- res= -1;
- break; // EOM (error should be reported by allocator)
- }
+ goto error;
}
else
{
@@ -2145,11 +2242,8 @@ mysql_execute_command(THD *thd)
query_len= need_conversion? (pstr->length() * to_cs->mbmaxlen) :
pstr->length();
if (!(query_str= alloc_root(thd->mem_root, query_len+1)))
- {
- res= -1;
- break; // EOM (error should be reported by allocator)
- }
-
+ goto error;
+
if (need_conversion)
{
uint dummy_errors;
@@ -2171,8 +2265,8 @@ mysql_execute_command(THD *thd)
query_len, query_str));
}
thd->command= COM_PREPARE;
- if (!mysql_stmt_prepare(thd, query_str, query_len + 1,
- &lex->prepared_stmt_name))
+ if (!(res= mysql_stmt_prepare(thd, query_str, query_len + 1,
+ &lex->prepared_stmt_name)))
send_ok(thd, 0L, 0L, "Statement prepared");
break;
}
@@ -2198,22 +2292,21 @@ mysql_execute_command(THD *thd)
}
else
{
- res= -1;
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0),
- lex->prepared_stmt_name.length, lex->prepared_stmt_name.str,
+ lex->prepared_stmt_name.length,
+ lex->prepared_stmt_name.str,
"DEALLOCATE PREPARE");
+ goto error;
}
break;
}
case SQLCOM_DO:
if (all_tables &&
- ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) ||
- (res= open_and_lock_tables(thd, all_tables))))
- break;
+ (check_table_access(thd, SELECT_ACL, all_tables, 0) ||
+ open_and_lock_tables(thd, all_tables)))
+ goto error;
res= mysql_do(thd, *lex->insert_list);
- if (thd->net.report_error)
- res= -1;
break;
case SQLCOM_EMPTY_QUERY:
@@ -2263,12 +2356,12 @@ mysql_execute_command(THD *thd)
goto error;
/* This query don't work now. See comment in repl_failsafe.cc */
#ifndef WORKING_NEW_MASTER
- net_printf(thd, ER_NOT_SUPPORTED_YET, "SHOW NEW MASTER");
- res= 1;
+ my_error(ER_NOT_SUPPORTED_YET, MYF(0), "SHOW NEW MASTER");
+ goto error;
#else
res = show_new_master(thd);
-#endif
break;
+#endif
}
#ifdef HAVE_REPLICATION
@@ -2364,7 +2457,7 @@ mysql_execute_command(THD *thd)
if (check_global_access(thd, SUPER_ACL))
goto error;
if (end_active_trans(thd))
- res= -1;
+ goto error;
else
res = load_master_data(thd);
break;
@@ -2395,7 +2488,7 @@ mysql_execute_command(THD *thd)
}
if (strlen(first_table->real_name) > NAME_LEN)
{
- net_printf(thd, ER_WRONG_TABLE_NAME, first_table->real_name);
+ my_error(ER_WRONG_TABLE_NAME, MYF(0), first_table->real_name);
break;
}
pthread_mutex_lock(&LOCK_active_mi);
@@ -2422,7 +2515,7 @@ mysql_execute_command(THD *thd)
TABLE_LIST *select_tables= lex->query_tables;
if ((res= create_table_precheck(thd, select_tables, create_table)))
- goto unsent_create_error;
+ goto create_error;
#ifndef HAVE_READLINK
lex->create_info.data_file_name=lex->create_info.index_file_name=0;
@@ -2432,10 +2525,7 @@ mysql_execute_command(THD *thd)
create_table->real_name) ||
append_file_to_dir(thd, &lex->create_info.index_file_name,
create_table->real_name))
- {
- res=-1;
- goto unsent_create_error;
- }
+ goto create_error;
#endif
/*
If we are using SET CHARSET without DEFAULT, add an implicit
@@ -2466,7 +2556,7 @@ mysql_execute_command(THD *thd)
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) &&
unique_table(create_table, select_tables))
{
- net_printf(thd, ER_UPDATE_TABLE_USED, create_table->real_name);
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table->real_name);
goto create_error;
}
/* If we create merge table, we have to test tables in merge, too */
@@ -2479,7 +2569,7 @@ mysql_execute_command(THD *thd)
{
if (unique_table(tab, select_tables))
{
- net_printf(thd, ER_UPDATE_TABLE_USED, tab->real_name);
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), tab->real_name);
goto create_error;
}
}
@@ -2526,11 +2616,9 @@ mysql_execute_command(THD *thd)
break;
create_error:
- res= 1; //error reported
-unsent_create_error:
/* put tables back for PS rexecuting */
lex->link_first_table_back(create_table, link_to_local);
- break;
+ goto error;
}
case SQLCOM_CREATE_INDEX:
DBUG_ASSERT(first_table == all_tables && first_table != 0);
@@ -2538,7 +2626,7 @@ unsent_create_error:
goto error; /* purecov: inspected */
thd->slow_command=TRUE;
if (end_active_trans(thd))
- res= -1;
+ goto error;
else
res = mysql_create_index(thd, first_table, lex->key_list);
break;
@@ -2567,7 +2655,8 @@ unsent_create_error:
*/
if (thd->locked_tables || thd->active_transaction())
{
- send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
+ my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION),
+ MYF(0));
goto error;
}
{
@@ -2581,16 +2670,16 @@ unsent_create_error:
case SQLCOM_ALTER_TABLE:
DBUG_ASSERT(first_table == all_tables && first_table != 0);
#if defined(DONT_ALLOW_SHOW_COMMANDS)
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
+ my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND),
+ MYF(0)); /* purecov: inspected */
goto error;
#else
{
ulong priv=0;
if (lex->name && (!lex->name[0] || strlen(lex->name) > NAME_LEN))
{
- net_printf(thd, ER_WRONG_TABLE_NAME, lex->name);
- res= 1;
- break;
+ my_error(ER_WRONG_TABLE_NAME, MYF(0), lex->name);
+ goto error;
}
if (!select_lex->db)
select_lex->db= first_table->db;
@@ -2621,7 +2710,7 @@ unsent_create_error:
lex->create_info.data_file_name=lex->create_info.index_file_name=0;
/* ALTER TABLE ends previous transaction */
if (end_active_trans(thd))
- res= -1;
+ goto error;
else
{
thd->slow_command=TRUE;
@@ -2666,16 +2755,15 @@ unsent_create_error:
}
}
query_cache_invalidate3(thd, first_table, 0);
- if (end_active_trans(thd))
- res= -1;
- else if (mysql_rename_tables(thd, first_table))
- res= -1;
+ if (end_active_trans(thd) || mysql_rename_tables(thd, first_table))
+ goto error;
break;
}
#ifndef EMBEDDED_LIBRARY
case SQLCOM_SHOW_BINLOGS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
+ my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND),
+ MYF(0)); /* purecov: inspected */
goto error;
#else
{
@@ -2689,7 +2777,8 @@ unsent_create_error:
case SQLCOM_SHOW_CREATE:
DBUG_ASSERT(first_table == all_tables && first_table != 0);
#ifdef DONT_ALLOW_SHOW_COMMANDS
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
+ my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND),
+ MYF(0)); /* purecov: inspected */
goto error;
#else
{
@@ -2795,8 +2884,6 @@ unsent_create_error:
(ORDER *) select_lex->order_list.first,
select_lex->select_limit,
lex->duplicates);
- if (thd->net.report_error)
- res= -1;
break;
case SQLCOM_UPDATE_MULTI:
{
@@ -2821,8 +2908,6 @@ unsent_create_error:
select_lex->item_list, lex->value_list,
(lex->value_list.elements ?
DUP_UPDATE : lex->duplicates));
- if (thd->net.report_error)
- res= -1;
if (first_table->view && !first_table->contain_auto_increment)
thd->last_insert_id= 0; // do not show last insert ID if VIEW have not it
break;
@@ -2875,11 +2960,9 @@ unsent_create_error:
lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
delete result;
}
- if (thd->net.report_error)
- res= -1;
}
else
- res= -1;
+ res= TRUE;
if (first_table->view && !first_table->contain_auto_increment)
thd->last_insert_id= 0; // do not show last insert ID if VIEW have not it
@@ -2896,7 +2979,8 @@ unsent_create_error:
*/
if (thd->locked_tables || thd->active_transaction())
{
- send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION,NullS);
+ my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+ ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
goto error;
}
@@ -2910,8 +2994,6 @@ unsent_create_error:
res = mysql_delete(thd, all_tables, select_lex->where,
&select_lex->order_list,
select_lex->select_limit, select_lex->options);
- if (thd->net.report_error)
- res= -1;
break;
}
case SQLCOM_DELETE_MULTI:
@@ -2929,15 +3011,12 @@ unsent_create_error:
if (select_lex->item_list.elements != 0)
select_lex->item_list.empty();
if (add_item_to_list(thd, new Item_null()))
- {
- res= -1;
- break;
- }
+ goto error;
thd->proc_info="init";
if ((res= open_and_lock_tables(thd, all_tables)) ||
(res= mysql_multi_delete_prepare(thd)))
- break;
+ goto error;
if (!thd->is_fatal_error && (result= new multi_delete(thd,aux_tables,
table_count)))
@@ -2952,12 +3031,10 @@ unsent_create_error:
select_lex->options | thd->options |
SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK,
result, unit, select_lex);
- if (thd->net.report_error)
- res= -1;
delete result;
}
else
- res= -1; // Error is not sent
+ res= TRUE;
close_thread_tables(thd);
break;
}
@@ -2969,10 +3046,7 @@ unsent_create_error:
if (check_table_access(thd, DROP_ACL, all_tables, 0))
goto error; /* purecov: inspected */
if (end_active_trans(thd))
- {
- res= -1;
- break;
- }
+ goto error;
}
else
{
@@ -2996,21 +3070,10 @@ unsent_create_error:
if (check_one_table_access(thd, INDEX_ACL, all_tables))
goto error; /* purecov: inspected */
if (end_active_trans(thd))
- res= -1;
+ goto error;
else
res = mysql_drop_index(thd, first_table, &lex->alter_info);
break;
- case SQLCOM_SHOW_DATABASES:
-#if defined(DONT_ALLOW_SHOW_COMMANDS)
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- goto error;
-#else
- if ((specialflag & SPECIAL_SKIP_SHOW_DB) &&
- check_global_access(thd, SHOW_DB_ACL))
- goto error;
- res= mysqld_show_dbs(thd, (lex->wild ? lex->wild->ptr() : NullS));
- break;
-#endif
case SQLCOM_SHOW_PROCESSLIST:
if (!thd->priv_user[0] && check_global_access(thd,PROCESS_ACL))
break;
@@ -3048,7 +3111,8 @@ unsent_create_error:
break;
case SQLCOM_SHOW_LOGS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
+ my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND),
+ MYF(0)); /* purecov: inspected */
goto error;
#else
{
@@ -3058,95 +3122,9 @@ unsent_create_error:
break;
}
#endif
- case SQLCOM_SHOW_TABLES:
- /* FALL THROUGH */
-#ifdef DONT_ALLOW_SHOW_COMMANDS
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- goto error;
-#else
- {
- char *db=select_lex->db ? select_lex->db : thd->db;
- if (!db)
- {
- send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */
- goto error; /* purecov: inspected */
- }
- remove_escape(db); // Fix escaped '_'
- if (check_db_name(db))
- {
- net_printf(thd,ER_WRONG_DB_NAME, db);
- goto error;
- }
- if (check_access(thd,SELECT_ACL,db,&thd->col_access,0,0))
- goto error; /* purecov: inspected */
- if (!thd->col_access && check_grant_db(thd,db))
- {
- net_printf(thd, ER_DBACCESS_DENIED_ERROR,
- thd->priv_user,
- thd->priv_host,
- db);
- goto error;
- }
- /* grant is checked in mysqld_show_tables */
- if (lex->describe)
- res= mysqld_extend_show_tables(thd,db,
- (lex->wild ? lex->wild->ptr() : NullS));
- else
- res= mysqld_show_tables(thd, db,
- (lex->wild ? lex->wild->ptr() : NullS),
- lex->verbose);
- break;
- }
-#endif
case SQLCOM_SHOW_OPEN_TABLES:
res= mysqld_show_open_tables(thd,(lex->wild ? lex->wild->ptr() : NullS));
break;
- case SQLCOM_SHOW_CHARSETS:
- res= mysqld_show_charsets(thd,(lex->wild ? lex->wild->ptr() : NullS));
- break;
- case SQLCOM_SHOW_COLLATIONS:
- res= mysqld_show_collations(thd,(lex->wild ? lex->wild->ptr() : NullS));
- break;
- case SQLCOM_SHOW_FIELDS:
- DBUG_ASSERT(first_table == all_tables && first_table != 0);
-#ifdef DONT_ALLOW_SHOW_COMMANDS
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- goto error;
-#else
- {
- char *db= first_table->db;
- remove_escape(db); // Fix escaped '_'
- remove_escape(first_table->real_name);
- if (check_access(thd,SELECT_ACL | EXTRA_ACL,db,
- &first_table->grant.privilege, 0, 0))
- goto error; /* purecov: inspected */
- if (grant_option && check_grant(thd, SELECT_ACL, first_table, 2, UINT_MAX, 0))
- goto error;
- res= mysqld_show_fields(thd, first_table,
- (lex->wild ? lex->wild->ptr() : NullS),
- lex->verbose);
- break;
- }
-#endif
- case SQLCOM_SHOW_KEYS:
- DBUG_ASSERT(first_table == all_tables && first_table != 0);
-#ifdef DONT_ALLOW_SHOW_COMMANDS
- send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
- goto error;
-#else
- {
- char *db= first_table->db;
- remove_escape(db); // Fix escaped '_'
- remove_escape(first_table->real_name);
- if (check_access(thd,SELECT_ACL | EXTRA_ACL,db,
- &first_table->grant.privilege, 0, 0))
- goto error; /* purecov: inspected */
- if (grant_option && check_grant(thd, SELECT_ACL, all_tables, 2, UINT_MAX, 0))
- goto error;
- res= mysqld_show_keys(thd, first_table);
- break;
- }
-#endif
case SQLCOM_CHANGE_DB:
mysql_change_db(thd,select_lex->db);
break;
@@ -3167,7 +3145,7 @@ unsent_create_error:
if (!(thd->client_capabilities & CLIENT_LOCAL_FILES) ||
! opt_local_infile)
{
- send_error(thd,ER_NOT_ALLOWED_COMMAND);
+ my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), MYF(0));
goto error;
}
if (check_one_table_access(thd, privilege, all_tables))
@@ -3183,15 +3161,13 @@ unsent_create_error:
{
List<set_var_base> *lex_var_list= &lex->var_list;
if (all_tables &&
- ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) ||
- (res= open_and_lock_tables(thd, all_tables))))
- break;
+ (check_table_access(thd, SELECT_ACL, all_tables, 0) ||
+ open_and_lock_tables(thd, all_tables)))
+ goto error;
if (lex->one_shot_set && not_all_support_one_shot(lex_var_list))
{
- my_printf_error(0, "The SET ONE_SHOT syntax is reserved for \
-purposes internal to the MySQL server", MYF(0));
- res= -1;
- break;
+ my_error(ER_RESERVED_SYNTAX, MYF(0), "SET ONE_SHOT");
+ goto error;
}
if (!(res= sql_set_variables(thd, lex_var_list)))
{
@@ -3202,12 +3178,16 @@ purposes internal to the MySQL server", MYF(0));
thd->one_shot_set|= lex->one_shot_set;
send_ok(thd);
}
- if (thd->net.report_error)
- res= -1;
break;
}
case SQLCOM_UNLOCK_TABLES:
+ /*
+ It is critical for mysqldump --single-transaction --master-data that
+ UNLOCK TABLES does not implicitely commit a connection which has only
+ done FLUSH TABLES WITH READ LOCK + BEGIN. If this assumption becomes
+ false, mysqldump will not work.
+ */
unlock_locked_tables(thd);
if (thd->options & OPTION_TABLE_LOCK)
{
@@ -3246,7 +3226,7 @@ purposes internal to the MySQL server", MYF(0));
char *alias;
if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name))
{
- net_printf(thd,ER_WRONG_DB_NAME, lex->name);
+ my_error(ER_WRONG_DB_NAME, MYF(0), lex->name);
break;
}
/*
@@ -3261,7 +3241,7 @@ purposes internal to the MySQL server", MYF(0));
(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
!db_ok_with_wild_table(lex->name)))
{
- my_error(ER_SLAVE_IGNORED_TABLE, MYF(0));
+ my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
break;
}
#endif
@@ -3276,7 +3256,7 @@ purposes internal to the MySQL server", MYF(0));
char *alias;
if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name))
{
- net_printf(thd, ER_WRONG_DB_NAME, lex->name);
+ my_error(ER_WRONG_DB_NAME, MYF(0), lex->name);
break;
}
/*
@@ -3291,7 +3271,7 @@ purposes internal to the MySQL server", MYF(0));
(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
!db_ok_with_wild_table(lex->name)))
{
- my_error(ER_SLAVE_IGNORED_TABLE, MYF(0));
+ my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
break;
}
#endif
@@ -3299,7 +3279,8 @@ purposes internal to the MySQL server", MYF(0));
break;
if (thd->locked_tables || thd->active_transaction())
{
- send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
+ my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+ ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
goto error;
}
res=mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : lex->name),
@@ -3310,7 +3291,7 @@ purposes internal to the MySQL server", MYF(0));
{
if (!strip_sp(lex->name) || check_db_name(lex->name))
{
- net_printf(thd, ER_WRONG_DB_NAME, lex->name);
+ my_error(ER_WRONG_DB_NAME, MYF(0), lex->name);
break;
}
/*
@@ -3325,7 +3306,7 @@ purposes internal to the MySQL server", MYF(0));
(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
!db_ok_with_wild_table(lex->name)))
{
- my_error(ER_SLAVE_IGNORED_TABLE, MYF(0));
+ my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
break;
}
#endif
@@ -3333,7 +3314,8 @@ purposes internal to the MySQL server", MYF(0));
break;
if (thd->locked_tables || thd->active_transaction())
{
- send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
+ my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+ ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
goto error;
}
res=mysql_alter_db(thd,lex->name,&lex->create_info);
@@ -3343,14 +3325,15 @@ purposes internal to the MySQL server", MYF(0));
{
if (!strip_sp(lex->name) || check_db_name(lex->name))
{
- net_printf(thd,ER_WRONG_DB_NAME, lex->name);
+ my_error(ER_WRONG_DB_NAME, MYF(0), lex->name);
break;
}
if (check_access(thd,SELECT_ACL,lex->name,0,1,0))
break;
if (thd->locked_tables || thd->active_transaction())
{
- send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
+ my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+ ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
goto error;
}
res=mysqld_show_create_db(thd,lex->name,&lex->create_info);
@@ -3364,13 +3347,13 @@ purposes internal to the MySQL server", MYF(0));
#ifdef HAVE_DLOPEN
if ((sph= sp_find_function(thd, lex->spname)))
{
- net_printf(thd, ER_UDF_EXISTS, lex->spname->m_name.str);
+ my_error(ER_UDF_EXISTS, MYF(0), lex->spname->m_name.str);
goto error;
}
if (!(res = mysql_create_function(thd,&lex->udf)))
send_ok(thd);
#else
- res= -1;
+ res= TRUE;
#endif
break;
}
@@ -3449,8 +3432,9 @@ purposes internal to the MySQL server", MYF(0));
{
if (lex->columns.elements)
{
- send_error(thd,ER_ILLEGAL_GRANT_FOR_TABLE);
- res=1;
+ my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE),
+ MYF(0));
+ goto error;
}
else
res = mysql_grant(thd, select_lex->db, lex->users_list, lex->grant,
@@ -3490,9 +3474,7 @@ purposes internal to the MySQL server", MYF(0));
binlog or not.
*/
bool write_to_binlog;
- if (reload_acl_and_cache(thd, lex->type, first_table, &write_to_binlog))
- send_error(thd, 0);
- else
+ if (!reload_acl_and_cache(thd, lex->type, first_table, &write_to_binlog))
{
/*
We WANT to write and we CAN write.
@@ -3515,7 +3497,6 @@ purposes internal to the MySQL server", MYF(0));
break;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
case SQLCOM_SHOW_GRANTS:
- res=0;
if ((thd->priv_user &&
!strcmp(thd->priv_user,lex->grant_user->user.str)) ||
!check_access(thd, SELECT_ACL, "mysql",0,1,0))
@@ -3559,15 +3540,15 @@ purposes internal to the MySQL server", MYF(0));
close_thread_tables(thd); // Free tables
}
if (end_active_trans(thd))
- {
- res= -1;
- }
+ goto error;
else
{
thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) |
OPTION_BEGIN);
thd->server_status|= SERVER_STATUS_IN_TRANS;
- send_ok(thd);
+ if (!(lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) ||
+ !(res= ha_start_consistent_snapshot(thd)))
+ send_ok(thd);
}
break;
case SQLCOM_COMMIT:
@@ -3584,7 +3565,7 @@ purposes internal to the MySQL server", MYF(0));
send_ok(thd);
}
else
- res= -1;
+ goto error;
break;
}
case SQLCOM_ROLLBACK:
@@ -3606,7 +3587,7 @@ purposes internal to the MySQL server", MYF(0));
send_ok(thd);
}
else
- res= -1;
+ res= TRUE;
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
break;
case SQLCOM_ROLLBACK_TO_SAVEPOINT:
@@ -3618,29 +3599,26 @@ purposes internal to the MySQL server", MYF(0));
send_ok(thd);
}
else
- res= -1;
+ goto error;
break;
case SQLCOM_SAVEPOINT:
if (!ha_savepoint(thd, lex->savepoint_name))
send_ok(thd);
else
- res= -1;
+ goto error;
break;
case SQLCOM_CREATE_PROCEDURE:
case SQLCOM_CREATE_SPFUNCTION:
{
uint namelen;
char *name;
+ int result;
- if (!lex->sphead)
- {
- res= -1; // Shouldn't happen
- break;
- }
+ DBUG_ASSERT(lex->sphead);
if (! lex->sphead->m_db.str)
{
- send_error(thd,ER_NO_DB_ERROR);
+ my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
delete lex->sphead;
lex->sphead= 0;
goto error;
@@ -3654,7 +3632,7 @@ purposes internal to the MySQL server", MYF(0));
if (udf)
{
- net_printf(thd, ER_UDF_EXISTS, name);
+ my_error(ER_UDF_EXISTS, MYF(0), name);
delete lex->sphead;
lex->sphead= 0;
goto error;
@@ -3664,14 +3642,14 @@ purposes internal to the MySQL server", MYF(0));
if (lex->sphead->m_type == TYPE_ENUM_FUNCTION &&
!lex->sphead->m_has_return)
{
- net_printf(thd, ER_SP_NORETURN, name);
+ my_error(ER_SP_NORETURN, MYF(0), name);
delete lex->sphead;
lex->sphead= 0;
goto error;
}
- res= lex->sphead->create(thd);
- switch (res) {
+ res= (result= lex->sphead->create(thd));
+ switch (result) {
case SP_OK:
send_ok(thd);
lex->unit.cleanup();
@@ -3679,19 +3657,19 @@ purposes internal to the MySQL server", MYF(0));
lex->sphead= 0;
break;
case SP_WRITE_ROW_FAILED:
- net_printf(thd, ER_SP_ALREADY_EXISTS, SP_TYPE_STRING(lex), name);
+ my_error(ER_SP_ALREADY_EXISTS, MYF(0), SP_TYPE_STRING(lex), name);
lex->unit.cleanup();
delete lex->sphead;
lex->sphead= 0;
goto error;
case SP_NO_DB_ERROR:
- net_printf(thd, ER_BAD_DB_ERROR, lex->sphead->m_db.str);
+ my_error(ER_BAD_DB_ERROR, MYF(0), lex->sphead->m_db.str);
lex->unit.cleanup();
delete lex->sphead;
lex->sphead= 0;
goto error;
default:
- net_printf(thd, ER_SP_STORE_FAILED, SP_TYPE_STRING(lex), name);
+ my_error(ER_SP_STORE_FAILED, MYF(0), SP_TYPE_STRING(lex), name);
lex->unit.cleanup();
delete lex->sphead;
lex->sphead= 0;
@@ -3705,8 +3683,8 @@ purposes internal to the MySQL server", MYF(0));
if (!(sp= sp_find_procedure(thd, lex->spname)))
{
- net_printf(thd, ER_SP_DOES_NOT_EXIST, "PROCEDURE",
- lex->spname->m_qname.str);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PROCEDURE",
+ lex->spname->m_qname.str);
goto error;
}
else
@@ -3720,17 +3698,11 @@ purposes internal to the MySQL server", MYF(0));
/* In case the arguments are subselects... */
if (all_tables &&
- ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) ||
- (res= open_and_lock_tables(thd, all_tables))))
- {
- break;
- }
+ (check_table_access(thd, SELECT_ACL, all_tables, 0) ||
+ open_and_lock_tables(thd, all_tables)))
+ goto error;
#ifndef EMBEDDED_LIBRARY
- /*
- When executing substatements, they're assumed to send_error when
- it happens, but not to send_ok.
- */
my_bool nsok= thd->net.no_send_ok;
thd->net.no_send_ok= TRUE;
#endif
@@ -3738,7 +3710,7 @@ purposes internal to the MySQL server", MYF(0));
{
if (! (thd->client_capabilities & CLIENT_MULTI_RESULTS))
{
- send_error(thd, ER_SP_BADSELECT);
+ my_message(ER_SP_BADSELECT, ER(ER_SP_BADSELECT), MYF(0));
#ifndef EMBEDDED_LIBRARY
thd->net.no_send_ok= nsok;
#endif
@@ -3771,7 +3743,7 @@ purposes internal to the MySQL server", MYF(0));
thd->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
}
- if (res == 0)
+ if (!res)
send_ok(thd, (ulong) (thd->row_count_func < 0 ? 0 : thd->row_count_func));
else
goto error; // Substatement should already have sent error
@@ -3781,6 +3753,7 @@ purposes internal to the MySQL server", MYF(0));
case SQLCOM_ALTER_PROCEDURE:
case SQLCOM_ALTER_FUNCTION:
{
+ int result;
sp_head *sp;
st_sp_chistics chistics;
@@ -3791,32 +3764,29 @@ purposes internal to the MySQL server", MYF(0));
sp= sp_find_function(thd, lex->spname);
mysql_reset_errors(thd);
if (! sp)
- res= SP_KEY_NOT_FOUND;
+ result= SP_KEY_NOT_FOUND;
else
{
if (check_sp_definer_access(thd, sp))
- {
- res= -1;
- break;
- }
+ goto error;
memcpy(&lex->sp_chistics, &chistics, sizeof(lex->sp_chistics));
if (lex->sql_command == SQLCOM_ALTER_PROCEDURE)
- res= sp_update_procedure(thd, lex->spname, &lex->sp_chistics);
+ result= sp_update_procedure(thd, lex->spname, &lex->sp_chistics);
else
- res= sp_update_function(thd, lex->spname, &lex->sp_chistics);
+ result= sp_update_function(thd, lex->spname, &lex->sp_chistics);
}
- switch (res)
+ switch (result)
{
case SP_OK:
send_ok(thd);
break;
case SP_KEY_NOT_FOUND:
- net_printf(thd, ER_SP_DOES_NOT_EXIST, SP_COM_STRING(lex),
- lex->spname->m_qname.str);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
+ SP_COM_STRING(lex), lex->spname->m_qname.str);
goto error;
default:
- net_printf(thd, ER_SP_CANT_ALTER, SP_COM_STRING(lex),
- lex->spname->m_qname.str);
+ my_error(ER_SP_CANT_ALTER, MYF(0),
+ SP_COM_STRING(lex), lex->spname->m_qname.str);
goto error;
}
break;
@@ -3825,6 +3795,7 @@ purposes internal to the MySQL server", MYF(0));
case SQLCOM_DROP_FUNCTION:
{
sp_head *sp;
+ int result;
if (lex->sql_command == SQLCOM_DROP_PROCEDURE)
sp= sp_find_procedure(thd, lex->spname);
@@ -3832,21 +3803,18 @@ purposes internal to the MySQL server", MYF(0));
sp= sp_find_function(thd, lex->spname);
mysql_reset_errors(thd);
if (! sp)
- res= SP_KEY_NOT_FOUND;
+ result= SP_KEY_NOT_FOUND;
else
{
if (check_sp_definer_access(thd, sp))
- {
- res= -1;
- break;
- }
+ goto error;
if (lex->sql_command == SQLCOM_DROP_PROCEDURE)
- res= sp_drop_procedure(thd, lex->spname);
+ result= sp_drop_procedure(thd, lex->spname);
else
{
- res= sp_drop_function(thd, lex->spname);
+ result= sp_drop_function(thd, lex->spname);
#ifdef HAVE_DLOPEN
- if (res == SP_KEY_NOT_FOUND)
+ if (result == SP_KEY_NOT_FOUND)
{
udf_func *udf = find_udf(lex->spname->m_name.str,
lex->spname->m_name.length);
@@ -3864,7 +3832,8 @@ purposes internal to the MySQL server", MYF(0));
#endif
}
}
- switch (res)
+ res= result;
+ switch (result)
{
case SP_OK:
send_ok(thd);
@@ -3875,34 +3844,31 @@ purposes internal to the MySQL server", MYF(0));
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
SP_COM_STRING(lex), lex->spname->m_name.str);
- res= 0;
+ res= FALSE;
send_ok(thd);
break;
}
- net_printf(thd, ER_SP_DOES_NOT_EXIST, SP_COM_STRING(lex),
- lex->spname->m_qname.str);
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
+ SP_COM_STRING(lex), lex->spname->m_qname.str);
goto error;
default:
- net_printf(thd, ER_SP_DROP_FAILED, SP_COM_STRING(lex),
- lex->spname->m_qname.str);
+ my_error(ER_SP_DROP_FAILED, MYF(0),
+ SP_COM_STRING(lex), lex->spname->m_qname.str);
goto error;
}
break;
}
case SQLCOM_SHOW_CREATE_PROC:
{
- res= -1;
if (lex->spname->m_name.length > NAME_LEN)
{
- net_printf(thd, ER_TOO_LONG_IDENT, lex->spname->m_name.str);
+ my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
goto error;
}
- res= sp_show_create_procedure(thd, lex->spname);
- if (res != SP_OK)
+ if (sp_show_create_procedure(thd, lex->spname) != SP_OK)
{ /* We don't distinguish between errors for now */
- net_printf(thd, ER_SP_DOES_NOT_EXIST,
- SP_COM_STRING(lex), lex->spname->m_name.str);
- res= 0;
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
+ SP_COM_STRING(lex), lex->spname->m_name.str);
goto error;
}
break;
@@ -3911,18 +3877,15 @@ purposes internal to the MySQL server", MYF(0));
{
if (lex->spname->m_name.length > NAME_LEN)
{
- net_printf(thd, ER_TOO_LONG_IDENT, lex->spname->m_name.str);
+ my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
goto error;
}
- res= sp_show_create_function(thd, lex->spname);
- if (res != SP_OK)
+ if (sp_show_create_function(thd, lex->spname) != SP_OK)
{ /* We don't distinguish between errors for now */
- net_printf(thd, ER_SP_DOES_NOT_EXIST,
- SP_COM_STRING(lex), lex->spname->m_name.str);
- res= 0;
+ my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
+ SP_COM_STRING(lex), lex->spname->m_name.str);
goto error;
}
- res= 0;
break;
}
case SQLCOM_SHOW_STATUS_PROC:
@@ -3944,13 +3907,9 @@ purposes internal to the MySQL server", MYF(0));
}
case SQLCOM_DROP_VIEW:
{
- if (check_table_access(thd, DROP_ACL, all_tables, 0))
- goto error;
- if (end_active_trans(thd))
- {
- res= -1;
- break;
- }
+ if (check_table_access(thd, DROP_ACL, all_tables, 0) ||
+ end_active_trans(thd))
+ goto error;
res= mysql_drop_view(thd, first_table, thd->lex->drop_mode);
break;
}
@@ -4018,17 +3977,10 @@ purposes internal to the MySQL server", MYF(0));
thd->row_count_func= -1;
}
- /*
- We end up here if res == 0 and send_ok() has been done,
- or res != 0 and no send_error() has yet been done.
- */
- if (res < 0)
- send_error(thd,thd->killed_errno());
- DBUG_RETURN(res);
+ DBUG_RETURN(res || thd->net.report_error);
error:
- /* We end up here if send_error() has already been done. */
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
@@ -4107,7 +4059,8 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
{
DBUG_PRINT("error",("No database"));
if (!no_errors)
- send_error(thd,ER_NO_DB_ERROR); /* purecov: tested */
+ my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR),
+ MYF(0)); /* purecov: tested */
DBUG_RETURN(TRUE); /* purecov: tested */
}
@@ -4134,10 +4087,12 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
{ // We can never grant this
DBUG_PRINT("error",("No possible access"));
if (!no_errors)
- net_printf(thd,ER_ACCESS_DENIED_ERROR,
- thd->priv_user,
- thd->priv_host,
- thd->password ? ER(ER_YES) : ER(ER_NO));/* purecov: tested */
+ my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
+ thd->priv_user,
+ thd->priv_host,
+ (thd->password ?
+ ER(ER_YES) :
+ ER(ER_NO))); /* purecov: tested */
DBUG_RETURN(TRUE); /* purecov: tested */
}
@@ -4164,10 +4119,12 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
DBUG_PRINT("error",("Access denied"));
if (!no_errors)
- net_printf(thd,ER_DBACCESS_DENIED_ERROR,
- thd->priv_user,
- thd->priv_host,
- db ? db : thd->db ? thd->db : "unknown"); /* purecov: tested */
+ my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
+ thd->priv_user,
+ thd->priv_host,
+ (db ? db : (thd->db ?
+ thd->db :
+ "unknown"))); /* purecov: tested */
DBUG_RETURN(TRUE); /* purecov: tested */
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
}
@@ -4201,8 +4158,7 @@ bool check_global_access(THD *thd, ulong want_access)
if ((thd->master_access & want_access))
return 0;
get_privilege_desc(command, sizeof(command), want_access);
- net_printf(thd,ER_SPECIFIC_ACCESS_DENIED_ERROR,
- command);
+ my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), command);
return 1;
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
}
@@ -4222,7 +4178,7 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables,
TABLE_LIST *org_tables=tables;
for (; tables; tables= tables->next_global)
{
- if (tables->derived ||
+ if (tables->derived || tables->schema_table ||
(tables->table && (int)tables->table->tmp_table) ||
my_tz_check_n_skip_implicit_tables(&tables,
thd->lex->time_zone_tables_used))
@@ -4317,7 +4273,8 @@ static bool check_db_used(THD *thd,TABLE_LIST *tables)
{
if (!(tables->db=thd->db))
{
- send_error(thd,ER_NO_DB_ERROR); /* purecov: tested */
+ my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR),
+ MYF(0)); /* purecov: tested */
return TRUE; /* purecov: tested */
}
}
@@ -4478,6 +4435,8 @@ mysql_init_select(LEX *lex)
SELECT_LEX *select_lex= lex->current_select;
select_lex->init_select();
select_lex->select_limit= HA_POS_ERROR;
+ lex->orig_sql_command= SQLCOM_END;
+ lex->wild= 0;
if (select_lex == &lex->select_lex)
{
DBUG_ASSERT(lex->result == 0);
@@ -4517,7 +4476,7 @@ mysql_new_select(LEX *lex, bool move_down)
{
if (lex->current_select->order_list.first && !lex->current_select->braces)
{
- net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "ORDER BY");
+ my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
return 1;
}
select_lex->include_neighbour(lex->current_select);
@@ -4618,7 +4577,6 @@ void mysql_parse(THD *thd, char *inBuf, uint length)
{
if (thd->net.report_error)
{
- send_error(thd, 0, NullS);
if (thd->lex->sphead)
{
if (lex != thd->lex)
@@ -4734,7 +4692,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
if (strlen(field_name) > NAME_LEN)
{
- net_printf(thd, ER_TOO_LONG_IDENT, field_name); /* purecov: inspected */
+ my_error(ER_TOO_LONG_IDENT, MYF(0), field_name); /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
if (type_modifier & PRI_KEY_FLAG)
@@ -4765,7 +4723,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
!(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
type == FIELD_TYPE_TIMESTAMP))
{
- net_printf(thd, ER_INVALID_DEFAULT, field_name);
+ my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
DBUG_RETURN(1);
}
else if (default_value->type() == Item::NULL_ITEM)
@@ -4774,20 +4732,20 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) ==
NOT_NULL_FLAG)
{
- net_printf(thd,ER_INVALID_DEFAULT,field_name);
+ my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
DBUG_RETURN(1);
}
}
else if (type_modifier & AUTO_INCREMENT_FLAG)
{
- net_printf(thd, ER_INVALID_DEFAULT, field_name);
+ my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
DBUG_RETURN(1);
}
}
if (on_update_value && type != FIELD_TYPE_TIMESTAMP)
{
- net_printf(thd, ER_INVALID_ON_UPDATE, field_name);
+ my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name);
DBUG_RETURN(1);
}
@@ -4913,7 +4871,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
res=default_value->val_str(&str);
if (res->length())
{
- net_printf(thd,ER_BLOB_CANT_HAVE_DEFAULT,field_name); /* purecov: inspected */
+ my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
+ field_name); /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
new_field->def=0;
@@ -4933,7 +4892,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
uint tmp_length=new_field->length;
if (tmp_length > PRECISION_FOR_DOUBLE)
{
- net_printf(thd,ER_WRONG_FIELD_SPEC,field_name);
+ my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name);
DBUG_RETURN(1);
}
else if (tmp_length > PRECISION_FOR_FLOAT)
@@ -5030,7 +4989,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
{
if (interval->count > sizeof(longlong)*8)
{
- net_printf(thd,ER_TOO_BIG_SET,field_name); /* purecov: inspected */
+ my_error(ER_TOO_BIG_SET, MYF(0), field_name); /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
new_field->pack_length=(interval->count+7)/8;
@@ -5056,7 +5015,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
&not_used, &not_used2, &not_used3);
if (thd->cuted_fields)
{
- net_printf(thd,ER_INVALID_DEFAULT,field_name);
+ my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
DBUG_RETURN(1);
}
}
@@ -5078,7 +5037,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
res->strip_sp();
if (!find_type(interval, res->ptr(), res->length(), 0))
{
- net_printf(thd,ER_INVALID_DEFAULT,field_name);
+ my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
DBUG_RETURN(1);
}
}
@@ -5092,14 +5051,14 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
type != FIELD_TYPE_STRING &&
type != FIELD_TYPE_VAR_STRING && type != FIELD_TYPE_GEOMETRY))
{
- net_printf(thd,ER_TOO_BIG_FIELDLENGTH,field_name,
- MAX_FIELD_CHARLENGTH); /* purecov: inspected */
+ my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0),
+ field_name, MAX_FIELD_CHARLENGTH);/* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
type_modifier&= AUTO_INCREMENT_FLAG;
if ((~allowed_type_modifier) & type_modifier)
{
- net_printf(thd,ER_WRONG_FIELD_SPEC,field_name);
+ my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name);
DBUG_RETURN(1);
}
if (!new_field->pack_length)
@@ -5229,7 +5188,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
if (check_table_name(table->table.str,table->table.length) ||
table->db.str && check_db_name(table->db.str))
{
- net_printf(thd, ER_WRONG_TABLE_NAME, table->table.str);
+ my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
DBUG_RETURN(0);
}
@@ -5237,7 +5196,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
{
if (table->sel)
{
- net_printf(thd,ER_DERIVED_MUST_HAVE_ALIAS);
+ my_message(ER_DERIVED_MUST_HAVE_ALIAS,
+ ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
DBUG_RETURN(0);
}
if (!(alias_str=thd->memdup(alias_str,table->table.length+1)))
@@ -5274,6 +5234,18 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX);
ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES);
ptr->derived= table->sel;
+ if (!my_strcasecmp(system_charset_info, ptr->db,
+ information_schema_name.str))
+ {
+ ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->real_name);
+ if (!schema_table)
+ {
+ my_error(ER_UNKNOWN_TABLE, MYF(0),
+ ptr->real_name, information_schema_name.str);
+ DBUG_RETURN(0);
+ }
+ ptr->schema_table= schema_table;
+ }
ptr->select_lex= lex->current_select;
ptr->cacheable_table= 1;
if (use_index_arg)
@@ -5293,7 +5265,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
!strcmp(ptr->db, tables->db))
{
- net_printf(thd,ER_NONUNIQ_TABLE,alias_str); /* purecov: tested */
+ my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */
DBUG_RETURN(0); /* purecov: tested */
}
}
@@ -5789,7 +5761,7 @@ void kill_one_thread(THD *thd, ulong id, bool only_kill_query)
if (!error)
send_ok(thd);
else
- net_printf(thd,error,id);
+ my_error(error, MYF(0), id);
}
/* Clear most status variables */
@@ -5865,12 +5837,13 @@ static bool append_file_to_dir(THD *thd, const char **filename_ptr,
bool check_simple_select()
{
THD *thd= current_thd;
- if (thd->lex->current_select != &thd->lex->select_lex)
+ LEX *lex= thd->lex;
+ if (lex->current_select != &lex->select_lex)
{
char command[80];
- strmake(command, thd->lex->yylval->symbol.str,
- min(thd->lex->yylval->symbol.length, sizeof(command)-1));
- net_printf(thd, ER_CANT_USE_OPTION_HERE, command);
+ strmake(command, lex->yylval->symbol.str,
+ min(lex->yylval->symbol.length, sizeof(command)-1));
+ my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
return 1;
}
return 0;
@@ -5958,7 +5931,7 @@ Item * all_any_subquery_creator(Item *left_expr,
One should normally create all indexes with CREATE TABLE or ALTER TABLE.
*/
-int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
+bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
{
List<create_field> fields;
ALTER_INFO alter_info;
@@ -5975,7 +5948,7 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
}
-int mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info)
+bool mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info)
{
List<create_field> fields;
List<Key> keys;
@@ -6002,12 +5975,11 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info)
tables Global/local table list (have to be the same)
RETURN VALUE
- 0 OK
- 1 Error (message is sent to user)
- -1 Error (message is not sent to user)
+ FALSE OK
+ TRUE Error
*/
-int multi_update_precheck(THD *thd, TABLE_LIST *tables)
+bool multi_update_precheck(THD *thd, TABLE_LIST *tables)
{
const char *msg= 0;
TABLE_LIST *table;
@@ -6017,8 +5989,8 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables)
if (select_lex->item_list.elements != lex->value_list.elements)
{
- my_error(ER_WRONG_VALUE_COUNT, MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
+ DBUG_RETURN(TRUE);
}
/*
Ensure that we have UPDATE or SELECT privilege for each table
@@ -6035,7 +6007,7 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables)
(check_access(thd, SELECT_ACL, table->db,
&table->grant.privilege, 0, 0) ||
grant_option && check_grant(thd, SELECT_ACL, table, 0, 1, 0)))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
table->table_in_first_from_clause= 1;
}
@@ -6052,7 +6024,7 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables)
if (check_access(thd, SELECT_ACL, table->db,
&table->grant.privilege, 0, 0) ||
grant_option && check_grant(thd, SELECT_ACL, table, 0, 1, 0))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
}
}
@@ -6065,9 +6037,9 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables)
if (msg)
{
my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
/*
@@ -6080,11 +6052,11 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables)
table_count Pointer to table counter
RETURN VALUE
- 0 OK
- 1 error (message is sent to user)
- -1 error (message is not sent to user)
+ FALSE OK
+ TRUE error
*/
-int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count)
+
+bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count)
{
SELECT_LEX *select_lex= &thd->lex->select_lex;
TABLE_LIST *aux_tables=
@@ -6099,11 +6071,12 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count)
if (check_db_used(thd, tables) || check_db_used(thd,aux_tables) ||
check_table_access(thd,SELECT_ACL, tables,0) ||
check_table_access(thd,DELETE_ACL, aux_tables,0))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
if ((thd->options & OPTION_SAFE_UPDATES) && !select_lex->where)
{
- my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
+ ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
+ DBUG_RETURN(TRUE);
}
for (target_tbl= aux_tables; target_tbl; target_tbl= target_tbl->next_local)
{
@@ -6119,14 +6092,14 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count)
}
if (!walk)
{
- my_error(ER_UNKNOWN_TABLE, MYF(0), target_tbl->real_name,
- "MULTI DELETE");
- DBUG_RETURN(-1);
+ my_error(ER_UNKNOWN_TABLE, MYF(0),
+ target_tbl->real_name, "MULTI DELETE");
+ DBUG_RETURN(TRUE);
}
walk->lock_type= target_tbl->lock_type;
target_tbl->correspondent_table= walk; // Remember corresponding table
}
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -6139,12 +6112,11 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count)
tables Global table list
RETURN VALUE
- 0 OK
- 1 Error (message is sent to user)
- -1 Error (message is not sent to user)
+ FALSE OK
+ TRUE Error
*/
-int insert_select_precheck(THD *thd, TABLE_LIST *tables)
+bool insert_select_precheck(THD *thd, TABLE_LIST *tables)
{
DBUG_ENTER("insert_select_precheck");
/*
@@ -6153,7 +6125,7 @@ int insert_select_precheck(THD *thd, TABLE_LIST *tables)
*/
ulong privilege= (thd->lex->duplicates == DUP_REPLACE ?
INSERT_ACL | DELETE_ACL : INSERT_ACL);
- DBUG_RETURN(check_one_table_access(thd, privilege, tables) ? 1 : 0);
+ DBUG_RETURN(check_one_table_access(thd, privilege, tables));
}
@@ -6166,21 +6138,20 @@ int insert_select_precheck(THD *thd, TABLE_LIST *tables)
tables Global table list
RETURN VALUE
- 0 OK
- 1 Error (message is sent to user)
- -1 Error (message is not sent to user)
+ FALSE OK
+ TRUE Error
*/
-int update_precheck(THD *thd, TABLE_LIST *tables)
+bool update_precheck(THD *thd, TABLE_LIST *tables)
{
DBUG_ENTER("update_precheck");
if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements)
{
- my_error(ER_WRONG_VALUE_COUNT, MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
+ DBUG_RETURN(TRUE);
}
- DBUG_RETURN((check_db_used(thd, tables) ||
- check_one_table_access(thd, UPDATE_ACL, tables)) ? 1 : 0);
+ DBUG_RETURN(check_db_used(thd, tables) ||
+ check_one_table_access(thd, UPDATE_ACL, tables));
}
@@ -6193,19 +6164,18 @@ int update_precheck(THD *thd, TABLE_LIST *tables)
tables Global table list
RETURN VALUE
- 0 OK
- 1 error (message is sent to user)
- -1 error (message is not sent to user)
+ FALSE OK
+ TRUE error
*/
-int delete_precheck(THD *thd, TABLE_LIST *tables)
+bool delete_precheck(THD *thd, TABLE_LIST *tables)
{
DBUG_ENTER("delete_precheck");
if (check_one_table_access(thd, DELETE_ACL, tables))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
/* Set privilege for the WHERE clause */
tables->grant.want_privilege=(SELECT_ACL & ~tables->grant.privilege);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -6218,12 +6188,11 @@ int delete_precheck(THD *thd, TABLE_LIST *tables)
tables Global table list
RETURN VALUE
- 0 OK
- 1 error (message is sent to user)
- -1 error (message is not sent to user)
+ FALSE OK
+ TRUE error
*/
-int insert_precheck(THD *thd, TABLE_LIST *tables)
+bool insert_precheck(THD *thd, TABLE_LIST *tables)
{
LEX *lex= thd->lex;
DBUG_ENTER("insert_precheck");
@@ -6233,14 +6202,14 @@ int insert_precheck(THD *thd, TABLE_LIST *tables)
(lex->value_list.elements ? UPDATE_ACL : 0));
if (check_one_table_access(thd, privilege, tables))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
if (lex->select_lex.item_list.elements != lex->value_list.elements)
{
- my_error(ER_WRONG_VALUE_COUNT, MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
+ DBUG_RETURN(TRUE);
}
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -6254,17 +6223,17 @@ int insert_precheck(THD *thd, TABLE_LIST *tables)
create_table Table which will be created
RETURN VALUE
- 0 OK
- 1 Error (message is sent to user)
+ FALSE OK
+ TRUE Error
*/
-int create_table_precheck(THD *thd, TABLE_LIST *tables,
- TABLE_LIST *create_table)
+bool create_table_precheck(THD *thd, TABLE_LIST *tables,
+ TABLE_LIST *create_table)
{
LEX *lex= thd->lex;
SELECT_LEX *select_lex= &lex->select_lex;
ulong want_priv;
- int error= 1; // Error message is given
+ bool error= TRUE; // Error message is given
DBUG_ENTER("create_table_precheck");
want_priv= ((lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) ?
@@ -6298,15 +6267,14 @@ int create_table_precheck(THD *thd, TABLE_LIST *tables,
find_table_in_global_list(tables, create_table->db,
create_table->real_name))
{
- net_printf(thd,ER_UPDATE_TABLE_USED, create_table->real_name);
-
+ error= FALSE;
goto err;
}
}
if (tables && check_table_access(thd, SELECT_ACL, tables,0))
goto err;
}
- error= 0;
+ error= FALSE;
err:
DBUG_RETURN(error);
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 1c23162b212..9e3395cf893 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -123,16 +123,13 @@ inline bool is_param_null(const uchar *pos, ulong param_no)
enum { STMT_QUERY_LOG_LENGTH= 8192 };
-enum enum_send_error { DONT_SEND_ERROR= 0, SEND_ERROR };
-
/*
Seek prepared statement in statement map by id: returns zero if statement
was not found, pointer otherwise.
*/
static Prepared_statement *
-find_prepared_statement(THD *thd, ulong id, const char *where,
- enum enum_send_error se)
+find_prepared_statement(THD *thd, ulong id, const char *where)
{
Statement *stmt= thd->stmt_map.find(id);
@@ -140,8 +137,6 @@ find_prepared_statement(THD *thd, ulong id, const char *where,
{
char llbuf[22];
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), 22, llstr(id, llbuf), where);
- if (se == SEND_ERROR)
- send_error(thd);
return 0;
}
return (Prepared_statement *) stmt;
@@ -181,7 +176,7 @@ static bool send_prep_stmt(Prepared_statement *stmt,
thd->client_stmt_id= stmt->id;
thd->client_param_count= stmt->param_count;
- thd->net.last_errno= 0;
+ thd->clear_error();
return 0;
}
@@ -882,24 +877,23 @@ static bool insert_params_from_vars_with_log(Prepared_statement *stmt,
tables global/local table list
RETURN VALUE
- 0 ok
- 1 error, sent to the client
- -1 error, not sent to client
+ FALSE OK
+ TRUE error
*/
-static int mysql_test_insert(Prepared_statement *stmt,
- TABLE_LIST *table_list,
- List<Item> &fields,
- List<List_item> &values_list,
- List<Item> &update_fields,
- List<Item> &update_values,
- enum_duplicates duplic)
+static bool mysql_test_insert(Prepared_statement *stmt,
+ TABLE_LIST *table_list,
+ List<Item> &fields,
+ List<List_item> &values_list,
+ List<Item> &update_fields,
+ List<Item> &update_values,
+ enum_duplicates duplic)
{
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
List_iterator_fast<List_item> its(values_list);
List_item *values;
- int res;
+ bool res;
DBUG_ENTER("mysql_test_insert");
if ((res= insert_precheck(thd, table_list)))
@@ -909,9 +903,9 @@ static int mysql_test_insert(Prepared_statement *stmt,
open temporary memory pool for temporary data allocated by derived
tables & preparation procedure
*/
- if ((res= open_and_lock_tables(thd, table_list)))
+ if (open_and_lock_tables(thd, table_list))
{
- DBUG_RETURN(res);
+ DBUG_RETURN(TRUE);
}
if ((values= its++))
@@ -932,9 +926,7 @@ static int mysql_test_insert(Prepared_statement *stmt,
counter++;
if (values->elements != value_count)
{
- my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW,
- ER(ER_WRONG_VALUE_COUNT_ON_ROW),
- MYF(0), counter);
+ my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
goto error;
}
if (setup_fields(thd, 0, table_list, *values, 0, 0, 0))
@@ -958,14 +950,13 @@ error:
tables list of tables queries
RETURN VALUE
- 0 success
- 1 error, sent to client
- -1 error, not sent to client
+ FALSE success
+ TRUE error
*/
-static int mysql_test_update(Prepared_statement *stmt,
- TABLE_LIST *table_list)
+static bool mysql_test_update(Prepared_statement *stmt,
+ TABLE_LIST *table_list)
{
- int res;
+ bool res;
THD *thd= stmt->thd;
SELECT_LEX *select= &stmt->lex->select_lex;
DBUG_ENTER("mysql_test_update");
@@ -1010,28 +1001,27 @@ static int mysql_test_update(Prepared_statement *stmt,
tables list of tables queries
RETURN VALUE
- 0 success
- 1 error, sent to client
- -1 error, not sent to client
+ FALSE success
+ TRUE error
*/
static int mysql_test_delete(Prepared_statement *stmt,
TABLE_LIST *table_list)
{
- int res;
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
DBUG_ENTER("mysql_test_delete");
- if ((res= delete_precheck(thd, table_list)))
- DBUG_RETURN(res);
+ if (delete_precheck(thd, table_list))
+ DBUG_RETURN(TRUE);
- if (!(res=open_and_lock_tables(thd, table_list)))
+ if (!open_and_lock_tables(thd, table_list))
{
- res= mysql_prepare_delete(thd, table_list, &lex->select_lex.where);
+ mysql_prepare_delete(thd, table_list, &lex->select_lex.where);
lex->unit.cleanup();
+ DBUG_RETURN(FALSE)
}
/* TODO: here we should send types of placeholders to the client. */
- DBUG_RETURN(res);
+ DBUG_RETURN(TRUE);
}
@@ -1046,9 +1036,8 @@ static int mysql_test_delete(Prepared_statement *stmt,
tables list of tables queries
RETURN VALUE
- 0 success
- 1 error, sent to client
- -1 error, not sent to client
+ FALSE success
+ TRUE error, sent to client
*/
static int mysql_test_select(Prepared_statement *stmt,
@@ -1057,7 +1046,7 @@ static int mysql_test_select(Prepared_statement *stmt,
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
SELECT_LEX_UNIT *unit= &lex->unit;
- int result;
+ bool result;
DBUG_ENTER("mysql_test_select");
#ifndef NO_EMBEDDED_ACCESS_CHECKS
@@ -1065,32 +1054,25 @@ static int mysql_test_select(Prepared_statement *stmt,
if (tables)
{
if (check_table_access(thd, privilege, tables,0))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
else if (check_access(thd, privilege, any_db,0,0,0))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
#endif
+ result= TRUE;
if (!lex->result && !(lex->result= new (stmt->mem_root) select_send))
- {
- send_error(thd);
goto err;
- }
- if ((result= open_and_lock_tables(thd, tables)))
- {
- result= 1; // Error sent
- send_error(thd);
+ if (open_and_lock_tables(thd, tables))
goto err;
- }
- result= 1;
+
thd->used_tables= 0; // Updated by setup_fields
// JOIN::prepare calls
if (unit->prepare(thd, 0, 0))
{
- send_error(thd);
goto err_prep;
}
if (!text_protocol)
@@ -1120,7 +1102,7 @@ static int mysql_test_select(Prepared_statement *stmt,
goto err_prep;
}
}
- result= 0; // ok
+ result= FALSE; // ok
err_prep:
unit->cleanup();
@@ -1139,30 +1121,27 @@ err:
values list of expressions
RETURN VALUE
- 0 success
- 1 error, sent to client
- -1 error, not sent to client
+ FALSE success
+ TRUE error, sent to client
*/
-static int mysql_test_do_fields(Prepared_statement *stmt,
+static bool mysql_test_do_fields(Prepared_statement *stmt,
TABLE_LIST *tables,
List<Item> *values)
{
DBUG_ENTER("mysql_test_do_fields");
THD *thd= stmt->thd;
- int res= 0;
- if (tables && (res= check_table_access(thd, SELECT_ACL, tables, 0)))
- DBUG_RETURN(res);
+ bool res;
+ if (tables && check_table_access(thd, SELECT_ACL, tables, 0))
+ DBUG_RETURN(TRUE);
- if (tables && (res= open_and_lock_tables(thd, tables)))
+ if (tables && open_and_lock_tables(thd, tables))
{
- DBUG_RETURN(res);
+ DBUG_RETURN(TRUE);
}
res= setup_fields(thd, 0, 0, *values, 0, 0, 0);
stmt->lex->unit.cleanup();
- if (res)
- DBUG_RETURN(-1);
- DBUG_RETURN(0);
+ DBUG_RETURN(res);
}
@@ -1176,22 +1155,21 @@ static int mysql_test_do_fields(Prepared_statement *stmt,
values list of expressions
RETURN VALUE
- 0 success
- 1 error, sent to client
- -1 error, not sent to client
+ FALSE success
+ TRUE error
*/
-static int mysql_test_set_fields(Prepared_statement *stmt,
- TABLE_LIST *tables,
- List<set_var_base> *var_list)
+static bool mysql_test_set_fields(Prepared_statement *stmt,
+ TABLE_LIST *tables,
+ List<set_var_base> *var_list)
{
DBUG_ENTER("mysql_test_set_fields");
List_iterator_fast<set_var_base> it(*var_list);
THD *thd= stmt->thd;
set_var_base *var;
- int res= 0;
+ bool res= 0;
- if (tables && (res= check_table_access(thd, SELECT_ACL, tables, 0)))
- DBUG_RETURN(res);
+ if (tables && check_table_access(thd, SELECT_ACL, tables, 0))
+ DBUG_RETURN(TRUE);
if (tables && (res= open_and_lock_tables(thd, tables)))
goto error;
@@ -1200,7 +1178,7 @@ static int mysql_test_set_fields(Prepared_statement *stmt,
if (var->light_check(thd))
{
stmt->lex->unit.cleanup();
- res= -1;
+ res= TRUE;
goto error;
}
}
@@ -1220,18 +1198,17 @@ error:
specific_prepare - function of command specific prepare
RETURN VALUE
- 0 success
- 1 error, sent to client
- -1 error, not sent to client
+ FALSE success
+ TRUE error
*/
-static int select_like_statement_test(Prepared_statement *stmt,
- TABLE_LIST *tables,
- int (*specific_prepare)(THD *thd))
+static bool select_like_statement_test(Prepared_statement *stmt,
+ TABLE_LIST *tables,
+ bool (*specific_prepare)(THD *thd))
{
DBUG_ENTER("select_like_statement_test");
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
- int res= 0;
+ bool res= 0;
if (tables && (res= open_and_lock_tables(thd, tables)))
goto end;
@@ -1244,7 +1221,7 @@ static int select_like_statement_test(Prepared_statement *stmt,
// JOIN::prepare calls
if (lex->unit.prepare(thd, 0, 0))
{
- res= thd->net.report_error ? -1 : 1;
+ res= TRUE;
}
end:
lex->unit.cleanup();
@@ -1301,16 +1278,15 @@ static int mysql_test_create_table(Prepared_statement *stmt)
tables list of tables queries
RETURN VALUE
- 0 success
- 1 error, sent to client
- -1 error, not sent to client
+ FALSE success
+ TRUE error
*/
-static int mysql_test_multiupdate(Prepared_statement *stmt,
+
+static bool mysql_test_multiupdate(Prepared_statement *stmt,
TABLE_LIST *tables)
{
- int res;
- if ((res= multi_update_precheck(stmt->thd, tables)))
- return res;
+ if (multi_update_precheck(stmt->thd, tables))
+ return TRUE;
/*
here we do not pass tables for opening, tables will be opened and locked
by mysql_multi_update_prepare
@@ -1386,23 +1362,34 @@ static int mysql_test_insert_select(Prepared_statement *stmt,
/*
- Send the prepare query results back to client
+ Perform semantic analysis of the parsed tree and send a response packet
+ to the client.
+
SYNOPSIS
- send_prepare_results()
- stmt prepared statement
+ check_prepared_statement()
+ stmt prepared statement
+
+ DESCRIPTION
+ This function
+ - opens all tables and checks access rights
+ - validates semantics of statement columns and SQL functions
+ by calling fix_fields.
+
RETURN VALUE
0 success
1 error, sent to client
*/
-static int send_prepare_results(Prepared_statement *stmt, bool text_protocol)
-{
+
+static int check_prepared_statement(Prepared_statement *stmt,
+ bool text_protocol)
+{
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
SELECT_LEX *select_lex= &lex->select_lex;
TABLE_LIST *tables;
enum enum_sql_command sql_command= lex->sql_command;
int res= 0;
- DBUG_ENTER("send_prepare_results");
+ DBUG_ENTER("check_prepared_statement");
DBUG_PRINT("enter",("command: %d, param_count: %ld",
sql_command, stmt->param_count));
@@ -1502,15 +1489,13 @@ static int send_prepare_results(Prepared_statement *stmt, bool text_protocol)
All other is not supported yet
*/
res= -1;
- my_error(ER_UNSUPPORTED_PS, MYF(0));
+ my_message(ER_UNSUPPORTED_PS, ER(ER_UNSUPPORTED_PS), MYF(0));
goto error;
}
if (res == 0)
DBUG_RETURN(text_protocol? 0 : (send_prep_stmt(stmt, 0) ||
thd->protocol->flush()));
error:
- if (res < 0)
- send_error(thd,thd->killed_errno());
DBUG_RETURN(1);
}
@@ -1529,9 +1514,8 @@ static bool init_param_array(Prepared_statement *stmt)
if (stmt->param_count > (uint) UINT_MAX16)
{
/* Error code to be defined in 5.0 */
- send_error(thd, ER_UNKNOWN_ERROR,
- "Prepared statement contains too many placeholders.");
- return 1;
+ my_message(ER_PS_MANY_PARAM, ER(ER_PS_MANY_PARAM), MYF(0));
+ return TRUE;
}
Item_param **to;
List_iterator<Item_param> param_iterator(lex->param_list);
@@ -1540,10 +1524,7 @@ static bool init_param_array(Prepared_statement *stmt)
alloc_root(stmt->thd->mem_root,
sizeof(Item_param*) * stmt->param_count);
if (!stmt->param_array)
- {
- send_error(thd, ER_OUT_OF_RESOURCES);
- return 1;
- }
+ return TRUE;
for (to= stmt->param_array;
to < stmt->param_array + stmt->param_count;
++to)
@@ -1551,7 +1532,7 @@ static bool init_param_array(Prepared_statement *stmt)
*to= param_iterator++;
}
}
- return 0;
+ return FALSE;
}
@@ -1567,10 +1548,10 @@ static bool init_param_array(Prepared_statement *stmt)
name NULL or statement name. For unnamed statements binary PS
protocol is used, for named statements text protocol is
used.
- RETURN
- 0 OK, statement prepared successfully
- other Error
-
+ RETURN
+ FALSE OK, statement prepared successfully
+ TRUE Error
+
NOTES
This function parses the query and sends the total number of parameters
and resultset metadata information back to client (if any), without
@@ -1584,21 +1565,18 @@ static bool init_param_array(Prepared_statement *stmt)
*/
-int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
- LEX_STRING *name)
+bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
+ LEX_STRING *name)
{
LEX *lex;
Prepared_statement *stmt= new Prepared_statement(thd);
- int error;
+ bool error;
DBUG_ENTER("mysql_stmt_prepare");
DBUG_PRINT("prep_query", ("%s", packet));
if (stmt == 0)
- {
- send_error(thd, ER_OUT_OF_RESOURCES);
- DBUG_RETURN(1);
- }
+ DBUG_RETURN(TRUE);
if (name)
{
@@ -1607,16 +1585,14 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
name->length)))
{
delete stmt;
- send_error(thd, ER_OUT_OF_RESOURCES);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
}
if (thd->stmt_map.insert(stmt))
{
delete stmt;
- send_error(thd, ER_OUT_OF_RESOURCES);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
thd->set_n_backup_statement(stmt, &thd->stmt_backup);
@@ -1628,8 +1604,7 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
thd->restore_backup_item_arena(stmt, &thd->stmt_backup);
/* Statement map deletes statement on erase */
thd->stmt_map.erase(stmt);
- send_error(thd, ER_OUT_OF_RESOURCES);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
mysql_log.write(thd, COM_PREPARE, "%s", packet);
@@ -1644,8 +1619,8 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
error= yyparse((void *)thd) || thd->is_fatal_error ||
thd->net.report_error || init_param_array(stmt);
/*
- While doing context analysis of the query (in send_prepare_results) we
- allocate a lot of additional memory: for open tables, JOINs, derived
+ While doing context analysis of the query (in check_prepared_statement)
+ we allocate a lot of additional memory: for open tables, JOINs, derived
tables, etc. Let's save a snapshot of current parse tree to the
statement and restore original THD. In cases when some tree
transformation can be reused on execute, we set again thd->mem_root from
@@ -1654,7 +1629,7 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
thd->restore_backup_item_arena(stmt, &thd->stmt_backup);
if (!error)
- error= send_prepare_results(stmt, test(name));
+ error= check_prepared_statement(stmt, test(name));
/* restore to WAIT_PRIOR: QUERY_PRIOR is set inside alloc_query */
if (!(specialflag & SPECIAL_NO_PRIOR))
@@ -1679,9 +1654,6 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
/* Statement map deletes statement on erase */
thd->stmt_map.erase(stmt);
stmt= NULL;
- if (thd->net.report_error)
- send_error(thd);
- /* otherwise the error is sent inside yyparse/send_prepare_results */
}
else
{
@@ -1817,8 +1789,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
packet+= 9; /* stmt_id + 5 bytes of flags */
- if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute",
- SEND_ERROR)))
+ if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute")))
DBUG_VOID_RETURN;
DBUG_PRINT("exec_query:", ("%s", stmt->query));
@@ -1826,7 +1797,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
/* Check if we got an error when sending long data */
if (stmt->state == Item_arena::ERROR)
{
- send_error(thd, stmt->last_errno, stmt->last_error);
+ my_message(stmt->last_errno, stmt->last_error, MYF(0));
DBUG_VOID_RETURN;
}
@@ -1848,10 +1819,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
DBUG_PRINT("info",("Using READ_ONLY cursor"));
if (!stmt->cursor &&
!(stmt->cursor= new (&stmt->main_mem_root) Cursor()))
- {
- send_error(thd, ER_OUT_OF_RESOURCES);
DBUG_VOID_RETURN;
- }
/* If lex->result is set, mysql_execute_command will use it */
stmt->lex->result= &stmt->cursor->result;
}
@@ -1919,7 +1887,6 @@ set_params_data_err:
reset_stmt_params(stmt);
my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_execute");
err:
- send_error(thd);
DBUG_VOID_RETURN;
}
@@ -1945,14 +1912,12 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name)
{
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), stmt_name->length,
stmt_name->str, "EXECUTE");
- send_error(thd);
DBUG_VOID_RETURN;
}
if (stmt->param_count != thd->lex->prepared_stmt_params.elements)
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE");
- send_error(thd);
DBUG_VOID_RETURN;
}
@@ -1965,7 +1930,6 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name)
&expanded_query))
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE");
- send_error(thd);
}
execute_stmt(thd, stmt, &expanded_query);
DBUG_VOID_RETURN;
@@ -1996,7 +1960,7 @@ static void execute_stmt(THD *thd, Prepared_statement *stmt,
alloc_query(thd, (char *)expanded_query->ptr(),
expanded_query->length()+1))
{
- my_error(ER_OUTOFMEMORY, 0, expanded_query->length());
+ my_error(ER_OUTOFMEMORY, MYF(0), expanded_query->length());
DBUG_VOID_RETURN;
}
/*
@@ -2055,7 +2019,6 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
!stmt->cursor->is_open())
{
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), stmt_id, "fetch");
- send_error(thd);
DBUG_VOID_RETURN;
}
@@ -2106,8 +2069,7 @@ void mysql_stmt_reset(THD *thd, char *packet)
DBUG_ENTER("mysql_stmt_reset");
- if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset",
- SEND_ERROR)))
+ if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset")))
DBUG_VOID_RETURN;
stmt->state= Item_arena::PREPARED;
@@ -2138,8 +2100,7 @@ void mysql_stmt_free(THD *thd, char *packet)
DBUG_ENTER("mysql_stmt_free");
- if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close",
- DONT_SEND_ERROR)))
+ if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close")))
DBUG_VOID_RETURN;
/* Statement map deletes statement on erase */
@@ -2189,8 +2150,8 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
stmt_id= uint4korr(packet);
packet+= 4;
- if (!(stmt=find_prepared_statement(thd, stmt_id, "mysql_stmt_send_long_data",
- DONT_SEND_ERROR)))
+ if (!(stmt=find_prepared_statement(thd, stmt_id,
+ "mysql_stmt_send_long_data")))
DBUG_VOID_RETURN;
param_number= uint2korr(packet);
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index 3298eb68a91..9f29a975441 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -44,7 +44,8 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list)
if (thd->locked_tables || thd->active_transaction())
{
- my_error(ER_LOCK_OR_ACTIVE_TRANSACTION,MYF(0));
+ my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+ ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
DBUG_RETURN(1);
}
@@ -156,7 +157,7 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
unpack_filename(name, name);
if (!access(name,F_OK))
{
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_alias);
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
DBUG_RETURN(ren_table); // This can't be skipped
}
sprintf(name,"%s/%s/%s%s",mysql_data_home,
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 10f0c23f54d..d2e3e72618d 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -276,41 +276,39 @@ bool log_in_use(const char* log_name)
return result;
}
-int purge_error_message(THD* thd, int res)
+bool purge_error_message(THD* thd, int res)
{
- const char *errmsg= 0;
+ uint errmsg= 0;
switch (res) {
case 0: break;
- case LOG_INFO_EOF: errmsg= "Target log not found in binlog index"; break;
- case LOG_INFO_IO: errmsg= "I/O error reading log index file"; break;
- case LOG_INFO_INVALID:
- errmsg= "Server configuration does not permit binlog purge"; break;
- case LOG_INFO_SEEK: errmsg= "Failed on fseek()"; break;
- case LOG_INFO_MEM: errmsg= "Out of memory"; break;
- case LOG_INFO_FATAL: errmsg= "Fatal error during purge"; break;
- case LOG_INFO_IN_USE: errmsg= "A purgeable log is in use, will not purge";
- break;
- default: errmsg= "Unknown error during purge"; break;
+ case LOG_INFO_EOF: errmsg= ER_UNKNOWN_TARGET_BINLOG; break;
+ case LOG_INFO_IO: errmsg= ER_IO_ERR_LOG_INDEX_READ; break;
+ case LOG_INFO_INVALID:errmsg= ER_BINLOG_PURGE_PROHIBITED; break;
+ case LOG_INFO_SEEK: errmsg= ER_FSEEK_FAIL; break;
+ case LOG_INFO_MEM: errmsg= ER_OUT_OF_RESOURCES; break;
+ case LOG_INFO_FATAL: errmsg= ER_BINLOG_PURGE_FATAL_ERR; break;
+ case LOG_INFO_IN_USE: errmsg= ER_LOG_IN_USE; break;
+ default: errmsg= ER_LOG_PURGE_UNKNOWN_ERR; break;
}
if (errmsg)
{
- send_error(thd, 0, errmsg);
- return 1;
+ my_message(errmsg, ER(errmsg), MYF(0));
+ return TRUE;
}
send_ok(thd);
- return 0;
+ return FALSE;
}
-int purge_master_logs(THD* thd, const char* to_log)
+bool purge_master_logs(THD* thd, const char* to_log)
{
char search_file_name[FN_REFLEN];
if (!mysql_bin_log.is_open())
{
send_ok(thd);
- return 0;
+ return FALSE;
}
mysql_bin_log.make_log_name(search_file_name, to_log);
@@ -320,7 +318,7 @@ int purge_master_logs(THD* thd, const char* to_log)
}
-int purge_master_logs_before_date(THD* thd, time_t purge_time)
+bool purge_master_logs_before_date(THD* thd, time_t purge_time)
{
if (!mysql_bin_log.is_open())
{
@@ -756,7 +754,7 @@ err:
pthread_mutex_unlock(&LOCK_thread_count);
if (file >= 0)
(void) my_close(file, MYF(MY_WME));
- send_error(thd, my_errno, errmsg);
+ my_message(my_errno, errmsg, MYF(0));
DBUG_VOID_RETURN;
}
@@ -872,7 +870,7 @@ int start_slave(THD* thd , MASTER_INFO* mi, bool net_report)
if (slave_errno)
{
if (net_report)
- send_error(thd, slave_errno);
+ my_message(slave_errno, ER(slave_errno), MYF(0));
DBUG_RETURN(1);
}
else if (net_report)
@@ -922,7 +920,7 @@ int stop_slave(THD* thd, MASTER_INFO* mi, bool net_report )
if (slave_errno)
{
if (net_report)
- send_error(thd, slave_errno);
+ my_message(slave_errno, ER(slave_errno), MYF(0));
return 1;
}
else if (net_report)
@@ -1003,7 +1001,7 @@ int reset_slave(THD *thd, MASTER_INFO* mi)
err:
unlock_slave_threads(mi);
- if (error)
+ if (error)
my_error(sql_errno, MYF(0), errmsg);
DBUG_RETURN(error);
}
@@ -1057,7 +1055,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id)
}
-int change_master(THD* thd, MASTER_INFO* mi)
+bool change_master(THD* thd, MASTER_INFO* mi)
{
int thread_mask;
const char* errmsg= 0;
@@ -1068,9 +1066,9 @@ int change_master(THD* thd, MASTER_INFO* mi)
init_thread_mask(&thread_mask,mi,0 /*not inverse*/);
if (thread_mask) // We refuse if any slave thread is running
{
- net_printf(thd,ER_SLAVE_MUST_STOP);
+ my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
unlock_slave_threads(mi);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
thd->proc_info = "Changing master";
@@ -1078,9 +1076,9 @@ int change_master(THD* thd, MASTER_INFO* mi)
// TODO: see if needs re-write
if (init_master_info(mi, master_info_file, relay_log_info_file, 0))
{
- send_error(thd, ER_MASTER_INFO);
+ my_message(ER_MASTER_INFO, ER(ER_MASTER_INFO), MYF(0));
unlock_slave_threads(mi);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
/*
@@ -1197,9 +1195,9 @@ int change_master(THD* thd, MASTER_INFO* mi)
0 /* not only reset, but also reinit */,
&errmsg))
{
- net_printf(thd, 0, "Failed purging old relay logs: %s",errmsg);
+ my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg);
unlock_slave_threads(mi);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
}
else
@@ -1213,9 +1211,9 @@ int change_master(THD* thd, MASTER_INFO* mi)
0 /*no data lock*/,
&msg, 0))
{
- net_printf(thd,0,"Failed initializing relay log position: %s",msg);
+ my_error(ER_RELAY_LOG_INIT, MYF(0), msg);
unlock_slave_threads(mi);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
}
mi->rli.group_master_log_pos = mi->master_log_pos;
@@ -1257,14 +1255,15 @@ int change_master(THD* thd, MASTER_INFO* mi)
unlock_slave_threads(mi);
thd->proc_info = 0;
send_ok(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
int reset_master(THD* thd)
{
if (!mysql_bin_log.is_open())
{
- my_error(ER_FLUSH_MASTER_BINLOG_CLOSED, MYF(ME_BELL+ME_WAITTANG));
+ my_message(ER_FLUSH_MASTER_BINLOG_CLOSED,
+ ER(ER_FLUSH_MASTER_BINLOG_CLOSED), MYF(ME_BELL+ME_WAITTANG));
return 1;
}
return mysql_bin_log.reset_logs(thd);
@@ -1288,7 +1287,7 @@ int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1,
}
-int show_binlog_events(THD* thd)
+bool show_binlog_events(THD* thd)
{
Protocol *protocol= thd->protocol;
DBUG_ENTER("show_binlog_events");
@@ -1302,7 +1301,7 @@ int show_binlog_events(THD* thd)
Log_event::init_show_field_list(&field_list);
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
if (mysql_bin_log.is_open())
{
@@ -1407,19 +1406,19 @@ err:
if (errmsg)
{
my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0),
- "SHOW BINLOG EVENTS", errmsg);
- DBUG_RETURN(-1);
+ "SHOW BINLOG EVENTS", errmsg);
+ DBUG_RETURN(TRUE);
}
send_eof(thd);
pthread_mutex_lock(&LOCK_thread_count);
thd->current_linfo = 0;
pthread_mutex_unlock(&LOCK_thread_count);
- DBUG_RETURN(0);
+ DBUG_RETURN(TRUE);
}
-int show_binlog_info(THD* thd)
+bool show_binlog_info(THD* thd)
{
Protocol *protocol= thd->protocol;
DBUG_ENTER("show_binlog_info");
@@ -1432,7 +1431,7 @@ int show_binlog_info(THD* thd)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
protocol->prepare_for_resend();
if (mysql_bin_log.is_open())
@@ -1445,10 +1444,10 @@ int show_binlog_info(THD* thd)
protocol->store(&binlog_do_db);
protocol->store(&binlog_ignore_db);
if (protocol->write())
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -1460,11 +1459,11 @@ int show_binlog_info(THD* thd)
thd Thread specific variable
RETURN VALUES
- 0 ok
- 1 error (Error message sent to client)
+ FALSE OK
+ TRUE error
*/
-int show_binlogs(THD* thd)
+bool show_binlogs(THD* thd)
{
IO_CACHE *index_file;
char fname[FN_REFLEN];
@@ -1475,15 +1474,14 @@ int show_binlogs(THD* thd)
if (!mysql_bin_log.is_open())
{
- //TODO: Replace with ER() error message
- send_error(thd, 0, "You are not using binary logging");
+ my_message(ER_NO_BINARY_LOGGING, ER(ER_NO_BINARY_LOGGING), MYF(0));
return 1;
}
field_list.push_back(new Item_empty_string("Log_name", 255));
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
mysql_bin_log.lock_index();
index_file=mysql_bin_log.get_index_file();
@@ -1501,11 +1499,11 @@ int show_binlogs(THD* thd)
}
mysql_bin_log.unlock_index();
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
err:
mysql_bin_log.unlock_index();
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
diff --git a/sql/sql_repl.h b/sql/sql_repl.h
index 66fdfb4c022..71b25548da4 100644
--- a/sql/sql_repl.h
+++ b/sql/sql_repl.h
@@ -43,17 +43,17 @@ File open_binlog(IO_CACHE *log, const char *log_file_name,
int start_slave(THD* thd, MASTER_INFO* mi, bool net_report);
int stop_slave(THD* thd, MASTER_INFO* mi, bool net_report);
-int change_master(THD* thd, MASTER_INFO* mi);
-int show_binlog_events(THD* thd);
+bool change_master(THD* thd, MASTER_INFO* mi);
+bool show_binlog_events(THD* thd);
int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1,
const char* log_file_name2, ulonglong log_pos2);
int reset_slave(THD *thd, MASTER_INFO* mi);
int reset_master(THD* thd);
-int purge_master_logs(THD* thd, const char* to_log);
-int purge_master_logs_before_date(THD* thd, time_t purge_time);
+bool purge_master_logs(THD* thd, const char* to_log);
+bool purge_master_logs_before_date(THD* thd, time_t purge_time);
bool log_in_use(const char* log_name);
void adjust_linfo_offsets(my_off_t purge_offset);
-int show_binlogs(THD* thd);
+bool show_binlogs(THD* thd);
extern int init_master_info(MASTER_INFO* mi);
void kill_zombie_dump_threads(uint32 slave_server_id);
int check_binlog_magic(IO_CACHE* log, const char** errmsg);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 92cf499eb2b..80c1c8a697f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -205,9 +205,9 @@ static void add_group_and_distinct_keys(JOIN *join, JOIN_TAB *join_tab);
This handles SELECT with and without UNION
*/
-int handle_select(THD *thd, LEX *lex, select_result *result)
+bool handle_select(THD *thd, LEX *lex, select_result *result)
{
- int res;
+ bool res;
register SELECT_LEX *select_lex = &lex->select_lex;
DBUG_ENTER("handle_select");
@@ -232,11 +232,14 @@ int handle_select(THD *thd, LEX *lex, select_result *result)
}
DBUG_PRINT("info",("res: %d report_error: %d", res,
thd->net.report_error));
- if (thd->net.report_error || res < 0)
+ res|= thd->net.report_error;
+ if (unlikely(res))
{
- result->send_error(0, NullS);
+ /*
+ If we have real error reported erly then this will be ignored
+ */
+ result->send_error(ER_UNKNOWN_ERROR, NullS);
result->abort();
- res= 1; // Error sent to client
}
DBUG_RETURN(res);
}
@@ -374,7 +377,8 @@ JOIN::prepare(Item ***rref_pointer_array,
}
if (flag == 3)
{
- my_error(ER_MIX_OF_GROUP_FUNC_AND_FIELDS,MYF(0));
+ my_message(ER_MIX_OF_GROUP_FUNC_AND_FIELDS,
+ ER(ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0));
DBUG_RETURN(-1);
}
}
@@ -401,21 +405,22 @@ JOIN::prepare(Item ***rref_pointer_array,
{
if (!test_if_subpart(procedure->group,group_list))
{ /* purecov: inspected */
- my_message(0,"Can't handle procedures with differents groups yet",
- MYF(0)); /* purecov: inspected */
+ my_message(ER_DIFF_GROUPS_PROC, ER(ER_DIFF_GROUPS_PROC),
+ MYF(0)); /* purecov: inspected */
goto err; /* purecov: inspected */
}
}
#ifdef NOT_NEEDED
else if (!group_list && procedure->flags & PROC_GROUP)
{
- my_message(0,"Select must have a group with this procedure",MYF(0));
+ my_message(ER_NO_GROUP_FOR_PROC, MYF(0));
goto err;
}
#endif
if (order && (procedure->flags & PROC_NO_SORT))
{ /* purecov: inspected */
- my_message(0,"Can't use order with this procedure",MYF(0)); /* purecov: inspected */
+ my_message(ER_ORDER_WITH_PROC, ER(ER_ORDER_WITH_PROC),
+ MYF(0)); /* purecov: inspected */
goto err; /* purecov: inspected */
}
}
@@ -1221,6 +1226,12 @@ JOIN::exec()
List<Item> *curr_fields_list= &fields_list;
TABLE *curr_tmp_table= 0;
+ if ((curr_join->select_lex->options & OPTION_SCHEMA_TABLE) &&
+ get_schema_tables_result(curr_join))
+ {
+ DBUG_VOID_RETURN;
+ }
+
/* Create a tmp table if distinct or if the sort is too complicated */
if (need_tmp)
{
@@ -1803,7 +1814,7 @@ Cursor::fetch(ulong num_rows)
if (thd->killed) /* Aborted by user */
{
- my_error(ER_SERVER_SHUTDOWN,MYF(0));
+ my_message(ER_SERVER_SHUTDOWN, ER(ER_SERVER_SHUTDOWN), MYF(0));
return -1;
}
@@ -1877,7 +1888,7 @@ Cursor::fetch(ulong num_rows)
thd->server_status&= ~SERVER_STATUS_LAST_ROW_SENT;
}
else
- send_error(thd, ER_OUT_OF_RESOURCES);
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
/* free cursor memory */
free_items(free_list);
free_list= 0;
@@ -1939,7 +1950,7 @@ Cursor::~Cursor()
/*********************************************************************/
-int
+bool
mysql_select(THD *thd, Item ***rref_pointer_array,
TABLE_LIST *tables, uint wild_num, List<Item> &fields,
COND *conds, uint og_num, ORDER *order, ORDER *group,
@@ -1947,7 +1958,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
select_result *result, SELECT_LEX_UNIT *unit,
SELECT_LEX *select_lex)
{
- int err;
+ bool err;
bool free_join= 1;
DBUG_ENTER("mysql_select");
@@ -1955,7 +1966,10 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
if (select_lex->join != 0)
{
join= select_lex->join;
- // is it single SELECT in derived table, called in derived table creation
+ /*
+ is it single SELECT in derived table, called in derived table
+ creation
+ */
if (select_lex->linkage != DERIVED_TABLE_TYPE ||
(select_options & SELECT_DESCRIBE))
{
@@ -1964,7 +1978,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
//here is EXPLAIN of subselect or derived table
if (join->change_result(result))
{
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
}
else
@@ -1983,7 +1997,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
else
{
if (!(join= new JOIN(thd, fields, select_options, result)))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
thd->proc_info="init";
thd->used_tables=0; // Updated by setup_fields
if (join->prepare(rref_pointer_array, tables, wild_num,
@@ -2031,10 +2045,8 @@ err:
{
thd->proc_info="end";
err= join->cleanup();
- if (thd->net.report_error)
- err= -1;
delete join;
- DBUG_RETURN(err);
+ DBUG_RETURN(err || thd->net.report_error);
}
DBUG_RETURN(join->error);
}
@@ -2128,6 +2140,8 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds,
s->dependent= tables->dep_tables;
s->key_dependent= 0;
+ if (tables->schema_table)
+ table->file->records= 2;
s->on_expr_ref= &tables->on_expr;
if (*s->on_expr_ref)
@@ -2191,7 +2205,7 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds,
if (s->dependent & s->table->map)
{
join->tables=0; // Don't use join->table
- my_error(ER_WRONG_OUTER_JOIN,MYF(0));
+ my_message(ER_WRONG_OUTER_JOIN, ER(ER_WRONG_OUTER_JOIN), MYF(0));
DBUG_RETURN(1);
}
s->key_dependent= s->dependent;
@@ -2935,14 +2949,14 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array,
Item_func *arg0=(Item_func *)(func->arguments()[0]),
*arg1=(Item_func *)(func->arguments()[1]);
if (arg1->const_item() &&
- ((functype == Item_func::GE_FUNC && arg1->val()> 0) ||
- (functype == Item_func::GT_FUNC && arg1->val()>=0)) &&
+ ((functype == Item_func::GE_FUNC && arg1->val_real() > 0) ||
+ (functype == Item_func::GT_FUNC && arg1->val_real() >=0)) &&
arg0->type() == Item::FUNC_ITEM &&
arg0->functype() == Item_func::FT_FUNC)
cond_func=(Item_func_match *) arg0;
else if (arg0->const_item() &&
- ((functype == Item_func::LE_FUNC && arg0->val()> 0) ||
- (functype == Item_func::LT_FUNC && arg0->val()>=0)) &&
+ ((functype == Item_func::LE_FUNC && arg0->val_real() > 0) ||
+ (functype == Item_func::LT_FUNC && arg0->val_real() >=0)) &&
arg1->type() == Item::FUNC_ITEM &&
arg1->functype() == Item_func::FT_FUNC)
cond_func=(Item_func_match *) arg1;
@@ -5613,7 +5627,8 @@ bool error_if_full_join(JOIN *join)
{
if (tab->type == JT_ALL && (!tab->select || !tab->select->quick))
{
- my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,MYF(0));
+ my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
+ ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
return(1);
}
}
@@ -7723,7 +7738,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
blob_count,group_null_items;
bool using_unique_constraint=0;
bool not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS);
- char *tmpname,path[FN_REFLEN];
+ char *tmpname,path[FN_REFLEN], filename[FN_REFLEN];
byte *pos,*group_buff;
uchar *null_flags;
Field **reg_field, **from_field, **blob_field;
@@ -7745,14 +7760,15 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
temp_pool_slot = bitmap_set_next(&temp_pool);
if (temp_pool_slot != MY_BIT_NONE) // we got a slot
- sprintf(path, "%s%s_%lx_%i", mysql_tmpdir, tmp_file_prefix,
- current_pid, temp_pool_slot);
+ sprintf(filename, "%s_%lx_%i", tmp_file_prefix,
+ current_pid, temp_pool_slot);
else // if we run out of slots or we are not using tempool
- sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid,
+ sprintf(filename,"%s%lx_%lx_%x",tmp_file_prefix,current_pid,
thd->thread_id, thd->tmp_table++);
if (lower_case_table_names)
my_casedn_str(files_charset_info, path);
+ sprintf(path, "%s%s", mysql_tmpdir, filename);
if (group)
{
@@ -9753,9 +9769,6 @@ end_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
{
Item *item= *group->item;
item->save_org_in_field(group->field);
-#ifdef EMBEDDED_LIBRARY
- join->thd->net.last_errno= 0;
-#endif
/* Store in the used key if the field was 0 */
if (item->maybe_null)
group->buff[-1]=item->null_value ? 1 : 0;
@@ -10716,7 +10729,7 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field,
}
if (copy_blobs(first_field))
{
- my_error(ER_OUTOFMEMORY,MYF(0));
+ my_message(ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(0));
error=0;
goto err;
}
@@ -11167,24 +11180,53 @@ cp_buffer_from_ref(TABLE_REF *ref)
*****************************************************************************/
/*
- Find order/group item in requested columns and change the item to point at
- it. If item doesn't exists, add it first in the field list
- Return 0 if ok.
+ Resolve an ORDER BY or GROUP BY column reference.
+
+ SYNOPSIS
+ find_order_in_list()
+ thd [in] Pointer to current thread structure
+ ref_pointer_array [in/out] All select, group and order by fields
+ tables [in] List of tables to search in (usually FROM clause)
+ order [in] Column reference to be resolved
+ fields [in] List of fields to search in (usually SELECT list)
+ all_fields [in/out] All select, group and order by fields
+ is_group_field [in] True if order is a GROUP field, false if
+ ORDER by field
+
+ DESCRIPTION
+ Given a column reference (represented by 'order') from a GROUP BY or ORDER
+ BY clause, find the actual column it represents. If the column being
+ resolved is from the GROUP BY clause, the procedure searches the SELECT
+ list 'fields' and the columns in the FROM list 'tables'. If 'order' is from
+ the ORDER BY clause, only the SELECT list is being searched.
+
+ If 'order' is resolved to an Item, then order->item is set to the found
+ Item. If there is no item for the found column (that is, it was resolved
+ into a table field), order->item is 'fixed' and is added to all_fields and
+ ref_pointer_array.
+
+ RETURN
+ 0 if OK
+ 1 if error occurred
*/
static int
-find_order_in_list(THD *thd, Item **ref_pointer_array,
- TABLE_LIST *tables,ORDER *order, List<Item> &fields,
- List<Item> &all_fields)
+find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
+ ORDER *order, List<Item> &fields, List<Item> &all_fields,
+ bool is_group_field)
{
- Item *it= *order->item;
- if (it->type() == Item::INT_ITEM)
+ Item *order_item= *order->item; /* The item from the GROUP/ORDER caluse. */
+ Item::Type order_item_type;
+ Item **select_item; /* The corresponding item from the SELECT clause. */
+ Field *from_field; /* The corresponding field from the FROM clause. */
+
+ if (order_item->type() == Item::INT_ITEM)
{ /* Order by position */
- uint count= (uint) it->val_int();
+ uint count= (uint) order_item->val_int();
if (!count || count > fields.elements)
{
- my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),
- MYF(0), it->full_name(), thd->where);
+ my_error(ER_BAD_FIELD_ERROR, MYF(0),
+ order_item->full_name(), thd->where);
return 1;
}
order->item= ref_pointer_array + count - 1;
@@ -11193,47 +11235,78 @@ find_order_in_list(THD *thd, Item **ref_pointer_array,
order->counter_used= 1;
return 0;
}
+ /* Lookup the current GROUP/ORDER field in the SELECT clause. */
uint counter;
bool unaliased;
- Item **item= find_item_in_list(it, fields, &counter,
+ select_item= find_item_in_list(order_item, fields, &counter,
REPORT_EXCEPT_NOT_FOUND, &unaliased);
- if (!item)
- return 1;
+ if (!select_item)
+ return 1; /* Some error occured. */
- if (item != (Item **)not_found_item)
+
+ /* Check whether the resolved field is not ambiguos. */
+ if (select_item != not_found_item)
{
/*
If we have found field not by its alias in select list but by its
original field name, we should additionaly check if we have conflict
for this name (in case if we would perform lookup in all tables).
*/
- if (unaliased && !it->fixed && it->fix_fields(thd, tables, order->item))
+ if (unaliased && !order_item->fixed && order_item->fix_fields(thd, tables, order->item))
return 1;
- order->item= ref_pointer_array + counter;
- order->in_field_list=1;
- return 0;
+ /* Lookup the current GROUP field in the FROM clause. */
+ order_item_type= order_item->type();
+ if (is_group_field &&
+ order_item_type == Item::FIELD_ITEM || order_item_type == Item::REF_ITEM)
+ {
+ Item **view_ref= NULL;
+ from_field= find_field_in_tables(thd, (Item_ident*) order_item, tables,
+ view_ref, IGNORE_ERRORS, TRUE);
+ if(!from_field)
+ from_field= (Field*) not_found_field;
+ }
+ else
+ from_field= (Field*) not_found_field;
+
+ if (from_field == not_found_field ||
+ from_field && from_field != view_ref_found &&
+ (*select_item)->type() == Item::FIELD_ITEM &&
+ ((Item_field*) (*select_item))->field->eq(from_field))
+ /*
+ If there is no such field in the FROM clause, or it is the same field as
+ the one found in the SELECT clause, then use the Item created for the
+ SELECT field. As a result if there was a derived field that 'shadowed'
+ a table field with the same name, the table field will be chosen over
+ the derived field.
+ */
+ {
+ order->item= ref_pointer_array + counter;
+ order->in_field_list=1;
+ return 0;
+ }
}
order->in_field_list=0;
/*
- We check it->fixed because Item_func_group_concat can put
+ We check order_item->fixed because Item_func_group_concat can put
arguments for which fix_fields already was called.
'it' reassigned in if condition because fix_field can change it.
*/
- if (!it->fixed &&
- (it->fix_fields(thd, tables, order->item) ||
- (it= *order->item)->check_cols(1) ||
+ if (!order_item->fixed &&
+ (order_item->fix_fields(thd, tables, order->item) ||
+ (order_item= *order->item)->check_cols(1) ||
thd->is_fatal_error))
return 1; // Wrong field
uint el= all_fields.elements;
- all_fields.push_front(it); // Add new field to field list
- ref_pointer_array[el]= it;
+ all_fields.push_front(order_item); // Add new field to field list
+ ref_pointer_array[el]= order_item;
order->item= ref_pointer_array + el;
return 0;
}
+
/*
Change order to point at item in select list. If item isn't a number
and doesn't exits in the select list, add it the the field list.
@@ -11246,7 +11319,7 @@ int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
for (; order; order=order->next)
{
if (find_order_in_list(thd, ref_pointer_array, tables, order, fields,
- all_fields))
+ all_fields, FALSE))
return 1;
}
return 0;
@@ -11298,13 +11371,12 @@ setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
for (; order; order=order->next)
{
if (find_order_in_list(thd, ref_pointer_array, tables, order, fields,
- all_fields))
+ all_fields, TRUE))
return 1;
(*order->item)->marker=1; /* Mark found */
if ((*order->item)->with_sum_func)
{
- my_printf_error(ER_WRONG_GROUP_FIELD, ER(ER_WRONG_GROUP_FIELD),MYF(0),
- (*order->item)->full_name());
+ my_error(ER_WRONG_GROUP_FIELD, MYF(0), (*order->item)->full_name());
return 1;
}
}
@@ -11319,9 +11391,7 @@ setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
if (item->type() != Item::SUM_FUNC_ITEM && !item->marker &&
!item->const_item())
{
- my_printf_error(ER_WRONG_FIELD_WITH_GROUP,
- ER(ER_WRONG_FIELD_WITH_GROUP),
- MYF(0),item->full_name());
+ my_error(ER_WRONG_FIELD_WITH_GROUP, MYF(0), item->full_name());
return 1;
}
}
@@ -12675,10 +12745,10 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
}
-int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
+bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
{
DBUG_ENTER("mysql_explain_union");
- int res= 0;
+ bool res= 0;
SELECT_LEX *first= unit->first_select();
for (SELECT_LEX *sl= first;
@@ -12729,9 +12799,7 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
first->options | thd->options | SELECT_DESCRIBE,
result, unit, first);
}
- if (res > 0 || thd->net.report_error)
- res= -1; // mysql_explain_select do not report error
- DBUG_RETURN(res);
+ DBUG_RETURN(res || thd->net.report_error);
}
@@ -12818,8 +12886,16 @@ void st_table_list::print(THD *thd, String *str)
{
append_identifier(thd, str, db, db_length);
str->append('.');
- append_identifier(thd, str, real_name, real_name_length);
- cmp_name= real_name;
+ if (schema_table)
+ {
+ append_identifier(thd, str, alias, strlen(alias));
+ cmp_name= alias;
+ }
+ else
+ {
+ append_identifier(thd, str, real_name, real_name_length);
+ cmp_name= real_name;
+ }
}
if (my_strcasecmp(table_alias_charset, cmp_name, alias))
{
@@ -12942,17 +13018,17 @@ void st_select_lex::print(THD *thd, String *str)
res new select_result object
RETURN
- 0 - OK
- -1 - error
+ FALSE - OK
+ TRUE - error
*/
-int JOIN::change_result(select_result *res)
+bool JOIN::change_result(select_result *res)
{
DBUG_ENTER("JOIN::change_result");
result= res;
if (!procedure && result->prepare(fields_list, select_lex->master_unit()))
{
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_select.h b/sql/sql_select.h
index e1bf60f6896..7fd9bf48b0b 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -333,7 +333,7 @@ class JOIN :public Sql_alloc
return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
!group_list);
}
- int change_result(select_result *result);
+ bool change_result(select_result *result);
};
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 557ec1bd5d2..17e6866f565 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -21,6 +21,7 @@
#include "sql_select.h" // For select_describe
#include "sql_acl.h"
#include "repl_failsafe.h"
+#include "sp_head.h"
#include <my_dir.h>
#ifdef HAVE_BERKELEY_DB
@@ -43,60 +44,11 @@ static int
view_store_create_info(THD *thd, TABLE_LIST *table, String *packet);
-/*
- Report list of databases
- A database is a directory in the mysql_data_home directory
-*/
-
-int
-mysqld_show_dbs(THD *thd,const char *wild)
-{
- Item_string *field=new Item_string("",0,thd->charset());
- List<Item> field_list;
- char *end;
- List<char> files;
- char *file_name;
- Protocol *protocol= thd->protocol;
- DBUG_ENTER("mysqld_show_dbs");
-
- field->name=(char*) thd->alloc(20+ (wild ? (uint) strlen(wild)+4: 0));
- field->max_length=NAME_LEN;
- end=strmov(field->name,"Database");
- if (wild && wild[0])
- strxmov(end," (",wild,")",NullS);
- field_list.push_back(field);
-
- if (protocol->send_fields(&field_list,
- Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
- if (mysql_find_files(thd,&files,NullS,mysql_data_home,wild,1))
- DBUG_RETURN(1);
- List_iterator_fast<char> it(files);
-
- while ((file_name=it++))
- {
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- if (thd->master_access & (DB_ACLS | SHOW_DB_ACL) ||
- acl_get(thd->host, thd->ip, thd->priv_user, file_name,0) ||
- (grant_option && !check_grant_db(thd, file_name)))
-#endif
- {
- protocol->prepare_for_resend();
- protocol->store(file_name, system_charset_info);
- if (protocol->write())
- DBUG_RETURN(-1);
- }
- }
- send_eof(thd);
- DBUG_RETURN(0);
-}
-
-
/***************************************************************************
List all open tables in a database
***************************************************************************/
-int mysqld_show_open_tables(THD *thd,const char *wild)
+bool mysqld_show_open_tables(THD *thd,const char *wild)
{
List<Item> field_list;
OPEN_TABLE_LIST *open_list;
@@ -110,10 +62,10 @@ int mysqld_show_open_tables(THD *thd,const char *wild)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
if (!(open_list=list_open_tables(thd,wild)) && thd->is_fatal_error)
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
for (; open_list ; open_list=open_list->next)
{
@@ -124,83 +76,19 @@ int mysqld_show_open_tables(THD *thd,const char *wild)
protocol->store_tiny((longlong) open_list->locked);
if (protocol->write())
{
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
/***************************************************************************
-** List all tables in a database (fast version)
-** A table is a .frm file in the current databasedir
-***************************************************************************/
-
-int mysqld_show_tables(THD *thd, const char *db, const char *wild,
- bool show_type)
-{
- Item_string *field=new Item_string("",0,thd->charset());
- List<Item> field_list;
- char path[FN_LEN],*end;
- List<char> files;
- char *file_name;
- Protocol *protocol= thd->protocol;
- uint len;
- DBUG_ENTER("mysqld_show_tables");
-
- field->name=(char*) thd->alloc(20+(uint) strlen(db)+
- (wild ? (uint) strlen(wild)+4:0));
- end=strxmov(field->name,"Tables_in_",db,NullS);
- if (wild && wild[0])
- strxmov(end," (",wild,")",NullS);
- field->max_length=NAME_LEN;
- (void) my_snprintf(path, FN_LEN, "%s/%s", mysql_data_home, db);
- end= path + (len= unpack_dirname(path,path));
- len= FN_LEN - len;
- field_list.push_back(field);
- if (show_type)
- field_list.push_back(new Item_empty_string("Table_type", 10));
- if (protocol->send_fields(&field_list,
- Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
- if (mysql_find_files(thd,&files,db,path,wild,0))
- DBUG_RETURN(-1);
- List_iterator_fast<char> it(files);
- while ((file_name=it++))
- {
- protocol->prepare_for_resend();
- protocol->store(file_name, system_charset_info);
- if (show_type)
- {
- my_snprintf(end, len, "/%s%s", file_name, reg_ext);
- switch (mysql_frm_type(path))
- {
- case FRMTYPE_ERROR:
- protocol->store("ERROR", system_charset_info);
- break;
- case FRMTYPE_TABLE:
- protocol->store("BASE TABLE", system_charset_info);
- break;
- case FRMTYPE_VIEW:
- protocol->store("VIEW", system_charset_info);
- break;
- default:
- DBUG_ASSERT(0); // this should be impossible
- }
- }
- if (protocol->write())
- DBUG_RETURN(-1);
- }
- send_eof(thd);
- DBUG_RETURN(0);
-}
-
-/***************************************************************************
** List all table types supported
***************************************************************************/
-int mysqld_show_storage_engines(THD *thd)
+bool mysqld_show_storage_engines(THD *thd)
{
List<Item> field_list;
Protocol *protocol= thd->protocol;
@@ -212,7 +100,7 @@ int mysqld_show_storage_engines(THD *thd)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
const char *default_type_name=
ha_get_storage_engine((enum db_type)thd->variables.table_type);
@@ -230,10 +118,10 @@ int mysqld_show_storage_engines(THD *thd)
protocol->store(option_name, system_charset_info);
protocol->store(types->comment, system_charset_info);
if (protocol->write())
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -275,7 +163,7 @@ static struct show_privileges_st sys_privileges[]=
{NullS, NullS, NullS}
};
-int mysqld_show_privileges(THD *thd)
+bool mysqld_show_privileges(THD *thd)
{
List<Item> field_list;
Protocol *protocol= thd->protocol;
@@ -287,7 +175,7 @@ int mysqld_show_privileges(THD *thd)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
show_privileges_st *privilege= sys_privileges;
for (privilege= sys_privileges; privilege->privilege ; privilege++)
@@ -297,10 +185,10 @@ int mysqld_show_privileges(THD *thd)
protocol->store(privilege->context, system_charset_info);
protocol->store(privilege->comment, system_charset_info);
if (protocol->write())
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -340,7 +228,7 @@ static struct show_column_type_st sys_column_types[]=
"A very small integer"},
};
-int mysqld_show_column_types(THD *thd)
+bool mysqld_show_column_types(THD *thd)
{
List<Item> field_list;
Protocol *protocol= thd->protocol;
@@ -363,7 +251,7 @@ int mysqld_show_column_types(THD *thd)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
/* TODO: Change the loop to not use 'i' */
for (uint i=0; i < sizeof(sys_column_types)/sizeof(sys_column_types[0]); i++)
@@ -384,10 +272,10 @@ int mysqld_show_column_types(THD *thd)
protocol->store(sys_column_types[i].default_value, system_charset_info);
protocol->store(sys_column_types[i].comment, system_charset_info);
if (protocol->write())
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -483,215 +371,10 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
/***************************************************************************
- Extended version of mysqld_show_tables
-***************************************************************************/
-
-int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
-{
- Item *item;
- List<char> files;
- List<Item> field_list;
- char path[FN_LEN];
- char *file_name;
- 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);
- (void) unpack_dirname(path,path);
- field_list.push_back(item=new Item_empty_string("Name",NAME_LEN));
- field_list.push_back(item=new Item_empty_string("Engine",10));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Version", (longlong) 0, 21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_empty_string("Row_format",10));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Rows",(longlong) 1,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Avg_row_length",(int32) 0,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Data_length",(longlong) 1,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Max_data_length",(longlong) 1,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Index_length",(longlong) 1,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Data_free",(longlong) 1,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Auto_increment",(longlong) 1,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_datetime("Create_time"));
- item->maybe_null=1;
- field_list.push_back(item=new Item_datetime("Update_time"));
- item->maybe_null=1;
- field_list.push_back(item=new Item_datetime("Check_time"));
- item->maybe_null=1;
- field_list.push_back(item=new Item_empty_string("Collation",32));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Checksum",(longlong) 1,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_empty_string("Create_options",255));
- item->maybe_null=1;
- field_list.push_back(item=new Item_empty_string("Comment",80));
- item->maybe_null=1;
- if (protocol->send_fields(&field_list,
- Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
-
- if (mysql_find_files(thd,&files,db,path,wild,0))
- DBUG_RETURN(-1);
- List_iterator_fast<char> it(files);
- while ((file_name=it++))
- {
- TABLE_LIST table_list;
- bzero((char*) &table_list,sizeof(table_list));
- protocol->prepare_for_resend();
- protocol->store(file_name, system_charset_info);
- table_list.db=(char*) db;
- table_list.real_name= table_list.alias= file_name;
- table_list.select_lex= &thd->lex->select_lex;
- if (lower_case_table_names)
- my_casedn_str(files_charset_info, file_name);
- 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 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)
- {
- for (uint i= 2; i < field_list.elements; i++)
- protocol->store_null();
- protocol->store("view", system_charset_info);
- }
- else
- {
- const char *str;
- handler *file= (table= table_list.table)->file;
- file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK);
- protocol->store(file->table_type(), system_charset_info);
- protocol->store((ulonglong) table->frm_version);
- str= ((table->db_options_in_use & HA_OPTION_COMPRESS_RECORD) ?
- "Compressed" :
- (table->db_options_in_use & HA_OPTION_PACK_RECORD) ?
- "Dynamic" : "Fixed");
- protocol->store(str, system_charset_info);
- protocol->store((ulonglong) file->records);
- protocol->store((ulonglong) file->mean_rec_length);
- protocol->store((ulonglong) file->data_file_length);
- if (file->max_data_file_length)
- protocol->store((ulonglong) file->max_data_file_length);
- else
- protocol->store_null();
- protocol->store((ulonglong) file->index_file_length);
- protocol->store((ulonglong) file->delete_length);
- if (table->found_next_number_field)
- {
- table->next_number_field=table->found_next_number_field;
- table->next_number_field->reset();
- file->update_auto_increment();
- protocol->store(table->next_number_field->val_int());
- table->next_number_field=0;
- }
- else
- protocol->store_null();
- if (!file->create_time)
- protocol->store_null();
- else
- {
- thd->variables.time_zone->gmt_sec_to_TIME(&time, file->create_time);
- protocol->store(&time);
- }
- if (!file->update_time)
- protocol->store_null();
- else
- {
- thd->variables.time_zone->gmt_sec_to_TIME(&time, file->update_time);
- protocol->store(&time);
- }
- if (!file->check_time)
- protocol->store_null();
- else
- {
- thd->variables.time_zone->gmt_sec_to_TIME(&time, file->check_time);
- protocol->store(&time);
- }
- str= (table->table_charset ? table->table_charset->name : "default");
- protocol->store(str, system_charset_info);
- if (file->table_flags() & HA_HAS_CHECKSUM)
- protocol->store((ulonglong)file->checksum());
- else
- protocol->store_null(); // Checksum
- {
- char option_buff[350],*ptr;
- ptr=option_buff;
- if (table->min_rows)
- {
- ptr=strmov(ptr," min_rows=");
- ptr=longlong10_to_str(table->min_rows,ptr,10);
- }
- if (table->max_rows)
- {
- ptr=strmov(ptr," max_rows=");
- ptr=longlong10_to_str(table->max_rows,ptr,10);
- }
- if (table->avg_row_length)
- {
- ptr=strmov(ptr," avg_row_length=");
- ptr=longlong10_to_str(table->avg_row_length,ptr,10);
- }
- if (table->db_create_options & HA_OPTION_PACK_KEYS)
- ptr=strmov(ptr," pack_keys=1");
- if (table->db_create_options & HA_OPTION_NO_PACK_KEYS)
- ptr=strmov(ptr," pack_keys=0");
- if (table->db_create_options & HA_OPTION_CHECKSUM)
- ptr=strmov(ptr," checksum=1");
- if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
- ptr=strmov(ptr," delay_key_write=1");
- if (table->row_type != ROW_TYPE_DEFAULT)
- ptr=strxmov(ptr, " row_format=", ha_row_type[(uint) table->row_type],
- NullS);
- if (file->raid_type)
- {
- char buff[100];
- sprintf(buff," raid_type=%s raid_chunks=%d raid_chunksize=%ld",
- my_raid_type(file->raid_type), file->raid_chunks, file->raid_chunksize/RAID_BLOCK_SIZE);
- ptr=strmov(ptr,buff);
- }
- protocol->store(option_buff+1,
- (ptr == option_buff ? 0 : (uint) (ptr-option_buff)-1)
- , system_charset_info);
- }
- {
- char *comment=table->file->update_table_comment(table->comment);
- protocol->store(comment, system_charset_info);
- if (comment != table->comment)
- my_free(comment,MYF(0));
- }
- }
- close_thread_tables(thd, 0);
- if (protocol->write())
- DBUG_RETURN(-1);
- }
- send_eof(thd);
- DBUG_RETURN(0);
-}
-
-
-/***************************************************************************
** List all columns in a table_list->real_name
***************************************************************************/
-int
+bool
mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
bool verbose)
{
@@ -707,11 +390,9 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
table_list->real_name));
table_list->lock_type= TL_UNLOCK;
- if ((res= open_and_lock_tables(thd, table_list)))
+ if (open_and_lock_tables(thd, table_list))
{
- if (res < 0)
- send_error(thd);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
table= table_list->table;
file=table->file;
@@ -737,7 +418,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
// Send first number of fields and records
if (protocol->send_records_num(&field_list, (ulonglong)file->records) ||
protocol->send_fields(&field_list, Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
restore_record(table,default_values); // Get empty record
Field **ptr,*field;
@@ -846,16 +527,16 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
system_charset_info);
}
if (protocol->write())
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
}
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
-int
+bool
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
{
TABLE *table;
@@ -868,18 +549,16 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
table_list->real_name));
/* Only one table for now, but VIEW can involve several tables */
- if ((res= open_and_lock_tables(thd, table_list)))
+ if (open_and_lock_tables(thd, table_list))
{
- if (res < 0)
- send_error(thd);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
/* TODO: add environment variables show when it become possible */
if (thd->lex->only_view && !table_list->view)
{
- my_error(ER_WRONG_OBJECT, MYF(0), table_list->db,
- table_list->real_name, "VIEW");
- DBUG_RETURN(-1);
+ my_error(ER_WRONG_OBJECT, MYF(0),
+ table_list->db, table_list->real_name, "VIEW");
+ DBUG_RETURN(TRUE);
}
table= table_list->table;
@@ -887,7 +566,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
if ((table_list->view ?
view_store_create_info(thd, table_list, &buffer) :
store_create_info(thd, table, &buffer)))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
List<Item> field_list;
if (table_list->view)
@@ -906,31 +585,31 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
protocol->prepare_for_resend();
buffer.length(0);
if (table_list->view)
{
protocol->store(table_list->view_name.str, system_charset_info);
if (view_store_create_info(thd, table_list, &buffer))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
else
{
protocol->store(table->table_name, system_charset_info);
if (store_create_info(thd, table, &buffer))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
if (protocol->write())
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
-int mysqld_show_create_db(THD *thd, char *dbname,
- HA_CREATE_INFO *create_info)
+bool mysqld_show_create_db(THD *thd, char *dbname,
+ HA_CREATE_INFO *create_info)
{
int length;
char path[FN_REFLEN];
@@ -947,8 +626,8 @@ int mysqld_show_create_db(THD *thd, char *dbname,
if (check_db_name(dbname))
{
- net_printf(thd,ER_WRONG_DB_NAME, dbname);
- DBUG_RETURN(1);
+ my_error(ER_WRONG_DB_NAME, MYF(0), dbname);
+ DBUG_RETURN(TRUE);
}
#ifndef NO_EMBEDDED_ACCESS_CHECKS
@@ -959,11 +638,11 @@ int mysqld_show_create_db(THD *thd, char *dbname,
thd->master_access);
if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname)))
{
- net_printf(thd,ER_DBACCESS_DENIED_ERROR,
- thd->priv_user, thd->host_or_ip, dbname);
+ my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
+ thd->priv_user, thd->host_or_ip, dbname);
mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
thd->priv_user, thd->host_or_ip, dbname);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
#endif
@@ -977,8 +656,8 @@ int mysqld_show_create_db(THD *thd, char *dbname,
}
if (access(path,F_OK))
{
- net_printf(thd,ER_BAD_DB_ERROR,dbname);
- DBUG_RETURN(1);
+ my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
+ DBUG_RETURN(TRUE);
}
if (found_libchar)
path[length-1]= FN_LIBCHAR;
@@ -991,7 +670,7 @@ int mysqld_show_create_db(THD *thd, char *dbname,
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
protocol->prepare_for_resend();
protocol->store(dbname, strlen(dbname), system_charset_info);
@@ -1016,12 +695,12 @@ int mysqld_show_create_db(THD *thd, char *dbname,
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
if (protocol->write())
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
-int
+bool
mysqld_show_logs(THD *thd)
{
List<Item> field_list;
@@ -1034,112 +713,15 @@ mysqld_show_logs(THD *thd)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
#ifdef HAVE_BERKELEY_DB
if ((have_berkeley_db == SHOW_OPTION_YES) && berkeley_show_logs(protocol))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
#endif
send_eof(thd);
- DBUG_RETURN(0);
-}
-
-
-int
-mysqld_show_keys(THD *thd, TABLE_LIST *table_list)
-{
- TABLE *table;
- Protocol *protocol= thd->protocol;
- DBUG_ENTER("mysqld_show_keys");
- DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
- table_list->real_name));
-
- if (!(table = open_ltable(thd, table_list, TL_UNLOCK)))
- {
- send_error(thd);
- DBUG_RETURN(1);
- }
-
- List<Item> field_list;
- Item *item;
- field_list.push_back(new Item_empty_string("Table",NAME_LEN));
- field_list.push_back(new Item_return_int("Non_unique",1, MYSQL_TYPE_TINY));
- field_list.push_back(new Item_empty_string("Key_name",NAME_LEN));
- field_list.push_back(new Item_return_int("Seq_in_index",2, MYSQL_TYPE_TINY));
- field_list.push_back(new Item_empty_string("Column_name",NAME_LEN));
- field_list.push_back(item=new Item_empty_string("Collation",1));
- item->maybe_null=1;
- field_list.push_back(item=new Item_int("Cardinality",0,21));
- item->maybe_null=1;
- field_list.push_back(item=new Item_return_int("Sub_part",3,
- MYSQL_TYPE_TINY));
- item->maybe_null=1;
- field_list.push_back(item=new Item_empty_string("Packed",10));
- item->maybe_null=1;
- field_list.push_back(new Item_empty_string("Null",3));
- field_list.push_back(new Item_empty_string("Index_type",16));
- field_list.push_back(new Item_empty_string("Comment",255));
- item->maybe_null=1;
-
- if (protocol->send_fields(&field_list,
- Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
-
- KEY *key_info=table->key_info;
- table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME);
- for (uint i=0 ; i < table->keys ; i++,key_info++)
- {
- KEY_PART_INFO *key_part= key_info->key_part;
- const char *str;
- for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
- {
- protocol->prepare_for_resend();
- protocol->store(table->table_name, system_charset_info);
- protocol->store_tiny((longlong) ((key_info->flags & HA_NOSAME) ? 0 :1));
- protocol->store(key_info->name, system_charset_info);
- protocol->store_tiny((longlong) (j+1));
- str=(key_part->field ? key_part->field->field_name :
- "?unknown field?");
- protocol->store(str, system_charset_info);
- if (table->file->index_flags(i, j, 0) & HA_READ_ORDER)
- protocol->store(((key_part->key_part_flag & HA_REVERSE_SORT) ?
- "D" : "A"), 1, system_charset_info);
- else
- protocol->store_null(); /* purecov: inspected */
- KEY *key=table->key_info+i;
- if (key->rec_per_key[j])
- {
- ha_rows records=(table->file->records / key->rec_per_key[j]);
- protocol->store((ulonglong) records);
- }
- else
- protocol->store_null();
-
- /* Check if we have a key part that only uses part of the field */
- if (!(key_info->flags & HA_FULLTEXT) && (!key_part->field ||
- key_part->length != table->field[key_part->fieldnr-1]->key_length()))
- protocol->store_tiny((longlong) key_part->length);
- else
- protocol->store_null();
- protocol->store_null(); // No pack_information yet
-
- /* Null flag */
- uint flags= key_part->field ? key_part->field->flags : 0;
- char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
- protocol->store((const char*) pos, system_charset_info);
- protocol->store(table->file->index_type(i), system_charset_info);
- /* Comment */
- if (!table->keys_in_use.is_set(i))
- protocol->store("disabled",8, system_charset_info);
- else
- protocol->store("", 0, system_charset_info);
- if (protocol->write())
- DBUG_RETURN(1); /* purecov: inspected */
- }
- }
- send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -1157,12 +739,8 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
DBUG_PRINT("enter",("table: %s",table_list->real_name));
table_list->lock_type= TL_UNLOCK;
- if ((res= open_and_lock_tables(thd, table_list)))
- {
- if (res < 0)
- send_error(thd);
+ if (open_and_lock_tables(thd, table_list))
DBUG_VOID_RETURN;
- }
table= table_list->table;
List<Item> field_list;
@@ -1816,116 +1394,10 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
Status functions
*****************************************************************************/
-static bool write_collation(Protocol *protocol, CHARSET_INFO *cs)
-{
- protocol->prepare_for_resend();
- protocol->store(cs->name, system_charset_info);
- protocol->store(cs->csname, system_charset_info);
- protocol->store_short((longlong) cs->number);
- protocol->store((cs->state & MY_CS_PRIMARY) ? "Yes" : "",system_charset_info);
- protocol->store((cs->state & MY_CS_COMPILED)? "Yes" : "",system_charset_info);
- protocol->store_short((longlong) cs->strxfrm_multiply);
- return protocol->write();
-}
-
-int mysqld_show_collations(THD *thd, const char *wild)
-{
- char buff[8192];
- String packet2(buff,sizeof(buff),thd->charset());
- List<Item> field_list;
- CHARSET_INFO **cs;
- Protocol *protocol= thd->protocol;
-
- DBUG_ENTER("mysqld_show_charsets");
-
- field_list.push_back(new Item_empty_string("Collation",30));
- field_list.push_back(new Item_empty_string("Charset",30));
- field_list.push_back(new Item_return_int("Id",11, FIELD_TYPE_SHORT));
- field_list.push_back(new Item_empty_string("Default",30));
- field_list.push_back(new Item_empty_string("Compiled",30));
- field_list.push_back(new Item_return_int("Sortlen",3, FIELD_TYPE_SHORT));
-
- if (protocol->send_fields(&field_list,
- Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
-
- for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ )
- {
- CHARSET_INFO **cl;
- if (!cs[0] || !(cs[0]->state & MY_CS_AVAILABLE) ||
- !(cs[0]->state & MY_CS_PRIMARY))
- continue;
- for ( cl= all_charsets; cl < all_charsets+255 ;cl ++)
- {
- if (!cl[0] || !(cl[0]->state & MY_CS_AVAILABLE) ||
- !my_charset_same(cs[0],cl[0]))
- continue;
- if (!(wild && wild[0] &&
- wild_case_compare(system_charset_info,cl[0]->name,wild)))
- {
- if (write_collation(protocol, cl[0]))
- goto err;
- }
- }
- }
- send_eof(thd);
- DBUG_RETURN(0);
-err:
- DBUG_RETURN(1);
-}
-
-static bool write_charset(Protocol *protocol, CHARSET_INFO *cs)
-{
- protocol->prepare_for_resend();
- protocol->store(cs->csname, system_charset_info);
- protocol->store(cs->comment ? cs->comment : "", system_charset_info);
- protocol->store(cs->name, system_charset_info);
- protocol->store_short((longlong) cs->mbmaxlen);
- return protocol->write();
-}
-
-int mysqld_show_charsets(THD *thd, const char *wild)
-{
- char buff[8192];
- String packet2(buff,sizeof(buff),thd->charset());
- List<Item> field_list;
- CHARSET_INFO **cs;
- Protocol *protocol= thd->protocol;
-
- DBUG_ENTER("mysqld_show_charsets");
-
- field_list.push_back(new Item_empty_string("Charset",30));
- field_list.push_back(new Item_empty_string("Description",60));
- field_list.push_back(new Item_empty_string("Default collation",60));
- field_list.push_back(new Item_return_int("Maxlen",3, FIELD_TYPE_SHORT));
-
- if (protocol->send_fields(&field_list,
- Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
-
- for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ )
- {
- if (cs[0] && (cs[0]->state & MY_CS_PRIMARY) &&
- (cs[0]->state & MY_CS_AVAILABLE) &&
- !(wild && wild[0] &&
- wild_case_compare(system_charset_info,cs[0]->csname,wild)))
- {
- if (write_charset(protocol, cs[0]))
- goto err;
- }
- }
- send_eof(thd);
- DBUG_RETURN(0);
-err:
- DBUG_RETURN(1);
-}
-
-
-
-int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
- enum enum_var_type value_type,
- pthread_mutex_t *mutex,
- struct system_status_var *status_var)
+bool mysqld_show(THD *thd, const char *wild, show_var_st *variables,
+ enum enum_var_type value_type,
+ pthread_mutex_t *mutex,
+ struct system_status_var *status_var)
{
char buff[1024];
List<Item> field_list;
@@ -1937,7 +1409,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
field_list.push_back(new Item_empty_string("Value",256));
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1); /* purecov: inspected */
+ DBUG_RETURN(TRUE); /* purecov: inspected */
null_lex_str.str= 0; // For sys_var->value_ptr()
null_lex_str.length= 0;
@@ -1965,7 +1437,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
switch (show_type) {
case SHOW_LONG_STATUS:
case SHOW_LONG_CONST_STATUS:
- value= ((char *) status_var + (uint) value);
+ value= ((char *) status_var + (ulong) value);
/* fall through */
case SHOW_LONG:
case SHOW_LONG_CONST:
@@ -2229,11 +1701,11 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
}
pthread_mutex_unlock(mutex);
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
err:
pthread_mutex_unlock(mutex);
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
@@ -2261,6 +1733,1686 @@ void calc_sum_of_all_status(STATUS_VAR *to)
}
+LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str,
+ const char* str, uint length,
+ bool allocate_lex_string)
+{
+ MEM_ROOT *mem= thd->mem_root;
+ if (allocate_lex_string)
+ lex_str= (LEX_STRING *)thd->alloc(sizeof(LEX_STRING));
+ lex_str->str= strmake_root(mem, str, length);
+ lex_str->length= length;
+ return lex_str;
+}
+
+
+/* INFORMATION_SCHEMA name */
+LEX_STRING information_schema_name= {(char*)"information_schema", 18};
+extern ST_SCHEMA_TABLE schema_tables[];
+
+typedef struct st_index_field_values
+{
+ const char *db_value, *table_value;
+} INDEX_FIELD_VALUES;
+
+
+void get_index_field_values(LEX *lex, INDEX_FIELD_VALUES *index_field_values)
+{
+ const char *wild= lex->wild ? lex->wild->ptr() : NullS;
+ switch (lex->orig_sql_command) {
+ case SQLCOM_SHOW_DATABASES:
+ index_field_values->db_value= wild;
+ break;
+ case SQLCOM_SHOW_TABLES:
+ case SQLCOM_SHOW_TABLE_STATUS:
+ index_field_values->db_value= lex->current_select->db;
+ index_field_values->table_value= wild;
+ break;
+ default:
+ index_field_values->db_value= NullS;
+ index_field_values->table_value= NullS;
+ break;
+ }
+}
+
+
+int make_table_list(THD *thd, SELECT_LEX *sel,
+ char *db, char *table)
+{
+ Table_ident *table_ident;
+ LEX_STRING ident_db, ident_table;
+ ident_db.str= db;
+ ident_db.length= strlen(db);
+ ident_table.str= table;
+ ident_table.length= strlen(table);
+ table_ident= new Table_ident(thd, ident_db, ident_table, 1);
+ sel->init_query();
+ if(!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ,
+ (List<String> *) 0, (List<String> *) 0))
+ return 1;
+ return 0;
+}
+
+
+bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
+{
+ if (item->type() == Item::FUNC_ITEM)
+ {
+ Item_func *item_func= (Item_func*)item;
+ Item **child;
+ Item **item_end= (item_func->arguments()) + item_func->argument_count();
+ for (child= item_func->arguments(); child != item_end; child++)
+ if (!uses_only_table_name_fields(*child, table))
+ return 0;
+ return 1;
+ }
+ else if (item->type() == Item::FIELD_ITEM)
+ {
+ Item_field *item_field= (Item_field*)item;
+ CHARSET_INFO *cs= system_charset_info;
+ ST_SCHEMA_TABLE *schema_table= table->schema_table;
+ ST_FIELD_INFO *field_info= schema_table->fields_info;
+ const char *field_name1= field_info[schema_table->idx_field1].field_name;
+ const char *field_name2= field_info[schema_table->idx_field2].field_name;
+ if(table->table != item_field->field->table ||
+ (cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
+ (uchar *) item_field->field_name,
+ strlen(item_field->field_name)) &&
+ cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
+ (uchar *) item_field->field_name,
+ strlen(item_field->field_name))))
+ return 0;
+ else
+ return 1;
+ }
+ else
+ return 1;
+}
+
+
+static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table)
+{
+ if (!cond)
+ return (COND*) 0;
+ if (cond->type() == Item::COND_ITEM)
+ {
+ if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
+ {
+ /* Create new top level AND item */
+ Item_cond_and *new_cond=new Item_cond_and;
+ if (!new_cond)
+ return (COND*) 0;
+ List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
+ Item *item;
+ while ((item=li++))
+ {
+ Item *fix= make_cond_for_info_schema(item, table);
+ if (fix)
+ new_cond->argument_list()->push_back(fix);
+ }
+ switch (new_cond->argument_list()->elements) {
+ case 0:
+ return (COND*) 0;
+ case 1:
+ return new_cond->argument_list()->head();
+ default:
+ new_cond->quick_fix_field();
+ return new_cond;
+ }
+ }
+ else
+ { // Or list
+ Item_cond_or *new_cond=new Item_cond_or;
+ if (!new_cond)
+ return (COND*) 0;
+ List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
+ Item *item;
+ while ((item=li++))
+ {
+ Item *fix=make_cond_for_info_schema(item, table);
+ if (!fix)
+ return (COND*) 0;
+ new_cond->argument_list()->push_back(fix);
+ }
+ new_cond->quick_fix_field();
+ new_cond->top_level_item();
+ return new_cond;
+ }
+ }
+
+ if (!uses_only_table_name_fields(cond, table))
+ return (COND*) 0;
+ return cond;
+}
+
+
+int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+ LEX *lex= thd->lex;
+ TABLE *table= tables->table;
+ SELECT_LEX *select_lex= &lex->select_lex;
+ SELECT_LEX *lsel= tables->schema_select_lex;
+ ST_SCHEMA_TABLE *schema_table= tables->schema_table;
+ DBUG_ENTER("fill_schema_tables");
+
+ if (lsel)
+ {
+ TABLE *old_open_tables= thd->open_tables;
+ TABLE_LIST *show_table_list= (TABLE_LIST*) lsel->table_list.first;
+ lex->all_selects_list= lsel;
+ bool res= open_and_lock_tables(thd, show_table_list);
+ if (schema_table->process_table(thd, show_table_list,
+ table, res, show_table_list->db,
+ show_table_list->real_name))
+ {
+ DBUG_RETURN(1);
+ }
+ close_thread_tables(thd, 0, 0, old_open_tables);
+ show_table_list->table= 0;
+ lex->all_selects_list= select_lex;
+ DBUG_RETURN(0);
+ }
+
+ SELECT_LEX sel;
+ INDEX_FIELD_VALUES idx_field_vals;
+ char path[FN_REFLEN], *end, *base_name, *file_name;
+ uint len;
+ List<char> bases;
+ lex->all_selects_list= &sel;
+ enum enum_schema_tables schema_table_idx=
+ (enum enum_schema_tables) (schema_table - &schema_tables[0]);
+ thr_lock_type lock_type= TL_UNLOCK;
+ if (schema_table_idx == SCH_TABLES)
+ lock_type= TL_READ;
+ get_index_field_values(lex, &idx_field_vals);
+ if (mysql_find_files(thd, &bases, NullS, mysql_data_home,
+ idx_field_vals.db_value, 1))
+ return 1;
+ List_iterator_fast<char> it(bases);
+ COND *partial_cond= make_cond_for_info_schema(cond, tables);
+ while ((base_name=it++) ||
+ /*
+ generate error for non existing database.
+ (to save old behaviour for SHOW TABLES FROM db)
+ */
+ ((lex->orig_sql_command == SQLCOM_SHOW_TABLES ||
+ lex->orig_sql_command == SQLCOM_SHOW_TABLE_STATUS) &&
+ (base_name= select_lex->db) && !bases.elements))
+ {
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ if (!check_access(thd,SELECT_ACL, base_name, &thd->col_access,0,1) ||
+ thd->master_access & (DB_ACLS | SHOW_DB_ACL) ||
+ acl_get(thd->host, thd->ip, thd->priv_user, base_name,0) ||
+ (grant_option && !check_grant_db(thd, base_name)))
+#endif
+ {
+ List<char> files;
+ strxmov(path, mysql_data_home, "/", base_name, NullS);
+ end= path + (len= unpack_dirname(path,path));
+ len= FN_LEN - len;
+ if (mysql_find_files(thd, &files, base_name,
+ path, idx_field_vals.table_value, 0))
+ DBUG_RETURN(1);
+
+ List_iterator_fast<char> it(files);
+ while ((file_name=it++))
+ {
+ restore_record(table, default_values);
+ table->field[schema_table->idx_field1]->
+ store(base_name, strlen(base_name), system_charset_info);
+ table->field[schema_table->idx_field2]->
+ store(file_name, strlen(file_name),system_charset_info);
+ if (!partial_cond || partial_cond->val_int())
+ {
+ if (schema_table_idx == SCH_TABLE_NAMES)
+ {
+ if (lex->verbose || lex->orig_sql_command == SQLCOM_END)
+ {
+ my_snprintf(end, len, "/%s%s", file_name, reg_ext);
+ switch (mysql_frm_type(path))
+ {
+ case FRMTYPE_ERROR:
+ table->field[3]->store("ERROR", 5, system_charset_info);
+ break;
+ case FRMTYPE_TABLE:
+ table->field[3]->store("BASE TABLE", 10, system_charset_info);
+ break;
+ case FRMTYPE_VIEW:
+ table->field[3]->store("VIEW", 4, system_charset_info);
+ break;
+ default:
+ DBUG_ASSERT(0);
+ }
+ }
+ table->file->write_row(table->record[0]);
+ }
+ else
+ {
+ int res;
+ TABLE *old_open_tables= thd->open_tables;
+ if (make_table_list(thd, &sel, base_name, file_name))
+ DBUG_RETURN(1);
+ TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
+ show_table_list->lock_type= lock_type;
+ res= open_and_lock_tables(thd, show_table_list);
+ if (schema_table->process_table(thd, show_table_list, table,
+ res, base_name, file_name))
+ {
+ DBUG_RETURN(1);
+ }
+ close_thread_tables(thd, 0, 0, old_open_tables);
+ }
+ }
+ }
+ }
+ }
+ lex->all_selects_list= select_lex;
+ DBUG_RETURN(0);
+}
+
+
+int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+ char path[FN_REFLEN],*end;
+ bool found_libchar;
+ INDEX_FIELD_VALUES idx_field_vals;
+ List<char> files;
+ char *file_name;
+ uint length;
+ HA_CREATE_INFO create;
+ TABLE *table= tables->table;
+
+ get_index_field_values(thd->lex, &idx_field_vals);
+ if (mysql_find_files(thd, &files, NullS, mysql_data_home,
+ idx_field_vals.db_value, 1))
+ return 1;
+ List_iterator_fast<char> it(files);
+ while ((file_name=it++))
+ {
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ if (thd->master_access & (DB_ACLS | SHOW_DB_ACL) ||
+ acl_get(thd->host, thd->ip, thd->priv_user, file_name,0) ||
+ (grant_option && !check_grant_db(thd, file_name)))
+#endif
+ {
+ strxmov(path, mysql_data_home, "/", file_name, NullS);
+ length=unpack_dirname(path,path); // Convert if not unix
+ found_libchar= 0;
+ if (length && path[length-1] == FN_LIBCHAR)
+ {
+ found_libchar= 1;
+ path[length-1]=0; // remove ending '\'
+ }
+
+ if (found_libchar)
+ path[length-1]= FN_LIBCHAR;
+ strmov(path+length, MY_DB_OPT_FILE);
+ load_db_opt(thd, path, &create);
+ restore_record(table, default_values);
+ table->field[1]->store(file_name, strlen(file_name), system_charset_info);
+ table->field[2]->store(create.default_table_charset->csname,
+ strlen(create.default_table_charset->csname),
+ system_charset_info);
+ table->file->write_row(table->record[0]);
+ }
+ }
+ return 0;
+}
+
+
+static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
+ TABLE *table, bool res,
+ const char *base_name,
+ const char *file_name)
+{
+ const char *tmp_buff;
+ TIME time;
+ CHARSET_INFO *cs= system_charset_info;
+
+ DBUG_ENTER("get_schema_tables_record");
+ restore_record(table, default_values);
+ table->field[1]->store(base_name, strlen(base_name), cs);
+ table->field[2]->store(file_name, strlen(file_name), cs);
+ if (res)
+ {
+ /*
+ there was errors during opening tables
+ */
+ const char *error= thd->net.last_error;
+ table->field[20]->store(error, strlen(error), cs);
+ thd->clear_error();
+ }
+ else if (tables->view)
+ {
+ table->field[3]->store("VIEW", 4, cs);
+ table->field[20]->store("view", 4, cs);
+ }
+ else
+ {
+ TABLE *show_table= tables->table;
+ handler *file= show_table->file;
+ file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK);
+ table->field[3]->store("BASE TABLE", 10, cs);
+ for (int i= 4; i < 20; i++)
+ {
+ if ((i > 12 && i < 17) || i == 18)
+ continue;
+ table->field[i]->set_notnull();
+ }
+ tmp_buff= file->table_type();
+ table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
+ table->field[5]->store((longlong) show_table->frm_version);
+ tmp_buff= ((show_table->db_options_in_use &
+ HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
+ (show_table->db_options_in_use & HA_OPTION_PACK_RECORD) ?
+ "Dynamic" : "Fixed");
+ table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
+ table->field[7]->store((longlong) file->records);
+ table->field[8]->store((longlong) file->mean_rec_length);
+ table->field[9]->store((longlong) file->data_file_length);
+ if (file->max_data_file_length)
+ {
+ table->field[10]->store((longlong) file->max_data_file_length);
+ }
+ table->field[11]->store((longlong) file->index_file_length);
+ table->field[12]->store((longlong) file->delete_length);
+ if (table->found_next_number_field)
+ {
+ show_table->next_number_field=show_table->found_next_number_field;
+ show_table->next_number_field->reset();
+ file->update_auto_increment();
+ table->field[13]->store((longlong) show_table->
+ next_number_field->val_int());
+ table->field[13]->set_notnull();
+ show_table->next_number_field=0;
+ }
+ if (file->create_time)
+ {
+ thd->variables.time_zone->gmt_sec_to_TIME(&time,
+ file->create_time);
+ table->field[14]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ table->field[14]->set_notnull();
+ }
+ if (file->update_time)
+ {
+ thd->variables.time_zone->gmt_sec_to_TIME(&time,
+ file->update_time);
+ table->field[15]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ table->field[15]->set_notnull();
+ }
+ if (file->check_time)
+ {
+ thd->variables.time_zone->gmt_sec_to_TIME(&time, file->check_time);
+ table->field[16]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ table->field[16]->set_notnull();
+ }
+ tmp_buff= (show_table->table_charset ? show_table->
+ table_charset->name : "default");
+ table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
+ if (file->table_flags() & HA_HAS_CHECKSUM)
+ {
+ table->field[18]->store((longlong) file->checksum());
+ table->field[18]->set_notnull();
+ }
+
+ char option_buff[350],*ptr;
+ ptr=option_buff;
+ if (show_table->min_rows)
+ {
+ ptr=strmov(ptr," min_rows=");
+ ptr=longlong10_to_str(show_table->min_rows,ptr,10);
+ }
+ if (show_table->max_rows)
+ {
+ ptr=strmov(ptr," max_rows=");
+ ptr=longlong10_to_str(show_table->max_rows,ptr,10);
+ }
+ if (show_table->avg_row_length)
+ {
+ ptr=strmov(ptr," avg_row_length=");
+ ptr=longlong10_to_str(show_table->avg_row_length,ptr,10);
+ }
+ if (show_table->db_create_options & HA_OPTION_PACK_KEYS)
+ ptr=strmov(ptr," pack_keys=1");
+ if (show_table->db_create_options & HA_OPTION_NO_PACK_KEYS)
+ ptr=strmov(ptr," pack_keys=0");
+ if (show_table->db_create_options & HA_OPTION_CHECKSUM)
+ ptr=strmov(ptr," checksum=1");
+ if (show_table->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
+ ptr=strmov(ptr," delay_key_write=1");
+ if (show_table->row_type != ROW_TYPE_DEFAULT)
+ ptr=strxmov(ptr, " row_format=",
+ ha_row_type[(uint) show_table->row_type],
+ NullS);
+ if (file->raid_type)
+ {
+ char buff[100];
+ my_snprintf(buff,sizeof(buff),
+ " raid_type=%s raid_chunks=%d raid_chunksize=%ld",
+ my_raid_type(file->raid_type), file->raid_chunks,
+ file->raid_chunksize/RAID_BLOCK_SIZE);
+ ptr=strmov(ptr,buff);
+ }
+ table->field[19]->store(option_buff+1,
+ (ptr == option_buff ? 0 :
+ (uint) (ptr-option_buff)-1), cs);
+
+ char *comment= show_table->file->
+ update_table_comment(show_table->comment);
+ table->field[20]->store(comment, strlen(comment), cs);
+ if (comment != show_table->comment)
+ my_free(comment,MYF(0));
+ }
+ table->file->write_row(table->record[0]);
+ DBUG_RETURN(0);
+}
+
+
+static int get_schema_column_record(THD *thd, struct st_table_list *tables,
+ TABLE *table, bool res,
+ const char *base_name,
+ const char *file_name)
+{
+ TIME time;
+ const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
+ CHARSET_INFO *cs= system_charset_info;
+ DBUG_ENTER("get_schema_column_record");
+ if (res)
+ {
+ DBUG_RETURN(1);
+ }
+
+ TABLE *show_table= tables->table;
+ handler *file= show_table->file;
+ file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
+ restore_record(show_table, default_values);
+ Field **ptr,*field;
+ int count= 0;
+ for (ptr=show_table->field; (field= *ptr) ; ptr++)
+ {
+ if (!wild || !wild[0] ||
+ !wild_case_compare(system_charset_info, field->field_name,wild))
+ {
+ uint tmp_length;
+ char *tmp_buff;
+ byte *pos;
+ uint flags=field->flags;
+ char tmp[MAX_FIELD_WIDTH];
+ char tmp1[MAX_FIELD_WIDTH];
+ String type(tmp,sizeof(tmp), system_charset_info);
+ char tmp_buffer[128];
+ count++;
+ restore_record(table, default_values);
+ table->field[1]->store(base_name, strlen(base_name), cs);
+ table->field[2]->store(file_name, strlen(file_name), cs);
+ table->field[3]->store(field->field_name, strlen(field->field_name),
+ cs);
+ table->field[4]->store((longlong) count);
+ field->sql_type(type);
+ table->field[11]->store(type.ptr(), type.length(), cs);
+ tmp_buff= strchr(type.ptr(),'(');
+ table->field[5]->store(type.ptr(),
+ (tmp_buff ? tmp_buff - type.ptr() :
+ type.length()), cs);
+
+ if (show_table->timestamp_field == field &&
+ field->unireg_check != Field::TIMESTAMP_UN_FIELD)
+ {
+ table->field[15]->store("CURRENT_TIMESTAMP", 17, cs);
+ table->field[15]->set_notnull();
+ }
+ else if (field->unireg_check != Field::NEXT_NUMBER &&
+ !field->is_null() &&
+ !(field->flags & NO_DEFAULT_VALUE_FLAG))
+ {
+ String def(tmp1,sizeof(tmp1), cs);
+ type.set(tmp, sizeof(tmp), field->charset());
+ field->val_str(&type);
+ uint dummy_errors;
+ def.copy(type.ptr(), type.length(), type.charset(), cs, &dummy_errors);
+ table->field[15]->store(def.ptr(), def.length(), def.charset());
+ table->field[15]->set_notnull();
+ }
+ else if (field->unireg_check == Field::NEXT_NUMBER ||
+ field->maybe_null())
+ table->field[15]->set_null(); // Null as default
+ else
+ {
+ table->field[15]->store("",0, cs);
+ table->field[15]->set_notnull();
+ }
+
+ pos=(byte*) ((flags & NOT_NULL_FLAG) &&
+ field->type() != FIELD_TYPE_TIMESTAMP ?
+ "" : "YES");
+ table->field[13]->store((const char*) pos,
+ strlen((const char*) pos), cs);
+ if (field->has_charset())
+ {
+ table->field[6]->store((longlong) field->field_length/
+ field->charset()->mbmaxlen);
+ }
+ table->field[7]->store((longlong) field->field_length);
+ table->field[8]->store((longlong) field->pack_length());
+ table->field[9]->store((longlong) field->decimals());
+ if (field->has_charset())
+ {
+ pos=(byte*) field->charset()->csname;
+ table->field[10]->store((const char*) pos,
+ strlen((const char*) pos), cs);
+ table->field[10]->set_notnull();
+ pos=(byte*) field->charset()->name;
+ table->field[12]->store((const char*) pos,
+ strlen((const char*) pos), cs);
+ table->field[12]->set_notnull();
+ }
+ pos=(byte*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
+ (field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
+ (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
+ table->field[14]->store((const char*) pos,
+ strlen((const char*) pos), cs);
+ char *end=tmp;
+ if (field->unireg_check == Field::NEXT_NUMBER)
+ end=strmov(tmp,"auto_increment");
+ table->field[16]->store(tmp, (uint) (end-tmp), cs);
+ if (thd->lex->verbose)
+ {
+ end=tmp;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ uint col_access;
+ check_access(thd,SELECT_ACL | EXTRA_ACL, base_name,
+ &tables->grant.privilege, 0, 0);
+ col_access= get_column_grant(thd, &tables->grant, tables->db,
+ tables->real_name,
+ field->field_name) & COL_ACLS;
+ for (uint bitnr=0; col_access ; col_access>>=1,bitnr++)
+ {
+ if (col_access & 1)
+ {
+ *end++=',';
+ end=strmov(end,grant_types.type_names[bitnr]);
+ }
+ }
+#else
+ end=strmov(end,"");
+#endif
+ table->field[17]->store(tmp+1,end == tmp ? 0 : (uint) (end-tmp-1), cs);
+ table->field[18]->store(field->comment.str, field->comment.length, cs);
+ }
+ table->file->write_row(table->record[0]);
+ }
+ }
+ DBUG_RETURN(0);
+}
+
+
+
+int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+ CHARSET_INFO **cs;
+ const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
+ TABLE *table= tables->table;
+ CHARSET_INFO *scs= system_charset_info;
+ for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ )
+ {
+ CHARSET_INFO *tmp_cs= cs[0];
+ if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
+ (tmp_cs->state & MY_CS_AVAILABLE) &&
+ !(wild && wild[0] &&
+ wild_case_compare(scs, tmp_cs->csname,wild)))
+ {
+ restore_record(table, default_values);
+ table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
+ table->field[1]->store(tmp_cs->comment ? tmp_cs->comment : "",
+ strlen(tmp_cs->comment ? tmp_cs->comment : ""),
+ scs);
+ table->field[2]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
+ table->field[3]->store((longlong) tmp_cs->mbmaxlen);
+ table->file->write_row(table->record[0]);
+ }
+ }
+ return 0;
+}
+
+
+int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+ CHARSET_INFO **cs;
+ const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
+ TABLE *table= tables->table;
+ CHARSET_INFO *scs= system_charset_info;
+ for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ )
+ {
+ CHARSET_INFO **cl;
+ CHARSET_INFO *tmp_cs= cs[0];
+ if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
+ !(tmp_cs->state & MY_CS_PRIMARY))
+ continue;
+ for ( cl= all_charsets; cl < all_charsets+255 ;cl ++)
+ {
+ CHARSET_INFO *tmp_cl= cl[0];
+ if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
+ !my_charset_same(tmp_cs, tmp_cl))
+ continue;
+ if (!(wild && wild[0] &&
+ wild_case_compare(scs, tmp_cl->name,wild)))
+ {
+ const char *tmp_buff;
+ restore_record(table, default_values);
+ table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
+ table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
+ table->field[2]->store((longlong) tmp_cl->number);
+ tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
+ table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
+ tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
+ table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
+ table->field[5]->store((longlong) tmp_cl->strxfrm_multiply);
+ table->file->write_row(table->record[0]);
+ }
+ }
+ }
+ return 0;
+}
+
+
+int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+ CHARSET_INFO **cs;
+ const char *wild= NullS;
+ TABLE *table= tables->table;
+ CHARSET_INFO *scs= system_charset_info;
+ for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ )
+ {
+ CHARSET_INFO **cl;
+ CHARSET_INFO *tmp_cs= cs[0];
+ if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
+ !(tmp_cs->state & MY_CS_PRIMARY))
+ continue;
+ for ( cl= all_charsets; cl < all_charsets+255 ;cl ++)
+ {
+ CHARSET_INFO *tmp_cl= cl[0];
+ if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
+ !my_charset_same(tmp_cs,tmp_cl))
+ continue;
+ restore_record(table, default_values);
+ table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
+ table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
+ table->file->write_row(table->record[0]);
+ }
+ }
+ return 0;
+}
+
+
+void store_schema_proc(THD *thd, TABLE *table,
+ TABLE *proc_table,
+ const char *wild)
+{
+ String tmp_string;
+ TIME time;
+ LEX *lex= thd->lex;
+ CHARSET_INFO *cs= system_charset_info;
+ restore_record(table, default_values);
+ if (lex->orig_sql_command == SQLCOM_SHOW_STATUS_PROC &&
+ proc_table->field[2]->val_int() == TYPE_ENUM_PROCEDURE ||
+ lex->orig_sql_command == SQLCOM_SHOW_STATUS_FUNC &&
+ proc_table->field[2]->val_int() == TYPE_ENUM_FUNCTION ||
+ lex->orig_sql_command == SQLCOM_END)
+ {
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[1], &tmp_string);
+ if (!wild || !wild[0] || !wild_compare(tmp_string.ptr(), wild, 0))
+ {
+ table->field[3]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[0], &tmp_string);
+ table->field[2]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[2], &tmp_string);
+ table->field[4]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[3], &tmp_string);
+ table->field[0]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[5], &tmp_string);
+ table->field[11]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[6], &tmp_string);
+ table->field[10]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[7], &tmp_string);
+ table->field[15]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[9], &tmp_string);
+ table->field[6]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[10], &tmp_string);
+ table->field[8]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[11], &tmp_string);
+ table->field[5]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ bzero((char *)&time, sizeof(time));
+ ((Field_timestamp *) proc_table->field[12])->get_time(&time);
+ table->field[14]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ bzero((char *)&time, sizeof(time));
+ ((Field_timestamp *) proc_table->field[13])->get_time(&time);
+ table->field[13]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ get_field(thd->mem_root, proc_table->field[14], &tmp_string);
+ table->field[16]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ tmp_string.length(0);
+ get_field(thd->mem_root, proc_table->field[15], &tmp_string);
+ table->field[17]->store(tmp_string.ptr(), tmp_string.length(), cs);
+ table->field[7]->store("SQL", 3, cs);
+ table->field[9]->store("SQL", 3, cs);
+ table->file->write_row(table->record[0]);
+ }
+ }
+}
+
+
+int fill_schema_proc(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+ TABLE *proc_table;
+ TABLE_LIST proc_tables;
+ const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
+ int res= 0;
+ TABLE *table= tables->table, *old_open_tables= thd->open_tables;
+ DBUG_ENTER("fill_schema_proc");
+
+ bzero((char*) &proc_tables,sizeof(proc_tables));
+ proc_tables.db= (char*) "mysql";
+ proc_tables.real_name= proc_tables.alias= (char*) "proc";
+ proc_tables.lock_type= TL_READ;
+ if (!(proc_table= open_ltable(thd, &proc_tables, TL_READ)))
+ {
+ DBUG_RETURN(1);
+ }
+ proc_table->file->ha_index_init(0);
+ if ((res= proc_table->file->index_first(proc_table->record[0])))
+ {
+ res= (res == HA_ERR_END_OF_FILE) ? 0 : 1;
+ goto err;
+ }
+ store_schema_proc(thd, table, proc_table, wild);
+ while (!proc_table->file->index_next(proc_table->record[0]))
+ store_schema_proc(thd, table, proc_table, wild);
+
+err:
+ proc_table->file->ha_index_end();
+ close_thread_tables(thd, 0, 0, old_open_tables);
+ DBUG_RETURN(res);
+}
+
+
+static int get_schema_stat_record(THD *thd, struct st_table_list *tables,
+ TABLE *table, bool res,
+ const char *base_name,
+ const char *file_name)
+{
+ CHARSET_INFO *cs= system_charset_info;
+ DBUG_ENTER("get_schema_stat_record");
+ if (!res)
+ {
+ TABLE *show_table= tables->table;
+ KEY *key_info=show_table->key_info;
+ show_table->file->info(HA_STATUS_VARIABLE |
+ HA_STATUS_NO_LOCK |
+ HA_STATUS_TIME);
+ for (uint i=0 ; i < show_table->keys ; i++,key_info++)
+ {
+ KEY_PART_INFO *key_part= key_info->key_part;
+ const char *str;
+ for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
+ {
+ restore_record(table, default_values);
+ table->field[1]->store(base_name, strlen(base_name), cs);
+ table->field[2]->store(file_name, strlen(file_name), cs);
+ table->field[3]->store((longlong) ((key_info->flags &
+ HA_NOSAME) ? 0 :1));
+ table->field[4]->store(base_name, strlen(base_name), cs);
+ table->field[5]->store(key_info->name, strlen(key_info->name), cs);
+ table->field[6]->store((longlong) (j+1));
+ str=(key_part->field ? key_part->field->field_name :
+ "?unknown field?");
+ table->field[7]->store(str, strlen(str), cs);
+ if (show_table->file->index_flags(i, j, 0) & HA_READ_ORDER)
+ {
+ table->field[8]->store(((key_part->key_part_flag &
+ HA_REVERSE_SORT) ?
+ "D" : "A"), 1, cs);
+ table->field[8]->set_notnull();
+ }
+ KEY *key=show_table->key_info+i;
+ if (key->rec_per_key[j])
+ {
+ ha_rows records=(show_table->file->records /
+ key->rec_per_key[j]);
+ table->field[9]->store((longlong) records);
+ table->field[9]->set_notnull();
+ }
+ if (!(key_info->flags & HA_FULLTEXT) &&
+ (!key_part->field ||
+ key_part->length !=
+ show_table->field[key_part->fieldnr-1]->key_length()))
+ {
+ table->field[10]->store((longlong) key_part->length);
+ table->field[10]->set_notnull();
+ }
+ uint flags= key_part->field ? key_part->field->flags : 0;
+ const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
+ table->field[12]->store(pos, strlen(pos), cs);
+ pos= show_table->file->index_type(i);
+ table->field[13]->store(pos, strlen(pos), cs);
+ if (!show_table->keys_in_use.is_set(i))
+ table->field[14]->store("disabled", 8, cs);
+ else
+ table->field[14]->store("", 0, cs);
+ table->field[14]->set_notnull();
+ table->file->write_row(table->record[0]);
+ }
+ }
+ }
+ DBUG_RETURN(res);
+}
+
+
+static int get_schema_views_record(THD *thd, struct st_table_list *tables,
+ TABLE *table, bool res,
+ const char *base_name,
+ const char *file_name)
+{
+ CHARSET_INFO *cs= system_charset_info;
+ DBUG_ENTER("get_schema_views_record");
+ if (!res)
+ {
+ if (tables->view)
+ {
+ restore_record(table, default_values);
+ table->field[1]->store(tables->view_db.str, tables->view_db.length, cs);
+ table->field[2]->store(tables->view_name.str,tables->view_name.length,cs);
+ table->field[3]->store(tables->query.str, tables->query.length, cs);
+
+ if (tables->with_check != VIEW_CHECK_NONE)
+ {
+ if (tables->with_check == VIEW_CHECK_LOCAL)
+ table->field[4]->store("WITH LOCAL CHECK OPTION", 23, cs);
+ else
+ table->field[4]->store("WITH CASCADED CHECK OPTION", 26, cs);
+ }
+ else
+ table->field[4]->store("NONE", 4, cs);
+
+ if (tables->updatable_view)
+ table->field[5]->store("YES", 3, cs);
+ else
+ table->field[5]->store("NO", 2, cs);
+ table->file->write_row(table->record[0]);
+ }
+ }
+ DBUG_RETURN(res);
+}
+
+
+static int get_schema_constarints_record(THD *thd, struct st_table_list *tables,
+ TABLE *table, bool res,
+ const char *base_name,
+ const char *file_name)
+{
+ CHARSET_INFO *cs= system_charset_info;
+ DBUG_ENTER("get_schema_constarints_record");
+ if (!res)
+ {
+ List<FOREIGN_KEY_INFO> f_key_list;
+ TABLE *show_table= tables->table;
+ KEY *key_info=show_table->key_info;
+ uint primary_key= show_table->primary_key;
+ show_table->file->info(HA_STATUS_VARIABLE |
+ HA_STATUS_NO_LOCK |
+ HA_STATUS_TIME);
+ for (uint i=0 ; i < show_table->keys ; i++, key_info++)
+ {
+ if (i != primary_key && !(key_info->flags & HA_NOSAME))
+ continue;
+ restore_record(table, default_values);
+ table->field[1]->store(base_name, strlen(base_name), cs);
+ table->field[2]->store(key_info->name, strlen(key_info->name), cs);
+ table->field[3]->store(base_name, strlen(base_name), cs);
+ table->field[4]->store(file_name, strlen(file_name), cs);
+ if (i == primary_key && !strcmp(key_info->name, primary_key_name))
+ table->field[5]->store("PRIMARY KEY", 11, cs);
+ else if (key_info->flags & HA_NOSAME)
+ table->field[5]->store("UNIQUE", 6, cs);
+ table->file->write_row(table->record[0]);
+ }
+
+ show_table->file->get_foreign_key_list(thd, &f_key_list);
+ FOREIGN_KEY_INFO *f_key_info;
+ List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
+ while ((f_key_info=it++))
+ {
+ restore_record(table, default_values);
+ table->field[1]->store(base_name, strlen(base_name), cs);
+ table->field[2]->store(f_key_info->forein_id->str,
+ f_key_info->forein_id->length, cs);
+ table->field[3]->store(base_name, strlen(base_name), cs);
+ table->field[4]->store(file_name, strlen(file_name), cs);
+ table->field[5]->store("FOREIGN KEY", 11, system_charset_info);
+ table->field[6]->store(f_key_info->constraint_method->str,
+ f_key_info->constraint_method->length, cs);
+ table->field[6]->set_notnull();
+ table->file->write_row(table->record[0]);
+ }
+ }
+ DBUG_RETURN(res);
+}
+
+
+static int get_schema_key_column_usage_record(THD *thd,
+ struct st_table_list *tables,
+ TABLE *table, bool res,
+ const char *base_name,
+ const char *file_name)
+{
+ DBUG_ENTER("get_schema_key_column_usage_record");
+ CHARSET_INFO *cs= system_charset_info;
+ if (!res)
+ {
+ List<FOREIGN_KEY_INFO> f_key_list;
+ TABLE *show_table= tables->table;
+ KEY *key_info=show_table->key_info;
+ uint primary_key= show_table->primary_key;
+ show_table->file->info(HA_STATUS_VARIABLE |
+ HA_STATUS_NO_LOCK |
+ HA_STATUS_TIME);
+ for (uint i=0 ; i < show_table->keys ; i++, key_info++)
+ {
+ if (i != primary_key && !(key_info->flags & HA_NOSAME))
+ continue;
+ uint f_idx= 0;
+ KEY_PART_INFO *key_part= key_info->key_part;
+ for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
+ {
+ uint f_idx= 0;
+ if (key_part->field)
+ {
+ f_idx++;
+ restore_record(table, default_values);
+ table->field[1]->store(base_name, strlen(base_name), cs);
+ table->field[2]->store(key_info->name, strlen(key_info->name), cs);
+ table->field[3]->store(base_name, strlen(base_name), cs);
+ table->field[4]->store(file_name, strlen(file_name), cs);
+ table->field[5]->store(key_part->field->field_name,
+ strlen(key_part->field->field_name), cs);
+ table->field[6]->store((longlong) f_idx);
+ table->file->write_row(table->record[0]);
+ }
+ }
+ }
+
+ show_table->file->get_foreign_key_list(thd, &f_key_list);
+ FOREIGN_KEY_INFO *f_key_info;
+ List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
+ while ((f_key_info= it++))
+ {
+ LEX_STRING *f_info, *r_info;
+ List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
+ it1(f_key_info->referenced_fields);
+ uint f_idx= 0;
+ while ((f_info= it++))
+ {
+ r_info= it1++;
+ f_idx++;
+ restore_record(table, default_values);
+ table->field[1]->store(base_name, strlen(base_name), cs);
+ table->field[2]->store(f_key_info->forein_id->str,
+ f_key_info->forein_id->length, cs);
+ table->field[3]->store(base_name, strlen(base_name), cs);
+ table->field[4]->store(file_name, strlen(file_name), cs);
+ table->field[5]->store(f_info->str, f_info->length, cs);
+ table->field[6]->store((longlong) f_idx);
+ table->field[7]->store(f_key_info->referenced_db->str,
+ f_key_info->referenced_db->length, cs);
+ table->field[7]->set_notnull();
+ table->field[8]->store(f_key_info->referenced_table->str,
+ f_key_info->referenced_table->length, cs);
+ table->field[8]->set_notnull();
+ table->field[9]->store(r_info->str, r_info->length, cs);
+ table->field[9]->set_notnull();
+ table->file->write_row(table->record[0]);
+ }
+ }
+ }
+ DBUG_RETURN(res);
+}
+
+
+/*
+ Find schema_tables elment by name
+
+ SYNOPSIS
+ find_schema_table()
+ thd thread handler
+ table_name table name
+
+ RETURN
+ 0 table not found
+ # pointer to 'shema_tables' element
+*/
+
+ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name)
+{
+ ST_SCHEMA_TABLE *schema_table= schema_tables;
+ for ( ; schema_table->table_name; schema_table++)
+ {
+ if (!my_strcasecmp(system_charset_info,
+ schema_table->table_name,
+ table_name))
+ return schema_table;
+ }
+ return 0;
+}
+
+
+ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx)
+{
+ return &schema_tables[schema_table_idx];
+}
+
+
+/*
+ Create information_schema table using schema_table data
+
+ SYNOPSIS
+ create_schema_table()
+ thd thread handler
+ schema_table pointer to 'shema_tables' element
+
+ RETURN
+ # Pointer to created table
+ 0 Can't create table
+*/
+
+TABLE *create_schema_table(THD *thd, ST_SCHEMA_TABLE *schema_table)
+{
+ int field_count= 0;
+ Item *item;
+ TABLE *table;
+ List<Item> field_list;
+ ST_FIELD_INFO *fields_info= schema_table->fields_info;
+ DBUG_ENTER("create_schema_table");
+
+ for ( ; fields_info->field_name; fields_info++)
+ {
+ switch (fields_info->field_type) {
+ case MYSQL_TYPE_LONG:
+ if (!(item= new Item_int(fields_info->field_name,
+ fields_info->value,
+ fields_info->field_length)))
+ {
+ DBUG_RETURN(0);
+ }
+ break;
+ case MYSQL_TYPE_TIMESTAMP:
+ if (!(item=new Item_datetime(fields_info->field_name)))
+ {
+ DBUG_RETURN(0);
+ }
+ break;
+ default:
+ CHARSET_INFO *cs= system_charset_info;
+ if (fields_info->utf8)
+ cs= thd->charset();
+ if (!(item= new Item_string("", fields_info->field_length, cs)))
+ {
+ DBUG_RETURN(0);
+ }
+ item->set_name(fields_info->field_name,
+ strlen(fields_info->field_name), cs);
+ break;
+ }
+ field_list.push_back(item);
+ item->maybe_null= fields_info->maybe_null;
+ field_count++;
+ }
+ TMP_TABLE_PARAM *tmp_table_param =
+ (TMP_TABLE_PARAM*) (thd->calloc(sizeof(TMP_TABLE_PARAM)));
+ tmp_table_param->init();
+ tmp_table_param->field_count= field_count;
+ SELECT_LEX *select_lex= thd->lex->current_select;
+ if (!(table= create_tmp_table(thd, tmp_table_param,
+ field_list, (ORDER*) 0, 0, 0,
+ (select_lex->options | thd->options |
+ TMP_TABLE_ALL_COLUMNS),
+ HA_POS_ERROR,
+ (char *) schema_table->table_name)))
+ DBUG_RETURN(0);
+ DBUG_RETURN(table);
+}
+
+
+/*
+ For old SHOW compatibility. It is used when
+ old SHOW doesn't have generated column names
+ Make list of fields for SHOW
+
+ SYNOPSIS
+ make_old_format()
+ thd thread handler
+ schema_table pointer to 'schema_tables' element
+
+ RETURN
+ -1 errror
+ 0 success
+*/
+
+int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
+{
+ ST_FIELD_INFO *field_info= schema_table->fields_info;
+ for ( ; field_info->field_name; field_info++)
+ {
+ if (field_info->old_name)
+ {
+ Item_field *field= new Item_field(NullS, NullS, field_info->field_name);
+ if (field)
+ {
+ field->set_name(field_info->old_name,
+ strlen(field_info->old_name),
+ system_charset_info);
+ if (add_item_to_list(thd, field))
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+
+int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
+{
+ char tmp[128];
+ LEX *lex= thd->lex;
+ SELECT_LEX *sel= lex->current_select;
+
+ if (!sel->item_list.elements)
+ {
+ ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
+ String buffer(tmp,sizeof(tmp), system_charset_info);
+ Item_field *field= new Item_field(NullS, NullS, field_info->field_name);
+ if (!field || add_item_to_list(thd, field))
+ return 1;
+ buffer.length(0);
+ buffer.append(field_info->old_name);
+ if (lex->wild && lex->wild->ptr())
+ {
+ buffer.append(" (");
+ buffer.append(lex->wild->ptr());
+ buffer.append(")");
+ }
+ field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
+ }
+ return 0;
+}
+
+
+int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
+{
+ char tmp[128];
+ String buffer(tmp,sizeof(tmp), thd->charset());
+ LEX *lex= thd->lex;
+
+ ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
+ buffer.length(0);
+ buffer.append(field_info->old_name);
+ buffer.append(lex->select_lex.db);
+ if (lex->wild && lex->wild->ptr())
+ {
+ buffer.append(" (");
+ buffer.append(lex->wild->ptr());
+ buffer.append(")");
+ }
+ Item_field *field= new Item_field(NullS, NullS, field_info->field_name);
+ if (add_item_to_list(thd, field))
+ return 1;
+ field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
+ if (thd->lex->verbose)
+ {
+ field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
+ field_info= &schema_table->fields_info[3];
+ field= new Item_field(NullS, NullS, field_info->field_name);
+ if (add_item_to_list(thd, field))
+ return 1;
+ field->set_name(field_info->old_name, strlen(field_info->old_name),
+ system_charset_info);
+ }
+ return 0;
+}
+
+
+int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
+{
+ ST_FIELD_INFO *field_info= &schema_table->fields_info[3];
+ int count= 2;
+ for ( ; field_info->field_name; field_info++)
+ {
+ count++;
+ if (field_info->old_name)
+ {
+ if (!thd->lex->verbose && (count == 12 ||count == 17 || count == 18))
+ continue;
+ Item_field *field= new Item_field(NullS, NullS, field_info->field_name);
+ if (field)
+ {
+ field->set_name(field_info->old_name,
+ strlen(field_info->old_name),
+ system_charset_info);
+ if (add_item_to_list(thd, field))
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+
+/*
+ Create information_schema table
+
+ SYNOPSIS
+ mysql_schema_table()
+ thd thread handler
+ lex pointer to LEX
+ table_list pointer to table_list
+
+ RETURN
+ 0 success
+ 1 error
+*/
+
+int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
+{
+ TABLE *table;
+ DBUG_ENTER("mysql_schema_table");
+ if (!(table= table_list->schema_table->
+ create_table(thd, table_list->schema_table)))
+ {
+ DBUG_RETURN(1);
+ }
+ table->tmp_table= TMP_TABLE;
+ table->grant.privilege= SELECT_ACL;
+ table_list->real_name= table->real_name;
+ table_list->table= table;
+ table->next= thd->derived_tables;
+ thd->derived_tables= table;
+ table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
+ DBUG_RETURN(0);
+}
+
+
+/*
+ Generate select from information_schema table
+
+ SYNOPSIS
+ make_schema_select()
+ thd thread handler
+ sel pointer to SELECT_LEX
+ schema_table_idx index of 'schema_tables' element
+
+ RETURN
+ 0 success
+ 1 error
+*/
+
+int make_schema_select(THD *thd, SELECT_LEX *sel,
+ enum enum_schema_tables schema_table_idx)
+{
+ ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
+ LEX_STRING db, table;
+ DBUG_ENTER("mysql_schema_select");
+ /*
+ We have to make non const db_name & table_name
+ because of lower_case_table_names
+ */
+ make_lex_string(thd, &db, information_schema_name.str,
+ information_schema_name.length, 0);
+ make_lex_string(thd, &table, schema_table->table_name,
+ strlen(schema_table->table_name), 0);
+ if (!sel->item_list.elements && /* Handle old syntax */
+ schema_table->old_format(thd, schema_table) ||
+ !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
+ 0, 0, TL_READ, (List<String> *) 0,
+ (List<String> *) 0))
+ {
+ DBUG_RETURN(1);
+ }
+ DBUG_RETURN(0);
+}
+
+
+/*
+ Fill temporaty schema tables before SELECT
+
+ SYNOPSIS
+ get_schema_tables_result()
+ join join which use schema tables
+
+ RETURN
+ FALSE success
+ TRUE error
+*/
+
+bool get_schema_tables_result(JOIN *join)
+{
+ DBUG_ENTER("get_schema_tables_result");
+ JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
+ THD *thd= join->thd;
+ for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
+ {
+ if (!tab->table || !tab->table->pos_in_table_list)
+ break;
+ TABLE_LIST *table_list= tab->table->pos_in_table_list;
+ TABLE_LIST *save_next_global= table_list->next_global;
+
+ if (table_list->schema_table && thd->fill_derived_tables())
+ {
+ TABLE *old_derived_tables= thd->derived_tables;
+ thd->derived_tables= 0;
+ thd->lex->sql_command= SQLCOM_SHOW_FIELDS;
+ table_list->table->file->records= 0;
+ MYSQL_LOCK *sql_lock= thd->lock;
+ thd->lock=0;
+ if (table_list->schema_table->fill_table(thd, table_list,
+ tab->select_cond))
+ {
+ thd->derived_tables= old_derived_tables;
+ thd->lock= sql_lock;
+ table_list->next_global= save_next_global;
+ DBUG_RETURN(TRUE);
+ }
+ thd->lock= sql_lock;
+ thd->lex->sql_command= SQLCOM_SELECT;
+ thd->derived_tables= old_derived_tables;
+ table_list->next_global= save_next_global;
+ }
+ }
+ DBUG_RETURN(FALSE);
+}
+
+
+ST_FIELD_INFO schema_fields_info[]=
+{
+ {"CATALOG_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"SCHEMA_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Database"},
+ {"DEFAULT_CHARACTER_SET_NAME", 60, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO tables_fields_info[]=
+{
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TABLE_SCHEMA",NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Name"},
+ {"TABLE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"ENGINE", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, "Engine"},
+ {"VERSION", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Version"},
+ {"ROW_FORMAT", 10, MYSQL_TYPE_STRING, 0, 1, 1, "Row_format"},
+ {"ROWS", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Rows"},
+ {"AVG_ROW_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Avg_row_length"},
+ {"DATA_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Data_length"},
+ {"MAX_DATA_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Max_data_length"},
+ {"INDEX_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Index_length"},
+ {"DATA_FREE", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Data_free"},
+ {"AUTO_INCREMENT", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Auto_increment"},
+ {"CREATE_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, 0, "Create_time"},
+ {"UPDATE_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, 0, "Update_time"},
+ {"CHECK_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, 0, "Check_time"},
+ {"COLLATION", 60, MYSQL_TYPE_STRING, 0, 1, 1, "Collation"},
+ {"CHECKSUM", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Checksum"},
+ {"CREATE_OPTIONS", 255, MYSQL_TYPE_STRING, 0, 1, 1, "Create_options"},
+ {"COMMENT", 80, MYSQL_TYPE_STRING, 0, 0, 1, "Comment"},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO columns_fields_info[]=
+{
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Field"},
+ {"ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0},
+ {"DATA_TYPE", 40, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"CHARACTER_MAXIMUM_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0},
+ {"CHARACTER_OCTET_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0},
+ {"NUMERIC_PRECISION", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0},
+ {"NUMERIC_SCALE", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0},
+ {"CHARACTER_SET_NAME", 40, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TYPE", 40, MYSQL_TYPE_STRING, 0, 0, 1, "Type"},
+ {"COLLATION_NAME", 40, MYSQL_TYPE_STRING, 0, 1, 1, "Collation"},
+ {"IS_NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, "Null"},
+ {"KEY", 3, MYSQL_TYPE_STRING, 0, 0, 1, "Key"},
+ {"COLUMN_DEFAULT", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, "Default"},
+ {"EXTRA", 20, MYSQL_TYPE_STRING, 0, 0, 1, "Extra"},
+ {"PRIVILEGES", 80, MYSQL_TYPE_STRING, 0, 0, 1, "Privileges"},
+ {"COMMENT", 255, MYSQL_TYPE_STRING, 0, 0, 1, "Comment"},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO charsets_fields_info[]=
+{
+ {"CHARACTER_SET_NAME", 30, MYSQL_TYPE_STRING, 0, 0, 1, "Charset"},
+ {"Description", 60, MYSQL_TYPE_STRING, 0, 0, 1, "Description"},
+ {"DEFAULT_COLLATE_NAME", 60, MYSQL_TYPE_STRING, 0, 0, 1, "Default collation"},
+ {"Maxlen", 3 ,MYSQL_TYPE_LONG, 0, 0, 0, "Maxlen"},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO collation_fields_info[]=
+{
+ {"COLLATION_NAME", 30, MYSQL_TYPE_STRING, 0, 0, 1, "Collation"},
+ {"Charset", 30, MYSQL_TYPE_STRING, 0, 0, 1, "Charset"},
+ {"Id", 11, MYSQL_TYPE_LONG, 0, 0, 0, "Id"},
+ {"Default", 30 ,MYSQL_TYPE_STRING, 0, 0, 1, "Default"},
+ {"Compiled", 30 ,MYSQL_TYPE_STRING, 0, 0, 1, "Compiled"},
+ {"Sortlen", 3 ,MYSQL_TYPE_LONG, 0, 0, 0, "Sortlen"},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO coll_charset_app_fields_info[]=
+{
+ {"COLLATION_NAME", 30, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"CHARACTER_SET_NAME", 30, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO proc_fields_info[]=
+{
+ {"SPECIFIC_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"ROUTINE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"ROUTINE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Db"},
+ {"ROUTINE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Name"},
+ {"ROUTINE_TYPE", 9, MYSQL_TYPE_STRING, 0, 0, 1, "Type"},
+ {"DEFINER", 77, MYSQL_TYPE_STRING, 0, 0, 1, "Definer"},
+ {"DTD_IDENTIFIER", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"ROUTINE_BODY", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"ROUTINE_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"PARAMETER_STYLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"IS_DETERMINISTIC", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"SQL_DATA_ACCESS", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"SQL_PATH", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"LAST_ALTERED", 0, MYSQL_TYPE_TIMESTAMP, 0, 0, 0, "Modified"},
+ {"CREATED", 0, MYSQL_TYPE_TIMESTAMP, 0, 0, 1, "Created"},
+ {"SECURITY_TYPE", 7, MYSQL_TYPE_STRING, 0, 0, 1, "Security_type"},
+ {"SQL_MODE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"ROUTINE_COMMENT", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Comment"},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO stat_fields_info[]=
+{
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Table"},
+ {"NON_UNIQUE", 1, MYSQL_TYPE_LONG, 0, 0, 0, "Non_unique"},
+ {"INDEX_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"INDEX_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Key_name"},
+ {"SEQ_IN_INDEX", 2, MYSQL_TYPE_LONG, 0, 0, 0, "Seq_in_index"},
+ {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Column_name"},
+ {"COLLATION", 1, MYSQL_TYPE_STRING, 0, 1, 1, "Collation"},
+ {"CARDINALITY", 21, MYSQL_TYPE_LONG, 0, 1, 0, "Cardinality"},
+ {"SUB_PART", 3, MYSQL_TYPE_LONG, 0, 1, 0, "Sub_part"},
+ {"PACKED", 10, MYSQL_TYPE_STRING, 0, 1, 1, "Packed"},
+ {"NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, "Null"},
+ {"INDEX_TYPE", 16, MYSQL_TYPE_STRING, 0, 0, 1, "Index_type"},
+ {"COMMENT", 16, MYSQL_TYPE_STRING, 0, 1, 1, "Comment"},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO view_fields_info[]=
+{
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"VIEW_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"CHECK_OPTION", 30, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"IS_UPDATABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO user_privileges_fields_info[]=
+{
+ {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"PRIVILEGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO schema_privileges_fields_info[]=
+{
+ {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"PRIVILEGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO table_privileges_fields_info[]=
+{
+ {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"PRIVILEGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO column_privileges_fields_info[]=
+{
+ {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"PRIVILEGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO table_constraints_fields_info[]=
+{
+ {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"CONSTRAINT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"CONSTRAINT_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"CONSTRAINT_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"CONSTRAINT_METHOD", 20, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO key_column_usage_fields_info[]=
+{
+ {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"CONSTRAINT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"CONSTRAINT_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"ORDINAL_POSITION", 10 ,MYSQL_TYPE_LONG, 0, 0, 0, 0},
+ {"REFERENCED_TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"REFERENCED_TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"REFERENCED_COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+ST_FIELD_INFO table_names_fields_info[]=
+{
+ {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0},
+ {"TABLE_SCHEMA",NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0},
+ {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Tables_in_"},
+ {"TABLE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Table_type"},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
+};
+
+
+/*
+ Description of ST_FIELD_INFO in table.h
+*/
+
+ST_SCHEMA_TABLE schema_tables[]=
+{
+ {"SCHEMATA", schema_fields_info, create_schema_table,
+ fill_schema_shemata, make_schemata_old_format, 0, 1, -1},
+ {"TABLES", tables_fields_info, create_schema_table,
+ get_all_tables, make_old_format, get_schema_tables_record, 1, 2},
+ {"COLUMNS", columns_fields_info, create_schema_table,
+ get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2},
+ {"CHARACTER_SETS", charsets_fields_info, create_schema_table,
+ fill_schema_charsets, make_old_format, 0, -1, -1},
+ {"COLLATIONS", collation_fields_info, create_schema_table,
+ fill_schema_collation, make_old_format, 0, -1, -1},
+ {"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
+ create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1},
+ {"ROUTINES", proc_fields_info, create_schema_table,
+ fill_schema_proc, make_old_format, 0, -1, -1},
+ {"STATISTICS", stat_fields_info, create_schema_table,
+ get_all_tables, make_old_format, get_schema_stat_record, 1, 2},
+ {"VIEWS", view_fields_info, create_schema_table,
+ get_all_tables, 0, get_schema_views_record, 1, 2},
+ {"USER_PRIVILEGES", user_privileges_fields_info, create_schema_table,
+ fill_schema_user_privileges, 0, 0, -1, -1},
+ {"SCHEMA_PRIVILEGES", schema_privileges_fields_info, create_schema_table,
+ fill_schema_schema_privileges, 0, 0, -1, -1},
+ {"TABLE_PRIVILEGES", table_privileges_fields_info, create_schema_table,
+ fill_schema_table_privileges, 0, 0, -1, -1},
+ {"COLUMN_PRIVILEGES", column_privileges_fields_info, create_schema_table,
+ fill_schema_column_privileges, 0, 0, -1, -1},
+ {"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
+ get_all_tables, 0, get_schema_constarints_record, 3, 4},
+ {"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
+ get_all_tables, 0, get_schema_key_column_usage_record, 3, 4},
+ {"TABLE_NAMES", table_names_fields_info, create_schema_table,
+ get_all_tables, make_table_names_old_format, 0, 1, 2},
+ {0, 0, 0, 0, 0, 0, 0, 0}
+};
+
+
#ifdef __GNUC__
template class List_iterator_fast<char>;
template class List<char>;
diff --git a/sql/sql_string.h b/sql/sql_string.h
index cb5b1fb25fd..2101db40f92 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -141,6 +141,34 @@ public:
bool set(longlong num, CHARSET_INFO *cs);
bool set(ulonglong num, CHARSET_INFO *cs);
bool set(double num,uint decimals, CHARSET_INFO *cs);
+
+ /*
+ PMG 2004.11.12
+ This is a method that works the same as perl's "chop". It simply
+ drops the last character of a string. This is useful in the case
+ of the federated storage handler where I'm building a unknown
+ number, list of values and fields to be used in a sql insert
+ statement to be run on the remote server, and have a comma after each.
+ When the list is complete, I "chop" off the trailing comma
+
+ ex.
+ String stringobj;
+ stringobj.append("VALUES ('foo', 'fi', 'fo',");
+ stringobj.chop();
+ stringobj.append(")");
+
+ In this case, the value of string was:
+
+ VALUES ('foo', 'fi', 'fo',
+ VALUES ('foo', 'fi', 'fo'
+ VALUES ('foo', 'fi', 'fo')
+
+ */
+ inline void chop()
+ {
+ Ptr[str_length--]= '\0';
+ }
+
inline void free()
{
if (alloced)
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index e73bf81eb74..8ff2fa5faa8 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -63,15 +63,15 @@ static int copy_data_between_tables(TABLE *from,TABLE *to,
Wait if global_read_lock (FLUSH TABLES WITH READ LOCK) is set.
RETURN
- 0 ok. In this case ok packet is sent to user
- -1 Error (Error message given but not sent to user)
+ FALSE OK. In this case ok packet is sent to user
+ TRUE Error
*/
-int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
- my_bool drop_temporary)
+bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
+ my_bool drop_temporary)
{
- int error= 0;
+ bool error= FALSE;
DBUG_ENTER("mysql_rm_table");
/* mark for close and remove all cached entries */
@@ -84,9 +84,8 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
{
if (thd->global_read_lock)
{
- my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE,MYF(0),
- tables->real_name);
- error= 1;
+ my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0), tables->real_name);
+ error= TRUE;
goto err;
}
while (global_read_lock && ! thd->killed)
@@ -106,9 +105,9 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
pthread_mutex_unlock(&thd->mysys_var->mutex);
if (error)
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
send_ok(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -268,9 +267,9 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
if (wrong_tables.length())
{
if (!foreign_key_error)
- my_error(ER_BAD_TABLE_ERROR,MYF(0), wrong_tables.c_ptr());
+ my_error(ER_BAD_TABLE_ERROR, MYF(0), wrong_tables.c_ptr());
else
- my_error(ER_ROW_IS_REFERENCED, MYF(0));
+ my_message(ER_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED), MYF(0));
error= 1;
}
@@ -485,7 +484,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
*/
if (field_no < select_field_pos || dup_no >= select_field_pos)
{
- my_error(ER_DUP_FIELDNAME,MYF(0),sql_field->field_name);
+ my_error(ER_DUP_FIELDNAME, MYF(0), sql_field->field_name);
DBUG_RETURN(-1);
}
else
@@ -537,8 +536,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
#ifdef HAVE_SPATIAL
if (!(file->table_flags() & HA_CAN_GEOMETRY))
{
- my_printf_error(ER_CHECK_NOT_IMPLEMENTED, ER(ER_CHECK_NOT_IMPLEMENTED),
- MYF(0), "GEOMETRY");
+ my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "GEOMETRY");
DBUG_RETURN(-1);
}
sql_field->pack_flag=FIELDFLAG_GEOM |
@@ -551,8 +549,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
blob_columns++;
break;
#else
- my_printf_error(ER_FEATURE_DISABLED,ER(ER_FEATURE_DISABLED), MYF(0),
- sym_group_geom.name, sym_group_geom.needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ sym_group_geom.name, sym_group_geom.needed_define);
DBUG_RETURN(-1);
#endif /*HAVE_SPATIAL*/
case FIELD_TYPE_VAR_STRING:
@@ -626,24 +624,27 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
}
if (timestamps_with_niladic > 1)
{
- my_error(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS,MYF(0));
+ my_message(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS,
+ ER(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS), MYF(0));
DBUG_RETURN(-1);
}
if (auto_increment > 1)
{
- my_error(ER_WRONG_AUTO_KEY,MYF(0));
+ my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0));
DBUG_RETURN(-1);
}
if (auto_increment &&
(file->table_flags() & HA_NO_AUTO_INCREMENT))
{
- my_error(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT,MYF(0));
+ my_message(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT,
+ ER(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT), MYF(0));
DBUG_RETURN(-1);
}
if (blob_columns && (file->table_flags() & HA_NO_BLOBS))
{
- my_error(ER_TABLE_CANT_HANDLE_BLOB,MYF(0));
+ my_message(ER_TABLE_CANT_HANDLE_BLOB, ER(ER_TABLE_CANT_HANDLE_BLOB),
+ MYF(0));
DBUG_RETURN(-1);
}
@@ -669,9 +670,9 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
if (fk_key->ref_columns.elements &&
fk_key->ref_columns.elements != fk_key->columns.elements)
{
- my_error(ER_WRONG_FK_DEF, MYF(0), fk_key->name ? fk_key->name :
- "foreign key without name",
- ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
+ my_error(ER_WRONG_FK_DEF, MYF(0),
+ (fk_key->name ? fk_key->name : "foreign key without name"),
+ ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
DBUG_RETURN(-1);
}
continue;
@@ -770,8 +771,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
key_info->flags= HA_SPATIAL;
break;
#else
- my_printf_error(ER_FEATURE_DISABLED,ER(ER_FEATURE_DISABLED),MYF(0),
- sym_group_geom.name, sym_group_geom.needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ sym_group_geom.name, sym_group_geom.needed_define);
DBUG_RETURN(-1);
#endif
case Key::FOREIGN_KEY:
@@ -793,7 +794,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
{
if (!(file->table_flags() & HA_CAN_FULLTEXT))
{
- my_error(ER_TABLE_CANT_HANDLE_FT, MYF(0));
+ my_message(ER_TABLE_CANT_HANDLE_FT, ER(ER_TABLE_CANT_HANDLE_FT),
+ MYF(0));
DBUG_RETURN(-1);
}
}
@@ -810,8 +812,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
{
if (key_info->key_parts != 1)
{
- my_printf_error(ER_WRONG_ARGUMENTS,
- ER(ER_WRONG_ARGUMENTS),MYF(0),"SPATIAL INDEX");
+ my_error(ER_WRONG_ARGUMENTS, MYF(0), "SPATIAL INDEX");
DBUG_RETURN(-1);
}
}
@@ -821,17 +822,15 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
#ifdef HAVE_RTREE_KEYS
if ((key_info->key_parts & 1) == 1)
{
- my_printf_error(ER_WRONG_ARGUMENTS,
- ER(ER_WRONG_ARGUMENTS),MYF(0),"RTREE INDEX");
+ my_error(ER_WRONG_ARGUMENTS, MYF(0), "RTREE INDEX");
DBUG_RETURN(-1);
}
/* TODO: To be deleted */
- my_printf_error(ER_NOT_SUPPORTED_YET, ER(ER_NOT_SUPPORTED_YET),
- MYF(0), "RTREE INDEX");
+ my_error(ER_NOT_SUPPORTED_YET, MYF(0), "RTREE INDEX");
DBUG_RETURN(-1);
#else
- my_printf_error(ER_FEATURE_DISABLED,ER(ER_FEATURE_DISABLED),MYF(0),
- sym_group_rtree.name, sym_group_rtree.needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ sym_group_rtree.name, sym_group_rtree.needed_define);
DBUG_RETURN(-1);
#endif
}
@@ -849,9 +848,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
field++;
if (!sql_field)
{
- my_printf_error(ER_KEY_COLUMN_DOES_NOT_EXITS,
- ER(ER_KEY_COLUMN_DOES_NOT_EXITS),MYF(0),
- column->field_name);
+ my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name);
DBUG_RETURN(-1);
}
/* for fulltext keys keyseg length is 1 for blobs (it's ignored in
@@ -869,8 +866,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
sql_field->charset->mbminlen > 1 || // ucs2 doesn't work yet
(ft_key_charset && sql_field->charset != ft_key_charset))
{
- my_printf_error(ER_BAD_FT_COLUMN,ER(ER_BAD_FT_COLUMN),MYF(0),
- column->field_name);
+ my_error(ER_BAD_FT_COLUMN, MYF(0), column->field_name);
DBUG_RETURN(-1);
}
ft_key_charset=sql_field->charset;
@@ -891,15 +887,12 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
{
if (!(file->table_flags() & HA_CAN_INDEX_BLOBS))
{
- my_printf_error(ER_BLOB_USED_AS_KEY,ER(ER_BLOB_USED_AS_KEY),MYF(0),
- column->field_name);
+ my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name);
DBUG_RETURN(-1);
}
if (!column->length)
{
- my_printf_error(ER_BLOB_KEY_WITHOUT_LENGTH,
- ER(ER_BLOB_KEY_WITHOUT_LENGTH),MYF(0),
- column->field_name);
+ my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name);
DBUG_RETURN(-1);
}
}
@@ -928,13 +921,13 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
key_info->flags|= HA_NULL_PART_KEY;
if (!(file->table_flags() & HA_NULL_IN_KEY))
{
- my_printf_error(ER_NULL_COLUMN_IN_INDEX,ER(ER_NULL_COLUMN_IN_INDEX),
- MYF(0),column->field_name);
+ my_error(ER_NULL_COLUMN_IN_INDEX, MYF(0), column->field_name);
DBUG_RETURN(-1);
}
if (key->type == Key::SPATIAL)
{
- my_error(ER_SPATIAL_CANT_HAVE_NULL, MYF(0));
+ my_message(ER_SPATIAL_CANT_HAVE_NULL,
+ ER(ER_SPATIAL_CANT_HAVE_NULL), MYF(0));
DBUG_RETURN(-1);
}
}
@@ -980,7 +973,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
(key_info->flags & HA_NOSAME))) &&
column->length != length)))
{
- my_error(ER_WRONG_SUB_KEY,MYF(0));
+ my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
DBUG_RETURN(-1);
}
else if (!(file->table_flags() & HA_NO_PREFIX_CHAR_KEYS))
@@ -988,8 +981,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
}
else if (length == 0)
{
- my_printf_error(ER_WRONG_KEY_COLUMN, ER(ER_WRONG_KEY_COLUMN), MYF(0),
- column->field_name);
+ my_error(ER_WRONG_KEY_COLUMN, MYF(0), column->field_name);
DBUG_RETURN(-1);
}
if (length > file->max_key_part_length())
@@ -1033,7 +1025,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
{
if (primary_key)
{
- my_error(ER_MULTIPLE_PRI_KEY,MYF(0));
+ my_message(ER_MULTIPLE_PRI_KEY, ER(ER_MULTIPLE_PRI_KEY),
+ MYF(0));
DBUG_RETURN(-1);
}
key_name=primary_key_name;
@@ -1044,7 +1037,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
key_info_buffer,key_info);
if (check_if_keyname_exists(key_name,key_info_buffer,key_info))
{
- my_error(ER_DUP_KEYNAME,MYF(0),key_name);
+ my_error(ER_DUP_KEYNAME, MYF(0), key_name);
DBUG_RETURN(-1);
}
key_info->name=(char*) key_name;
@@ -1069,12 +1062,12 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
if (!unique_key && !primary_key &&
(file->table_flags() & HA_REQUIRE_PRIMARY_KEY))
{
- my_error(ER_REQUIRES_PRIMARY_KEY,MYF(0));
+ my_message(ER_REQUIRES_PRIMARY_KEY, ER(ER_REQUIRES_PRIMARY_KEY), MYF(0));
DBUG_RETURN(-1);
}
if (auto_increment > 0)
{
- my_error(ER_WRONG_AUTO_KEY,MYF(0));
+ my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0));
DBUG_RETURN(-1);
}
/* Sort keys in optimized order */
@@ -1108,30 +1101,31 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
and must be zero for standard create of table.
RETURN VALUES
- 0 ok
- -1 error
+ FALSE OK
+ TRUE error
*/
-int mysql_create_table(THD *thd,const char *db, const char *table_name,
- HA_CREATE_INFO *create_info,
- List<create_field> &fields,
- List<Key> &keys,bool tmp_table,
- uint select_field_count)
+bool mysql_create_table(THD *thd,const char *db, const char *table_name,
+ HA_CREATE_INFO *create_info,
+ List<create_field> &fields,
+ List<Key> &keys,bool tmp_table,
+ uint select_field_count)
{
char path[FN_REFLEN];
const char *alias;
- int error= -1;
uint db_options, key_count;
KEY *key_info_buffer;
handler *file;
+ bool error= TRUE;
enum db_type new_db_type;
DBUG_ENTER("mysql_create_table");
/* Check for duplicate fields and check type of table to create */
if (!fields.elements)
{
- my_error(ER_TABLE_MUST_HAVE_COLUMNS,MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_TABLE_MUST_HAVE_COLUMNS, ER(ER_TABLE_MUST_HAVE_COLUMNS),
+ MYF(0));
+ DBUG_RETURN(TRUE);
}
if ((new_db_type= ha_checktype(create_info->db_type)) !=
create_info->db_type)
@@ -1160,8 +1154,8 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
if ((create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
(file->table_flags() & HA_NO_TEMP_TABLES))
{
- my_error(ER_ILLEGAL_HA,MYF(0),table_name);
- DBUG_RETURN(-1);
+ my_error(ER_ILLEGAL_HA, MYF(0), table_name);
+ DBUG_RETURN(TRUE);
}
#endif
@@ -1186,7 +1180,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
keys, tmp_table, db_options, file,
key_info_buffer, &key_count,
select_field_count))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
/* Check if table exists */
if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
@@ -1209,10 +1203,10 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
{
create_info->table_existed= 1; // Mark that table existed
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (wait_if_global_read_lock(thd, 0, 1))
DBUG_RETURN(error);
@@ -1224,10 +1218,10 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
{
create_info->table_existed= 1; // Mark that table existed
- error= 0;
+ error= FALSE;
}
else
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
goto end;
}
}
@@ -1253,10 +1247,10 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
if (create_if_not_exists)
{
create_info->table_existed= 1; // Mark that table existed
- error= 0;
+ error= FALSE;
}
else
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
goto end;
}
}
@@ -1292,7 +1286,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
HA_LEX_CREATE_TMP_TABLE));
mysql_bin_log.write(&qinfo);
}
- error=0;
+ error= FALSE;
end:
VOID(pthread_mutex_unlock(&LOCK_open));
start_waiting_global_read_lock(thd);
@@ -1422,7 +1416,6 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
}
table->file->extra(HA_EXTRA_WRITE_CACHE);
DBUG_RETURN(table);
- /* Note that leaving the function resets binlogging properties */
}
@@ -1565,7 +1558,7 @@ static int send_check_errmsg(THD *thd, TABLE_LIST* table,
protocol->store((char*) operator_name, system_charset_info);
protocol->store("error", 5, system_charset_info);
protocol->store(errmsg, system_charset_info);
- thd->net.last_error[0]=0;
+ thd->clear_error();
if (protocol->write())
return -1;
return 1;
@@ -1742,20 +1735,20 @@ end:
/*
RETURN VALUES
- 0 Message sent to net (admin operation went ok)
- -1 Message should be sent by caller
- (admin operation or network communication failed)
+ FALSE Message sent to net (admin operation went ok)
+ TRUE Message should be sent by caller
+ (admin operation or network communication failed)
*/
-static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
- HA_CHECK_OPT* check_opt,
- const char *operator_name,
- thr_lock_type lock_type,
- bool open_for_modify,
- uint extra_open_options,
- int (*prepare_func)(THD *, TABLE_LIST *,
- HA_CHECK_OPT *),
- int (handler::*operator_func)
- (THD *, HA_CHECK_OPT *))
+static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
+ HA_CHECK_OPT* check_opt,
+ const char *operator_name,
+ thr_lock_type lock_type,
+ bool open_for_modify,
+ uint extra_open_options,
+ int (*prepare_func)(THD *, TABLE_LIST *,
+ HA_CHECK_OPT *),
+ int (handler::*operator_func)
+ (THD *, HA_CHECK_OPT *))
{
TABLE_LIST *table;
List<Item> field_list;
@@ -1773,7 +1766,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
item->maybe_null = 1;
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
mysql_ha_flush(thd, tables, MYSQL_HA_CLOSE_FINAL);
for (table= tables; table; table= table->next_local)
@@ -1785,9 +1778,6 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
thd->open_options|= extra_open_options;
table->table = open_ltable(thd, table, lock_type);
-#ifdef EMBEDDED_LIBRARY
- thd->net.last_errno= 0; // these errors shouldn't get client
-#endif
thd->open_options&= ~extra_open_options;
if (prepare_func)
@@ -1813,7 +1803,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
if (!(err_msg=thd->net.last_error))
err_msg=ER(ER_CHECK_NO_SUCH_TABLE);
protocol->store(err_msg, system_charset_info);
- thd->net.last_error[0]=0;
+ thd->clear_error();
if (protocol->write())
goto err;
continue;
@@ -1857,9 +1847,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
}
int result_code = (table->table->file->*operator_func)(thd, check_opt);
-#ifdef EMBEDDED_LIBRARY
- thd->net.last_errno= 0; // these errors shouldn't get client
-#endif
+ thd->clear_error(); // these errors shouldn't get client
protocol->prepare_for_resend();
protocol->store(table_name, system_charset_info);
protocol->store(operator_name, system_charset_info);
@@ -1960,16 +1948,16 @@ send_result_message:
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
err:
close_thread_tables(thd); // Shouldn't be needed
if (table)
table->table=0;
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
-int mysql_backup_table(THD* thd, TABLE_LIST* table_list)
+bool mysql_backup_table(THD* thd, TABLE_LIST* table_list)
{
DBUG_ENTER("mysql_backup_table");
DBUG_RETURN(mysql_admin_table(thd, table_list, 0,
@@ -1978,7 +1966,7 @@ int mysql_backup_table(THD* thd, TABLE_LIST* table_list)
}
-int mysql_restore_table(THD* thd, TABLE_LIST* table_list)
+bool mysql_restore_table(THD* thd, TABLE_LIST* table_list)
{
DBUG_ENTER("mysql_restore_table");
DBUG_RETURN(mysql_admin_table(thd, table_list, 0,
@@ -1988,7 +1976,7 @@ int mysql_restore_table(THD* thd, TABLE_LIST* table_list)
}
-int mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
+bool mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
{
DBUG_ENTER("mysql_repair_table");
DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
@@ -1998,7 +1986,7 @@ int mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
}
-int mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
+bool mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
{
DBUG_ENTER("mysql_optimize_table");
DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
@@ -2016,11 +2004,11 @@ int mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
tables Table list (one table only)
RETURN VALUES
- 0 ok
- -1 error
+ FALSE ok
+ TRUE error
*/
-int mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables,
+bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables,
LEX_STRING *key_cache_name)
{
HA_CHECK_OPT check_opt;
@@ -2033,7 +2021,7 @@ int mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables,
{
pthread_mutex_unlock(&LOCK_global_system_variables);
my_error(ER_UNKNOWN_KEY_CACHE, MYF(0), key_cache_name->str);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
pthread_mutex_unlock(&LOCK_global_system_variables);
check_opt.key_cache= key_cache;
@@ -2091,11 +2079,11 @@ int reassign_keycache_tables(THD *thd, KEY_CACHE *src_cache,
tables Table list (one table only)
RETURN VALUES
- 0 ok
- -1 error
+ FALSE ok
+ TRUE error
*/
-int mysql_preload_keys(THD* thd, TABLE_LIST* tables)
+bool mysql_preload_keys(THD* thd, TABLE_LIST* tables)
{
DBUG_ENTER("mysql_preload_keys");
DBUG_RETURN(mysql_admin_table(thd, tables, 0,
@@ -2115,13 +2103,13 @@ int mysql_preload_keys(THD* thd, TABLE_LIST* tables)
table_ident Src table_ident
RETURN VALUES
- 0 ok
- -1 error
+ FALSE OK
+ TRUE error
*/
-int mysql_create_like_table(THD* thd, TABLE_LIST* table,
- HA_CREATE_INFO *create_info,
- Table_ident *table_ident)
+bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
+ HA_CREATE_INFO *create_info,
+ Table_ident *table_ident)
{
TABLE **tmp_table;
char src_path[FN_REFLEN], dst_path[FN_REFLEN];
@@ -2129,7 +2117,8 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table,
char *table_name= table->real_name;
char *src_db= thd->db;
char *src_table= table_ident->table.str;
- int err, res= -1;
+ int err;
+ bool res= TRUE;
TABLE_LIST src_tables_list;
DBUG_ENTER("mysql_create_like_table");
@@ -2142,7 +2131,7 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table,
table_ident->db.str && check_db_name((src_db= table_ident->db.str)))
{
my_error(ER_WRONG_TABLE_NAME, MYF(0), src_table);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
bzero((gptr)&src_tables_list, sizeof(src_tables_list));
@@ -2229,7 +2218,7 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table,
HA_LEX_CREATE_TMP_TABLE));
mysql_bin_log.write(&qinfo);
}
- res= 0;
+ res= FALSE;
goto err;
table_exists:
@@ -2240,7 +2229,7 @@ table_exists:
ER(ER_TABLE_EXISTS_ERROR), table_name);
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_TABLE_EXISTS_ERROR,warn_buff);
- res= 0;
+ res= FALSE;
}
else
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
@@ -2253,7 +2242,7 @@ err:
}
-int mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
+bool mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
{
#ifdef OS2
thr_lock_type lock_type = TL_WRITE;
@@ -2268,7 +2257,7 @@ int mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
}
-int mysql_check_table(THD* thd, TABLE_LIST* tables,HA_CHECK_OPT* check_opt)
+bool mysql_check_table(THD* thd, TABLE_LIST* tables,HA_CHECK_OPT* check_opt)
{
#ifdef OS2
thr_lock_type lock_type = TL_WRITE;
@@ -2559,13 +2548,13 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list,
Alter table
*/
-int mysql_alter_table(THD *thd,char *new_db, char *new_name,
- HA_CREATE_INFO *create_info,
- TABLE_LIST *table_list,
- List<create_field> &fields, List<Key> &keys,
- uint order_num, ORDER *order,
- enum enum_duplicates handle_duplicates,
- ALTER_INFO *alter_info, bool do_send_ok)
+bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
+ HA_CREATE_INFO *create_info,
+ TABLE_LIST *table_list,
+ List<create_field> &fields, List<Key> &keys,
+ uint order_num, ORDER *order,
+ enum enum_duplicates handle_duplicates,
+ ALTER_INFO *alter_info, bool do_send_ok)
{
TABLE *table,*new_table=0;
int error;
@@ -2594,7 +2583,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list,
alter_info->tablespace_op));
if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ)))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
/* Check that we are not trying to rename to an existing table */
if (new_name)
@@ -2625,8 +2614,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
{
if (find_temporary_table(thd,new_db,new_name_buff))
{
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_name_buff);
- DBUG_RETURN(-1);
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff);
+ DBUG_RETURN(TRUE);
}
}
else
@@ -2637,8 +2626,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
F_OK))
{
/* Table will be closed in do_command() */
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0), new_alias);
- DBUG_RETURN(-1);
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
+ DBUG_RETURN(TRUE);
}
}
}
@@ -2678,7 +2667,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
error=0;
if (!access(new_name_buff,F_OK))
{
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_name);
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name);
error= -1;
}
else
@@ -2822,8 +2811,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
{
if (def->sql_type == FIELD_TYPE_BLOB)
{
- my_error(ER_BLOB_CANT_HAVE_DEFAULT,MYF(0),def->change);
- DBUG_RETURN(-1);
+ my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
+ DBUG_RETURN(TRUE);
}
def->def=alter->def; // Use new default
alter_it.remove();
@@ -2836,8 +2825,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
{
if (def->change && ! def->field)
{
- my_error(ER_BAD_FIELD_ERROR,MYF(0),def->change,table_name);
- DBUG_RETURN(-1);
+ my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table_name);
+ DBUG_RETURN(TRUE);
}
if (!def->after)
create_list.push_back(def);
@@ -2854,22 +2843,23 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
if (!find)
{
- my_error(ER_BAD_FIELD_ERROR,MYF(0),def->after,table_name);
- DBUG_RETURN(-1);
+ my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table_name);
+ DBUG_RETURN(TRUE);
}
find_it.after(def); // Put element after this
}
}
if (alter_info->alter_list.elements)
{
- my_error(ER_BAD_FIELD_ERROR,MYF(0),alter_info->alter_list.head()->name,
- table_name);
- DBUG_RETURN(-1);
+ my_error(ER_BAD_FIELD_ERROR, MYF(0),
+ alter_info->alter_list.head()->name, table_name);
+ DBUG_RETURN(TRUE);
}
if (!create_list.elements)
{
- my_error(ER_CANT_REMOVE_ALL_FIELDS,MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS),
+ MYF(0));
+ DBUG_RETURN(TRUE);
}
/*
@@ -2958,21 +2948,21 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
!my_strcasecmp(system_charset_info,key->name,primary_key_name))
{
my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
}
}
if (alter_info->drop_list.elements)
{
- my_error(ER_CANT_DROP_FIELD_OR_KEY,MYF(0),
- alter_info->drop_list.head()->name);
+ my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0),
+ alter_info->drop_list.head()->name);
goto err;
}
if (alter_info->alter_list.elements)
{
- my_error(ER_CANT_DROP_FIELD_OR_KEY,MYF(0),
- alter_info->alter_list.head()->name);
+ my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0),
+ alter_info->alter_list.head()->name);
goto err;
}
@@ -3175,7 +3165,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (!access(new_name_buff,F_OK))
{
error=1;
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_name_buff);
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff);
VOID(quick_rm_table(new_db_type,new_db,tmp_name));
VOID(pthread_mutex_unlock(&LOCK_open));
goto err;
@@ -3313,10 +3303,10 @@ end_temporary:
if (do_send_ok)
send_ok(thd,copied+deleted,0L,tmp_name);
thd->some_tables_deleted=0;
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
err:
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
@@ -3502,8 +3492,8 @@ copy_data_between_tables(TABLE *from,TABLE *to,
RETURN
Like mysql_alter_table().
*/
-int mysql_recreate_table(THD *thd, TABLE_LIST *table_list,
- bool do_send_ok)
+bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list,
+ bool do_send_ok)
{
DBUG_ENTER("mysql_recreate_table");
LEX *lex= thd->lex;
@@ -3525,7 +3515,7 @@ int mysql_recreate_table(THD *thd, TABLE_LIST *table_list,
}
-int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
+bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
{
TABLE_LIST *table;
List<Item> field_list;
@@ -3539,7 +3529,7 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
item->maybe_null= 1;
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
for (table= tables; table; table= table->next_local)
{
@@ -3558,7 +3548,7 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
{
/* Table didn't exist */
protocol->store_null();
- thd->net.last_error[0]=0;
+ thd->clear_error();
}
else
{
@@ -3620,11 +3610,11 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
}
send_eof(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
err:
close_thread_tables(thd); // Shouldn't be needed
if (table)
table->table=0;
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 5d175be74e1..7637679430f 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -38,12 +38,13 @@ static File_option triggers_file_parameters[]=
methods.
RETURN VALUE
- 0 - Success, non-0 in case of error.
+ FALSE Success
+ TRUE error
*/
-int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
+bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
{
TABLE *table;
- int result= 0;
+ bool result= 0;
DBUG_ENTER("mysql_create_or_drop_trigger");
@@ -53,7 +54,7 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
*/
if (open_and_lock_tables(thd, tables))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
/*
TODO: We should check if user has TRIGGER privilege for table here.
@@ -61,7 +62,7 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
we don't have proper privilege checking for triggers in place yet.
*/
if (check_global_access(thd, SUPER_ACL))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
table= tables->table;
@@ -74,19 +75,19 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
if (tables->view || table->tmp_table != NO_TMP_TABLE)
{
my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (!table->triggers)
{
if (!create)
{
- my_error(ER_TRG_DOES_NOT_EXIST, MYF(0));
- DBUG_RETURN(-1);
+ my_message(ER_TRG_DOES_NOT_EXIST, ER(ER_TRG_DOES_NOT_EXIST), MYF(0));
+ DBUG_RETURN(TRUE);
}
if (!(table->triggers= new (&table->mem_root) Table_triggers_list()))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
/*
@@ -96,12 +97,12 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
global read lock is held without helding LOCK_open).
*/
if (wait_if_global_read_lock(thd, 0, 0))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
VOID(pthread_mutex_lock(&LOCK_open));
- if ((create ? table->triggers->create_trigger(thd, tables):
- table->triggers->drop_trigger(thd, tables)))
- result= -1;
+ result= (create ?
+ table->triggers->create_trigger(thd, tables):
+ table->triggers->drop_trigger(thd, tables));
/* It is sensible to invalidate table in any case */
close_cached_table(thd, table);
@@ -140,7 +141,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables)
/* We don't allow creation of several triggers of the same type yet */
if (bodies[lex->trg_chistics.event][lex->trg_chistics.action_time])
{
- my_error(ER_TRG_ALREADY_EXISTS, MYF(0));
+ my_message(ER_TRG_ALREADY_EXISTS, ER(ER_TRG_ALREADY_EXISTS), MYF(0));
return 1;
}
@@ -150,7 +151,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables)
if (my_strcasecmp(system_charset_info, lex->name_and_length.str,
name->str) == 0)
{
- my_error(ER_TRG_ALREADY_EXISTS, MYF(0));
+ my_message(ER_TRG_ALREADY_EXISTS, ER(ER_TRG_ALREADY_EXISTS), MYF(0));
return 1;
}
}
@@ -256,7 +257,7 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables)
}
}
- my_error(ER_TRG_DOES_NOT_EXIST, MYF(0));
+ my_message(ER_TRG_DOES_NOT_EXIST, ER(ER_TRG_DOES_NOT_EXIST), MYF(0));
return 1;
}
@@ -416,8 +417,8 @@ err_with_lex_cleanup:
We don't care about this error message much because .TRG files will
be merged into .FRM anyway.
*/
- my_error(ER_WRONG_OBJECT, MYF(0), table_name, triggers_file_ext,
- "TRIGGER");
+ my_error(ER_WRONG_OBJECT, MYF(0),
+ table_name, triggers_file_ext, "TRIGGER");
DBUG_RETURN(1);
}
diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h
index 8ab2ab003f8..d0376f056d9 100644
--- a/sql/sql_trigger.h
+++ b/sql/sql_trigger.h
@@ -58,5 +58,11 @@ public:
static bool check_n_load(THD *thd, const char *db, const char *table_name,
TABLE *table);
+ bool has_delete_triggers()
+ {
+ return (bodies[TRG_EVENT_DELETE][TRG_ACTION_BEFORE] ||
+ bodies[TRG_EVENT_DELETE][TRG_ACTION_AFTER]);
+ }
+
friend class Item_trigger_field;
};
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index 0bb8ac8a28b..7fd81f22e66 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -368,7 +368,7 @@ int mysql_create_function(THD *thd,udf_func *udf)
if (!initialized)
{
- send_error(thd, ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES));
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
DBUG_RETURN(1);
}
@@ -379,19 +379,19 @@ int mysql_create_function(THD *thd,udf_func *udf)
*/
if (strchr(udf->dl, '/'))
{
- send_error(thd, ER_UDF_NO_PATHS,ER(ER_UDF_NO_PATHS));
+ my_message(ER_UDF_NO_PATHS, ER(ER_UDF_NO_PATHS), MYF(0));
DBUG_RETURN(1);
}
if (udf->name.length > NAME_LEN)
{
- net_printf(thd, ER_TOO_LONG_IDENT,udf->name);
+ my_error(ER_TOO_LONG_IDENT, MYF(0), udf->name);
DBUG_RETURN(1);
}
rw_wrlock(&THR_LOCK_udf);
if ((hash_search(&udf_hash,(byte*) udf->name.str, udf->name.length)))
{
- net_printf(thd, ER_UDF_EXISTS, udf->name);
+ my_error(ER_UDF_EXISTS, MYF(0), udf->name);
goto err;
}
if (!(dl = find_udf_dl(udf->dl)))
@@ -400,7 +400,8 @@ int mysql_create_function(THD *thd,udf_func *udf)
{
DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)",
udf->dl,errno,dlerror()));
- net_printf(thd, ER_CANT_OPEN_LIBRARY, udf->dl, errno, dlerror());
+ my_error(ER_CANT_OPEN_LIBRARY, MYF(0),
+ udf->dl, errno, dlerror());
goto err;
}
new_dl=1;
@@ -410,16 +411,13 @@ int mysql_create_function(THD *thd,udf_func *udf)
if (udf->func == NULL)
{
- net_printf(thd, ER_CANT_FIND_DL_ENTRY, udf->name);
+ my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), udf->name);
goto err;
}
udf->name.str=strdup_root(&mem,udf->name.str);
udf->dl=strdup_root(&mem,udf->dl);
if (!(u_d=add_udf(&udf->name,udf->returns,udf->dl,udf->type)))
- {
- send_error(thd,0); // End of memory
goto err;
- }
u_d->dlhandle = dl;
u_d->func=udf->func;
u_d->func_init=udf->func_init;
@@ -447,7 +445,7 @@ int mysql_create_function(THD *thd,udf_func *udf)
close_thread_tables(thd);
if (error)
{
- net_printf(thd, ER_ERROR_ON_WRITE, "func@mysql",error);
+ my_error(ER_ERROR_ON_WRITE, MYF(0), "func@mysql", error);
del_udf(u_d);
goto err;
}
@@ -470,14 +468,14 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
DBUG_ENTER("mysql_drop_function");
if (!initialized)
{
- send_error(thd, ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES));
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
DBUG_RETURN(1);
}
rw_wrlock(&THR_LOCK_udf);
if (!(udf=(udf_func*) hash_search(&udf_hash,(byte*) udf_name->str,
(uint) udf_name->length)))
{
- net_printf(thd, ER_FUNCTION_NOT_DEFINED, udf_name->str);
+ my_error(ER_FUNCTION_NOT_DEFINED, MYF(0), udf_name->str);
goto err;
}
del_udf(udf);
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 792e2cdf775..815e04c0111 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -24,21 +24,20 @@
#include "mysql_priv.h"
#include "sql_select.h"
-int mysql_union(THD *thd, LEX *lex, select_result *result,
- SELECT_LEX_UNIT *unit)
+bool mysql_union(THD *thd, LEX *lex, select_result *result,
+ SELECT_LEX_UNIT *unit)
{
DBUG_ENTER("mysql_union");
- int res, res_cln;
+ bool res;
if (!(res= unit->prepare(thd, result, SELECT_NO_UNLOCK)))
res= unit->exec();
- if (res == 0 && thd->cursor && thd->cursor->is_open())
+ if (!res && thd->cursor && thd->cursor->is_open())
{
thd->cursor->set_unit(unit);
- res_cln= 0;
}
else
- res_cln= unit->cleanup();
- DBUG_RETURN(res?res:res_cln);
+ res|= unit->cleanup();
+ DBUG_RETURN(res);
}
@@ -76,7 +75,7 @@ bool select_union::send_data(List<Item> &values)
unit->offset_limit_cnt--;
return 0;
}
- fill_record(table->field, values, 1);
+ fill_record(thd, table->field, values, 1);
if (thd->net.report_error || write_record(thd, table,&info))
{
if (thd->net.last_errno == ER_RECORD_FILE_FULL)
@@ -104,8 +103,7 @@ bool select_union::flush()
int error;
if ((error=table->file->extra(HA_EXTRA_NO_CACHE)))
{
- table->file->print_error(error,MYF(0));
- ::send_error(thd);
+ table->file->print_error(error, MYF(0));
return 1;
}
return 0;
@@ -147,8 +145,8 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd)
}
-int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
- ulong additional_options)
+bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
+ ulong additional_options)
{
SELECT_LEX *lex_select_save= thd_arg->lex->current_select;
SELECT_LEX *sl, *first_select;
@@ -177,16 +175,16 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
if (!sl->join->procedure &&
result->prepare(sl->join->fields_list, this))
{
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
sl->join->select_options|= SELECT_DESCRIBE;
sl->join->reinit();
}
}
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
prepared= 1;
- res= 0;
+ res= FALSE;
thd_arg->lex->current_select= sl= first_select= first_select_in_union();
found_rows_for_union= first_select->options & OPTION_FOUND_ROWS;
@@ -239,7 +237,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
sl->with_wild= 0;
last_procedure= join->procedure;
- if (res || thd_arg->is_fatal_error)
+ if ((res= (res || thd_arg->is_fatal_error)))
goto err;
if (sl == first_select)
{
@@ -269,7 +267,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
while ((type= tp++, item_tmp= it++))
{
if (((Item_type_holder*)type)->join_types(thd_arg, item_tmp))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
}
}
@@ -325,7 +323,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
{
if (tmp_arena)
thd->restore_backup_item_arena(tmp_arena, &backup);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
}
if (tmp_arena)
@@ -343,7 +341,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
result)))
{
fake_select_lex->table_list.empty();
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
fake_select_lex->item_list= item_list;
@@ -378,15 +376,15 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
thd_arg->lex->current_select= lex_select_save;
- DBUG_RETURN(res || thd_arg->is_fatal_error ? 1 : 0);
+ DBUG_RETURN(res || thd_arg->is_fatal_error);
err:
thd_arg->lex->current_select= lex_select_save;
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
-int st_select_lex_unit::exec()
+bool st_select_lex_unit::exec()
{
SELECT_LEX *lex_select_save= thd->lex->current_select;
SELECT_LEX *select_cursor=first_select_in_union();
@@ -395,7 +393,7 @@ int st_select_lex_unit::exec()
DBUG_ENTER("st_select_lex_unit::exec");
if (executed && !uncacheable && !describe)
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
executed= 1;
if (uncacheable || !item || !item->assigned() || describe)
@@ -410,7 +408,7 @@ int st_select_lex_unit::exec()
}
/* re-enabling indexes for next subselect iteration */
if (union_distinct && table->file->enable_indexes(HA_KEY_SWITCH_ALL))
- DBUG_ASSERT(1);
+ DBUG_ASSERT(TRUE);
}
for (SELECT_LEX *sl= select_cursor; sl; sl= sl->next_select())
{
@@ -465,7 +463,7 @@ int st_select_lex_unit::exec()
if (sl == union_distinct)
{
if (table->file->disable_indexes(HA_KEY_SWITCH_ALL))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
table->no_keyread=1;
}
res= sl->join->error;
@@ -474,7 +472,7 @@ int st_select_lex_unit::exec()
{
examined_rows+= thd->examined_row_count;
thd->lex->current_select= lex_select_save;
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
}
}
if (res)
@@ -500,7 +498,7 @@ int st_select_lex_unit::exec()
optimized= 1;
/* Send result to 'result' */
- res= -1;
+ res= TRUE;
{
List<Item_func_match> empty_list;
empty_list.empty();
@@ -519,7 +517,7 @@ int st_select_lex_unit::exec()
fake_select_lex->options, result)))
{
fake_select_lex->table_list.empty();
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
/*
@@ -566,7 +564,7 @@ int st_select_lex_unit::exec()
}
-int st_select_lex_unit::cleanup()
+bool st_select_lex_unit::cleanup()
{
int error= 0;
JOIN *join;
@@ -574,7 +572,7 @@ int st_select_lex_unit::cleanup()
if (cleaned)
{
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
cleaned= 1;
@@ -648,19 +646,19 @@ void st_select_lex_unit::reinit_exec_mechanism()
old_result old select_result object
RETURN
- 0 - OK
- -1 - error
+ FALSE - OK
+ TRUE - error
*/
-int st_select_lex_unit::change_result(select_subselect *result,
- select_subselect *old_result)
+bool st_select_lex_unit::change_result(select_subselect *result,
+ select_subselect *old_result)
{
- int res= 0;
+ bool res= FALSE;
for (SELECT_LEX *sl= first_select_in_union(); sl; sl= sl->next_select())
{
if (sl->join && sl->join->result == old_result)
- if ((res= sl->join->change_result(result)))
- return (res);
+ if (sl->join->change_result(result))
+ return TRUE;
}
if (fake_select_lex && fake_select_lex->join)
res= fake_select_lex->join->change_result(result);
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 561480bd289..c5167018701 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -38,15 +38,15 @@ static bool compare_record(TABLE *table, ulong query_id)
if (memcmp(table->null_flags,
table->null_flags+table->rec_buff_length,
table->null_bytes))
- return 1; // Diff in NULL value
+ return TRUE; // Diff in NULL value
/* Compare updated fields */
for (Field **ptr=table->field ; *ptr ; ptr++)
{
if ((*ptr)->query_id == query_id &&
(*ptr)->cmp_binary_offset(table->rec_buff_length))
- return 1;
+ return TRUE;
}
- return 0;
+ return FALSE;
}
@@ -86,21 +86,21 @@ static bool check_fields(THD *thd, List<Item> &items)
}
-int mysql_update(THD *thd,
- TABLE_LIST *table_list,
- List<Item> &fields,
- List<Item> &values,
- COND *conds,
- uint order_num, ORDER *order,
- ha_rows limit,
- enum enum_duplicates handle_duplicates)
+bool mysql_update(THD *thd,
+ TABLE_LIST *table_list,
+ List<Item> &fields,
+ List<Item> &values,
+ COND *conds,
+ uint order_num, ORDER *order,
+ ha_rows limit,
+ enum enum_duplicates handle_duplicates)
{
bool using_limit= limit != HA_POS_ERROR;
bool safe_update= thd->options & OPTION_SAFE_UPDATES;
bool used_key_is_modified, transactional_table, log_delayed;
bool ignore_err= (thd->lex->duplicates == DUP_IGNORE);
+ bool res;
int error=0;
- int res;
uint used_index;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
uint want_privilege;
@@ -111,13 +111,14 @@ int mysql_update(THD *thd,
TABLE *table;
SQL_SELECT *select;
READ_RECORD info;
+ SELECT_LEX *select_lex= &thd->lex->select_lex;
DBUG_ENTER("mysql_update");
LINT_INIT(used_index);
LINT_INIT(timestamp_query_id);
- if ((error= open_and_lock_tables(thd, table_list)))
- DBUG_RETURN(error);
+ if (open_and_lock_tables(thd, table_list))
+ DBUG_RETURN(TRUE);
thd->proc_info="init";
table= table_list->table;
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
@@ -132,8 +133,8 @@ int mysql_update(THD *thd,
table_list->grant.want_privilege :
table->grant.want_privilege);
#endif
- if ((error= mysql_prepare_update(thd, table_list, &conds, order_num, order)))
- DBUG_RETURN(error);
+ if (mysql_prepare_update(thd, table_list, &conds, order_num, order))
+ DBUG_RETURN(TRUE);
old_used_keys= table->used_keys; // Keys used in WHERE
/*
@@ -151,20 +152,20 @@ int mysql_update(THD *thd,
table_list->grant.want_privilege= table->grant.want_privilege= want_privilege;
#endif
{
- thd->lex->select_lex.no_wrap_view_item= 1;
+ select_lex->no_wrap_view_item= 1;
res= setup_fields(thd, 0, table_list, fields, 1, 0, 0);
- thd->lex->select_lex.no_wrap_view_item= 0;
+ select_lex->no_wrap_view_item= 0;
if (res)
- DBUG_RETURN(-1); /* purecov: inspected */
+ DBUG_RETURN(TRUE); /* purecov: inspected */
}
if (table_list->view && check_fields(thd, fields))
{
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (!table_list->updatable || check_key_in_view(thd, table_list))
{
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "UPDATE");
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (table->timestamp_field)
{
@@ -182,8 +183,8 @@ int mysql_update(THD *thd,
#endif
if (setup_fields(thd, 0, table_list, values, 0, 0, 0))
{
- free_underlaid_joins(thd, &thd->lex->select_lex);
- DBUG_RETURN(-1); /* purecov: inspected */
+ free_underlaid_joins(thd, select_lex);
+ DBUG_RETURN(TRUE); /* purecov: inspected */
}
// Don't count on usage of 'only index' when calculating which key to use
@@ -193,13 +194,13 @@ int mysql_update(THD *thd,
(select && select->check_quick(thd, safe_update, limit)) || !limit)
{
delete select;
- free_underlaid_joins(thd, &thd->lex->select_lex);
+ free_underlaid_joins(thd, select_lex);
if (error)
{
- DBUG_RETURN(-1); // Error in where
+ DBUG_RETURN(TRUE); // Error in where
}
send_ok(thd); // No matching records
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
/* If running in safe sql mode, don't allow updates without keys */
if (table->quick_keys.is_clear_all())
@@ -212,7 +213,7 @@ int mysql_update(THD *thd,
goto err;
}
}
- init_ftfuncs(thd, &thd->lex->select_lex, 1);
+ init_ftfuncs(thd, select_lex, 1);
/* Check if we are modifying a key that we are used to search with */
if (select && select->quick)
@@ -361,8 +362,9 @@ int mysql_update(THD *thd,
if (!(select && select->skip_record()))
{
store_record(table,record[1]);
- if (fill_record(fields,values, 0) || thd->net.report_error)
+ if (fill_record(thd, fields, values, 0))
break; /* purecov: inspected */
+
found++;
if (table->triggers)
@@ -455,10 +457,8 @@ int mysql_update(THD *thd,
thd->lock=0;
}
- free_underlaid_joins(thd, &thd->lex->select_lex);
- if (error >= 0)
- send_error(thd,thd->killed_errno()); /* purecov: inspected */
- else
+ free_underlaid_joins(thd, select_lex);
+ if (error < 0)
{
char buff[80];
sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
@@ -472,18 +472,18 @@ int mysql_update(THD *thd,
thd->count_cuted_fields= CHECK_FIELD_IGNORE; /* calc cuted fields */
thd->abort_on_warning= 0;
free_io_cache(table);
- DBUG_RETURN(0);
+ DBUG_RETURN(error >= 0 || thd->net.report_error);
err:
delete select;
- free_underlaid_joins(thd, &thd->lex->select_lex);
+ free_underlaid_joins(thd, select_lex);
if (table->key_read)
{
table->key_read=0;
table->file->extra(HA_EXTRA_NO_KEYREAD);
}
thd->abort_on_warning= 0;
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
/*
@@ -498,11 +498,10 @@ err:
order - ORDER BY clause list
RETURN VALUE
- 0 - OK
- 1 - error (message is sent to user)
- -1 - error (message is not sent to user)
+ FALSE OK
+ TRUE error
*/
-int mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
+bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
Item **conds, uint order_num, ORDER *order)
{
TABLE *table= table_list->table;
@@ -526,16 +525,16 @@ int mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
setup_order(thd, select_lex->ref_pointer_array,
table_list, all_fields, all_fields, order) ||
setup_ftfuncs(select_lex))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
/* Check that we are not using table that we are updating in a sub select */
if (unique_table(table_list, table_list->next_global))
{
my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
select_lex->fix_prepare_information(thd, conds);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -568,11 +567,11 @@ static table_map get_table_map(List<Item> *items)
thd thread handler
RETURN
- 0 OK
- -1 Error
+ FALSE OK
+ TRUE Error
*/
-int mysql_multi_update_prepare(THD *thd)
+bool mysql_multi_update_prepare(THD *thd)
{
LEX *lex= thd->lex;
ulong opened_tables;
@@ -589,7 +588,7 @@ int mysql_multi_update_prepare(THD *thd)
/* open tables and create derived ones, but do not lock and fill them */
if (open_tables(thd, table_list, & table_count) ||
mysql_handle_derived(lex, &mysql_derived_prepare))
- DBUG_RETURN(thd->net.report_error ? -1 : 1);
+ DBUG_RETURN(TRUE);
/*
Ensure that we have update privilege for all tables and columns in the
SET part
@@ -618,7 +617,7 @@ int mysql_multi_update_prepare(THD *thd)
res= setup_fields(thd, 0, table_list, *fields, 1, 0, 0),
lex->select_lex.no_wrap_view_item= 0,
res))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
for (tl= table_list; tl ; tl= tl->next_local)
{
@@ -631,7 +630,7 @@ int mysql_multi_update_prepare(THD *thd)
if (update_view && check_fields(thd, *fields))
{
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
tables_for_update= get_table_map(fields);
@@ -657,7 +656,7 @@ int mysql_multi_update_prepare(THD *thd)
if (!tl->updatable || check_key_in_view(thd, tl))
{
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), tl->alias, "UPDATE");
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
/*
@@ -668,7 +667,7 @@ int mysql_multi_update_prepare(THD *thd)
tl->real_name))
{
my_error(ER_UPDATE_TABLE_USED, MYF(0), tl->real_name);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
DBUG_PRINT("info",("setting table `%s` for update", tl->alias));
tl->lock_type= lex->multi_lock_option;
@@ -687,7 +686,7 @@ int mysql_multi_update_prepare(THD *thd)
opened_tables= thd->status_var.opened_tables;
/* now lock and fill tables */
if (lock_tables(thd, table_list, table_count))
- DBUG_RETURN(thd->net.report_error ? -1 : 1);
+ DBUG_RETURN(TRUE);
/*
we have to re-call fixfields for fixed items, because lock maybe
@@ -718,12 +717,12 @@ int mysql_multi_update_prepare(THD *thd)
res= setup_fields(thd, 0, table_list, *fields, 1, 0, 0),
lex->select_lex.no_wrap_view_item= 0,
res))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (thd->fill_derived_tables() &&
mysql_handle_derived(lex, &mysql_derived_filling))
- DBUG_RETURN(thd->net.report_error ? -1 : 1);
- DBUG_RETURN (0);
+ DBUG_RETURN(TRUE);
+ DBUG_RETURN (FALSE);
}
@@ -731,25 +730,25 @@ int mysql_multi_update_prepare(THD *thd)
Setup multi-update handling and call SELECT to do the join
*/
-int mysql_multi_update(THD *thd,
- TABLE_LIST *table_list,
- List<Item> *fields,
- List<Item> *values,
- COND *conds,
- ulong options,
- enum enum_duplicates handle_duplicates,
- SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
+bool mysql_multi_update(THD *thd,
+ TABLE_LIST *table_list,
+ List<Item> *fields,
+ List<Item> *values,
+ COND *conds,
+ ulong options,
+ enum enum_duplicates handle_duplicates,
+ SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
{
- int res;
+ bool res;
multi_update *result;
DBUG_ENTER("mysql_multi_update");
- if ((res= mysql_multi_update_prepare(thd)))
- DBUG_RETURN(res);
+ if (mysql_multi_update_prepare(thd))
+ DBUG_RETURN(TRUE);
if (!(result= new multi_update(thd, table_list, fields, values,
handle_duplicates)))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
thd->no_trans_update= 0;
thd->abort_on_warning= test(thd->variables.sql_mode &
@@ -766,7 +765,7 @@ int mysql_multi_update(THD *thd,
result, unit, select_lex);
delete result;
thd->abort_on_warning= 0;
- DBUG_RETURN(res);
+ DBUG_RETURN(TRUE);
}
@@ -804,7 +803,7 @@ int multi_update::prepare(List<Item> &not_used_values,
if (!tables_to_update)
{
- my_error(ER_NO_TABLES_USED, MYF(0));
+ my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
DBUG_RETURN(1);
}
@@ -1016,7 +1015,7 @@ static bool safe_update_on_fly(JOIN_TAB *join_tab, List<Item> *fields)
case JT_SYSTEM:
case JT_CONST:
case JT_EQ_REF:
- return 1; // At most one matching row
+ return TRUE; // At most one matching row
case JT_REF:
return !check_if_key_used(table, join_tab->ref.key, *fields);
case JT_ALL:
@@ -1027,11 +1026,11 @@ static bool safe_update_on_fly(JOIN_TAB *join_tab, List<Item> *fields)
if ((table->file->table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
table->primary_key < MAX_KEY)
return !check_if_key_used(table, table->primary_key, *fields);
- return 1;
+ return TRUE;
default:
break; // Avoid compler warning
}
- return 0;
+ return FALSE;
}
@@ -1090,8 +1089,10 @@ bool multi_update::send_data(List<Item> &not_used_values)
{
table->status|= STATUS_UPDATED;
store_record(table,record[1]);
- if (fill_record(*fields_for_table[offset], *values_for_table[offset], 0))
+ if (fill_record(thd, *fields_for_table[offset],
+ *values_for_table[offset], 0))
DBUG_RETURN(1);
+
found++;
if (compare_record(table, thd->query_id))
{
@@ -1134,7 +1135,7 @@ bool multi_update::send_data(List<Item> &not_used_values)
{
int error;
TABLE *tmp_table= tmp_tables[offset];
- fill_record(tmp_table->field+1, *values_for_table[offset], 1);
+ fill_record(thd, tmp_table->field+1, *values_for_table[offset], 1);
found++;
/* Store pointer to row */
memcpy((char*) tmp_table->field[0]->ptr,
@@ -1160,7 +1161,7 @@ bool multi_update::send_data(List<Item> &not_used_values)
void multi_update::send_error(uint errcode,const char *err)
{
/* First send error what ever it is ... */
- ::send_error(thd,errcode,err);
+ my_error(errcode, MYF(0), err);
/* If nothing updated return */
if (!updated)
@@ -1353,8 +1354,7 @@ bool multi_update::send_eof()
/* Safety: If we haven't got an error before (should not happen) */
my_message(ER_UNKNOWN_ERROR, "An error occured in multi-table update",
MYF(0));
- ::send_error(thd);
- return 1;
+ return TRUE;
}
@@ -1364,5 +1364,5 @@ bool multi_update::send_eof()
(thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
::send_ok(thd, (ulong) thd->row_count_func,
thd->insert_id_used ? thd->insert_id() : 0L,buff);
- return 0;
+ return FALSE;
}
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 760ada9cdbd..68024876b32 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -42,13 +42,12 @@ TYPELIB updatable_views_with_limit_typelib=
mode - VIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE
RETURN VALUE
- 0 OK
- -1 Error
- 1 Error and error message given
+ FALSE OK
+ TRUE Error
*/
-int mysql_create_view(THD *thd,
- enum_view_create_mode mode)
+bool mysql_create_view(THD *thd,
+ enum_view_create_mode mode)
{
LEX *lex= thd->lex;
bool link_to_local;
@@ -58,7 +57,7 @@ int mysql_create_view(THD *thd,
TABLE_LIST *tbl;
SELECT_LEX *select_lex= &lex->select_lex, *sl;
SELECT_LEX_UNIT *unit= &lex->unit;
- int res= 0;
+ bool res= FALSE;
DBUG_ENTER("mysql_create_view");
if (lex->proc_list.first ||
@@ -67,16 +66,17 @@ int mysql_create_view(THD *thd,
my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), (lex->result ?
"INTO" :
"PROCEDURE"));
- res= -1;
+ res= TRUE;
goto err;
}
if (lex->derived_tables ||
lex->variables_used || lex->param_list.elements)
{
- my_error((lex->derived_tables ?
+ int err= (lex->derived_tables ?
ER_VIEW_SELECT_DERIVED :
- ER_VIEW_SELECT_VARIABLE), MYF(0));
- res= -1;
+ ER_VIEW_SELECT_VARIABLE);
+ my_message(err, ER(err), MYF(0));
+ res= TRUE;
goto err;
}
@@ -102,7 +102,7 @@ int mysql_create_view(THD *thd,
(check_access(thd, DELETE_ACL, view->db, &view->grant.privilege,
0, 0) ||
grant_option && check_grant(thd, DELETE_ACL, view, 0, 1, 0))))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
for (sl= select_lex; sl; sl= sl->next_select())
{
for (tbl= sl->get_table_list(); tbl; tbl= tbl->next_local)
@@ -113,14 +113,9 @@ int mysql_create_view(THD *thd,
*/
if (check_some_access(thd, VIEW_ANY_ACL, tbl))
{
- my_printf_error(ER_TABLEACCESS_DENIED_ERROR,
- ER(ER_TABLEACCESS_DENIED_ERROR),
- MYF(0),
- "ANY",
- thd->priv_user,
- thd->host_or_ip,
- tbl->real_name);
- DBUG_RETURN(-1);
+ my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
+ "ANY", thd->priv_user, thd->host_or_ip, tbl->real_name);
+ DBUG_RETURN(TRUE);
}
/*
Mark this table as a table which will be checked after the prepare
@@ -156,7 +151,7 @@ int mysql_create_view(THD *thd,
&tbl->grant.privilege, 0, 0) ||
grant_option && check_grant(thd, SELECT_ACL, tbl, 0, 1, 0))
{
- res= 1;
+ res= TRUE;
goto err;
}
}
@@ -178,8 +173,8 @@ int mysql_create_view(THD *thd,
}
#endif
- if ((res= open_and_lock_tables(thd, tables)))
- DBUG_RETURN(res);
+ if (open_and_lock_tables(thd, tables))
+ DBUG_RETURN(TRUE);
/*
check that tables are not temporary and this VIEW do not used in query
@@ -188,10 +183,11 @@ int mysql_create_view(THD *thd,
for (tbl= tables; tbl; tbl= tbl->next_global)
{
/* is this table temporary and is not view? */
- if (tbl->table->tmp_table != NO_TMP_TABLE && !tbl->view)
+ if (tbl->table->tmp_table != NO_TMP_TABLE && !tbl->view &&
+ !tbl->schema_table)
{
my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias);
- res= -1;
+ res= TRUE;
goto err;
}
@@ -201,7 +197,7 @@ int mysql_create_view(THD *thd,
strcmp(tbl->view_name.str, view->real_name) == 0)
{
my_error(ER_NO_SUCH_TABLE, MYF(0), tbl->view_db.str, tbl->view_name.str);
- res= -1;
+ res= TRUE;
goto err;
}
@@ -221,7 +217,7 @@ int mysql_create_view(THD *thd,
some errors from prepare are reported to user, if is not then
it will be checked after err: label
*/
- res= 1;
+ res= TRUE;
goto err;
}
@@ -256,7 +252,7 @@ int mysql_create_view(THD *thd,
if (strcmp(item->name, check->name) == 0)
{
my_error(ER_DUP_FIELDNAME, MYF(0), item->name);
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
}
}
@@ -287,15 +283,10 @@ int mysql_create_view(THD *thd,
if ((~fld->have_privileges & priv))
{
/* VIEW column has more privileges */
- my_printf_error(ER_COLUMNACCESS_DENIED_ERROR,
- ER(ER_COLUMNACCESS_DENIED_ERROR),
- MYF(0),
- "create view",
- thd->priv_user,
- thd->host_or_ip,
- item->name,
- view->real_name);
- DBUG_RETURN(-1);
+ my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
+ "create view", thd->priv_user, thd->host_or_ip, item->name,
+ view->real_name);
+ DBUG_RETURN(TRUE);
}
}
}
@@ -304,7 +295,7 @@ int mysql_create_view(THD *thd,
if (wait_if_global_read_lock(thd, 0, 0))
{
- res= -1;
+ res= TRUE;
goto err;
}
VOID(pthread_mutex_lock(&LOCK_open));
@@ -322,9 +313,7 @@ err:
thd->proc_info= "end";
lex->link_first_table_back(view, link_to_local);
unit->cleanup();
- if (thd->net.report_error)
- res= -1;
- DBUG_RETURN(res);
+ DBUG_RETURN(res || thd->net.report_error);
}
@@ -441,8 +430,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
if (!parser->ok() ||
strncmp("VIEW", parser->type()->str, parser->type()->length))
{
- my_error(ER_WRONG_OBJECT, MYF(0), (view->db ? view->db : thd->db),
- view->real_name, "VIEW");
+ my_error(ER_WRONG_OBJECT, MYF(0),
+ (view->db ? view->db : thd->db), view->real_name, "VIEW");
DBUG_RETURN(-1);
}
@@ -494,7 +483,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
tbl;
tbl= tbl->next_local)
{
- if (tbl->view && !tbl->updatable_view)
+ if ((tbl->view && !tbl->updatable_view) || tbl->schema_table)
{
view->updatable_view= 0;
break;
@@ -696,7 +685,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
if (check_table_access(thd, SELECT_ACL, view_tables, 1) &&
check_table_access(thd, SHOW_VIEW_ACL, table, 1))
{
- my_error(ER_VIEW_NO_EXPLAIN, MYF(0));
+ my_message(ER_VIEW_NO_EXPLAIN, ER(ER_VIEW_NO_EXPLAIN), MYF(0));
goto err;
}
}
@@ -845,12 +834,11 @@ err:
drop_mode - cascade/check
RETURN VALUE
- 0 OK
- -1 Error
- 1 Error and error message given
+ FALSE OK
+ TRUE Error
*/
-int mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
+bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
{
DBUG_ENTER("mysql_drop_view");
char path[FN_REFLEN];
@@ -886,11 +874,11 @@ int mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
VOID(pthread_mutex_unlock(&LOCK_open));
}
send_ok(thd);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
err:
VOID(pthread_mutex_unlock(&LOCK_open));
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
diff --git a/sql/sql_view.h b/sql/sql_view.h
index 538f548d97b..4cb2514f5b9 100644
--- a/sql/sql_view.h
+++ b/sql/sql_view.h
@@ -16,12 +16,12 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-int mysql_create_view(THD *thd,
- enum_view_create_mode mode);
+bool mysql_create_view(THD *thd,
+ enum_view_create_mode mode);
my_bool mysql_make_view(File_parser *parser, TABLE_LIST *table);
-int mysql_drop_view(THD *thd, TABLE_LIST *view, enum_drop_mode drop_mode);
+bool mysql_drop_view(THD *thd, TABLE_LIST *view, enum_drop_mode drop_mode);
bool check_key_in_view(THD *thd, TABLE_LIST * view);
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 309a9249d0e..e6e7c9b59ae 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -140,6 +140,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token CLIENT_SYM
%token COMMENT_SYM
%token COMMIT_SYM
+%token CONSISTENT_SYM
%token COUNT_SYM
%token CREATE
%token CROSS
@@ -176,6 +177,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token SELECT_SYM
%token SHOW
%token SLAVE
+%token SNAPSHOT_SYM
%token SQL_SYM
%token SQL_THREAD
%token START_SYM
@@ -661,7 +663,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
opt_table_alias
%type <table>
- table_ident table_ident_nodb references
+ table_ident table_ident_nodb references from_table_ident
%type <simple_string>
remember_name remember_end opt_ident opt_db text_or_password
@@ -676,6 +678,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
table_option opt_if_not_exists opt_no_write_to_binlog opt_var_type
opt_var_ident_type delete_option opt_temporary all_or_any opt_distinct
opt_ignore_leaves fulltext_options spatial_type union_option
+ start_transaction_opts
%type <ulong_num>
ULONG_NUM raid_types merge_insert_types
@@ -814,7 +817,7 @@ query:
if (!thd->bootstrap &&
(!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
{
- send_error(thd,ER_EMPTY_QUERY);
+ my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
YYABORT;
}
else
@@ -1150,7 +1153,7 @@ create:
if (lex->sphead)
{
- net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "PROCEDURE");
+ my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "PROCEDURE");
YYABORT;
}
/* Order is important here: new - reset - init */
@@ -1223,7 +1226,7 @@ create:
if (lex->sphead)
{
- net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "TRIGGER");
+ my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "TRIGGER");
YYABORT;
}
@@ -1304,7 +1307,7 @@ create_function_tail:
if (lex->sphead)
{
- net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "FUNCTION");
+ my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "FUNCTION");
YYABORT;
}
/* Order is important here: new - reset - init */
@@ -1464,7 +1467,7 @@ sp_fdparam:
if (spc->find_pvar(&$1, TRUE))
{
- net_printf(YYTHD, ER_SP_DUP_PARAM, $1.str);
+ my_error(ER_SP_DUP_PARAM, MYF(0), $1.str);
YYABORT;
}
spc->push_pvar(&$1, (enum enum_field_types)$2, sp_param_in);
@@ -1490,7 +1493,7 @@ sp_pdparam:
if (spc->find_pvar(&$2, TRUE))
{
- net_printf(YYTHD, ER_SP_DUP_PARAM, $2.str);
+ my_error(ER_SP_DUP_PARAM, MYF(0), $2.str);
YYABORT;
}
spc->push_pvar(&$2, (enum enum_field_types)$3,
@@ -1528,12 +1531,14 @@ sp_decls:
better error handling this way.) */
if (($2.vars || $2.conds) && ($1.curs || $1.hndlrs))
{ /* Variable or condition following cursor or handler */
- send_error(YYTHD, ER_SP_VARCOND_AFTER_CURSHNDLR);
+ my_message(ER_SP_VARCOND_AFTER_CURSHNDLR,
+ ER(ER_SP_VARCOND_AFTER_CURSHNDLR), MYF(0));
YYABORT;
}
if ($2.curs && $1.hndlrs)
{ /* Cursor following handler */
- send_error(YYTHD, ER_SP_CURSOR_AFTER_HANDLER);
+ my_message(ER_SP_CURSOR_AFTER_HANDLER,
+ ER(ER_SP_CURSOR_AFTER_HANDLER), MYF(0));
YYABORT;
}
$$.vars= $1.vars + $2.vars;
@@ -1581,7 +1586,7 @@ sp_decl:
if (spc->find_cond(&$2, TRUE))
{
- net_printf(YYTHD, ER_SP_DUP_COND, $2.str);
+ my_error(ER_SP_DUP_COND, MYF(0), $2.str);
YYABORT;
}
YYTHD->lex->spcont->push_cond(&$2, $5);
@@ -1638,7 +1643,7 @@ sp_decl:
if (ctx->find_cursor(&$2, &offp, TRUE))
{
- net_printf(YYTHD, ER_SP_DUP_CURS, $2.str);
+ my_error(ER_SP_DUP_CURS, MYF(0), $2.str);
delete $5;
YYABORT;
}
@@ -1665,12 +1670,14 @@ sp_cursor_stmt:
if (lex->sql_command != SQLCOM_SELECT)
{
- send_error(YYTHD, ER_SP_BAD_CURSOR_QUERY);
+ my_message(ER_SP_BAD_CURSOR_QUERY, ER(ER_SP_BAD_CURSOR_QUERY),
+ MYF(0));
YYABORT;
}
if (lex->result)
{
- send_error(YYTHD, ER_SP_BAD_CURSOR_SELECT);
+ my_message(ER_SP_BAD_CURSOR_SELECT, ER(ER_SP_BAD_CURSOR_SELECT),
+ MYF(0));
YYABORT;
}
lex->sp_lex_in_use= TRUE;
@@ -1740,7 +1747,7 @@ sp_hcond:
$$= Lex->spcont->find_cond(&$1);
if ($$ == NULL)
{
- net_printf(YYTHD, ER_SP_COND_MISMATCH, $1.str);
+ my_error(ER_SP_COND_MISMATCH, MYF(0), $1.str);
YYABORT;
}
}
@@ -1769,7 +1776,7 @@ sp_decl_idents:
if (spc->find_pvar(&$1, TRUE))
{
- net_printf(YYTHD, ER_SP_DUP_VAR, $1.str);
+ my_error(ER_SP_DUP_VAR, MYF(0), $1.str);
YYABORT;
}
spc->push_pvar(&$1, (enum_field_types)0, sp_param_in);
@@ -1782,7 +1789,7 @@ sp_decl_idents:
if (spc->find_pvar(&$3, TRUE))
{
- net_printf(YYTHD, ER_SP_DUP_VAR, $3.str);
+ my_error(ER_SP_DUP_VAR, MYF(0), $3.str);
YYABORT;
}
spc->push_pvar(&$3, (enum_field_types)0, sp_param_in);
@@ -1815,7 +1822,7 @@ sp_proc_stmt:
}
if (lex->sql_command == SQLCOM_CHANGE_DB)
{ /* "USE db" doesn't work in a procedure */
- send_error(YYTHD, ER_SP_NO_USE);
+ my_message(ER_SP_NO_USE, ER(ER_SP_NO_USE), MYF(0));
YYABORT;
}
/* Don't add an instruction for empty SET statements.
@@ -1834,7 +1841,7 @@ sp_proc_stmt:
*/
if (sp->m_type != TYPE_ENUM_PROCEDURE)
{
- send_error(YYTHD, ER_SP_BADSTATEMENT);
+ my_message(ER_SP_BADSTATEMENT, ER(ER_SP_BADSTATEMENT), MYF(0));
YYABORT;
}
else
@@ -1864,7 +1871,7 @@ sp_proc_stmt:
if (lex->sphead->m_type == TYPE_ENUM_PROCEDURE)
{
- send_error(YYTHD, ER_SP_BADRETURN);
+ my_message(ER_SP_BADRETURN, ER(ER_SP_BADRETURN), MYF(0));
YYABORT;
}
else
@@ -1873,7 +1880,7 @@ sp_proc_stmt:
if ($2->type() == Item::SUBSELECT_ITEM)
{ /* QQ For now, just disallow subselects as values */
- send_error(lex->thd, ER_SP_BADSTATEMENT);
+ my_message(ER_SP_BADSTATEMENT, ER(ER_SP_BADSTATEMENT), MYF(0));
YYABORT;
}
i= new sp_instr_freturn(lex->sphead->instructions(),
@@ -1936,7 +1943,7 @@ sp_proc_stmt:
if (! lab)
{
- net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "LEAVE", $2.str);
+ my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "LEAVE", $2.str);
YYABORT;
}
else
@@ -1966,7 +1973,7 @@ sp_proc_stmt:
if (! lab || lab->type != SP_LAB_ITER)
{
- net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "ITERATE", $2.str);
+ my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "ITERATE", $2.str);
YYABORT;
}
else
@@ -1994,7 +2001,7 @@ sp_proc_stmt:
if (lab)
{
- net_printf(YYTHD, ER_SP_LABEL_REDEFINE, $2.str);
+ my_error(ER_SP_LABEL_REDEFINE, MYF(0), $2.str);
YYABORT;
}
else
@@ -2018,7 +2025,7 @@ sp_proc_stmt:
if (sp->m_in_handler)
{
- send_error(lex->thd, ER_SP_GOTO_IN_HNDLR);
+ my_message(ER_SP_GOTO_IN_HNDLR, ER(ER_SP_GOTO_IN_HNDLR), MYF(0));
YYABORT;
}
lab= ctx->find_label($2.str);
@@ -2069,7 +2076,7 @@ sp_proc_stmt:
if (! lex->spcont->find_cursor(&$2, &offset))
{
- net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str);
+ my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str);
YYABORT;
}
i= new sp_instr_copen(sp->instructions(), lex->spcont, offset);
@@ -2084,7 +2091,7 @@ sp_proc_stmt:
if (! lex->spcont->find_cursor(&$3, &offset))
{
- net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $3.str);
+ my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $3.str);
YYABORT;
}
i= new sp_instr_cfetch(sp->instructions(), lex->spcont, offset);
@@ -2101,7 +2108,7 @@ sp_proc_stmt:
if (! lex->spcont->find_cursor(&$2, &offset))
{
- net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str);
+ my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str);
YYABORT;
}
i= new sp_instr_cclose(sp->instructions(), lex->spcont, offset);
@@ -2125,7 +2132,7 @@ sp_fetch_list:
if (!spc || !(spv = spc->find_pvar(&$1)))
{
- net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str);
+ my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
YYABORT;
}
else
@@ -2147,7 +2154,7 @@ sp_fetch_list:
if (!spc || !(spv = spc->find_pvar(&$3)))
{
- net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $3.str);
+ my_error(ER_SP_UNDECLARED_VAR, MYF(0), $3.str);
YYABORT;
}
else
@@ -2271,7 +2278,7 @@ sp_labeled_control:
if (lab)
{
- net_printf(YYTHD, ER_SP_LABEL_REDEFINE, $1.str);
+ my_error(ER_SP_LABEL_REDEFINE, MYF(0), $1.str);
YYABORT;
}
else
@@ -2292,7 +2299,7 @@ sp_labeled_control:
if (!lab ||
my_strcasecmp(system_charset_info, $5.str, lab->name) != 0)
{
- net_printf(YYTHD, ER_SP_LABEL_MISMATCH, $5.str);
+ my_error(ER_SP_LABEL_MISMATCH, MYF(0), $5.str);
YYABORT;
}
}
@@ -2550,9 +2557,9 @@ default_charset:
cinfo->default_table_charset && $4 &&
!my_charset_same(cinfo->default_table_charset,$4))
{
- net_printf(YYTHD, ER_CONFLICTING_DECLARATIONS,
- "CHARACTER SET ", cinfo->default_table_charset->csname,
- "CHARACTER SET ", $4->csname);
+ my_error(ER_CONFLICTING_DECLARATIONS, MYF(0),
+ "CHARACTER SET ", cinfo->default_table_charset->csname,
+ "CHARACTER SET ", $4->csname);
YYABORT;
}
Lex->create_info.default_table_charset= $4;
@@ -2567,8 +2574,8 @@ default_collation:
cinfo->default_table_charset && $4 &&
!my_charset_same(cinfo->default_table_charset,$4))
{
- net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
- $4->name, cinfo->default_table_charset->csname);
+ my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
+ $4->name, cinfo->default_table_charset->csname);
YYABORT;
}
Lex->create_info.default_table_charset= $4;
@@ -2580,7 +2587,7 @@ storage_engines:
{
$$ = ha_resolve_by_name($1.str,$1.length);
if ($$ == DB_TYPE_UNKNOWN) {
- net_printf(YYTHD, ER_UNKNOWN_STORAGE_ENGINE, $1.str);
+ my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
YYABORT;
}
};
@@ -2770,18 +2777,18 @@ type:
$$=FIELD_TYPE_TINY_BLOB; }
| BLOB_SYM opt_len { Lex->charset=&my_charset_bin;
$$=FIELD_TYPE_BLOB; }
- | spatial_type {
+ | spatial_type
+ {
#ifdef HAVE_SPATIAL
- Lex->charset=&my_charset_bin;
- Lex->uint_geom_type= (uint)$1;
- $$=FIELD_TYPE_GEOMETRY;
+ Lex->charset=&my_charset_bin;
+ Lex->uint_geom_type= (uint)$1;
+ $$=FIELD_TYPE_GEOMETRY;
#else
- net_printf(Lex->thd, ER_FEATURE_DISABLED,
- sym_group_geom.name,
- sym_group_geom.needed_define);
- YYABORT;
+ my_error(ER_FEATURE_DISABLED, MYF(0)
+ sym_group_geom.name, sym_group_geom.needed_define);
+ YYABORT;
#endif
- }
+ }
| MEDIUMBLOB { Lex->charset=&my_charset_bin;
$$=FIELD_TYPE_MEDIUM_BLOB; }
| LONGBLOB { Lex->charset=&my_charset_bin;
@@ -2945,8 +2952,8 @@ attribute:
{
if (Lex->charset && !my_charset_same(Lex->charset,$2))
{
- net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
- $2->name,Lex->charset->csname);
+ my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
+ $2->name,Lex->charset->csname);
YYABORT;
}
else
@@ -2971,7 +2978,7 @@ charset_name:
{
if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
{
- net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
+ my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
YYABORT;
}
}
@@ -2989,7 +2996,7 @@ old_or_new_charset_name:
if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) &&
!($$=get_old_charset_by_name($1.str)))
{
- net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
+ my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
YYABORT;
}
}
@@ -3005,7 +3012,7 @@ collation_name:
{
if (!($$=get_charset_by_name($1.str,MYF(0))))
{
- net_printf(YYTHD,ER_UNKNOWN_COLLATION,$1.str);
+ my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
YYABORT;
}
};
@@ -3029,9 +3036,10 @@ opt_binary:
| BYTE_SYM { Lex->charset=&my_charset_bin; }
| UNICODE_SYM
{
- if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0))))
+ if (!(Lex->charset=get_charset_by_csname("ucs2",
+ MY_CS_PRIMARY,MYF(0))))
{
- net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
+ my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
YYABORT;
}
}
@@ -3093,8 +3101,8 @@ key_type:
#ifdef HAVE_SPATIAL
$$= Key::SPATIAL;
#else
- net_printf(Lex->thd, ER_FEATURE_DISABLED,
- sym_group_geom.name, sym_group_geom.needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ sym_group_geom.name, sym_group_geom.needed_define);
YYABORT;
#endif
};
@@ -3126,8 +3134,8 @@ opt_unique_or_fulltext:
#ifdef HAVE_SPATIAL
$$= Key::SPATIAL;
#else
- net_printf(Lex->thd, ER_FEATURE_DISABLED,
- sym_group_geom.name, sym_group_geom.needed_define);
+ my_message(ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), MYF(0),
+ sym_group_geom.name, sym_group_geom.needed_define);
YYABORT;
#endif
}
@@ -3157,9 +3165,7 @@ key_part:
int key_part_len= atoi($3.str);
if (!key_part_len)
{
- my_printf_error(ER_UNKNOWN_ERROR,
- "Key part '%s' length cannot be 0",
- MYF(0), $1.str);
+ my_error(ER_KEY_PART_0, MYF(0), $1.str);
}
$$=new key_part_spec($1.str,(uint) key_part_len);
};
@@ -3368,7 +3374,7 @@ alter_list_item:
if (check_table_name($3->table.str,$3->table.length) ||
$3->db.str && check_db_name($3->db.str))
{
- net_printf(lex->thd,ER_WRONG_TABLE_NAME,$3->table.str);
+ my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
YYABORT;
}
lex->alter_info.flags|= ALTER_RENAME;
@@ -3383,8 +3389,8 @@ alter_list_item:
$5= $5 ? $5 : $4;
if (!my_charset_same($4,$5))
{
- net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
- $5->name,$4->csname);
+ my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
+ $5->name, $4->csname);
YYABORT;
}
LEX *lex= Lex;
@@ -3473,10 +3479,21 @@ slave:
start:
- START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
- {}
+ START_SYM TRANSACTION_SYM start_transaction_opts
+ {
+ Lex->sql_command = SQLCOM_BEGIN;
+ Lex->start_transaction_opt= $3;
+ }
;
+start_transaction_opts:
+ /*empty*/ { $$ = 0; }
+ | WITH CONSISTENT_SYM SNAPSHOT_SYM
+ {
+ $$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
+ }
+ ;
+
slave_thread_opts:
{ Lex->slave_thd_opt= 0; }
slave_thread_opt_list
@@ -3504,7 +3521,8 @@ slave_until:
!((lex->mi.log_file_name && lex->mi.pos) ||
(lex->mi.relay_log_name && lex->mi.relay_log_pos)))
{
- send_error(lex->thd, ER_BAD_SLAVE_UNTIL_COND);
+ my_message(ER_BAD_SLAVE_UNTIL_COND,
+ ER(ER_BAD_SLAVE_UNTIL_COND), MYF(0));
YYABORT;
}
@@ -4217,9 +4235,9 @@ simple_expr:
{
if (!$1.symbol->create_func)
{
- net_printf(Lex->thd, ER_FEATURE_DISABLED,
- $1.symbol->group->name,
- $1.symbol->group->needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ $1.symbol->group->name,
+ $1.symbol->group->needed_define);
YYABORT;
}
$$= ((Item*(*)(void))($1.symbol->create_func))();
@@ -4228,9 +4246,9 @@ simple_expr:
{
if (!$1.symbol->create_func)
{
- net_printf(Lex->thd, ER_FEATURE_DISABLED,
- $1.symbol->group->name,
- $1.symbol->group->needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ $1.symbol->group->name,
+ $1.symbol->group->needed_define);
YYABORT;
}
$$= ((Item*(*)(Item*))($1.symbol->create_func))($3);
@@ -4239,9 +4257,9 @@ simple_expr:
{
if (!$1.symbol->create_func)
{
- net_printf(Lex->thd, ER_FEATURE_DISABLED,
- $1.symbol->group->name,
- $1.symbol->group->needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ $1.symbol->group->name,
+ $1.symbol->group->needed_define);
YYABORT;
}
$$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);
@@ -4250,9 +4268,9 @@ simple_expr:
{
if (!$1.symbol->create_func)
{
- net_printf(Lex->thd, ER_FEATURE_DISABLED,
- $1.symbol->group->name,
- $1.symbol->group->needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ $1.symbol->group->name,
+ $1.symbol->group->needed_define);
YYABORT;
}
$$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);
@@ -4355,8 +4373,8 @@ simple_expr:
#ifdef HAVE_SPATIAL
$$= $1;
#else
- net_printf(Lex->thd, ER_FEATURE_DISABLED,
- sym_group_geom.name, sym_group_geom.needed_define);
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ sym_group_geom.name, sym_group_geom.needed_define);
YYABORT;
#endif
}
@@ -5212,12 +5230,12 @@ olap_opt:
LEX *lex=Lex;
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
{
- net_printf(lex->thd, ER_WRONG_USAGE, "WITH CUBE",
+ my_error(ER_WRONG_USAGE, MYF(0), "WITH CUBE",
"global union parameters");
YYABORT;
}
lex->current_select->olap= CUBE_TYPE;
- net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
+ my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE");
YYABORT; /* To be deleted in 5.1 */
}
| WITH ROLLUP_SYM
@@ -5225,7 +5243,7 @@ olap_opt:
LEX *lex= Lex;
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
{
- net_printf(lex->thd, ER_WRONG_USAGE, "WITH ROLLUP",
+ my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
"global union parameters");
YYABORT;
}
@@ -5249,9 +5267,8 @@ order_clause:
lex->current_select->olap !=
UNSPECIFIED_OLAP_TYPE)
{
- net_printf(lex->thd, ER_WRONG_USAGE,
- "CUBE/ROLLUP",
- "ORDER BY");
+ my_error(ER_WRONG_USAGE, MYF(0),
+ "CUBE/ROLLUP", "ORDER BY");
YYABORT;
}
} order_list;
@@ -5349,9 +5366,7 @@ procedure_clause:
LEX *lex=Lex;
if (&lex->select_lex != lex->current_select)
{
- net_printf(lex->thd, ER_WRONG_USAGE,
- "PROCEDURE",
- "subquery");
+ my_error(ER_WRONG_USAGE, MYF(0), "PROCEDURE", "subquery");
YYABORT;
}
lex->proc_list.elements=0;
@@ -5415,7 +5430,7 @@ select_var_ident:
if (!lex->spcont || !(t=lex->spcont->find_pvar(&$1)))
{
- net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str);
+ my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
YYABORT;
}
if (! lex->result)
@@ -5506,7 +5521,7 @@ drop:
LEX *lex=Lex;
if (lex->sphead)
{
- net_printf(YYTHD, ER_SP_NO_DROP_SP, "FUNCTION");
+ my_error(ER_SP_NO_DROP_SP, MYF(0), "FUNCTION");
YYABORT;
}
lex->sql_command = SQLCOM_DROP_FUNCTION;
@@ -5518,7 +5533,7 @@ drop:
LEX *lex=Lex;
if (lex->sphead)
{
- net_printf(YYTHD, ER_SP_NO_DROP_SP, "PROCEDURE");
+ my_error(ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE");
YYABORT;
}
lex->sql_command = SQLCOM_DROP_PROCEDURE;
@@ -5771,8 +5786,8 @@ update:
else if (lex->select_lex.get_table_list()->derived)
{
/* it is single table update and it is update of derived table */
- net_printf(lex->thd, ER_NON_UPDATABLE_TABLE,
- lex->select_lex.get_table_list()->alias, "UPDATE");
+ my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
+ lex->select_lex.get_table_list()->alias, "UPDATE");
YYABORT;
}
else
@@ -5890,21 +5905,32 @@ show: SHOW
;
show_param:
- DATABASES wild
- { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
- | opt_full TABLES opt_db wild
- {
- LEX *lex= Lex;
- lex->sql_command= SQLCOM_SHOW_TABLES;
- lex->select_lex.db= $3;
- }
- | TABLE_SYM STATUS_SYM opt_db wild
- {
- LEX *lex= Lex;
- lex->sql_command= SQLCOM_SHOW_TABLES;
- lex->describe= DESCRIBE_EXTENDED;
- lex->select_lex.db= $3;
- }
+ DATABASES ext_select_item_list wild_and_where
+ {
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_DATABASES;
+ if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
+ YYABORT;
+ }
+ | opt_full TABLES ext_select_item_list opt_db wild_and_where
+ {
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_TABLES;
+ lex->select_lex.db= $4;
+ if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
+ YYABORT;
+ }
+ | TABLE_SYM STATUS_SYM ext_select_item_list opt_db wild_and_where
+ {
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_TABLE_STATUS;
+ lex->select_lex.db= $4;
+ if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
+ YYABORT;
+ }
| OPEN_SYM TABLES opt_db wild
{
LEX *lex= Lex;
@@ -5914,12 +5940,14 @@ show_param:
| ENGINE_SYM storage_engines
{ Lex->create_info.db_type= $2; }
show_engine_param
- | opt_full COLUMNS from_or_in table_ident opt_db wild
+ | opt_full COLUMNS ext_select_item_list from_table_ident opt_db wild_and_where
{
- Lex->sql_command= SQLCOM_SHOW_FIELDS;
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_FIELDS;
if ($5)
$4->change_db($5);
- if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
+ if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
YYABORT;
}
| NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
@@ -5945,13 +5973,15 @@ show_param:
LEX *lex= Lex;
lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
} opt_limit_clause_init
- | keys_or_index from_or_in table_ident opt_db
- {
- Lex->sql_command= SQLCOM_SHOW_KEYS;
+ | keys_or_index ext_select_item_list from_table_ident opt_db where_clause
+ {
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_KEYS;
if ($4)
$3->change_db($4);
- if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
- YYABORT;
+ if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
+ YYABORT;
}
| COLUMN_SYM TYPES_SYM
{
@@ -5998,10 +6028,22 @@ show_param:
thd->lex->sql_command= SQLCOM_SHOW_VARIABLES;
thd->lex->option_type= (enum_var_type) $1;
}
- | charset wild
- { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
- | COLLATION_SYM wild
- { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; }
+ | charset ext_select_item_list wild_and_where
+ {
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_CHARSETS;
+ if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS))
+ YYABORT;
+ }
+ | COLLATION_SYM ext_select_item_list wild_and_where
+ {
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_COLLATIONS;
+ if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS))
+ YYABORT;
+ }
| BERKELEY_DB_SYM LOGS_SYM
{ Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); }
| LOGS_SYM
@@ -6080,13 +6122,21 @@ show_param:
lex->sql_command = SQLCOM_SHOW_CREATE_FUNC;
lex->spname= $3;
}
- | PROCEDURE STATUS_SYM wild
+ | PROCEDURE STATUS_SYM ext_select_item_list wild_and_where
{
- Lex->sql_command = SQLCOM_SHOW_STATUS_PROC;
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_STATUS_PROC;
+ if (prepare_schema_table(YYTHD, lex, 0, SCH_PROCEDURES))
+ YYABORT;
}
- | FUNCTION_SYM STATUS_SYM wild
+ | FUNCTION_SYM STATUS_SYM ext_select_item_list wild_and_where
{
- Lex->sql_command = SQLCOM_SHOW_STATUS_FUNC;
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_STATUS_FUNC;
+ if (prepare_schema_table(YYTHD, lex, 0, SCH_PROCEDURES))
+ YYABORT;
};
show_engine_param:
@@ -6097,7 +6147,7 @@ show_engine_param:
Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
break;
default:
- net_printf(YYTHD, ER_NOT_SUPPORTED_YET, "STATUS");
+ my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS");
YYABORT;
}
}
@@ -6108,7 +6158,7 @@ show_engine_param:
Lex->sql_command = SQLCOM_SHOW_LOGS;
break;
default:
- net_printf(YYTHD, ER_NOT_SUPPORTED_YET, "LOGS");
+ my_error(ER_NOT_SUPPORTED_YET, MYF(0), "LOGS");
YYABORT;
}
};
@@ -6147,16 +6197,49 @@ binlog_from:
/* empty */ { Lex->mi.pos = 4; /* skip magic number */ }
| FROM ulonglong_num { Lex->mi.pos = $2; };
+from_table_ident:
+ /* empty */ { $$= 0; }
+ | from_or_in table_ident { $$= $2; }
+ ;
+
+wild_and_where:
+ /* empty */
+ | LIKE TEXT_STRING_sys
+ { Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
+ system_charset_info); }
+ | WHERE expr
+ {
+ Select->where= $2;
+ if ($2)
+ $2->top_level_item();
+ }
+ ;
+
+ext_select_item_list:
+ {
+ LEX *lex=Lex;
+ SELECT_LEX *sel= lex->current_select;
+ lex->lock_option= TL_READ;
+ mysql_init_select(lex);
+ lex->current_select->parsing_place= SELECT_LIST;
+ }
+ /* empty */
+ | select_item_list {};
+
/* A Oracle compatible synonym for show */
describe:
describe_command table_ident
{
- LEX *lex=Lex;
- lex->wild=0;
- lex->verbose=0;
- lex->sql_command=SQLCOM_SHOW_FIELDS;
- if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
+ LEX *lex= Lex;
+ lex->lock_option= TL_READ;
+ mysql_init_select(lex);
+ lex->current_select->parsing_place= SELECT_LIST;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->orig_sql_command= SQLCOM_SHOW_FIELDS;
+ lex->select_lex.db= 0;
+ lex->verbose= 0;
+ if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
YYABORT;
}
opt_describe_column {}
@@ -6260,7 +6343,7 @@ purge_option:
{
if ($2->check_cols(1) || $2->fix_fields(Lex->thd, 0, &$2))
{
- net_printf(Lex->thd, ER_WRONG_ARGUMENTS, "PURGE LOGS BEFORE");
+ my_error(ER_WRONG_ARGUMENTS, MYF(0), "PURGE LOGS BEFORE");
YYABORT;
}
Item *tmp= new Item_func_unix_timestamp($2);
@@ -6282,7 +6365,8 @@ kill:
LEX *lex=Lex;
if ($3->fix_fields(lex->thd, 0, &$3) || $3->check_cols(1))
{
- send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
+ my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY),
+ MYF(0));
YYABORT;
}
lex->sql_command=SQLCOM_KILL;
@@ -6453,7 +6537,7 @@ param_marker:
(uchar *) thd->query));
if (!($$= item) || lex->param_list.push_back(item))
{
- send_error(thd, ER_OUT_OF_RESOURCES);
+ my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
YYABORT;
}
}
@@ -6509,7 +6593,6 @@ NUM_literal:
$$= new Item_real($1.str, $1.length);
if (YYTHD->net.report_error)
{
- send_error(YYTHD, 0, NullS);
YYABORT;
}
}
@@ -6518,7 +6601,6 @@ NUM_literal:
$$ = new Item_float($1.str, $1.length);
if (YYTHD->net.report_error)
{
- send_error(YYTHD, 0, NullS);
YYABORT;
}
}
@@ -6607,16 +6689,14 @@ simple_ident_q:
if (lex->trg_chistics.event == TRG_EVENT_INSERT &&
!new_row)
{
- net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "OLD",
- "on INSERT");
+ my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0), "OLD", "on INSERT");
YYABORT;
}
if (lex->trg_chistics.event == TRG_EVENT_DELETE &&
new_row)
{
- net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "NEW",
- "on DELETE");
+ my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0), "NEW", "on DELETE");
YYABORT;
}
@@ -6633,8 +6713,8 @@ simple_ident_q:
FIXME. Far from perfect solution. See comment for
"SET NEW.field_name:=..." for more info.
*/
- net_printf(YYTHD, ER_BAD_FIELD_ERROR, $3.str,
- new_row ? "NEW": "OLD");
+ my_error(ER_BAD_FIELD_ERROR, MYF(0),
+ $3.str, new_row ? "NEW": "OLD");
YYABORT;
}
@@ -6645,9 +6725,8 @@ simple_ident_q:
SELECT_LEX *sel= lex->current_select;
if (sel->no_table_names_allowed)
{
- my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
- ER(ER_TABLENAME_NOT_ALLOWED_HERE),
- MYF(0), $1.str, thd->where);
+ my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
+ MYF(0), $1.str, thd->where);
}
$$= (sel->parsing_place != IN_HAVING ||
sel->get_in_sum_expr() > 0) ?
@@ -6662,9 +6741,8 @@ simple_ident_q:
SELECT_LEX *sel= lex->current_select;
if (sel->no_table_names_allowed)
{
- my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
- ER(ER_TABLENAME_NOT_ALLOWED_HERE),
- MYF(0), $2.str, thd->where);
+ my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
+ MYF(0), $2.str, thd->where);
}
$$= (sel->parsing_place != IN_HAVING ||
sel->get_in_sum_expr() > 0) ?
@@ -6678,9 +6756,8 @@ simple_ident_q:
SELECT_LEX *sel= lex->current_select;
if (sel->no_table_names_allowed)
{
- my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
- ER(ER_TABLENAME_NOT_ALLOWED_HERE),
- MYF(0), $3.str, thd->where);
+ my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
+ MYF(0), $3.str, thd->where);
}
$$= (sel->parsing_place != IN_HAVING ||
sel->get_in_sum_expr() > 0) ?
@@ -6721,8 +6798,8 @@ IDENT_sys:
$1.length);
if (wlen < $1.length)
{
- net_printf(YYTHD, ER_INVALID_CHARACTER_STRING, cs->csname,
- $1.str + wlen);
+ my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
+ cs->csname, $1.str + wlen);
YYABORT;
}
$$= $1;
@@ -6846,6 +6923,7 @@ keyword:
| COMMIT_SYM {}
| COMPRESSED_SYM {}
| CONCURRENT {}
+ | CONSISTENT_SYM {}
| CONTAINS_SYM {}
| CUBE_SYM {}
| DATA_SYM {}
@@ -6998,6 +7076,7 @@ keyword:
| SHARE_SYM {}
| SHUTDOWN {}
| SLAVE {}
+ | SNAPSHOT_SYM {}
| SOUNDS_SYM {}
| SQL_CACHE_SYM {}
| SQL_BUFFER_RESULT {}
@@ -7103,7 +7182,8 @@ option_value:
*/
if (lex->query_tables)
{
- send_error(YYTHD, ER_SP_SUBSELECT_NYI);
+ my_message(ER_SP_SUBSELECT_NYI, ER(ER_SP_SUBSELECT_NYI),
+ MYF(0));
YYABORT;
}
sp_instr_set_user_var *i=
@@ -7126,7 +7206,8 @@ option_value:
sp_instr_set_trigger_field *i;
if (lex->query_tables)
{
- send_error(YYTHD, ER_SP_SUBSELECT_NYI);
+ my_message(ER_SP_SUBSELECT_NYI, ER(ER_SP_SUBSELECT_NYI),
+ MYF(0));
YYABORT;
}
if ($3)
@@ -7155,7 +7236,7 @@ option_value:
Error message also should be improved.
*/
- net_printf(YYTHD, ER_BAD_FIELD_ERROR, $1.base_name, "NEW");
+ my_error(ER_BAD_FIELD_ERROR, MYF(0), $1.base_name, "NEW");
YYABORT;
}
lex->sphead->add_instr(i);
@@ -7221,7 +7302,8 @@ option_value:
$3= $3 ? $3 : $2;
if (!my_charset_same($2,$3))
{
- net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
+ my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
+ $3->name, $2->csname);
YYABORT;
}
lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
@@ -7287,18 +7369,18 @@ internal_variable_name:
{
if ($1.str[0]=='O' || $1.str[0]=='o')
{
- net_printf(YYTHD, ER_TRG_CANT_CHANGE_ROW, "OLD", "");
+ my_error(ER_TRG_CANT_CHANGE_ROW, MYF(0), "OLD", "");
YYABORT;
}
if (lex->trg_chistics.event == TRG_EVENT_DELETE)
{
- net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "NEW",
- "on DELETE");
+ my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0),
+ "NEW", "on DELETE");
YYABORT;
}
if (lex->trg_chistics.action_time == TRG_ACTION_AFTER)
{
- net_printf(YYTHD, ER_TRG_CANT_CHANGE_ROW, "NEW", "after ");
+ my_error(ER_TRG_CANT_CHANGE_ROW, MYF(0), "NEW", "after ");
YYABORT;
}
/* This special combination will denote field of NEW row */
@@ -7311,7 +7393,7 @@ internal_variable_name:
if (!tmp)
YYABORT;
if (!tmp->is_struct())
- net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str);
+ my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
$$.var= tmp;
$$.base_name= $1;
}
@@ -7322,7 +7404,7 @@ internal_variable_name:
if (!tmp)
YYABORT;
if (!tmp->is_struct())
- net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str);
+ my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
$$.var= tmp;
$$.base_name.str= (char*) "default";
$$.base_name.length= 7;
@@ -7489,7 +7571,7 @@ revoke_command:
grant_privileges ON opt_table FROM user_list
{}
|
- ALL PRIVILEGES ',' GRANT OPTION FROM user_list
+ ALL opt_privileges ',' GRANT OPTION FROM user_list
{
Lex->sql_command = SQLCOM_REVOKE_ALL;
}
@@ -7515,10 +7597,14 @@ grant:
grant_privileges:
grant_privilege_list {}
- | ALL PRIVILEGES { Lex->grant = GLOBAL_ACLS;}
- | ALL { Lex->grant = GLOBAL_ACLS;}
+ | ALL opt_privileges { Lex->grant = GLOBAL_ACLS;}
;
+opt_privileges:
+ /* empty */
+ | PRIVILEGES
+ ;
+
grant_privilege_list:
grant_privilege
| grant_privilege_list ',' grant_privilege;
@@ -7567,7 +7653,7 @@ require_list_element:
LEX *lex=Lex;
if (lex->x509_subject)
{
- net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
+ my_error(ER_DUP_ARGUMENT, MYF(0), "SUBJECT");
YYABORT;
}
lex->x509_subject=$2.str;
@@ -7577,7 +7663,7 @@ require_list_element:
LEX *lex=Lex;
if (lex->x509_issuer)
{
- net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
+ my_error(ER_DUP_ARGUMENT, MYF(0), "ISSUER");
YYABORT;
}
lex->x509_issuer=$2.str;
@@ -7587,7 +7673,7 @@ require_list_element:
LEX *lex=Lex;
if (lex->ssl_cipher)
{
- net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
+ my_error(ER_DUP_ARGUMENT, MYF(0), "CIPHER");
YYABORT;
}
lex->ssl_cipher=$2.str;
@@ -7603,7 +7689,8 @@ opt_table:
lex->grant = DB_ACLS & ~GRANT_ACL;
else if (lex->columns.elements)
{
- send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
+ my_message(ER_ILLEGAL_GRANT_FOR_TABLE,
+ ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0));
YYABORT;
}
}
@@ -7615,7 +7702,8 @@ opt_table:
lex->grant = DB_ACLS & ~GRANT_ACL;
else if (lex->columns.elements)
{
- send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
+ my_message(ER_ILLEGAL_GRANT_FOR_TABLE,
+ ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0));
YYABORT;
}
}
@@ -7627,7 +7715,8 @@ opt_table:
lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
else if (lex->columns.elements)
{
- send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
+ my_message(ER_ILLEGAL_GRANT_FOR_TABLE,
+ ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0));
YYABORT;
}
}
@@ -7767,7 +7856,7 @@ grant_option:
;
begin:
- BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
+ BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN; Lex->start_transaction_opt= 0;} opt_work {}
;
opt_work:
@@ -7812,7 +7901,7 @@ union_list:
if (lex->exchange)
{
/* Only the last SELECT can have INTO...... */
- net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
+ my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
YYABORT;
}
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
diff --git a/sql/table.cc b/sql/table.cc
index 0e8045abacf..6702a9acf0a 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -984,11 +984,11 @@ static void frm_error(int error, TABLE *form, const char *name, myf errortype)
uint length=dirname_part(buff,name);
buff[length-1]=0;
db=buff+dirname_length(buff);
- my_error(ER_NO_SUCH_TABLE,MYF(0),db,form->real_name);
+ my_error(ER_NO_SUCH_TABLE, MYF(0), db, form->real_name);
}
else
- my_error(ER_FILE_NOT_FOUND,errortype,
- fn_format(buff,name,form_dev,reg_ext,0),my_errno);
+ my_error(ER_FILE_NOT_FOUND, errortype,
+ fn_format(buff, name, form_dev, reg_ext, 0), my_errno);
break;
case 2:
{
@@ -996,14 +996,14 @@ static void frm_error(int error, TABLE *form, const char *name, myf errortype)
datext= datext==NullS ? "" : datext;
err_no= (my_errno == ENOENT) ? ER_FILE_NOT_FOUND : (my_errno == EAGAIN) ?
ER_FILE_USED : ER_CANT_OPEN_FILE;
- my_error(err_no,errortype,
- fn_format(buff,form->real_name,form_dev,datext,2),my_errno);
+ my_error(err_no, errortype,
+ fn_format(buff, form->real_name, form_dev, datext, 2), my_errno);
break;
}
default: /* Better wrong error than none */
case 4:
- my_error(ER_NOT_FORM_FILE,errortype,
- fn_format(buff,name,form_dev,reg_ext,0));
+ my_error(ER_NOT_FORM_FILE, errortype,
+ fn_format(buff, name, form_dev, reg_ext, 0));
break;
}
DBUG_VOID_RETURN;
@@ -1520,6 +1520,7 @@ void st_table_list::set_ancestor()
if (ancestor->ancestor)
ancestor->set_ancestor();
table= ancestor->table;
+ schema_table= ancestor->schema_table;
ancestor->table->grant= grant;
}
diff --git a/sql/table.h b/sql/table.h
index f95be1fcccb..db3ce638842 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -204,6 +204,58 @@ struct st_table {
};
+typedef struct st_foreign_key_info
+{
+ LEX_STRING *forein_id;
+ LEX_STRING *referenced_db;
+ LEX_STRING *referenced_table;
+ LEX_STRING *constraint_method;
+ List<LEX_STRING> foreign_fields;
+ List<LEX_STRING> referenced_fields;
+} FOREIGN_KEY_INFO;
+
+
+enum enum_schema_tables
+{
+ SCH_SCHEMATA= 0, SCH_TABLES, SCH_COLUMNS, SCH_CHARSETS, SCH_COLLATIONS,
+ SCH_COLLATION_CHARACTER_SET_APPLICABILITY, SCH_PROCEDURES, SCH_STATISTICS,
+ SCH_VIEWS, SCH_USER_PRIVILEGES, SCH_SCHEMA_PRIVILEGES, SCH_TABLE_PRIVILEGES,
+ SCH_COLUMN_PRIVILEGES, SCH_TABLE_CONSTRAINTS, SCH_KEY_COLUMN_USAGE,
+ SCH_TABLE_NAMES
+};
+
+
+typedef struct st_field_info
+{
+ const char* field_name;
+ uint field_length;
+ enum enum_field_types field_type;
+ int value;
+ bool maybe_null;
+ bool utf8;
+ const char* old_name;
+} ST_FIELD_INFO;
+
+struct st_table_list;
+typedef class Item COND;
+
+typedef struct st_schema_table
+{
+ const char* table_name;
+ ST_FIELD_INFO *fields_info;
+ /* Create information_schema table */
+ TABLE *(*create_table) (THD *thd, struct st_schema_table *schema_table);
+ /* Fill table with data */
+ int (*fill_table) (THD *thd, struct st_table_list *tables, COND *cond);
+ /* Handle fileds for old SHOW */
+ int (*old_format) (THD *thd, struct st_schema_table *schema_table);
+ int (*process_table) (THD *thd, struct st_table_list *tables,
+ TABLE *table, bool res, const char *base_name,
+ const char *file_name);
+ int idx_field1, idx_field2;
+} ST_SCHEMA_TABLE;
+
+
#define JOIN_TYPE_LEFT 1
#define JOIN_TYPE_RIGHT 2
@@ -252,6 +304,8 @@ typedef struct st_table_list
*/
st_table_list *correspondent_table;
st_select_lex_unit *derived; /* SELECT_LEX_UNIT of derived table */
+ ST_SCHEMA_TABLE *schema_table; /* Information_schema table */
+ st_select_lex *schema_select_lex;
/* link to select_lex where this table was used */
st_select_lex *select_lex;
st_lex *view; /* link on VIEW lex for merging */
diff --git a/sql/unireg.cc b/sql/unireg.cc
index decac2a0549..636156940a4 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -383,7 +383,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type,
if (create_fields.elements > MAX_FIELDS)
{
- my_error(ER_TOO_MANY_FIELDS,MYF(0));
+ my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0));
DBUG_RETURN(1);
}
@@ -448,7 +448,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type,
if (info_length+(ulong) create_fields.elements*FCOMP+288+
n_length+int_length+com_length > 65535L || int_count > 255)
{
- my_error(ER_TOO_MANY_FIELDS,MYF(0));
+ my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0));
DBUG_RETURN(1);
}