~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

  • Committer: Monty Taylor
  • Date: 2010-10-21 23:10:12 UTC
  • mto: (1879.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1880.
  • Revision ID: mordred@inaugust.com-20101021231012-uhsebiqo23xi0ygy
Updated AUTHORS list with everyone from bzr logs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "drizzled/field/decimal.h"
42
42
#include "drizzled/field/real.h"
43
43
#include "drizzled/field/double.h"
44
 
#include "drizzled/field/int32.h"
45
 
#include "drizzled/field/int64.h"
 
44
#include "drizzled/field/long.h"
 
45
#include "drizzled/field/int64_t.h"
46
46
#include "drizzled/field/num.h"
47
47
#include "drizzled/field/timestamp.h"
48
48
#include "drizzled/field/datetime.h"
92
92
  {
93
93
    case INT_RESULT:
94
94
      return val_int() != 0;
95
 
 
96
95
    case DECIMAL_RESULT:
97
96
    {
98
97
      my_decimal decimal_value;
101
100
        return !my_decimal_is_zero(val);
102
101
      return false;
103
102
    }
104
 
 
105
103
    case REAL_RESULT:
106
104
    case STRING_RESULT:
107
105
      return val_real() != 0.0;
108
 
 
109
106
    case ROW_RESULT:
 
107
    default:
110
108
      assert(0);
111
 
      abort();
 
109
      return false;
112
110
  }
113
 
 
114
 
  assert(0);
115
 
  abort();
116
111
}
117
112
 
118
113
String *Item::val_string_from_real(String *str)
856
851
    - the found item on success
857
852
    - NULL if find_item is not in group_list
858
853
*/
859
 
static Item** find_field_in_group_list(Item *find_item, Order *group_list)
 
854
static Item** find_field_in_group_list(Item *find_item, order_st *group_list)
860
855
{
861
856
  const char *db_name;
862
857
  const char *table_name;
863
858
  const char *field_name;
864
 
  Order *found_group= NULL;
 
859
  order_st *found_group= NULL;
865
860
  int found_match_degree= 0;
866
861
  Item_ident *cur_field;
867
862
  int cur_match_degree= 0;
887
882
 
888
883
  assert(field_name != 0);
889
884
 
890
 
  for (Order *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
 
885
  for (order_st *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
891
886
  {
892
887
    if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM)
893
888
    {
949
944
{
950
945
  Item **group_by_ref= NULL;
951
946
  Item **select_ref= NULL;
952
 
  Order *group_list= (Order*) select->group_list.first;
 
947
  order_st *group_list= (order_st*) select->group_list.first;
953
948
  bool ambiguous_fields= false;
954
949
  uint32_t counter;
955
950
  enum_resolution_type resolution;
1049
1044
  case REAL_RESULT:    
1050
1045
    return DRIZZLE_TYPE_DOUBLE;
1051
1046
  case ROW_RESULT:
 
1047
  default:
1052
1048
    assert(0);
 
1049
    return DRIZZLE_TYPE_VARCHAR;
1053
1050
  }
1054
 
 
1055
 
  abort();
1056
1051
}
1057
1052
 
1058
1053
bool Item::is_datetime()
1063
1058
    case DRIZZLE_TYPE_DATETIME:
1064
1059
    case DRIZZLE_TYPE_TIMESTAMP:
1065
1060
      return true;
1066
 
    case DRIZZLE_TYPE_BLOB:
1067
 
    case DRIZZLE_TYPE_VARCHAR:
1068
 
    case DRIZZLE_TYPE_DOUBLE:
1069
 
    case DRIZZLE_TYPE_DECIMAL:
1070
 
    case DRIZZLE_TYPE_ENUM:
1071
 
    case DRIZZLE_TYPE_LONG:
1072
 
    case DRIZZLE_TYPE_LONGLONG:
1073
 
    case DRIZZLE_TYPE_NULL:
1074
 
    case DRIZZLE_TYPE_UUID:
1075
 
      return false;
 
1061
    default:
 
1062
      break;
1076
1063
  }
1077
 
 
1078
 
  assert(0);
1079
 
  abort();
 
1064
  return false;
1080
1065
}
1081
1066
 
1082
1067
String *Item::check_well_formed_result(String *str, bool send_error)
1161
1146
    The field functions defines a field to be not null if null_ptr is not 0
1162
1147
  */
1163
1148
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
1164
 
  Field *field= NULL;
 
1149
  Field *field;
1165
1150
 
1166
1151
  switch (field_type()) {
1167
1152
  case DRIZZLE_TYPE_DECIMAL:
1176
1161
                                 unsigned_flag);
1177
1162
    break;
1178
1163
  case DRIZZLE_TYPE_LONG:
1179
 
    field= new field::Int32((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, name);
 
1164
    field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
 
1165
                          name, 0, unsigned_flag);
1180
1166
    break;
1181
1167
  case DRIZZLE_TYPE_LONGLONG:
1182
 
    field= new field::Int64((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, name);
 
1168
    field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
 
1169
                              name, 0, unsigned_flag);
1183
1170
    break;
1184
1171
  case DRIZZLE_TYPE_DOUBLE:
1185
1172
    field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
1186
 
                            name, decimals, 0, unsigned_flag);
 
