Drizzled Public API Documentation

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 
21 #pragma once
22 
23 #include <string>
24 #include <boost/dynamic_bitset.hpp>
25 
26 #include <drizzled/memory/sql_alloc.h>
27 #include <drizzled/key_part_spec.h>
28 #include <drizzled/sql_list.h>
29 #include <drizzled/lex_string.h>
30 #include <drizzled/sql_string.h>
31 #include <drizzled/handler_structs.h>
32 
33 namespace drizzled {
34 
35 class Key : public memory::SqlAlloc
36 {
37 public:
38  enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY };
39  Keytype type;
40  KEY_CREATE_INFO key_create_info;
41  List<Key_part_spec> columns;
42  str_ref name;
43  bool generated;
44 
45  Key(Keytype type_par, str_ref name_arg, KEY_CREATE_INFO *key_info_arg, bool generated_arg, List<Key_part_spec> &cols) :
46  type(type_par),
47  key_create_info(*key_info_arg),
48  columns(cols),
49  name(name_arg),
50  generated(generated_arg)
51  {}
52 
53  virtual ~Key() {}
54  /* Equality comparison of keys (ignoring name) */
55  friend bool foreign_key_prefix(Key *a, Key *b);
56 };
57 
58 
59 int find_ref_key(KeyInfo *key, uint32_t key_count, unsigned char *record, Field *field, uint32_t *key_length, uint32_t *keypart);
75 DRIZZLED_API void key_copy(unsigned char *to_key, unsigned char *from_record, KeyInfo *key_info, uint32_t key_length);
76 void key_copy(std::basic_string<unsigned char> &to_key, unsigned char *from_record, KeyInfo *key_info, uint32_t key_length);
77 void key_restore(unsigned char *to_record, unsigned char *from_key, KeyInfo *key_info, uint16_t key_length);
78 void key_zero_nulls(unsigned char *tuple, KeyInfo *key_info);
79 bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
80 void key_unpack(String *to, const Table *form,uint32_t index);
81 bool is_key_used(Table *table, uint32_t idx, const boost::dynamic_bitset<>& fields);
82 int key_cmp(KeyPartInfo *key_part, const unsigned char *key, uint32_t key_length);
83 
84 } /* namespace drizzled */