~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

  • Committer: Lee Bieber
  • Date: 2011-02-11 20:30:05 UTC
  • mfrom: (2157.1.3 build)
  • Revision ID: kalebral@gmail.com-20110211203005-757o1y2yf78dxzqr
Merge Stewart - 716848: drizzleimport displays wrong program_name
Merge Stewart - update README file
Merge Andrew and Joe - Exposes the InnoDB SYS_REPLICATION_LOG to data_dictionary so that it is fast and fixes many issues we have been having

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
 
 
54
 
#include <drizzled/current_session.h>
55
 
#include <drizzled/session.h>
56
 
 
57
 
#include <drizzled/internal/m_string.h>
 
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
 
 
54
#include "drizzled/internal/m_string.h"
58
55
 
59
56
#include <cstdio>
60
57
#include <math.h>
308
305
 
309
306
  /*
310
307
    Item constructor can be called during execution other then SQL_COM
311
 
    command => we should check session->getLex()->current_select on zero (session->lex
 
308
    command => we should check session->lex->current_select on zero (session->lex
312
309
    can be uninitialised)
313
310
  */
314
 
  if (getSession().getLex()->current_select)
 
311
  if (getSession().lex->current_select)
315
312
  {
316
313
    enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
317
314
    if (place == SELECT_LIST || place == IN_HAVING)
788
785
    Item *real_itm= real_item();
789
786
 
790
787
    ref_pointer_array[el]= real_itm;
791
 
    if (!(item_ref= new Item_aggregate_ref(&session->getLex()->current_select->context,
 
788
    if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context,
792
789
                                           ref_pointer_array + el, 0, name)))
793
790
      return; /* fatal_error is set */
794
791
    if (type() == SUM_FUNC_ITEM)
821
818
  if (mark_item)
822
819
    mark_item->depended_from= last;
823
820
  current->mark_as_dependent(last);
824
 
  if (session->getLex()->describe & DESCRIBE_EXTENDED)
 
821
  if (session->lex->describe & DESCRIBE_EXTENDED)
825
822
  {
826
823
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
827
824
    snprintf(warn_buff, sizeof(warn_buff), ER(ER_WARN_FIELD_RESOLVED),
1090
1087
 
1091
1088
bool Item::is_datetime()
1092
1089
{
1093
 
  return field::isDateTime(field_type());
 
1090
  switch (field_type())
 
1091
  {
 
1092
    case DRIZZLE_TYPE_TIME:
 
1093
    case DRIZZLE_TYPE_DATE:
 
1094
    case DRIZZLE_TYPE_DATETIME:
 
1095
    case DRIZZLE_TYPE_TIMESTAMP:
 
1096
    case DRIZZLE_TYPE_MICROTIME:
 
1097
      return true;
 
1098
    case DRIZZLE_TYPE_BLOB:
 
1099
    case DRIZZLE_TYPE_VARCHAR:
 
1100
    case DRIZZLE_TYPE_DOUBLE:
 
1101
    case DRIZZLE_TYPE_DECIMAL:
 
1102
    case DRIZZLE_TYPE_ENUM:
 
1103
    case DRIZZLE_TYPE_LONG:
 
1104
    case DRIZZLE_TYPE_LONGLONG:
 
1105
    case DRIZZLE_TYPE_NULL:
 
1106
    case DRIZZLE_TYPE_UUID:
 
1107
    case DRIZZLE_TYPE_BOOLEAN:
 
1108
      return false;
 
1109
  }
 
1110
 
 
1111
  assert(0);
 
1112
  abort();
1094
1113
}
1095
1114
 
1096
1115
String *Item::check_well_formed_result(String *str, bool send_error)
1197
1216
                            name, decimals, 0, unsigned_flag);
1198
1217
    break;
1199
1218
  case DRIZZLE_TYPE_NULL:
1200
 
    field= new Field_null((unsigned char*) 0, max_length, name);
 
1219
    field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1201
1220
    break;
1202
1221
  case DRIZZLE_TYPE_DATE:
1203
 
    field= new Field_date(maybe_null, name);
 
1222
    field= new Field_date(maybe_null, name, &my_charset_bin);
1204
1223
    break;
1205
1224
 
1206
1225
  case DRIZZLE_TYPE_MICROTIME:
1211
1230
    field= new field::Epoch(maybe_null, name);
1212
1231
    break;
1213
1232
  case DRIZZLE_TYPE_DATETIME:
1214
 
    field= new Field_datetime(maybe_null, name);
 
1233
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
1215
1234
    break;
1216
1235
  case DRIZZLE_TYPE_TIME:
1217
 
    field= new field::Time(maybe_null, name);
 
1236
    field= new field::Time(maybe_null, name, &my_charset_bin);
1218
1237
    break;
1219
1238
  case DRIZZLE_TYPE_BOOLEAN:
1220
1239
  case DRIZZLE_TYPE_UUID:
1428
1447
  return result;
1429
1448
}
1430
1449
 
1431
 
uint32_t Item::max_char_length() const
1432
 
{
1433
 
  return max_length / collation.collation->mbmaxlen;
1434
 
}
1435
 
 
1436
 
void Item::fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs)
1437
 
1438
 
  max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
1439
 
  collation.collation= cs;
1440
 
}
1441
 
 
1442
 
void Item::fix_char_length(uint32_t max_char_length_arg)
1443
 
1444
 
  max_length= char_to_byte_length_safe(max_char_length_arg, collation.collation->mbmaxlen);
1445
 
}
1446
 
 
1447
 
void Item::fix_char_length_uint64_t(uint64_t max_char_length_arg)
1448
 
1449
 
  uint64_t max_result_length= max_char_length_arg *
1450
 
    collation.collation->mbmaxlen;
1451
 
 
1452
 
  if (max_result_length >= MAX_BLOB_WIDTH)
1453
 
  { 
1454
 
    max_length= MAX_BLOB_WIDTH;
1455
 
    maybe_null= false;
1456
 
  }
1457
 
  else
1458
 
  {
1459
 
    max_length= max_result_length;
1460
 
  }
1461
 
}
1462
 
 
1463
 
void Item::fix_length_and_charset_datetime(uint32_t max_char_length_arg)
1464
 
1465
 
  collation.set(&my_charset_bin);
1466
 
  fix_char_length(max_char_length_arg);
1467
 
}
1468
 
 
1469
1450
Item_result item_cmp_type(Item_result a,Item_result b)
1470
1451
{
1471
1452
  if (a == STRING_RESULT && b == STRING_RESULT)
1681
1662
  case STRING_RESULT:
1682
1663
    assert(item->collation.collation);
1683
1664
 
 
1665
    enum enum_field_types type;
1684
1666
    /*
1685
1667
      DATE/TIME fields have STRING_RESULT result type.
1686
1668
      To preserve type they needed to be handled separately.
1687
1669
    */
1688
 
    if (field::isDateTime(item->field_type()))
 
1670
    if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
 
1671
        type == DRIZZLE_TYPE_TIME ||
 
1672
        type == DRIZZLE_TYPE_MICROTIME ||
 
1673
        type == DRIZZLE_TYPE_DATE ||
 
1674
        type == DRIZZLE_TYPE_TIMESTAMP)
1689
1675
    {
1690
1676
      new_field= item->tmp_table_field_from_field_type(table, 1);
1691
1677
      /*