~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/debian-changes-2010.12.06-0ubuntu4/drizzled/function/get_user_var.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2011-01-04 09:31:58 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110104093158-smhgvkfdi2y9au3i
Tags: 2011.01.07-0ubuntu1
New upstream release.

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, Inc.
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 "config.h"
21
 
 
22
 
#include <float.h>
23
 
 
24
 
#include <drizzled/function/get_user_var.h>
25
 
#include <drizzled/item/null.h>
26
 
#include <drizzled/sql_parse.h>
27
 
#include <drizzled/session.h>
28
 
 
29
 
namespace drizzled
30
 
{
31
 
 
32
 
String *Item_func_get_user_var::val_str(String *str)
33
 
{
34
 
  assert(fixed == 1);
35
 
  if (!var_entry)
36
 
    return((String*) 0);                        // No such variable
37
 
  return(var_entry->val_str(&null_value, str, decimals));
38
 
}
39
 
 
40
 
 
41
 
double Item_func_get_user_var::val_real()
42
 
{
43
 
  assert(fixed == 1);
44
 
  if (!var_entry)
45
 
    return 0.0;                                 // No such variable
46
 
  return (var_entry->val_real(&null_value));
47
 
}
48
 
 
49
 
 
50
 
my_decimal *Item_func_get_user_var::val_decimal(my_decimal *dec)
51
 
{
52
 
  assert(fixed == 1);
53
 
  if (!var_entry)
54
 
    return 0;
55
 
  return var_entry->val_decimal(&null_value, dec);
56
 
}
57
 
 
58
 
int64_t Item_func_get_user_var::val_int()
59
 
{
60
 
  assert(fixed == 1);
61
 
  if (!var_entry)
62
 
    return 0L;                          // No such variable
63
 
  return (var_entry->val_int(&null_value));
64
 
}
65
 
 
66
 
void Item_func_get_user_var::fix_length_and_dec()
67
 
{
68
 
  maybe_null=1;
69
 
  decimals=NOT_FIXED_DEC;
70
 
  max_length=MAX_BLOB_WIDTH;
71
 
 
72
 
  var_entry= session.getVariable(name, false);
73
 
 
74
 
  /*
75
 
    If the variable didn't exist it has been created as a STRING-type.
76
 
    'var_entry' is NULL only if there occured an error during the call to
77
 
    get_var_with_binlog.
78
 
  */
79
 
  if (var_entry)
80
 
  {
81
 
    m_cached_result_type= var_entry->type;
82
 
    unsigned_flag= var_entry->unsigned_flag;
83
 
    max_length= var_entry->length;
84
 
 
85
 
    collation.set(var_entry->collation);
86
 
    switch(m_cached_result_type) 
87
 
    {
88
 
    case REAL_RESULT:
89
 
      max_length= DBL_DIG + 8;
90
 
      break;
91
 
 
92
 
    case INT_RESULT:
93
 
      max_length= MAX_BIGINT_WIDTH;
94
 
      decimals=0;
95
 
      break;
96
 
    case STRING_RESULT:
97
 
      max_length= MAX_BLOB_WIDTH;
98
 
      break;
99
 
 
100
 
    case DECIMAL_RESULT:
101
 
      max_length= DECIMAL_MAX_STR_LENGTH;
102
 
      decimals= DECIMAL_MAX_SCALE;
103
 
      break;
104
 
 
105
 
    case ROW_RESULT:                            // Keep compiler happy
106
 
      assert(0);
107
 
      break;
108
 
    }
109
 
  }
110
 
  else
111
 
  {
112
 
    collation.set(&my_charset_bin, DERIVATION_IMPLICIT);
113
 
    null_value= 1;
114
 
    m_cached_result_type= STRING_RESULT;
115
 
    max_length= MAX_BLOB_WIDTH;
116
 
  }
117
 
}
118
 
 
119
 
 
120
 
bool Item_func_get_user_var::const_item() const
121
 
{
122
 
  return (!var_entry || session.getQueryId() != var_entry->update_query_id);
123
 
}
124
 
 
125
 
 
126
 
enum Item_result Item_func_get_user_var::result_type() const
127
 
{
128
 
  return m_cached_result_type;
129
 
}
130
 
 
131
 
 
132
 
void Item_func_get_user_var::print(String *str,
133
 
                                   enum_query_type )
134
 
{
135
 
  str->append(STRING_WITH_LEN("(@"));
136
 
  str->append(name.str,name.length);
137
 
  str->append(')');
138
 
}
139
 
 
140
 
 
141
 
bool Item_func_get_user_var::eq(const Item *item,
142
 
                                bool ) const
143
 
{
144
 
  /* Assume we don't have rtti */
145
 
  if (this == item)
146
 
    return 1;                                   // Same item is same.
147
 
  /* Check if other type is also a get_user_var() object */
148
 
  if (item->type() != FUNC_ITEM ||
149
 
      ((Item_func*) item)->functype() != functype())
150
 
    return 0;
151
 
  Item_func_get_user_var *other=(Item_func_get_user_var*) item;
152
 
  return (name.length == other->name.length &&
153
 
          !memcmp(name.str, other->name.str, name.length));
154
 
}
155
 
 
156
 
} /* namespace drizzled */