~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/varstring.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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
 
                  const CHARSET_INFO * const cs);
55
 
  Field_varstring(uint32_t len_arg,
56
 
                  bool maybe_null_arg,
57
 
                  const char *field_name_arg,
58
 
                  const CHARSET_INFO * const cs);
59
 
 
60
 
  enum_field_types type() const { return DRIZZLE_TYPE_VARCHAR; }
61
 
  enum ha_base_keytype key_type() const;
62
 
  bool zero_pack() const { return 0; }
63
 
  int  reset(void) { memset(ptr, 0, field_length+length_bytes); return 0; }
64
 
  uint32_t pack_length() const { return (uint32_t) field_length+length_bytes; }
65
 
  uint32_t pack_length_no_ptr() const { return length_bytes; }
66
 
  uint32_t key_length() const { return (uint32_t) field_length; }
67
 
  uint32_t sort_length() const
68
 
  {
69
 
    return (uint32_t) field_length + (field_charset == &my_charset_bin ?
70
 
                                      length_bytes : 0);
71
 
  }
72
 
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
73
 
 
74
 
 
75
 
  int  store(int64_t nr, bool unsigned_val);
76
 
  int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
77
 
  double val_real(void);
78
 
  int64_t val_int(void);
79
 
  String *val_str(String*,String *);
80
 
  inline String *val_str(String *str) { return val_str(str, str); }
81
 
  my_decimal *val_decimal(my_decimal *);
82
 
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
83
 
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
84
 
  int cmp(const unsigned char *a,const unsigned char *b)
85
 
  {
86
 
    return cmp_max(a, b, UINT32_MAX);
87
 
  }
88
 
  void sort_string(unsigned char *buff,uint32_t length);
89
 
  uint32_t get_key_image(unsigned char *buff,uint32_t length);
90
 
  uint32_t get_key_image(std::basic_string <unsigned char> &buff, uint32_t length);
91
 
  void set_key_image(const unsigned char *buff,uint32_t length);
92
 
  void sql_type(String &str) const;
93
 
  virtual unsigned char *pack(unsigned char *to,
94
 
                              const unsigned char *from,
95
 
                              uint32_t max_length,
96
 
                              bool low_byte_first);
97
 
 
98
 
  virtual const unsigned char *unpack(unsigned char* to,
99
 
                                      const unsigned char *from,
100
 
                                      uint32_t param_data,
101
 
                                      bool low_byte_first);
102
 
 
103
 
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
104
 
  int key_cmp(const unsigned char *,const unsigned char*);
105
 
  int key_cmp(const unsigned char *str, uint32_t length);
106
 
  uint32_t max_packed_col_length(uint32_t max_length);
107
 
  uint32_t used_length();
108
 
  uint32_t size_of() const { return sizeof(*this); }
109
 
  enum_field_types real_type() const { return DRIZZLE_TYPE_VARCHAR; }
110
 
  bool has_charset(void) const
111
 
  { return charset() == &my_charset_bin ? false : true; }
112
 
  Field *new_field(memory::Root *root, Table *new_table, bool keep_type);
113
 
  Field *new_key_field(memory::Root *root, Table *new_table,
114
 
                       unsigned char *new_ptr, unsigned char *new_null_ptr,
115
 
                       uint32_t new_null_bit);
116
 
};
117
 
 
118
 
} /* namespace drizzled */
119
 
 
120
 
#endif /* DRIZZLED_FIELD_VARSTRING_H */
121