1173
                            name, decimals, 0, unsigned_flag);
1187
1174
    break;
1188
1175
  case DRIZZLE_TYPE_NULL:
1189
1176
    field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1197
1184
  case DRIZZLE_TYPE_DATETIME:
1198
1185
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
1199
1186
    break;
1200
 
  case DRIZZLE_TYPE_UUID:
 
1187
  default:
 
1188
    /* This case should never be chosen */
 
1189
    assert(0);
 
1190
    /* Fall through to make_string_field() */
1201
1191
  case DRIZZLE_TYPE_ENUM:
1202
1192
  case DRIZZLE_TYPE_VARCHAR:
1203
1193
    return make_string_field(table);
1204
1194
  case DRIZZLE_TYPE_BLOB:
 
1195
    if (this->type() == Item::TYPE_HOLDER)
 
1196
      field= new Field_blob(max_length, maybe_null, name, collation.collation,
 
1197
                            1);
 
1198
    else
1205
1199
      field= new Field_blob(max_length, maybe_null, name, collation.collation);
1206
1200
    break;                                      // Blob handled outside of case
1207
1201
  }
1208
 
  assert(field);
1209
 
 
1210
1202
  if (field)
1211
1203
    field->init(table);
1212
1204
  return field;
1341
1333
  enum_field_types f_type;
1342
1334
 
1343
1335
  switch ((f_type=field_type())) {
1344
 
  case DRIZZLE_TYPE_DATE:
 
1336
  default:
1345
1337
  case DRIZZLE_TYPE_NULL:
1346
1338
  case DRIZZLE_TYPE_ENUM:
1347
1339
  case DRIZZLE_TYPE_BLOB:
1348
1340
  case DRIZZLE_TYPE_VARCHAR:
1349
 
  case DRIZZLE_TYPE_UUID:
1350
1341
  case DRIZZLE_TYPE_DECIMAL:
1351
 
    {
1352
 
      String *res;
1353
 
      if ((res=val_str(buffer)))
1354
 
        result= client->store(res->ptr(),res->length());
1355
 
      break;
1356
 
    }
 
1342
  {
 
1343
    String *res;
 
1344
    if ((res=val_str(buffer)))
 
1345
      result= client->store(res->ptr(),res->length());
 
1346
    break;
 
1347
  }
1357
1348
  case DRIZZLE_TYPE_LONG:
1358
 
    {
1359
 
      int64_t nr;
1360
 
      nr= val_int();
1361
 
      if (!null_value)
1362
 
        result= client->store((int32_t)nr);
1363
 
      break;
1364
 
    }
 
1349
  {
 
1350
    int64_t nr;
 
1351
    nr= val_int();
 
1352
    if (!null_value)
 
1353
      result= client->store((int32_t)nr);
 
1354
    break;
 
1355
  }
1365
1356
  case DRIZZLE_TYPE_LONGLONG:
 
1357
  {
 
1358
    int64_t nr;
 
1359
    nr= val_int();
 
1360
    if (!null_value)
1366
1361
    {
1367
 
      int64_t nr;
1368
 
      nr= val_int();
1369
 
      if (!null_value)
1370
 
      {
1371
 
        if (unsigned_flag)
1372
 
          result= client->store((uint64_t)nr);
1373
 
        else
1374
 
          result= client->store((int64_t)nr);
1375
 
      }
1376
 
      break;
 
1362
      if (unsigned_flag)
 
1363
        result= client->store((uint64_t)nr);
 
1364
      else
 
1365
        result= client->store((int64_t)nr);
1377
1366
    }
 
1367
    break;
 
1368
  }
1378
1369
  case DRIZZLE_TYPE_DOUBLE:
1379
 
    {
1380
 
      double nr= val_real();
1381
 
      if (!null_value)
1382
 
        result= client->store(nr, decimals, buffer);
1383
 
      break;
1384
 
    }
 
1370
  {
 
1371
    double nr= val_real();
 
1372
    if (!null_value)
 
1373
      result= client->store(nr, decimals, buffer);
 
1374
    break;
 
1375
  }
1385
1376
  case DRIZZLE_TYPE_DATETIME:
1386
1377
  case DRIZZLE_TYPE_TIMESTAMP:
1387
 
    {
1388
 
      DRIZZLE_TIME tm;
1389
 
      get_date(&tm, TIME_FUZZY_DATE);
1390
 
      if (!null_value)
1391
 
        result= client->store(&tm);
1392
 
      break;
1393
 
    }
 
1378
  {
 
1379
    DRIZZLE_TIME tm;
 
1380
    get_date(&tm, TIME_FUZZY_DATE);
 
1381
    if (!null_value)
 
1382
      result= client->store(&tm);
 
1383
    break;
 
1384
  }
1394
1385
  }
