~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/stored_key.h

  • Committer: Andrew Hutchings
  • Date: 2011-02-01 10:23:22 UTC
  • mto: (2136.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2137.
  • Revision ID: andrew@linuxjedi.co.uk-20110201102322-oxztcyrjzg3c7yta
Fix counters cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#pragma once
21
 
 
22
 
#include <drizzled/memory/sql_alloc.h>
23
 
#include <drizzled/copy_field.h>
24
 
#include <drizzled/item.h>
25
 
 
26
 
namespace drizzled {
 
20
#ifndef DRIZZLED_STORED_KEY_H
 
21
#define DRIZZLED_STORED_KEY_H
 
22
 
 
23
namespace drizzled
 
24
{
27
25
 
28
26
/** class to store an field/item as a key struct */
29
27
class StoredKey :public memory::SqlAlloc
36
34
    STORE_KEY_FATAL, 
37
35
    STORE_KEY_CONV 
38
36
  };
39
 
 
40
37
protected:
41
38
  Field *to_field;                              // Store data here
42
39
  unsigned char *null_ptr;
43
40
  unsigned char err;
44
41
  virtual enum store_key_result copy_inner()=0;
45
 
 
46
42
public:
47
43
  StoredKey(Session *session,
48
44
            Field *field_arg, 
49
45
            unsigned char *ptr,
50
46
            unsigned char *null, 
51
 
            uint32_t length);
 
47
            uint32_t length)
 
48
    :
 
49
      null_key(0), 
 
50
      null_ptr(null), 
 
51
      err(0)
 
52
  {
 
53
    if (field_arg->type() == DRIZZLE_TYPE_BLOB)
 
54
    {
 
55
      /*
 
56
        Key segments are always packed with a 2 byte length prefix.
 
57
        See mi_rkey for details.
 
58
      */
 
59
      to_field= new Field_varstring(ptr,
 
60
                                    length,
 
61
                                    2,
 
62
                                    null,
 
63
                                    1,
 
64
                                    field_arg->field_name,
 
65
                                    field_arg->charset());
 
66
      to_field->init(field_arg->getTable());
 
67
    }
 
68
    else
 
69
      to_field= field_arg->new_key_field(session->mem_root, field_arg->getTable(),
 
70
                                        ptr, null, 1);
52
71
 
 
72
    to_field->setWriteSet();
 
73
  }
53
74
  virtual ~StoredKey() {}                       /** Not actually needed */
54
75
  virtual const char *name() const=0;
55
76
 
59
80
    @details this function makes sure truncation warnings when preparing the
60
81
    key buffers don't end up as errors (because of an enclosing INSERT/UPDATE).
61
82
  */
62
 
  enum store_key_result copy();
 
83
  enum store_key_result copy()
 
84
  {
 
85
    enum store_key_result result;
 
86
    Session *session= to_field->getTable()->in_use;
 
87
    enum_check_fields saved_count_cuted_fields= session->count_cuted_fields;
 
88
    session->count_cuted_fields= CHECK_FIELD_IGNORE;
 
89
    result= copy_inner();
 
90
    session->count_cuted_fields= saved_count_cuted_fields;
63
91
 
 
92
    return result;
 
93
  }
64
94
};
65
95
 
66
96
class store_key_field: public StoredKey
67
97
{
68
98
  CopyField copy_field;
69
99
  const char *field_name;
70
 
 
71
100
public:
72
101
  store_key_field(Session *session, Field *to_field_arg, unsigned char *ptr,
73
102
                  unsigned char *null_ptr_arg,
74
 
                  uint32_t length, Field *from_field, const char *name_arg) :
75
 
    StoredKey(session, to_field_arg,ptr,
76
 
              null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
77
 
              : (unsigned char*) 0, length), field_name(name_arg)
78
 
    {
 
103
                  uint32_t length, Field *from_field, const char *name_arg)
 
104
    :StoredKey(session, to_field_arg,ptr,
 
105
               null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
 
106
               : (unsigned char*) 0, length), field_name(name_arg)
 
107
  {
79
108
    if (to_field)
80
109
    {
81
110
      copy_field.set(to_field,from_field,0);
94
123
 
95
124
class store_key_item :public StoredKey
96
125
{
97
 
protected:
 
126
 protected:
98
127
  Item *item;
99
 
 
100
128
public:
101
129
  store_key_item(Session *session, Field *to_field_arg, unsigned char *ptr,
102
 
                 unsigned char *null_ptr_arg, uint32_t length, Item *item_arg) :
103
 
    StoredKey(session, to_field_arg, ptr,
 
130
                 unsigned char *null_ptr_arg, uint32_t length, Item *item_arg)
 
131
    :StoredKey(session, to_field_arg, ptr,
104
132
               null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
105
133
               &err : (unsigned char*) 0, length), item(item_arg)
106
134
  {}
118
146
class store_key_const_item :public store_key_item
119
147
{
120
148
  bool inited;
121
 
 
122
149
public:
123
150
  store_key_const_item(Session *session, Field *to_field_arg, unsigned char *ptr,
124
 
                       unsigned char *null_ptr_arg, uint32_t length,
125
 
                       Item *item_arg) :
126
 
    store_key_item(session, to_field_arg,ptr,
127
 
                   null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
128
 
                   &err : (unsigned char*) 0, length, item_arg), inited(0)
 
151
                       unsigned char *null_ptr_arg, uint32_t length,
 
152
                       Item *item_arg)
 
153
    :store_key_item(session, to_field_arg,ptr,
 
154
                    null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
 
155
                    &err : (unsigned char*) 0, length, item_arg), inited(0)
129
156
  {
130
157
  }
131
158
  const char *name() const { return "const"; }
150
177
 
151
178
} /* namespace drizzled */
152
179
 
 
180
#endif /* DRIZZLED_STORED_KEY_H */