17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "drizzled/session.h"
23
#include "drizzled/error.h"
24
#include "drizzled/show.h"
25
#include "drizzled/item/ref.h"
26
#include "drizzled/plugin/client.h"
27
#include "drizzled/item/sum.h"
22
#include <drizzled/session.h>
23
#include <drizzled/error.h>
24
#include <drizzled/show.h>
25
#include <drizzled/item/ref.h>
26
#include <drizzled/plugin/client.h>
27
#include <drizzled/item/sum.h>
28
#include <drizzled/item/subselect.h>
29
#include <drizzled/sql_lex.h>
32
33
Item_ref::Item_ref(Name_resolution_context *context_arg,
33
34
Item **item, const char *table_name_arg,
114
115
enum_parsing_place place= NO_MATTER;
115
116
assert(fixed == 0);
116
Select_Lex *current_sel= session->lex->current_select;
117
Select_Lex *current_sel= session->lex().current_select;
118
119
if (!ref || ref == not_found_item)
120
if (!(ref= resolve_ref_in_select_and_group(session, this,
121
context->select_lex)))
122
goto error; /* Some error occurred (e.g. ambiguous names). */
121
if (!(ref= resolve_ref_in_select_and_group(session, this, context->select_lex)))
122
return true; /* Some error occurred (e.g. ambiguous names). */
124
124
if (ref == not_found_item) /* This reference was not resolved. */
131
131
if (!outer_context)
133
133
/* The current reference cannot be resolved in this query. */
134
my_error(ER_BAD_FIELD_ERROR,MYF(0),
135
full_name(), session->where());
134
my_error(ER_BAD_FIELD_ERROR,MYF(0), full_name(), session->where());
158
157
if (outer_context->resolve_in_select_list)
160
159
if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
161
goto error; /* Some error occurred (e.g. ambiguous names). */
160
return true; /* Some error occurred (e.g. ambiguous names). */
162
161
if (ref != not_found_item)
164
163
assert(*ref && (*ref)->fixed);
264
263
if (from_field != not_found_field)
267
if (!(fld= new Item_field(from_field)))
269
session->change_item_tree(reference, fld);
266
fld= new Item_field(from_field);
270
268
mark_as_dependent(session, last_checked_context->select_lex,
271
session->lex->current_select, this, fld);
269
session->lex().current_select, this, fld);
273
271
A reference is resolved to a nest level that's outer or the same as
274
272
the nest level of the enclosing set function : adjust the value of
275
273
max_arg_level for the function if it's needed.
277
if (session->lex->in_sum_func &&
278
session->lex->in_sum_func->nest_level >=
275
if (session->lex().in_sum_func &&
276
session->lex().in_sum_func->nest_level >=
279
277
last_checked_context->select_lex->nest_level)
280
set_if_bigger(session->lex->in_sum_func->max_arg_level,
278
set_if_bigger(session->lex().in_sum_func->max_arg_level,
281
279
last_checked_context->select_lex->nest_level);
286
284
/* The item was not a table field and not a reference */
287
my_error(ER_BAD_FIELD_ERROR, MYF(0),
288
full_name(), session->where());
285
my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where());
291
288
/* Should be checked in resolve_ref_in_select_and_group(). */
292
289
assert(*ref && (*ref)->fixed);
297
294
the nest level of the enclosing set function : adjust the value of
298
295
max_arg_level for the function if it's needed.
300
if (session->lex->in_sum_func &&
301
session->lex->in_sum_func->nest_level >=
297
if (session->lex().in_sum_func &&
298
session->lex().in_sum_func->nest_level >=
302
299
last_checked_context->select_lex->nest_level)
303
set_if_bigger(session->lex->in_sum_func->max_arg_level,
300
set_if_bigger(session->lex().in_sum_func->max_arg_level,
304
301
last_checked_context->select_lex->nest_level);
319
316
current_sel->having_fix_field)) ||
322
my_error(ER_ILLEGAL_REFERENCE, MYF(0),
323
name, ((*ref)->with_sum_func?
324
"reference to group function":
325
"forward reference in item list"));
319
my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, ((*ref)->with_sum_func ? "reference to group function" : "forward reference in item list"));
329
323
set_properties();
331
325
if ((*ref)->check_cols(1))
336
context->process_error(session);
378
368
str->append_identifier(name, (uint32_t) strlen(name));
381
(*ref)->print(str, query_type);
384
Item_ident::print(str, query_type);
374
Item_ident::print(str);
388
bool Item_ref::send(plugin::Client *client, String *tmp)
378
void Item_ref::send(plugin::Client *client, String *tmp)
390
380
if (result_field)
391
return client->store(result_field);
382
client->store(result_field);
392
385
return (*ref)->send(client, tmp);