1395
1386
  if (null_value)
1396
1387
    result= client->store();
1397
 
 
1398
1388
  return result;
1399
1389
}
1400
1390
 
1402
1392
{
1403
1393
  if (a == STRING_RESULT && b == STRING_RESULT)
1404
1394
    return STRING_RESULT;
1405
 
 
1406
1395
  if (a == INT_RESULT && b == INT_RESULT)
1407
1396
    return INT_RESULT;
1408
1397
  else if (a == ROW_RESULT || b == ROW_RESULT)
1409
1398
    return ROW_RESULT;
1410
 
 
1411
1399
  if ((a == INT_RESULT || a == DECIMAL_RESULT) &&
1412
1400
      (b == INT_RESULT || b == DECIMAL_RESULT))
1413
1401
    return DECIMAL_RESULT;
1414
 
 
1415
1402
  return REAL_RESULT;
1416
1403
}
1417
1404
 
1427
1414
 
1428
1415
  switch (res_type) {
1429
1416
  case STRING_RESULT:
 
1417
  {
 
1418
    char buff[MAX_FIELD_WIDTH];
 
1419
    String tmp(buff,sizeof(buff),&my_charset_bin),*result;
 
1420
    result=item->val_str(&tmp);
 
1421
    if (item->null_value)
 
1422
      new_item= new Item_null(name);
 
1423
    else
1430
1424
    {
1431
 
      char buff[MAX_FIELD_WIDTH];
1432
 
      String tmp(buff,sizeof(buff),&my_charset_bin),*result;
1433
 
      result=item->val_str(&tmp);
1434
 
      if (item->null_value)
1435
 
        new_item= new Item_null(name);
1436
 
      else
1437
 
      {
1438
 
        uint32_t length= result->length();
1439
 
        char *tmp_str= memory::sql_strmake(result->ptr(), length);
1440
 
        new_item= new Item_string(name, tmp_str, length, result->charset());
1441
 
      }
1442
 
      break;
 
1425
      uint32_t length= result->length();
 
1426
      char *tmp_str= memory::sql_strmake(result->ptr(), length);
 
1427
      new_item= new Item_string(name, tmp_str, length, result->charset());
1443
1428
    }
 
1429
    break;
 
1430
  }
1444
1431
  case INT_RESULT:
1445
 
    {
1446
 
      int64_t result=item->val_int();
1447
 
      uint32_t length=item->max_length;
1448
 
      bool null_value=item->null_value;
1449
 
      new_item= (null_value ? (Item*) new Item_null(name) :
1450
 
                 (Item*) new Item_int(name, result, length));
1451
 
      break;
1452
 
    }
 
1432
  {
 
1433
    int64_t result=item->val_int();
 
1434
    uint32_t length=item->max_length;
 
1435
    bool null_value=item->null_value;
 
1436
    new_item= (null_value ? (Item*) new Item_null(name) :
 
1437
               (Item*) new Item_int(name, result, length));
 
1438
    break;
 
1439
  }
1453
1440
  case ROW_RESULT:
1454
 
    if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM)
