~drizzle-trunk/drizzle/development

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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
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>
2154.2.24 by Brian Aker
Merge in all changes for current_session, etc.
28
#include <drizzled/user_var_entry.h>
492.3.32 by Lee
more changes to move functions from item_func.cc/h to the functions directory
29
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
30
namespace drizzled
31
{
32
33
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
34
{
35
  assert(fixed == 1);
36
  if (!var_entry)
37
    return((String*) 0);                        // No such variable
38
  return(var_entry->val_str(&null_value, str, decimals));
39
}
40
41
42
double Item_func_get_user_var::val_real()
43
{
44
  assert(fixed == 1);
45
  if (!var_entry)
46
    return 0.0;                                 // No such variable
47
  return (var_entry->val_real(&null_value));
48
}
49
50
2030.1.4 by Brian Aker
Change my_decimal to Decimal
51
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
52
{
53
  assert(fixed == 1);
54
  if (!var_entry)
55
    return 0;
56
  return var_entry->val_decimal(&null_value, dec);
57
}
58
59
int64_t Item_func_get_user_var::val_int()
60
{
61
  assert(fixed == 1);
62
  if (!var_entry)
63
    return 0L;                          // No such variable
64
  return (var_entry->val_int(&null_value));
65
}
66
67
void Item_func_get_user_var::fix_length_and_dec()
68
{
69
  maybe_null=1;
70
  decimals=NOT_FIXED_DEC;
71
  max_length=MAX_BLOB_WIDTH;
72
1633.4.3 by Brian Aker
Remove session usage.
73
  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
74
75
  /*
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
78
    get_var_with_binlog.
79
  */
80
  if (var_entry)
81
  {
82
    m_cached_result_type= var_entry->type;
83
    unsigned_flag= var_entry->unsigned_flag;
84
    max_length= var_entry->length;
85
86
    collation.set(var_entry->collation);
995 by Brian Aker
Refactor get_variable to session
87
    switch(m_cached_result_type) 
88
    {
492.3.32 by Lee
more changes to move functions from item_func.cc/h to the functions directory
89
    case REAL_RESULT:
90
      max_length= DBL_DIG + 8;
91
      break;
2008 by Brian Aker
Formatting + remove default from switch/case.
92
492.3.32 by Lee
more changes to move functions from item_func.cc/h to the functions directory
93
    case INT_RESULT:
94
      max_length= MAX_BIGINT_WIDTH;
95
      decimals=0;
96
      break;
97
    case STRING_RESULT:
98
      max_length= MAX_BLOB_WIDTH;
99
      break;
2008 by Brian Aker
Formatting + remove default from switch/case.
100
492.3.32 by Lee
more changes to move functions from item_func.cc/h to the functions directory
101
    case DECIMAL_RESULT:
102
      max_length= DECIMAL_MAX_STR_LENGTH;
103
      decimals= DECIMAL_MAX_SCALE;
104
      break;
2008 by Brian Aker
Formatting + remove default from switch/case.
105
492.3.32 by Lee
more changes to move functions from item_func.cc/h to the functions directory
106
    case ROW_RESULT:                            // Keep compiler happy
107
      assert(0);
108
      break;
109
    }
110
  }
111
  else
112
  {
113
    collation.set(&my_charset_bin, DERIVATION_IMPLICIT);
114
    null_value= 1;
115
    m_cached_result_type= STRING_RESULT;
116
    max_length= MAX_BLOB_WIDTH;
117
  }
118
}
119
120
121
bool Item_func_get_user_var::const_item() const
122
{
1633.4.5 by Brian Aker
More current_session.
123
  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
124
}
125
126
127
enum Item_result Item_func_get_user_var::result_type() const
128
{
129
  return m_cached_result_type;
130
}
131
132
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
133
void Item_func_get_user_var::print(String *str)
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("(@"));
2430.1.1 by Olaf van der Spek
Use lex_string assign(), data() and size()
136
  str->append(name);
492.3.32 by Lee
more changes to move functions from item_func.cc/h to the functions directory
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;
2430.1.1 by Olaf van der Spek
Use lex_string assign(), data() and size()
152
  return (name.size() == other->name.size() &&
153
	  !memcmp(name.data(), other->name.data(), name.size()));
492.3.32 by Lee
more changes to move functions from item_func.cc/h to the functions directory
154
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
155
156
} /* namespace drizzled */