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
1158
case DRIZZLE_TYPE_LONG:
1190
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);
1192
1162
case DRIZZLE_TYPE_LONGLONG:
1193
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);
1195
1166
case DRIZZLE_TYPE_DOUBLE:
1196
1167
field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
1197
name, decimals, 0, unsigned_flag);
1168
name, decimals, 0, unsigned_flag);
1199
1170
case DRIZZLE_TYPE_NULL:
1200
field= new Field_null((unsigned char*) 0, max_length, name);
1171
field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1202
1173
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);
1174
field= new Field_date(maybe_null, name, &my_charset_bin);
1210
1176
case DRIZZLE_TYPE_TIMESTAMP:
1211
field= new field::Epoch(maybe_null, name);
1177
field= new Field_timestamp(maybe_null, name, &my_charset_bin);
1213
1179
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:
1180
field= new Field_datetime(maybe_null, name, &my_charset_bin);
1183
/* This case should never be chosen */
1185
/* Fall through to make_string_field() */
1221
1186
case DRIZZLE_TYPE_ENUM:
1222
1187
case DRIZZLE_TYPE_VARCHAR:
1223
1188
return make_string_field(table);
1224
1189
case DRIZZLE_TYPE_BLOB:
1190
if (this->type() == Item::TYPE_HOLDER)
1191
field= new Field_blob(max_length, maybe_null, name, collation.collation,
1225
1194
field= new Field_blob(max_length, maybe_null, name, collation.collation);
1226
1195
break; // Blob handled outside of case
1231
1198
field->init(table);
1361
1328
enum_field_types f_type;
1363
1330
switch ((f_type=field_type())) {
1364
case DRIZZLE_TYPE_DATE:
1365
1332
case DRIZZLE_TYPE_NULL:
1366
1333
case DRIZZLE_TYPE_ENUM:
1367
1334
case DRIZZLE_TYPE_BLOB:
1368
1335
case DRIZZLE_TYPE_VARCHAR:
1369
case DRIZZLE_TYPE_BOOLEAN:
1370
case DRIZZLE_TYPE_UUID:
1371
1336
case DRIZZLE_TYPE_DECIMAL:
1374
if ((res=val_str(buffer)))
1375
result= client->store(res->ptr(),res->length());
1339
if ((res=val_str(buffer)))
1340
result= client->store(res->ptr(),res->length());
1378
1343
case DRIZZLE_TYPE_LONG:
1383
result= client->store((int32_t)nr);
1348
result= client->store((int32_t)nr);
1386
1351
case DRIZZLE_TYPE_LONGLONG:
1393
result= client->store((uint64_t)nr);
1395
result= client->store((int64_t)nr);
1358
result= client->store((uint64_t)nr);
1360
result= client->store((int64_t)nr);
1399
1364
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);
1366
double nr= val_real();
1368
result= client->store(nr, decimals, buffer);
1414
1371
case DRIZZLE_TYPE_DATETIME:
1415
case DRIZZLE_TYPE_MICROTIME:
1416
1372
case DRIZZLE_TYPE_TIMESTAMP:
1419
get_date(tm, TIME_FUZZY_DATE);
1421
result= client->store(&tm);
1375
get_date(&tm, TIME_FUZZY_DATE);
1377
result= client->store(&tm);
1425
1381
if (null_value)
1426
1382
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
1386
Item_result item_cmp_type(Item_result a,Item_result b)
1471
1388
if (a == STRING_RESULT && b == STRING_RESULT)
1472
1389
return STRING_RESULT;
1474
1390
if (a == INT_RESULT && b == INT_RESULT)
1475
1391
return INT_RESULT;
1476
1392
else if (a == ROW_RESULT || b == ROW_RESULT)
1477
1393
return ROW_RESULT;
1479
1394
if ((a == INT_RESULT || a == DECIMAL_RESULT) &&
1480
1395
(b == INT_RESULT || b == DECIMAL_RESULT))
1481
1396
return DECIMAL_RESULT;
1483
1397
return REAL_RESULT;
1496
1410
switch (res_type) {
1497
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);
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());
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());
1512
1426
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));
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));
1521
1435
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).
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).
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));
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));
1551
1465
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));
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));
1560
1474
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));
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));
1574
1489
session->change_item_tree(ref, new_item);
1588
1503
item_result=item->val_str(&item_tmp);
1589
1504
if (item->null_value)
1590
1505
return 1; // This must be true
1591
field->val_str_internal(&field_tmp);
1592
return not stringcmp(&field_tmp,item_result);
1506
field->val_str(&field_tmp);
1507
return !stringcmp(&field_tmp,item_result);
1595
1509
if (res_type == INT_RESULT)
1596
1510
return 1; // Both where of type int
1598
1511
if (res_type == DECIMAL_RESULT)
1600
type::Decimal item_buf, *item_val,
1513
my_decimal item_buf, *item_val,
1601
1514
field_buf, *field_val;
1602
1515
item_val= item->val_decimal(&item_buf);
1603
1516
if (item->null_value)
1604
1517
return 1; // This must be true
1605
1518
field_val= field->val_decimal(&field_buf);
1606
return !class_decimal_cmp(item_val, field_val);
1519
return !my_decimal_cmp(item_val, field_val);
1609
1521
double result= item->val_real();
1610
1522
if (item->null_value)
1613
1524
return result == field->val_real();
1645
1556
uint32_t convert_blob_length)
1647
1558
bool maybe_null= item->maybe_null;
1648
Field *new_field= NULL;
1650
1561
switch (item->result_type()) {
1651
1562
case REAL_RESULT:
1652
1563
new_field= new Field_double(item->max_length, maybe_null,
1653
1564
item->name, item->decimals, true);
1656
1566
case INT_RESULT:
1658
1568
Select an integer type with the minimal fit precision.
1659
1569
MY_INT32_NUM_DECIMAL_DIGITS is sign inclusive, don't consider the sign.
1660
1570
Values with MY_INT32_NUM_DECIMAL_DIGITS digits may or may not fit into
1661
Int32 -> make them field::Int64.
1571
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);
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);
1675
new_field= new field::Int32(item->max_length, maybe_null,
1676
item->name, item->unsigned_flag);
1577
new_field=new Field_long(item->max_length, maybe_null,
1578
item->name, item->unsigned_flag);
1681
1580
case STRING_RESULT:
1682
1581
assert(item->collation.collation);
1583
enum enum_field_types type;
1685
1585
DATE/TIME fields have STRING_RESULT result type.
1686
1586
To preserve type they needed to be handled separately.
1688
if (field::isDateTime(item->field_type()))
1588
if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
1589
type == DRIZZLE_TYPE_DATE ||
1590
type == DRIZZLE_TYPE_TIMESTAMP)
1690
1591
new_field= item->tmp_table_field_from_field_type(table, 1);
1692
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
1696
1596
else if (item->max_length/item->collation.collation->mbmaxlen > 255 &&
1697
1597
convert_blob_length <= Field_varstring::MAX_SIZE &&
1698
1598
convert_blob_length)
1700
table->setVariableWidth();
1701
1599
new_field= new Field_varstring(convert_blob_length, maybe_null,
1702
item->name, item->collation.collation);
1600
item->name, table->getMutableShare(),
1601
item->collation.collation);
1706
1603
new_field= item->make_string_field(table);
1708
1604
new_field->set_derivation(item->collation.derivation);
1711
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.
1713
uint8_t dec= item->decimals;
1714
uint8_t intg= ((Item_decimal *) item)->decimal_precision() - dec;
1715
uint32_t len= item->max_length;
1620
signed int overflow;
1622
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.
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
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);
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);
1753
1647
case ROW_RESULT:
1754
1649
// This case should never be choosen
1760
1655
new_field->init(table);
1762
1657
if (copy_func && item->is_result_field())
1763
1658
*((*copy_func)++) = item; // Save for copy_funcs
1765
1659
if (modify_item)
1766
1660
item->set_result_field(new_field);
1768
1661
if (item->type() == Item::NULL_ITEM)
1769
1662
new_field->is_created_from_null_item= true;
1771
1663
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
1765
} /* namespace drizzled */