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 class Key : public memory::SqlAlloc 
00036 {
00037 public:
00038   enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY };
00039   Keytype type;
00040   KEY_CREATE_INFO key_create_info;
00041   List<Key_part_spec> columns;
00042   str_ref name;
00043   bool generated;
00044 
00045   Key(Keytype type_par, str_ref name_arg, KEY_CREATE_INFO *key_info_arg, bool generated_arg, List<Key_part_spec> &cols) :
00046     type(type_par),
00047     key_create_info(*key_info_arg),
00048     columns(cols),
00049     name(name_arg),
00050     generated(generated_arg)
00051   {}
00052 
00053   virtual ~Key() {}
00054   /* Equality comparison of keys (ignoring name) */
00055   friend bool foreign_key_prefix(Key *a, Key *b);
00056 };
00057 
00058 
00059 int find_ref_key(KeyInfo *key, uint32_t key_count, unsigned char *record, Field *field, uint32_t *key_length, uint32_t *keypart);
00075 DRIZZLED_API void key_copy(unsigned char *to_key, unsigned char *from_record, KeyInfo *key_info, uint32_t key_length);
00076 void key_copy(std::basic_string<unsigned char> &to_key, unsigned char *from_record, KeyInfo *key_info, uint32_t key_length);
00077 void key_restore(unsigned char *to_record, unsigned char *from_key, KeyInfo *key_info, uint16_t key_length);
00078 void key_zero_nulls(unsigned char *tuple, KeyInfo *key_info);
00079 bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
00080 void key_unpack(String *to, const Table *form,uint32_t index);
00081 bool is_key_used(Table *table, uint32_t idx, const boost::dynamic_bitset<>& fields);
00082 int key_cmp(KeyPartInfo *key_part, const unsigned char *key, uint32_t key_length);
00083 
00084 } /* namespace drizzled */