~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-02-11 22:43:58 UTC
  • Revision ID: brian@gaz-20100211224358-y0gdvnat2ahg4c1e
Disabling support for memcached plugins until we can test for version of
memcached.

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