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/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>
34
#include <drizzled/field/str.h>
35
#include <drizzled/field/num.h>
36
#include <drizzled/field/blob.h>
37
#include <drizzled/field/date.h>
38
#include <drizzled/field/datetime.h>
39
#include <drizzled/field/decimal.h>
40
#include <drizzled/field/double.h>
41
#include <drizzled/field/enum.h>
42
#include <drizzled/field/epoch.h>
43
#include <drizzled/field/int32.h>
44
#include <drizzled/field/int64.h>
45
#include <drizzled/field/microtime.h>
46
#include <drizzled/field/null.h>
47
#include <drizzled/field/real.h>
48
#include <drizzled/field/size.h>
49
#include <drizzled/field/time.h>
50
#include <drizzled/field/varstring.h>
51
#include <drizzled/current_session.h>
52
#include <drizzled/session.h>
53
#include <drizzled/internal/m_string.h>
54
#include <drizzled/item/ref.h>
55
#include <drizzled/item/subselect.h>
56
#include <drizzled/sql_lex.h>
57
#include <drizzled/system_variables.h>
307
306
Item constructor can be called during execution other then SQL_COM
308
command => we should check session->lex->current_select on zero (session->lex
307
command => we should check session->lex().current_select on zero (session->lex
309
308
can be uninitialised)
311
if (getSession().lex->current_select)
310
if (getSession().lex().current_select)
313
enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
312
enum_parsing_place place= getSession().lex().current_select->parsing_place;
314
313
if (place == SELECT_LIST || place == IN_HAVING)
315
getSession().getLex()->current_select->select_n_having_items++;
314
getSession().lex().current_select->select_n_having_items++;
436
420
if (orig_len != length && ! is_autogenerated_name)
439
push_warning_printf(&getSession(),
440
DRIZZLE_ERROR::WARN_LEVEL_WARN,
441
ER_NAME_BECOMES_EMPTY,
442
ER(ER_NAME_BECOMES_EMPTY),
443
str + length - orig_len);
423
push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY), str + length - orig_len);
445
push_warning_printf(&getSession(),
446
DRIZZLE_ERROR::WARN_LEVEL_WARN,
448
ER(ER_REMOVED_SPACES),
449
str + length - orig_len);
425
push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES), str + length - orig_len);
452
428
name= memory::sql_strmake(str, length);
781
750
Item_ref to allow fields from view being stored in tmp table.
783
752
Item_aggregate_ref *item_ref;
784
uint32_t el= fields.elements;
753
uint32_t el= fields.size();
785
754
Item *real_itm= real_item();
787
756
ref_pointer_array[el]= real_itm;
788
if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context,
789
ref_pointer_array + el, 0, name)))
790
return; /* fatal_error is set */
757
item_ref= new Item_aggregate_ref(&session->lex().current_select->context, ref_pointer_array + el, 0, name);
791
758
if (type() == SUM_FUNC_ITEM)
792
759
item_ref->depended_from= ((Item_sum *) this)->depended_from();
793
760
fields.push_front(real_itm);
794
session->change_item_tree(ref, item_ref);
1088
1055
bool Item::is_datetime()
1090
switch (field_type())
1092
case DRIZZLE_TYPE_TIME:
1093
case DRIZZLE_TYPE_DATE:
1094
case DRIZZLE_TYPE_DATETIME:
1095
case DRIZZLE_TYPE_TIMESTAMP:
1096
case DRIZZLE_TYPE_MICROTIME:
1098
case DRIZZLE_TYPE_BLOB:
1099
case DRIZZLE_TYPE_VARCHAR:
1100
case DRIZZLE_TYPE_DOUBLE:
1101
case DRIZZLE_TYPE_DECIMAL:
1102
case DRIZZLE_TYPE_ENUM:
1103
case DRIZZLE_TYPE_LONG:
1104
case DRIZZLE_TYPE_LONGLONG:
1105
case DRIZZLE_TYPE_NULL:
1106
case DRIZZLE_TYPE_UUID:
1107
case DRIZZLE_TYPE_BOOLEAN:
1057
return field::isDateTime(field_type());
1115
1060
String *Item::check_well_formed_result(String *str, bool send_error)
1117
1062
/* Check whether we got a well-formed string */
1118
const CHARSET_INFO * const cs= str->charset();
1063
const charset_info_st * const cs= str->charset();
1119
1064
int well_formed_error;
1120
1065
uint32_t wlen= cs->cset->well_formed_len(cs,
1121
1066
str->ptr(), str->ptr() + str->length(),
1216
1161
name, decimals, 0, unsigned_flag);
1218
1163
case DRIZZLE_TYPE_NULL:
1219
field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1164
field= new Field_null((unsigned char*) 0, max_length, name);
1221
1166
case DRIZZLE_TYPE_DATE:
1222
field= new Field_date(maybe_null, name, &my_charset_bin);
1167
field= new Field_date(maybe_null, name);
1225
1170
case DRIZZLE_TYPE_MICROTIME:
1389
1332
case DRIZZLE_TYPE_UUID:
1390
1333
case DRIZZLE_TYPE_DECIMAL:
1393
if ((res=val_str(buffer)))
1394
result= client->store(res->ptr(),res->length());
1335
if (String* res=val_str(buffer))
1336
client->store(res->ptr(), res->length());
1397
1339
case DRIZZLE_TYPE_LONG:
1341
int64_t nr= val_int();
1401
1342
if (!null_value)
1402
result= client->store((int32_t)nr);
1343
client->store((int32_t)nr);
1405
1346
case DRIZZLE_TYPE_LONGLONG:
1348
int64_t nr= val_int();
1409
1349
if (!null_value)
1411
1351
if (unsigned_flag)
1412
result= client->store((uint64_t)nr);
1352
client->store((uint64_t)nr);
1414
result= client->store((int64_t)nr);
1354
client->store((int64_t)nr);
1452
1390
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
1393
void Item::fix_char_length(uint32_t max_char_length_arg)
1463
1395
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
1398
Item_result item_cmp_type(Item_result a,Item_result b)
1490
1400
if (a == STRING_RESULT && b == STRING_RESULT)
1700
1600
case STRING_RESULT:
1701
1601
assert(item->collation.collation);
1703
enum enum_field_types type;
1705
1604
DATE/TIME fields have STRING_RESULT result type.
1706
1605
To preserve type they needed to be handled separately.
1708
if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
1709
type == DRIZZLE_TYPE_TIME ||
1710
type == DRIZZLE_TYPE_MICROTIME ||
1711
type == DRIZZLE_TYPE_DATE ||
1712
type == DRIZZLE_TYPE_TIMESTAMP)
1607
if (field::isDateTime(item->field_type()))
1714
1609
new_field= item->tmp_table_field_from_field_type(table, 1);