drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
varstring.h
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#pragma once
22
23#include <drizzled/field/str.h>
24#include <string>
25
26namespace drizzled
27{
28
29class Field_varstring :public Field_str {
30public:
31
32 using Field::store;
33 using Field::pack;
34 using Field::unpack;
35 using Field::val_int;
36 using Field::val_str;
37
38 /*
39 The maximum space available in a Field_varstring, in bytes. See
40 length_bytes.
41 */
42 static const uint32_t MAX_SIZE;
43private:
44 /* Store number of bytes used to store length (1 or 2) */
45 uint32_t length_bytes;
46public:
47 Field_varstring(unsigned char *ptr_arg,
48 uint32_t len_arg,
49 uint32_t length_bytes_arg,
50 unsigned char *null_ptr_arg,
51 unsigned char null_bit_arg,
52 const char *field_name_arg,
53 const charset_info_st * const cs);
54 Field_varstring(uint32_t len_arg,
55 bool maybe_null_arg,
56 const char *field_name_arg,
57 const charset_info_st * const cs);
58
59 enum_field_types type() const { return DRIZZLE_TYPE_VARCHAR; }
60 enum ha_base_keytype key_type() const;
61 bool zero_pack() const { return 0; }
62 int reset(void) { memset(ptr, 0, field_length+length_bytes); return 0; }
63 uint32_t pack_length() const { return (uint32_t) field_length+length_bytes; }
64 uint32_t pack_length_no_ptr() const { return length_bytes; }
65 uint32_t key_length() const { return (uint32_t) field_length; }
66 uint32_t sort_length() const
67 {
68 return (uint32_t) field_length + (field_charset == &my_charset_bin ?
69 length_bytes : 0);
70 }
71 int store(const char *to,uint32_t length, const charset_info_st * const charset);
72
73
74 int store(int64_t nr, bool unsigned_val);
75 int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
76 double val_real(void) const;
77 int64_t val_int(void) const;
78 String *val_str(String*,String *) const;
79 inline String *val_str(String *str) { return val_str(str, str); }
80 type::Decimal *val_decimal(type::Decimal *) const;
81 int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
82 inline int cmp(const unsigned char *str) { return cmp(ptr,str); }
83 int cmp(const unsigned char *a,const unsigned char *b)
84 {
85 return cmp_max(a, b, UINT32_MAX);
86 }
87 void sort_string(unsigned char *buff,uint32_t length);
88 uint32_t get_key_image(unsigned char *buff,uint32_t length);
89 uint32_t get_key_image(std::basic_string <unsigned char> &buff, uint32_t length);
90 void set_key_image(const unsigned char *buff,uint32_t length);
91 virtual unsigned char *pack(unsigned char *to,
92 const unsigned char *from,
93 uint32_t max_length,
94 bool low_byte_first);
95
96 virtual const unsigned char *unpack(unsigned char* to,
97 const unsigned char *from,
98 uint32_t param_data,
99 bool low_byte_first);
100
101 int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
102 int key_cmp(const unsigned char *,const unsigned char*);
103 int key_cmp(const unsigned char *str, uint32_t length);
104 uint32_t max_packed_col_length(uint32_t max_length);
105 uint32_t used_length();
106 uint32_t size_of() const { return sizeof(*this); }
107 enum_field_types real_type() const { return DRIZZLE_TYPE_VARCHAR; }
108 bool has_charset(void) const
109 { return charset() == &my_charset_bin ? false : true; }
110 Field *new_field(memory::Root *root, Table *new_table, bool keep_type);
111 Field *new_key_field(memory::Root *root, Table *new_table,
112 unsigned char *new_ptr, unsigned char *new_null_ptr,
113 uint32_t new_null_bit);
114};
115
116} /* namespace drizzled */
117
118
int store(double nr)
Definition str.cc:124
uint32_t pack_length() const
Definition varstring.h:63
int store(double nr)
Definition varstring.h:75
uint32_t get_key_image(unsigned char *buff, uint32_t length)
Definition varstring.cc:386
int key_cmp(const unsigned char *, const unsigned char *)
Definition varstring.cc:240
virtual unsigned char * pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first)
Definition varstring.cc:292
virtual const unsigned char * unpack(unsigned char *to, const unsigned char *from, uint32_t param_data, bool low_byte_first)
Definition varstring.cc:329
unsigned char * ptr
Definition field.h:73
virtual const unsigned char * unpack(unsigned char *to, const unsigned char *from, uint32_t param_data, bool low_byte_first)
Definition field.cc:968
virtual unsigned char * pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool low_byte_first)
Definition field.cc:955
Field(unsigned char *ptr_arg, uint32_t length_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg, utype unireg_check_arg, const char *field_name_arg)
This is used as a table name when the table structure is not set up.
Definition field.cc:892
uint32_t field_length
Definition field.h:131
TODO: Rename this file - func.h is stupid.