1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
22
#include <drizzled/function/str/make_set.h>
23
#include <drizzled/session.h>
25
void Item_func_make_set::update_used_tables()
27
Item_func::update_used_tables();
28
item->update_used_tables();
29
used_tables_cache|=item->used_tables();
30
const_item_cache&=item->const_item();
34
void Item_func_make_set::split_sum_func(Session *session, Item **ref_pointer_array,
37
item->split_sum_func(session, ref_pointer_array, fields, &item, true);
38
Item_str_func::split_sum_func(session, ref_pointer_array, fields);
42
void Item_func_make_set::fix_length_and_dec()
44
max_length=arg_count-1;
46
if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
49
for (uint32_t i=0 ; i < arg_count ; i++)
50
max_length+=args[i]->max_length;
52
used_tables_cache|= item->used_tables();
53
not_null_tables_cache&= item->not_null_tables();
54
const_item_cache&= item->const_item();
55
with_sum_func= with_sum_func || item->with_sum_func;
58
String *Item_func_make_set::val_str(String *str)
64
String *result=&my_empty_string;
67
if ((null_value=item->null_value))
71
bits &= ((uint64_t) 1 << arg_count)-1;
73
for (; bits; bits >>= 1, ptr++)
77
String *res= (*ptr)->val_str(str);
78
if (res) // Skip nulls
84
result=res; // Use original string
87
if (tmp_str.copy(*res)) // Don't use 'str'
88
return &my_empty_string;
94
if (result != &tmp_str)
95
{ // Copy data to tmp_str
96
if (tmp_str.alloc(result->length()+res->length()+1) ||
97
tmp_str.copy(*result))
98
return &my_empty_string;
101
if (tmp_str.append(STRING_WITH_LEN(","), &my_charset_bin) || tmp_str.append(*res))
102
return &my_empty_string;
111
Item *Item_func_make_set::transform(Item_transformer transformer, unsigned char *arg)
113
Item *new_item= item->transform(transformer, arg);
118
Session::change_item_tree() should be called only if the tree was
119
really transformed, i.e. when a new item has been created.
120
Otherwise we'll be allocating a lot of unnecessary memory for
121
change records at each execution.
123
if (item != new_item)
124
current_session->change_item_tree(&item, new_item);
125
return Item_str_func::transform(transformer, arg);
129
void Item_func_make_set::print(String *str, enum_query_type query_type)
131
str->append(STRING_WITH_LEN("make_set("));
132
item->print(str, query_type);
136
print_args(str, 0, query_type);