642.1.1
by Lee
move functions from item.cc/item.h to item 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
|
|
22 |
#include <drizzled/show.h> |
|
23 |
#include <drizzled/table.h> |
|
670.2.1
by Monty Taylor
Moved pthread keys |
24 |
#include <drizzled/current_session.h> |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
25 |
#include <drizzled/item/ident.h> |
26 |
||
820.3.25
by Padraig
Updated the fix for Bug#319796. |
27 |
using namespace std; |
28 |
||
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
29 |
const uint32_t NO_CACHED_FIELD_INDEX= UINT32_MAX; |
30 |
||
31 |
Item_ident::Item_ident(Name_resolution_context *context_arg, |
|
32 |
const char *db_name_arg,const char *table_name_arg, |
|
33 |
const char *field_name_arg) |
|
34 |
:orig_db_name(db_name_arg), orig_table_name(table_name_arg), |
|
35 |
orig_field_name(field_name_arg), context(context_arg), |
|
36 |
db_name(db_name_arg), table_name(table_name_arg), |
|
37 |
field_name(field_name_arg), |
|
38 |
alias_name_used(false), cached_field_index(NO_CACHED_FIELD_INDEX), |
|
39 |
cached_table(0), depended_from(0) |
|
40 |
{
|
|
41 |
name = (char*) field_name_arg; |
|
42 |
}
|
|
43 |
||
44 |
/**
|
|
45 |
Constructor used by Item_field & Item_*_ref (see Item comment)
|
|
46 |
*/
|
|
47 |
||
48 |
Item_ident::Item_ident(Session *session, Item_ident *item) |
|
49 |
:Item(session, item), |
|
50 |
orig_db_name(item->orig_db_name), |
|
51 |
orig_table_name(item->orig_table_name), |
|
52 |
orig_field_name(item->orig_field_name), |
|
53 |
context(item->context), |
|
54 |
db_name(item->db_name), |
|
55 |
table_name(item->table_name), |
|
56 |
field_name(item->field_name), |
|
57 |
alias_name_used(item->alias_name_used), |
|
58 |
cached_field_index(item->cached_field_index), |
|
59 |
cached_table(item->cached_table), |
|
60 |
depended_from(item->depended_from) |
|
61 |
{}
|
|
62 |
||
63 |
void Item_ident::cleanup() |
|
64 |
{
|
|
65 |
#ifdef CANT_BE_USED_AS_MEMORY_IS_FREED
|
|
66 |
db_name ? db_name : "(null)", |
|
67 |
orig_db_name ? orig_db_name : "(null)", |
|
68 |
table_name ? table_name : "(null)", |
|
69 |
orig_table_name ? orig_table_name : "(null)", |
|
70 |
field_name ? field_name : "(null)", |
|
71 |
orig_field_name ? orig_field_name : "(null)")); |
|
72 |
#endif
|
|
73 |
Item::cleanup(); |
|
74 |
db_name= orig_db_name; |
|
75 |
table_name= orig_table_name; |
|
76 |
field_name= orig_field_name; |
|
77 |
depended_from= 0; |
|
78 |
return; |
|
79 |
}
|
|
80 |
||
81 |
bool Item_ident::remove_dependence_processor(unsigned char * arg) |
|
82 |
{
|
|
846
by Brian Aker
Removing on typedeffed class. |
83 |
if (depended_from == (Select_Lex *) arg) |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
84 |
depended_from= 0; |
85 |
return(0); |
|
86 |
}
|
|
87 |
||
88 |
const char *Item_ident::full_name() const |
|
89 |
{
|
|
90 |
char *tmp; |
|
91 |
if (!table_name || !field_name) |
|
92 |
return field_name ? field_name : name ? name : "tmp_field"; |
|
93 |
if (db_name && db_name[0]) |
|
94 |
{
|
|
95 |
tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+ |
|
96 |
(uint) strlen(field_name)+3); |
|
673.2.2
by Toru Maesaka
Final pass of replacing MySQL's strxmov with libc's alternatives |
97 |
sprintf(tmp,"%s.%s.%s",db_name,table_name,field_name); |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
98 |
}
|
99 |
else
|
|
100 |
{
|
|
101 |
if (table_name[0]) |
|
102 |
{
|
|
103 |
tmp= (char*) sql_alloc((uint) strlen(table_name) + |
|
104 |
(uint) strlen(field_name) + 2); |
|
673.2.2
by Toru Maesaka
Final pass of replacing MySQL's strxmov with libc's alternatives |
105 |
sprintf(tmp, "%s.%s", table_name, field_name); |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
106 |
}
|
107 |
else
|
|
108 |
tmp= (char*) field_name; |
|
109 |
}
|
|
110 |
return tmp; |
|
111 |
}
|
|
112 |
||
113 |
||
114 |
void Item_ident::print(String *str, |
|
115 |
enum_query_type) |
|
116 |
{
|
|
873.2.29
by Monty Taylor
Shortened a small chunk of code. |
117 |
string d_name, t_name; |
820.3.26
by Padraig
Added extra checks when creating strings. Need to make sure that the content |
118 |
|
873.2.29
by Monty Taylor
Shortened a small chunk of code. |
119 |
if (table_name && table_name[0]) |
120 |
{
|
|
121 |
t_name.assign(table_name); |
|
122 |
if (lower_case_table_names== 1 || |
|
123 |
(lower_case_table_names == 2 && !alias_name_used)) |
|
124 |
// Keeping the std:: here, since Item_ident has a transform method
|
|
125 |
std::transform(t_name.begin(), t_name.end(), |
|
126 |
t_name.begin(), ::tolower); |
|
127 |
}
|
|
128 |
||
129 |
if (db_name && db_name[0]) |
|
130 |
{
|
|
131 |
d_name.assign(db_name); |
|
132 |
if (lower_case_table_names== 1 || |
|
133 |
(lower_case_table_names == 2 && !alias_name_used)) |
|
134 |
// Keeping the std:: prefix here, since Item_ident has a transform method
|
|
135 |
std::transform(d_name.begin(), d_name.end(), |
|
136 |
d_name.begin(), ::tolower); |
|
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
137 |
}
|
138 |
||
139 |
if (!table_name || !field_name || !field_name[0]) |
|
140 |
{
|
|
141 |
const char *nm= (field_name && field_name[0]) ? |
|
142 |
field_name : name ? name : "tmp_field"; |
|
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
143 |
str->append_identifier(nm, (uint) strlen(nm)); |
144 |
||
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
145 |
return; |
146 |
}
|
|
147 |
if (db_name && db_name[0] && !alias_name_used) |
|
148 |
{
|
|
149 |
{
|
|
873.2.29
by Monty Taylor
Shortened a small chunk of code. |
150 |
str->append_identifier(d_name.c_str(), d_name.length()); |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
151 |
str->append('.'); |
152 |
}
|
|
873.2.29
by Monty Taylor
Shortened a small chunk of code. |
153 |
str->append_identifier(t_name.c_str(), t_name.length()); |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
154 |
str->append('.'); |
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
155 |
str->append_identifier(field_name, (uint)strlen(field_name)); |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
156 |
}
|
157 |
else
|
|
158 |
{
|
|
159 |
if (table_name[0]) |
|
160 |
{
|
|
873.2.29
by Monty Taylor
Shortened a small chunk of code. |
161 |
str->append_identifier(t_name.c_str(), t_name.length()); |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
162 |
str->append('.'); |
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
163 |
str->append_identifier(field_name, (uint) strlen(field_name)); |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
164 |
}
|
165 |
else
|
|
794
by Brian Aker
Refactor append_identifier and remove dead OPTION_QUOTE_SHOW_CREATE option |
166 |
str->append_identifier(field_name, (uint) strlen(field_name)); |
642.1.1
by Lee
move functions from item.cc/item.h to item directory |
167 |
}
|
168 |
}
|
|
169 |
||
170 |
double Item_ident_for_show::val_real() |
|
171 |
{
|
|
172 |
return field->val_real(); |
|
173 |
}
|
|
174 |
||
175 |
||
176 |
int64_t Item_ident_for_show::val_int() |
|
177 |
{
|
|
178 |
return field->val_int(); |
|
179 |
}
|
|
180 |
||
181 |
||
182 |
String *Item_ident_for_show::val_str(String *str) |
|
183 |
{
|
|
184 |
return field->val_str(str); |
|
185 |
}
|
|
186 |
||
187 |
||
188 |
my_decimal *Item_ident_for_show::val_decimal(my_decimal *dec) |
|
189 |
{
|
|
190 |
return field->val_decimal(dec); |
|
191 |
}
|
|
192 |
||
193 |
void Item_ident_for_show::make_field(Send_field *tmp_field) |
|
194 |
{
|
|
195 |
tmp_field->table_name= tmp_field->org_table_name= table_name; |
|
196 |
tmp_field->db_name= db_name; |
|
197 |
tmp_field->col_name= tmp_field->org_col_name= field->field_name; |
|
198 |
tmp_field->charsetnr= field->charset()->number; |
|
199 |
tmp_field->length=field->field_length; |
|
200 |
tmp_field->type=field->type(); |
|
201 |
tmp_field->flags= field->table->maybe_null ? |
|
202 |
(field->flags & ~NOT_NULL_FLAG) : field->flags; |
|
203 |
tmp_field->decimals= field->decimals(); |
|
204 |
}
|
|
205 |