~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cache_str.cc

  • Committer: Brian Aker
  • Date: 2009-10-01 22:56:26 UTC
  • mto: (1154.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1155.
  • Revision ID: brian@gaz-20091001225626-sb1pdykpxlnkheaj
Remove Factory/make scheduler work like everything else.

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