~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/user_var_entry.cc

  • Committer: Brian Aker
  • Date: 2009-07-10 01:49:29 UTC
  • mto: (1090.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1091.
  • Revision ID: brian@gaz-20090710014929-v8pmvf7woqkld9iv
Cleanup of user_var

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
  }
138
138
  return(val);
139
139
}
 
140
 
 
141
/**
 
142
  Set value to user variable.
 
143
 
 
144
  @param entry          pointer to structure representing variable
 
145
  @param set_null       should we set NULL value ?
 
146
  @param ptr            pointer to buffer with new value
 
147
  @param length         length of new value
 
148
  @param type           type of new value
 
149
  @param cs             charset info for new value
 
150
  @param dv             derivation for new value
 
151
  @param unsigned_arg   indiates if a value of type INT_RESULT is unsigned
 
152
 
 
153
  @note Sets error and fatal error if allocation fails.
 
154
 
 
155
  @retval
 
156
    false   success
 
157
  @retval
 
158
    true    failure
 
159
*/
 
160
 
 
161
#define extra_size sizeof(double)
 
162
 
 
163
bool user_var_entry::update_hash(bool set_null, void *ptr, uint32_t arg_length,
 
164
                                 Item_result arg_type, const CHARSET_INFO * const cs, Derivation dv,
 
165
                                 bool unsigned_arg)
 
166
{
 
167
  if (set_null)
 
168
  {
 
169
    if (value)
 
170
    {
 
171
      assert(length && size);
 
172
      free(value);
 
173
      value= NULL;
 
174
      length= 0;
 
175
      size= 0;
 
176
    }
 
177
  }
 
178
  else
 
179
  {
 
180
    size_t needed_size= arg_length + ((arg_type == STRING_RESULT) ? 1 : 0);
 
181
 
 
182
    if (needed_size > size)
 
183
    {
 
184
      char *new_ptr;
 
185
 
 
186
      new_ptr= (char *)realloc(value, needed_size);
 
187
 
 
188
      if (new_ptr == NULL)
 
189
        return true;
 
190
 
 
191
      value= new_ptr;
 
192
      size= needed_size;
 
193
    }
 
194
 
 
195
    if (arg_type == STRING_RESULT)
 
196
      value[arg_length]= 0;                     // Store end \0
 
197
 
 
198
    memcpy(value, ptr, arg_length);
 
199
    if (arg_type == DECIMAL_RESULT)
 
200
      ((my_decimal*)value)->fix_buffer_pointer();
 
201
    length= arg_length;
 
202
    collation.set(cs, dv);
 
203
    unsigned_flag= unsigned_arg;
 
204
  }
 
205
  type= arg_type;
 
206
 
 
207
  return false;
 
208
}