~drizzle-trunk/drizzle/development

466 by Monty Taylor
Fixed modelines... these files are c++.
1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 MySQL
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; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
21
#pragma once
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
22
1034.1.3 by Brian Aker
Collapse field classes (this does change enum/time decimal conversion
23
#include <drizzled/field/str.h>
2281.5.1 by Muhammad Umair
Merged charset declarations of global_charset_info.h and charset_info.h into charset.h header file.
24
#include <drizzled/charset.h>
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
25
#include <string>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
26
#include <drizzled/visibility.h>
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
27
2281.4.6 by Olaf van der Spek
Return void
28
namespace drizzled {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
29
1055.2.5 by Jay Pipes
Removal of dead Field::image_type and st_key_part::image_type member variables. Legacy from geometry MyISAM types...
30
/**
31
 * Class representing a BLOB data type column
32
 */
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
33
class DRIZZLED_API Field_blob :
34
  public Field_str
35
{
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
36
protected:
37
  String value;				// For temporaries
38
public:
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
39
40
  using Field::store;
41
  using Field::cmp;
42
  using Field::pack;
43
  using Field::unpack;
44
  using Field::val_int;
45
  using Field::val_str;
46
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
47
  Field_blob(unsigned char *ptr_arg,
48
             unsigned char *null_ptr_arg,
49
             unsigned char null_bit_arg,
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
50
             const char *field_name_arg,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
51
             TableShare *share,
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
52
             const charset_info_st * const cs);
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
53
  Field_blob(uint32_t len_arg,
54
             bool maybe_null_arg,
55
             const char *field_name_arg,
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
56
             const charset_info_st * const cs)
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
57
    :Field_str((unsigned char*) NULL,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
58
               len_arg,
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
59
               maybe_null_arg ? (unsigned char *) "": 0,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
60
               0,
61
               field_name_arg,
1267.1.4 by Stewart Smith
remove last bits of packlength from Field_blob, leaving only support for 4 byte length for blobs (not 1, not 2 and certainly not 3).
62
               cs)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
63
  {
64
    flags|= BLOB_FLAG;
65
  }
1267.1.2 by Stewart Smith
remove Field_blob constructor that only takes packlength as argument. It's never even called
66
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
67
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
68
  enum ha_base_keytype key_type() const
69
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
70
  int  store(const char *to,uint32_t length,
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
71
             const charset_info_st * const charset);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
72
  int  store(double nr);
73
  int  store(int64_t nr, bool unsigned_val);
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
74
2181.2.1 by Brian Aker
Protect all of the val_* methods from modification.
75
  double val_real(void) const;
76
  int64_t val_int(void) const;
77
  String *val_str(String*,String *) const;
78
  type::Decimal *val_decimal(type::Decimal *) const;
481 by Brian Aker
Remove all of uchar.
79
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
80
  int cmp(const unsigned char *a,const unsigned char *b)
365.2.6 by Monty Taylor
Undid some stupid int->int16_t conversions.
81
    { return cmp_max(a, b, UINT32_MAX); }
481 by Brian Aker
Remove all of uchar.
82
  int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
83
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
84
  int key_cmp(const unsigned char *,const unsigned char*);
482 by Brian Aker
Remove uint.
85
  int key_cmp(const unsigned char *str, uint32_t length);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
86
  uint32_t key_length() const { return 0; }
482 by Brian Aker
Remove uint.
87
  void sort_string(unsigned char *buff,uint32_t length);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
88
  uint32_t pack_length() const;
89
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
90
91
  /**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
92
     Return the packed length without the pointer size added.
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
93
94
     This is used to determine the size of the actual data in the row
95
     buffer.
96
97
     @returns The length of the raw data itself without the pointer.
98
  */
99
  uint32_t pack_length_no_ptr() const
1267.1.4 by Stewart Smith
remove last bits of packlength from Field_blob, leaving only support for 4 byte length for blobs (not 1, not 2 and certainly not 3).
100
  { return (uint32_t) (sizeof(uint32_t)); }
1267.1.5 by Stewart Smith
merge trunk
101
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
102
  uint32_t sort_length() const;
103
  virtual uint32_t max_data_length() const
104
  {
1267.1.4 by Stewart Smith
remove last bits of packlength from Field_blob, leaving only support for 4 byte length for blobs (not 1, not 2 and certainly not 3).
105
    return (uint32_t) (((uint64_t) 1 << 32) -1);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
106
  }
1267.1.4 by Stewart Smith
remove last bits of packlength from Field_blob, leaving only support for 4 byte length for blobs (not 1, not 2 and certainly not 3).
107
  int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
108
  void reset_fields() { memset(&value, 0, sizeof(value)); }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
109
#ifndef WORDS_BIGENDIAN
110
  static
111
#endif
1267.1.4 by Stewart Smith
remove last bits of packlength from Field_blob, leaving only support for 4 byte length for blobs (not 1, not 2 and certainly not 3).
112
  void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
113
  void store_length(unsigned char *i_ptr, uint32_t i_number);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
114
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
115
  inline void store_length(uint32_t number)
116
  {
1267.1.4 by Stewart Smith
remove last bits of packlength from Field_blob, leaving only support for 4 byte length for blobs (not 1, not 2 and certainly not 3).
117
    store_length(ptr, number);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
118
  }
119
120
  /**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
121
     Return the packed length plus the length of the data.
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
122
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
123
     This is used to determine the size of the data plus the
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
124
     packed length portion in the row data.
125
126
     @returns The length in the row plus the size of the data.
127
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
128
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
129
2181.2.1 by Brian Aker
Protect all of the val_* methods from modification.
130
  DRIZZLED_API uint32_t get_length(uint32_t row_offset= 0) const;
131
  DRIZZLED_API uint32_t get_length(const unsigned char *ptr, bool low_byte_first) const;
132
  DRIZZLED_API uint32_t get_length(const unsigned char *ptr_arg) const;
481 by Brian Aker
Remove all of uchar.
133
  void put_length(unsigned char *pos, uint32_t length);
2313.3.3 by Olaf van der Spek
Refactor
134
  inline unsigned char* get_ptr() const
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
135
    {
2313.3.3 by Olaf van der Spek
Refactor
136
      unsigned char* str;
137
      memcpy(&str, ptr + sizeof(uint32_t), sizeof(unsigned char*));
138
      return str;
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
139
    }
481 by Brian Aker
Remove all of uchar.
140
  inline void set_ptr(unsigned char *length, unsigned char *data)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
141
    {
1267.1.4 by Stewart Smith
remove last bits of packlength from Field_blob, leaving only support for 4 byte length for blobs (not 1, not 2 and certainly not 3).
142
      memcpy(ptr,length,sizeof(uint32_t));
143
      memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
144
    }
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
145
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
146
    {
481 by Brian Aker
Remove all of uchar.
147
      unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
1267.1.4 by Stewart Smith
remove last bits of packlength from Field_blob, leaving only support for 4 byte length for blobs (not 1, not 2 and certainly not 3).
148
      store_length(ptr_ofs, length);
149
      memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
150
    }
481 by Brian Aker
Remove all of uchar.
151
  inline void set_ptr(uint32_t length, unsigned char *data)
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
152
    {
153
      set_ptr_offset(0, length, data);
154
    }
1055.2.5 by Jay Pipes
Removal of dead Field::image_type and st_key_part::image_type member variables. Legacy from geometry MyISAM types...
155
  uint32_t get_key_image(unsigned char *buff,uint32_t length);
156
  uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length);
482 by Brian Aker
Remove uint.
157
  void set_key_image(const unsigned char *buff,uint32_t length);
2313.3.1 by Olaf van der Spek
Return void
158
  inline void copy()
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
159
  {
2385.2.6 by Olaf van der Spek
Refactor
160
    value.copy((char*)get_ptr(), get_length(), charset());
161
    char* tmp= value.ptr();
162
    memcpy(ptr + sizeof(uint32_t), &tmp, sizeof(char*));
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
163
  }
2385.2.6 by Olaf van der Spek
Refactor
164
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
165
  unsigned char *pack_key(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
166
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from, uint32_t , bool low_byte_first);
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
167
  void free() { value.free(); }
168
  friend int field_conv(Field *to,Field *from);
482 by Brian Aker
Remove uint.
169
  uint32_t size_of() const { return sizeof(*this); }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
170
  bool has_charset(void) const
2385.2.6 by Olaf van der Spek
Refactor
171
  { return charset() != &my_charset_bin; }
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
172
  uint32_t max_display_length();
173
};
174
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
175
} /* namespace drizzled */
176
173.1.2 by Toru Maesaka
forgot to bzr-add new files in the previous push
177