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_user_var.h>
23
#include <drizzled/item/null.h>
24
#include <drizzled/sql_parse.h>
25
#include <drizzled/session.h>
28
Item_func_get_user_var::val_str(String *str)
32
return((String*) 0); // No such variable
33
return(var_entry->val_str(&null_value, str, decimals));
37
double Item_func_get_user_var::val_real()
41
return 0.0; // No such variable
42
return (var_entry->val_real(&null_value));
46
my_decimal *Item_func_get_user_var::val_decimal(my_decimal *dec)
51
return var_entry->val_decimal(&null_value, dec);
54
int64_t Item_func_get_user_var::val_int()
58
return 0L; // No such variable
59
return (var_entry->val_int(&null_value));
62
void Item_func_get_user_var::fix_length_and_dec()
64
Session *session=current_session;
66
decimals=NOT_FIXED_DEC;
67
max_length=MAX_BLOB_WIDTH;
69
var_entry= session->getVariable(name, false);
72
If the variable didn't exist it has been created as a STRING-type.
73
'var_entry' is NULL only if there occured an error during the call to
78
m_cached_result_type= var_entry->type;
79
unsigned_flag= var_entry->unsigned_flag;
80
max_length= var_entry->length;
82
collation.set(var_entry->collation);
83
switch(m_cached_result_type)
86
max_length= DBL_DIG + 8;
89
max_length= MAX_BIGINT_WIDTH;
93
max_length= MAX_BLOB_WIDTH;
96
max_length= DECIMAL_MAX_STR_LENGTH;
97
decimals= DECIMAL_MAX_SCALE;
99
case ROW_RESULT: // Keep compiler happy
107
collation.set(&my_charset_bin, DERIVATION_IMPLICIT);
109
m_cached_result_type= STRING_RESULT;
110
max_length= MAX_BLOB_WIDTH;
115
bool Item_func_get_user_var::const_item() const
117
return (!var_entry || current_session->query_id != var_entry->update_query_id);
121
enum Item_result Item_func_get_user_var::result_type() const
123
return m_cached_result_type;
127
void Item_func_get_user_var::print(String *str,
130
str->append(STRING_WITH_LEN("(@"));
131
str->append(name.str,name.length);
136
bool Item_func_get_user_var::eq(const Item *item,
139
/* Assume we don't have rtti */
141
return 1; // Same item is same.
142
/* Check if other type is also a get_user_var() object */
143
if (item->type() != FUNC_ITEM ||
144
((Item_func*) item)->functype() != functype())
146
Item_func_get_user_var *other=(Item_func_get_user_var*) item;
147
return (name.length == other->name.length &&
148
!memcmp(name.str, other->name.str, name.length));