~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/insert_value.cc

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:16:28 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: mordred@inaugust.com-20090304021628-rfq0b16uoi09g8tx
Fix to make VPATH builds work again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/error.h>
 
23
#include <drizzled/name_resolution_context.h>
 
24
#include <drizzled/table.h>
 
25
#include <drizzled/item/insert_value.h>
 
26
#include <drizzled/item/ref.h>
 
27
#include <drizzled/item/copy_string.h>
 
28
#include <drizzled/field/null.h>
 
29
 
 
30
 
 
31
bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
 
32
{
 
33
  return item->type() == INSERT_VALUE_ITEM &&
 
34
    ((Item_default_value *)item)->arg->eq(arg, binary_cmp);
 
35
}
 
36
 
 
37
bool Item_insert_value::fix_fields(Session *session, Item **)
 
38
{
 
39
  assert(fixed == 0);
 
40
  /* We should only check that arg is in first table */
 
41
  if (!arg->fixed)
 
42
  {
 
43
    bool res;
 
44
    TableList *orig_next_table= context->last_name_resolution_table;
 
45
    context->last_name_resolution_table= context->first_name_resolution_table;
 
46
    res= arg->fix_fields(session, &arg);
 
47
    context->last_name_resolution_table= orig_next_table;
 
48
    if (res)
 
49
      return true;
 
50
  }
 
51
 
 
52
  if (arg->type() == REF_ITEM)
 
53
  {
 
54
    Item_ref *ref= (Item_ref *)arg;
 
55
    if (ref->ref[0]->type() != FIELD_ITEM)
 
56
    {
 
57
      my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function");
 
58
      return true;
 
59
    }
 
60
    arg= ref->ref[0];
 
61
  }
 
62
  /*
 
63
    According to our SQL grammar, VALUES() function can reference
 
64
    only to a column.
 
65
  */
 
66
  assert(arg->type() == FIELD_ITEM);
 
67
 
 
68
  Item_field *field_arg= (Item_field *)arg;
 
69
 
 
70
  if (field_arg->field->table->insert_values)
 
71
  {
 
72
    Field *def_field= (Field*) sql_alloc(field_arg->field->size_of());
 
73
    if (!def_field)
 
74
      return true;
 
75
    memcpy(def_field, field_arg->field, field_arg->field->size_of());
 
76
    def_field->move_field_offset((my_ptrdiff_t)
 
77
                                 (def_field->table->insert_values -
 
78
                                  def_field->table->record[0]));
 
79
    set_field(def_field);
 
80
  }
 
81
  else
 
82
  {
 
83
    Field *tmp_field= field_arg->field;
 
84
    /* charset doesn't matter here, it's to avoid sigsegv only */
 
85
    tmp_field= new Field_null(0, 0, Field::NONE, field_arg->field->field_name,
 
86
                          &my_charset_bin);
 
87
    if (tmp_field)
 
88
    {
 
89
      tmp_field->init(field_arg->field->table);
 
90
      set_field(tmp_field);
 
91
    }
 
92
  }
 
93
  return false;
 
94
}
 
95
 
 
96
 
 
97
void Item_insert_value::print(String *str, enum_query_type query_type)
 
98
{
 
99
  str->append(STRING_WITH_LEN("values("));
 
100
  arg->print(str, query_type);
 
101
  str->append(')');
 
102
}
 
103
 
 
104
 
 
105