492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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
|
|
670.1.20
by Monty Taylor
Renamed functions to function... everything else is singular. |
22 |
#include <drizzled/function/get_user_var.h> |
642.1.20
by Lee
header file clean up |
23 |
#include <drizzled/item/null.h> |
575.4.7
by Monty Taylor
More header cleanup. |
24 |
#include <drizzled/sql_parse.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
25 |
#include <drizzled/session.h> |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
26 |
|
27 |
String * |
|
28 |
Item_func_get_user_var::val_str(String *str) |
|
29 |
{
|
|
30 |
assert(fixed == 1); |
|
31 |
if (!var_entry) |
|
32 |
return((String*) 0); // No such variable |
|
33 |
return(var_entry->val_str(&null_value, str, decimals)); |
|
34 |
}
|
|
35 |
||
36 |
||
37 |
double Item_func_get_user_var::val_real() |
|
38 |
{
|
|
39 |
assert(fixed == 1); |
|
40 |
if (!var_entry) |
|
41 |
return 0.0; // No such variable |
|
42 |
return (var_entry->val_real(&null_value)); |
|
43 |
}
|
|
44 |
||
45 |
||
46 |
my_decimal *Item_func_get_user_var::val_decimal(my_decimal *dec) |
|
47 |
{
|
|
48 |
assert(fixed == 1); |
|
49 |
if (!var_entry) |
|
50 |
return 0; |
|
51 |
return var_entry->val_decimal(&null_value, dec); |
|
52 |
}
|
|
53 |
||
54 |
int64_t Item_func_get_user_var::val_int() |
|
55 |
{
|
|
56 |
assert(fixed == 1); |
|
57 |
if (!var_entry) |
|
58 |
return 0L; // No such variable |
|
59 |
return (var_entry->val_int(&null_value)); |
|
60 |
}
|
|
61 |
||
62 |
void Item_func_get_user_var::fix_length_and_dec() |
|
63 |
{
|
|
64 |
Session *session=current_session; |
|
65 |
maybe_null=1; |
|
66 |
decimals=NOT_FIXED_DEC; |
|
67 |
max_length=MAX_BLOB_WIDTH; |
|
68 |
||
995
by Brian Aker
Refactor get_variable to session |
69 |
var_entry= session->getVariable(name, false); |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
70 |
|
71 |
/*
|
|
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
|
|
74 |
get_var_with_binlog.
|
|
75 |
*/
|
|
76 |
if (var_entry) |
|
77 |
{
|
|
78 |
m_cached_result_type= var_entry->type; |
|
79 |
unsigned_flag= var_entry->unsigned_flag; |
|
80 |
max_length= var_entry->length; |
|
81 |
||
82 |
collation.set(var_entry->collation); |
|
995
by Brian Aker
Refactor get_variable to session |
83 |
switch(m_cached_result_type) |
84 |
{
|
|
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
85 |
case REAL_RESULT: |
86 |
max_length= DBL_DIG + 8; |
|
87 |
break; |
|
88 |
case INT_RESULT: |
|
89 |
max_length= MAX_BIGINT_WIDTH; |
|
90 |
decimals=0; |
|
91 |
break; |
|
92 |
case STRING_RESULT: |
|
93 |
max_length= MAX_BLOB_WIDTH; |
|
94 |
break; |
|
95 |
case DECIMAL_RESULT: |
|
96 |
max_length= DECIMAL_MAX_STR_LENGTH; |
|
97 |
decimals= DECIMAL_MAX_SCALE; |
|
98 |
break; |
|
99 |
case ROW_RESULT: // Keep compiler happy |
|
100 |
default: |
|
101 |
assert(0); |
|
102 |
break; |
|
103 |
}
|
|
104 |
}
|
|
105 |
else
|
|
106 |
{
|
|
107 |
collation.set(&my_charset_bin, DERIVATION_IMPLICIT); |
|
108 |
null_value= 1; |
|
109 |
m_cached_result_type= STRING_RESULT; |
|
110 |
max_length= MAX_BLOB_WIDTH; |
|
111 |
}
|
|
112 |
}
|
|
113 |
||
114 |
||
115 |
bool Item_func_get_user_var::const_item() const |
|
116 |
{
|
|
117 |
return (!var_entry || current_session->query_id != var_entry->update_query_id); |
|
118 |
}
|
|
119 |
||
120 |
||
121 |
enum Item_result Item_func_get_user_var::result_type() const |
|
122 |
{
|
|
123 |
return m_cached_result_type; |
|
124 |
}
|
|
125 |
||
126 |
||
127 |
void Item_func_get_user_var::print(String *str, |
|
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
128 |
enum_query_type ) |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
129 |
{
|
130 |
str->append(STRING_WITH_LEN("(@")); |
|
131 |
str->append(name.str,name.length); |
|
132 |
str->append(')'); |
|
133 |
}
|
|
134 |
||
135 |
||
136 |
bool Item_func_get_user_var::eq(const Item *item, |
|
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
137 |
bool ) const |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
138 |
{
|
139 |
/* Assume we don't have rtti */
|
|
140 |
if (this == item) |
|
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()) |
|
145 |
return 0; |
|
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)); |
|
149 |
}
|