~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_buff.cc

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

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
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
19
16
 
20
17
/**
21
18
  @file
24
21
  Buffers to save and compare item values
25
22
*/
26
23
 
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
 
{
 
24
#include <drizzled/server_includes.h>
37
25
 
38
26
/**
39
27
  Create right type of Cached_item for an item.
40
28
*/
41
29
 
42
 
Cached_item *new_Cached_item(Session *session, Item *item)
 
30
Cached_item *new_Cached_item(Session *session, Item *item, bool use_result_field)
43
31
{
44
32
  if (item->real_item()->type() == Item::FIELD_ITEM &&
45
33
      !(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
46
34
  {
47
35
    Item_field *real_item= (Item_field *) item->real_item();
48
 
    Field *cached_field= real_item->field;
 
36
    Field *cached_field= use_result_field ? real_item->result_field :
 
37
                                            real_item->field;
49
38
    return new Cached_item_field(cached_field);
50
39
  }
51
 
 
52
40
  switch (item->result_type()) {
53
41
  case STRING_RESULT:
54
42
    return new Cached_item_str(session, (Item_field *) item);
59
47
  case DECIMAL_RESULT:
60
48
    return new Cached_item_decimal(item);
61
49
  case ROW_RESULT:
 
50
  default:
62
51
    assert(0);
63
52
    return 0;
64
53
  }
65
 
 
66
 
  abort();
67
54
}
68
55
 
69
56
Cached_item::~Cached_item() {}
76
63
*/
77
64
 
78
65
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))
 
66
  :item(arg), value(cmin(arg->max_length, (uint32_t)session->variables.max_sort_length))
81
67
{}
82
68
 
83
69
bool Cached_item_str::cmp(void)
86
72
  bool tmp;
87
73
 
88
74
  if ((res=item->val_str(&tmp_value)))
89
 
    res->length(min(res->length(), value.alloced_length()));
 
75
    res->length(cmin(res->length(), value.alloced_length()));
90
76
 
91
77
  if (null_value != item->null_value)
92
78
  {
93
79
    if ((null_value= item->null_value))
94
 
      // New value was null
95
 
      return(true);
 
80
      return(true);                     // New value was null
96
81
    tmp=true;
97
82
  }
98
83
  else if (null_value)
99
 
    // new and old value was null
100
 
    return(0);
 
84
    return(0);                          // new and old value was null
101
85
  else
102
86
    tmp= sortcmp(&value,res,item->collation.collation) != 0;
103
87
  if (tmp)
104
 
    // Remember for next cmp
105
 
    value.copy(*res);
 
88
    value.copy(*res);                           // Remember for next cmp
106
89
  return(tmp);
107
90
}
108
91
 
109
92
Cached_item_str::~Cached_item_str()
110
93
{
111
 
  // Safety
112
 
  item=0;
 
94
  item=0;                                       // Safety
113
95
}
114
96
 
115
97
bool Cached_item_real::cmp(void)
137
119
}
138
120
 
139
121
 
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
122
bool Cached_item_field::cmp(void)
149
123
{
150
 
  // This is not a blob!
151
 
  bool tmp= field->cmp_internal(buff) != 0;
152
 
 
 
124
  bool tmp= field->cmp(buff) != 0;              // This is not a blob!
153
125
  if (tmp)
154
126
    field->get_image(buff,length,field->charset());
155
127
  if (null_value != field->is_null())
164
136
Cached_item_decimal::Cached_item_decimal(Item *it)
165
137
  :item(it)
166
138
{
167
 
  value.set_zero();
 
139
  my_decimal_set_zero(&value);
168
140
}
169
141
 
170
142
 
171
143
bool Cached_item_decimal::cmp()
172
144
{
173
 
  type::Decimal tmp;
174
 
  type::Decimal *ptmp= item->val_decimal(&tmp);
 
145
  my_decimal tmp;
 
146
  my_decimal *ptmp= item->val_decimal(&tmp);
175
147
  if (null_value != item->null_value ||
176
 
      (!item->null_value && class_decimal_cmp(&value, ptmp)))
 
148
      (!item->null_value && my_decimal_cmp(&value, ptmp)))
177
149
  {
178
150
    null_value= item->null_value;
179
151
    /* Save only not null values */
180
152
    if (!null_value)
181
153
    {
182
 
      class_decimal2decimal(ptmp, &value);
 
154
      my_decimal2decimal(ptmp, &value);
183
155
      return true;
184
156
    }
185
157
    return false;
187
159
  return false;
188
160
}
189
161
 
190
 
} /* namespace drizzled */
 
162
 
 
163
/*****************************************************************************
 
164
** Instansiate templates
 
165
*****************************************************************************/
 
166
 
 
167
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
 
168
template class List<Cached_item>;
 
169
template class List_iterator<Cached_item>;
 
170
#endif