~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/varstring.h

  • Committer: Brian Aker
  • Date: 2008-07-08 16:17:31 UTC
  • Revision ID: brian@tangent.org-20080708161731-io36j7igglok79py
DATE cleanup.

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 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
 
 
21
 
#ifndef DRIZZLED_FIELD_VARSTRING_H
22
 
#define DRIZZLED_FIELD_VARSTRING_H
23
 
 
24
 
#include <drizzled/field/str.h>
25
 
#include <string>
26
 
 
27
 
namespace drizzled
28
 
{
29
 
 
30
 
class Field_varstring :public Field_str {
31
 
public:
32
 
 
33
 
  using Field::store;
34
 
  using Field::pack;
35
 
  using Field::unpack;
36
 
  using Field::val_int;
37
 
  using Field::val_str;
38
 
 
39
 
  /*
40
 
    The maximum space available in a Field_varstring, in bytes. See
41
 
    length_bytes.
42
 
  */
43
 
  static const uint32_t MAX_SIZE;
44
 
private:
45
 
  /* Store number of bytes used to store length (1 or 2) */
46
 
  uint32_t length_bytes;
47
 
public:
48
 
  Field_varstring(unsigned char *ptr_arg,
49
 
                  uint32_t len_arg,
50
 
                  uint32_t length_bytes_arg,
51
 
                  unsigned char *null_ptr_arg,
52
 
                  unsigned char null_bit_arg,
53
 
                  const char *field_name_arg,
54
 
                  TableShare *share,
55
 
                  const CHARSET_INFO * const cs);
56
 
  Field_varstring(uint32_t len_arg,
57
 
                  bool maybe_null_arg,
58
 
                  const char *field_name_arg,
59
 
                  TableShare *share,
60
 
                  const CHARSET_INFO * const cs);
61
 
 
62
 
  enum_field_types type() const { return DRIZZLE_TYPE_VARCHAR; }
63
 
  enum ha_base_keytype key_type() const;
64
 
  bool zero_pack() const { return 0; }
65
 
  int  reset(void) { memset(ptr, 0, field_length+length_bytes); return 0; }
66
 
  uint32_t pack_length() const { return (uint32_t) field_length+length_bytes; }
67
 
  uint32_t pack_length_no_ptr() const { return length_bytes; }
68
 
  uint32_t key_length() const { return (uint32_t) field_length; }
69
 
  uint32_t sort_length() const
70
 
  {
71
 
    return (uint32_t) field_length + (field_charset == &my_charset_bin ?
72
 
                                      length_bytes : 0);
73
 
  }
74
 
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
75
 
 
76
 
 
77
 
  int  store(int64_t nr, bool unsigned_val);
78
 
  int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
79
 
  double val_real(void);
80
 
  int64_t val_int(void);
81
 
  String *val_str(String*,String *);
82
 
  inline String *val_str(String *str) { return val_str(str, str); }
83
 
  my_decimal *val_decimal(my_decimal *);
84
 
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
85
 
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
86
 
  int cmp(const unsigned char *a,const unsigned char *b)
87
 
  {
88
 
    return cmp_max(a, b, UINT32_MAX);
89
 
  }
90
 
  void sort_string(unsigned char *buff,uint32_t length);
91
 
  uint32_t get_key_image(unsigned char *buff,uint32_t length);
92
 
  uint32_t get_key_image(std::basic_string <unsigned char> &buff, uint32_t length);
93
 
  void set_key_image(const unsigned char *buff,uint32_t length);
94
 
  void sql_type(String &str) const;
95
 
  virtual unsigned char *pack(unsigned char *to,
96
 
                              const unsigned char *from,
97
 
                              uint32_t max_length,
98
 
                              bool low_byte_first);
99
 
 
100
 
  virtual const unsigned char *unpack(unsigned char* to,
101
 
                                      const unsigned char *from,
102
 
                                      uint32_t param_data,
103
 
                                      bool low_byte_first);
104
 
 
105
 
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
106
 
  int key_cmp(const unsigned char *,const unsigned char*);
107
 
  int key_cmp(const unsigned char *str, uint32_t length);
108
 
  uint32_t max_packed_col_length(uint32_t max_length);
109
 
  uint32_t used_length();
110
 
  uint32_t size_of() const { return sizeof(*this); }
111
 
  enum_field_types real_type() const { return DRIZZLE_TYPE_VARCHAR; }
112
 
  bool has_charset(void) const
113
 
  { return charset() == &my_charset_bin ? false : true; }
114
 
  Field *new_field(memory::Root *root, Table *new_table, bool keep_type);
115
 
  Field *new_key_field(memory::Root *root, Table *new_table,
116
 
                       unsigned char *new_ptr, unsigned char *new_null_ptr,
117
 
                       uint32_t new_null_bit);
118
 
};
119
 
 
120
 
} /* namespace drizzled */
121
 
 
122
 
#endif /* DRIZZLED_FIELD_VARSTRING_H */
123