~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cache_str.cc

  • Committer: Moriyoshi Koizumi
  • Date: 2008-11-15 18:36:31 UTC
  • mto: (584.1.5 devel)
  • mto: This revision was merged to the branch mainline in revision 588.
  • Revision ID: mozo@mozo.jp-20081115183631-81d0clowyot42mk7
Incorporating changes proposed by mtaylor.

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, 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/item/cache_str.h>
23
 
#include <drizzled/field.h>
24
 
 
25
 
namespace drizzled
26
 
{
27
 
 
28
 
Item_cache_str::Item_cache_str(const Item *item) :
29
 
  Item_cache(), value(0),
30
 
  is_varbinary(item->type() == FIELD_ITEM &&
31
 
               ((const Item_field *) item)->field->type() ==
32
 
               DRIZZLE_TYPE_VARCHAR &&
33
 
               !((const Item_field *) item)->field->has_charset())
34
 
{}
35
 
 
36
 
void Item_cache_str::store(Item *item)
37
 
{
38
 
  value_buff.set(buffer, sizeof(buffer), item->collation.collation);
39
 
  value= item->str_result(&value_buff);
40
 
  if ((null_value= item->null_value))
41
 
    value= 0;
42
 
  else if (value != &value_buff)
43
 
  {
44
 
    /*
45
 
      We copy string value to avoid changing value if 'item' is table field
46
 
      in queries like following (where t1.c is varchar):
47
 
      select a,
48
 
             (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),
49
 
             (select c from t1 where a=t2.a)
50
 
        from t2;
51
 
    */
52
 
    value_buff.copy(*value);
53
 
    value= &value_buff;
54
 
  }
55
 
}
56
 
 
57
 
double Item_cache_str::val_real()
58
 
{
59
 
  assert(fixed == 1);
60
 
  int err_not_used;
61
 
  char *end_not_used;
62
 
  if (value)
63
 
    return my_strntod(value->charset(), (char*) value->ptr(),
64
 
                      value->length(), &end_not_used, &err_not_used);
65
 
  return (double) 0;
66
 
}
67
 
 
68
 
 
69
 
int64_t Item_cache_str::val_int()
70
 
{
71
 
  assert(fixed == 1);
72
 
  int err;
73
 
  if (value)
74
 
    return my_strntoll(value->charset(), value->ptr(),
75
 
                       value->length(), 10, (char**) 0, &err);
76
 
  else
77
 
    return (int64_t)0;
78
 
}
79
 
 
80
 
type::Decimal *Item_cache_str::val_decimal(type::Decimal *decimal_val)
81
 
{
82
 
  assert(fixed == 1);
83
 
  if (value)
84
 
    decimal_val->store(E_DEC_FATAL_ERROR, value);
85
 
  else
86
 
    decimal_val= 0;
87
 
  return decimal_val;
88
 
}
89
 
 
90
 
int Item_cache_str::save_in_field(Field *field, bool no_conversions)
91
 
{
92
 
  int res= Item_cache::save_in_field(field, no_conversions);
93
 
 
94
 
  return res;
95
 
}
96
 
 
97
 
} /* namespace drizzled */