20
20
#ifndef DRIZZLED_STORED_KEY_H
21
21
#define DRIZZLED_STORED_KEY_H
23
#include <drizzled/memory/sql_alloc.h>
24
#include <drizzled/copy_field.h>
26
33
/** class to store an field/item as a key struct */
27
34
class StoredKey :public memory::SqlAlloc
38
46
Field *to_field; // Store data here
39
47
unsigned char *null_ptr;
41
49
virtual enum store_key_result copy_inner()=0;
43
52
StoredKey(Session *session,
45
54
unsigned char *ptr,
46
55
unsigned char *null,
53
if (field_arg->type() == DRIZZLE_TYPE_BLOB)
56
Key segments are always packed with a 2 byte length prefix.
57
See mi_rkey for details.
59
to_field= new Field_varstring(ptr,
64
field_arg->field_name,
65
field_arg->charset());
66
to_field->init(field_arg->getTable());
69
to_field= field_arg->new_key_field(session->mem_root, field_arg->getTable(),
72
to_field->setWriteSet();
74
58
virtual ~StoredKey() {} /** Not actually needed */
75
59
virtual const char *name() const=0;
80
64
@details this function makes sure truncation warnings when preparing the
81
65
key buffers don't end up as errors (because of an enclosing INSERT/UPDATE).
83
enum store_key_result copy()
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;
90
session->count_cuted_fields= saved_count_cuted_fields;
67
enum store_key_result copy();
96
71
class store_key_field: public StoredKey
98
73
CopyField copy_field;
99
74
const char *field_name;
101
77
store_key_field(Session *session, Field *to_field_arg, unsigned char *ptr,
102
78
unsigned char *null_ptr_arg,
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)
79
uint32_t length, Field *from_field, const char *name_arg) :
80
StoredKey(session, to_field_arg,ptr,
81
null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
82
: (unsigned char*) 0, length), field_name(name_arg)
110
86
copy_field.set(to_field,from_field,0);
124
100
class store_key_item :public StoredKey
129
106
store_key_item(Session *session, Field *to_field_arg, unsigned char *ptr,
130
unsigned char *null_ptr_arg, uint32_t length, Item *item_arg)
131
:StoredKey(session, to_field_arg, ptr,
107
unsigned char *null_ptr_arg, uint32_t length, Item *item_arg) :
108
StoredKey(session, to_field_arg, ptr,
132
109
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
133
110
&err : (unsigned char*) 0, length), item(item_arg)
146
123
class store_key_const_item :public store_key_item
150
128
store_key_const_item(Session *session, Field *to_field_arg, unsigned char *ptr,
151
unsigned char *null_ptr_arg, uint32_t length,
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
unsigned char *null_ptr_arg, uint32_t length,
131
store_key_item(session, to_field_arg,ptr,
132
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
133
&err : (unsigned char*) 0, length, item_arg), inited(0)
158
136
const char *name() const { return "const"; }