1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
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.
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.
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
21
#ifndef DRIZZLE_SERVER_FIELD_VARSTRING
22
#define DRIZZLE_SERVER_FIELD_VARSTRING
24
#include "mysql_priv.h"
26
class Field_varstring :public Field_longstr {
29
The maximum space available in a Field_varstring, in bytes. See
32
static const uint MAX_SIZE;
33
/* Store number of bytes used to store length (1 or 2) */
35
Field_varstring(uchar *ptr_arg,
36
uint32 len_arg, uint length_bytes_arg,
37
uchar *null_ptr_arg, uchar null_bit_arg,
38
enum utype unireg_check_arg, const char *field_name_arg,
39
TABLE_SHARE *share, CHARSET_INFO *cs)
40
:Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
41
unireg_check_arg, field_name_arg, cs),
42
length_bytes(length_bytes_arg)
44
share->varchar_fields++;
46
Field_varstring(uint32 len_arg,bool maybe_null_arg,
47
const char *field_name_arg,
48
TABLE_SHARE *share, CHARSET_INFO *cs)
49
:Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
50
NONE, field_name_arg, cs),
51
length_bytes(len_arg < 256 ? 1 :2)
53
share->varchar_fields++;
56
enum_field_types type() const { return MYSQL_TYPE_VARCHAR; }
57
enum ha_base_keytype key_type() const;
58
uint row_pack_length() { return field_length; }
59
bool zero_pack() const { return 0; }
60
int reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
61
uint32 pack_length() const { return (uint32) field_length+length_bytes; }
62
uint32 key_length() const { return (uint32) field_length; }
63
uint32 sort_length() const
65
return (uint32) field_length + (field_charset == &my_charset_bin ?
68
int store(const char *to,uint length,CHARSET_INFO *charset);
69
int store(int64_t nr, bool unsigned_val);
70
int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
71
double val_real(void);
72
int64_t val_int(void);
73
String *val_str(String*,String *);
74
my_decimal *val_decimal(my_decimal *);
75
int cmp_max(const uchar *, const uchar *, uint max_length);
76
int cmp(const uchar *a,const uchar *b)
78
return cmp_max(a, b, ~0L);
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);
83
void sql_type(String &str) const;
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 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);
101
uint32 data_length();
102
uint32 used_length();
103
uint size_of() const { return sizeof(*this); }
104
enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
105
bool has_charset(void) const
106
{ return charset() == &my_charset_bin ? false : true; }
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,
111
uint is_equal(Create_field *new_field);
112
void hash(ulong *nr, ulong *nr2);
114
int do_save_field_metadata(uchar *first_byte);