17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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>
35
#include <drizzled/field/str.h>
36
#include <drizzled/field/num.h>
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>
54
#include <drizzled/current_session.h>
55
#include <drizzled/session.h>
57
#include <drizzled/internal/m_string.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"
35
#include "drizzled/field/str.h"
36
#include "drizzled/field/num.h"
37
#include "drizzled/field/blob.h"
38
#include "drizzled/field/enum.h"
39
#include "drizzled/field/null.h"
40
#include "drizzled/field/date.h"
41
#include "drizzled/field/decimal.h"
42
#include "drizzled/field/real.h"
43
#include "drizzled/field/double.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"
49
#include "drizzled/field/varstring.h"
50
#include "drizzled/internal/m_string.h"
145
133
String *Item::val_string_from_decimal(String *str)
147
type::Decimal dec_buf, *dec= val_decimal(&dec_buf);
135
my_decimal dec_buf, *dec= val_decimal(&dec_buf);
151
class_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
152
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);
156
type::Decimal *Item::val_decimal_from_real(type::Decimal *decimal_value)
144
my_decimal *Item::val_decimal_from_real(my_decimal *decimal_value)
158
146
double nr= val_real();
162
double2_class_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
150
double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
163
151
return (decimal_value);
166
type::Decimal *Item::val_decimal_from_int(type::Decimal *decimal_value)
154
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value)
168
156
int64_t nr= val_int();
172
int2_class_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
160
int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
173
161
return decimal_value;
176
type::Decimal *Item::val_decimal_from_string(type::Decimal *decimal_value)
164
my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
195
184
return decimal_value;
198
type::Decimal *Item::val_decimal_from_date(type::Decimal *decimal_value)
187
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
202
if (get_date(ltime, TIME_FUZZY_DATE))
191
if (get_date(<ime, TIME_FUZZY_DATE))
204
decimal_value->set_zero();
193
my_decimal_set_zero(decimal_value);
205
194
null_value= 1; // set NULL, stop processing
208
return date2_class_decimal(<ime, decimal_value);
197
return date2my_decimal(<ime, decimal_value);
211
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))
217
decimal_value->set_zero();
206
my_decimal_set_zero(decimal_value);
220
return date2_class_decimal(<ime, decimal_value);
209
return date2my_decimal(<ime, decimal_value);
223
212
double Item::val_real_from_decimal()
225
214
/* Note that fix_fields may not be called for Item_avg_field items */
227
type::Decimal value_buff, *dec_val= val_decimal(&value_buff);
216
my_decimal value_buff, *dec_val= val_decimal(&value_buff);
230
class_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
219
my_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
236
225
/* Note that fix_fields may not be called for Item_avg_field items */
238
type::Decimal value, *dec_val= val_decimal(&value);
227
my_decimal value, *dec_val= val_decimal(&value);
242
dec_val->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
230
my_decimal2int(E_DEC_FATAL_ERROR, dec_val, unsigned_flag, &result);
247
bool Item::save_time_in_field(Field *field)
234
int Item::save_time_in_field(Field *field)
237
if (get_time(<ime))
252
238
return set_field_to_null(field);
254
239
field->set_notnull();
256
return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_TIME);
240
return field->store_time(<ime, DRIZZLE_TIMESTAMP_TIME);
259
bool Item::save_date_in_field(Field *field)
243
int Item::save_date_in_field(Field *field)
263
if (get_date(ltime, TIME_FUZZY_DATE))
246
if (get_date(<ime, TIME_FUZZY_DATE))
264
247
return set_field_to_null(field);
266
248
field->set_notnull();
268
return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
249
return field->store_time(<ime, DRIZZLE_TIMESTAMP_DATETIME);
297
276
with_sum_func(false),
298
277
is_autogenerated_name(true),
299
278
with_subselect(false),
300
collation(&my_charset_bin, DERIVATION_COERCIBLE),
301
_session(*current_session)
279
collation(&my_charset_bin, DERIVATION_COERCIBLE)
303
281
cmp_context= (Item_result)-1;
305
283
/* Put item in free list so that we can free all items at end */
306
next= getSession().free_list;
307
getSession().free_list= this;
284
Session *session= current_session;
285
next= session->free_list;
286
session->free_list= this;
310
289
Item constructor can be called during execution other then SQL_COM
311
command => we should check session->getLex()->current_select on zero (session->lex
290
command => we should check session->lex->current_select on zero (session->lex
312
291
can be uninitialised)
314
if (getSession().getLex()->current_select)
293
if (session->lex->current_select)
316
enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
295
enum_parsing_place place= session->lex->current_select->parsing_place;
317
296
if (place == SELECT_LIST || place == IN_HAVING)
318
getSession().getLex()->current_select->select_n_having_items++;
297
session->lex->current_select->select_n_having_items++;
474
452
return conv->safe ? conv : NULL;
477
bool Item::get_date(type::Time <ime,uint32_t fuzzydate)
455
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
485
else if (result_type() == STRING_RESULT)
487
char buff[type::Time::MAX_STRING_LENGTH];
488
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
489
if (!(res=val_str(&tmp)) ||
490
str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
491
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
498
int64_t value= val_int();
499
type::datetime_t date_value;
501
ltime.convert(date_value, value, fuzzydate);
503
if (not type::is_valid(date_value))
505
char buff[DECIMAL_LONGLONG_DIGITS], *end;
506
end= internal::int64_t10_to_str(value, buff, -10);
507
make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
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));
521
bool Item::get_time(type::Time <ime)
487
bool Item::get_time(DRIZZLE_TIME *ltime)
523
char buff[type::Time::MAX_STRING_LENGTH];
524
490
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
525
if (!(res=val_str(&tmp)) or
526
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));
536
bool Item::get_date_result(type::Time <ime,uint32_t fuzzydate)
500
bool Item::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
538
return get_date(ltime, fuzzydate);
502
return get_date(ltime,fuzzydate);
541
505
bool Item::is_null()
1189
1163
case DRIZZLE_TYPE_LONG:
1190
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);
1192
1167
case DRIZZLE_TYPE_LONGLONG:
1193
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);
1195
1171
case DRIZZLE_TYPE_DOUBLE:
1196
1172
field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
1197
name, decimals, 0, unsigned_flag);
1173
name, decimals, 0, unsigned_flag);
1199
1175
case DRIZZLE_TYPE_NULL:
1200
field= new Field_null((unsigned char*) 0, max_length, name);
1176
field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1202
1178
case DRIZZLE_TYPE_DATE:
1203
field= new Field_date(maybe_null, name);
1206
case DRIZZLE_TYPE_MICROTIME:
1207
field= new field::Microtime(maybe_null, name);
1179
field= new Field_date(maybe_null, name, &my_charset_bin);
1210
1181
case DRIZZLE_TYPE_TIMESTAMP:
1211
field= new field::Epoch(maybe_null, name);
1182
field= new Field_timestamp(maybe_null, name, &my_charset_bin);
1213
1184
case DRIZZLE_TYPE_DATETIME:
1214
field= new Field_datetime(maybe_null, name);
1216
case DRIZZLE_TYPE_TIME:
1217
field= new field::Time(maybe_null, name);
1219
case DRIZZLE_TYPE_BOOLEAN:
1220
case DRIZZLE_TYPE_UUID:
1185
field= new Field_datetime(maybe_null, name, &my_charset_bin);
1188
/* This case should never be chosen */
1190
/* Fall through to make_string_field() */
1221
1191
case DRIZZLE_TYPE_ENUM:
1222
1192
case DRIZZLE_TYPE_VARCHAR:
1223
1193
return make_string_field(table);
1361
1329
enum_field_types f_type;
1363
1331
switch ((f_type=field_type())) {
1364
case DRIZZLE_TYPE_DATE:
1365
1333
case DRIZZLE_TYPE_NULL:
1366
1334
case DRIZZLE_TYPE_ENUM:
1367
1335
case DRIZZLE_TYPE_BLOB:
1368
1336
case DRIZZLE_TYPE_VARCHAR:
1369
case DRIZZLE_TYPE_BOOLEAN:
1370
case DRIZZLE_TYPE_UUID:
1371
1337
case DRIZZLE_TYPE_DECIMAL:
1374
if ((res=val_str(buffer)))
1375
result= client->store(res->ptr(),res->length());
1340
if ((res=val_str(buffer)))
1341
result= client->store(res->ptr(),res->length());
1378
1344
case DRIZZLE_TYPE_LONG:
1383
result= client->store((int32_t)nr);
1349
result= client->store((int32_t)nr);
1386
1352
case DRIZZLE_TYPE_LONGLONG:
1393
result= client->store((uint64_t)nr);
1395
result= client->store((int64_t)nr);
1359
result= client->store((uint64_t)nr);
1361
result= client->store((int64_t)nr);
1399
1365
case DRIZZLE_TYPE_DOUBLE:
1401
double nr= val_real();
1403
result= client->store(nr, decimals, buffer);
1406
case DRIZZLE_TYPE_TIME:
1411
result= client->store(&tm);
1367
double nr= val_real();
1369
result= client->store(nr, decimals, buffer);
1414
1372
case DRIZZLE_TYPE_DATETIME:
1415
case DRIZZLE_TYPE_MICROTIME:
1416
1373
case DRIZZLE_TYPE_TIMESTAMP:
1419
get_date(tm, TIME_FUZZY_DATE);
1421
result= client->store(&tm);
1376
get_date(&tm, TIME_FUZZY_DATE);
1378
result= client->store(&tm);
1425
1382
if (null_value)
1426
1383
result= client->store();
1431
uint32_t Item::max_char_length() const
1433
return max_length / collation.collation->mbmaxlen;
1436
void Item::fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs)
1438
max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
1439
collation.collation= cs;
1442
void Item::fix_char_length(uint32_t max_char_length_arg)
1444
max_length= char_to_byte_length_safe(max_char_length_arg, collation.collation->mbmaxlen);
1447
void Item::fix_char_length_uint64_t(uint64_t max_char_length_arg)
1449
uint64_t max_result_length= max_char_length_arg *
1450
collation.collation->mbmaxlen;
1452
if (max_result_length >= MAX_BLOB_WIDTH)
1454
max_length= MAX_BLOB_WIDTH;
1459
max_length= max_result_length;
1463
void Item::fix_length_and_charset_datetime(uint32_t max_char_length_arg)
1465
collation.set(&my_charset_bin);
1466
fix_char_length(max_char_length_arg);
1469
1387
Item_result item_cmp_type(Item_result a,Item_result b)
1471
1389
if (a == STRING_RESULT && b == STRING_RESULT)
1472
1390
return STRING_RESULT;
1474
1391
if (a == INT_RESULT && b == INT_RESULT)
1475
1392
return INT_RESULT;
1476
1393
else if (a == ROW_RESULT || b == ROW_RESULT)
1477
1394
return ROW_RESULT;
1479
1395
if ((a == INT_RESULT || a == DECIMAL_RESULT) &&
1480
1396
(b == INT_RESULT || b == DECIMAL_RESULT))
1481
1397
return DECIMAL_RESULT;
1483
1398
return REAL_RESULT;
1496
1411
switch (res_type) {
1497
1412
case STRING_RESULT:
1414
char buff[MAX_FIELD_WIDTH];
1415
String tmp(buff,sizeof(buff),&my_charset_bin),*result;
1416
result=item->val_str(&tmp);
1417
if (item->null_value)
1418
new_item= new Item_null(name);
1499
char buff[MAX_FIELD_WIDTH];
1500
String tmp(buff,sizeof(buff),&my_charset_bin),*result;
1501
result=item->val_str(&tmp);
1502
if (item->null_value)
1503
new_item= new Item_null(name);
1506
uint32_t length= result->length();
1507
char *tmp_str= memory::sql_strmake(result->ptr(), length);
1508
new_item= new Item_string(name, tmp_str, length, result->charset());
1421
uint32_t length= result->length();
1422
char *tmp_str= memory::sql_strmake(result->ptr(), length);
1423
new_item= new Item_string(name, tmp_str, length, result->charset());
1512
1427
case INT_RESULT:
1514
int64_t result=item->val_int();
1515
uint32_t length=item->max_length;
1516
bool null_value=item->null_value;
1517
new_item= (null_value ? (Item*) new Item_null(name) :
1518
(Item*) new Item_int(name, result, length));
1429
int64_t result=item->val_int();
1430
uint32_t length=item->max_length;
1431
bool null_value=item->null_value;
1432
new_item= (null_value ? (Item*) new Item_null(name) :
1433
(Item*) new Item_int(name, result, length));
1521
1436
case ROW_RESULT:
1522
if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM)
1525
Substitute constants only in Item_rows. Don't affect other Items
1526
with ROW_RESULT (eg Item_singlerow_subselect).
1437
if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM)
1440
Substitute constants only in Item_rows. Don't affect other Items
1441
with ROW_RESULT (eg Item_singlerow_subselect).
1528
For such Items more optimal is to detect if it is constant and replace
1529
it with Item_row. This would optimize queries like this:
1530
SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1);
1532
Item_row *item_row= (Item_row*) item;
1533
Item_row *comp_item_row= (Item_row*) comp_item;
1537
If item and comp_item are both Item_rows and have same number of cols
1538
then process items in Item_row one by one.
1539
We can't ignore NULL values here as this item may be used with <=>, in
1540
which case NULL's are significant.
1542
assert(item->result_type() == comp_item->result_type());
1543
assert(item_row->cols() == comp_item_row->cols());
1544
col= item_row->cols();
1546
resolve_const_item(session, item_row->addr(col),
1547
comp_item_row->element_index(col));
1443
For such Items more optimal is to detect if it is constant and replace
1444
it with Item_row. This would optimize queries like this:
1445
SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1);
1447
Item_row *item_row= (Item_row*) item;
1448
Item_row *comp_item_row= (Item_row*) comp_item;
1452
If item and comp_item are both Item_rows and have same number of cols
1453
then process items in Item_row one by one.
1454
We can't ignore NULL values here as this item may be used with <=>, in
1455
which case NULL's are significant.
1457
assert(item->result_type() == comp_item->result_type());
1458
assert(item_row->cols() == comp_item_row->cols());
1459
col= item_row->cols();
1461
resolve_const_item(session, item_row->addr(col),
1462
comp_item_row->element_index(col));
1551
1466
case REAL_RESULT:
1552
{ // It must REAL_RESULT
1553
double result= item->val_real();
1554
uint32_t length=item->max_length,decimals=item->decimals;
1555
bool null_value=item->null_value;
1556
new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
1557
new Item_float(name, result, decimals, length));
1467
{ // It must REAL_RESULT
1468
double result= item->val_real();
1469
uint32_t length=item->max_length,decimals=item->decimals;
1470
bool null_value=item->null_value;
1471
new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
1472
new Item_float(name, result, decimals, length));
1560
1475
case DECIMAL_RESULT:
1562
type::Decimal decimal_value;
1563
type::Decimal *result= item->val_decimal(&decimal_value);
1564
uint32_t length= item->max_length, decimals= item->decimals;
1565
bool null_value= item->null_value;
1566
new_item= (null_value ?
1567
(Item*) new Item_null(name) :
1568
(Item*) new Item_decimal(name, result, length, decimals));
1477
my_decimal decimal_value;
1478
my_decimal *result= item->val_decimal(&decimal_value);
1479
uint32_t length= item->max_length, decimals= item->decimals;
1480
bool null_value= item->null_value;
1481
new_item= (null_value ?
1482
(Item*) new Item_null(name) :
1483
(Item*) new Item_decimal(name, result, length, decimals));
1574
1490
session->change_item_tree(ref, new_item);
1588
1504
item_result=item->val_str(&item_tmp);
1589
1505
if (item->null_value)
1590
1506
return 1; // This must be true
1591
field->val_str_internal(&field_tmp);
1592
return not stringcmp(&field_tmp,item_result);
1507
field->val_str(&field_tmp);
1508
return !stringcmp(&field_tmp,item_result);
1595
1510
if (res_type == INT_RESULT)
1596
1511
return 1; // Both where of type int
1598
1512
if (res_type == DECIMAL_RESULT)
1600
type::Decimal item_buf, *item_val,
1514
my_decimal item_buf, *item_val,
1601
1515
field_buf, *field_val;
1602
1516
item_val= item->val_decimal(&item_buf);
1603
1517
if (item->null_value)
1604
1518
return 1; // This must be true
1605
1519
field_val= field->val_decimal(&field_buf);
1606
return !class_decimal_cmp(item_val, field_val);
1520
return !my_decimal_cmp(item_val, field_val);
1609
1522
double result= item->val_real();
1610
1523
if (item->null_value)
1613
1525
return result == field->val_real();
1645
1557
uint32_t convert_blob_length)
1647
1559
bool maybe_null= item->maybe_null;
1648
Field *new_field= NULL;
1650
1562
switch (item->result_type()) {
1651
1563
case REAL_RESULT:
1652
1564
new_field= new Field_double(item->max_length, maybe_null,
1653
1565
item->name, item->decimals, true);
1656
1567
case INT_RESULT:
1658
1569
Select an integer type with the minimal fit precision.
1659
1570
MY_INT32_NUM_DECIMAL_DIGITS is sign inclusive, don't consider the sign.
1660
1571
Values with MY_INT32_NUM_DECIMAL_DIGITS digits may or may not fit into
1661
Int32 -> make them field::Int64.
1572
Field_long : make them Field_int64_t.
1663
if (item->unsigned_flag)
1665
new_field= new field::Size(item->max_length, maybe_null,
1666
item->name, item->unsigned_flag);
1668
else if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
1670
new_field= new field::Int64(item->max_length, maybe_null,
1671
item->name, item->unsigned_flag);
1574
if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
1575
new_field=new Field_int64_t(item->max_length, maybe_null,
1576
item->name, item->unsigned_flag);
1675
new_field= new field::Int32(item->max_length, maybe_null,
1676
item->name, item->unsigned_flag);
1578
new_field=new Field_long(item->max_length, maybe_null,
1579
item->name, item->unsigned_flag);
1681
1581
case STRING_RESULT:
1682
1582
assert(item->collation.collation);
1584
enum enum_field_types type;
1685
1586
DATE/TIME fields have STRING_RESULT result type.
1686
1587
To preserve type they needed to be handled separately.
1688
if (field::isDateTime(item->field_type()))
1589
if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
1590
type == DRIZZLE_TYPE_DATE ||
1591
type == DRIZZLE_TYPE_TIMESTAMP)
1690
1593
new_field= item->tmp_table_field_from_field_type(table, 1);
1708
1611
new_field->set_derivation(item->collation.derivation);
1711
1613
case DECIMAL_RESULT:
1615
uint8_t dec= item->decimals;
1616
uint8_t intg= ((Item_decimal *) item)->decimal_precision() - dec;
1617
uint32_t len= item->max_length;
1620
Trying to put too many digits overall in a DECIMAL(prec,dec)
1621
will always throw a warning. We must limit dec to
1622
DECIMAL_MAX_SCALE however to prevent an assert() later.
1713
uint8_t dec= item->decimals;
1714
uint8_t intg= ((Item_decimal *) item)->decimal_precision() - dec;
1715
uint32_t len= item->max_length;
1627
signed int overflow;
1629
dec= min(dec, (uint8_t)DECIMAL_MAX_SCALE);
1718
Trying to put too many digits overall in a DECIMAL(prec,dec)
1719
will always throw a warning. We must limit dec to
1720
DECIMAL_MAX_SCALE however to prevent an assert() later.
1632
If the value still overflows the field with the corrected dec,
1633
we'll throw out decimals rather than integers. This is still
1634
bad and of course throws a truncation warning.
1635
+1: for decimal point
1725
signed int overflow;
1727
dec= min(dec, (uint8_t)DECIMAL_MAX_SCALE);
1730
If the value still overflows the field with the corrected dec,
1731
we'll throw out decimals rather than integers. This is still
1732
bad and of course throws a truncation warning.
1733
+1: for decimal point
1736
overflow= class_decimal_precision_to_length(intg + dec, dec,
1737
item->unsigned_flag) - len;
1740
dec= max(0, dec - overflow); // too long, discard fract
1742
len-= item->decimals - dec; // corrected value fits
1745
new_field= new Field_decimal(len,
1749
item->unsigned_flag);
1638
overflow= my_decimal_precision_to_length(intg + dec, dec,
1639
item->unsigned_flag) - len;
1642
dec= max(0, dec - overflow); // too long, discard fract
1644
len-= item->decimals - dec; // corrected value fits
1647
new_field= new Field_decimal(len,
1651
item->unsigned_flag);
1753
1654
case ROW_RESULT:
1754
1656
// This case should never be choosen
1760
1662
new_field->init(table);
1762
1664
if (copy_func && item->is_result_field())
1763
1665
*((*copy_func)++) = item; // Save for copy_funcs
1765
1666
if (modify_item)
1766
1667
item->set_result_field(new_field);
1768
1668
if (item->type() == Item::NULL_ITEM)
1769
1669
new_field->is_created_from_null_item= true;
1771
1670
return new_field;
1875
std::ostream& operator<<(std::ostream& output, const Item &item)
1877
switch (item.type())
1879
case drizzled::Item::SUBSELECT_ITEM :
1880
case drizzled::Item::FIELD_ITEM :
1881
case drizzled::Item::SUM_FUNC_ITEM :
1882
case drizzled::Item::STRING_ITEM :
1883
case drizzled::Item::INT_ITEM :
1884
case drizzled::Item::REAL_ITEM :
1885
case drizzled::Item::NULL_ITEM :
1886
case drizzled::Item::VARBIN_ITEM :
1887
case drizzled::Item::COPY_STR_ITEM :
1888
case drizzled::Item::FIELD_AVG_ITEM :
1889
case drizzled::Item::DEFAULT_VALUE_ITEM :
1890
case drizzled::Item::PROC_ITEM :
1891
case drizzled::Item::COND_ITEM :
1892
case drizzled::Item::REF_ITEM :
1893
case drizzled::Item::FIELD_STD_ITEM :
1894
case drizzled::Item::FIELD_VARIANCE_ITEM :
1895
case drizzled::Item::INSERT_VALUE_ITEM :
1896
case drizzled::Item::ROW_ITEM:
1897
case drizzled::Item::CACHE_ITEM :
1898
case drizzled::Item::TYPE_HOLDER :
1899
case drizzled::Item::PARAM_ITEM :
1900
case drizzled::Item::DECIMAL_ITEM :
1901
case drizzled::Item::FUNC_ITEM :
1902
case drizzled::Item::BOOLEAN_ITEM :
1905
output << item.full_name();
1907
output << drizzled::display::type(item.type());
1913
return output; // for multiple << operators.
1916
1772
} /* namespace drizzled */