Drizzled Public API Documentation

export_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/export_set.h>
23 
24 #include <algorithm>
25 
26 using namespace std;
27 
28 namespace drizzled {
29 
30 String* Item_func_export_set::val_str(String* str)
31 {
32  assert(fixed == 1);
33  uint64_t the_set = (uint64_t) args[0]->val_int();
34  String yes_buf, *yes;
35  yes = args[1]->val_str(&yes_buf);
36  String no_buf, *no;
37  no = args[2]->val_str(&no_buf);
38  String *sep = NULL, sep_buf ;
39 
40  uint32_t num_set_values = 64;
41  uint64_t mask = 0x1;
42  str->length(0);
43  str->set_charset(collation.collation);
44 
45  /* Check if some argument is a NULL value */
46  if (args[0]->null_value || args[1]->null_value || args[2]->null_value)
47  {
48  null_value=1;
49  return 0;
50  }
51  /*
52  Arg count can only be 3, 4 or 5 here. This is guaranteed from the
53  grammar for EXPORT_SET()
54  */
55  switch(arg_count) {
56  case 5:
57  num_set_values = (uint) args[4]->val_int();
58  if (num_set_values > 64)
59  num_set_values=64;
60  if (args[4]->null_value)
61  {
62  null_value=1;
63  return 0;
64  }
65  /* Fall through */
66  case 4:
67  if (!(sep = args[3]->val_str(&sep_buf))) // Only true if NULL
68  {
69  null_value=1;
70  return 0;
71  }
72  break;
73  case 3:
74  {
75  sep_buf.copy(STRING_WITH_LEN(","), collation.collation);
76  sep = &sep_buf;
77  }
78  break;
79  default:
80  assert(0); // cannot happen
81  }
82  null_value=0;
83 
84  for (uint32_t i = 0; i < num_set_values; i++, mask = (mask << 1))
85  {
86  if (the_set & mask)
87  str->append(*yes);
88  else
89  str->append(*no);
90  if (i != num_set_values - 1)
91  str->append(*sep);
92  }
93  return str;
94 }
95 
96 void Item_func_export_set::fix_length_and_dec()
97 {
98  uint32_t length= max(args[1]->max_length,args[2]->max_length);
99  uint32_t sep_length= (arg_count > 3 ? args[3]->max_length : 1);
100  max_length= length*64+sep_length*63;
101 
102  if (agg_arg_charsets(collation, args+1, min(4U,arg_count)-1,
103  MY_COLL_ALLOW_CONV, 1))
104  return;
105 }
106 
107 } /* namespace drizzled */
TODO: Rename this file - func.h is stupid.