~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/get_variable.cc

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 */
19
 
 
20
 
#include <drizzled/server_includes.h>
21
 
#include CSTDINT_H
22
 
#include <drizzled/functions/get_variable.h>
23
 
 
24
 
#define extra_size sizeof(double)
25
 
 
26
 
user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
27
 
                                    bool create_if_not_exists)
28
 
{
29
 
  user_var_entry *entry;
30
 
 
31
 
  if (!(entry = (user_var_entry*) hash_search(hash, (unsigned char*) name.str,
32
 
                                              name.length)) &&
33
 
      create_if_not_exists)
34
 
  {
35
 
    uint32_t size=ALIGN_SIZE(sizeof(user_var_entry))+name.length+1+extra_size;
36
 
    if (!hash_inited(hash))
37
 
      return 0;
38
 
    if (!(entry = (user_var_entry*) my_malloc(size,MYF(MY_WME | ME_FATALERROR))))
39
 
      return 0;
40
 
    entry->name.str=(char*) entry+ ALIGN_SIZE(sizeof(user_var_entry))+
41
 
      extra_size;
42
 
    entry->name.length=name.length;
43
 
    entry->value=0;
44
 
    entry->length=0;
45
 
    entry->update_query_id=0;
46
 
    entry->collation.set(NULL, DERIVATION_IMPLICIT, 0);
47
 
    entry->unsigned_flag= 0;
48
 
    /*
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).
57
 
    */
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))
62
 
    {
63
 
      free((char*) entry);
64
 
      return 0;
65
 
    }
66
 
  }
67
 
  return entry;
68
 
}