~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cached_item.cc

Merged in latest plugin-slot-reorg.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
 
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
 */
16
19
 
17
20
/**
18
21
  @file
22
25
*/
23
26
 
24
27
#include <drizzled/server_includes.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;
25
34
 
26
35
/**
27
36
  Create right type of Cached_item for an item.
28
37
*/
29
38
 
30
 
Cached_item *new_Cached_item(THD *thd, Item *item, bool use_result_field)
 
39
Cached_item *new_Cached_item(Session *session, Item *item,
 
40
                             bool use_result_field)
31
41
{
32
42
  if (item->real_item()->type() == Item::FIELD_ITEM &&
33
43
      !(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
39
49
  }
40
50
  switch (item->result_type()) {
41
51
  case STRING_RESULT:
42
 
    return new Cached_item_str(thd, (Item_field *) item);
 
52
    return new Cached_item_str(session, (Item_field *) item);
43
53
  case INT_RESULT:
44
54
    return new Cached_item_int((Item_field *) item);
45
55
  case REAL_RESULT:
62
72
    Return true if values have changed
63
73
*/
64
74
 
65
 
Cached_item_str::Cached_item_str(THD *thd, Item *arg)
66
 
  :item(arg), value(cmin(arg->max_length, (uint32_t)thd->variables.max_sort_length))
 
75
Cached_item_str::Cached_item_str(Session *session, Item *arg)
 
76
  :item(arg), value(min(arg->max_length,
 
77
                        (uint32_t)session->variables.max_sort_length))
67
78
{}
68
79
 
69
80
bool Cached_item_str::cmp(void)
72
83
  bool tmp;
73
84
 
74
85
  if ((res=item->val_str(&tmp_value)))
75
 
    res->length(cmin(res->length(), value.alloced_length()));
 
86
    res->length(min(res->length(), value.alloced_length()));
76
87
 
77
88
  if (null_value != item->null_value)
78
89
  {
79
90
    if ((null_value= item->null_value))
80
 
      return(true);                     // New value was null
 
91
      // New value was null
 
92
      return(true);
81
93
    tmp=true;
82
94
  }
83
95
  else if (null_value)
84
 
    return(0);                          // new and old value was null
 
96
    // new and old value was null
 
97
    return(0);
85
98
  else
86
99
    tmp= sortcmp(&value,res,item->collation.collation) != 0;
87
100
  if (tmp)
88
 
    value.copy(*res);                           // Remember for next cmp
 
101
    // Remember for next cmp
 
102
    value.copy(*res);
89
103
  return(tmp);
90
104
}
91
105
 
92
106
Cached_item_str::~Cached_item_str()
93
107
{
94
 
  item=0;                                       // Safety
 
108
  // Safety
 
109
  item=0;
95
110
}
96
111
 
97
112
bool Cached_item_real::cmp(void)
121
136
 
122
137
bool Cached_item_field::cmp(void)
123
138
{
124
 
  bool tmp= field->cmp(buff) != 0;              // This is not a blob!
 
139
  // This is not a blob!
 
140
  bool tmp= field->cmp(buff) != 0;
 
141
 
125
142
  if (tmp)
126
143
    field->get_image(buff,length,field->charset());
127
144
  if (null_value != field->is_null())
160
177
}
161
178
 
162
179
 
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