~drizzle-trunk/drizzle/development

1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
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.
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
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>
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
21
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
22
#include <drizzled/error.h>
23
#include <drizzled/name_resolution_context.h>
24
#include <drizzled/table.h>
25
#include <drizzled/session.h>
26
#include <drizzled/item/default_value.h>
27
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
28
namespace drizzled
29
{
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
30
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
31
bool Item_default_value::eq(const Item *item, bool binary_cmp) const
32
{
33
  return item->type() == DEFAULT_VALUE_ITEM &&
34
    ((Item_default_value *)item)->arg->eq(arg, binary_cmp);
35
}
36
37
38
bool Item_default_value::fix_fields(Session *session, Item **)
39
{
40
  Item *real_arg;
41
  Item_field *field_arg;
42
  Field *def_field;
43
  assert(fixed == 0);
44
45
  if (!arg)
46
  {
47
    fixed= 1;
48
    return false;
49
  }
50
  if (!arg->fixed && arg->fix_fields(session, &arg))
51
    goto error;
52
53
54
  real_arg= arg->real_item();
55
  if (real_arg->type() != FIELD_ITEM)
56
  {
57
    my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg->name);
58
    goto error;
59
  }
60
61
  field_arg= (Item_field *)real_arg;
62
  if (field_arg->field->flags & NO_DEFAULT_VALUE_FLAG)
63
  {
64
    my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), field_arg->field->field_name);
65
    goto error;
66
  }
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
67
  if (!(def_field= (Field*) memory::sql_alloc(field_arg->field->size_of())))
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
68
    goto error;
69
  memcpy(def_field, field_arg->field, field_arg->field->size_of());
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
70
  def_field->move_field_offset((ptrdiff_t)
1660.1.3 by Brian Aker
Encapsulate Table in field
71
                               (def_field->getTable()->getDefaultValues() - def_field->getTable()->record[0]));
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
72
  set_field(def_field);
73
  return false;
74
75
error:
76
  context->process_error(session);
77
  return true;
78
}
79
80
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.
81
void Item_default_value::print(String *str)
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
82
{
83
  if (!arg)
84
  {
85
    str->append(STRING_WITH_LEN("default"));
86
    return;
87
  }
88
  str->append(STRING_WITH_LEN("default("));
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.
89
  arg->print(str);
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
90
  str->append(')');
91
}
92
93
94
int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
95
{
96
  if (!arg)
97
  {
98
    if (field_arg->flags & NO_DEFAULT_VALUE_FLAG)
99
    {
100
      if (field_arg->reset())
101
      {
102
        my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
103
                   ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
104
        return -1;
105
      }
106
107
      {
1660.1.3 by Brian Aker
Encapsulate Table in field
108
        push_warning_printf(field_arg->getTable()->in_use,
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
109
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
110
                            ER_NO_DEFAULT_FOR_FIELD,
111
                            ER(ER_NO_DEFAULT_FOR_FIELD),
112
                            field_arg->field_name);
113
      }
114
      return 1;
115
    }
116
    field_arg->set_default();
117
    return 0;
118
  }
119
  return Item_field::save_in_field(field_arg, no_conversions);
120
}
121
122
123
/**
124
  This method like the walk method traverses the item tree, but at the
125
  same time it can replace some nodes in the tree.
126
*/
127
128
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
129
{
130
  Item *new_item= arg->transform(transformer, args);
131
  if (!new_item)
132
    return NULL;
2197.3.2 by Olaf van der Spek
Remove Session::change_item_tree
133
  arg= new_item;
1008.3.1 by Stewart Smith
move Item_default_value out into its own files under drizzled/item/ to make it easier to find and follow current convention
134
  return (this->*transformer)(args);
135
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
136
137
138
} /* namespace drizzled */