35
35
#include "drizzled/field/str.h"
36
36
#include "drizzled/field/num.h"
38
37
#include "drizzled/field/blob.h"
38
#include "drizzled/field/enum.h"
39
#include "drizzled/field/null.h"
39
40
#include "drizzled/field/date.h"
40
#include "drizzled/field/datetime.h"
41
41
#include "drizzled/field/decimal.h"
42
#include "drizzled/field/real.h"
42
43
#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"
44
#include "drizzled/field/long.h"
45
#include "drizzled/field/int64_t.h"
46
#include "drizzled/field/num.h"
47
#include "drizzled/field/timestamp.h"
48
#include "drizzled/field/datetime.h"
52
49
#include "drizzled/field/varstring.h"
54
50
#include "drizzled/internal/m_string.h"
142
133
String *Item::val_string_from_decimal(String *str)
144
type::Decimal dec_buf, *dec= val_decimal(&dec_buf);
135
my_decimal dec_buf, *dec= val_decimal(&dec_buf);
148
class_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
149
class_decimal2string(&dec_buf, 0, str);
139
my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
140
my_decimal2string(E_DEC_FATAL_ERROR, &dec_buf, 0, 0, 0, str);
153
type::Decimal *Item::val_decimal_from_real(type::Decimal *decimal_value)
144
my_decimal *Item::val_decimal_from_real(my_decimal *decimal_value)
155
146
double nr= val_real();
159
double2_class_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
150
double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
160
151
return (decimal_value);
163
type::Decimal *Item::val_decimal_from_int(type::Decimal *decimal_value)
154
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value)
165
156
int64_t nr= val_int();
169
int2_class_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
160
int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
170
161
return decimal_value;
173
type::Decimal *Item::val_decimal_from_string(type::Decimal *decimal_value)
164
my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
192
184
return decimal_value;
195
type::Decimal *Item::val_decimal_from_date(type::Decimal *decimal_value)
187
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
199
if (get_date(ltime, TIME_FUZZY_DATE))
191
if (get_date(<ime, TIME_FUZZY_DATE))
201
decimal_value->set_zero();
193
my_decimal_set_zero(decimal_value);
202
194
null_value= 1; // set NULL, stop processing
205
return date2_class_decimal(<ime, decimal_value);
197
return date2my_decimal(<ime, decimal_value);
208
type::Decimal *Item::val_decimal_from_time(type::Decimal *decimal_value)
200
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
204
if (get_time(<ime))
214
decimal_value->set_zero();
206
my_decimal_set_zero(decimal_value);
217
return date2_class_decimal(<ime, decimal_value);
209
return date2my_decimal(<ime, decimal_value);
220
212
double Item::val_real_from_decimal()
222
214
/* Note that fix_fields may not be called for Item_avg_field items */
224
type::Decimal value_buff, *dec_val= val_decimal(&value_buff);
216
my_decimal value_buff, *dec_val= val_decimal(&value_buff);
227
class_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
219
my_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
233
225
/* Note that fix_fields may not be called for Item_avg_field items */
235
type::Decimal value, *dec_val= val_decimal(&value);
227
my_decimal value, *dec_val= val_decimal(&value);
239
dec_val->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
230
my_decimal2int(E_DEC_FATAL_ERROR, dec_val, unsigned_flag, &result);
244
bool Item::save_time_in_field(Field *field)
234
int Item::save_time_in_field(Field *field)
237
if (get_time(<ime))
249
238
return set_field_to_null(field);
251
239
field->set_notnull();
253
return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_TIME);
240
return field->store_time(<ime, DRIZZLE_TIMESTAMP_TIME);
256
bool Item::save_date_in_field(Field *field)
243
int Item::save_date_in_field(Field *field)
260
if (get_date(ltime, TIME_FUZZY_DATE))
246
if (get_date(<ime, TIME_FUZZY_DATE))
261
247
return set_field_to_null(field);
263
248
field->set_notnull();
265
return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
249
return field->store_time(<ime, DRIZZLE_TIMESTAMP_DATETIME);
294
276
with_sum_func(false),
295
277
is_autogenerated_name(true),
296
278
with_subselect(false),
297
collation(&my_charset_bin, DERIVATION_COERCIBLE),
298
_session(*current_session)
279
collation(&my_charset_bin, DERIVATION_COERCIBLE)
300
281
cmp_context= (Item_result)-1;
302
283
/* Put item in free list so that we can free all items at end */
303
next= getSession().free_list;
304
getSession().free_list= this;
284
Session *session= current_session;
285
next= session->free_list;
286
session->free_list= this;
307
289
Item constructor can be called during execution other then SQL_COM
308
290
command => we should check session->lex->current_select on zero (session->lex
309
291
can be uninitialised)
311
if (getSession().lex->current_select)
293
if (session->lex->current_select)
313
enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
295
enum_parsing_place place= session->lex->current_select->parsing_place;
314
296
if (place == SELECT_LIST || place == IN_HAVING)
315
getSession().getLex()->current_select->select_n_having_items++;
297
session->lex->current_select->select_n_having_items++;
471
452
return conv->safe ? conv : NULL;
474
bool Item::get_date(type::Time <ime,uint32_t fuzzydate)
455
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
482
else if (result_type() == STRING_RESULT)
484
char buff[type::Time::MAX_STRING_LENGTH];
485
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
486
if (!(res=val_str(&tmp)) ||
487
str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
488
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
495
int64_t value= val_int();
496
type::datetime_t date_value;
498
ltime.convert(date_value, value, fuzzydate);
500
if (not type::is_valid(date_value))
502
char buff[DECIMAL_LONGLONG_DIGITS], *end;
503
end= internal::int64_t10_to_str(value, buff, -10);
504
make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
505
buff, (int) (end-buff), type::DRIZZLE_TIMESTAMP_NONE, NULL);
457
if (result_type() == STRING_RESULT)
460
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
461
if (!(res=val_str(&tmp)) ||
462
str_to_datetime_with_warn(res->ptr(), res->length(),
463
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
468
int64_t value= val_int();
470
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
473
end= internal::int64_t10_to_str(value, buff, -10);
474
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
475
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
483
memset(ltime, 0, sizeof(*ltime));
518
bool Item::get_time(type::Time <ime)
487
bool Item::get_time(DRIZZLE_TIME *ltime)
520
char buff[type::Time::MAX_STRING_LENGTH];
521
490
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
522
if (!(res=val_str(&tmp)) or
523
str_to_time_with_warn(&getSession(), res->ptr(), res->length(), <ime))
491
if (!(res=val_str(&tmp)) ||
492
str_to_time_with_warn(res->ptr(), res->length(), ltime))
494
memset(ltime, 0, sizeof(*ltime));
533
bool Item::get_date_result(type::Time <ime,uint32_t fuzzydate)
500
bool Item::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
535
return get_date(ltime, fuzzydate);
502
return get_date(ltime,fuzzydate);
538
505
bool Item::is_null()
1208
1158
case DRIZZLE_TYPE_LONG:
1209
field= new field::Int32((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, name);
1159
field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
1160
name, 0, unsigned_flag);
1211
1162
case DRIZZLE_TYPE_LONGLONG:
1212
field= new field::Int64((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, name);
1163
field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
1164
name, 0, unsigned_flag);
1214
1166
case DRIZZLE_TYPE_DOUBLE:
1215
1167
field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
1216
name, decimals, 0, unsigned_flag);
1168
name, decimals, 0, unsigned_flag);
1218
1170
case DRIZZLE_TYPE_NULL:
1219
1171
field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1221
1173
case DRIZZLE_TYPE_DATE:
1222
1174
field= new Field_date(maybe_null, name, &my_charset_bin);
1225
case DRIZZLE_TYPE_MICROTIME:
1226
field= new field::Microtime(maybe_null, name);
1229
1176
case DRIZZLE_TYPE_TIMESTAMP:
1230
field= new field::Epoch(maybe_null, name);
1177
field= new Field_timestamp(maybe_null, name, &my_charset_bin);
1232
1179
case DRIZZLE_TYPE_DATETIME:
1233
1180
field= new Field_datetime(maybe_null, name, &my_charset_bin);
1235
case DRIZZLE_TYPE_TIME:
1236
field= new field::Time(maybe_null, name, &my_charset_bin);
1238
case DRIZZLE_TYPE_BOOLEAN:
1239
case DRIZZLE_TYPE_UUID:
1183
/* This case should never be chosen */
1185
/* Fall through to make_string_field() */
1240
1186
case DRIZZLE_TYPE_ENUM:
1241
1187
case DRIZZLE_TYPE_VARCHAR:
1242
1188
return make_string_field(table);
1243
1189
case DRIZZLE_TYPE_BLOB:
1190
if (this->type() == Item::TYPE_HOLDER)
1191
field= new Field_blob(max_length, maybe_null, name, collation.collation,
1244
1194
field= new Field_blob(max_length, maybe_null, name, collation.collation);
1245
1195
break; // Blob handled outside of case
1250
1198
field->init(table);
1380
1328
enum_field_types f_type;
1382
1330
switch ((f_type=field_type())) {
1383
case DRIZZLE_TYPE_DATE:
1384
1332
case DRIZZLE_TYPE_NULL:
1385
1333
case DRIZZLE_TYPE_ENUM:
1386
1334
case DRIZZLE_TYPE_BLOB:
1387
1335
case DRIZZLE_TYPE_VARCHAR:
1388
case DRIZZLE_TYPE_BOOLEAN:
1389
case DRIZZLE_TYPE_UUID:
1390
1336
case DRIZZLE_TYPE_DECIMAL:
1393
if ((res=val_str(buffer)))
1394
result= client->store(res->ptr(),res->length());
1339
if ((res=val_str(buffer)))
1340
result= client->store(res->ptr(),res->length());
1397
1343
case DRIZZLE_TYPE_LONG:
1402
result= client->store((int32_t)nr);
1348
result= client->store((int32_t)nr);
1405
1351
case DRIZZLE_TYPE_LONGLONG:
1412
result= client->store((uint64_t)nr);
1414
result= client->store((int64_t)nr);
1358
result= client->store((uint64_t)nr);
1360
result= client->store((int64_t)nr);
1418
1364
case DRIZZLE_TYPE_DOUBLE:
1420
double nr= val_real();
1422
result= client->store(nr, decimals, buffer);
1425
case DRIZZLE_TYPE_TIME:
1430
result= client->store(&tm);
1366
double nr= val_real();
1368
result= client->store(nr, decimals, buffer);
1433
1371
case DRIZZLE_TYPE_DATETIME:
1434
case DRIZZLE_TYPE_MICROTIME:
1435
1372
case DRIZZLE_TYPE_TIMESTAMP:
1438
get_date(tm, TIME_FUZZY_DATE);
1440
result= client->store(&tm);
1375
get_date(&tm, TIME_FUZZY_DATE);
1377
result= client->store(&tm);
1444
1381
if (null_value)
1445
1382
result= client->store();
1450
uint32_t Item::max_char_length() const
1452
return max_length / collation.collation->mbmaxlen;
1455
void Item::fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs)
1457
max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
1458
collation.collation= cs;
1461
void Item::fix_char_length(uint32_t max_char_length_arg)
1463
max_length= char_to_byte_length_safe(max_char_length_arg, collation.collation->mbmaxlen);
1466
void Item::fix_char_length_uint64_t(uint64_t max_char_length_arg)
1468
uint64_t max_result_length= max_char_length_arg *
1469
collation.collation->mbmaxlen;
1471
if (max_result_length >= MAX_BLOB_WIDTH)
1473
max_length= MAX_BLOB_WIDTH;
1478
max_length= max_result_length;
1482
void Item::fix_length_and_charset_datetime(uint32_t max_char_length_arg)
1484
collation.set(&my_charset_bin);
1485
fix_char_length(max_char_length_arg);
1488
1386
Item_result item_cmp_type(Item_result a,Item_result b)
1490
1388
if (a == STRING_RESULT && b == STRING_RESULT)
1491
1389
return STRING_RESULT;
1493
1390
if (a == INT_RESULT && b == INT_RESULT)
1494
1391
return INT_RESULT;
1495
1392
else if (a == ROW_RESULT || b == ROW_RESULT)
1496
1393
return ROW_RESULT;
1498
1394
if ((a == INT_RESULT || a == DECIMAL_RESULT) &&
1499
1395
(b == INT_RESULT || b == DECIMAL_RESULT))
1500
1396
return DECIMAL_RESULT;
1502
1397
return REAL_RESULT;
1515
1410
switch (res_type) {
1516
1411
case STRING_RESULT:
1413
char buff[MAX_FIELD_WIDTH];
1414
String tmp(buff,sizeof(buff),&my_charset_bin),*result;
1415
result=item->val_str(&tmp);
1416
if (item->null_value)
1417
new_item= new Item_null(name);
1518
char buff[MAX_FIELD_WIDTH];
1519
String tmp(buff,sizeof(buff),&my_charset_bin),*result;
1520
result=item->val_str(&tmp);
1521
if (item->null_value)
1522
new_item= new Item_null(name);
1525
uint32_t length= result->length();
1526
char *tmp_str= memory::sql_strmake(result->ptr(), length);
1527
new_item= new Item_string(name, tmp_str, length, result->charset());
1420
uint32_t length= result->length();
1421
char *tmp_str= memory::sql_strmake(result->ptr(), length);
1422
new_item= new Item_string(name, tmp_str, length, result->charset());
1531
1426
case INT_RESULT:
1533
int64_t result=item->val_int();
1534
uint32_t length=item->max_length;
1535
bool null_value=item->null_value;
1536
new_item= (null_value ? (Item*) new Item_null(name) :
1537
(Item*) new Item_int(name, result, length));
1428
int64_t result=item->val_int();
1429
uint32_t length=item->max_length;
1430
bool null_value=item->null_value;
1431
new_item= (null_value ? (Item*) new Item_null(name) :
1432
(Item*) new Item_int(name, result, length));
1540
1435
case ROW_RESULT:
1541
if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM)
1544
Substitute constants only in Item_rows. Don't affect other Items
1545
with ROW_RESULT (eg Item_singlerow_subselect).
1436
if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM)
1439
Substitute constants only in Item_rows. Don't affect other Items
1440
with ROW_RESULT (eg Item_singlerow_subselect).
1547
For such Items more optimal is to detect if it is constant and replace
1548
it with Item_row. This would optimize queries like this:
1549
SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1);
1551
Item_row *item_row= (Item_row*) item;
1552
Item_row *comp_item_row= (Item_row*) comp_item;
1556
If item and comp_item are both Item_rows and have same number of cols
1557
then process items in Item_row one by one.
1558
We can't ignore NULL values here as this item may be used with <=>, in
1559
which case NULL's are significant.
1561
assert(item->result_type() == comp_item->result_type());
1562
assert(item_row->cols() == comp_item_row->cols());
1563
col= item_row->cols();
1565
resolve_const_item(session, item_row->addr(col),
1566
comp_item_row->element_index(col));
1442
For such Items more optimal is to detect if it is constant and replace
1443
it with Item_row. This would optimize queries like this:
1444
SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1);
1446
Item_row *item_row= (Item_row*) item;
1447
Item_row *comp_item_row= (Item_row*) comp_item;
1451
If item and comp_item are both Item_rows and have same number of cols
1452
then process items in Item_row one by one.
1453
We can't ignore NULL values here as this item may be used with <=>, in
1454
which case NULL's are significant.
1456
assert(item->result_type() == comp_item->result_type());
1457
assert(item_row->cols() == comp_item_row->cols());
1458
col= item_row->cols();
1460
resolve_const_item(session, item_row->addr(col),
1461
comp_item_row->element_index(col));
1570
1465
case REAL_RESULT:
1571
{ // It must REAL_RESULT
1572
double result= item->val_real();
1573
uint32_t length=item->max_length,decimals=item->decimals;
1574
bool null_value=item->null_value;
1575
new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
1576
new Item_float(name, result, decimals, length));
1466
{ // It must REAL_RESULT
1467
double result= item->val_real();
1468
uint32_t length=item->max_length,decimals=item->decimals;
1469
bool null_value=item->null_value;
1470
new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
1471
new Item_float(name, result, decimals, length));
1579
1474
case DECIMAL_RESULT:
1581
type::Decimal decimal_value;
1582
type::Decimal *result= item->val_decimal(&decimal_value);
1583
uint32_t length= item->max_length, decimals= item->decimals;
1584
bool null_value= item->null_value;
1585
new_item= (null_value ?
1586
(Item*) new Item_null(name) :
1587
(Item*) new Item_decimal(name, result, length, decimals));
1476
my_decimal decimal_value;
1477
my_decimal *result= item->val_decimal(&decimal_value);
1478
uint32_t length= item->max_length, decimals= item->decimals;
1479
bool null_value= item->null_value;
1480
new_item= (null_value ?
1481
(Item*) new Item_null(name) :
1482
(Item*) new Item_decimal(name, result, length, decimals));
1593
1489
session->change_item_tree(ref, new_item);
1607
1503
item_result=item->val_str(&item_tmp);
1608
1504
if (item->null_value)
1609
1505
return 1; // This must be true
1610
field->val_str_internal(&field_tmp);
1611
return not stringcmp(&field_tmp,item_result);
1506
field->val_str(&field_tmp);
1507
return !stringcmp(&field_tmp,item_result);
1614
1509
if (res_type == INT_RESULT)
1615
1510
return 1; // Both where of type int
1617
1511
if (res_type == DECIMAL_RESULT)
1619
type::Decimal item_buf, *item_val,
1513
my_decimal item_buf, *item_val,
1620
1514
field_buf, *field_val;
1621
1515
item_val= item->val_decimal(&item_buf);
1622
1516
if (item->null_value)
1623
1517
return 1; // This must be true
1624
1518
field_val= field->val_decimal(&field_buf);
1625
return !class_decimal_cmp(item_val, field_val);
1519
return !my_decimal_cmp(item_val, field_val);
1628
1521
double result= item->val_real();
1629
1522
if (item->null_value)
1632
1524
return result == field->val_real();
1664
1556
uint32_t convert_blob_length)
1666
1558
bool maybe_null= item->maybe_null;
1667
Field *new_field= NULL;
1669
1561
switch (item->result_type()) {
1670
1562
case REAL_RESULT:
1671
1563
new_field= new Field_double(item->max_length, maybe_null,
1672
1564
item->name, item->decimals, true);
1675
1566
case INT_RESULT:
1677
1568
Select an integer type with the minimal fit precision.
1678
1569
MY_INT32_NUM_DECIMAL_DIGITS is sign inclusive, don't consider the sign.
1679
1570
Values with MY_INT32_NUM_DECIMAL_DIGITS digits may or may not fit into
1680
Int32 -> make them field::Int64.
1571
Field_long : make them Field_int64_t.
1682
if (item->unsigned_flag)
1684
new_field= new field::Size(item->max_length, maybe_null,
1685
item->name, item->unsigned_flag);
1687
else if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
1689
new_field= new field::Int64(item->max_length, maybe_null,
1690
item->name, item->unsigned_flag);
1573
if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
1574
new_field=new Field_int64_t(item->max_length, maybe_null,
1575
item->name, item->unsigned_flag);
1694
new_field= new field::Int32(item->max_length, maybe_null,
1695
item->name, item->unsigned_flag);
1577
new_field=new Field_long(item->max_length, maybe_null,
1578
item->name, item->unsigned_flag);
1700
1580
case STRING_RESULT:
1701
1581
assert(item->collation.collation);
1706
1586
To preserve type they needed to be handled separately.
1708
1588
if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
1709
type == DRIZZLE_TYPE_TIME ||
1710
type == DRIZZLE_TYPE_MICROTIME ||
1711
1589
type == DRIZZLE_TYPE_DATE ||
1712
1590
type == DRIZZLE_TYPE_TIMESTAMP)
1714
1591
new_field= item->tmp_table_field_from_field_type(table, 1);
1716
Make sure that the blob fits into a Field_varstring which has
1593
Make sure that the blob fits into a Field_varstring which has
1720
1596
else if (item->max_length/item->collation.collation->mbmaxlen > 255 &&
1721
1597
convert_blob_length <= Field_varstring::MAX_SIZE &&
1722
1598
convert_blob_length)
1724
table->setVariableWidth();
1725
1599
new_field= new Field_varstring(convert_blob_length, maybe_null,
1726
item->name, item->collation.collation);
1600
item->name, table->getMutableShare(),
1601
item->collation.collation);
1730
1603
new_field= item->make_string_field(table);
1732
1604
new_field->set_derivation(item->collation.derivation);
1735
1606
case DECIMAL_RESULT:
1608
uint8_t dec= item->decimals;
1609
uint8_t intg= ((Item_decimal *) item)->decimal_precision() - dec;
1610
uint32_t len= item->max_length;
1613
Trying to put too many digits overall in a DECIMAL(prec,dec)
1614
will always throw a warning. We must limit dec to
1615
DECIMAL_MAX_SCALE however to prevent an assert() later.
1737
uint8_t dec= item->decimals;
1738
uint8_t intg= ((Item_decimal *) item)->decimal_precision() - dec;
1739
uint32_t len= item->max_length;
1620
signed int overflow;
1622
dec= min(dec, (uint8_t)DECIMAL_MAX_SCALE);
1742
Trying to put too many digits overall in a DECIMAL(prec,dec)
1743
will always throw a warning. We must limit dec to
1744
DECIMAL_MAX_SCALE however to prevent an assert() later.
1625
If the value still overflows the field with the corrected dec,
1626
we'll throw out decimals rather than integers. This is still
1627
bad and of course throws a truncation warning.
1628
+1: for decimal point
1749
signed int overflow;
1751
dec= min(dec, (uint8_t)DECIMAL_MAX_SCALE);
1754
If the value still overflows the field with the corrected dec,
1755
we'll throw out decimals rather than integers. This is still
1756
bad and of course throws a truncation warning.
1757
+1: for decimal point
1760
overflow= class_decimal_precision_to_length(intg + dec, dec,
1761
item->unsigned_flag) - len;
1764
dec= max(0, dec - overflow); // too long, discard fract
1766
len-= item->decimals - dec; // corrected value fits
1769
new_field= new Field_decimal(len,
1773
item->unsigned_flag);
1631
overflow= my_decimal_precision_to_length(intg + dec, dec,
1632
item->unsigned_flag) - len;
1635
dec= max(0, dec - overflow); // too long, discard fract
1637
len-= item->decimals - dec; // corrected value fits
1640
new_field= new Field_decimal(len,
1644
item->unsigned_flag);
1777
1647
case ROW_RESULT:
1778
1649
// This case should never be choosen
1784
1655
new_field->init(table);
1786
1657
if (copy_func && item->is_result_field())
1787
1658
*((*copy_func)++) = item; // Save for copy_funcs
1789
1659
if (modify_item)
1790
1660
item->set_result_field(new_field);
1792
1661
if (item->type() == Item::NULL_ITEM)
1793
1662
new_field->is_created_from_null_item= true;
1795
1663
return new_field;
1899
std::ostream& operator<<(std::ostream& output, const Item &item)
1901
switch (item.type())
1903
case drizzled::Item::SUBSELECT_ITEM :
1904
case drizzled::Item::FIELD_ITEM :
1905
case drizzled::Item::SUM_FUNC_ITEM :
1906
case drizzled::Item::STRING_ITEM :
1907
case drizzled::Item::INT_ITEM :
1908
case drizzled::Item::REAL_ITEM :
1909
case drizzled::Item::NULL_ITEM :
1910
case drizzled::Item::VARBIN_ITEM :
1911
case drizzled::Item::COPY_STR_ITEM :
1912
case drizzled::Item::FIELD_AVG_ITEM :
1913
case drizzled::Item::DEFAULT_VALUE_ITEM :
1914
case drizzled::Item::PROC_ITEM :
1915
case drizzled::Item::COND_ITEM :
1916
case drizzled::Item::REF_ITEM :
1917
case drizzled::Item::FIELD_STD_ITEM :
1918
case drizzled::Item::FIELD_VARIANCE_ITEM :
1919
case drizzled::Item::INSERT_VALUE_ITEM :
1920
case drizzled::Item::ROW_ITEM:
1921
case drizzled::Item::CACHE_ITEM :
1922
case drizzled::Item::TYPE_HOLDER :
1923
case drizzled::Item::PARAM_ITEM :
1924
case drizzled::Item::DECIMAL_ITEM :
1925
case drizzled::Item::FUNC_ITEM :
1926
case drizzled::Item::BOOLEAN_ITEM :
1929
output << item.full_name();
1931
output << drizzled::display::type(item.type());
1937
return output; // for multiple << operators.
1940
1765
} /* namespace drizzled */