~ubuntu-branches/ubuntu/precise/drizzle/precise

« back to all changes in this revision

Viewing changes to drizzled/item.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2011-03-02 10:38:38 UTC
  • mfrom: (1.2.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110302103838-4ezi8b065c4bv329
Tags: 2011.03.11-0ubuntu1
* New upstream release.
* Sleep no longer an so.
* Re-add get-orig-source, but this time with working.
* New symbol added to libdrizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include "drizzled/sql_select.h"
22
 
#include "drizzled/error.h"
23
 
#include "drizzled/show.h"
24
 
#include "drizzled/item/cmpfunc.h"
25
 
#include "drizzled/item/cache_row.h"
26
 
#include "drizzled/item/type_holder.h"
27
 
#include "drizzled/item/sum.h"
28
 
#include "drizzled/item/copy_string.h"
29
 
#include "drizzled/function/str/conv_charset.h"
30
 
#include "drizzled/sql_base.h"
31
 
#include "drizzled/util/convert.h"
32
 
#include "drizzled/plugin/client.h"
33
 
#include "drizzled/time_functions.h"
34
 
 
35
 
#include "drizzled/field/str.h"
36
 
#include "drizzled/field/num.h"
37
 
 
38
 
#include "drizzled/field/blob.h"
39
 
#include "drizzled/field/date.h"
40
 
#include "drizzled/field/datetime.h"
41
 
#include "drizzled/field/decimal.h"
42
 
#include "drizzled/field/double.h"
43
 
#include "drizzled/field/enum.h"
44
 
#include "drizzled/field/epoch.h"
45
 
#include "drizzled/field/int32.h"
46
 
#include "drizzled/field/int64.h"
47
 
#include "drizzled/field/microtime.h"
48
 
#include "drizzled/field/null.h"
49
 
#include "drizzled/field/real.h"
50
 
#include "drizzled/field/size.h"
51
 
#include "drizzled/field/time.h"
52
 
#include "drizzled/field/varstring.h"
53
 
 
 
20
#include <config.h>
 
21
#include <drizzled/sql_select.h>
 
22
#include <drizzled/error.h>
 
23
#include <drizzled/show.h>
 
24
#include <drizzled/item/cmpfunc.h>
 
25
#include <drizzled/item/cache_row.h>
 
26
#include <drizzled/item/type_holder.h>
 
27
#include <drizzled/item/sum.h>
 
28
#include <drizzled/item/copy_string.h>
 
29
#include <drizzled/function/str/conv_charset.h>
 
30
#include <drizzled/sql_base.h>
 
31
#include <drizzled/util/convert.h>
 
32
#include <drizzled/plugin/client.h>
 
33
#include <drizzled/time_functions.h>
 
34
#include <drizzled/field/str.h>
 
35
#include <drizzled/field/num.h>
 
36
#include <drizzled/field/blob.h>
 
37
#include <drizzled/field/date.h>
 
38
#include <drizzled/field/datetime.h>
 
39
#include <drizzled/field/decimal.h>
 
40
#include <drizzled/field/double.h>
 
41
#include <drizzled/field/enum.h>
 
42
#include <drizzled/field/epoch.h>
 
43
#include <drizzled/field/int32.h>
 
44
#include <drizzled/field/int64.h>
 
45
#include <drizzled/field/microtime.h>
 
46
#include <drizzled/field/null.h>
 
47
#include <drizzled/field/real.h>
 
48
#include <drizzled/field/size.h>
 
49
#include <drizzled/field/time.h>
 
50
#include <drizzled/field/varstring.h>
54
51
#include <drizzled/current_session.h>
55
52
#include <drizzled/session.h>
56
 
 
57
 
#include "drizzled/internal/m_string.h"
 
53
#include <drizzled/internal/m_string.h>
 
54
#include <drizzled/item/ref.h>
 
55
#include <drizzled/item/subselect.h>
58
56
 
59
57
#include <cstdio>
60
58
#include <math.h>
308
306
 
309
307
  /*
310
308
    Item constructor can be called during execution other then SQL_COM
311
 
    command => we should check session->lex->current_select on zero (session->lex
 
309
    command => we should check session->getLex()->current_select on zero (session->lex
312
310
    can be uninitialised)
313
311
  */
314
 
  if (getSession().lex->current_select)
 
312
  if (getSession().getLex()->current_select)
315
313
  {
316
314
    enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
317
315
    if (place == SELECT_LIST || place == IN_HAVING)
784
782
      Item_ref to allow fields from view being stored in tmp table.
785
783
    */
786
784
    Item_aggregate_ref *item_ref;
787
 
    uint32_t el= fields.elements;
 
785
    uint32_t el= fields.size();
788
786
    Item *real_itm= real_item();
789
787
 
790
788
    ref_pointer_array[el]= real_itm;
791
 
    if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context,
 
789
    if (!(item_ref= new Item_aggregate_ref(&session->getLex()->current_select->context,
792
790
                                           ref_pointer_array + el, 0, name)))
793
791
      return; /* fatal_error is set */
794
792
    if (type() == SUM_FUNC_ITEM)
795
793
      item_ref->depended_from= ((Item_sum *) this)->depended_from();
796
794
    fields.push_front(real_itm);
797
 
    session->change_item_tree(ref, item_ref);
 
795
    *ref= item_ref;
798
796
  }
799
797
}
800
798
 
