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>
28
#include <drizzled/user_var_entry.h>
33
String *Item_func_get_user_var::val_str(String *str)
37
return((String*) 0); // No such variable
38
return(var_entry->val_str(&null_value, str, decimals));
42
double Item_func_get_user_var::val_real()
46
return 0.0; // No such variable
47
return (var_entry->val_real(&null_value));
51
type::Decimal *Item_func_get_user_var::val_decimal(type::Decimal *dec)
56
return var_entry->val_decimal(&null_value, dec);
59
int64_t Item_func_get_user_var::val_int()
63
return 0L; // No such variable
64
return (var_entry->val_int(&null_value));
67
void Item_func_get_user_var::fix_length_and_dec()
70
decimals=NOT_FIXED_DEC;
71
max_length=MAX_BLOB_WIDTH;
73
var_entry= session.getVariable(name, false);
76
If the variable didn't exist it has been created as a STRING-type.
77
'var_entry' is NULL only if there occured an error during the call to
82
m_cached_result_type= var_entry->type;
83
unsigned_flag= var_entry->unsigned_flag;
84
max_length= var_entry->length;
86
collation.set(var_entry->collation);
87
switch(m_cached_result_type)
90
max_length= DBL_DIG + 8;
94
max_length= MAX_BIGINT_WIDTH;
98
max_length= MAX_BLOB_WIDTH;
102
max_length= DECIMAL_MAX_STR_LENGTH;
103
decimals= DECIMAL_MAX_SCALE;
106
case ROW_RESULT: // Keep compiler happy
113
collation.set(&my_charset_bin, DERIVATION_IMPLICIT);
115
m_cached_result_type= STRING_RESULT;
116
max_length= MAX_BLOB_WIDTH;
121
bool Item_func_get_user_var::const_item() const
123
return (!var_entry || session.getQueryId() != var_entry->update_query_id);
127
enum Item_result Item_func_get_user_var::result_type() const
129
return m_cached_result_type;
133
void Item_func_get_user_var::print(String *str,
136
str->append(STRING_WITH_LEN("(@"));
137
str->append(name.str,name.length);
142
bool Item_func_get_user_var::eq(const Item *item,
145
/* Assume we don't have rtti */
147
return 1; // Same item is same.
148
/* Check if other type is also a get_user_var() object */
149
if (item->type() != FUNC_ITEM ||
150
((Item_func*) item)->functype() != functype())
152
Item_func_get_user_var *other=(Item_func_get_user_var*) item;
153
return (name.length == other->name.length &&
154
!memcmp(name.str, other->name.str, name.length));
157
} /* namespace drizzled */