~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/key.h

Removing global errbuff and cleaning up two remaining instances that referenced it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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
#ifndef DRIZZLED_KEY_H
 
22
#define DRIZZLED_KEY_H
 
23
 
 
24
 
 
25
#include <drizzled/sql_alloc.h>
 
26
#include <drizzled/key_part_spec.h>
 
27
#include <drizzled/sql_list.h>
 
28
#include <drizzled/lex_string.h>
 
29
#include <drizzled/handler_structs.h>
 
30
#include <bitset>
 
31
 
 
32
class Item;
 
33
typedef struct st_mem_root MEM_ROOT;
 
34
 
 
35
class Key :public Sql_alloc {
 
36
public:
 
37
  enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY};
 
38
  enum Keytype type;
 
39
  KEY_CREATE_INFO key_create_info;
 
40
  List<Key_part_spec> columns;
 
41
  LEX_STRING name;
 
42
  bool generated;
 
43
 
 
44
  Key(enum Keytype type_par, const LEX_STRING &name_arg,
 
45
      KEY_CREATE_INFO *key_info_arg,
 
46
      bool generated_arg, List<Key_part_spec> &cols)
 
47
    :type(type_par), key_create_info(*key_info_arg), columns(cols),
 
48
    name(name_arg), generated(generated_arg)
 
49
  {}
 
50
  Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
 
51
      KEY_CREATE_INFO *key_info_arg, bool generated_arg,
 
52
      List<Key_part_spec> &cols)
 
53
    :type(type_par), key_create_info(*key_info_arg), columns(cols),
 
54
    generated(generated_arg)
 
55
  {
 
56
    name.str= (char *)name_arg;
 
57
    name.length= name_len_arg;
 
58
  }
 
59
 
 
60
  /**
 
61
   * Construct an (almost) deep copy of this key. Only those
 
62
   * elements that are known to never change are not copied.
 
63
   * If out of memory, a partial copy is returned and an error is set
 
64
   * in Session.
 
65
   */
 
66
  Key(const Key &rhs, MEM_ROOT *mem_root);
 
67
  virtual ~Key() {}
 
68
  /* Equality comparison of keys (ignoring name) */
 
69
  friend bool foreign_key_prefix(Key *a, Key *b);
 
70
  /**
 
71
    Used to make a clone of this object for ALTER/CREATE TABLE
 
72
    @sa comment for Key_part_spec::clone
 
73
  */
 
74
  virtual Key *clone(MEM_ROOT *mem_root) const
 
75
    { return new (mem_root) Key(*this, mem_root); }
 
76
};
 
77
 
 
78
 
 
79
int find_ref_key(KEY *key, uint32_t key_count, unsigned char *record, Field *field,
 
80
                 uint32_t *key_length, uint32_t *keypart);
 
81
/**
 
82
  Copy part of a record that forms a key or key prefix to a buffer.
 
83
 
 
84
    The function takes a complete table record (as e.g. retrieved by
 
85
    handler::index_read()), and a description of an index on the same table,
 
86
    and extracts the first key_length bytes of the record which are part of a
 
87
    key into to_key. If length == 0 then copy all bytes from the record that
 
88
    form a key.
 
89
 
 
90
  @param to_key      buffer that will be used as a key
 
91
  @param from_record full record to be copied from
 
92
  @param key_info    descriptor of the index
 
93
  @param key_length  specifies length of all keyparts that will be copied
 
94
*/
 
95
 
 
96
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info, uint32_t key_length);
 
97
void key_copy(std::basic_string<unsigned char> &to_key,
 
98
              unsigned char *from_record, KEY *key_info, uint32_t key_length);
 
99
void key_restore(unsigned char *to_record, unsigned char *from_key, KEY *key_info,
 
100
                 uint16_t key_length);
 
101
void key_zero_nulls(unsigned char *tuple, KEY *key_info);
 
102
bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
 
103
void key_unpack(String *to,Table *form,uint32_t index);
 
104
bool is_key_used(Table *table, uint32_t idx, const std::bitset<MAX_FIELDS> *fields);
 
105
int key_cmp(KEY_PART_INFO *key_part, const unsigned char *key, uint32_t key_length);
 
106
extern "C" int key_rec_cmp(void *key_info, unsigned char *a, unsigned char *b);
 
107
#endif /* DRIZZLED_KEY_H */