821
819
  if (mark_item)
822
820
    mark_item->depended_from= last;
823
821
  current->mark_as_dependent(last);
824
 
  if (session->lex->describe & DESCRIBE_EXTENDED)
 
822
  if (session->getLex()->describe & DESCRIBE_EXTENDED)
825
823
  {
826
824
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
827
825
    snprintf(warn_buff, sizeof(warn_buff), ER(ER_WARN_FIELD_RESOLVED),
1090
1088
 
1091
1089
bool Item::is_datetime()
1092
1090
{
1093
 
  switch (field_type())
1094
 
  {
1095
 
    case DRIZZLE_TYPE_TIME:
1096
 
    case DRIZZLE_TYPE_DATE:
1097
 
    case DRIZZLE_TYPE_DATETIME:
1098
 
    case DRIZZLE_TYPE_TIMESTAMP:
1099
 
    case DRIZZLE_TYPE_MICROTIME:
1100
 
      return true;
1101
 
    case DRIZZLE_TYPE_BLOB:
1102
 
    case DRIZZLE_TYPE_VARCHAR:
1103
 
    case DRIZZLE_TYPE_DOUBLE:
1104
 
    case DRIZZLE_TYPE_DECIMAL:
1105
 
    case DRIZZLE_TYPE_ENUM:
1106
 
    case DRIZZLE_TYPE_LONG:
1107
 
    case DRIZZLE_TYPE_LONGLONG:
1108
 
    case DRIZZLE_TYPE_NULL:
1109
 
    case DRIZZLE_TYPE_UUID:
1110
 
    case DRIZZLE_TYPE_BOOLEAN:
1111
 
      return false;
1112
 
  }
1113
 
 
1114
 
  assert(0);
1115
 
  abort();
 
1091
  return field::isDateTime(field_type());
1116
1092
}
1117
1093
 
1118
1094
String *Item::check_well_formed_result(String *str, bool send_error)
1219
1195
                            name, decimals, 0, unsigned_flag);
1220
1196
    break;
1221
1197
  case DRIZZLE_TYPE_NULL:
1222
 
    field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
 
1198
    field= new Field_null((unsigned char*) 0, max_length, name);
1223
1199
    break;
1224
1200
  case DRIZZLE_TYPE_DATE:
1225
 
    field= new Field_date(maybe_null, name, &my_charset_bin);
 
1201
    field= new Field_date(maybe_null, name);
1226
1202
    break;
1227
1203
 
1228
1204
  case DRIZZLE_TYPE_MICROTIME:
1233
1209
    field= new field::Epoch(maybe_null, name);
1234
1210
    break;
1235
1211
  case DRIZZLE_TYPE_DATETIME:
1236
 
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
 
1212
    field= new Field_datetime(maybe_null, name);
1237
1213
    break;
1238
1214
  case DRIZZLE_TYPE_TIME:
1239
 
    field= new field::Time(maybe_null, name, &my_charset_bin);
 
1215
    field= new field::Time(maybe_null, name);
1240
1216
    break;
1241
1217
  case DRIZZLE_TYPE_BOOLEAN:
1242
1218
  case DRIZZLE_TYPE_UUID:
1593
1569
  }
1594
1570
 
1595
1571
  if (new_item)
1596
 
    session->change_item_tree(ref, new_item);
 
1572
    *ref= new_item;
1597
1573
}
1598
1574
 
1599
1575
bool field_is_equal_to_item(Field *field,Item *item)
1703
1679
  case STRING_RESULT:
1704
1680
    assert(item->collation.collation);
1705
1681
 
1706
 
    enum enum_field_types type;
1707
1682
    /*
1708
1683
      DATE/TIME fields have STRING_RESULT result type.
1709
1684
      To preserve type they needed to be handled separately.
1710
1685
    */
1711
 
    if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
1712
 
        type == DRIZZLE_TYPE_TIME ||
1713
 
        type == DRIZZLE_TYPE_MICROTIME ||
1714
 
        type == DRIZZLE_TYPE_DATE ||
1715
 
        type == DRIZZLE_TYPE_TIMESTAMP)
 
1686
    if (field::isDateTime(item->field_type()))
1716
1687
    {
1717
1688
      new_field= item->tmp_table_field_from_field_type(table, 1);
1718
1689
      /*