~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/stored_key.h

  • Committer: Lee Bieber
  • Date: 2010-11-14 23:15:42 UTC
  • mfrom: (1929.1.42 warning-stack-frame)
  • Revision ID: kalebral@gmail.com-20101114231542-fnnu6ydd2p17n582
Merge Monty - fix bug 672372: some functions use > 32k stack

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
20
20
#ifndef DRIZZLED_STORED_KEY_H
21
21
#define DRIZZLED_STORED_KEY_H
22
22
 
23
 
#include <drizzled/memory/sql_alloc.h>
24
 
#include <drizzled/copy_field.h>
25
 
 
26
23
namespace drizzled
27
24
{
28
25
 
29
 
class Field;
30
 
class Session;
31
 
class Item;
32
 
 
33
26
/** class to store an field/item as a key struct */
34
27
class StoredKey :public memory::SqlAlloc
35
28
{
41
34
    STORE_KEY_FATAL, 
42
35
    STORE_KEY_CONV 
43
36
  };
44
 
 
45
37
protected:
46
38
  Field *to_field;                              // Store data here
47
39
  unsigned char *null_ptr;
48
40
  unsigned char err;
49
41
  virtual enum store_key_result copy_inner()=0;
50
 
 
51
42
public:
52
43
  StoredKey(Session *session,
53
44
            Field *field_arg, 
54
45
            unsigned char *ptr,
55
46
            unsigned char *null, 
56
 
            uint32_t length);
 
47
            uint32_t length)
 
48
    :
 
49
      null_key(0), 
 
50
      null_ptr(null), 
 
51
      err(0)
 
52
  {
 
53
    if (field_arg->type() == DRIZZLE_TYPE_BLOB)
 
54
    {
 
55
      /*
 
56
        Key segments are always packed with a 2 byte length prefix.
 
57
        See mi_rkey for details.
 
58
      */
 
59
      to_field= new Field_varstring(ptr,
 
60
                                    length,
 
61
                                    2,
 
62
                                    null,
 
63
                                    1,
 
64
                                    field_arg->field_name,
 
65
                                    field_arg->charset());
 
66
      to_field->init(field_arg->getTable());
 
67
    }
 
68
    else
 
69
      to_field= field_arg->new_key_field(session->mem_root, field_arg->getTable(),
 
70
                                        ptr, null, 1);
57
71
 
 
72
    to_field->setWriteSet();
 
73
  }
58
74
  virtual ~StoredKey() {}                       /** Not actually needed */
59
75
  virtual const char *name() const=0;
60
76
 
64
80
    @details this function makes sure truncation warnings when preparing the
65
81
    key buffers don't end up as errors (because of an enclosing INSERT/UPDATE).
66
82
  */
67
 
  enum store_key_result copy();
 
83
  enum store_key_result copy()
 
84
  {
 
85
    enum store_key_result result;
 
86
    Session *session= to_field->getTable()->in_use;
 
87
    enum_check_fields saved_count_cuted_fields= session->count_cuted_fields;
 
88
    session->count_cuted_fields= CHECK_FIELD_IGNORE;
 
89
    result= copy_inner();
 
90
    session->count_cuted_fields= saved_count_cuted_fields;
68
91
 
 
92
    return result;
 
93
  }
69
94
};
70
95
 
71
96
class store_key_field: public StoredKey
72
97
{
73
98
  CopyField copy_field;
74
99
  const char *field_name;
75
 
 
76
100
public:
77
101
  store_key_field(Session *session, Field *to_field_arg, unsigned char *ptr,
78
102
                  unsigned char *null_ptr_arg,
79
 
                  uint32_t length, Field *from_field, const char *name_arg) :
80
 
    StoredKey(session, to_field_arg,ptr,
81
 
              null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
82
 
              : (unsigned char*) 0, length), field_name(name_arg)
83
 
    {
 
103
                  uint32_t length, Field *from_field, const char *name_arg)
 
104
    :StoredKey(session, to_field_arg,ptr,
 
105
               null_ptr_arg ? null_ptr_arg : from_field->maybe_null() ? &err
 
106
               : (unsigned char*) 0, length), field_name(name_arg)
 
107
  {
84
108
    if (to_field)
85
109
    {
86
110
      copy_field.set(to_field,from_field,0);
99
123
 
100
124
class store_key_item :public StoredKey
101
125
{
102
 
protected:
 
126
 protected:
103
127
  Item *item;
104
 
 
105
128
public:
106
129
  store_key_item(Session *session, Field *to_field_arg, unsigned char *ptr,
107
 
                 unsigned char *null_ptr_arg, uint32_t length, Item *item_arg) :
108
 
    StoredKey(session, to_field_arg, ptr,
 
130
                 unsigned char *null_ptr_arg, uint32_t length, Item *item_arg)
 
131
    :StoredKey(session, to_field_arg, ptr,
109
132
               null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
110
133
               &err : (unsigned char*) 0, length), item(item_arg)
111
134
  {}
123
146
class store_key_const_item :public store_key_item
124
147
{
125
148
  bool inited;
126
 
 
127
149
public:
128
150
  store_key_const_item(Session *session, Field *to_field_arg, unsigned char *ptr,
129
 
                       unsigned char *null_ptr_arg, uint32_t length,
130
 
                       Item *item_arg) :
131
 
    store_key_item(session, to_field_arg,ptr,
132
 
                   null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
133
 
                   &err : (unsigned char*) 0, length, item_arg), inited(0)
 
151
                       unsigned char *null_ptr_arg, uint32_t length,
 
152
                       Item *item_arg)
 
153
    :store_key_item(session, to_field_arg,ptr,
 
154
                    null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
 
155
                    &err : (unsigned char*) 0, length, item_arg), inited(0)
134
156
  {
135
157
  }
136
158
  const char *name() const { return "const"; }