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/functions/get_variable.h>
24
#define extra_size sizeof(double)
26
user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
27
bool create_if_not_exists)
29
user_var_entry *entry;
31
if (!(entry = (user_var_entry*) hash_search(hash, (unsigned char*) name.str,
35
uint32_t size=ALIGN_SIZE(sizeof(user_var_entry))+name.length+1+extra_size;
36
if (!hash_inited(hash))
38
if (!(entry = (user_var_entry*) my_malloc(size,MYF(MY_WME | ME_FATALERROR))))
40
entry->name.str=(char*) entry+ ALIGN_SIZE(sizeof(user_var_entry))+
42
entry->name.length=name.length;
45
entry->update_query_id=0;
46
entry->collation.set(NULL, DERIVATION_IMPLICIT, 0);
47
entry->unsigned_flag= 0;
49
If we are here, we were called from a SET or a query which sets a
50
variable. Imagine it is this:
51
INSERT INTO t SELECT @a:=10, @a:=@a+1.
52
Then when we have a Item_func_get_user_var (because of the @a+1) so we
53
think we have to write the value of @a to the binlog. But before that,
54
we have a Item_func_set_user_var to create @a (@a:=10), in this we mark
55
the variable as "already logged" (line below) so that it won't be logged
56
by Item_func_get_user_var (because that's not necessary).
58
entry->used_query_id=current_session->query_id;
59
entry->type=STRING_RESULT;
60
memcpy(entry->name.str, name.str, name.length+1);
61
if (my_hash_insert(hash,(unsigned char*) entry))