Drizzled Public API Documentation

elt.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 "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 
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 
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 
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 */
virtual int64_t val_int()=0
bool fixed
Definition: item.h:120
int64_t val_int()
Definition: elt.cc:56
double val_real()
Definition: elt.cc:44
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
String * val_str(String *str)
Definition: elt.cc:70