~drizzle-trunk/drizzle/development

2154.2.6 by Brian Aker
Merge in small cleanups.
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
2154.2.6 by Brian Aker
Merge in small cleanups.
21
22
#include <drizzled/field/varstring.h>
23
#include <drizzled/session.h>
24
#include <drizzled/stored_key.h>
2241.2.14 by Olaf van der Spek
Refactor
25
#include <drizzled/table.h>
2154.2.6 by Brian Aker
Merge in small cleanups.
26
2241.2.14 by Olaf van der Spek
Refactor
27
namespace drizzled {
2154.2.6 by Brian Aker
Merge in small cleanups.
28
29
StoredKey::StoredKey(Session *session,
30
                     Field *field_arg, 
31
                     unsigned char *ptr,
32
                     unsigned char *null, 
33
                     uint32_t length) :
34
  null_key(0), 
35
  null_ptr(null), 
36
  err(0)
37
  {
38
    if (field_arg->type() == DRIZZLE_TYPE_BLOB)
39
    {
40
      /*
41
        Key segments are always packed with a 2 byte length prefix.
42
        See mi_rkey for details.
43
      */
44
      to_field= new Field_varstring(ptr,
45
                                    length,
46
                                    2,
47
                                    null,
48
                                    1,
49
                                    field_arg->field_name,
50
                                    field_arg->charset());
51
      to_field->init(field_arg->getTable());
52
    }
53
    else
54
    {
55
      to_field= field_arg->new_key_field(session->mem_root, field_arg->getTable(),
56
                                         ptr, null, 1);
57
    }
58
59
    to_field->setWriteSet();
60
  }
61
62
StoredKey::store_key_result StoredKey::copy()
63
{
64
  store_key_result result;
65
  Session *session= to_field->getTable()->in_use;
66
  enum_check_fields saved_count_cuted_fields= session->count_cuted_fields;
67
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
68
  result= copy_inner();
69
  session->count_cuted_fields= saved_count_cuted_fields;
70
71
  return result;
72
}
73
74
} /* namespace drizzled */