1455
 
    {
1456
 
      /*
1457
 
        Substitute constants only in Item_rows. Don't affect other Items
1458
 
        with ROW_RESULT (eg Item_singlerow_subselect).
 
1441
  if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM)
 
1442
  {
 
1443
    /*
 
1444
      Substitute constants only in Item_rows. Don't affect other Items
 
1445
      with ROW_RESULT (eg Item_singlerow_subselect).
1459
1446
 
1460
 
        For such Items more optimal is to detect if it is constant and replace
1461
 
        it with Item_row. This would optimize queries like this:
1462
 
        SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1);
1463
 
      */
1464
 
      Item_row *item_row= (Item_row*) item;
1465
 
      Item_row *comp_item_row= (Item_row*) comp_item;
1466
 
      uint32_t col;
1467
 
      new_item= 0;
1468
 
      /*
1469
 
        If item and comp_item are both Item_rows and have same number of cols
1470
 
        then process items in Item_row one by one.
1471
 
        We can't ignore NULL values here as this item may be used with <=>, in
1472
 
        which case NULL's are significant.
1473
 
      */
1474
 
      assert(item->result_type() == comp_item->result_type());
1475
 
      assert(item_row->cols() == comp_item_row->cols());
1476
 
      col= item_row->cols();
1477
 
      while (col-- > 0)
1478
 
        resolve_const_item(session, item_row->addr(col),
1479
 
                           comp_item_row->element_index(col));
1480
 
      break;
1481
 
    }
1482
 
    /* Fallthrough */
 
1447
      For such Items more optimal is to detect if it is constant and replace
 
1448
      it with Item_row. This would optimize queries like this:
 
1449
      SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1);
 
1450
    */
 
1451
    Item_row *item_row= (Item_row*) item;
 
1452
    Item_row *comp_item_row= (Item_row*) comp_item;
 
1453
    uint32_t col;
 
1454
    new_item= 0;
 
1455
    /*
 
1456
      If item and comp_item are both Item_rows and have same number of cols
 
1457
      then process items in Item_row one by one.
 
1458
      We can't ignore NULL values here as this item may be used with <=>, in
 
1459
      which case NULL's are significant.
 
1460
    */
 
1461
    assert(item->result_type() == comp_item->result_type());
 
1462
    assert(item_row->cols() == comp_item_row->cols());
 
1463
    col= item_row->cols();
 
1464
    while (col-- > 0)
 
1465
      resolve_const_item(session, item_row->addr(col),
 
1466
                         comp_item_row->element_index(col));
 
1467
    break;
 
1468
  }
 
1469
  /* Fallthrough */
1483
1470
  case REAL_RESULT:
1484
 
    {                                           // It must REAL_RESULT
1485
 
      double result= item->val_real();
1486
 
      uint32_t length=item->max_length,decimals=item->decimals;
1487
 
      bool null_value=item->null_value;
1488
 
      new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
1489
 
                 new Item_float(name, result, decimals, length));
1490
 
      break;
1491
 
    }
 
1471
  {                                             // It must REAL_RESULT
 
1472
    double result= item->val_real();
 
1473
    uint32_t length=item->max_length,decimals=item->decimals;
 
1474
    bool null_value=item->null_value;
 
1475
    new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
 
1476
               new Item_float(name, result, decimals, length));
 
1477
    break;
 
1478
  }
1492
1479
  case DECIMAL_RESULT:
1493
 
    {
1494
 
      my_decimal decimal_value;
1495
 
      my_decimal *result= item->val_decimal(&decimal_value);
1496
 
      uint32_t length= item->max_length, decimals= item->decimals;
1497
 
      bool null_value= item->null_value;
1498
 
      new_item= (null_value ?
1499
 
                 (Item*) new Item_null(name) :
1500
 
                 (Item*) new Item_decimal(name, result, length, decimals));
1501
 
      break;
1502
 
    }
1503
 
  }
1504
 
 
 
1480
  {
 
1481
    my_decimal decimal_value;
 
1482
    my_decimal *result= item->val_decimal(&decimal_value);
 
1483
    uint32_t length= item->max_length, decimals= item->decimals;
 
1484
    bool null_value= item->null_value;
 
1485
    new_item= (null_value ?
 
1486
               (Item*) new Item_null(name) :
 
1487
               (Item*) new Item_decimal(name, result, length, decimals));
 
1488
    break;
 
1489
  }
 
