~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/str/make_set.cc

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
25
 
namespace drizzled
26
 
{
27
 
 
28
 
void Item_func_make_set::update_used_tables()
29
 
{
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();
34
 
}
35
 
 
36
 
 
37
 
void Item_func_make_set::split_sum_func(Session *session_arg, Item **ref_pointer_array,
38
 
                                        List<Item> &fields)
39
 
{
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);
42
 
}
43
 
 
44
 
 
45
 
void Item_func_make_set::fix_length_and_dec()
46
 
{
47
 
  max_length=arg_count-1;
48
 
 
49
 
  if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
50
 
    return;
51
 
 
52
 
  for (uint32_t i=0 ; i < arg_count ; i++)
53
 
    max_length+=args[i]->max_length;
54
 
 
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;
59
 
}
60
 
 
61
 
String *Item_func_make_set::val_str(String *str)
62
 
{
63
 
  assert(fixed == 1);
64
 
  uint64_t bits;
65
 
  bool first_found=0;
66
 
  Item **ptr=args;
67
 
  String *result=&my_empty_string;
68
 
 
69
 
  bits=item->val_int();
70
 
  if ((null_value=item->null_value))
71
 
    return NULL;
72
 
 
73
 
  if (arg_count < 64)
74
 
    bits &= ((uint64_t) 1 << arg_count)-1;
75
 
 
76
 
  for (; bits; bits >>= 1, ptr++)
77
 
  {
78
 
    if (bits & 1)
79
 
    {
80
 
      String *res= (*ptr)->val_str(str);
81
 
      if (res)                                  // Skip nulls
82
 
      {
83
 
        if (!first_found)
84
 
        {                                       // First argument
85
 
          first_found=1;
86
 
          if (res != str)
87
 
            result=res;                         // Use original string
88
 
          else
89
 
          {
90
 
            if (tmp_str.copy(*res))             // Don't use 'str'
91
 
              return &my_empty_string;
92
 
            result= &tmp_str;
93
 
          }
94
 
        }
95
 
        else
96
 
        {
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;
102
 
            result= &tmp_str;
103
 
          }
104
 
          if (tmp_str.append(STRING_WITH_LEN(","), &my_charset_bin) || tmp_str.append(*res))
105
 
            return &my_empty_string;
106
 
        }
107
 
      }
108
 
    }
109
 
  }
110
 
  return result;
111
 
}
112
 
 
113
 
 
114
 
Item *Item_func_make_set::transform(Item_transformer transformer, unsigned char *arg)
115
 
{
116
 
  Item *new_item= item->transform(transformer, arg);
117
 
  if (!new_item)
118
 
    return 0;
119
 
 
120
 
  /*
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.
125
 
  */
126
 
  if (item != new_item)
127
 
    session.change_item_tree(&item, new_item);
128
 
 
129
 
  return Item_str_func::transform(transformer, arg);
130
 
}
131
 
 
132
 
 
133
 
void Item_func_make_set::print(String *str, enum_query_type query_type)
134
 
{
135
 
  str->append(STRING_WITH_LEN("make_set("));
136
 
  item->print(str, query_type);
137
 
  if (arg_count)
138
 
  {
139
 
    str->append(',');
140
 
    print_args(str, 0, query_type);
141
 
  }
142
 
  str->append(')');
143
 
}
144
 
 
145
 
} /* namespace drizzled */