2000-07-31 21:29:14 +02:00
|
|
|
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
2001-12-06 14:10:51 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2001-12-06 14:10:51 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2001-12-06 14:10:51 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma implementation // gcc: Class implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#include <m_ctype.h>
|
|
|
|
#include "my_dir.h"
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01:00
|
|
|
#include "sp_rcontext.h"
|
2004-07-16 01:15:55 +03:00
|
|
|
#include "sql_acl.h"
|
2004-09-07 16:29:46 +04:00
|
|
|
#include "sp_head.h"
|
|
|
|
#include "sql_trigger.h"
|
2004-10-28 17:31:26 +03:00
|
|
|
#include "sql_select.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-07-25 01:02:42 +03:00
|
|
|
static void mark_as_dependent(THD *thd,
|
|
|
|
SELECT_LEX *last, SELECT_LEX *current,
|
2003-06-20 10:15:58 +03:00
|
|
|
Item_ident *item);
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
const String my_null_string("NULL", 4, default_charset_info);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
** Item functions
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* Init all special items */
|
|
|
|
|
|
|
|
void item_init(void)
|
|
|
|
{
|
|
|
|
item_user_lock_init();
|
|
|
|
}
|
|
|
|
|
2002-11-21 11:01:33 +02:00
|
|
|
Item::Item():
|
2003-09-13 17:47:59 +03:00
|
|
|
name_length(0), fixed(0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-01-30 18:07:39 +02:00
|
|
|
marker= 0;
|
2002-10-25 13:58:32 +05:00
|
|
|
maybe_null=null_value=with_sum_func=unsigned_flag=0;
|
2003-08-05 12:52:37 +05:00
|
|
|
collation.set(default_charset(), DERIVATION_COERCIBLE);
|
2003-01-30 18:07:39 +02:00
|
|
|
name= 0;
|
|
|
|
decimals= 0; max_length= 0;
|
2003-11-03 14:01:59 +02:00
|
|
|
|
|
|
|
/* Put item in free list so that we can free all items at end */
|
|
|
|
THD *thd= current_thd;
|
|
|
|
next= thd->free_list;
|
2003-01-30 18:07:39 +02:00
|
|
|
thd->free_list= this;
|
2003-07-02 14:45:35 +03:00
|
|
|
/*
|
2003-08-19 16:00:12 +03:00
|
|
|
Item constructor can be called during execution other then SQL_COM
|
2003-12-19 20:52:13 +03:00
|
|
|
command => we should check thd->lex->current_select on zero (thd->lex
|
2003-07-02 15:03:49 +03:00
|
|
|
can be uninitialised)
|
2003-07-02 14:45:35 +03:00
|
|
|
*/
|
2003-08-26 17:41:40 +02:00
|
|
|
if (thd->lex->current_select)
|
2003-07-29 13:00:32 +03:00
|
|
|
{
|
2004-08-13 10:01:30 +03:00
|
|
|
enum_parsing_place place=
|
2003-08-26 11:51:09 +02:00
|
|
|
thd->lex->current_select->parsing_place;
|
2004-08-13 10:01:30 +03:00
|
|
|
if (place == SELECT_LIST ||
|
|
|
|
place == IN_HAVING)
|
2003-08-26 11:51:09 +02:00
|
|
|
thd->lex->current_select->select_n_having_items++;
|
2003-07-29 13:00:32 +03:00
|
|
|
}
|
2002-11-14 00:26:18 +02:00
|
|
|
}
|
|
|
|
|
2003-01-30 18:07:39 +02:00
|
|
|
/*
|
|
|
|
Constructor used by Item_field, Item_ref & agregate (sum) functions.
|
|
|
|
Used for duplicating lists in processing queries with temporary
|
|
|
|
tables
|
|
|
|
*/
|
2004-01-19 19:53:25 +04:00
|
|
|
Item::Item(THD *thd, Item *item):
|
|
|
|
str_value(item->str_value),
|
|
|
|
name(item->name),
|
|
|
|
max_length(item->max_length),
|
|
|
|
marker(item->marker),
|
|
|
|
decimals(item->decimals),
|
|
|
|
maybe_null(item->maybe_null),
|
|
|
|
null_value(item->null_value),
|
|
|
|
unsigned_flag(item->unsigned_flag),
|
|
|
|
with_sum_func(item->with_sum_func),
|
|
|
|
fixed(item->fixed),
|
|
|
|
collation(item->collation)
|
2003-01-25 02:25:52 +02:00
|
|
|
{
|
2003-11-03 14:01:59 +02:00
|
|
|
next= thd->free_list; // Put in free list
|
2003-01-30 18:07:39 +02:00
|
|
|
thd->free_list= this;
|
2003-01-25 02:25:52 +02:00
|
|
|
}
|
|
|
|
|
2003-10-16 15:54:47 +03:00
|
|
|
|
|
|
|
void Item::print_item_w_name(String *str)
|
|
|
|
{
|
|
|
|
print(str);
|
|
|
|
if (name)
|
|
|
|
{
|
2004-07-20 18:51:02 +03:00
|
|
|
THD *thd= current_thd;
|
|
|
|
str->append(" AS ", 4);
|
|
|
|
append_identifier(thd, str, name, strlen(name));
|
2003-10-16 15:54:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-09 06:59:26 +03:00
|
|
|
void Item::cleanup()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item::cleanup");
|
|
|
|
DBUG_PRINT("info", ("Item: 0x%lx", this));
|
|
|
|
DBUG_PRINT("info", ("Type: %d", (int)type()));
|
|
|
|
fixed=0;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2003-12-17 17:35:34 +02:00
|
|
|
Item_ident::Item_ident(const char *db_name_par,const char *table_name_par,
|
|
|
|
const char *field_name_par)
|
2004-04-01 23:27:22 +03:00
|
|
|
:orig_db_name(db_name_par), orig_table_name(table_name_par),
|
2004-03-31 21:25:55 +04:00
|
|
|
orig_field_name(field_name_par), changed_during_fix_field(0),
|
|
|
|
db_name(db_name_par), table_name(table_name_par),
|
|
|
|
field_name(field_name_par), cached_field_index(NO_CACHED_FIELD_INDEX),
|
|
|
|
cached_table(0), depended_from(0)
|
2003-12-17 17:35:34 +02:00
|
|
|
{
|
|
|
|
name = (char*) field_name_par;
|
|
|
|
}
|
|
|
|
|
2003-01-30 18:07:39 +02:00
|
|
|
// Constructor used by Item_field & Item_ref (see Item comment)
|
2004-03-17 14:26:26 +02:00
|
|
|
Item_ident::Item_ident(THD *thd, Item_ident *item)
|
|
|
|
:Item(thd, item),
|
2004-03-31 21:25:55 +04:00
|
|
|
orig_db_name(item->orig_db_name),
|
|
|
|
orig_table_name(item->orig_table_name),
|
|
|
|
orig_field_name(item->orig_field_name),
|
2004-03-17 14:26:26 +02:00
|
|
|
changed_during_fix_field(0),
|
|
|
|
db_name(item->db_name),
|
|
|
|
table_name(item->table_name),
|
|
|
|
field_name(item->field_name),
|
2004-03-28 04:11:54 +04:00
|
|
|
cached_field_index(item->cached_field_index),
|
2004-03-31 21:25:55 +04:00
|
|
|
cached_table(item->cached_table),
|
2004-03-17 14:26:26 +02:00
|
|
|
depended_from(item->depended_from)
|
2003-01-25 02:25:52 +02:00
|
|
|
{}
|
2002-12-06 21:55:53 +02:00
|
|
|
|
2004-03-17 14:26:26 +02:00
|
|
|
void Item_ident::cleanup()
|
|
|
|
{
|
2004-04-01 23:27:22 +03:00
|
|
|
DBUG_ENTER("Item_ident::cleanup");
|
|
|
|
DBUG_PRINT("enter", ("b:%s(%s), t:%s(%s), f:%s(%s)",
|
|
|
|
db_name, orig_db_name,
|
|
|
|
table_name, orig_table_name,
|
|
|
|
field_name, orig_field_name));
|
2004-03-17 14:26:26 +02:00
|
|
|
Item::cleanup();
|
|
|
|
if (changed_during_fix_field)
|
|
|
|
{
|
|
|
|
*changed_during_fix_field= this;
|
|
|
|
changed_during_fix_field= 0;
|
|
|
|
}
|
2004-03-31 21:25:55 +04:00
|
|
|
db_name= orig_db_name;
|
|
|
|
table_name= orig_table_name;
|
|
|
|
field_name= orig_field_name;
|
2004-04-01 23:27:22 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2004-03-17 14:26:26 +02:00
|
|
|
}
|
|
|
|
|
2003-07-02 13:12:18 +03:00
|
|
|
bool Item_ident::remove_dependence_processor(byte * arg)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_ident::remove_dependence_processor");
|
|
|
|
if (depended_from == (st_select_lex *) arg)
|
|
|
|
depended_from= 0;
|
2003-08-23 13:29:38 +03:00
|
|
|
DBUG_RETURN(0);
|
2003-07-02 13:12:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-27 16:37:13 +03:00
|
|
|
/*
|
|
|
|
Store the pointer to this item field into a list if not already there.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Item_field::collect_item_field_processor()
|
|
|
|
arg pointer to a List<Item_field>
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
The method is used by Item::walk to collect all unique Item_field objects
|
|
|
|
from a tree of Items into a set of items represented as a list.
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
Item_cond::walk() and Item_func::walk() stop the evaluation of the
|
|
|
|
processor function for its arguments once the processor returns
|
|
|
|
true.Therefore in order to force this method being called for all item
|
|
|
|
arguments in a condition the method must return false.
|
|
|
|
|
|
|
|
RETURN
|
2004-10-11 08:28:30 +03:00
|
|
|
false to force the evaluation of collect_item_field_processor
|
|
|
|
for the subsequent items.
|
2004-08-27 16:37:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_field::collect_item_field_processor(byte *arg)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_field::collect_item_field_processor");
|
|
|
|
DBUG_PRINT("info", ("%s", field->field_name ? field->field_name : "noname"));
|
|
|
|
List<Item_field> *item_list= (List<Item_field>*) arg;
|
|
|
|
List_iterator<Item_field> item_list_it(*item_list);
|
|
|
|
Item_field *curr_item;
|
|
|
|
while ((curr_item= item_list_it++))
|
|
|
|
{
|
|
|
|
if (curr_item->eq(this, 1))
|
|
|
|
DBUG_RETURN(false); /* Already in the set. */
|
|
|
|
}
|
|
|
|
item_list->push_back(this);
|
|
|
|
DBUG_RETURN(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-15 20:32:09 +02:00
|
|
|
bool Item::check_cols(uint c)
|
|
|
|
{
|
|
|
|
if (c != 1)
|
|
|
|
{
|
2003-10-06 22:35:05 +03:00
|
|
|
my_error(ER_OPERAND_COLUMNS, MYF(0), c);
|
2002-11-15 20:32:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-21 21:39:58 +03:00
|
|
|
|
|
|
|
void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if (!length)
|
|
|
|
{
|
2003-05-21 21:39:58 +03:00
|
|
|
/* Empty string, used by AS or internal function like last_insert_id() */
|
|
|
|
name= (char*) str;
|
2003-09-13 17:47:59 +03:00
|
|
|
name_length= 0;
|
2003-05-21 21:39:58 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-08-13 11:13:56 +05:00
|
|
|
if (cs->ctype)
|
|
|
|
{
|
2004-09-06 15:14:10 +03:00
|
|
|
/*
|
|
|
|
This will probably need a better implementation in the future:
|
|
|
|
a function in CHARSET_INFO structure.
|
|
|
|
*/
|
2004-08-13 11:13:56 +05:00
|
|
|
while (length && !my_isgraph(cs,*str))
|
|
|
|
{ // Fix problem with yacc
|
|
|
|
length--;
|
|
|
|
str++;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-05-21 21:39:58 +03:00
|
|
|
if (!my_charset_same(cs, system_charset_info))
|
|
|
|
{
|
|
|
|
uint32 res_length;
|
2003-09-13 17:47:59 +03:00
|
|
|
name= sql_strmake_with_convert(str, name_length= length, cs,
|
2003-05-21 21:39:58 +03:00
|
|
|
MAX_ALIAS_NAME, system_charset_info,
|
|
|
|
&res_length);
|
|
|
|
}
|
|
|
|
else
|
2003-09-13 17:47:59 +03:00
|
|
|
name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-05-21 21:39:58 +03:00
|
|
|
|
2002-03-22 14:03:42 +02:00
|
|
|
/*
|
2003-06-04 18:28:51 +03:00
|
|
|
This function is called when:
|
|
|
|
- Comparing items in the WHERE clause (when doing where optimization)
|
|
|
|
- When trying to find an ORDER BY/GROUP BY item in the SELECT part
|
2002-03-22 14:03:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item::eq(const Item *item, bool binary_cmp) const
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
return type() == item->type() && name && item->name &&
|
2002-03-12 21:37:58 +04:00
|
|
|
!my_strcasecmp(system_charset_info,name,item->name);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-02-16 10:03:25 +02:00
|
|
|
|
2002-03-22 14:03:42 +02:00
|
|
|
bool Item_string::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
|
|
|
if (type() == item->type())
|
|
|
|
{
|
|
|
|
if (binary_cmp)
|
2004-02-16 10:03:25 +02:00
|
|
|
return !stringcmp(&str_value, &item->str_value);
|
2003-08-05 12:52:37 +05:00
|
|
|
return !sortcmp(&str_value, &item->str_value, collation.collation);
|
2002-03-22 14:03:42 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*
|
|
|
|
Get the value of the function as a TIME structure.
|
|
|
|
As a extra convenience the time structure is reset on error!
|
|
|
|
*/
|
|
|
|
|
2003-11-03 14:01:59 +02:00
|
|
|
bool Item::get_date(TIME *ltime,uint fuzzydate)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
char buff[40];
|
2003-01-29 17:31:20 +04:00
|
|
|
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(res=val_str(&tmp)) ||
|
2004-06-24 19:08:36 +04:00
|
|
|
str_to_datetime_with_warn(res->ptr(), res->length(),
|
|
|
|
ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get time of first argument.
|
|
|
|
As a extra convenience the time structure is reset on error!
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item::get_time(TIME *ltime)
|
|
|
|
{
|
|
|
|
char buff[40];
|
2003-01-29 17:31:20 +04:00
|
|
|
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(res=val_str(&tmp)) ||
|
2004-06-18 10:11:31 +04:00
|
|
|
str_to_time_with_warn(res->ptr(), res->length(), ltime))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-07 12:09:10 +04:00
|
|
|
CHARSET_INFO *Item::default_charset()
|
2002-11-06 15:49:53 +04:00
|
|
|
{
|
2003-04-23 18:19:22 +05:00
|
|
|
return current_thd->variables.collation_connection;
|
2002-11-06 15:49:53 +04:00
|
|
|
}
|
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01:00
|
|
|
|
2004-09-17 03:08:23 +03:00
|
|
|
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
THD *thd= field->table->in_use;
|
|
|
|
enum_check_fields tmp= thd->count_cuted_fields;
|
|
|
|
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
|
|
|
res= save_in_field(field, no_conversions);
|
|
|
|
thd->count_cuted_fields= tmp;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01:00
|
|
|
Item *
|
|
|
|
Item_splocal::this_item()
|
|
|
|
{
|
|
|
|
THD *thd= current_thd;
|
|
|
|
|
|
|
|
return thd->spcont->get_item(m_offset);
|
2002-11-06 15:49:53 +04:00
|
|
|
}
|
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01:00
|
|
|
Item *
|
|
|
|
Item_splocal::this_const_item() const
|
|
|
|
{
|
|
|
|
THD *thd= current_thd;
|
|
|
|
|
|
|
|
return thd->spcont->get_item(m_offset);
|
|
|
|
}
|
|
|
|
|
2003-12-04 15:17:55 +01:00
|
|
|
Item::Type
|
|
|
|
Item_splocal::type() const
|
|
|
|
{
|
|
|
|
THD *thd= current_thd;
|
|
|
|
|
|
|
|
if (thd->spcont)
|
|
|
|
return thd->spcont->get_item(m_offset)->type();
|
|
|
|
return NULL_ITEM; // Anything but SUBSELECT_ITEM
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-01 13:56:33 +05:00
|
|
|
bool DTCollation::aggregate(DTCollation &dt, bool superset_conversion)
|
2003-03-19 15:55:17 +04:00
|
|
|
{
|
2004-09-01 13:56:33 +05:00
|
|
|
nagg++;
|
2003-06-24 17:12:07 +05:00
|
|
|
if (!my_charset_same(collation, dt.collation))
|
2003-03-19 15:55:17 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
/*
|
|
|
|
We do allow to use binary strings (like BLOBS)
|
|
|
|
together with character strings.
|
2003-06-27 16:09:53 +05:00
|
|
|
Binaries have more precedance than a character
|
|
|
|
string of the same derivation.
|
2003-06-24 17:12:07 +05:00
|
|
|
*/
|
2003-06-27 16:08:52 +05:00
|
|
|
if (collation == &my_charset_bin)
|
2003-06-24 17:12:07 +05:00
|
|
|
{
|
2003-06-27 16:08:52 +05:00
|
|
|
if (derivation <= dt.derivation)
|
|
|
|
; // Do nothing
|
|
|
|
else
|
2004-09-01 13:56:33 +05:00
|
|
|
{
|
|
|
|
set(dt);
|
|
|
|
strong= nagg;
|
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
}
|
2003-06-27 16:08:52 +05:00
|
|
|
else if (dt.collation == &my_charset_bin)
|
2003-06-24 17:12:07 +05:00
|
|
|
{
|
2003-06-27 16:08:52 +05:00
|
|
|
if (dt.derivation <= derivation)
|
2004-09-01 13:56:33 +05:00
|
|
|
{
|
2003-06-27 16:08:52 +05:00
|
|
|
set(dt);
|
2004-09-01 13:56:33 +05:00
|
|
|
strong= nagg;
|
|
|
|
}
|
2003-06-27 16:08:52 +05:00
|
|
|
else
|
|
|
|
; // Do nothing
|
2003-06-24 17:12:07 +05:00
|
|
|
}
|
2004-09-01 13:56:33 +05:00
|
|
|
else if (superset_conversion)
|
|
|
|
{
|
|
|
|
if (derivation < dt.derivation &&
|
|
|
|
collation->state & MY_CS_UNICODE)
|
|
|
|
; // Do nothing
|
|
|
|
else if (dt.derivation < derivation &&
|
|
|
|
dt.collation->state & MY_CS_UNICODE)
|
|
|
|
{
|
|
|
|
set(dt);
|
|
|
|
strong= nagg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Cannot convert to superset
|
|
|
|
set(0, DERIVATION_NONE);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
set(0, DERIVATION_NONE);
|
|
|
|
return 1;
|
|
|
|
}
|
2003-03-19 15:55:17 +04:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
else if (derivation < dt.derivation)
|
2003-03-19 15:55:17 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
// Do nothing
|
2003-03-19 15:55:17 +04:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
else if (dt.derivation < derivation)
|
2003-03-19 15:55:17 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
set(dt);
|
2004-09-01 13:56:33 +05:00
|
|
|
strong= nagg;
|
2003-03-19 15:55:17 +04:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (collation == dt.collation)
|
2003-03-19 17:24:46 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (derivation == DERIVATION_EXPLICIT)
|
2003-03-21 11:21:01 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
set(0, DERIVATION_NONE);
|
|
|
|
return 1;
|
2003-03-21 11:21:01 +04:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
CHARSET_INFO *bin= get_charset_by_csname(collation->csname,
|
|
|
|
MY_CS_BINSORT,MYF(0));
|
|
|
|
set(bin, DERIVATION_NONE);
|
2003-03-19 17:24:46 +04:00
|
|
|
}
|
2003-03-19 15:55:17 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-03-20 13:36:26 +02:00
|
|
|
Item_field::Item_field(Field *f)
|
2004-07-16 01:15:55 +03:00
|
|
|
:Item_ident(NullS, f->table_name, f->field_name),
|
2004-10-19 14:12:55 -07:00
|
|
|
item_equal(0), no_const_subst(0),
|
2004-07-16 01:15:55 +03:00
|
|
|
have_privileges(0), any_privileges(0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
set_field(f);
|
2003-08-05 12:52:37 +05:00
|
|
|
collation.set(DERIVATION_IMPLICIT);
|
2004-03-20 13:36:26 +02:00
|
|
|
fixed= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-03-31 21:25:55 +04:00
|
|
|
Item_field::Item_field(THD *thd, Field *f)
|
|
|
|
:Item_ident(NullS, thd->strdup(f->table_name),
|
2004-07-16 01:15:55 +03:00
|
|
|
thd->strdup(f->field_name)),
|
2004-10-19 14:12:55 -07:00
|
|
|
item_equal(0), no_const_subst(0),
|
2004-07-16 01:15:55 +03:00
|
|
|
have_privileges(0), any_privileges(0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
set_field(f);
|
2003-08-05 12:52:37 +05:00
|
|
|
collation.set(DERIVATION_IMPLICIT);
|
2004-03-31 21:25:55 +04:00
|
|
|
fixed= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-01-30 18:07:39 +02:00
|
|
|
// Constructor need to process subselect with temporary tables (see Item)
|
2004-01-19 19:53:25 +04:00
|
|
|
Item_field::Item_field(THD *thd, Item_field *item)
|
2003-10-19 14:25:33 +03:00
|
|
|
:Item_ident(thd, item),
|
2004-01-19 19:53:25 +04:00
|
|
|
field(item->field),
|
2004-07-16 01:15:55 +03:00
|
|
|
result_field(item->result_field),
|
2004-10-19 14:12:55 -07:00
|
|
|
item_equal(item->item_equal),
|
|
|
|
no_const_subst(item->no_const_subst),
|
2004-07-16 01:15:55 +03:00
|
|
|
have_privileges(item->have_privileges),
|
|
|
|
any_privileges(item->any_privileges)
|
2003-10-19 14:25:33 +03:00
|
|
|
{
|
|
|
|
collation.set(DERIVATION_IMPLICIT);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
void Item_field::set_field(Field *field_par)
|
|
|
|
{
|
|
|
|
field=result_field=field_par; // for easy coding with fields
|
|
|
|
maybe_null=field->maybe_null();
|
|
|
|
max_length=field_par->field_length;
|
|
|
|
decimals= field->decimals();
|
|
|
|
table_name=field_par->table_name;
|
|
|
|
field_name=field_par->field_name;
|
2003-06-04 18:28:51 +03:00
|
|
|
db_name=field_par->table->table_cache_key;
|
2001-09-27 21:45:48 +03:00
|
|
|
unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
|
2003-08-05 12:52:37 +05:00
|
|
|
collation.set(field_par->charset(), DERIVATION_IMPLICIT);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Item_ident::full_name() const
|
|
|
|
{
|
|
|
|
char *tmp;
|
2003-11-23 02:01:15 +02:00
|
|
|
if (!table_name || !field_name)
|
2000-07-31 21:29:14 +02:00
|
|
|
return field_name ? field_name : name ? name : "tmp_field";
|
2002-12-17 21:04:37 +02:00
|
|
|
if (db_name && db_name[0])
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2000-08-22 00:18:32 +03:00
|
|
|
tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
|
|
|
|
(uint) strlen(field_name)+3);
|
2000-07-31 21:29:14 +02:00
|
|
|
strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-06 20:40:21 +03:00
|
|
|
if (table_name[0])
|
|
|
|
{
|
|
|
|
tmp= (char*) sql_alloc((uint) strlen(table_name) +
|
|
|
|
(uint) strlen(field_name) + 2);
|
|
|
|
strxmov(tmp, table_name, ".", field_name, NullS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tmp= (char*) field_name;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2004-07-20 08:48:28 +03:00
|
|
|
void Item_ident::print(String *str)
|
|
|
|
{
|
2004-07-20 18:51:02 +03:00
|
|
|
THD *thd= current_thd;
|
2004-09-07 19:58:02 +03:00
|
|
|
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
|
|
|
|
const char *d_name= db_name, *t_name= table_name;
|
|
|
|
if (lower_case_table_names)
|
|
|
|
{
|
|
|
|
if (table_name && table_name[0])
|
|
|
|
{
|
|
|
|
strmov(t_name_buff, table_name);
|
|
|
|
my_casedn_str(files_charset_info, t_name_buff);
|
|
|
|
t_name= t_name_buff;
|
|
|
|
}
|
|
|
|
if (db_name && db_name[0])
|
|
|
|
{
|
|
|
|
strmov(d_name_buff, db_name);
|
|
|
|
my_casedn_str(files_charset_info, d_name_buff);
|
|
|
|
d_name= d_name_buff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-20 08:48:28 +03:00
|
|
|
if (!table_name || !field_name)
|
|
|
|
{
|
2004-07-20 18:51:02 +03:00
|
|
|
const char *nm= field_name ? field_name : name ? name : "tmp_field";
|
|
|
|
append_identifier(thd, str, nm, strlen(nm));
|
2004-07-20 08:48:28 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (db_name && db_name[0])
|
|
|
|
{
|
2004-09-07 19:58:02 +03:00
|
|
|
append_identifier(thd, str, d_name, strlen(d_name));
|
2004-07-20 18:51:02 +03:00
|
|
|
str->append('.');
|
2004-09-07 19:58:02 +03:00
|
|
|
append_identifier(thd, str, t_name, strlen(t_name));
|
2004-07-20 18:51:02 +03:00
|
|
|
str->append('.');
|
|
|
|
append_identifier(thd, str, field_name, strlen(field_name));
|
2004-07-20 08:48:28 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (table_name[0])
|
|
|
|
{
|
2004-09-07 19:58:02 +03:00
|
|
|
append_identifier(thd, str, t_name, strlen(t_name));
|
2004-07-20 18:51:02 +03:00
|
|
|
str->append('.');
|
|
|
|
append_identifier(thd, str, field_name, strlen(field_name));
|
2004-07-20 08:48:28 +03:00
|
|
|
}
|
|
|
|
else
|
2004-07-20 18:51:02 +03:00
|
|
|
append_identifier(thd, str, field_name, strlen(field_name));
|
2004-07-20 08:48:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* ARGSUSED */
|
|
|
|
String *Item_field::val_str(String *str)
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
if ((null_value=field->is_null()))
|
|
|
|
return 0;
|
2003-01-03 15:07:40 +02:00
|
|
|
str->set_charset(str_value.charset());
|
2000-07-31 21:29:14 +02:00
|
|
|
return field->val_str(str,&str_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
double Item_field::val()
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
if ((null_value=field->is_null()))
|
|
|
|
return 0.0;
|
|
|
|
return field->val_real();
|
|
|
|
}
|
|
|
|
|
|
|
|
longlong Item_field::val_int()
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
if ((null_value=field->is_null()))
|
|
|
|
return 0;
|
|
|
|
return field->val_int();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_field::str_result(String *str)
|
|
|
|
{
|
|
|
|
if ((null_value=result_field->is_null()))
|
|
|
|
return 0;
|
2002-12-31 18:01:53 +02:00
|
|
|
str->set_charset(str_value.charset());
|
2000-07-31 21:29:14 +02:00
|
|
|
return result_field->val_str(str,&str_value);
|
|
|
|
}
|
|
|
|
|
2003-11-03 14:01:59 +02:00
|
|
|
bool Item_field::get_date(TIME *ltime,uint fuzzydate)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
|
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-03 14:01:59 +02:00
|
|
|
bool Item_field::get_date_result(TIME *ltime,uint fuzzydate)
|
2003-03-11 21:20:53 +01:00
|
|
|
{
|
|
|
|
if ((null_value=result_field->is_null()) ||
|
|
|
|
result_field->get_date(ltime,fuzzydate))
|
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
bool Item_field::get_time(TIME *ltime)
|
|
|
|
{
|
|
|
|
if ((null_value=field->is_null()) || field->get_time(ltime))
|
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Item_field::val_result()
|
|
|
|
{
|
|
|
|
if ((null_value=result_field->is_null()))
|
|
|
|
return 0.0;
|
|
|
|
return result_field->val_real();
|
|
|
|
}
|
|
|
|
|
|
|
|
longlong Item_field::val_int_result()
|
|
|
|
{
|
|
|
|
if ((null_value=result_field->is_null()))
|
|
|
|
return 0;
|
|
|
|
return result_field->val_int();
|
|
|
|
}
|
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
|
2002-03-22 14:03:42 +02:00
|
|
|
bool Item_field::eq(const Item *item, bool binary_cmp) const
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-06-04 18:28:51 +03:00
|
|
|
if (item->type() != FIELD_ITEM)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Item_field *item_field= (Item_field*) item;
|
|
|
|
if (item_field->field)
|
|
|
|
return item_field->field == field;
|
|
|
|
/*
|
|
|
|
We may come here when we are trying to find a function in a GROUP BY
|
|
|
|
clause from the select list.
|
|
|
|
In this case the '100 % correct' way to do this would be to first
|
|
|
|
run fix_fields() on the GROUP BY item and then retry this function, but
|
|
|
|
I think it's better to relax the checking a bit as we will in
|
|
|
|
most cases do the correct thing by just checking the field name.
|
|
|
|
(In cases where we would choose wrong we would have to generate a
|
|
|
|
ER_NON_UNIQ_ERROR).
|
|
|
|
*/
|
|
|
|
return (!my_strcasecmp(system_charset_info, item_field->name,
|
|
|
|
field_name) &&
|
|
|
|
(!item_field->table_name ||
|
|
|
|
(!my_strcasecmp(table_alias_charset, item_field->table_name,
|
|
|
|
table_name) &&
|
|
|
|
(!item_field->db_name ||
|
2004-03-22 15:43:13 +02:00
|
|
|
(item_field->db_name && !strcmp(item_field->db_name,
|
|
|
|
db_name))))));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
table_map Item_field::used_tables() const
|
|
|
|
{
|
|
|
|
if (field->table->const_table)
|
|
|
|
return 0; // const item
|
2003-05-06 01:38:38 +03:00
|
|
|
return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2003-01-30 18:07:39 +02:00
|
|
|
Item *Item_field::get_tmp_table_item(THD *thd)
|
2003-01-25 02:25:52 +02:00
|
|
|
{
|
2004-01-19 19:53:25 +04:00
|
|
|
Item_field *new_item= new Item_field(thd, this);
|
2003-01-25 02:25:52 +02:00
|
|
|
if (new_item)
|
|
|
|
new_item->field= new_item->result_field;
|
|
|
|
return new_item;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2004-05-07 01:43:17 +03:00
|
|
|
/*
|
|
|
|
Create an item from a string we KNOW points to a valid longlong/ulonglong
|
|
|
|
end \0 terminated number string
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item_int::Item_int(const char *str_arg, uint length)
|
|
|
|
{
|
|
|
|
char *end_ptr= (char*) str_arg + length;
|
|
|
|
int error;
|
|
|
|
value= my_strtoll10(str_arg, &end_ptr, &error);
|
|
|
|
max_length= (uint) (end_ptr - str_arg);
|
|
|
|
name= (char*) str_arg;
|
|
|
|
fixed= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
String *Item_int::val_str(String *str)
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2003-11-03 12:28:36 +02:00
|
|
|
str->set(value, &my_charset_bin);
|
2000-07-31 21:29:14 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item_int::print(String *str)
|
|
|
|
{
|
2003-11-03 12:28:36 +02:00
|
|
|
// my_charset_bin is good enough for numbers
|
|
|
|
str_value.set(value, &my_charset_bin);
|
2003-10-16 15:54:47 +03:00
|
|
|
str->append(str_value);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2004-05-07 01:43:17 +03:00
|
|
|
Item_uint::Item_uint(const char *str_arg, uint length):
|
|
|
|
Item_int(str_arg, length)
|
|
|
|
{
|
|
|
|
unsigned_flag= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-14 02:54:33 +03:00
|
|
|
String *Item_uint::val_str(String *str)
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2003-11-03 12:28:36 +02:00
|
|
|
str->set((ulonglong) value, &my_charset_bin);
|
2001-09-14 02:54:33 +03:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2001-09-14 02:54:33 +03:00
|
|
|
void Item_uint::print(String *str)
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
// latin1 is good enough for numbers
|
2003-10-16 15:54:47 +03:00
|
|
|
str_value.set((ulonglong) value, default_charset());
|
|
|
|
str->append(str_value);
|
2001-09-14 02:54:33 +03:00
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
String *Item_real::val_str(String *str)
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2003-11-03 12:28:36 +02:00
|
|
|
str->set(value,decimals,&my_charset_bin);
|
2000-07-31 21:29:14 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
void Item_string::print(String *str)
|
|
|
|
{
|
2003-10-12 17:56:05 +03:00
|
|
|
str->append('_');
|
|
|
|
str->append(collation.collation->csname);
|
2000-07-31 21:29:14 +02:00
|
|
|
str->append('\'');
|
2003-11-03 12:28:36 +02:00
|
|
|
str_value.print(str);
|
2000-07-31 21:29:14 +02:00
|
|
|
str->append('\'');
|
|
|
|
}
|
|
|
|
|
2002-03-22 14:03:42 +02:00
|
|
|
bool Item_null::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{ return item->type() == type(); }
|
2004-03-18 15:14:36 +02:00
|
|
|
double Item_null::val()
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2004-03-18 15:14:36 +02:00
|
|
|
null_value=1;
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
longlong Item_null::val_int()
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2004-03-18 15:14:36 +02:00
|
|
|
null_value=1;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
/* ARGSUSED */
|
|
|
|
String *Item_null::val_str(String *str)
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2004-03-18 15:14:36 +02:00
|
|
|
null_value=1;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
2004-03-15 20:20:47 +03:00
|
|
|
/*********************** Item_param related ******************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Default function of Item_param::set_param_func, so in case
|
|
|
|
of malformed packet the server won't SIGSEGV
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_set_param_func(Item_param *param,
|
|
|
|
uchar **pos __attribute__((unused)),
|
|
|
|
ulong len __attribute__((unused)))
|
|
|
|
{
|
|
|
|
param->set_null();
|
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
Item_param::Item_param(unsigned pos_in_query_arg) :
|
|
|
|
state(NO_VALUE),
|
2004-03-15 20:20:47 +03:00
|
|
|
item_result_type(STRING_RESULT),
|
2004-06-18 04:16:08 +04:00
|
|
|
/* Don't pretend to be a literal unless value for this item is set. */
|
|
|
|
item_type(PARAM_ITEM),
|
2004-06-09 03:21:50 +04:00
|
|
|
param_type(MYSQL_TYPE_STRING),
|
2004-05-25 02:03:49 +04:00
|
|
|
pos_in_query(pos_in_query_arg),
|
2004-03-15 20:20:47 +03:00
|
|
|
set_param_func(default_set_param_func)
|
|
|
|
{
|
|
|
|
name= (char*) "?";
|
2004-05-04 19:08:19 +04:00
|
|
|
/*
|
|
|
|
Since we can't say whenever this item can be NULL or cannot be NULL
|
|
|
|
before mysql_stmt_execute(), so we assuming that it can be NULL until
|
|
|
|
value is set.
|
|
|
|
*/
|
|
|
|
maybe_null= 1;
|
2004-03-15 20:20:47 +03:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
void Item_param::set_null()
|
2003-09-02 14:37:06 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_null");
|
2004-05-04 19:08:19 +04:00
|
|
|
/* These are cleared after each execution by reset() method */
|
2004-05-20 19:08:34 +03:00
|
|
|
max_length= 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
null_value= 1;
|
|
|
|
/*
|
|
|
|
Because of NULL and string values we need to set max_length for each new
|
|
|
|
placeholder value: user can submit NULL for any placeholder type, and
|
|
|
|
string length can be different in each execution.
|
|
|
|
*/
|
|
|
|
max_length= 0;
|
|
|
|
decimals= 0;
|
|
|
|
state= NULL_VALUE;
|
2003-09-02 14:37:06 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
void Item_param::set_int(longlong i, uint32 max_length_arg)
|
2003-09-02 14:37:06 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_int");
|
2004-05-25 02:03:49 +04:00
|
|
|
value.integer= (longlong) i;
|
|
|
|
state= INT_VALUE;
|
|
|
|
max_length= max_length_arg;
|
|
|
|
decimals= 0;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2003-09-02 14:37:06 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
void Item_param::set_double(double d)
|
2003-09-02 14:37:06 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_double");
|
2004-05-25 02:03:49 +04:00
|
|
|
value.real= d;
|
|
|
|
state= REAL_VALUE;
|
|
|
|
max_length= DBL_DIG + 8;
|
2004-05-20 19:08:34 +03:00
|
|
|
decimals= NOT_FIXED_DEC;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2003-09-02 14:37:06 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
void Item_param::set_time(TIME *tm, timestamp_type type, uint32 max_length_arg)
|
2003-01-23 22:32:39 -08:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_ENTER("Item_param::set_time");
|
2003-01-23 22:32:39 -08:00
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
value.time= *tm;
|
|
|
|
value.time.time_type= type;
|
2003-01-23 22:32:39 -08:00
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
state= TIME_VALUE;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
max_length= max_length_arg;
|
|
|
|
decimals= 0;
|
2003-09-02 14:37:06 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
bool Item_param::set_str(const char *str, ulong length)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_str");
|
|
|
|
/*
|
|
|
|
Assign string with no conversion: data is converted only after it's
|
|
|
|
been written to the binary log.
|
|
|
|
*/
|
|
|
|
if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin))
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
state= STRING_VALUE;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
/* max_length and decimals are set after charset conversion */
|
|
|
|
/* sic: str may be not null-terminated, don't add DBUG_PRINT here */
|
|
|
|
DBUG_RETURN(FALSE);
|
2003-01-23 22:32:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
bool Item_param::set_longdata(const char *str, ulong length)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_longdata");
|
|
|
|
|
|
|
|
/*
|
|
|
|
If client character set is multibyte, end of long data packet
|
|
|
|
may hit at the middle of a multibyte character. Additionally,
|
|
|
|
if binary log is open we must write long data value to the
|
|
|
|
binary log in character set of client. This is why we can't
|
|
|
|
convert long data to connection character set as it comes
|
|
|
|
(here), and first have to concatenate all pieces together,
|
|
|
|
write query to the binary log and only then perform conversion.
|
|
|
|
*/
|
|
|
|
if (str_value.append(str, length, &my_charset_bin))
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
state= LONG_DATA_VALUE;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
|
|
|
|
DBUG_RETURN(FALSE);
|
2004-05-04 19:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-07 12:09:10 +04:00
|
|
|
/*
|
|
|
|
Set parameter value from user variable value.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
set_from_user_var
|
|
|
|
thd Current thread
|
|
|
|
entry User variable structure (NULL means use NULL value)
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 OK
|
|
|
|
1 Out of memort
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_from_user_var");
|
|
|
|
if (entry && entry->value)
|
|
|
|
{
|
|
|
|
item_result_type= entry->type;
|
2004-06-22 03:25:54 +04:00
|
|
|
switch (entry->type) {
|
|
|
|
case REAL_RESULT:
|
|
|
|
set_double(*(double*)entry->value);
|
2004-06-25 15:16:00 +03:00
|
|
|
item_type= Item::REAL_ITEM;
|
|
|
|
item_result_type= REAL_RESULT;
|
2004-06-22 03:25:54 +04:00
|
|
|
break;
|
|
|
|
case INT_RESULT:
|
|
|
|
set_int(*(longlong*)entry->value, 21);
|
2004-06-25 15:16:00 +03:00
|
|
|
item_type= Item::INT_ITEM;
|
|
|
|
item_result_type= INT_RESULT;
|
2004-06-22 03:25:54 +04:00
|
|
|
break;
|
|
|
|
case STRING_RESULT:
|
2004-06-07 12:09:10 +04:00
|
|
|
{
|
2004-06-22 03:25:54 +04:00
|
|
|
CHARSET_INFO *fromcs= entry->collation.collation;
|
|
|
|
CHARSET_INFO *tocs= thd->variables.collation_connection;
|
|
|
|
uint32 dummy_offset;
|
|
|
|
|
|
|
|
value.cs_info.character_set_client= fromcs;
|
|
|
|
/*
|
|
|
|
Setup source and destination character sets so that they
|
|
|
|
are different only if conversion is necessary: this will
|
|
|
|
make later checks easier.
|
|
|
|
*/
|
|
|
|
value.cs_info.final_character_set_of_str_value=
|
|
|
|
String::needs_conversion(0, fromcs, tocs, &dummy_offset) ?
|
|
|
|
tocs : fromcs;
|
|
|
|
/*
|
|
|
|
Exact value of max_length is not known unless data is converted to
|
|
|
|
charset of connection, so we have to set it later.
|
|
|
|
*/
|
|
|
|
item_type= Item::STRING_ITEM;
|
|
|
|
item_result_type= STRING_RESULT;
|
|
|
|
|
|
|
|
if (set_str((const char *)entry->value, entry->length))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
set_null();
|
2004-06-07 12:09:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
set_null();
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-05-04 19:08:19 +04:00
|
|
|
/*
|
|
|
|
Resets parameter after execution.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Item_param::reset()
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
We clear null_value here instead of setting it in set_* methods,
|
|
|
|
because we want more easily handle case for long data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Item_param::reset()
|
2004-05-25 02:03:49 +04:00
|
|
|
{
|
|
|
|
/* Shrink string buffer if it's bigger than max possible CHAR column */
|
|
|
|
if (str_value.alloced_length() > MAX_CHAR_WIDTH)
|
|
|
|
str_value.free();
|
|
|
|
else
|
|
|
|
str_value.length(0);
|
2004-05-31 14:21:48 +04:00
|
|
|
str_value_ptr.length(0);
|
2004-05-25 02:03:49 +04:00
|
|
|
/*
|
2004-05-31 14:21:48 +04:00
|
|
|
We must prevent all charset conversions untill data has been written
|
|
|
|
to the binary log.
|
2004-05-25 02:03:49 +04:00
|
|
|
*/
|
|
|
|
str_value.set_charset(&my_charset_bin);
|
|
|
|
state= NO_VALUE;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 1;
|
|
|
|
null_value= 0;
|
2004-06-18 04:16:08 +04:00
|
|
|
/*
|
|
|
|
Don't reset item_type to PARAM_ITEM: it's only needed to guard
|
|
|
|
us from item optimizations at prepare stage, when item doesn't yet
|
|
|
|
contain a literal of some kind.
|
|
|
|
In all other cases when this object is accessed its value is
|
|
|
|
set (this assumption is guarded by 'state' and
|
|
|
|
DBUG_ASSERTS(state != NO_VALUE) in all Item_param::get_*
|
|
|
|
methods).
|
|
|
|
*/
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-06 23:39:11 -08:00
|
|
|
int Item_param::save_in_field(Field *field, bool no_conversions)
|
2002-06-12 14:13:12 -07:00
|
|
|
{
|
|
|
|
field->set_notnull();
|
2004-05-25 02:03:49 +04:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case INT_VALUE:
|
|
|
|
return field->store(value.integer);
|
|
|
|
case REAL_VALUE:
|
|
|
|
return field->store(value.real);
|
|
|
|
case TIME_VALUE:
|
|
|
|
field->store_time(&value.time, value.time.time_type);
|
2003-01-23 22:32:39 -08:00
|
|
|
return 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
|
|
|
return field->store(str_value.ptr(), str_value.length(),
|
|
|
|
str_value.charset());
|
|
|
|
case NULL_VALUE:
|
|
|
|
return set_field_to_null(field);
|
|
|
|
case NO_VALUE:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
return 1;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
|
2003-01-23 22:32:39 -08:00
|
|
|
bool Item_param::get_time(TIME *res)
|
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
if (state == TIME_VALUE)
|
|
|
|
{
|
|
|
|
*res= value.time;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
If parameter value isn't supplied assertion will fire in val_str()
|
|
|
|
which is called from Item::get_time().
|
|
|
|
*/
|
|
|
|
return Item::get_time(res);
|
2003-01-23 22:32:39 -08:00
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
|
2004-06-09 03:21:50 +04:00
|
|
|
bool Item_param::get_date(TIME *res, uint fuzzydate)
|
|
|
|
{
|
|
|
|
if (state == TIME_VALUE)
|
|
|
|
{
|
|
|
|
*res= value.time;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return Item::get_date(res, fuzzydate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
double Item_param::val()
|
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
switch (state) {
|
|
|
|
case REAL_VALUE:
|
|
|
|
return value.real;
|
|
|
|
case INT_VALUE:
|
|
|
|
return (double) value.integer;
|
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
|
|
|
{
|
|
|
|
int dummy_err;
|
|
|
|
return my_strntod(str_value.charset(), (char*) str_value.ptr(),
|
|
|
|
str_value.length(), (char**) 0, &dummy_err);
|
|
|
|
}
|
|
|
|
case TIME_VALUE:
|
|
|
|
/*
|
|
|
|
This works for example when user says SELECT ?+0.0 and supplies
|
|
|
|
time value for the placeholder.
|
|
|
|
*/
|
2004-08-24 18:00:45 +03:00
|
|
|
return ulonglong2double(TIME_to_ulonglong(&value.time));
|
2004-05-25 02:03:49 +04:00
|
|
|
case NULL_VALUE:
|
2004-05-05 20:04:25 +04:00
|
|
|
return 0.0;
|
2002-06-12 14:13:12 -07:00
|
|
|
default:
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_ASSERT(0);
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
return 0.0;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
longlong Item_param::val_int()
|
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
switch (state) {
|
|
|
|
case REAL_VALUE:
|
|
|
|
return (longlong) (value.real + (value.real > 0 ? 0.5 : -0.5));
|
|
|
|
case INT_VALUE:
|
|
|
|
return value.integer;
|
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
|
|
|
{
|
|
|
|
int dummy_err;
|
|
|
|
return my_strntoll(str_value.charset(), str_value.ptr(),
|
|
|
|
str_value.length(), 10, (char**) 0, &dummy_err);
|
|
|
|
}
|
|
|
|
case TIME_VALUE:
|
|
|
|
return (longlong) TIME_to_ulonglong(&value.time);
|
|
|
|
case NULL_VALUE:
|
|
|
|
return 0;
|
2002-06-12 14:13:12 -07:00
|
|
|
default:
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_ASSERT(0);
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
return 0;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
String *Item_param::val_str(String* str)
|
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
switch (state) {
|
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
2004-05-31 14:21:48 +04:00
|
|
|
return &str_value_ptr;
|
2004-05-25 02:03:49 +04:00
|
|
|
case REAL_VALUE:
|
|
|
|
str->set(value.real, NOT_FIXED_DEC, &my_charset_bin);
|
|
|
|
return str;
|
|
|
|
case INT_VALUE:
|
|
|
|
str->set(value.integer, &my_charset_bin);
|
2002-06-12 14:13:12 -07:00
|
|
|
return str;
|
2004-05-25 02:03:49 +04:00
|
|
|
case TIME_VALUE:
|
|
|
|
{
|
|
|
|
if (str->reserve(MAX_DATE_REP_LENGTH))
|
|
|
|
break;
|
|
|
|
TIME_to_string(&value.time, str);
|
2002-06-12 14:13:12 -07:00
|
|
|
return str;
|
2004-05-25 02:03:49 +04:00
|
|
|
}
|
|
|
|
case NULL_VALUE:
|
|
|
|
return NULL;
|
2002-06-12 14:13:12 -07:00
|
|
|
default:
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_ASSERT(0);
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
return str;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2003-04-04 12:33:17 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Return Param item values in string format, for generating the dynamic
|
|
|
|
query used in update/binary logs
|
2004-05-25 02:03:49 +04:00
|
|
|
TODO: change interface and implementation to fill log data in place
|
|
|
|
and avoid one more memcpy/alloc between str and log string.
|
2003-04-04 12:33:17 -05:00
|
|
|
*/
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
const String *Item_param::query_val_str(String* str) const
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
switch (state) {
|
|
|
|
case INT_VALUE:
|
|
|
|
str->set(value.integer, &my_charset_bin);
|
|
|
|
break;
|
|
|
|
case REAL_VALUE:
|
|
|
|
str->set(value.real, NOT_FIXED_DEC, &my_charset_bin);
|
|
|
|
break;
|
|
|
|
case TIME_VALUE:
|
2003-04-04 12:33:17 -05:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
char *buf, *ptr;
|
|
|
|
String tmp;
|
|
|
|
str->length(0);
|
|
|
|
/*
|
|
|
|
TODO: in case of error we need to notify replication
|
|
|
|
that binary log contains wrong statement
|
|
|
|
*/
|
|
|
|
if (str->reserve(MAX_DATE_REP_LENGTH+3))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Create date string inplace */
|
|
|
|
buf= str->c_ptr_quick();
|
|
|
|
ptr= buf;
|
|
|
|
*ptr++= '\'';
|
|
|
|
tmp.set(ptr, MAX_DATE_REP_LENGTH, &my_charset_bin);
|
|
|
|
tmp.length(0);
|
|
|
|
TIME_to_string(&value.time, &tmp);
|
|
|
|
|
|
|
|
ptr+= tmp.length();
|
|
|
|
*ptr++= '\'';
|
|
|
|
str->length((uint32) (ptr - buf));
|
|
|
|
break;
|
2003-04-04 12:33:17 -05:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
2003-04-04 12:33:17 -05:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
char *buf, *ptr;
|
|
|
|
str->length(0);
|
|
|
|
if (str->reserve(str_value.length()*2+3))
|
|
|
|
break;
|
|
|
|
|
|
|
|
buf= str->c_ptr_quick();
|
|
|
|
ptr= buf;
|
|
|
|
*ptr++= '\'';
|
|
|
|
ptr+= escape_string_for_mysql(str_value.charset(), ptr,
|
|
|
|
str_value.ptr(), str_value.length());
|
|
|
|
*ptr++= '\'';
|
|
|
|
str->length(ptr - buf);
|
|
|
|
break;
|
2003-04-04 12:33:17 -05:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
case NULL_VALUE:
|
|
|
|
return &my_null_string;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
2003-04-04 12:33:17 -05:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Convert string from client character set to the character set of
|
|
|
|
connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_param::convert_str_value(THD *thd)
|
|
|
|
{
|
|
|
|
bool rc= FALSE;
|
|
|
|
if (state == STRING_VALUE || state == LONG_DATA_VALUE)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Check is so simple because all charsets were set up properly
|
|
|
|
in setup_one_conversion_function, where typecode of
|
|
|
|
placeholder was also taken into account: the variables are different
|
|
|
|
here only if conversion is really necessary.
|
|
|
|
*/
|
|
|
|
if (value.cs_info.final_character_set_of_str_value !=
|
|
|
|
value.cs_info.character_set_client)
|
|
|
|
{
|
|
|
|
rc= thd->convert_string(&str_value,
|
|
|
|
value.cs_info.character_set_client,
|
|
|
|
value.cs_info.final_character_set_of_str_value);
|
|
|
|
}
|
|
|
|
max_length= str_value.length();
|
|
|
|
decimals= 0;
|
2004-05-31 14:21:48 +04:00
|
|
|
/*
|
|
|
|
str_value_ptr is returned from val_str(). It must be not alloced
|
|
|
|
to prevent it's modification by val_str() invoker.
|
|
|
|
*/
|
|
|
|
str_value_ptr.set(str_value.ptr(), str_value.length(),
|
|
|
|
str_value.charset());
|
2004-05-25 02:03:49 +04:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
|
2004-09-04 15:02:57 +03:00
|
|
|
void Item_param::print(String *str)
|
|
|
|
{
|
|
|
|
if (state == NO_VALUE)
|
|
|
|
{
|
|
|
|
str->append('?');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char buffer[80];
|
|
|
|
String tmp(buffer, sizeof(buffer), &my_charset_bin);
|
|
|
|
const String *res;
|
|
|
|
res= query_val_str(&tmp);
|
|
|
|
str->append(*res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Item_copy_string
|
|
|
|
****************************************************************************/
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
void Item_copy_string::copy()
|
|
|
|
{
|
|
|
|
String *res=item->val_str(&str_value);
|
|
|
|
if (res && res != &str_value)
|
|
|
|
str_value.copy(*res);
|
|
|
|
null_value=item->null_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
String *Item_copy_string::val_str(String *str)
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
// Item_copy_string is used without fix_fields call
|
2000-07-31 21:29:14 +02:00
|
|
|
if (null_value)
|
|
|
|
return (String*) 0;
|
|
|
|
return &str_value;
|
|
|
|
}
|
|
|
|
|
2004-03-25 22:11:22 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*
|
2002-10-02 13:33:08 +03:00
|
|
|
Functions to convert item to field (for send_fields)
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
bool Item::fix_fields(THD *thd,
|
2002-07-01 14:14:51 +03:00
|
|
|
struct st_table_list *list,
|
|
|
|
Item ** ref)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-03-17 14:26:26 +02:00
|
|
|
|
|
|
|
// We do not check fields which are fixed during construction
|
2004-03-20 13:36:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0 || basic_const_item());
|
2002-11-21 11:01:33 +02:00
|
|
|
fixed= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-06 21:55:53 +02:00
|
|
|
double Item_ref_null_helper::val()
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2002-12-06 21:55:53 +02:00
|
|
|
double tmp= (*ref)->val_result();
|
2002-12-10 18:10:00 +02:00
|
|
|
owner->was_null|= null_value= (*ref)->null_value;
|
2002-12-06 21:55:53 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
2004-03-18 15:14:36 +02:00
|
|
|
|
|
|
|
|
2002-12-06 21:55:53 +02:00
|
|
|
longlong Item_ref_null_helper::val_int()
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2002-12-06 21:55:53 +02:00
|
|
|
longlong tmp= (*ref)->val_int_result();
|
2002-12-10 18:10:00 +02:00
|
|
|
owner->was_null|= null_value= (*ref)->null_value;
|
2002-12-06 21:55:53 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
2004-03-18 15:14:36 +02:00
|
|
|
|
|
|
|
|
2002-12-06 21:55:53 +02:00
|
|
|
String* Item_ref_null_helper::val_str(String* s)
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2002-12-06 21:55:53 +02:00
|
|
|
String* tmp= (*ref)->str_result(s);
|
2002-12-10 18:10:00 +02:00
|
|
|
owner->was_null|= null_value= (*ref)->null_value;
|
2002-12-06 21:55:53 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
2004-03-18 15:14:36 +02:00
|
|
|
|
|
|
|
|
2003-11-03 14:01:59 +02:00
|
|
|
bool Item_ref_null_helper::get_date(TIME *ltime, uint fuzzydate)
|
2002-12-06 21:55:53 +02:00
|
|
|
{
|
|
|
|
return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
|
|
|
|
}
|
2002-10-27 23:27:00 +02:00
|
|
|
|
2003-06-20 10:15:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
Mark item and SELECT_LEXs as dependent if it is not outer resolving
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
mark_as_dependent()
|
2003-07-25 01:02:42 +03:00
|
|
|
thd - thread handler
|
2003-06-20 10:15:58 +03:00
|
|
|
last - select from which current item depend
|
|
|
|
current - current select
|
|
|
|
item - item which should be marked
|
|
|
|
*/
|
|
|
|
|
2003-07-25 01:02:42 +03:00
|
|
|
static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
|
2003-06-20 10:15:58 +03:00
|
|
|
Item_ident *item)
|
|
|
|
{
|
2003-07-02 01:45:22 +03:00
|
|
|
// store pointer on SELECT_LEX from wich item is dependent
|
|
|
|
item->depended_from= last;
|
|
|
|
current->mark_as_dependent(last);
|
2003-11-19 15:19:46 +01:00
|
|
|
if (thd->lex->describe & DESCRIBE_EXTENDED)
|
2003-07-25 01:02:42 +03:00
|
|
|
{
|
|
|
|
char warn_buff[MYSQL_ERRMSG_SIZE];
|
|
|
|
sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
|
|
|
|
(item->db_name?item->db_name:""), (item->db_name?".":""),
|
|
|
|
(item->table_name?item->table_name:""), (item->table_name?".":""),
|
|
|
|
item->field_name,
|
|
|
|
current->select_number, last->select_number);
|
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
|
|
|
|
ER_WARN_FIELD_RESOLVED, warn_buff);
|
|
|
|
}
|
2003-06-20 10:15:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-01 14:14:51 +03:00
|
|
|
bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2001-09-21 03:38:35 +03:00
|
|
|
if (!field) // If field is not checked
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-10-11 17:41:15 +03:00
|
|
|
bool upward_lookup= 0;
|
2002-12-26 01:28:59 +02:00
|
|
|
Field *tmp= (Field *)not_found_field;
|
2004-11-02 18:23:15 +02:00
|
|
|
if ((tmp= find_field_in_tables(thd, this, tables, ref,
|
|
|
|
IGNORE_EXCEPT_NON_UNIQUE,
|
2004-07-16 01:15:55 +03:00
|
|
|
!any_privileges)) ==
|
2002-12-26 01:28:59 +02:00
|
|
|
not_found_field)
|
2002-05-26 22:50:32 +03:00
|
|
|
{
|
|
|
|
/*
|
2003-10-11 13:06:55 +02:00
|
|
|
We can't find table field in table list of current select,
|
2002-05-26 22:50:32 +03:00
|
|
|
consequently we have to find it in outer subselect(s).
|
2003-10-11 13:06:55 +02:00
|
|
|
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
|
2002-05-26 22:50:32 +03:00
|
|
|
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.
|
|
|
|
*/
|
2002-07-01 14:14:51 +03:00
|
|
|
SELECT_LEX *last= 0;
|
2002-07-11 13:43:21 +05:00
|
|
|
#ifdef EMBEDDED_LIBRARY
|
|
|
|
thd->net.last_errno= 0;
|
|
|
|
#endif
|
2003-05-21 23:35:51 +03:00
|
|
|
TABLE_LIST *table_list;
|
2002-11-21 11:01:33 +02:00
|
|
|
Item **refer= (Item **)not_found_item;
|
2003-01-30 18:07:39 +02:00
|
|
|
uint counter;
|
2002-11-11 10:49:41 +02:00
|
|
|
// Prevent using outer fields in subselects, that is not supported now
|
2003-12-19 20:52:13 +03:00
|
|
|
SELECT_LEX *cursel= (SELECT_LEX *) thd->lex->current_select;
|
2003-07-02 01:45:22 +03:00
|
|
|
if (cursel->master_unit()->first_select()->linkage != DERIVED_TABLE_TYPE)
|
2003-10-17 00:36:01 +03:00
|
|
|
{
|
|
|
|
SELECT_LEX_UNIT *prev_unit= cursel->master_unit();
|
|
|
|
for (SELECT_LEX *sl= prev_unit->outer_select();
|
2002-11-11 10:49:41 +02:00
|
|
|
sl;
|
2003-10-17 00:36:01 +03:00
|
|
|
sl= (prev_unit= sl->master_unit())->outer_select())
|
2002-11-21 11:01:33 +02:00
|
|
|
{
|
2003-10-11 17:41:15 +03:00
|
|
|
upward_lookup= 1;
|
2003-05-21 23:35:51 +03:00
|
|
|
table_list= (last= sl)->get_table_list();
|
2003-07-29 16:59:46 +03:00
|
|
|
if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list)
|
2003-05-21 23:35:51 +03:00
|
|
|
{
|
2004-08-13 10:01:30 +03:00
|
|
|
/*
|
|
|
|
it is primary INSERT st_select_lex => skip first table
|
|
|
|
resolving
|
|
|
|
*/
|
2004-07-16 01:15:55 +03:00
|
|
|
table_list= table_list->next_local;
|
2003-05-21 23:35:51 +03:00
|
|
|
}
|
2003-10-23 20:50:53 +03:00
|
|
|
|
|
|
|
Item_subselect *prev_subselect_item= prev_unit->item;
|
2004-09-06 15:14:10 +03:00
|
|
|
enum_parsing_place place= prev_subselect_item->parsing_place;
|
2004-08-13 10:01:30 +03:00
|
|
|
/*
|
|
|
|
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 &&
|
|
|
|
place != SELECT_LIST) ||
|
|
|
|
(sl->with_sum_func == 0 && sl->group_list.elements == 0)) &&
|
|
|
|
(tmp= find_field_in_tables(thd, this,
|
2004-07-16 01:15:55 +03:00
|
|
|
table_list, ref,
|
2004-11-02 18:23:15 +02:00
|
|
|
IGNORE_EXCEPT_NON_UNIQUE, 1)) !=
|
|
|
|
not_found_field)
|
2003-10-17 00:36:01 +03:00
|
|
|
{
|
2004-09-01 23:27:40 +03:00
|
|
|
if (tmp)
|
|
|
|
{
|
|
|
|
if (tmp != view_ref_found)
|
|
|
|
{
|
|
|
|
prev_subselect_item->used_tables_cache|= tmp->table->map;
|
|
|
|
prev_subselect_item->const_item_cache= 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev_subselect_item->used_tables_cache|=
|
|
|
|
(*ref)->used_tables();
|
|
|
|
prev_subselect_item->const_item_cache&=
|
|
|
|
(*ref)->const_item();
|
|
|
|
}
|
|
|
|
}
|
2002-11-11 10:49:41 +02:00
|
|
|
break;
|
2003-10-17 00:36:01 +03:00
|
|
|
}
|
2003-07-29 16:59:46 +03:00
|
|
|
if (sl->resolve_mode == SELECT_LEX::SELECT_MODE &&
|
2003-10-11 13:06:55 +02:00
|
|
|
(refer= find_item_in_list(this, sl->item_list, &counter,
|
|
|
|
REPORT_EXCEPT_NOT_FOUND)) !=
|
2003-05-13 11:15:11 +03:00
|
|
|
(Item **) not_found_item)
|
2003-10-17 00:36:01 +03:00
|
|
|
{
|
|
|
|
if (*refer && (*refer)->fixed) // Avoid crash in case of error
|
|
|
|
{
|
2003-10-23 20:50:53 +03:00
|
|
|
prev_subselect_item->used_tables_cache|= (*refer)->used_tables();
|
|
|
|
prev_subselect_item->const_item_cache&= (*refer)->const_item();
|
2003-10-17 00:36:01 +03:00
|
|
|
}
|
2002-11-21 11:01:33 +02:00
|
|
|
break;
|
2003-10-17 00:36:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reference is not found => depend from outer (or just error)
|
2003-10-23 20:50:53 +03:00
|
|
|
prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
|
|
|
|
prev_subselect_item->const_item_cache= 0;
|
2003-10-17 00:36:01 +03:00
|
|
|
|
2002-12-17 23:18:19 +02:00
|
|
|
if (sl->master_unit()->first_select()->linkage ==
|
|
|
|
DERIVED_TABLE_TYPE)
|
2002-11-25 10:58:49 +02:00
|
|
|
break; // do not look over derived table
|
2002-11-21 11:01:33 +02:00
|
|
|
}
|
2003-10-17 00:36:01 +03:00
|
|
|
}
|
2002-05-26 22:50:32 +03:00
|
|
|
if (!tmp)
|
2002-10-08 14:50:12 +03:00
|
|
|
return -1;
|
2004-09-09 06:59:26 +03:00
|
|
|
if (!refer)
|
2002-11-21 11:01:33 +02:00
|
|
|
return 1;
|
2004-09-09 06:59:26 +03:00
|
|
|
if (tmp == not_found_field && refer == (Item **)not_found_item)
|
2002-10-03 16:35:08 +03:00
|
|
|
{
|
2003-10-11 17:41:15 +03:00
|
|
|
if (upward_lookup)
|
2003-11-02 16:56:39 +02:00
|
|
|
{
|
2003-10-11 17:41:15 +03:00
|
|
|
// 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);
|
2003-11-02 16:56:39 +02:00
|
|
|
}
|
2003-10-11 17:41:15 +03:00
|
|
|
else
|
2003-11-02 16:56:39 +02:00
|
|
|
{
|
2003-10-11 17:41:15 +03:00
|
|
|
// Call to report error
|
2004-11-02 18:23:15 +02:00
|
|
|
find_field_in_tables(thd, this, tables, ref, REPORT_ALL_ERRORS, 1);
|
2003-11-02 16:56:39 +02:00
|
|
|
}
|
2002-10-03 16:35:08 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2002-11-21 11:01:33 +02:00
|
|
|
else if (refer != (Item **)not_found_item)
|
|
|
|
{
|
2003-01-25 02:25:52 +02:00
|
|
|
if (!(*refer)->fixed)
|
|
|
|
{
|
|
|
|
my_error(ER_ILLEGAL_REFERENCE, MYF(0), name,
|
|
|
|
"forward reference in item list");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-06-20 10:15:58 +03:00
|
|
|
Item_ref *rf;
|
|
|
|
*ref= rf= new Item_ref(last->ref_pointer_array + counter,
|
2003-12-30 14:08:19 +04:00
|
|
|
ref,
|
2003-06-20 10:15:58 +03:00
|
|
|
(char *)table_name,
|
|
|
|
(char *)field_name);
|
2004-03-17 14:26:26 +02:00
|
|
|
register_item_tree_changing(ref);
|
2003-06-20 10:15:58 +03:00
|
|
|
if (!rf)
|
2002-11-21 11:01:33 +02:00
|
|
|
return 1;
|
2004-02-18 01:08:52 +02:00
|
|
|
/*
|
|
|
|
rf is Item_ref => never substitute other items (in this case)
|
|
|
|
during fix_fields() => we can use rf after fix_fields()
|
|
|
|
*/
|
2003-06-20 10:15:58 +03:00
|
|
|
if (rf->fix_fields(thd, tables, ref) || rf->check_cols(1))
|
2002-11-29 12:30:04 +02:00
|
|
|
return 1;
|
2003-06-20 10:15:58 +03:00
|
|
|
|
2003-07-25 01:02:42 +03:00
|
|
|
mark_as_dependent(thd, last, cursel, rf);
|
2002-11-21 11:01:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-05-26 22:50:32 +03:00
|
|
|
else
|
2002-07-01 14:14:51 +03:00
|
|
|
{
|
2003-07-25 01:02:42 +03:00
|
|
|
mark_as_dependent(thd, last, cursel, this);
|
2003-06-20 10:15:58 +03:00
|
|
|
if (last->having_fix_field)
|
2002-12-26 01:28:59 +02:00
|
|
|
{
|
|
|
|
Item_ref *rf;
|
2004-01-19 19:53:25 +04:00
|
|
|
*ref= rf= new Item_ref(ref, *ref,
|
2004-07-16 01:15:55 +03:00
|
|
|
(cached_table->db[0]?cached_table->db:0),
|
|
|
|
(char *)cached_table->alias,
|
2002-12-26 01:28:59 +02:00
|
|
|
(char *)field_name);
|
|
|
|
if (!rf)
|
|
|
|
return 1;
|
2004-02-18 01:08:52 +02:00
|
|
|
/*
|
|
|
|
rf is Item_ref => never substitute other items (in this case)
|
|
|
|
during fix_fields() => we can use rf after fix_fields()
|
|
|
|
*/
|
2003-01-21 13:55:26 +02:00
|
|
|
return rf->fix_fields(thd, tables, ref) || rf->check_cols(1);
|
2002-12-26 01:28:59 +02:00
|
|
|
}
|
2002-07-01 14:14:51 +03:00
|
|
|
}
|
2003-06-04 18:28:51 +03:00
|
|
|
}
|
2002-10-08 14:50:12 +03:00
|
|
|
else if (!tmp)
|
|
|
|
return -1;
|
|
|
|
|
2004-07-16 01:15:55 +03:00
|
|
|
/*
|
|
|
|
if it is not expression from merged VIEW we will set this field.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (tmp != view_ref_found)
|
|
|
|
set_field(tmp);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-10-31 17:52:00 +03:00
|
|
|
else if (thd->set_query_id && field->query_id != thd->query_id)
|
2001-09-21 03:38:35 +03:00
|
|
|
{
|
|
|
|
/* We only come here in unions */
|
|
|
|
TABLE *table=field->table;
|
|
|
|
field->query_id=thd->query_id;
|
|
|
|
table->used_fields++;
|
2003-10-11 13:06:55 +02:00
|
|
|
table->used_keys.intersect(field->part_of_key);
|
2001-09-21 03:38:35 +03:00
|
|
|
}
|
2004-07-16 01:15:55 +03:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
if (any_privileges)
|
|
|
|
{
|
|
|
|
char *db, *tab;
|
|
|
|
if (cached_table->view)
|
|
|
|
{
|
|
|
|
db= cached_table->view_db.str;
|
|
|
|
tab= cached_table->view_name.str;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
db= cached_table->db;
|
|
|
|
tab= cached_table->real_name;
|
|
|
|
}
|
|
|
|
if (!(have_privileges= (get_column_grant(thd, &field->table->grant,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-21 11:01:33 +02:00
|
|
|
fixed= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-30 14:08:19 +04:00
|
|
|
void Item_field::cleanup()
|
|
|
|
{
|
2004-02-08 20:14:13 +02:00
|
|
|
DBUG_ENTER("Item_field::cleanup");
|
2003-12-30 14:08:19 +04:00
|
|
|
Item_ident::cleanup();
|
2004-03-17 14:26:26 +02:00
|
|
|
/*
|
|
|
|
Even if this object was created by direct link to field in setup_wild()
|
|
|
|
it will be linked correctly next tyme by name of field and table alias.
|
|
|
|
I.e. we can drop 'field'.
|
|
|
|
*/
|
2004-01-19 19:53:25 +04:00
|
|
|
field= result_field= 0;
|
2004-02-19 12:04:46 -08:00
|
|
|
}
|
2004-02-18 22:21:37 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
Find a field among specified multiple equalities
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
find_item_equal()
|
|
|
|
cond_equal reference to list of multiple equalities where
|
|
|
|
the field (this object) is to be looked for
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
The function first searches the field among multiple equalities
|
|
|
|
of the current level (in the cond_equal->current_level list).
|
|
|
|
If it fails, it continues searching in upper levels accessed
|
|
|
|
through a pointer cond_equal->upper_levels.
|
|
|
|
The search terminates as soon as a multiple equality containing
|
|
|
|
the field is found.
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
First Item_equal containing the field, if success
|
|
|
|
0, otherwise
|
|
|
|
*/
|
2004-10-19 14:12:55 -07:00
|
|
|
Item_equal *Item_field::find_item_equal(COND_EQUAL *cond_equal)
|
|
|
|
{
|
|
|
|
Item_equal *item= 0;
|
|
|
|
while (cond_equal)
|
|
|
|
{
|
|
|
|
List_iterator_fast<Item_equal> li(cond_equal->current_level);
|
|
|
|
while ((item= li++))
|
|
|
|
{
|
|
|
|
if (item->contains(field))
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
The field is not found in any of the multiple equalities
|
|
|
|
of the current level. Look for it in upper levels
|
|
|
|
*/
|
|
|
|
cond_equal= cond_equal->upper_levels;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Set a pointer to the multiple equality the field reference belongs to (if any)
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
equal_fields_propagator()
|
|
|
|
arg - reference to list of multiple equalities where
|
|
|
|
the field (this object) is to be looked for
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
The function looks for a multiple equality containing the field item
|
|
|
|
among those referenced by arg.
|
|
|
|
In the case such equality exists the function does the following.
|
|
|
|
If the found multiple equality contains a constant, then the field
|
|
|
|
reference is substituted for this constant, otherwise it sets a pointer
|
|
|
|
to the multiple equality in the field item.
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
This function is supposed to be called as a callback parameter in calls
|
|
|
|
of the transform method.
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
pointer to the replacing constant item, if the field item was substituted
|
|
|
|
pointer to the field item, otherwise.
|
|
|
|
*/
|
2004-02-18 22:21:37 -08:00
|
|
|
|
2004-10-19 14:12:55 -07:00
|
|
|
Item *Item_field::equal_fields_propagator(byte *arg)
|
|
|
|
{
|
|
|
|
if (no_const_subst)
|
|
|
|
return this;
|
|
|
|
item_equal= find_item_equal((COND_EQUAL *) arg);
|
|
|
|
Item *item= 0;
|
|
|
|
if (item_equal)
|
|
|
|
item= item_equal->get_const();
|
|
|
|
if (!item)
|
|
|
|
item= this;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Set a pointer to the multiple equality the field reference belongs to (if any)
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
replace_equal_field_processor()
|
|
|
|
arg - a dummy parameter, is not used here
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
The function replaces a pointer to a field in the Item_field object
|
|
|
|
by a pointer to another field.
|
|
|
|
The replacement field is taken from the very beginning of
|
|
|
|
the item_equal list which the Item_field object refers to (belongs to)
|
|
|
|
If the Item_field object does not refer any Item_equal object,
|
|
|
|
nothing is done.
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
This function is supposed to be called as a callback parameter in calls
|
|
|
|
of the walk method.
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
0
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_field::replace_equal_field_processor(byte *arg)
|
|
|
|
{
|
|
|
|
if (item_equal)
|
|
|
|
{
|
|
|
|
Item_field *subst= item_equal->get_first();
|
|
|
|
if (!field->eq(subst->field))
|
|
|
|
{
|
|
|
|
field= subst->field;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2003-12-30 14:08:19 +04:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
void Item::init_make_field(Send_field *tmp_field,
|
|
|
|
enum enum_field_types field_type)
|
2003-10-11 13:06:55 +02:00
|
|
|
{
|
2003-02-04 03:19:19 +02:00
|
|
|
char *empty_name= (char*) "";
|
2003-10-11 13:06:55 +02:00
|
|
|
tmp_field->db_name= empty_name;
|
2003-02-04 03:19:19 +02:00
|
|
|
tmp_field->org_table_name= empty_name;
|
|
|
|
tmp_field->org_col_name= empty_name;
|
|
|
|
tmp_field->table_name= empty_name;
|
|
|
|
tmp_field->col_name= name;
|
2003-10-11 13:06:55 +02:00
|
|
|
tmp_field->charsetnr= collation.collation->number;
|
2000-07-31 21:29:14 +02:00
|
|
|
tmp_field->flags=maybe_null ? 0 : NOT_NULL_FLAG;
|
|
|
|
tmp_field->type=field_type;
|
|
|
|
tmp_field->length=max_length;
|
|
|
|
tmp_field->decimals=decimals;
|
2001-09-27 21:45:48 +03:00
|
|
|
if (unsigned_flag)
|
|
|
|
tmp_field->flags |= UNSIGNED_FLAG;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
void Item::make_field(Send_field *tmp_field)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
init_make_field(tmp_field, field_type());
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-21 20:21:07 +02:00
|
|
|
void Item_empty_string::make_field(Send_field *tmp_field)
|
|
|
|
{
|
|
|
|
init_make_field(tmp_field,FIELD_TYPE_VAR_STRING);
|
|
|
|
}
|
|
|
|
|
2002-07-25 01:00:56 +03:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
enum_field_types Item::field_type() const
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
return ((result_type() == STRING_RESULT) ? FIELD_TYPE_VAR_STRING :
|
|
|
|
(result_type() == INT_RESULT) ? FIELD_TYPE_LONGLONG :
|
|
|
|
FIELD_TYPE_DOUBLE);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-11-03 14:01:59 +02:00
|
|
|
|
2003-08-27 19:11:54 -04:00
|
|
|
Field *Item::tmp_table_field_from_field_type(TABLE *table)
|
|
|
|
{
|
2003-12-15 17:58:15 +02:00
|
|
|
/*
|
|
|
|
The field functions defines a field to be not null if null_ptr is not 0
|
|
|
|
*/
|
|
|
|
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
|
|
|
|
|
|
|
|
switch (field_type()) {
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_DECIMAL:
|
2003-12-15 17:58:15 +02:00
|
|
|
return new Field_decimal((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table, decimals, 0, unsigned_flag);
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_TINY:
|
2003-12-15 17:58:15 +02:00
|
|
|
return new Field_tiny((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table, 0, unsigned_flag);
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_SHORT:
|
2003-12-15 17:58:15 +02:00
|
|
|
return new Field_short((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table, 0, unsigned_flag);
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_LONG:
|
2003-12-15 17:58:15 +02:00
|
|
|
return new Field_long((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table, 0, unsigned_flag);
|
2003-08-27 19:11:54 -04:00
|
|
|
#ifdef HAVE_LONG_LONG
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
2003-12-15 17:58:15 +02:00
|
|
|
return new Field_longlong((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table, 0, unsigned_flag);
|
2003-08-27 19:11:54 -04:00
|
|
|
#endif
|
2003-12-15 17:58:15 +02:00
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
return new Field_float((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table, decimals, 0, unsigned_flag);
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
return new Field_double((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table, decimals, 0, unsigned_flag);
|
|
|
|
case MYSQL_TYPE_NULL:
|
|
|
|
return new Field_null((char*) 0, max_length, Field::NONE,
|
|
|
|
name, table, &my_charset_bin);
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_NEWDATE:
|
|
|
|
case MYSQL_TYPE_INT24:
|
2003-12-15 17:58:15 +02:00
|
|
|
return new Field_medium((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table, 0, unsigned_flag);
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_DATE:
|
|
|
|
return new Field_date(maybe_null, name, table, &my_charset_bin);
|
|
|
|
case MYSQL_TYPE_TIME:
|
|
|
|
return new Field_time(maybe_null, name, table, &my_charset_bin);
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
return new Field_datetime(maybe_null, name, table, &my_charset_bin);
|
|
|
|
case MYSQL_TYPE_YEAR:
|
2003-12-15 17:58:15 +02:00
|
|
|
return new Field_year((char*) 0, max_length, null_ptr, 0, Field::NONE,
|
|
|
|
name, table);
|
|
|
|
default:
|
|
|
|
/* This case should never be choosen */
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
/* If something goes awfully wrong, it's better to get a string than die */
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_ENUM:
|
|
|
|
case MYSQL_TYPE_SET:
|
2003-12-15 17:58:15 +02:00
|
|
|
case MYSQL_TYPE_VAR_STRING:
|
|
|
|
if (max_length > 255)
|
|
|
|
break; // If blob
|
|
|
|
return new Field_varstring(max_length, maybe_null, name, table,
|
|
|
|
collation.collation);
|
|
|
|
case MYSQL_TYPE_STRING:
|
|
|
|
if (max_length > 255) // If blob
|
|
|
|
break;
|
|
|
|
return new Field_string(max_length, maybe_null, name, table,
|
|
|
|
collation.collation);
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_TINY_BLOB:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
|
|
|
case MYSQL_TYPE_BLOB:
|
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2003-12-15 17:58:15 +02:00
|
|
|
break; // Blob handled outside of case
|
2003-08-27 19:11:54 -04:00
|
|
|
}
|
2003-12-15 17:58:15 +02:00
|
|
|
|
|
|
|
/* blob is special as it's generated for both blobs and long strings */
|
|
|
|
return new Field_blob(max_length, maybe_null, name, table,
|
|
|
|
collation.collation);
|
2003-08-27 19:11:54 -04:00
|
|
|
}
|
|
|
|
|
2003-12-15 17:58:15 +02:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
/* ARGSUSED */
|
|
|
|
void Item_field::make_field(Send_field *tmp_field)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
field->make_field(tmp_field);
|
2004-05-05 12:31:17 +03:00
|
|
|
DBUG_ASSERT(tmp_field->table_name);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (name)
|
|
|
|
tmp_field->col_name=name; // Use user supplied name
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-05-05 12:31:17 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*
|
2004-05-05 12:31:17 +03:00
|
|
|
Set a field:s value from a item
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void Item_field::save_org_in_field(Field *to)
|
|
|
|
{
|
|
|
|
if (field->is_null())
|
|
|
|
{
|
|
|
|
null_value=1;
|
2002-12-03 13:08:25 +02:00
|
|
|
set_field_to_null_with_conversions(to, 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
to->set_notnull();
|
|
|
|
field_conv(to,field);
|
|
|
|
null_value=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item_field::save_in_field(Field *to, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if (result_field->is_null())
|
|
|
|
{
|
|
|
|
null_value=1;
|
2002-12-03 13:08:25 +02:00
|
|
|
return set_field_to_null_with_conversions(to, no_conversions);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
to->set_notnull();
|
|
|
|
field_conv(to,result_field);
|
|
|
|
null_value=0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-16 10:32:45 +03:00
|
|
|
|
2002-10-16 22:48:51 +03:00
|
|
|
/*
|
|
|
|
Store null in field
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
save_in_field()
|
|
|
|
field Field where we want to store NULL
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This is used on INSERT.
|
|
|
|
Allow NULL to be inserted in timestamp and auto_increment values
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
0 ok
|
|
|
|
1 Field doesn't support NULL values and can't handle 'field = NULL'
|
|
|
|
*/
|
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item_null::save_in_field(Field *field, bool no_conversions)
|
2002-10-16 22:48:51 +03:00
|
|
|
{
|
2002-12-03 13:08:25 +02:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2002-10-16 22:48:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-16 10:32:45 +03:00
|
|
|
/*
|
|
|
|
Store null in field
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
save_safe_in_field()
|
|
|
|
field Field where we want to store NULL
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
0 ok
|
|
|
|
1 Field doesn't support NULL values
|
|
|
|
*/
|
|
|
|
|
2002-10-16 19:30:24 +03:00
|
|
|
int Item_null::save_safe_in_field(Field *field)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
return set_field_to_null(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-08-24 14:49:04 +03:00
|
|
|
int error;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (result_type() == STRING_RESULT ||
|
|
|
|
result_type() == REAL_RESULT &&
|
|
|
|
field->result_type() == STRING_RESULT)
|
|
|
|
{
|
|
|
|
String *result;
|
2003-08-05 12:52:37 +05:00
|
|
|
CHARSET_INFO *cs= collation.collation;
|
2000-07-31 21:29:14 +02:00
|
|
|
char buff[MAX_FIELD_WIDTH]; // Alloc buffer for small columns
|
2004-03-25 22:11:22 +02:00
|
|
|
str_value.set_quick(buff, sizeof(buff), cs);
|
2000-07-31 21:29:14 +02:00
|
|
|
result=val_str(&str_value);
|
|
|
|
if (null_value)
|
2004-04-28 03:37:45 +03:00
|
|
|
{
|
2004-05-05 21:24:21 +03:00
|
|
|
str_value.set_quick(0, 0, cs);
|
2002-12-03 13:08:25 +02:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2004-04-28 03:37:45 +03:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
field->set_notnull();
|
2002-08-24 14:49:04 +03:00
|
|
|
error=field->store(result->ptr(),result->length(),cs);
|
2002-05-17 16:29:52 +05:00
|
|
|
str_value.set_quick(0, 0, cs);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else if (result_type() == REAL_RESULT)
|
|
|
|
{
|
|
|
|
double nr=val();
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
2002-08-24 14:49:04 +03:00
|
|
|
error=field->store(nr);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
longlong nr=val_int();
|
|
|
|
if (null_value)
|
2002-12-03 13:08:25 +02:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2000-07-31 21:29:14 +02:00
|
|
|
field->set_notnull();
|
2002-08-24 14:49:04 +03:00
|
|
|
error=field->store(nr);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2004-03-16 13:26:37 +04:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-10-16 10:32:45 +03:00
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item_string::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
String *result;
|
|
|
|
result=val_str(&str_value);
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
2004-03-16 13:26:37 +04:00
|
|
|
return field->store(result->ptr(),result->length(),collation.collation);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-11-20 22:30:48 +02:00
|
|
|
int Item_uint::save_in_field(Field *field, bool no_conversions)
|
2003-11-16 17:37:15 +01:00
|
|
|
{
|
2003-11-21 00:17:46 +02:00
|
|
|
/*
|
|
|
|
TODO: To be fixed when wen have a
|
|
|
|
field->store(longlong, unsigned_flag) method
|
|
|
|
*/
|
2003-11-21 01:53:01 +02:00
|
|
|
return Item_int::save_in_field(field, no_conversions);
|
2003-11-16 17:37:15 +01:00
|
|
|
}
|
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
|
|
|
|
int Item_int::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
longlong nr=val_int();
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
2004-03-16 13:26:37 +04:00
|
|
|
return field->store(nr);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-03-20 13:36:26 +02:00
|
|
|
Item_num *Item_uint::neg()
|
|
|
|
{
|
|
|
|
return new Item_real(name, - ((double) value), 0, max_length);
|
|
|
|
}
|
2002-12-05 19:38:42 +02:00
|
|
|
|
2004-10-02 22:20:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
This function is only called during parsing. We will signal an error if
|
|
|
|
value is not a true double value (overflow)
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item_real::Item_real(const char *str_arg, uint length)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
char *end;
|
|
|
|
value= my_strntod(&my_charset_bin, (char*) str_arg, length, &end, &error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Note that we depend on that str_arg is null terminated, which is true
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
presentation= name=(char*) str_arg;
|
|
|
|
decimals=(uint8) nr_of_decimals(str_arg);
|
|
|
|
max_length=length;
|
|
|
|
fixed= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item_real::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
double nr=val();
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
2004-03-16 13:26:37 +04:00
|
|
|
return field->store(nr);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-09-01 20:30:48 +03:00
|
|
|
|
|
|
|
void Item_real::print(String *str)
|
|
|
|
{
|
|
|
|
if (presentation)
|
|
|
|
{
|
|
|
|
str->append(presentation);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char buffer[20];
|
|
|
|
String num(buffer, sizeof(buffer), &my_charset_bin);
|
|
|
|
num.set(value, decimals, &my_charset_bin);
|
|
|
|
str->append(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/****************************************************************************
|
|
|
|
** varbinary item
|
|
|
|
** In string context this is a binary string
|
|
|
|
** In number context this is a longlong value.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2001-01-25 22:38:26 +02:00
|
|
|
inline uint char_val(char X)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
return (uint) (X >= '0' && X <= '9' ? X-'0' :
|
|
|
|
X >= 'A' && X <= 'Z' ? X-'A'+10 :
|
|
|
|
X-'a'+10);
|
|
|
|
}
|
|
|
|
|
2003-04-27 22:12:08 +03:00
|
|
|
|
2002-10-25 13:58:32 +05:00
|
|
|
Item_varbinary::Item_varbinary(const char *str, uint str_length)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
name=(char*) str-2; // Lex makes this start with 0x
|
|
|
|
max_length=(str_length+1)/2;
|
|
|
|
char *ptr=(char*) sql_alloc(max_length+1);
|
|
|
|
if (!ptr)
|
|
|
|
return;
|
2003-01-29 17:31:20 +04:00
|
|
|
str_value.set(ptr,max_length,&my_charset_bin);
|
2000-07-31 21:29:14 +02:00
|
|
|
char *end=ptr+max_length;
|
|
|
|
if (max_length*2 != str_length)
|
|
|
|
*ptr++=char_val(*str++); // Not even, assume 0 prefix
|
|
|
|
while (ptr != end)
|
|
|
|
{
|
|
|
|
*ptr++= (char) (char_val(str[0])*16+char_val(str[1]));
|
|
|
|
str+=2;
|
|
|
|
}
|
|
|
|
*ptr=0; // Keep purify happy
|
2003-08-05 12:52:37 +05:00
|
|
|
collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
|
2004-03-20 13:36:26 +02:00
|
|
|
fixed= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
longlong Item_varbinary::val_int()
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
char *end=(char*) str_value.ptr()+str_value.length(),
|
|
|
|
*ptr=end-min(str_value.length(),sizeof(longlong));
|
|
|
|
|
|
|
|
ulonglong value=0;
|
|
|
|
for (; ptr != end ; ptr++)
|
|
|
|
value=(value << 8)+ (ulonglong) (uchar) *ptr;
|
|
|
|
return (longlong) value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item_varbinary::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-08-24 14:49:04 +03:00
|
|
|
int error;
|
2000-07-31 21:29:14 +02:00
|
|
|
field->set_notnull();
|
|
|
|
if (field->result_type() == STRING_RESULT)
|
|
|
|
{
|
2003-08-05 12:52:37 +05:00
|
|
|
error=field->store(str_value.ptr(),str_value.length(),collation.collation);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
longlong nr=val_int();
|
2002-08-24 14:49:04 +03:00
|
|
|
error=field->store(nr);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2004-03-16 13:26:37 +04:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
/*
|
|
|
|
Pack data in buffer for sending
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_null::send(Protocol *protocol, String *packet)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
return protocol->store_null();
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-12-11 09:17:51 +02:00
|
|
|
This is only called from items that is not of type item_field
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
bool Item::send(Protocol *protocol, String *buffer)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
bool result;
|
|
|
|
enum_field_types type;
|
2004-09-09 06:59:26 +03:00
|
|
|
LINT_INIT(result); // Will be set if null_value == 0
|
2002-12-11 09:17:51 +02:00
|
|
|
|
|
|
|
switch ((type=field_type())) {
|
|
|
|
default:
|
2002-12-14 17:43:01 +02:00
|
|
|
case MYSQL_TYPE_NULL:
|
|
|
|
case MYSQL_TYPE_DECIMAL:
|
|
|
|
case MYSQL_TYPE_ENUM:
|
|
|
|
case MYSQL_TYPE_SET:
|
|
|
|
case MYSQL_TYPE_TINY_BLOB:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
|
|
|
case MYSQL_TYPE_BLOB:
|
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2002-12-11 09:17:51 +02:00
|
|
|
case MYSQL_TYPE_STRING:
|
|
|
|
case MYSQL_TYPE_VAR_STRING:
|
|
|
|
{
|
|
|
|
String *res;
|
|
|
|
if ((res=val_str(buffer)))
|
2003-03-17 13:14:04 +04:00
|
|
|
result= protocol->store(res->ptr(),res->length(),res->charset());
|
2002-12-11 09:17:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
{
|
|
|
|
longlong nr;
|
|
|
|
nr= val_int();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_tiny(nr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
{
|
|
|
|
longlong nr;
|
|
|
|
nr= val_int();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_short(nr);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-14 17:43:01 +02:00
|
|
|
case MYSQL_TYPE_INT24:
|
2002-12-11 09:17:51 +02:00
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
{
|
|
|
|
longlong nr;
|
|
|
|
nr= val_int();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_long(nr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
{
|
|
|
|
longlong nr;
|
|
|
|
nr= val_int();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_longlong(nr, unsigned_flag);
|
|
|
|
break;
|
|
|
|
}
|
2003-10-20 18:52:45 +05:00
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
{
|
|
|
|
float nr;
|
2003-11-20 22:06:25 +02:00
|
|
|
nr= (float) val();
|
2003-10-20 18:52:45 +05:00
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store(nr, decimals, buffer);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-11 09:17:51 +02:00
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
{
|
|
|
|
double nr;
|
|
|
|
nr= val();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store(nr, decimals, buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
case MYSQL_TYPE_DATE:
|
2002-12-14 17:43:01 +02:00
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
2002-12-11 09:17:51 +02:00
|
|
|
{
|
|
|
|
TIME tm;
|
2003-11-03 14:01:59 +02:00
|
|
|
get_date(&tm, TIME_FUZZY_DATE);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (!null_value)
|
|
|
|
{
|
|
|
|
if (type == MYSQL_TYPE_DATE)
|
|
|
|
return protocol->store_date(&tm);
|
|
|
|
else
|
|
|
|
result= protocol->store(&tm);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_TIME:
|
|
|
|
{
|
|
|
|
TIME tm;
|
|
|
|
get_time(&tm);
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_time(&tm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (null_value)
|
|
|
|
result= protocol->store_null();
|
|
|
|
return result;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
|
|
|
|
bool Item_field::send(Protocol *protocol, String *buffer)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
return protocol->store(result_field);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*
|
2004-10-28 17:31:26 +03:00
|
|
|
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;
|
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
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;
|
|
|
|
|
2004-10-28 17:31:26 +03:00
|
|
|
++cur_match_degree;
|
2004-11-05 15:48:44 +02:00
|
|
|
if (cur_field->db_name && db_name)
|
|
|
|
{
|
2004-10-28 17:31:26 +03:00
|
|
|
/* If field_name is also qualified by a database name. */
|
2004-11-05 15:48:44 +02:00
|
|
|
if (strcmp(cur_field->db_name, db_name))
|
|
|
|
/* Same field names, different databases. */
|
|
|
|
return NULL;
|
2004-10-28 17:31:26 +03:00
|
|
|
++cur_match_degree;
|
2004-11-05 15:48:44 +02:00
|
|
|
}
|
2004-10-28 17:31:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_match_degree > found_match_degree)
|
|
|
|
{
|
|
|
|
found_match_degree= cur_match_degree;
|
|
|
|
found_group= cur_group;
|
|
|
|
}
|
2004-11-05 15:48:44 +02:00
|
|
|
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_printf_error(ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR),
|
|
|
|
MYF(0), find_item->full_name(), current_thd->where);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-10-28 17:31:26 +03:00
|
|
|
}
|
|
|
|
}
|
2004-11-05 15:48:44 +02:00
|
|
|
|
2004-10-28 17:31:26 +03:00
|
|
|
if (found_group)
|
|
|
|
return found_group->item;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
/*
|
|
|
|
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_ref *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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
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)))
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (*select_ref && !(*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-28 17:31:26 +03:00
|
|
|
/*
|
|
|
|
Resolve the name of a column reference.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Item_ref::fix_fields()
|
2004-11-02 18:23:15 +02:00
|
|
|
thd [in] current thread
|
|
|
|
tables [in] the tables in the FROM clause
|
|
|
|
reference [in/out] view column if this item was resolved to a view column
|
2004-10-28 17:31:26 +03:00
|
|
|
|
|
|
|
DESCRIPTION
|
2004-11-02 18:23:15 +02:00
|
|
|
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
|
2004-11-05 15:48:44 +02:00
|
|
|
used typically for columns in the HAVING clause which are not under
|
|
|
|
aggregate functions.
|
2004-10-28 17:31:26 +03:00
|
|
|
|
|
|
|
NOTES
|
|
|
|
The name resolution algorithm used is:
|
2004-11-02 18:23:15 +02:00
|
|
|
|
2004-10-28 17:31:26 +03:00
|
|
|
resolve_extended([T_j].col_ref_i)
|
|
|
|
{
|
|
|
|
Search for a column or derived column named col_ref_i [in table T_j]
|
2004-11-05 15:48:44 +02:00
|
|
|
in the SELECT and GROUP clauses of Q.
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2004-11-02 18:23:15 +02:00
|
|
|
if such a column is NOT found AND // Lookup in outer queries.
|
|
|
|
there are outer queries
|
2004-10-28 17:31:26 +03:00
|
|
|
{
|
|
|
|
for each outer query Q_k beginning from the inner-most one
|
|
|
|
{
|
2004-11-05 15:48:44 +02:00
|
|
|
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
|
2004-10-28 17:31:26 +03:00
|
|
|
{
|
|
|
|
search for a column or derived column named col_ref_i
|
|
|
|
[in table T_j] in the FROM clause of Q_k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-02 18:23:15 +02:00
|
|
|
|
|
|
|
This procedure treats GROUP BY and SELECT clauses as one namespace for
|
|
|
|
column references in HAVING.
|
2004-10-28 17:31:26 +03:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
TRUE if error
|
|
|
|
FALSE on success
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-07-16 01:15:55 +03:00
|
|
|
bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-03-17 14:26:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2004-10-28 17:31:26 +03:00
|
|
|
SELECT_LEX *current_sel= thd->lex->current_select;
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!ref)
|
|
|
|
{
|
2004-10-28 17:31:26 +03:00
|
|
|
SELECT_LEX_UNIT *prev_unit= current_sel->master_unit();
|
|
|
|
SELECT_LEX *outer_sel= prev_unit->outer_select();
|
2004-11-05 15:48:44 +02:00
|
|
|
ORDER *group_list= (ORDER*) current_sel->group_list.first;
|
|
|
|
bool ambiguous_fields= FALSE;
|
|
|
|
Item **group_by_ref= NULL;
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
if (!(ref= resolve_ref_in_select_and_group(thd, this, current_sel)))
|
|
|
|
return TRUE; /* Some error occured (e.g. ambigous names). */
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
if (ref == not_found_item) /* This reference was not resolved. */
|
2002-07-01 14:14:51 +03:00
|
|
|
{
|
|
|
|
/*
|
2004-11-05 15:48:44 +02:00
|
|
|
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.
|
2002-07-01 14:14:51 +03:00
|
|
|
*/
|
2004-11-05 15:48:44 +02:00
|
|
|
if (outer_sel && (current_sel->master_unit()->first_select()->linkage !=
|
|
|
|
DERIVED_TABLE_TYPE))
|
2002-11-24 21:10:52 +02:00
|
|
|
{
|
2004-11-05 15:48:44 +02:00
|
|
|
TABLE_LIST *table_list;
|
|
|
|
Field *tmp= (Field*) not_found_field;
|
|
|
|
SELECT_LEX *last= 0;
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
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)
|
2004-09-01 23:27:40 +03:00
|
|
|
{
|
2004-11-05 15:48:44 +02:00
|
|
|
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)
|
2004-09-01 23:27:40 +03:00
|
|
|
{
|
2004-11-05 15:48:44 +02:00
|
|
|
DBUG_ASSERT(*ref && (*ref)->fixed);
|
|
|
|
/*
|
|
|
|
Avoid crash in case of error.
|
|
|
|
TODO: what does this comment mean?
|
|
|
|
*/
|
|
|
|
prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
|
|
|
|
prev_subselect_item->const_item_cache&= (*ref)->const_item();
|
|
|
|
break;
|
2004-09-01 23:27:40 +03:00
|
|
|
}
|
2004-11-05 15:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 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 SELECT list, or 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 && place != SELECT_LIST) ||
|
|
|
|
(!outer_sel->with_sum_func &&
|
|
|
|
outer_sel->group_list.elements == 0)))
|
|
|
|
{
|
|
|
|
if ((tmp= find_field_in_tables(thd, this, table_list, reference,
|
|
|
|
IGNORE_EXCEPT_NON_UNIQUE, TRUE)) !=
|
|
|
|
not_found_field)
|
2004-09-01 23:27:40 +03:00
|
|
|
{
|
2004-11-05 15:48:44 +02:00
|
|
|
if (tmp != view_ref_found)
|
|
|
|
{
|
|
|
|
prev_subselect_item->used_tables_cache|= tmp->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;
|
2004-09-01 23:27:40 +03:00
|
|
|
}
|
|
|
|
}
|
2003-10-17 00:36:01 +03:00
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
/* 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;
|
2003-10-17 00:36:01 +03:00
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
if (outer_sel->master_unit()->first_select()->linkage ==
|
|
|
|
DERIVED_TABLE_TYPE)
|
|
|
|
break; /* Do not consider derived tables. */
|
|
|
|
}
|
2002-10-08 14:50:12 +03:00
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
DBUG_ASSERT(ref);
|
|
|
|
if (!tmp)
|
|
|
|
return TRUE;
|
|
|
|
else if (ref == not_found_item && tmp == not_found_field)
|
|
|
|
{
|
|
|
|
my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0),
|
|
|
|
this->full_name(), current_thd->where);
|
|
|
|
ref= 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (tmp != not_found_field)
|
|
|
|
{
|
|
|
|
ref= 0; // To prevent "delete *ref;" on ~Item_ref() of this item
|
|
|
|
if (tmp != view_ref_found)
|
|
|
|
{
|
|
|
|
Item_field* fld= new Item_field(tmp);
|
|
|
|
if (!((*reference)= fld))
|
|
|
|
return TRUE;
|
|
|
|
mark_as_dependent(thd, last, current_sel, fld);
|
|
|
|
register_item_tree_changing(reference);
|
|
|
|
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
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(*ref && (*ref)->fixed);
|
|
|
|
mark_as_dependent(thd, last, current_sel, this);
|
|
|
|
}
|
2002-07-01 14:14:51 +03:00
|
|
|
}
|
2004-10-28 17:31:26 +03:00
|
|
|
else
|
2003-01-25 02:25:52 +02:00
|
|
|
{
|
2004-11-05 15:48:44 +02:00
|
|
|
/* The current reference cannot be resolved in this query. */
|
|
|
|
my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0),
|
|
|
|
this->full_name(), current_thd->where);
|
|
|
|
return TRUE;
|
2003-01-25 02:25:52 +02:00
|
|
|
}
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-01-25 02:25:52 +02:00
|
|
|
|
2003-05-14 21:51:33 +03:00
|
|
|
/*
|
|
|
|
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.
|
2004-11-05 15:48:44 +02:00
|
|
|
|
|
|
|
TODO: this comment is impossible to understand.
|
2003-05-14 21:51:33 +03:00
|
|
|
*/
|
2003-03-17 15:16:26 +02:00
|
|
|
if (((*ref)->with_sum_func && name &&
|
2003-05-14 21:51:33 +03:00
|
|
|
(depended_from ||
|
2004-11-05 15:48:44 +02:00
|
|
|
!(current_sel->linkage != GLOBAL_OPTIONS_TYPE &&
|
|
|
|
current_sel->having_fix_field))) ||
|
2002-11-21 11:01:33 +02:00
|
|
|
!(*ref)->fixed)
|
|
|
|
{
|
|
|
|
my_error(ER_ILLEGAL_REFERENCE, MYF(0), name,
|
|
|
|
((*ref)->with_sum_func?
|
2004-11-05 15:48:44 +02:00
|
|
|
"reference to group function":
|
2002-11-21 11:01:33 +02:00
|
|
|
"forward reference in item list"));
|
2004-10-28 17:31:26 +03:00
|
|
|
return TRUE;
|
2002-11-21 11:01:33 +02:00
|
|
|
}
|
2003-01-29 19:42:39 +02:00
|
|
|
max_length= (*ref)->max_length;
|
|
|
|
maybe_null= (*ref)->maybe_null;
|
|
|
|
decimals= (*ref)->decimals;
|
2003-07-30 14:15:25 +05:00
|
|
|
collation.set((*ref)->collation);
|
2003-03-26 18:37:38 +02:00
|
|
|
with_sum_func= (*ref)->with_sum_func;
|
2002-11-21 11:01:33 +02:00
|
|
|
fixed= 1;
|
2003-02-14 11:47:41 +02:00
|
|
|
|
2002-11-15 20:32:09 +02:00
|
|
|
if (ref && (*ref)->check_cols(1))
|
2004-10-28 17:31:26 +03:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-02-14 11:47:41 +02:00
|
|
|
|
2003-12-30 14:08:19 +04:00
|
|
|
void Item_ref::cleanup()
|
|
|
|
{
|
2004-02-08 20:14:13 +02:00
|
|
|
DBUG_ENTER("Item_ref::cleanup");
|
2003-12-30 14:08:19 +04:00
|
|
|
Item_ident::cleanup();
|
2004-08-26 14:34:56 +03:00
|
|
|
result_field= 0;
|
2003-12-30 14:08:19 +04:00
|
|
|
if (hook_ptr)
|
|
|
|
*hook_ptr= orig_item;
|
2004-02-08 20:14:13 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2003-12-30 14:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-16 15:54:47 +03:00
|
|
|
void Item_ref::print(String *str)
|
|
|
|
{
|
|
|
|
if (ref && *ref)
|
|
|
|
(*ref)->print(str);
|
|
|
|
else
|
|
|
|
Item_ident::print(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-26 13:11:06 +03:00
|
|
|
bool Item_ref::send(Protocol *prot, String *tmp)
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
return prot->store(result_field);
|
|
|
|
return (*ref)->send(prot, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-26 14:34:56 +03:00
|
|
|
double Item_ref::val_result()
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
|
|
|
return 0.0;
|
|
|
|
return result_field->val_real();
|
|
|
|
}
|
|
|
|
return val();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item_ref::val_int_result()
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
2004-08-30 11:09:56 +02:00
|
|
|
return 0;
|
2004-08-26 14:34:56 +03:00
|
|
|
return result_field->val_int();
|
|
|
|
}
|
|
|
|
return val_int();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_ref::str_result(String* str)
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
|
|
|
return 0;
|
|
|
|
str->set_charset(str_value.charset());
|
|
|
|
return result_field->val_str(str, &str_value);
|
|
|
|
}
|
|
|
|
return val_str(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-16 15:54:47 +03:00
|
|
|
void Item_ref_null_helper::print(String *str)
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
str->append("<ref_null_helper>(", 18);
|
2003-10-16 15:54:47 +03:00
|
|
|
if (ref && *ref)
|
|
|
|
(*ref)->print(str);
|
|
|
|
else
|
|
|
|
str->append('?');
|
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_null_helper::print(String *str)
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
str->append("<null_helper>(", 14);
|
2003-10-16 15:54:47 +03:00
|
|
|
store->print(str);
|
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-05 14:07:24 +04:00
|
|
|
bool Item_default_value::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
2003-01-22 20:08:12 +04:00
|
|
|
return item->type() == DEFAULT_VALUE_ITEM &&
|
2003-01-05 14:07:24 +04:00
|
|
|
((Item_default_value *)item)->arg->eq(arg, binary_cmp);
|
|
|
|
}
|
|
|
|
|
2003-02-14 11:47:41 +02:00
|
|
|
|
2004-02-18 01:08:52 +02:00
|
|
|
bool Item_default_value::fix_fields(THD *thd,
|
|
|
|
struct st_table_list *table_list,
|
|
|
|
Item **items)
|
2003-01-05 14:07:24 +04:00
|
|
|
{
|
2004-10-02 22:20:08 +03:00
|
|
|
Item_field *field_arg;
|
|
|
|
Field *def_field;
|
2004-03-17 14:26:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2004-10-02 22:20:08 +03:00
|
|
|
|
2003-01-21 20:20:46 +04:00
|
|
|
if (!arg)
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
|
|
|
fixed= 1;
|
2004-02-18 01:08:52 +02:00
|
|
|
return 0;
|
2004-03-18 15:14:36 +02:00
|
|
|
}
|
2004-02-18 01:08:52 +02:00
|
|
|
if (arg->fix_fields(thd, table_list, &arg))
|
|
|
|
return 1;
|
|
|
|
|
2003-01-05 14:07:24 +04:00
|
|
|
if (arg->type() == REF_ITEM)
|
|
|
|
{
|
|
|
|
Item_ref *ref= (Item_ref *)arg;
|
|
|
|
if (ref->ref[0]->type() != FIELD_ITEM)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
arg= ref->ref[0];
|
|
|
|
}
|
2004-10-02 22:20:08 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of())))
|
2003-01-05 14:07:24 +04:00
|
|
|
return 1;
|
|
|
|
memcpy(def_field, field_arg->field, field_arg->field->size_of());
|
2003-05-03 01:16:56 +02:00
|
|
|
def_field->move_field(def_field->table->default_values -
|
|
|
|
def_field->table->record[0]);
|
2003-01-05 14:07:24 +04:00
|
|
|
set_field(def_field);
|
2004-03-18 15:14:36 +02:00
|
|
|
fixed= 1;
|
2003-01-05 14:07:24 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-05 17:56:11 +04:00
|
|
|
void Item_default_value::print(String *str)
|
|
|
|
{
|
2003-01-21 20:20:46 +04:00
|
|
|
if (!arg)
|
|
|
|
{
|
2003-10-31 11:52:01 +02:00
|
|
|
str->append("default", 7);
|
2003-01-22 20:08:12 +04:00
|
|
|
return;
|
2003-01-21 20:20:46 +04:00
|
|
|
}
|
2003-10-31 11:52:01 +02:00
|
|
|
str->append("default(", 8);
|
2003-01-05 17:56:11 +04:00
|
|
|
arg->print(str);
|
|
|
|
str->append(')');
|
|
|
|
}
|
2002-12-03 13:08:25 +02:00
|
|
|
|
2003-05-03 01:16:56 +02:00
|
|
|
bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
|
|
|
return item->type() == INSERT_VALUE_ITEM &&
|
|
|
|
((Item_default_value *)item)->arg->eq(arg, binary_cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-28 12:18:13 +02:00
|
|
|
bool Item_insert_value::fix_fields(THD *thd,
|
|
|
|
struct st_table_list *table_list,
|
|
|
|
Item **items)
|
2003-05-03 01:16:56 +02:00
|
|
|
{
|
2004-03-17 14:26:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2004-02-18 01:08:52 +02:00
|
|
|
if (arg->fix_fields(thd, table_list, &arg))
|
|
|
|
return 1;
|
|
|
|
|
2003-05-03 01:16:56 +02:00
|
|
|
if (arg->type() == REF_ITEM)
|
|
|
|
{
|
|
|
|
Item_ref *ref= (Item_ref *)arg;
|
|
|
|
if (ref->ref[0]->type() != FIELD_ITEM)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
arg= ref->ref[0];
|
|
|
|
}
|
|
|
|
Item_field *field_arg= (Item_field *)arg;
|
|
|
|
if (field_arg->field->table->insert_values)
|
|
|
|
{
|
|
|
|
Field *def_field= (Field*) sql_alloc(field_arg->field->size_of());
|
|
|
|
if (!def_field)
|
|
|
|
return 1;
|
|
|
|
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]);
|
|
|
|
set_field(def_field);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-28 12:18:13 +02:00
|
|
|
Field *tmp_field= field_arg->field;
|
2003-05-03 01:16:56 +02:00
|
|
|
/* charset doesn't matter here, it's to avoid sigsegv only */
|
2003-11-28 12:18:13 +02:00
|
|
|
set_field(new Field_null(0, 0, Field::NONE, tmp_field->field_name,
|
|
|
|
tmp_field->table, &my_charset_bin));
|
2003-05-03 01:16:56 +02:00
|
|
|
}
|
2004-03-18 15:14:36 +02:00
|
|
|
fixed= 1;
|
2003-05-03 01:16:56 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item_insert_value::print(String *str)
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
str->append("values(", 7);
|
2003-05-03 01:16:56 +02:00
|
|
|
arg->print(str);
|
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
2004-09-07 16:29:46 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Bind item representing field of row being changed in trigger
|
|
|
|
to appropriate Field object.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
setup_field()
|
|
|
|
thd - current thread context
|
|
|
|
table - table of trigger (and where we looking for fields)
|
|
|
|
event - type of trigger event
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
This function does almost the same as fix_fields() for Item_field
|
|
|
|
but is invoked during trigger definition parsing and takes TABLE
|
|
|
|
object as its argument.
|
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
0 ok
|
|
|
|
1 field was not found.
|
|
|
|
*/
|
|
|
|
bool Item_trigger_field::setup_field(THD *thd, TABLE *table,
|
|
|
|
enum trg_event_type event)
|
|
|
|
{
|
|
|
|
bool result= 1;
|
|
|
|
uint field_idx= (uint)-1;
|
|
|
|
bool save_set_query_id= thd->set_query_id;
|
|
|
|
|
|
|
|
/* TODO: Think more about consequences of this step. */
|
|
|
|
thd->set_query_id= 0;
|
|
|
|
|
|
|
|
if (find_field_in_real_table(thd, table, field_name,
|
|
|
|
strlen(field_name), 0, 0,
|
|
|
|
&field_idx))
|
|
|
|
{
|
|
|
|
field= (row_version == OLD_ROW && event == TRG_EVENT_UPDATE) ?
|
|
|
|
table->triggers->old_field[field_idx] :
|
|
|
|
table->field[field_idx];
|
|
|
|
result= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
thd->set_query_id= save_set_query_id;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_trigger_field::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
|
|
|
return item->type() == TRIGGER_FIELD_ITEM &&
|
|
|
|
row_version == ((Item_trigger_field *)item)->row_version &&
|
|
|
|
!my_strcasecmp(system_charset_info, field_name,
|
|
|
|
((Item_trigger_field *)item)->field_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_trigger_field::fix_fields(THD *thd,
|
|
|
|
TABLE_LIST *table_list,
|
|
|
|
Item **items)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Since trigger is object tightly associated with TABLE object most
|
|
|
|
of its set up can be performed during trigger loading i.e. trigger
|
|
|
|
parsing! So we have little to do in fix_fields. :)
|
|
|
|
FIXME may be we still should bother about permissions here.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(fixed == 0);
|
|
|
|
// QQ: May be this should be moved to setup_field?
|
|
|
|
set_field(field);
|
|
|
|
fixed= 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_trigger_field::print(String *str)
|
|
|
|
{
|
|
|
|
str->append((row_version == NEW_ROW) ? "NEW" : "OLD", 3);
|
|
|
|
str->append('.');
|
|
|
|
str->append(field_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_trigger_field::cleanup()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Since special nature of Item_trigger_field we should not do most of
|
|
|
|
things from Item_field::cleanup() or Item_ident::cleanup() here.
|
|
|
|
*/
|
|
|
|
Item::cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*
|
2002-12-03 13:08:25 +02:00
|
|
|
If item is a const function, calculate it and return a const item
|
|
|
|
The original item is freed if not returned
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
Item_result item_cmp_type(Item_result a,Item_result b)
|
|
|
|
{
|
|
|
|
if (a == STRING_RESULT && b == STRING_RESULT)
|
|
|
|
return STRING_RESULT;
|
2003-12-10 22:26:31 +03:00
|
|
|
if (a == INT_RESULT && b == INT_RESULT)
|
2000-07-31 21:29:14 +02:00
|
|
|
return INT_RESULT;
|
2002-11-15 20:32:09 +02:00
|
|
|
else if (a == ROW_RESULT || b == ROW_RESULT)
|
|
|
|
return ROW_RESULT;
|
2003-12-10 22:26:31 +03:00
|
|
|
return REAL_RESULT;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item *resolve_const_item(Item *item,Item *comp_item)
|
|
|
|
{
|
|
|
|
if (item->basic_const_item())
|
|
|
|
return item; // Can't be better
|
|
|
|
Item_result res_type=item_cmp_type(comp_item->result_type(),
|
|
|
|
item->result_type());
|
|
|
|
char *name=item->name; // Alloced by sql_alloc
|
|
|
|
|
|
|
|
if (res_type == STRING_RESULT)
|
|
|
|
{
|
|
|
|
char buff[MAX_FIELD_WIDTH];
|
2003-01-29 17:31:20 +04:00
|
|
|
String tmp(buff,sizeof(buff),&my_charset_bin),*result;
|
2000-07-31 21:29:14 +02:00
|
|
|
result=item->val_str(&tmp);
|
|
|
|
if (item->null_value)
|
|
|
|
return new Item_null(name);
|
|
|
|
uint length=result->length();
|
|
|
|
char *tmp_str=sql_strmake(result->ptr(),length);
|
2002-12-20 18:08:49 +04:00
|
|
|
return new Item_string(name,tmp_str,length,result->charset());
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
if (res_type == INT_RESULT)
|
|
|
|
{
|
|
|
|
longlong result=item->val_int();
|
|
|
|
uint length=item->max_length;
|
|
|
|
bool null_value=item->null_value;
|
|
|
|
return (null_value ? (Item*) new Item_null(name) :
|
|
|
|
(Item*) new Item_int(name,result,length));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // It must REAL_RESULT
|
|
|
|
double result=item->val();
|
|
|
|
uint length=item->max_length,decimals=item->decimals;
|
|
|
|
bool null_value=item->null_value;
|
|
|
|
return (null_value ? (Item*) new Item_null(name) :
|
|
|
|
(Item*) new Item_real(name,result,decimals,length));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Return true if the value stored in the field is equal to the const item
|
|
|
|
We need to use this on the range optimizer because in some cases
|
|
|
|
we can't store the value in the field without some precision/character loss.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool field_is_equal_to_item(Field *field,Item *item)
|
|
|
|
{
|
|
|
|
|
|
|
|
Item_result res_type=item_cmp_type(field->result_type(),
|
|
|
|
item->result_type());
|
|
|
|
if (res_type == STRING_RESULT)
|
|
|
|
{
|
|
|
|
char item_buff[MAX_FIELD_WIDTH];
|
|
|
|
char field_buff[MAX_FIELD_WIDTH];
|
2003-01-29 17:31:20 +04:00
|
|
|
String item_tmp(item_buff,sizeof(item_buff),&my_charset_bin),*item_result;
|
|
|
|
String field_tmp(field_buff,sizeof(field_buff),&my_charset_bin);
|
2000-07-31 21:29:14 +02:00
|
|
|
item_result=item->val_str(&item_tmp);
|
|
|
|
if (item->null_value)
|
|
|
|
return 1; // This must be true
|
2004-04-06 21:35:26 +02:00
|
|
|
field->val_str(&field_tmp);
|
2004-02-16 10:03:25 +02:00
|
|
|
return !stringcmp(&field_tmp,item_result);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
if (res_type == INT_RESULT)
|
|
|
|
return 1; // Both where of type int
|
|
|
|
double result=item->val();
|
|
|
|
if (item->null_value)
|
|
|
|
return 1;
|
|
|
|
return result == field->val_real();
|
|
|
|
}
|
|
|
|
|
2002-12-19 07:38:33 +02:00
|
|
|
Item_cache* Item_cache::get_cache(Item_result type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case INT_RESULT:
|
|
|
|
return new Item_cache_int();
|
|
|
|
case REAL_RESULT:
|
|
|
|
return new Item_cache_real();
|
|
|
|
case STRING_RESULT:
|
|
|
|
return new Item_cache_str();
|
2002-12-19 21:15:09 +02:00
|
|
|
case ROW_RESULT:
|
|
|
|
return new Item_cache_row();
|
2002-12-19 07:38:33 +02:00
|
|
|
default:
|
|
|
|
// should never be in real life
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-16 15:54:47 +03:00
|
|
|
|
|
|
|
void Item_cache::print(String *str)
|
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
str->append("<cache>(", 8);
|
2003-10-16 15:54:47 +03:00
|
|
|
if (example)
|
|
|
|
example->print(str);
|
|
|
|
else
|
|
|
|
Item::print(str);
|
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_cache_int::store(Item *item)
|
|
|
|
{
|
|
|
|
value= item->val_int_result();
|
|
|
|
null_value= item->null_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_cache_real::store(Item *item)
|
|
|
|
{
|
|
|
|
value= item->val_result();
|
|
|
|
null_value= item->null_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-19 07:38:33 +02:00
|
|
|
void Item_cache_str::store(Item *item)
|
|
|
|
{
|
2003-08-11 11:51:33 +03:00
|
|
|
value_buff.set(buffer, sizeof(buffer), item->collation.collation);
|
2003-06-26 15:07:42 +03:00
|
|
|
value= item->str_result(&value_buff);
|
2002-12-19 07:38:33 +02:00
|
|
|
if ((null_value= item->null_value))
|
|
|
|
value= 0;
|
2003-06-26 15:07:42 +03:00
|
|
|
else if (value != &value_buff)
|
2002-12-19 07:38:33 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
We copy string value to avoid changing value if 'item' is table field
|
|
|
|
in queries like following (where t1.c is varchar):
|
|
|
|
select a,
|
|
|
|
(select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),
|
|
|
|
(select c from t1 where a=t2.a)
|
|
|
|
from t2;
|
|
|
|
*/
|
2003-06-26 15:07:42 +03:00
|
|
|
value_buff.copy(*value);
|
|
|
|
value= &value_buff;
|
2002-12-19 07:38:33 +02:00
|
|
|
}
|
|
|
|
}
|
2003-11-23 02:01:15 +02:00
|
|
|
|
|
|
|
|
2002-12-19 07:38:33 +02:00
|
|
|
double Item_cache_str::val()
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2003-01-16 17:17:07 +04:00
|
|
|
int err;
|
2002-12-19 07:38:33 +02:00
|
|
|
if (value)
|
2003-01-14 14:28:36 +02:00
|
|
|
return my_strntod(value->charset(), (char*) value->ptr(),
|
2003-01-16 17:17:07 +04:00
|
|
|
value->length(), (char**) 0, &err);
|
2002-12-19 07:38:33 +02:00
|
|
|
else
|
|
|
|
return (double)0;
|
|
|
|
}
|
2003-11-23 02:01:15 +02:00
|
|
|
|
|
|
|
|
2002-12-19 07:38:33 +02:00
|
|
|
longlong Item_cache_str::val_int()
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2003-01-16 17:17:07 +04:00
|
|
|
int err;
|
2002-12-19 07:38:33 +02:00
|
|
|
if (value)
|
|
|
|
return my_strntoll(value->charset(), value->ptr(),
|
2003-01-16 17:17:07 +04:00
|
|
|
value->length(), 10, (char**) 0, &err);
|
2002-12-19 07:38:33 +02:00
|
|
|
else
|
|
|
|
return (longlong)0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
bool Item_cache_row::allocate(uint num)
|
|
|
|
{
|
2002-12-28 01:01:05 +02:00
|
|
|
item_count= num;
|
2002-12-19 21:15:09 +02:00
|
|
|
THD *thd= current_thd;
|
2002-12-28 01:01:05 +02:00
|
|
|
return (!(values=
|
|
|
|
(Item_cache **) thd->calloc(sizeof(Item_cache *)*item_count)));
|
2002-12-19 21:15:09 +02:00
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
bool Item_cache_row::setup(Item * item)
|
|
|
|
{
|
2003-10-16 15:54:47 +03:00
|
|
|
example= item;
|
2002-12-19 21:15:09 +02:00
|
|
|
if (!values && allocate(item->cols()))
|
|
|
|
return 1;
|
2002-12-28 01:01:05 +02:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
2002-12-19 21:15:09 +02:00
|
|
|
{
|
2002-12-31 18:39:16 +02:00
|
|
|
Item *el= item->el(i);
|
2003-01-02 12:24:33 +02:00
|
|
|
Item_cache *tmp;
|
|
|
|
if (!(tmp= values[i]= Item_cache::get_cache(el->result_type())))
|
2002-12-19 21:15:09 +02:00
|
|
|
return 1;
|
2003-01-02 12:24:33 +02:00
|
|
|
tmp->setup(el);
|
2002-12-19 21:15:09 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
void Item_cache_row::store(Item * item)
|
|
|
|
{
|
|
|
|
null_value= 0;
|
|
|
|
item->bring_value();
|
2002-12-28 01:01:05 +02:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
2002-12-19 21:15:09 +02:00
|
|
|
{
|
|
|
|
values[i]->store(item->el(i));
|
|
|
|
null_value|= values[i]->null_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
void Item_cache_row::illegal_method_call(const char *method)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_cache_row::illegal_method_call");
|
|
|
|
DBUG_PRINT("error", ("!!! %s method was called for row item", method));
|
|
|
|
DBUG_ASSERT(0);
|
2003-10-06 22:35:05 +03:00
|
|
|
my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
|
2002-12-19 21:15:09 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
bool Item_cache_row::check_cols(uint c)
|
|
|
|
{
|
2002-12-28 01:01:05 +02:00
|
|
|
if (c != item_count)
|
2002-12-19 21:15:09 +02:00
|
|
|
{
|
2003-10-06 22:35:05 +03:00
|
|
|
my_error(ER_OPERAND_COLUMNS, MYF(0), c);
|
2002-12-19 21:15:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
bool Item_cache_row::null_inside()
|
|
|
|
{
|
2002-12-28 01:01:05 +02:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
2002-12-19 21:15:09 +02:00
|
|
|
{
|
|
|
|
if (values[i]->cols() > 1)
|
|
|
|
{
|
|
|
|
if (values[i]->null_inside())
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
values[i]->val_int();
|
|
|
|
if (values[i]->null_value)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
void Item_cache_row::bring_value()
|
|
|
|
{
|
2002-12-28 01:01:05 +02:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
2002-12-19 21:15:09 +02:00
|
|
|
values[i]->bring_value();
|
|
|
|
return;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
|
|
|
Item_type_holder::Item_type_holder(THD *thd, Item *item)
|
2004-01-20 20:55:47 +04:00
|
|
|
:Item(thd, item), item_type(item->result_type()),
|
|
|
|
orig_type(item_type)
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(item->fixed);
|
2003-11-23 21:26:43 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
It is safe assign pointer on field, because it will be used just after
|
|
|
|
all JOIN::prepare calls and before any SELECT execution
|
|
|
|
*/
|
2003-11-23 02:01:15 +02:00
|
|
|
if (item->type() == Item::FIELD_ITEM)
|
2003-11-23 21:26:43 +02:00
|
|
|
field_example= ((Item_field*) item)->field;
|
2003-11-23 02:01:15 +02:00
|
|
|
else
|
|
|
|
field_example= 0;
|
2004-06-16 16:06:30 +03:00
|
|
|
max_length= real_length(item);
|
2003-11-25 23:52:10 +02:00
|
|
|
collation.set(item->collation);
|
2003-11-23 02:01:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-25 23:52:10 +02:00
|
|
|
/*
|
|
|
|
STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT
|
|
|
|
|
|
|
|
ROW_RESULT should never appear in Item_type_holder::join_types,
|
|
|
|
but it is included in following table just to make table full
|
|
|
|
(there DBUG_ASSERT in function to catch ROW_RESULT)
|
|
|
|
*/
|
2003-11-23 02:01:15 +02:00
|
|
|
static Item_result type_convertor[4][4]=
|
|
|
|
{{STRING_RESULT, STRING_RESULT, STRING_RESULT, ROW_RESULT},
|
|
|
|
{STRING_RESULT, REAL_RESULT, REAL_RESULT, ROW_RESULT},
|
|
|
|
{STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT},
|
|
|
|
{ROW_RESULT, ROW_RESULT, ROW_RESULT, ROW_RESULT}};
|
|
|
|
|
2003-11-25 23:52:10 +02:00
|
|
|
bool Item_type_holder::join_types(THD *thd, Item *item)
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
2004-06-16 16:06:30 +03:00
|
|
|
uint32 new_length= real_length(item);
|
2003-11-23 02:01:15 +02:00
|
|
|
bool change_field= 0, skip_store_field= 0;
|
|
|
|
Item_result new_type= type_convertor[item_type][item->result_type()];
|
|
|
|
|
|
|
|
// we have both fields
|
|
|
|
if (field_example && item->type() == Item::FIELD_ITEM)
|
|
|
|
{
|
|
|
|
Field *field= ((Item_field *)item)->field;
|
2003-11-23 21:26:43 +02:00
|
|
|
if (field_example->field_cast_type() != field->field_cast_type())
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
2003-11-23 21:26:43 +02:00
|
|
|
if (!(change_field=
|
|
|
|
field_example->field_cast_compatible(field->field_cast_type())))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if old field can't store value of 'worse' new field we will make
|
|
|
|
decision about result field type based only on Item result type
|
|
|
|
*/
|
|
|
|
if (!field->field_cast_compatible(field_example->field_cast_type()))
|
|
|
|
skip_store_field= 1;
|
|
|
|
}
|
2003-11-23 02:01:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// size/type should be changed
|
|
|
|
if (change_field ||
|
|
|
|
(new_type != item_type) ||
|
2004-06-16 16:06:30 +03:00
|
|
|
(max_length < new_length) ||
|
2003-11-23 02:01:15 +02:00
|
|
|
((new_type == INT_RESULT) &&
|
|
|
|
(decimals < item->decimals)) ||
|
2003-11-25 23:52:10 +02:00
|
|
|
(!maybe_null && item->maybe_null) ||
|
|
|
|
(item_type == STRING_RESULT && new_type == STRING_RESULT &&
|
|
|
|
!my_charset_same(collation.collation, item->collation.collation)))
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
|
|
|
// new field has some parameters worse then current
|
|
|
|
skip_store_field|= (change_field &&
|
2004-06-16 16:06:30 +03:00
|
|
|
(max_length > new_length) ||
|
2003-11-23 02:01:15 +02:00
|
|
|
((new_type == INT_RESULT) &&
|
|
|
|
(decimals > item->decimals)) ||
|
2003-11-25 23:52:10 +02:00
|
|
|
(maybe_null && !item->maybe_null) ||
|
|
|
|
(item_type == STRING_RESULT &&
|
|
|
|
new_type == STRING_RESULT &&
|
|
|
|
!my_charset_same(collation.collation,
|
|
|
|
item->collation.collation)));
|
2003-11-23 21:26:43 +02:00
|
|
|
/*
|
|
|
|
It is safe assign pointer on field, because it will be used just after
|
|
|
|
all JOIN::prepare calls and before any SELECT execution
|
|
|
|
*/
|
2003-11-23 02:01:15 +02:00
|
|
|
if (skip_store_field || item->type() != Item::FIELD_ITEM)
|
|
|
|
field_example= 0;
|
|
|
|
else
|
2003-11-23 21:26:43 +02:00
|
|
|
field_example= ((Item_field*) item)->field;
|
|
|
|
|
2003-11-25 23:52:10 +02:00
|
|
|
const char *old_cs= collation.collation->name,
|
|
|
|
*old_derivation= collation.derivation_name();
|
|
|
|
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");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-06-16 16:06:30 +03:00
|
|
|
max_length= max(max_length, new_length);
|
2003-11-23 02:01:15 +02:00
|
|
|
decimals= max(decimals, item->decimals);
|
|
|
|
maybe_null|= item->maybe_null;
|
|
|
|
item_type= new_type;
|
|
|
|
}
|
|
|
|
DBUG_ASSERT(item_type != ROW_RESULT);
|
2003-11-25 23:52:10 +02:00
|
|
|
return 0;
|
2003-11-23 02:01:15 +02:00
|
|
|
}
|
|
|
|
|
2004-06-16 16:06:30 +03:00
|
|
|
uint32 Item_type_holder::real_length(Item *item)
|
|
|
|
{
|
|
|
|
if (item->type() == Item::FIELD_ITEM)
|
|
|
|
{
|
2004-06-17 13:48:31 +03:00
|
|
|
return ((Item_field *)item)->max_disp_length();
|
2004-06-16 16:06:30 +03:00
|
|
|
}
|
|
|
|
switch (item->result_type())
|
|
|
|
{
|
|
|
|
case STRING_RESULT:
|
|
|
|
return item->max_length;
|
|
|
|
case REAL_RESULT:
|
|
|
|
return 53;
|
|
|
|
case INT_RESULT:
|
|
|
|
return 20;
|
|
|
|
case ROW_RESULT:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0); // we should never go there
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2003-11-23 02:01:15 +02:00
|
|
|
|
|
|
|
double Item_type_holder::val()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // should never be called
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item_type_holder::val_int()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // should never be called
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_type_holder::val_str(String*)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // should never be called
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
** Instantiate templates
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
template class List<Item>;
|
|
|
|
template class List_iterator<Item>;
|
2001-08-02 06:29:50 +03:00
|
|
|
template class List_iterator_fast<Item>;
|
2000-07-31 21:29:14 +02:00
|
|
|
template class List<List_item>;
|
|
|
|
#endif
|