1490
  default:
 
1491
    assert(0);
 
1492
  }
1505
1493
  if (new_item)
1506
1494
    session->change_item_tree(ref, new_item);
1507
1495
}
1520
1508
    item_result=item->val_str(&item_tmp);
1521
1509
    if (item->null_value)
1522
1510
      return 1;                                 // This must be true
1523
 
    field->val_str_internal(&field_tmp);
1524
 
    return not stringcmp(&field_tmp,item_result);
 
1511
    field->val_str(&field_tmp);
 
1512
    return !stringcmp(&field_tmp,item_result);
1525
1513
  }
1526
 
 
1527
1514
  if (res_type == INT_RESULT)
1528
1515
    return 1;                                   // Both where of type int
1529
 
 
1530
1516
  if (res_type == DECIMAL_RESULT)
1531
1517
  {
1532
1518
    my_decimal item_buf, *item_val,
1537
1523
    field_val= field->val_decimal(&field_buf);
1538
1524
    return !my_decimal_cmp(item_val, field_val);
1539
1525
  }
1540
 
 
1541
1526
  double result= item->val_real();
1542
1527
  if (item->null_value)
1543
1528
    return 1;
1544
 
 
1545
1529
  return result == field->val_real();
1546
1530
}
1547
1531
 
1577
1561
                                         uint32_t convert_blob_length)
1578
1562
{
1579
1563
  bool maybe_null= item->maybe_null;
1580
 
  Field *new_field= NULL;
 
1564
  Field *new_field;
1581
1565
 
1582
1566
  switch (item->result_type()) {
1583
1567
  case REAL_RESULT:
1584
1568
    new_field= new Field_double(item->max_length, maybe_null,
1585
1569
                                item->name, item->decimals, true);
1586
1570
    break;
1587
 
 
1588
1571
  case INT_RESULT:
1589
1572
    /*
1590
1573
      Select an integer type with the minimal fit precision.
1591
1574
      MY_INT32_NUM_DECIMAL_DIGITS is sign inclusive, don't consider the sign.
1592
1575
      Values with MY_INT32_NUM_DECIMAL_DIGITS digits may or may not fit into
1593
 
      Int32 -> make them field::Int64.
 
1576
      Field_long : make them Field_int64_t.
1594
1577
    */
1595
1578
    if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
1596
 
      new_field=new field::Int64(item->max_length, maybe_null,
1597
 
                                 item->name, item->unsigned_flag);
 
1579
      new_field=new Field_int64_t(item->max_length, maybe_null,
 
1580
                                   item->name, item->unsigned_flag);
1598
1581
    else
1599
 
      new_field=new field::Int32(item->max_length, maybe_null,
1600
 
                                 item->name, item->unsigned_flag);
 
1582
      new_field=new Field_long(item->max_length, maybe_null,
 
1583
                               item->name, item->unsigned_flag);
1601
1584
    break;
1602
 
 
1603
1585
  case STRING_RESULT:
1604
1586
    assert(item->collation.collation);
1605
1587
 
1632
1614
    }
1633
1615
    new_field->set_derivation(item->collation.derivation);
1634
1616
    break;
1635
 
 
1636
1617
  case DECIMAL_RESULT:
 
1618
  {
 
1619
    uint8_t dec= item->decimals;
 
1620
    uint8_t intg= ((Item_decimal *) item)->decimal_precision() - dec;
 
1621
    uint32_t len= item->max_length;
 
1622
 
 
1623
    /*
 
1624
      Trying to put too many digits overall in a DECIMAL(prec,dec)
 
1625
      will always throw a warning. We must limit dec to
 
1626
      DECIMAL_MAX_SCALE however to prevent an assert() later.
 
1627
    */
 
1628
 
 
1629
    if (dec > 0)
1637
1630
    {
1638
 
      uint8_t dec= item->decimals;
1639
 
      uint8_t intg= ((Item_decimal *) item)->decimal_precision() - dec;
1640
 
      uint32_t len= item->max_length;
 
1631
      signed int overflow;
 
1632
 
 
1633
      dec= min(dec, (uint8_t)DECIMAL_MAX_SCALE);
1641
1634
 
1642
1635
      /*
1643
 
        Trying to put too many digits overall in a DECIMAL(prec,dec)
1644
 
        will always throw a warning. We must limit dec to
1645
 
        DECIMAL_MAX_SCALE however to prevent an assert() later.
 
1636
        If the value still overflows the field with the corrected dec,
 
1637
        we'll throw out decimals rather than integers. This is still
 
1638
        bad and of course throws a truncation warning.
 
1639
        +1: for decimal point
1646
1640
      */
1647
1641
 
1648
 
      if (dec > 0)
1649
 
      {
1650
 
        signed int overflow;
1651
 
 
1652
 
        dec= min(dec, (uint8_t)DECIMAL_MAX_SCALE);
1653
 
 
1654
 
        /*
1655
 
          If the value still overflows the field with the corrected dec,
1656
 
          we'll throw out decimals rather than integers. This is still
1657
 
          bad and of course throws a truncation warning.
1658
 
          +1: for decimal point
1659
 
        */
1660
 
 
1661
 
        overflow= my_decimal_precision_to_length(intg + dec, dec,
1662
 
                                                 item->unsigned_flag) - len;
1663
 
 
1664
 
        if (overflow > 0)
1665
 
          dec= max(0, dec - overflow);            // too long, discard fract
1666
 
        else
1667
 
          len-= item->decimals - dec;             // corrected value fits
1668
 
      }
1669
 
 
1670
 
      new_field= new Field_decimal(len,
1671
 
                                   maybe_null,
1672
 
                                   item->name,
1673
 
                                   dec,
1674
 
                                   item->unsigned_flag);
1675
 
      break;
 
1642
      overflow= my_decimal_precision_to_length(intg + dec, dec,
 
1643
                                               item->unsigned_flag) - len;
 
1644
 
 
1645
      if (overflow > 0)
 
1646
        dec= max(0, dec - overflow);            // too long, discard fract
 
1647
      else
 
1648
        len-= item->decimals - dec;             // corrected value fits
1676
1649
    }
1677
1650
 
 
1651
    new_field= new Field_decimal(len,
 
1652
                                 maybe_null,
 
1653
                                 item->name,
 
1654
                                 dec,
 
1655
                                 item->unsigned_flag);
 
1656
    break;
 
1657
  }
1678
1658
  case ROW_RESULT:
 
1659
  default:
1679
1660
    // This case should never be choosen
1680
1661
    assert(0);
1681
 
    abort();
 
1662
    new_field= 0;
 
1663
    break;
1682
1664
  }
