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