1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#include <drizzled/server_includes.h>
22
#include <drizzled/function/update_hash.h>
23
#include <drizzled/session.h>
26
Set value to user variable.
28
@param entry pointer to structure representing variable
29
@param set_null should we set NULL value ?
30
@param ptr pointer to buffer with new value
31
@param length length of new value
32
@param type type of new value
33
@param cs charset info for new value
34
@param dv derivation for new value
35
@param unsigned_arg indiates if a value of type INT_RESULT is unsigned
37
@note Sets error and fatal error if allocation fails.
45
#define extra_size sizeof(double)
48
update_hash(user_var_entry *entry, bool set_null, void *ptr, uint32_t length,
49
Item_result type, const CHARSET_INFO * const cs, Derivation dv,
54
char *pos= (char*) entry+ ALIGN_SIZE(sizeof(user_var_entry));
55
if (entry->value && entry->value != pos)
62
if (type == STRING_RESULT)
63
length++; // Store strings with end \0
64
if (length <= extra_size)
66
/* Save value in value struct */
67
char *pos= (char*) entry+ ALIGN_SIZE(sizeof(user_var_entry));
68
if (entry->value != pos)
77
/* Allocate variable */
78
if (entry->length != length)
80
char *pos= (char*) entry+ ALIGN_SIZE(sizeof(user_var_entry));
81
if (entry->value == pos)
83
void *tmpptr= realloc(entry->value, length);
86
entry->value= (char *)tmpptr;
89
if (type == STRING_RESULT)
91
length--; // Fix length change above
92
entry->value[length]= 0; // Store end \0
94
memcpy(entry->value,ptr,length);
95
if (type == DECIMAL_RESULT)
96
((my_decimal*)entry->value)->fix_buffer_pointer();
97
entry->length= length;
98
entry->collation.set(cs, dv);
99
entry->unsigned_flag= unsigned_arg;