summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authormonty@mysql.com <>2005-10-08 03:37:23 +0300
committermonty@mysql.com <>2005-10-08 03:37:23 +0300
commit17d7ba931d2293f1db89cbd1107a4bc71bc4fcdf (patch)
treeac2ca2aacd05cc4eb1bec0b1f8c909b9d64fa2e6 /sql
parentdad1e2048d3ac1477557a2645ccd323143601723 (diff)
parentf577ebb88fc4f56f440ee3736b54512d528ca0a9 (diff)
downloadmariadb-git-17d7ba931d2293f1db89cbd1107a4bc71bc4fcdf.tar.gz
Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/home/my/mysql-5.0
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_federated.cc79
-rw-r--r--sql/item.cc46
-rw-r--r--sql/item.h14
-rw-r--r--sql/item_func.cc25
-rw-r--r--sql/log_event.cc5
-rw-r--r--sql/opt_range.cc10
-rw-r--r--sql/sp_head.cc1
-rw-r--r--sql/sql_class.cc14
-rw-r--r--sql/sql_parse.cc30
-rw-r--r--sql/sql_prepare.cc106
-rw-r--r--sql/sql_table.cc18
-rw-r--r--sql/structs.h2
-rw-r--r--sql/table.cc16
-rw-r--r--sql/table.h2
14 files changed, 163 insertions, 205 deletions
diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc
index 2b2be71cf53..20badb05f09 100644
--- a/sql/ha_federated.cc
+++ b/sql/ha_federated.cc
@@ -480,6 +480,7 @@ static int check_foreign_data_source(
String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
MYSQL *mysql;
DBUG_ENTER("ha_federated::check_foreign_data_source");
+
/* Zero the length, otherwise the string will have misc chars */
query.length(0);
@@ -564,6 +565,7 @@ static int parse_url_error(FEDERATED_SHARE *share, TABLE *table, int error_num)
char buf[FEDERATED_QUERY_BUFFER_SIZE];
int buf_len;
DBUG_ENTER("ha_federated parse_url_error");
+
if (share->scheme)
{
DBUG_PRINT("info",
@@ -572,11 +574,9 @@ static int parse_url_error(FEDERATED_SHARE *share, TABLE *table, int error_num)
my_free((gptr) share->scheme, MYF(0));
share->scheme= 0;
}
- buf_len= (table->s->connect_string.length > (FEDERATED_QUERY_BUFFER_SIZE - 1))
- ? FEDERATED_QUERY_BUFFER_SIZE - 1 : table->s->connect_string.length;
-
- strnmov(buf, table->s->connect_string.str, buf_len);
- buf[buf_len]= '\0';
+ buf_len= min(table->s->connect_string.length,
+ FEDERATED_QUERY_BUFFER_SIZE-1);
+ strmake(buf, table->s->connect_string.str, buf_len);
my_error(error_num, MYF(0), buf);
DBUG_RETURN(error_num);
}
@@ -767,12 +767,9 @@ uint ha_federated::convert_row_to_internal_format(byte *record, MYSQL_ROW row)
{
ulong *lengths;
Field **field;
-
DBUG_ENTER("ha_federated::convert_row_to_internal_format");
- // num_fields= mysql_num_fields(stored_result);
lengths= mysql_fetch_lengths(stored_result);
-
memset(record, 0, table->s->null_bytes);
for (field= table->field; *field; field++)
@@ -1127,8 +1124,8 @@ bool ha_federated::create_where_from_key(String *to,
char tmpbuff[FEDERATED_QUERY_BUFFER_SIZE];
String tmp(tmpbuff, sizeof(tmpbuff), system_charset_info);
const key_range *ranges[2]= { start_key, end_key };
-
DBUG_ENTER("ha_federated::create_where_from_key");
+
tmp.length(0);
if (start_key == NULL && end_key == NULL)
DBUG_RETURN(1);
@@ -1334,7 +1331,6 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
query.append(FEDERATED_FROM);
query.append(FEDERATED_BTICK);
-
if (!(share= (FEDERATED_SHARE *)
my_multi_malloc(MYF(MY_WME),
&share, sizeof(*share),
@@ -1389,8 +1385,8 @@ error:
static int free_share(FEDERATED_SHARE *share)
{
DBUG_ENTER("free_share");
- pthread_mutex_lock(&federated_mutex);
+ pthread_mutex_lock(&federated_mutex);
if (!--share->use_count)
{
hash_delete(&federated_open_tables, (byte*) share);
@@ -1581,7 +1577,6 @@ int ha_federated::write_row(byte *buf)
values_string.length(0);
insert_string.length(0);
insert_field_value_string.length(0);
-
DBUG_ENTER("ha_federated::write_row");
DBUG_PRINT("info",
("table charset name %s csname %s",
@@ -1708,7 +1703,6 @@ int ha_federated::optimize(THD* thd, HA_CHECK_OPT* check_opt)
{
char query_buffer[STRING_BUFFER_USUAL_SIZE];
String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
-
DBUG_ENTER("ha_federated::optimize");
query.length(0);
@@ -1732,7 +1726,6 @@ int ha_federated::repair(THD* thd, HA_CHECK_OPT* check_opt)
{
char query_buffer[STRING_BUFFER_USUAL_SIZE];
String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
-
DBUG_ENTER("ha_federated::repair");
query.length(0);
@@ -1778,14 +1771,16 @@ int ha_federated::repair(THD* thd, HA_CHECK_OPT* check_opt)
int ha_federated::update_row(const byte *old_data, byte *new_data)
{
/*
- This used to control how the query was built. If there was a primary key,
- the query would be built such that there was a where clause with only
- that column as the condition. This is flawed, because if we have a multi-part
- primary key, it would only use the first part! We don't need to do this anyway,
- because read_range_first will retrieve the correct record, which is what is used
- to build the WHERE clause. We can however use this to append a LIMIT to the end
- if there is NOT a primary key. Why do this? Because we only are updating one
- record, and LIMIT enforces this.
+ This used to control how the query was built. If there was a
+ primary key, the query would be built such that there was a where
+ clause with only that column as the condition. This is flawed,
+ because if we have a multi-part primary key, it would only use the
+ first part! We don't need to do this anyway, because
+ read_range_first will retrieve the correct record, which is what
+ is used to build the WHERE clause. We can however use this to
+ append a LIMIT to the end if there is NOT a primary key. Why do
+ this? Because we only are updating one record, and LIMIT enforces
+ this.
*/
bool has_a_primary_key= (table->s->primary_key == 0 ? TRUE : FALSE);
/*
@@ -1812,7 +1807,6 @@ int ha_federated::update_row(const byte *old_data, byte *new_data)
String where_string(where_buffer,
sizeof(where_buffer),
&my_charset_bin);
-
DBUG_ENTER("ha_federated::update_row");
/*
set string lengths to 0 to avoid misc chars in string
@@ -2007,12 +2001,10 @@ int ha_federated::index_read_idx(byte *buf, uint index, const byte *key,
sizeof(sql_query_buffer),
&my_charset_bin);
key_range range;
+ DBUG_ENTER("ha_federated::index_read_idx");
index_string.length(0);
sql_query.length(0);
-
- DBUG_ENTER("ha_federated::index_read_idx");
-
statistic_increment(table->in_use->status_var.ha_read_key_count,
&LOCK_status);
@@ -2101,8 +2093,8 @@ int ha_federated::read_range_first(const key_range *start_key,
String sql_query(sql_query_buffer,
sizeof(sql_query_buffer),
&my_charset_bin);
-
DBUG_ENTER("ha_federated::read_range_first");
+
if (start_key == NULL && end_key == NULL)
DBUG_RETURN(0);
@@ -2417,7 +2409,6 @@ void ha_federated::info(uint flag)
MYSQL_RES *result= 0;
MYSQL_ROW row;
String status_query_string(status_buf, sizeof(status_buf), &my_charset_bin);
-
DBUG_ENTER("ha_federated::info");
error_code= ER_QUERY_ON_FOREIGN_DATA_SOURCE;
@@ -2508,10 +2499,10 @@ error:
int ha_federated::delete_all_rows()
{
- DBUG_ENTER("ha_federated::delete_all_rows");
-
char query_buffer[FEDERATED_QUERY_BUFFER_SIZE];
String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
+ DBUG_ENTER("ha_federated::delete_all_rows");
+
query.length(0);
query.set_charset(system_charset_info);
@@ -2606,32 +2597,14 @@ THR_LOCK_DATA **ha_federated::store_lock(THD *thd,
int ha_federated::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info)
{
- int retval= 0;
- /*
- only a temporary share, to test the url
- */
- FEDERATED_SHARE tmp_share;
+ int retval;
+ FEDERATED_SHARE tmp_share; // Only a temporary share, to test the url
DBUG_ENTER("ha_federated::create");
- if ((retval= parse_url(&tmp_share, table_arg, 1)))
- goto error;
+ if (!(retval= parse_url(&tmp_share, table_arg, 1)))
+ retval= check_foreign_data_source(&tmp_share, 1);
- if ((retval= check_foreign_data_source(&tmp_share, 1)))
- goto error;
-
- if (tmp_share.scheme)
- {
- my_free((gptr) tmp_share.scheme, MYF(0));
- tmp_share.scheme= 0;
- }
- DBUG_RETURN(retval);
-
-error:
- if (tmp_share.scheme)
- {
- my_free((gptr) tmp_share.scheme, MYF(0));
- tmp_share.scheme= 0;
- }
+ my_free((gptr) tmp_share.scheme, MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN(retval);
}
diff --git a/sql/item.cc b/sql/item.cc
index 966dbbaec53..98e0320d366 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -817,9 +817,12 @@ String *Item_splocal::val_str(String *sp)
{
DBUG_ASSERT(fixed);
Item *it= this_item();
- String *ret= it->val_str(sp);
+ String *res= it->val_str(sp);
null_value= it->null_value;
+ if (!res)
+ return NULL;
+
/*
This way we mark returned value of val_str as const,
so that various functions (e.g. CONCAT) won't try to
@@ -836,12 +839,11 @@ String *Item_splocal::val_str(String *sp)
Item_param class contain some more details on the topic.
*/
- if (!ret)
- return NULL;
-
- str_value_ptr.set(ret->ptr(), ret->length(),
- ret->charset());
- return &str_value_ptr;
+ if (res != &str_value)
+ str_value.set(res->ptr(), res->length(), res->charset());
+ else
+ res->mark_as_const();
+ return &str_value;
}
@@ -858,17 +860,13 @@ my_decimal *Item_splocal::val_decimal(my_decimal *decimal_value)
bool Item_splocal::is_null()
{
Item *it= this_item();
- bool ret= it->is_null();
- null_value= it->null_value;
- return ret;
+ return it->is_null();
}
Item *
Item_splocal::this_item()
{
- THD *thd= current_thd;
-
return thd->spcont->get_item(m_offset);
}
@@ -882,25 +880,23 @@ Item_splocal::this_item_addr(THD *thd, Item **addr)
Item *
Item_splocal::this_const_item() const
{
- THD *thd= current_thd;
-
return thd->spcont->get_item(m_offset);
}
Item::Type
Item_splocal::type() const
{
- THD *thd= current_thd;
-
- if (thd->spcont)
+ if (thd && thd->spcont)
return thd->spcont->get_item(m_offset)->type();
return NULL_ITEM; // Anything but SUBSELECT_ITEM
}
-bool Item_splocal::fix_fields(THD *, Item **)
+bool Item_splocal::fix_fields(THD *thd_arg, Item **ref)
{
- Item *it= this_item();
+ Item *it;
+ thd= thd_arg; // Must be set before this_item()
+ it= this_item();
DBUG_ASSERT(it->fixed);
max_length= it->max_length;
decimals= it->decimals;
@@ -928,6 +924,7 @@ void Item_splocal::print(String *str)
/*****************************************************************************
Item_name_const methods
*****************************************************************************/
+
double Item_name_const::val_real()
{
DBUG_ASSERT(fixed);
@@ -966,9 +963,7 @@ my_decimal *Item_name_const::val_decimal(my_decimal *decimal_value)
bool Item_name_const::is_null()
{
- bool ret= value_item->is_null();
- null_value= value_item->null_value;
- return ret;
+ return value_item->is_null();
}
Item::Type Item_name_const::type() const
@@ -977,7 +972,7 @@ Item::Type Item_name_const::type() const
}
-bool Item_name_const::fix_fields(THD *thd, Item **)
+bool Item_name_const::fix_fields(THD *thd, Item **ref)
{
char buf[128];
String *item_name;
@@ -2783,7 +2778,7 @@ int Item_copy_string::save_in_field(Field *field, bool no_conversions)
*/
/* ARGSUSED */
-bool Item::fix_fields(THD *thd, Item ** ref)
+bool Item::fix_fields(THD *thd, Item **ref)
{
// We do not check fields which are fixed during construction
@@ -4765,8 +4760,7 @@ String *Item_ref::val_str(String* tmp)
bool Item_ref::is_null()
{
DBUG_ASSERT(fixed);
- (void) (*ref)->val_int_result();
- return (*ref)->null_value;
+ return (*ref)->is_null();
}
diff --git a/sql/item.h b/sql/item.h
index a8f013f60d4..8e6b4e245d2 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -721,13 +721,7 @@ class Item_splocal : public Item
public:
LEX_STRING m_name;
-
- /*
- Buffer, pointing to the string value of the item. We need it to
- protect internal buffer from changes. See comment to analogous
- member in Item_param for more details.
- */
- String str_value_ptr;
+ THD *thd;
/*
Position of this reference to SP variable in the statement (the
@@ -739,10 +733,10 @@ public:
Value of 0 means that this object doesn't corresponding to reference to
SP variable in query text.
*/
- int pos_in_query;
+ uint pos_in_query;
- Item_splocal(LEX_STRING name, uint offset, int pos_in_q=0)
- : m_offset(offset), m_name(name), pos_in_query(pos_in_q)
+ Item_splocal(LEX_STRING name, uint offset, uint pos_in_q=0)
+ : m_offset(offset), m_name(name), thd(0), pos_in_query(pos_in_q)
{
maybe_null= TRUE;
}
diff --git a/sql/item_func.cc b/sql/item_func.cc
index f07460f2a05..ef896ca3cfd 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2015,7 +2015,6 @@ String *Item_func_min_max::val_str(String *str)
{
String *res;
LINT_INIT(res);
- null_value= 0;
for (uint i=0; i < arg_count ; i++)
{
if (i == 0)
@@ -2030,14 +2029,11 @@ String *Item_func_min_max::val_str(String *str)
if ((cmp_sign < 0 ? cmp : -cmp) < 0)
res=res2;
}
- else
- res= 0;
}
if ((null_value= args[i]->null_value))
- break;
+ return 0;
}
- if (res) // If !NULL
- res->set_charset(collation.collation);
+ res->set_charset(collation.collation);
return res;
}
case ROW_RESULT:
@@ -2054,7 +2050,6 @@ double Item_func_min_max::val_real()
{
DBUG_ASSERT(fixed == 1);
double value=0.0;
- null_value= 0;
for (uint i=0; i < arg_count ; i++)
{
if (i == 0)
@@ -2076,7 +2071,6 @@ longlong Item_func_min_max::val_int()
{
DBUG_ASSERT(fixed == 1);
longlong value=0;
- null_value= 0;
for (uint i=0; i < arg_count ; i++)
{
if (i == 0)
@@ -2097,21 +2091,21 @@ longlong Item_func_min_max::val_int()
my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
{
DBUG_ASSERT(fixed == 1);
- my_decimal tmp_buf, *tmp, *res= NULL;
- null_value= 0;
+ my_decimal tmp_buf, *tmp, *res;
+ LINT_INIT(res);
+
for (uint i=0; i < arg_count ; i++)
{
if (i == 0)
res= args[i]->val_decimal(dec);
else
{
- tmp= args[i]->val_decimal(&tmp_buf);
- if (args[i]->null_value)
- res= 0;
- else if ((my_decimal_cmp(tmp, res) * cmp_sign) < 0)
+ tmp= args[i]->val_decimal(&tmp_buf); // Zero if NULL
+ if (tmp && (my_decimal_cmp(tmp, res) * cmp_sign) < 0)
{
if (tmp == &tmp_buf)
{
+ /* Move value out of tmp_buf as this will be reused on next loop */
my_decimal2decimal(tmp, dec);
res= dec;
}
@@ -2120,7 +2114,10 @@ my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
}
}
if ((null_value= args[i]->null_value))
+ {
+ res= 0;
break;
+ }
}
return res;
}
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 5cb4c289a10..55c761d4c6e 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -121,8 +121,9 @@ static char *pretty_print_str(char *packet, char *str, int len)
static inline char* slave_load_file_stem(char*buf, uint file_id,
int event_server_id)
{
- fn_format(buf,"SQL_LOAD-",slave_load_tmpdir, "",
- MY_UNPACK_FILENAME | MY_UNIX_PATH);
+ fn_format(buf,"SQL_LOAD-",slave_load_tmpdir, "", MY_UNPACK_FILENAME);
+ to_unix_path(buf);
+
buf = strend(buf);
buf = int10_to_str(::server_id, buf, 10);
*buf++ = '-';
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index d6b9ec282e0..1a6d97caa6a 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -7040,19 +7040,15 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree)
*/
if (thd->query_id == cur_field->query_id)
{
- bool is_covered= FALSE;
KEY_PART_INFO *key_part= cur_index_info->key_part;
KEY_PART_INFO *key_part_end= key_part + cur_index_info->key_parts;
- for (; key_part != key_part_end ; key_part++)
+ for (;;)
{
if (key_part->field == cur_field)
- {
- is_covered= TRUE;
break;
- }
+ if (++key_part == key_part_end)
+ goto next_index; // Field was not part of key
}
- if (!is_covered)
- goto next_index;
}
}
}
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 671acbc2a0c..0ab81a159be 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -794,6 +794,7 @@ static bool subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str)
splocal < sp_vars_uses.back(); splocal++)
{
Item *val;
+ (*splocal)->thd= thd; // fix_fields() is not yet done
/* append the text between sp ref occurences */
res|= qbuf.append(cur + prev_pos, (*splocal)->pos_in_query - prev_pos);
prev_pos= (*splocal)->pos_in_query + (*splocal)->m_name.length;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index fc7ea6a2794..abb3cf666b0 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -1703,15 +1703,19 @@ Statement_map::Statement_map() :
int Statement_map::insert(Statement *statement)
{
- int rc= my_hash_insert(&st_hash, (byte *) statement);
+ int res= my_hash_insert(&st_hash, (byte *) statement);
+ if (res)
+ return res;
if (statement->name.str)
{
- if ((rc= my_hash_insert(&names_hash, (byte*)statement)))
+ if ((res= my_hash_insert(&names_hash, (byte*)statement)))
+ {
hash_delete(&st_hash, (byte*)statement);
+ return res;
+ }
}
- if (rc == 0)
- last_found_statement= statement;
- return rc;
+ last_found_statement= statement;
+ return res;
}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index b70409704a2..8a6b776e803 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4526,7 +4526,8 @@ end_with_restore_list:
command[thd->lex->create_view_mode].length);
view_store_options(thd, first_table, &buff);
buff.append("VIEW ", 5);
- if (!first_table->current_db_used)
+ /* Test if user supplied a db (ie: we did not use thd->db) */
+ if (first_table->db != thd->db && first_table->db[0])
{
append_identifier(thd, &buff, first_table->db,
first_table->db_length);
@@ -4852,7 +4853,6 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
bool db_is_pattern= test(want_access & GRANT_ACL);
#endif
ulong dummy;
- const char *db_name;
DBUG_ENTER("check_access");
DBUG_PRINT("enter",("db: %s want_access: %lu master_access: %lu",
db ? db : "", want_access, sctx->master_access));
@@ -4870,15 +4870,16 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
DBUG_RETURN(TRUE); /* purecov: tested */
}
- db_name= db ? db : thd->db;
if (schema_db)
{
if (want_access & ~(SELECT_ACL | EXTRA_ACL))
{
if (!no_errors)
+ {
+ const char *db_name= db ? db : thd->db;
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
- sctx->priv_user,
- sctx->priv_host, db_name);
+ sctx->priv_user, sctx->priv_host, db_name);
+ }
DBUG_RETURN(TRUE);
}
else
@@ -6144,14 +6145,12 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
{
ptr->db= thd->db;
ptr->db_length= thd->db_length;
- ptr->current_db_used= 1;
}
else
{
/* The following can't be "" as we may do 'casedn_str()' on it */
ptr->db= empty_c_string;
ptr->db_length= 0;
- ptr->current_db_used= 1;
}
if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
ptr->db= thd->strdup(ptr->db);
@@ -7451,9 +7450,9 @@ Item *negate_expression(THD *thd, Item *expr)
Assign as view definer current user
SYNOPSIS
- default_definer()
- Secytity_context current decurity context
- definer structure where it should be assigned
+ default_view_definer()
+ sctx current security context
+ definer structure where it should be assigned
RETURN
FALSE OK
@@ -7464,15 +7463,14 @@ bool default_view_definer(Security_context *sctx, st_lex_user *definer)
{
definer->user.str= sctx->priv_user;
definer->user.length= strlen(sctx->priv_user);
- if (*sctx->priv_host != 0)
- {
- definer->host.str= sctx->priv_host;
- definer->host.length= strlen(sctx->priv_host);
- }
- else
+
+ if (!*sctx->priv_host)
{
my_error(ER_NO_VIEW_USER, MYF(0));
return TRUE;
}
+
+ definer->host.str= sctx->priv_host;
+ definer->host.length= strlen(sctx->priv_host);
return FALSE;
}
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 2dbcfc9d6c5..aebe7880451 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -101,6 +101,11 @@ public:
class Prepared_statement: public Statement
{
public:
+ enum flag_values
+ {
+ IS_IN_USE= 1
+ };
+
THD *thd;
Select_fetch_protocol_prep result;
Protocol *protocol;
@@ -131,19 +136,8 @@ public:
bool execute(String *expanded_query, bool open_cursor);
/* Destroy this statement */
bool deallocate();
-
- /* Possible values of flags */
-#if defined(_MSC_VER) && _MSC_VER < 1300
- static const int IS_IN_USE;
-#else
- static const int IS_IN_USE= 1;
-#endif
};
-/* VC6 can't handle initializing in declaration */
-#if defined(_MSC_VER) && _MSC_VER < 1300
-const int Prepared_statement::IS_IN_USE= 1;
-#endif
/******************************************************************************
Implementation
@@ -1830,7 +1824,7 @@ static bool init_param_array(Prepared_statement *stmt)
void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length)
{
Prepared_statement *stmt= new Prepared_statement(thd, &thd->protocol_prep);
- bool rc;
+ bool error;
DBUG_ENTER("mysql_stmt_prepare");
DBUG_PRINT("prep_query", ("%s", packet));
@@ -1853,12 +1847,12 @@ void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length)
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);
- rc= stmt->prepare(packet, packet_length);
+ error= stmt->prepare(packet, packet_length);
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),WAIT_PRIOR);
- if (rc)
+ if (error)
{
/* Statement map deletes statement on erase */
thd->stmt_map.erase(stmt);
@@ -1900,7 +1894,7 @@ static const char *get_dynamic_sql_string(LEX *lex, uint *query_len)
CHARSET_INFO *to_cs= thd->variables.collation_connection;
bool needs_conversion;
user_var_entry *entry;
- String *pstr= &str;
+ String *var_value= &str;
uint32 unused, len;
/*
Convert @var contents to string in connection character set. Although
@@ -1914,13 +1908,13 @@ static const char *get_dynamic_sql_string(LEX *lex, uint *query_len)
&& entry->value)
{
my_bool is_var_null;
- pstr= entry->val_str(&is_var_null, &str, NOT_FIXED_DEC);
+ var_value= entry->val_str(&is_var_null, &str, NOT_FIXED_DEC);
/*
NULL value of variable checked early as entry->value so here
we can't get NULL in normal conditions
*/
DBUG_ASSERT(!is_var_null);
- if (!pstr)
+ if (!var_value)
goto end;
}
else
@@ -1932,22 +1926,25 @@ static const char *get_dynamic_sql_string(LEX *lex, uint *query_len)
str.set("NULL", 4, &my_charset_latin1);
}
- needs_conversion= String::needs_conversion(pstr->length(),
- pstr->charset(), to_cs, &unused);
+ needs_conversion= String::needs_conversion(var_value->length(),
+ var_value->charset(), to_cs,
+ &unused);
- len= needs_conversion ? pstr->length() * to_cs->mbmaxlen : pstr->length();
+ len= (needs_conversion ? var_value->length() * to_cs->mbmaxlen :
+ var_value->length());
if (!(query_str= alloc_root(thd->mem_root, len+1)))
goto end;
if (needs_conversion)
{
uint dummy_errors;
- len= copy_and_convert(query_str, len, to_cs, pstr->ptr(), pstr->length(),
- pstr->charset(), &dummy_errors);
+ len= copy_and_convert(query_str, len, to_cs, var_value->ptr(),
+ var_value->length(), var_value->charset(),
+ &dummy_errors);
}
else
- memcpy(query_str, pstr->ptr(), pstr->length());
- query_str[len]= '\0';
+ memcpy(query_str, var_value->ptr(), var_value->length());
+ query_str[len]= '\0'; // Safety (mostly for debug)
*query_len= len;
}
else
@@ -1997,10 +1994,9 @@ void mysql_sql_stmt_prepare(THD *thd)
Prepared_statement *stmt;
const char *query;
uint query_len;
-
DBUG_ENTER("mysql_sql_stmt_prepare");
-
DBUG_ASSERT(thd->protocol == &thd->protocol_simple);
+
if ((stmt= (Prepared_statement*) thd->stmt_map.find_by_name(name)))
{
/*
@@ -2182,7 +2178,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
uchar *packet_end= (uchar *) packet + packet_length - 1;
#endif
Prepared_statement *stmt;
- bool rc;
+ bool error;
DBUG_ENTER("mysql_stmt_execute");
packet+= 9; /* stmt_id + 5 bytes of flags */
@@ -2217,12 +2213,11 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
#endif
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);
- rc= stmt->execute(&expanded_query,
- test(flags & (ulong) CURSOR_TYPE_READ_ONLY));
+ error= stmt->execute(&expanded_query,
+ test(flags & (ulong) CURSOR_TYPE_READ_ONLY));
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(), WAIT_PRIOR);
-
- if (rc == 0)
+ if (error == 0)
mysql_log.write(thd, COM_STMT_EXECUTE, "[%lu] %s", stmt->id, thd->query);
DBUG_VOID_RETURN;
@@ -2261,9 +2256,7 @@ void mysql_sql_stmt_execute(THD *thd)
LEX_STRING *name= &lex->prepared_stmt_name;
/* Query text for binary, general or slow log, if any of them is open */
String expanded_query;
-
DBUG_ENTER("mysql_sql_stmt_execute");
-
DBUG_PRINT("info", ("EXECUTE: %.*s\n", name->length, name->str));
if (!(stmt= (Prepared_statement*) thd->stmt_map.find_by_name(name)))
@@ -2408,7 +2401,6 @@ void mysql_stmt_close(THD *thd, char *packet)
/* There is always space for 4 bytes in packet buffer */
ulong stmt_id= uint4korr(packet);
Prepared_statement *stmt;
-
DBUG_ENTER("mysql_stmt_close");
if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close")))
@@ -2418,7 +2410,7 @@ void mysql_stmt_close(THD *thd, char *packet)
The only way currently a statement can be deallocated when it's
in use is from within Dynamic SQL.
*/
- DBUG_ASSERT(! (stmt->flags & Prepared_statement::IS_IN_USE));
+ DBUG_ASSERT(! (stmt->flags & (uint) Prepared_statement::IS_IN_USE));
(void) stmt->deallocate();
DBUG_VOID_RETURN;
@@ -2462,7 +2454,7 @@ void mysql_sql_stmt_close(THD *thd)
mysql_stmt_get_longdata()
thd Thread handle
packet String to append
- packet_length Length of string
+ packet_length Length of string (including end \0)
DESCRIPTION
Get a part of a long data. To make the protocol efficient, we are
@@ -2479,13 +2471,12 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
Prepared_statement *stmt;
Item_param *param;
char *packet_end= packet + packet_length - 1;
-
DBUG_ENTER("mysql_stmt_get_longdata");
statistic_increment(thd->status_var.com_stmt_send_long_data, &LOCK_status);
#ifndef EMBEDDED_LIBRARY
/* Minimal size of long data packet is 6 bytes */
- if ((ulong) (packet_end - packet) < MYSQL_LONG_DATA_HEADER)
+ if (packet_length <= MYSQL_LONG_DATA_HEADER)
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_send_long_data");
DBUG_VOID_RETURN;
@@ -2592,7 +2583,7 @@ Prepared_statement::Prepared_statement(THD *thd_arg, Protocol *protocol_arg)
param_array(0),
param_count(0),
last_errno(0),
- flags(IS_IN_USE)
+ flags((uint) IS_IN_USE)
{
*last_error= '\0';
}
@@ -2709,7 +2700,7 @@ bool Prepared_statement::set_name(LEX_STRING *name_arg)
bool Prepared_statement::prepare(const char *packet, uint packet_len)
{
- bool rc;
+ bool error;
Statement stmt_backup;
Query_arena *old_stmt_arena;
DBUG_ENTER("Prepared_statement::prepare");
@@ -2740,7 +2731,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
lex->safe_to_cache_query= FALSE;
lex->stmt_prepare_mode= TRUE;
- rc= yyparse((void *)thd) || thd->is_fatal_error ||
+ error= yyparse((void *)thd) || thd->is_fatal_error ||
thd->net.report_error || init_param_array(this);
/*
While doing context analysis of the query (in check_prepared_statement)
@@ -2764,10 +2755,10 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
*/
DBUG_ASSERT(thd->free_list == NULL);
- if (rc == 0)
- rc= check_prepared_statement(this, name.str != 0);
+ if (error == 0)
+ error= check_prepared_statement(this, name.str != 0);
- if (rc && lex->sphead)
+ if (error && lex->sphead)
{
delete lex->sphead;
lex->sphead= NULL;
@@ -2777,14 +2768,14 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
thd->restore_backup_statement(this, &stmt_backup);
thd->stmt_arena= old_stmt_arena;
- if (rc == 0)
+ if (error == 0)
{
setup_set_params();
init_stmt_after_parse(lex);
state= Query_arena::PREPARED;
- flags&= ~IS_IN_USE;
+ flags&= ~ (uint) IS_IN_USE;
}
- DBUG_RETURN(rc);
+ DBUG_RETURN(error);
}
/*
@@ -2806,6 +2797,10 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
Preconditions, postconditions.
------------------------------
See the comment for Prepared_statement::prepare().
+
+ RETURN
+ FALSE ok
+ TRUE Error
*/
bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
@@ -2813,7 +2808,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
Statement stmt_backup;
Query_arena *old_stmt_arena;
Item *old_free_list;
- bool rc= TRUE;
+ bool error= TRUE;
statistic_increment(thd->status_var.com_stmt_execute, &LOCK_status);
@@ -2823,7 +2818,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
my_message(last_errno, last_error, MYF(0));
return TRUE;
}
- if (flags & IS_IN_USE)
+ if (flags & (uint) IS_IN_USE)
{
my_error(ER_PS_NO_RECURSION, MYF(0));
return TRUE;
@@ -2885,9 +2880,10 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
reinit_stmt_before_use(thd, lex);
thd->protocol= protocol; /* activate stmt protocol */
- rc= open_cursor ? mysql_open_cursor(thd, (uint) ALWAYS_MATERIALIZED_CURSOR,
- &result, &cursor) :
- mysql_execute_command(thd);
+ error= (open_cursor ?
+ mysql_open_cursor(thd, (uint) ALWAYS_MATERIALIZED_CURSOR,
+ &result, &cursor) :
+ mysql_execute_command(thd));
thd->protocol= &thd->protocol_simple; /* use normal protocol */
/* Assert that if an error, no cursor is open */
@@ -2906,8 +2902,8 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
state= Query_arena::EXECUTED;
error:
- flags&= ~IS_IN_USE;
- return rc;
+ flags&= ~ (uint) IS_IN_USE;
+ return error;
}
@@ -2917,7 +2913,7 @@ bool Prepared_statement::deallocate()
{
/* We account deallocate in the same manner as mysql_stmt_close */
statistic_increment(thd->status_var.com_stmt_close, &LOCK_status);
- if (flags & IS_IN_USE)
+ if (flags & (uint) IS_IN_USE)
{
my_error(ER_PS_NO_RECURSION, MYF(0));
return TRUE;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 0bc1537235b..8fb39ea3098 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1571,7 +1571,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
DBUG_RETURN(TRUE);
}
if (wait_if_global_read_lock(thd, 0, 1))
- DBUG_RETURN(error);
+ DBUG_RETURN(TRUE);
VOID(pthread_mutex_lock(&LOCK_open));
if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{
@@ -1636,20 +1636,20 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
mysql_bin_log.write(&qinfo);
}
error= FALSE;
- goto end;
-
-warn:
- error= 0;
- push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
- ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
- alias);
- create_info->table_existed= 1; // Mark that table existed
end:
VOID(pthread_mutex_unlock(&LOCK_open));
start_waiting_global_read_lock(thd);
thd->proc_info="After create";
DBUG_RETURN(error);
+
+warn:
+ error= FALSE;
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
+ alias);
+ create_info->table_existed= 1; // Mark that table existed
+ goto end;
}
/*
diff --git a/sql/structs.h b/sql/structs.h
index e490a2de60c..21aaf584925 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -20,7 +20,7 @@
struct st_table;
class Field;
-#define STRING_WITH_LEN(X) X, (sizeof(X)-1)
+#define STRING_WITH_LEN(X) ((char*) X), (sizeof(X)-1)
typedef struct st_lex_string
{
diff --git a/sql/table.cc b/sql/table.cc
index 0b3423d0750..44c747930c3 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -457,9 +457,11 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
{
outparam->null_flags=null_pos=(uchar*) record+1;
null_bit_pos= (db_create_options & HA_OPTION_PACK_RECORD) ? 0 : 1;
- /* null_bytes below is only correct under the condition that
- there are no bit fields. Correct values is set below after the
- table struct is initialized */
+ /*
+ null_bytes below is only correct under the condition that
+ there are no bit fields. Correct values is set below after the
+ table struct is initialized
+ */
share->null_bytes= (share->null_fields + null_bit_pos + 7) / 8;
}
else
@@ -872,8 +874,12 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
}
}
- /* the correct null_bytes can now be set, since bitfields have been taken into account */
- share->null_bytes= null_pos - (uchar*) outparam->null_flags + (null_bit_pos + 7) / 8;
+ /*
+ the correct null_bytes can now be set, since bitfields have been taken
+ into account
+ */
+ share->null_bytes= (null_pos - (uchar*) outparam->null_flags +
+ (null_bit_pos + 7) / 8);
share->last_null_bit_pos= null_bit_pos;
/* The table struct is now initialized; Open the table */
diff --git a/sql/table.h b/sql/table.h
index 44fe69e9397..e76d005f494 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -585,8 +585,6 @@ typedef struct st_table_list
bool compact_view_format; /* Use compact format for SHOW CREATE VIEW */
/* view where processed */
bool where_processed;
- /* db part was not defined in table definition */
- bool current_db_used;
/* FRMTYPE_ERROR if any type is acceptable */
enum frm_type_enum required_type;
char timestamp_buffer[20]; /* buffer for timestamp (19+1) */