~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cached_item.cc

Reverted 1103

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
24
24
  Buffers to save and compare item values
25
25
*/
26
26
 
27
 
#include "config.h"
 
27
#include <drizzled/server_includes.h>
28
28
#include <drizzled/cached_item.h>
29
29
#include <drizzled/sql_string.h>
30
30
#include <drizzled/session.h>
32
32
 
33
33
using namespace std;
34
34
 
35
 
namespace drizzled
36
 
{
37
 
 
38
35
/**
39
36
  Create right type of Cached_item for an item.
40
37
*/
41
38
 
42
 
Cached_item *new_Cached_item(Session *session, Item *item)
 
39
Cached_item *new_Cached_item(Session *session, Item *item,
 
40
                             bool use_result_field)
43
41
{
44
42
  if (item->real_item()->type() == Item::FIELD_ITEM &&
45
43
      !(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
46
44
  {
47
45
    Item_field *real_item= (Item_field *) item->real_item();
48
 
    Field *cached_field= real_item->field;
 
46
    Field *cached_field= use_result_field ? real_item->result_field :
 
47
                                            real_item->field;
49
48
    return new Cached_item_field(cached_field);
50
49
  }
51
 
 
52
50
  switch (item->result_type()) {
53
51
  case STRING_RESULT:
54
52
    return new Cached_item_str(session, (Item_field *) item);
59
57
  case DECIMAL_RESULT:
60
58
    return new Cached_item_decimal(item);
61
59
  case ROW_RESULT:
 
60
  default:
62
61
    assert(0);
63
62
    return 0;
64
63
  }
65
 
 
66
 
  abort();
67
64
}
68
65
 
69
66
Cached_item::~Cached_item() {}
137
134
}
138
135
 
139
136
 
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
137
bool Cached_item_field::cmp(void)
149
138
{
150
139
  // This is not a blob!
151
 
  bool tmp= field->cmp_internal(buff) != 0;
 
140
  bool tmp= field->cmp(buff) != 0;
152
141
 
153
142
  if (tmp)
154
143
    field->get_image(buff,length,field->charset());
164
153
Cached_item_decimal::Cached_item_decimal(Item *it)
165
154
  :item(it)
166
155
{
167
 
  value.set_zero();
 
156
  my_decimal_set_zero(&value);
168
157
}
169
158
 
170
159
 
171
160
bool Cached_item_decimal::cmp()
172
161
{
173
 
  type::Decimal tmp;
174
 
  type::Decimal *ptmp= item->val_decimal(&tmp);
 
162
  my_decimal tmp;
 
163
  my_decimal *ptmp= item->val_decimal(&tmp);
175
164
  if (null_value != item->null_value ||
176
 
      (!item->null_value && class_decimal_cmp(&value, ptmp)))
 
165
      (!item->null_value && my_decimal_cmp(&value, ptmp)))
177
166
  {
178
167
    null_value= item->null_value;
179
168
    /* Save only not null values */
180
169
    if (!null_value)
181
170
    {
182
 
      class_decimal2decimal(ptmp, &value);
 
171
      my_decimal2decimal(ptmp, &value);
183
172
      return true;
184
173
    }
185
174
    return false;
187
176
  return false;
188
177
}
189
178
 
190
 
} /* namespace drizzled */
 
179