drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
make_set.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
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.
9 *
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.
14 *
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
18 */
19
20#include <config.h>
21
22#include <drizzled/function/str/make_set.h>
23#include <drizzled/session.h>
24
25namespace drizzled {
26
27void Item_func_make_set::update_used_tables()
28{
29 Item_func::update_used_tables();
30 item->update_used_tables();
31 used_tables_cache|=item->used_tables();
32 const_item_cache&=item->const_item();
33}
34
35
36void Item_func_make_set::split_sum_func(Session *session_arg, Item **ref_pointer_array,
37 List<Item> &fields)
38{
39 item->split_sum_func(session_arg, ref_pointer_array, fields, &item, true);
40 Item_str_func::split_sum_func(session_arg, ref_pointer_array, fields);
41}
42
43
44void Item_func_make_set::fix_length_and_dec()
45{
46 max_length=arg_count-1;
47
48 if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
49 return;
50
51 for (uint32_t i=0 ; i < arg_count ; i++)
52 max_length+=args[i]->max_length;
53
54 used_tables_cache|= item->used_tables();
55 not_null_tables_cache&= item->not_null_tables();
56 const_item_cache&= item->const_item();
57 with_sum_func= with_sum_func || item->with_sum_func;
58}
59
61{
62 assert(fixed == 1);
63 uint64_t bits;
64 bool first_found=0;
65 Item **ptr=args;
66 String *result=&my_empty_string;
67
68 bits=item->val_int();
69 if ((null_value=item->null_value))
70 return NULL;
71
72 if (arg_count < 64)
73 bits &= ((uint64_t) 1 << arg_count)-1;
74
75 for (; bits; bits >>= 1, ptr++)
76 {
77 if (bits & 1)
78 {
79 String *res= (*ptr)->val_str(str);
80 if (res) // Skip nulls
81 {
82 if (!first_found)
83 { // First argument
84 first_found=1;
85 if (res != str)
86 result=res; // Use original string
87 else
88 {
89 tmp_str.copy(*res);
90 result= &tmp_str;
91 }
92 }
93 else
94 {
95 if (result != &tmp_str)
96 { // Copy data to tmp_str
97 tmp_str.alloc(result->length()+res->length()+1);
98 tmp_str.copy(*result);
99 result= &tmp_str;
100 }
101 tmp_str.append(STRING_WITH_LEN(","));
102 tmp_str.append(*res);
103 }
104 }
105 }
106 }
107 return result;
108}
109
110
111Item *Item_func_make_set::transform(Item_transformer transformer, unsigned char *arg)
112{
113 Item *new_item= item->transform(transformer, arg);
114 if (!new_item)
115 return 0;
116 item= new_item;
117 return Item_str_func::transform(transformer, arg);
118}
119
120
122{
123 str->append(STRING_WITH_LEN("make_set("));
124 item->print(str);
125 if (arg_count)
126 {
127 str->append(',');
128 print_args(str, 0);
129 }
130 str->append(')');
131}
132
133} /* namespace drizzled */
virtual void print(String *str)
Definition make_set.cc:121
String * val_str(String *str)
Definition make_set.cc:60
void split_sum_func(Session *session_arg, Item **ref_pointer_array, List< Item > &fields)
Definition make_set.cc:36
Item * transform(Item_transformer transformer, unsigned char *arg)
Definition make_set.cc:111
virtual void split_sum_func(Session *session, Item **ref_pointer_array, List< Item > &fields)
Definition func.cc:408
Item * transform(Item_transformer transformer, unsigned char *arg)
Definition func.cc:340
bool fixed
Definition item.h:122
virtual Item * transform(Item_transformer transformer, unsigned char *arg)
Definition item.cc:387
bool null_value
Definition item.h:124
TODO: Rename this file - func.h is stupid.