1683
 
 
1684
1665
  if (new_field)
1685
1666
    new_field->init(table);
1686
1667
 
1687
1668
  if (copy_func && item->is_result_field())
1688
1669
    *((*copy_func)++) = item;                   // Save for copy_funcs
1689
 
 
1690
1670
  if (modify_item)
1691
1671
    item->set_result_field(new_field);
1692
 
 
1693
1672
  if (item->type() == Item::NULL_ITEM)
1694
1673
    new_field->is_created_from_null_item= true;
1695
 
 
1696
1674
  return new_field;
1697
1675
}
1698
1676
 
1749
1727
        field->result_field= result;
1750
1728
    }
1751
1729
    else
1752
 
    {
1753
1730
      result= create_tmp_field_from_field(session, (*from_field= field->field),
1754
1731
                                          orig_item ? orig_item->name :
1755
1732
                                          item->name,
1757
1734
                                          modify_item ? field :
1758
1735
                                          NULL,
1759
1736
                                          convert_blob_length);
1760
 
    }
1761
1737
    if (orig_type == Item::REF_ITEM && orig_modify)
1762
1738
      ((Item_ref*)orig_item)->set_result_field(result);
1763
1739
    if (field->field->eq_def(result))
1797
1773
  }
1798
1774
}
1799
1775
 
1800
 
std::ostream& operator<<(std::ostream& output, const Item &item)
1801
 
{
1802
 
  output << "Item:(";
1803
 
  output <<  item.name;
1804
 
  output << ", ";
1805
 
  output << drizzled::display::type(item.type());
1806
 
  output << ")";
1807
 
 
1808
 
  return output;  // for multiple << operators.
1809
 
}
1810
 
 
1811
1776
} /* namespace drizzled */