~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_buff.cc

  • Committer: Monty Taylor
  • Date: 2008-07-09 16:42:25 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 112.
  • Revision ID: monty@inaugust.com-20080709164225-2r6n4j98nhxh031l
Moved test to tests... 

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  Buffers to save and compare item values
22
22
*/
23
23
 
24
 
#include <drizzled/server_includes.h>
 
24
#include "mysql_priv.h"
25
25
 
26
26
/**
27
27
  Create right type of Cached_item for an item.
28
28
*/
29
29
 
30
 
Cached_item *new_Cached_item(Session *session, Item *item, bool use_result_field)
 
30
Cached_item *new_Cached_item(THD *thd, Item *item, bool use_result_field)
31
31
{
32
32
  if (item->real_item()->type() == Item::FIELD_ITEM &&
33
33
      !(((Item_field *) (item->real_item()))->field->flags & BLOB_FLAG))
39
39
  }
40
40
  switch (item->result_type()) {
41
41
  case STRING_RESULT:
42
 
    return new Cached_item_str(session, (Item_field *) item);
 
42
    return new Cached_item_str(thd, (Item_field *) item);
43
43
  case INT_RESULT:
44
44
    return new Cached_item_int((Item_field *) item);
45
45
  case REAL_RESULT:
48
48
    return new Cached_item_decimal(item);
49
49
  case ROW_RESULT:
50
50
  default:
51
 
    assert(0);
 
51
    DBUG_ASSERT(0);
52
52
    return 0;
53
53
  }
54
54
}
62
62
    Return true if values have changed
63
63
*/
64
64
 
65
 
Cached_item_str::Cached_item_str(Session *session, Item *arg)
66
 
  :item(arg), value(cmin(arg->max_length, (uint32_t)session->variables.max_sort_length))
 
65
Cached_item_str::Cached_item_str(THD *thd, Item *arg)
 
66
  :item(arg), value(min(arg->max_length, thd->variables.max_sort_length))
67
67
{}
68
68
 
69
69
bool Cached_item_str::cmp(void)
71
71
  String *res;
72
72
  bool tmp;
73
73
 
 
74
  DBUG_ENTER("Cached_item_str::cmp");
74
75
  if ((res=item->val_str(&tmp_value)))
75
 
    res->length(cmin(res->length(), value.alloced_length()));
76
 
 
 
76
    res->length(min(res->length(), value.alloced_length()));
 
77
  DBUG_PRINT("info", ("old: %s, new: %s",
 
78
                      value.c_ptr_safe(), res ? res->c_ptr_safe() : ""));
77
79
  if (null_value != item->null_value)
78
80
  {
79
81
    if ((null_value= item->null_value))
80
 
      return(true);                     // New value was null
81
 
    tmp=true;
 
82
      DBUG_RETURN(TRUE);                        // New value was null
 
83
    tmp=TRUE;
82
84
  }
83
85
  else if (null_value)
84
 
    return(0);                          // new and old value was null
 
86
    DBUG_RETURN(0);                             // new and old value was null
85
87
  else
86
88
    tmp= sortcmp(&value,res,item->collation.collation) != 0;
87
89
  if (tmp)
88
90
    value.copy(*res);                           // Remember for next cmp
89
 
  return(tmp);
 
91
  DBUG_RETURN(tmp);
90
92
}
91
93
 
92
94
Cached_item_str::~Cached_item_str()
96
98
 
97
99
bool Cached_item_real::cmp(void)
98
100
{
 
101
  DBUG_ENTER("Cached_item_real::cmp");
99
102
  double nr= item->val_real();
 
103
  DBUG_PRINT("info", ("old: %f, new: %f", value, nr));
100
104
  if (null_value != item->null_value || nr != value)
101
105
  {
102
106
    null_value= item->null_value;
103
107
    value=nr;
104
 
    return(true);
 
108
    DBUG_RETURN(TRUE);
105
109
  }
106
 
  return(false);
 
110
  DBUG_RETURN(FALSE);
107
111
}
108
112
 
109
113
bool Cached_item_int::cmp(void)
110
114
{
111
 
  int64_t nr=item->val_int();
 
115
  DBUG_ENTER("Cached_item_int::cmp");
 
116
  longlong nr=item->val_int();
 
117
  DBUG_PRINT("info", ("old: %Ld, new: %Ld", value, nr));
112
118
  if (null_value != item->null_value || nr != value)
113
119
  {
114
120
    null_value= item->null_value;
115
121
    value=nr;
116
 
    return(true);
 
122
    DBUG_RETURN(TRUE);
117
123
  }
118
 
  return(false);
 
124
  DBUG_RETURN(FALSE);
119
125
}
120
126
 
121
127
 
122
128
bool Cached_item_field::cmp(void)
123
129
{
 
130
  DBUG_ENTER("Cached_item_field::cmp");
124
131
  bool tmp= field->cmp(buff) != 0;              // This is not a blob!
 
132
  DBUG_EXECUTE("info", dbug_print(););
125
133
  if (tmp)
126
134
    field->get_image(buff,length,field->charset());
127
135
  if (null_value != field->is_null())
128
136
  {
129
137
    null_value= !null_value;
130
 
    tmp=true;
 
138
    tmp=TRUE;
131
139
  }
132
 
  return(tmp);
 
140
  DBUG_RETURN(tmp);
133
141
}
134
142
 
135
143
 
152
160
    if (!null_value)
153
161
    {
154
162
      my_decimal2decimal(ptmp, &value);
155
 
      return true;
 
163
      return TRUE;
156
164
    }
157
 
    return false;
 
165
    return FALSE;
158
166
  }
159
 
  return false;
 
167
  return FALSE;
160
168
}
161
169
 
162
170