diff options
author | unknown <monty@mysql.com> | 2004-03-25 22:11:22 +0200 |
---|---|---|
committer | unknown <monty@mysql.com> | 2004-03-25 22:11:22 +0200 |
commit | 054d2de499625fac668cff166af605a8106b8eaf (patch) | |
tree | 36abf1d40f08cd21cd81f6d5966b89ab4e995ac6 /sql | |
parent | d78cb8998133d98b595b791379b9d1424c103962 (diff) | |
download | mariadb-git-054d2de499625fac668cff166af605a8106b8eaf.tar.gz |
Cleanups & safety fixes
include/mysql.h:
cleanup of load data infile patch
libmysql/libmysql.c:
cleanup of load data infile patch
myisam/mi_search.c:
Added missing assert.h
mysql-test/r/func_time.result:
Make test more secure
mysql-test/t/func_time.test:
Make test more secure
sql/item.cc:
restore to use str_value in item::save_in_field
sql/item.h:
Simple cleanup
sql/item_cmpfunc.cc:
Safety fix
sql/item_cmpfunc.h:
Simple optimization
sql/item_func.cc:
Updated comment
sql/sql_base.cc:
Simple optimization
sql/sql_select.cc:
Simple optimization
sql/sql_union.cc:
safey fixes
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item.cc | 14 | ||||
-rw-r--r-- | sql/item.h | 11 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 3 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 4 | ||||
-rw-r--r-- | sql/item_func.cc | 4 | ||||
-rw-r--r-- | sql/sql_base.cc | 6 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 | ||||
-rw-r--r-- | sql/sql_union.cc | 9 |
8 files changed, 38 insertions, 15 deletions
diff --git a/sql/item.cc b/sql/item.cc index e889bbf1930..36b263f62cf 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -820,6 +820,16 @@ String *Item_copy_string::val_str(String *str) return &str_value; } + +int Item_copy_string::save_in_field(Field *field, bool no_conversions) +{ + if (null_value) + return set_field_to_null(field); + field->set_notnull(); + return field->store(str_value.ptr(),str_value.length(), + collation.collation); +} + /* Functions to convert item to field (for send_fields) */ @@ -1284,8 +1294,8 @@ int Item::save_in_field(Field *field, bool no_conversions) String *result; CHARSET_INFO *cs= collation.collation; char buff[MAX_FIELD_WIDTH]; // Alloc buffer for small columns - String loc_value(buff, sizeof(buff), cs); - result=val_str(&loc_value); + str_value.set_quick(buff, sizeof(buff), cs); + result=val_str(&str_value); if (null_value) return set_field_to_null_with_conversions(field, no_conversions); field->set_notnull(); diff --git a/sql/item.h b/sql/item.h index 5f94320b547..dffa93eaac8 100644 --- a/sql/item.h +++ b/sql/item.h @@ -102,7 +102,11 @@ public: enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE }; - String str_value; /* used to store value */ + /* + str_values's main purpose is to be used to cache the value in + save_in_field + */ + String str_value; my_string name; /* Name from select */ Item *next; uint32 max_length; @@ -138,7 +142,7 @@ public: virtual void make_field(Send_field *field); virtual bool fix_fields(THD *, struct st_table_list *, Item **); /* - should be used in case where we are shure that we do not need + should be used in case where we are sure that we do not need complete fix_fields() procedure. */ inline void quick_fix_field() { fixed= 1; } @@ -250,7 +254,7 @@ public: class Item_num: public Item { public: - virtual Item_num* neg()= 0; + virtual Item_num *neg()= 0; }; @@ -813,6 +817,7 @@ public: String *val_str(String*); void make_field(Send_field *field) { item->make_field(field); } void copy(); + int save_in_field(Field *field, bool no_conversions); table_map used_tables() const { return (table_map) 1L; } bool const_item() const { return 0; } bool is_null() { return null_value; } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 8f55467a23e..9175f12a60c 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1920,7 +1920,8 @@ void Item_cond::neg_arguments(THD *thd) Item *new_item= item->neg_transformer(thd); if (!new_item) { - new_item= new Item_func_not(item); + if (!(new_item= new Item_func_not(item))) + return; // Fatal OEM error /* We can use 0 as tables list because Item_func_not do not use it on fix_fields and its arguments are already fixed. diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 95520c0c222..cbd1e9feffa 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -991,13 +991,13 @@ public: /* Some usefull inline functions */ -inline Item *and_conds(Item *a, Item *b, TABLE_LIST *tables) +inline Item *and_conds(THD *thd, Item *a, Item *b, TABLE_LIST *tables) { if (!b) return a; if (!a) return b; Item *cond= new Item_cond_and(a,b); if (cond) - cond->fix_fields(current_thd, tables, &cond); + cond->fix_fields(thd, tables, &cond); return cond; } diff --git a/sql/item_func.cc b/sql/item_func.cc index 5151fb2876d..984dee3ade9 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2783,8 +2783,8 @@ void Item_func_match::init_search(bool no_order) /* Above function used only to get value and do not need fix_fields for it: Item_string - basic constant - fields - fix_fieds already was called for this arguments - Item_func_concat_ws - do not need fix_fields to produce value + fields - fix_fields() was already called for this arguments + Item_func_concat_ws - do not need fix_fields() to produce value */ concat->quick_fix_field(); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 56857aaa632..7a913a0a73d 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2365,7 +2365,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) !(specialflag & SPECIAL_NO_NEW_FUNC))) { table->outer_join= 0; - if (!(*conds= and_conds(*conds, table->on_expr, tables))) + if (!(*conds= and_conds(thd, *conds, table->on_expr, tables))) DBUG_RETURN(1); table->on_expr=0; } @@ -2407,14 +2407,14 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) if (!table->outer_join) // Not left join { - if (!(*conds= and_conds(*conds, cond_and, tables)) || + if (!(*conds= and_conds(thd, *conds, cond_and, tables)) || (*conds && !(*conds)->fixed && (*conds)->fix_fields(thd, tables, conds))) DBUG_RETURN(1); } else { - table->on_expr= and_conds(table->on_expr, cond_and, tables); + table->on_expr= and_conds(thd, table->on_expr, cond_and, tables); if (table->on_expr && !table->on_expr->fixed && table->on_expr->fix_fields(thd, tables, &table->on_expr)) DBUG_RETURN(1); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 94bedd9bfa2..34bfabd845f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3536,7 +3536,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) { /* Join with outer join condition */ COND *orig_cond=sel->cond; - sel->cond=and_conds(sel->cond, tab->on_expr, 0); + sel->cond=and_conds(join->thd, sel->cond, tab->on_expr, 0); if (sel->test_quick_select(join->thd, tab->keys, used_tables & ~ current_map, (join->select_options & diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 3a27e606cff..1f35c6b6f3d 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -150,6 +150,9 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, JOIN *join= new JOIN(thd_arg, sl->item_list, sl->options | thd_arg->options | additional_options, tmp_result); + if (!join) + goto err; + thd_arg->lex->current_select= sl; offset_limit_cnt= sl->offset_limit; select_limit_cnt= sl->select_limit+sl->offset_limit; @@ -178,6 +181,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, Item *item_tmp; while ((item_tmp= it++)) { + /* Error's in 'new' will be detected after loop */ types.push_back(new Item_type_holder(thd_arg, item_tmp)); } @@ -384,7 +388,10 @@ int st_select_lex_unit::exec() allocate JOIN for fake select only once (privent mysql_select automatic allocation) */ - fake_select_lex->join= new JOIN(thd, item_list, thd->options, result); + if (!(fake_select_lex->join= new JOIN(thd, item_list, thd->options, + result))) + DBUG_RETURN(-1); + /* Fake st_select_lex should have item list for correctref_array allocation. |