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 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
20 |
#include "config.h" |
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
21 |
|
22 |
#include <float.h> |
|
23 |
||
670.1.20
by Monty Taylor
Renamed functions to function... everything else is singular. |
24 |
#include <drizzled/function/get_user_var.h> |
642.1.20
by Lee
header file clean up |
25 |
#include <drizzled/item/null.h> |
575.4.7
by Monty Taylor
More header cleanup. |
26 |
#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. |
27 |
#include <drizzled/session.h> |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
28 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
29 |
namespace drizzled |
30 |
{
|
|
31 |
||
32 |
String *Item_func_get_user_var::val_str(String *str) |
|
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
50 |
type::Decimal *Item_func_get_user_var::val_decimal(type::Decimal *dec) |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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 |
||
1633.4.3
by Brian Aker
Remove session usage. |
72 |
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 |
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); |
|
995
by Brian Aker
Refactor get_variable to session |
86 |
switch(m_cached_result_type) |
87 |
{
|
|
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
88 |
case REAL_RESULT: |
89 |
max_length= DBL_DIG + 8; |
|
90 |
break; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
91 |
|
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
99 |
|
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
100 |
case DECIMAL_RESULT: |
101 |
max_length= DECIMAL_MAX_STR_LENGTH; |
|
102 |
decimals= DECIMAL_MAX_SCALE; |
|
103 |
break; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
104 |
|
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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 |
{
|
|
1633.4.5
by Brian Aker
More current_session. |
122 |
return (!var_entry || session.getQueryId() != var_entry->update_query_id); |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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, |
|
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
133 |
enum_query_type ) |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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, |
|
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
142 |
bool ) const |
492.3.32
by Lee
more changes to move functions from item_func.cc/h to the functions directory |
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 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
155 |
|
156 |
} /* namespace drizzled */ |