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, Inc.
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
22
#include <drizzled/function/str/make_set.h>
23
#include <drizzled/session.h>
28
void Item_func_make_set::update_used_tables()
30
Item_func::update_used_tables();
31
item->update_used_tables();
32
used_tables_cache|=item->used_tables();
33
const_item_cache&=item->const_item();
37
void Item_func_make_set::split_sum_func(Session *session_arg, Item **ref_pointer_array,
40
item->split_sum_func(session_arg, ref_pointer_array, fields, &item, true);
41
Item_str_func::split_sum_func(session_arg, ref_pointer_array, fields);
45
void Item_func_make_set::fix_length_and_dec()
47
max_length=arg_count-1;
49
if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
52
for (uint32_t i=0 ; i < arg_count ; i++)
53
max_length+=args[i]->max_length;
55
used_tables_cache|= item->used_tables();
56
not_null_tables_cache&= item->not_null_tables();
57
const_item_cache&= item->const_item();
58
with_sum_func= with_sum_func || item->with_sum_func;
61
String *Item_func_make_set::val_str(String *str)
67
String *result=&my_empty_string;
70
if ((null_value=item->null_value))
74
bits &= ((uint64_t) 1 << arg_count)-1;
76
for (; bits; bits >>= 1, ptr++)
80
String *res= (*ptr)->val_str(str);
81
if (res) // Skip nulls
87
result=res; // Use original string
90
if (tmp_str.copy(*res)) // Don't use 'str'
91
return &my_empty_string;
97
if (result != &tmp_str)
98
{ // Copy data to tmp_str
99
if (tmp_str.alloc(result->length()+res->length()+1) ||
100
tmp_str.copy(*result))
101
return &my_empty_string;
104
if (tmp_str.append(STRING_WITH_LEN(","), &my_charset_bin) || tmp_str.append(*res))
105
return &my_empty_string;
114
Item *Item_func_make_set::transform(Item_transformer transformer, unsigned char *arg)
116
Item *new_item= item->transform(transformer, arg);
121
Session::change_item_tree() should be called only if the tree was
122
really transformed, i.e. when a new item has been created.
123
Otherwise we'll be allocating a lot of unnecessary memory for
124
change records at each execution.
126
if (item != new_item)
127
session.change_item_tree(&item, new_item);
129
return Item_str_func::transform(transformer, arg);
133
void Item_func_make_set::print(String *str, enum_query_type query_type)
135
str->append(STRING_WITH_LEN("make_set("));
136
item->print(str, query_type);
140
print_args(str, 0, query_type);
145
} /* namespace drizzled */