~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merge of Jay

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/function/str/elt.h>
 
23
 
 
24
void Item_func_elt::fix_length_and_dec()
 
25
{
 
26
  max_length=0;
 
27
  decimals=0;
 
28
 
 
29
  if (agg_arg_charsets(collation, args+1, arg_count-1, MY_COLL_ALLOW_CONV, 1))
 
30
    return;
 
31
 
 
32
  for (uint32_t i= 1 ; i < arg_count ; i++)
 
33
  {
 
34
    set_if_bigger(max_length,args[i]->max_length);
 
35
    set_if_bigger(decimals,args[i]->decimals);
 
36
  }
 
37
  maybe_null=1;                                 // NULL if wrong first arg
 
38
}
 
39
 
 
40
 
 
41
double Item_func_elt::val_real()
 
42
{
 
43
  assert(fixed == 1);
 
44
  uint32_t tmp;
 
45
  null_value=1;
 
46
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
 
47
    return 0.0;
 
48
  double result= args[tmp]->val_real();
 
49
  null_value= args[tmp]->null_value;
 
50
  return result;
 
51
}
 
52
 
 
53
int64_t Item_func_elt::val_int()
 
54
{
 
55
  assert(fixed == 1);
 
56
  uint32_t tmp;
 
57
  null_value=1;
 
58
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
 
59
    return 0;
 
60
 
 
61
  int64_t result= args[tmp]->val_int();
 
62
  null_value= args[tmp]->null_value;
 
63
  return result;
 
64
}
 
65
 
 
66
 
 
67
String *Item_func_elt::val_str(String *str)
 
68
{
 
69
  assert(fixed == 1);
 
70
  uint32_t tmp;
 
71
  null_value=1;
 
72
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
 
73
    return NULL;
 
74
 
 
75
  String *result= args[tmp]->val_str(str);
 
76
  if (result)
 
77
    result->set_charset(collation.collation);
 
78
  null_value= args[tmp]->null_value;
 
79
  return result;
 
80
}
 
81
 
 
82