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, Inc.
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
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>
32
String *Item_func_get_user_var::val_str(String *str)
36
return((String*) 0); // No such variable
37
return(var_entry->val_str(&null_value, str, decimals));
41
double Item_func_get_user_var::val_real()
45
return 0.0; // No such variable
46
return (var_entry->val_real(&null_value));
50
type::Decimal *Item_func_get_user_var::val_decimal(type::Decimal *dec)
55
return var_entry->val_decimal(&null_value, dec);
58
int64_t Item_func_get_user_var::val_int()
62
return 0L; // No such variable
63
return (var_entry->val_int(&null_value));
66
void Item_func_get_user_var::fix_length_and_dec()
69
decimals=NOT_FIXED_DEC;
70
max_length=MAX_BLOB_WIDTH;
72
var_entry= session.getVariable(name, false);
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
81
m_cached_result_type= var_entry->type;
82
unsigned_flag= var_entry->unsigned_flag;
83
max_length= var_entry->length;
85
collation.set(var_entry->collation);
86
switch(m_cached_result_type)
89
max_length= DBL_DIG + 8;
93
max_length= MAX_BIGINT_WIDTH;
97
max_length= MAX_BLOB_WIDTH;
101
max_length= DECIMAL_MAX_STR_LENGTH;
102
decimals= DECIMAL_MAX_SCALE;
105
case ROW_RESULT: // Keep compiler happy
112
collation.set(&my_charset_bin, DERIVATION_IMPLICIT);
114
m_cached_result_type= STRING_RESULT;
115
max_length= MAX_BLOB_WIDTH;
120
bool Item_func_get_user_var::const_item() const
122
return (!var_entry || session.getQueryId() != var_entry->update_query_id);
126
enum Item_result Item_func_get_user_var::result_type() const
128
return m_cached_result_type;
132
void Item_func_get_user_var::print(String *str,
135
str->append(STRING_WITH_LEN("(@"));
136
str->append(name.str,name.length);
141
bool Item_func_get_user_var::eq(const Item *item,
144
/* Assume we don't have rtti */
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())
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));
156
} /* namespace drizzled */