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, Inc.
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
#include <drizzled/memory/sql_alloc.h>
24
#include <drizzled/copy_field.h>
33
/** class to store an field/item as a key struct */
34
class StoredKey :public memory::SqlAlloc
37
bool null_key; /**< If true, the value of the key has a null part */
46
Field *to_field; // Store data here
47
unsigned char *null_ptr;
49
virtual enum store_key_result copy_inner()=0;
52
StoredKey(Session *session,
58
virtual ~StoredKey() {} /** Not actually needed */
59
virtual const char *name() const=0;
62
@brief sets ignore truncation warnings mode and calls the real copy method
64
@details this function makes sure truncation warnings when preparing the
65
key buffers don't end up as errors (because of an enclosing INSERT/UPDATE).
67
enum store_key_result copy();
71
class store_key_field: public StoredKey
74
const char *field_name;
77
store_key_field(Session *session, Field *to_field_arg, unsigned char *ptr,
78
unsigned char *null_ptr_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)
86
copy_field.set(to_field,from_field,0);
89
const char *name() const { return field_name; }
92
enum store_key_result copy_inner()
94
copy_field.do_copy(©_field);
95
null_key= to_field->is_null();
96
return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
100
class store_key_item :public StoredKey
106
store_key_item(Session *session, Field *to_field_arg, unsigned char *ptr,
107
unsigned char *null_ptr_arg, uint32_t length, Item *item_arg) :
108
StoredKey(session, to_field_arg, ptr,
109
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
110
&err : (unsigned char*) 0, length), item(item_arg)
112
const char *name() const { return "func"; }
115
enum store_key_result copy_inner()
117
int res= item->save_in_field(to_field, 1);
118
null_key= to_field->is_null() || item->null_value;
119
return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res);
123
class store_key_const_item :public store_key_item
128
store_key_const_item(Session *session, Field *to_field_arg, unsigned char *ptr,
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)
136
const char *name() const { return "const"; }
139
enum store_key_result copy_inner()
145
if ((res= item->save_in_field(to_field, 1)))
151
null_key= to_field->is_null() || item->null_value;
152
return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err);
156
} /* namespace drizzled */
158
#endif /* DRIZZLED_STORED_KEY_H */