1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_STORED_KEY_H
21
#define DRIZZLED_STORED_KEY_H
23
/** class to store an field/item as a key struct */
24
class StoredKey :public Sql_alloc
27
bool null_key; /**< If true, the value of the key has a null part */
35
Field *to_field; // Store data here
36
unsigned char *null_ptr;
38
virtual enum store_key_result copy_inner()=0;
40
StoredKey(Session *session,
50
if (field_arg->type() == DRIZZLE_TYPE_BLOB)
53
Key segments are always packed with a 2 byte length prefix.
54
See mi_rkey for details.
56
to_field= new Field_varstring(ptr, length, 2, null, 1,
57
Field::NONE, field_arg->field_name,
58
field_arg->table->s, field_arg->charset());
59
to_field->init(field_arg->table);
62
to_field= field_arg->new_key_field(session->mem_root, field_arg->table,
65
to_field->setWriteSet();
67
virtual ~StoredKey() {} /** Not actually needed */
68
virtual const char *name() const=0;
71
@brief sets ignore truncation warnings mode and calls the real copy method
73
@details this function makes sure truncation warnings when preparing the
74
key buffers don't end up as errors (because of an enclosing INSERT/UPDATE).
76
enum store_key_result copy()
78
enum store_key_result result;
79
Session *session= to_field->table->in_use;
80
enum_check_fields saved_count_cuted_fields= session->count_cuted_fields;
81
session->count_cuted_fields= CHECK_FIELD_IGNORE;
83
session->count_cuted_fields= saved_count_cuted_fields;
89
class store_key_field: public StoredKey
92
const char *field_name;
94
store_key_field(Session *session, Field *to_field_arg, unsigned char *ptr,
95
unsigned char *null_ptr_arg,
96
uint32_t length, Field *from_field, const char *name_arg)
97
:StoredKey(session, to_field_arg,ptr,
98
null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
99
: (unsigned char*) 0, length), field_name(name_arg)
103
copy_field.set(to_field,from_field,0);
106
const char *name() const { return field_name; }
109
enum store_key_result copy_inner()
111
copy_field.do_copy(©_field);
112
null_key= to_field->is_null();
113
return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
117
class store_key_item :public StoredKey
122
store_key_item(Session *session, Field *to_field_arg, unsigned char *ptr,
123
unsigned char *null_ptr_arg, uint32_t length, Item *item_arg)
124
:StoredKey(session, to_field_arg, ptr,
125
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
126
&err : (unsigned char*) 0, length), item(item_arg)
128
const char *name() const { return "func"; }
131
enum store_key_result copy_inner()
133
int res= item->save_in_field(to_field, 1);
134
null_key= to_field->is_null() || item->null_value;
135
return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res);
139
class store_key_const_item :public store_key_item
143
store_key_const_item(Session *session, Field *to_field_arg, unsigned char *ptr,
144
unsigned char *null_ptr_arg, uint32_t length,
146
:store_key_item(session, to_field_arg,ptr,
147
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
148
&err : (unsigned char*) 0, length, item_arg), inited(0)
151
const char *name() const { return "const"; }
154
enum store_key_result copy_inner()
160
if ((res= item->save_in_field(to_field, 1)))
166
null_key= to_field->is_null() || item->null_value;
167
return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err);
171
#endif /* DRIZZLED_STORED_KEY_H */