Drizzled Public API Documentation

stored_key.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
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 
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 {
27 
30 {
31 public:
32  bool null_key;
33  enum store_key_result
34  {
35  STORE_KEY_OK,
36  STORE_KEY_FATAL,
37  STORE_KEY_CONV
38  };
39 
40 protected:
41  Field *to_field; // Store data here
42  unsigned char *null_ptr;
43  unsigned char err;
44  virtual enum store_key_result copy_inner()=0;
45 
46 public:
47  StoredKey(Session *session,
48  Field *field_arg,
49  unsigned char *ptr,
50  unsigned char *null,
51  uint32_t length);
52 
53  virtual ~StoredKey() {}
54  virtual const char *name() const=0;
55 
62  enum store_key_result copy();
63 
64 };
65 
67 {
68  CopyField copy_field;
69  const char *field_name;
70 
71 public:
72  store_key_field(Session *session, Field *to_field_arg, unsigned char *ptr,
73  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  {
79  if (to_field)
80  {
81  copy_field.set(to_field,from_field,0);
82  }
83  }
84  const char *name() const { return field_name; }
85 
86 protected:
87  enum store_key_result copy_inner()
88  {
89  copy_field.do_copy(&copy_field);
90  null_key= to_field->is_null();
91  return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
92  }
93 };
94 
96 {
97 protected:
98  Item *item;
99 
100 public:
101  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,
104  null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
105  &err : (unsigned char*) 0, length), item(item_arg)
106  {}
107  const char *name() const { return "func"; }
108 
109  protected:
110  enum store_key_result copy_inner()
111  {
112  int res= item->save_in_field(to_field, 1);
113  null_key= to_field->is_null() || item->null_value;
114  return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res);
115  }
116 };
117 
119 {
120  bool inited;
121 
122 public:
123  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)
129  {
130  }
131  const char *name() const { return "const"; }
132 
133 protected:
134  enum store_key_result copy_inner()
135  {
136  int res;
137  if (!inited)
138  {
139  inited=1;
140  if ((res= item->save_in_field(to_field, 1)))
141  {
142  if (!err)
143  err= res;
144  }
145  }
146  null_key= to_field->is_null() || item->null_value;
147  return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err);
148  }
149 };
150 
151 } /* namespace drizzled */
152 
virtual const char * name() const =0
bool null_value
Definition: item.h:122
const char * name() const
Definition: stored_key.h:107
bool maybe_null
Definition: item.h:121
const char * name() const
Definition: stored_key.h:84
enum store_key_result copy()
sets ignore truncation warnings mode and calls the real copy method
Definition: stored_key.cc:62
const char * name() const
Definition: stored_key.h:131