Drizzled Public API Documentation

field.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/field.h>
23 #include <drizzled/item/cmpfunc.h>
24 
25 // Conversion functions
26 
27 namespace drizzled
28 {
29 
31 {
32  assert(fixed == 1);
33 
34  if (cmp_type == STRING_RESULT)
35  {
36  String *field;
37  if (!(field= args[0]->val_str(&value)))
38  return 0;
39  for (uint32_t i=1 ; i < arg_count ; i++)
40  {
41  String *tmp_value=args[i]->val_str(&tmp);
42  if (tmp_value && !sortcmp(field,tmp_value,cmp_collation.collation))
43  return (int64_t) (i);
44  }
45  }
46  else if (cmp_type == INT_RESULT)
47  {
48  int64_t val= args[0]->val_int();
49  if (args[0]->null_value)
50  return 0;
51  for (uint32_t i=1; i < arg_count ; i++)
52  {
53  if (val == args[i]->val_int() && !args[i]->null_value)
54  return (int64_t) (i);
55  }
56  }
57  else if (cmp_type == DECIMAL_RESULT)
58  {
59  type::Decimal dec_arg_buf, *dec_arg,
60  dec_buf, *dec= args[0]->val_decimal(&dec_buf);
61  if (args[0]->null_value)
62  return 0;
63  for (uint32_t i=1; i < arg_count; i++)
64  {
65  dec_arg= args[i]->val_decimal(&dec_arg_buf);
66  if (!args[i]->null_value && !class_decimal_cmp(dec_arg, dec))
67  return (int64_t) (i);
68  }
69  }
70  else
71  {
72  double val= args[0]->val_real();
73  if (args[0]->null_value)
74  return 0;
75  for (uint32_t i=1; i < arg_count ; i++)
76  {
77  if (val == args[i]->val_real() && !args[i]->null_value)
78  return (int64_t) (i);
79  }
80  }
81  return 0;
82 }
83 
84 void Item_func_field::fix_length_and_dec()
85 {
86  maybe_null=0; max_length=3;
87  cmp_type= args[0]->result_type();
88  for (uint32_t i=1; i < arg_count ; i++)
89  cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
90  if (cmp_type == STRING_RESULT)
91  agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1);
92 }
93 
94 } /* namespace drizzled */
virtual int64_t val_int()=0
bool fixed
Definition: item.h:120
TODO: Rename this file - func.h is stupid.
String * val_str(String *str)
Definition: int.cc:41
int class_decimal_cmp(const type::Decimal *a, const type::Decimal *b)
Definition: decimal.h:425
bool null_value
Definition: item.h:122
bool maybe_null
Definition: item.h:121
virtual double val_real()=0
virtual String * val_str(String *str)=0
virtual type::Decimal * val_decimal(type::Decimal *decimal_buffer)=0
double val_real()
Definition: int.cc:33