~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/varstring.h

Renamed strings to mystrings, for include/lib naming consistency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 MySQL
21
21
#ifndef DRIZZLE_SERVER_FIELD_VARSTRING
22
22
#define DRIZZLE_SERVER_FIELD_VARSTRING
23
23
 
 
24
#include "mysql_priv.h"
 
25
 
24
26
class Field_varstring :public Field_longstr {
25
27
public:
26
28
  /*
27
29
    The maximum space available in a Field_varstring, in bytes. See
28
30
    length_bytes.
29
31
  */
30
 
  static const uint32_t MAX_SIZE;
 
32
  static const uint MAX_SIZE;
31
33
  /* Store number of bytes used to store length (1 or 2) */
32
34
  uint32_t length_bytes;
33
 
  Field_varstring(unsigned char *ptr_arg,
34
 
                  uint32_t len_arg, uint32_t length_bytes_arg,
35
 
                  unsigned char *null_ptr_arg, unsigned char null_bit_arg,
 
35
  Field_varstring(uchar *ptr_arg,
 
36
                  uint32_t len_arg, uint length_bytes_arg,
 
37
                  uchar *null_ptr_arg, uchar null_bit_arg,
36
38
                  enum utype unireg_check_arg, const char *field_name_arg,
37
 
                  TABLE_SHARE *share, const CHARSET_INFO * const cs)
 
39
                  TABLE_SHARE *share, CHARSET_INFO *cs)
38
40
    :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
39
41
                   unireg_check_arg, field_name_arg, cs),
40
42
     length_bytes(length_bytes_arg)
43
45
  }
44
46
  Field_varstring(uint32_t len_arg,bool maybe_null_arg,
45
47
                  const char *field_name_arg,
46
 
                  TABLE_SHARE *share, const CHARSET_INFO * const cs)
47
 
    :Field_longstr((unsigned char*) 0,len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
 
48
                  TABLE_SHARE *share, CHARSET_INFO *cs)
 
49
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
48
50
                   NONE, field_name_arg, cs),
49
51
     length_bytes(len_arg < 256 ? 1 :2)
50
52
  {
53
55
 
54
56
  enum_field_types type() const { return DRIZZLE_TYPE_VARCHAR; }
55
57
  enum ha_base_keytype key_type() const;
56
 
  uint32_t row_pack_length() { return field_length; }
 
58
  uint row_pack_length() { return field_length; }
57
59
  bool zero_pack() const { return 0; }
58
 
  int  reset(void) { memset(ptr, 0, field_length+length_bytes); return 0; }
 
60
  int  reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
59
61
  uint32_t pack_length() const { return (uint32_t) field_length+length_bytes; }
60
62
  uint32_t key_length() const { return (uint32_t) field_length; }
61
63
  uint32_t sort_length() const
63
65
    return (uint32_t) field_length + (field_charset == &my_charset_bin ?
64
66
                                    length_bytes : 0);
65
67
  }
66
 
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
 
68
  int  store(const char *to,uint length,CHARSET_INFO *charset);
67
69
  int  store(int64_t nr, bool unsigned_val);
68
70
  int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
69
71
  double val_real(void);
70
72
  int64_t val_int(void);
71
73
  String *val_str(String*,String *);
72
74
  my_decimal *val_decimal(my_decimal *);
73
 
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
74
 
  int cmp(const unsigned char *a,const unsigned char *b)
 
75
  int cmp_max(const uchar *, const uchar *, uint max_length);
 
76
  int cmp(const uchar *a,const uchar *b)
75
77
  {
76
 
    return cmp_max(a, b, UINT32_MAX);
 
78
    return cmp_max(a, b, ~0L);
77
79
  }
78
 
  void sort_string(unsigned char *buff,uint32_t length);
79
 
  uint32_t get_key_image(unsigned char *buff,uint32_t length, imagetype type);
80
 
  void set_key_image(const unsigned char *buff,uint32_t length);
 
80
  void sort_string(uchar *buff,uint length);
 
81
  uint get_key_image(uchar *buff,uint length, imagetype type);
 
82
  void set_key_image(const uchar *buff,uint length);
81
83
  void sql_type(String &str) const;
82
 
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
83
 
                      uint32_t max_length, bool low_byte_first);
84
 
  unsigned char *pack_key(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first);
85
 
  unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
86
 
                                 uint32_t max_length, bool low_byte_first);
87
 
  virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
88
 
                              uint32_t param_data, bool low_byte_first);
89
 
  const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
90
 
                          uint32_t max_length, bool low_byte_first);
91
 
  int pack_cmp(const unsigned char *a, const unsigned char *b, uint32_t key_length,
92
 
               bool insert_or_update);
93
 
  int pack_cmp(const unsigned char *b, uint32_t key_length,bool insert_or_update);
94
 
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
95
 
  int key_cmp(const unsigned char *,const unsigned char*);
96
 
  int key_cmp(const unsigned char *str, uint32_t length);
97
 
  uint32_t packed_col_length(const unsigned char *to, uint32_t length);
98
 
  uint32_t max_packed_col_length(uint32_t max_length);
 
84
  virtual uchar *pack(uchar *to, const uchar *from,
 
85
                      uint max_length, bool low_byte_first);
 
86
  uchar *pack_key(uchar *to, const uchar *from, uint max_length, bool low_byte_first);
 
87
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
88
                                 uint max_length, bool low_byte_first);
 
89
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
90
                              uint param_data, bool low_byte_first);
 
91
  const uchar *unpack_key(uchar* to, const uchar *from,
 
92
                          uint max_length, bool low_byte_first);
 
93
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
 
94
               my_bool insert_or_update);
 
95
  int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
 
96
  int cmp_binary(const uchar *a,const uchar *b, uint32_t max_length=~0L);
 
97
  int key_cmp(const uchar *,const uchar*);
 
98
  int key_cmp(const uchar *str, uint length);
 
99
  uint packed_col_length(const uchar *to, uint length);
 
100
  uint max_packed_col_length(uint max_length);
99
101
  uint32_t data_length();
100
102
  uint32_t used_length();
101
 
  uint32_t size_of() const { return sizeof(*this); }
 
103
  uint size_of() const { return sizeof(*this); }
102
104
  enum_field_types real_type() const { return DRIZZLE_TYPE_VARCHAR; }
103
105
  bool has_charset(void) const
104
106
  { return charset() == &my_charset_bin ? false : true; }
105
 
  Field *new_field(MEM_ROOT *root, Table *new_table, bool keep_type);
106
 
  Field *new_key_field(MEM_ROOT *root, Table *new_table,
107
 
                       unsigned char *new_ptr, unsigned char *new_null_ptr,
108
 
                       uint32_t new_null_bit);
109
 
  uint32_t is_equal(Create_field *new_field);
110
 
  void hash(uint32_t *nr, uint32_t *nr2);
 
107
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
 
108
  Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
 
109
                       uchar *new_ptr, uchar *new_null_ptr,
 
110
                       uint new_null_bit);
 
111
  uint is_equal(Create_field *new_field);
 
112
  void hash(ulong *nr, ulong *nr2);
111
113
private:
112
 
  int do_save_field_metadata(unsigned char *first_byte);
 
114
  int do_save_field_metadata(uchar *first_byte);
113
115
};
114
116
 
115
117
#endif