Drizzled Public API Documentation

key.h

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 
00021 #pragma once
00022 
00023 #include <string>
00024 #include <boost/dynamic_bitset.hpp>
00025 
00026 #include <drizzled/memory/sql_alloc.h>
00027 #include <drizzled/key_part_spec.h>
00028 #include <drizzled/sql_list.h>
00029 #include <drizzled/lex_string.h>
00030 #include <drizzled/sql_string.h>
00031 #include <drizzled/handler_structs.h>
00032 
00033 namespace drizzled
00034 {
00035 
00036 namespace memory { class Root; }
00037 
00038 class Item;
00039 
00040 class Key :public memory::SqlAlloc {
00041 public:
00042   enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY};
00043   Keytype type;
00044   KEY_CREATE_INFO key_create_info;
00045   List<Key_part_spec> columns;
00046   LEX_STRING name;
00047   bool generated;
00048 
00049   Key(Keytype type_par,
00050       const lex_string_t &name_arg,
00051       KEY_CREATE_INFO *key_info_arg,
00052       bool generated_arg, List<Key_part_spec> &cols) :
00053     type(type_par),
00054     key_create_info(*key_info_arg),
00055     columns(cols),
00056     name(name_arg),
00057     generated(generated_arg)
00058   {}
00059 
00060   Key(Keytype type_par,
00061       const char *name_arg,
00062       size_t name_len_arg,
00063       KEY_CREATE_INFO *key_info_arg,
00064       bool generated_arg,
00065       List<Key_part_spec> &cols) :
00066     type(type_par),
00067     key_create_info(*key_info_arg),
00068     columns(cols),
00069     generated(generated_arg)
00070   {
00071     name.str= const_cast<char *>(name_arg);
00072     name.length= name_len_arg;
00073   }
00074 
00075   virtual ~Key() {}
00076   /* Equality comparison of keys (ignoring name) */
00077   friend bool foreign_key_prefix(Key *a, Key *b);
00078 };
00079 
00080 
00081 int find_ref_key(KeyInfo *key, uint32_t key_count, unsigned char *record, Field *field,
00082                  uint32_t *key_length, uint32_t *keypart);
00098 DRIZZLED_API void key_copy(unsigned char *to_key, unsigned char *from_record, KeyInfo *key_info, uint32_t key_length);
00099 void key_copy(std::basic_string<unsigned char> &to_key,
00100               unsigned char *from_record, KeyInfo *key_info, uint32_t key_length);
00101 void key_restore(unsigned char *to_record, unsigned char *from_key, KeyInfo *key_info,
00102                  uint16_t key_length);
00103 void key_zero_nulls(unsigned char *tuple, KeyInfo *key_info);
00104 bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
00105 void key_unpack(String *to, const Table *form,uint32_t index);
00106 bool is_key_used(Table *table, uint32_t idx, const boost::dynamic_bitset<>& fields);
00107 int key_cmp(KeyPartInfo *key_part, const unsigned char *key, uint32_t key_length);
00108 
00109 } /* namespace drizzled */
00110