~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/debian-changes-2010.12.06-0ubuntu4/drizzled/cached_item.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2011-01-04 09:31:58 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110104093158-smhgvkfdi2y9au3i
Tags: 2011.01.07-0ubuntu1
New upstream release.

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
 
/**
21
 
  @file
22
 
 
23
 
  @brief
24
 
  Buffers to save and compare item values
25
 
*/
26
 
 
27
 
#include "config.h"
28
 
#include <drizzled/cached_item.h>
29
 
#include <drizzled/sql_string.h>
30
 
#include <drizzled/session.h>
31
 
#include <algorithm>
32
 
 
33
 
using namespace std;
34
 
 
35
 
namespace drizzled
36
 
{
37
 
 
38
 
/**
39
 
  Create right type of Cached_item for an item.
40
 
*/
41
 
 
42
 
Cached_item *new_Cached_item(Session *session, Item *item)
43
 
{
44
 
  if (item->real_item()->type() == Item::FIELD_ITEM &&
45
 
      !(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
46
 
  {
47
 
    Item_field *real_item= (Item_field *) item->real_item();
48
 
    Field *cached_field= real_item->field;
49
 
    return new Cached_item_field(cached_field);
50
 
  }
51
 
 
52
 
  switch (item->result_type()) {
53
 
  case STRING_RESULT:
54
 
    return new Cached_item_str(session, (Item_field *) item);
55
 
  case INT_RESULT:
56
 
    return new Cached_item_int((Item_field *) item);
57
 
  case REAL_RESULT:
58
 
    return new Cached_item_real(item);
59
 
  case DECIMAL_RESULT:
60
 
    return new Cached_item_decimal(item);
61
 
  case ROW_RESULT:
62
 
    assert(0);
63
 
    return 0;
64
 
  }
65
 
 
66
 
  abort();
67
 
}
68
 
 
69
 
Cached_item::~Cached_item() {}
70
 
 
71
 
/**
72
 
  Compare with old value and replace value with new value.
73
 
 
74
 
  @return
75
 
    Return true if values have changed
76
 
*/
77
 
 
78
 
Cached_item_str::Cached_item_str(Session *session, Item *arg)
79
 
  :item(arg), value(min(arg->max_length,
80
 
                        (uint32_t)session->variables.max_sort_length))
81
 
{}
82
 
 
83
 
bool Cached_item_str::cmp(void)
84
 
{
85
 
  String *res;
86
 
  bool tmp;
87
 
 
88
 
  if ((res=item->val_str(&tmp_value)))
89
 
    res->length(min(res->length(), value.alloced_length()));
90
 
 
91
 
  if (null_value != item->null_value)
92
 
  {
93
 
    if ((null_value= item->null_value))
94
 
      // New value was null
95
 
      return(true);
96
 
    tmp=true;
97
 
  }
98
 
  else if (null_value)
99
 
    // new and old value was null
100
 
    return(0);
101
 
  else
102
 
    tmp= sortcmp(&value,res,item->collation.collation) != 0;
103
 
  if (tmp)
104
 
    // Remember for next cmp
105
 
    value.copy(*res);
106
 
  return(tmp);
107
 
}
108
 
 
109
 
Cached_item_str::~Cached_item_str()
110
 
{
111
 
  // Safety
112
 
  item=0;
113
 
}
114
 
 
115
 
bool Cached_item_real::cmp(void)
116
 
{
117
 
  double nr= item->val_real();
118
 
  if (null_value != item->null_value || nr != value)
119
 
  {
120
 
    null_value= item->null_value;
121
 
    value=nr;
122
 
    return(true);
123
 
  }
124
 
  return(false);
125
 
}
126
 
 
127
 
bool Cached_item_int::cmp(void)
128
 
{
129
 
  int64_t nr=item->val_int();
130
 
  if (null_value != item->null_value || nr != value)
131
 
  {
132
 
    null_value= item->null_value;
133
 
    value=nr;
134
 
    return(true);
135
 
  }
136
 
  return(false);
137
 
}
138
 
 
139
 
 
140
 
Cached_item_field::Cached_item_field(Field *arg_field) 
141
 
  : 
142
 
    field(arg_field)
143
 
{
144
 
  /* TODO: take the memory allocation below out of the constructor. */
145
 
  buff= (unsigned char*) memory::sql_calloc(length= field->pack_length());
146
 
}
147
 
 
148
 
bool Cached_item_field::cmp(void)
149
 
{
150
 
  // This is not a blob!
151
 
  bool tmp= field->cmp_internal(buff) != 0;
152
 
 
153
 
  if (tmp)
154
 
    field->get_image(buff,length,field->charset());
155
 
  if (null_value != field->is_null())
156
 
  {
157
 
    null_value= !null_value;
158
 
    tmp=true;
159
 
  }
160
 
  return(tmp);
161
 
}
162
 
 
163
 
 
164
 
Cached_item_decimal::Cached_item_decimal(Item *it)
165
 
  :item(it)
166
 
{
167
 
  my_decimal_set_zero(&value);
168
 
}
169
 
 
170
 
 
171
 
bool Cached_item_decimal::cmp()
172
 
{
173
 
  my_decimal tmp;
174
 
  my_decimal *ptmp= item->val_decimal(&tmp);
175
 
  if (null_value != item->null_value ||
176
 
      (!item->null_value && my_decimal_cmp(&value, ptmp)))
177
 
  {
178
 
    null_value= item->null_value;
179
 
    /* Save only not null values */
180
 
    if (!null_value)
181
 
    {
182
 
      my_decimal2decimal(ptmp, &value);
183
 
      return true;
184
 
    }
185
 
    return false;
186
 
  }
187
 
  return false;
188
 
}
189
 
 
190
 
} /* namespace drizzled */