~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/field.cc

  • Committer: Lee
  • Date: 2008-10-28 21:50:18 UTC
  • mto: (520.4.23 devel) (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 567.
  • Revision ID: lbieber@lbieber-desktop-20081028215018-w9b4eln4s74s25dz
more changes to move functions from item_func.cc/h to the functions directory

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
 
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 <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include <drizzled/functions/field.h>
 
23
 
 
24
// Conversion functions
 
25
 
 
26
int64_t Item_func_field::val_int()
 
27
{
 
28
  assert(fixed == 1);
 
29
 
 
30
  if (cmp_type == STRING_RESULT)
 
31
  {
 
32
    String *field;
 
33
    if (!(field= args[0]->val_str(&value)))
 
34
      return 0;
 
35
    for (uint32_t i=1 ; i < arg_count ; i++)
 
36
    {
 
37
      String *tmp_value=args[i]->val_str(&tmp);
 
38
      if (tmp_value && !sortcmp(field,tmp_value,cmp_collation.collation))
 
39
        return (int64_t) (i);
 
40
    }
 
41
  }
 
42
  else if (cmp_type == INT_RESULT)
 
43
  {
 
44
    int64_t val= args[0]->val_int();
 
45
    if (args[0]->null_value)
 
46
      return 0;
 
47
    for (uint32_t i=1; i < arg_count ; i++)
 
48
    {
 
49
      if (val == args[i]->val_int() && !args[i]->null_value)
 
50
        return (int64_t) (i);
 
51
    }
 
52
  }
 
53
  else if (cmp_type == DECIMAL_RESULT)
 
54
  {
 
55
    my_decimal dec_arg_buf, *dec_arg,
 
56
               dec_buf, *dec= args[0]->val_decimal(&dec_buf);
 
57
    if (args[0]->null_value)
 
58
      return 0;
 
59
    for (uint32_t i=1; i < arg_count; i++)
 
60
    {
 
61
      dec_arg= args[i]->val_decimal(&dec_arg_buf);
 
62
      if (!args[i]->null_value && !my_decimal_cmp(dec_arg, dec))
 
63
        return (int64_t) (i);
 
64
    }
 
65
  }
 
66
  else
 
67
  {
 
68
    double val= args[0]->val_real();
 
69
    if (args[0]->null_value)
 
70
      return 0;
 
71
    for (uint32_t i=1; i < arg_count ; i++)
 
72
    {
 
73
      if (val == args[i]->val_real() && !args[i]->null_value)
 
74
        return (int64_t) (i);
 
75
    }
 
76
  }
 
77
  return 0;
 
78
}
 
79
 
 
80
void Item_func_field::fix_length_and_dec()
 
81
{
 
82
  maybe_null=0; max_length=3;
 
83
  cmp_type= args[0]->result_type();
 
84
  for (uint32_t i=1; i < arg_count ; i++)
 
85
    cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
 
86
  if (cmp_type == STRING_RESULT)
 
87
    agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1);
 
88
}