17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_SQL_STRING_H
21
#define DRIZZLED_SQL_STRING_H
20
#ifndef DRIZZLE_SERVER_SQL_STRING_H
21
#define DRIZZLE_SERVER_SQL_STRING_H
23
23
/* This file is originally from the mysql distribution. Coded by monty */
27
#define NOT_FIXED_DEC 31
25
30
#include <drizzled/common.h>
32
#define NOT_FIXED_DEC (uint8_t)31
31
#include <mysys/iocache.h>
40
extern String my_empty_string;
41
extern const String my_null_string;
42
namespace memory { class Root; }
43
typedef struct charset_info_st CHARSET_INFO;
45
std::string String_to_std_string(String const& s);
46
String* set_String_from_std_string(String* s, std::string const& cs);
48
int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
49
int stringcmp(const String *a,const String *b);
50
String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
51
uint32_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
52
char *to, uint32_t to_length,
53
const CHARSET_INFO * const from_cs,
54
const char *from, uint32_t from_length,
56
const char **well_formed_error_pos,
57
const char **cannot_convert_error_pos,
58
const char **from_end_pos);
37
#if defined(__cplusplus)
41
int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
42
int stringcmp(const String *a,const String *b);
43
String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
44
uint32_t copy_and_convert(char *to, uint32_t to_length,
45
const CHARSET_INFO * const to_cs,
46
const char *from, uint32_t from_length,
47
const CHARSET_INFO * const from_cs,
49
uint32_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
50
char *to, uint32_t to_length,
51
const CHARSET_INFO * const from_cs,
52
const char *from, uint32_t from_length,
54
const char **well_formed_error_pos,
55
const char **cannot_convert_error_pos,
56
const char **from_end_pos);
57
size_t my_copy_with_hex_escaping(const CHARSET_INFO * const cs,
58
char *dst, size_t dstlen,
59
const char *src, size_t srclen);
61
#if defined(__cplusplus)
66
70
const CHARSET_INFO *str_charset;
70
String(uint32_t length_arg);
71
String(const char *str, const CHARSET_INFO * const cs);
72
String(const char *str, uint32_t len, const CHARSET_INFO * const cs);
73
String(char *str, uint32_t len, const CHARSET_INFO * const cs);
74
String(const String &str);
76
static void *operator new(size_t size, memory::Root *mem_root);
75
Ptr=0; str_length=Alloced_length=0; alloced=0;
76
str_charset= &my_charset_bin;
78
String(uint32_t length_arg)
80
alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
81
str_charset= &my_charset_bin;
83
String(const char *str, const CHARSET_INFO * const cs)
85
Ptr=(char*) str; str_length=(uint32_t) strlen(str); Alloced_length=0; alloced=0;
88
String(const char *str,uint32_t len, const CHARSET_INFO * const cs)
90
Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
93
String(char *str,uint32_t len, const CHARSET_INFO * const cs)
95
Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
98
String(const String &str)
100
Ptr=str.Ptr ; str_length=str.str_length ;
101
Alloced_length=str.Alloced_length; alloced=0;
102
str_charset=str.str_charset;
104
static void *operator new(size_t size, MEM_ROOT *mem_root)
105
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
77
106
static void operator delete(void *, size_t)
79
static void operator delete(void *, memory::Root *)
107
{ TRASH(ptr_arg, size); }
108
static void operator delete(void *, MEM_ROOT *)
109
{ /* never called */ }
110
~String() { free(); }
83
112
inline void set_charset(const CHARSET_INFO * const charset_arg)
84
113
{ str_charset= charset_arg; }
114
140
(void) realloc(str_length);
119
if (Ptr && str_length < Alloced_length)
122
(void) realloc(str_length);
125
143
void append_identifier(const char *name, uint32_t length);
127
145
void set(String &str,uint32_t offset,uint32_t arg_length)
129
147
assert(&str != this);
131
Ptr= str.ptr()+offset; str_length=arg_length; alloced=0;
149
Ptr=(char*) str.ptr()+offset; str_length=arg_length; alloced=0;
132
150
if (str.Alloced_length)
133
151
Alloced_length=str.Alloced_length-offset;
138
156
inline void set(char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
141
Ptr= str; str_length=Alloced_length=arg_length ; alloced=0;
159
Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0;
144
162
inline void set(const char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
147
Ptr= const_cast<char*>(str);
148
str_length=arg_length; Alloced_length=0 ; alloced=0;
165
Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
151
168
bool set_ascii(const char *str, uint32_t arg_length);
156
Ptr= str; str_length= Alloced_length= arg_length;
173
Ptr=(char*) str; str_length=Alloced_length=arg_length;
160
177
bool set_int(int64_t num, bool unsigned_flag, const CHARSET_INFO * const cs);
161
178
bool set(int64_t num, const CHARSET_INFO * const cs)
162
179
{ return set_int(num, false, cs); }
163
180
bool set(uint64_t num, const CHARSET_INFO * const cs)
164
{ return set_int(static_cast<int64_t>(num), true, cs); }
181
{ return set_int((int64_t)num, true, cs); }
165
182
bool set_real(double num,uint32_t decimals, const CHARSET_INFO * const cs);
250
267
static bool needs_conversion(uint32_t arg_length,
251
268
const CHARSET_INFO * const cs_from, const CHARSET_INFO * const cs_to,
252
269
uint32_t *offset);
270
bool copy_aligned(const char *s, uint32_t arg_length, uint32_t offset,
271
const CHARSET_INFO * const cs);
253
272
bool set_or_copy_aligned(const char *s, uint32_t arg_length, const CHARSET_INFO * const cs);
254
273
bool copy(const char*s,uint32_t arg_length, const CHARSET_INFO * const csfrom,
255
274
const CHARSET_INFO * const csto, uint32_t *errors);
257
276
bool append(const char *s);
258
277
bool append(const char *s,uint32_t arg_length);
259
278
bool append(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs);
279
bool append(IO_CACHE* file, uint32_t arg_length);
260
280
bool append_with_prefill(const char *s, uint32_t arg_length,
261
281
uint32_t full_length, char fill_char);
262
282
int strstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
294
315
q_*** methods writes values of parameters itself
295
316
qs_*** methods writes string representation of value
297
void q_append(const char c);
298
void q_append(const uint32_t n);
299
void q_append(double d);
300
void q_append(double *d);
301
void q_append(const char *data, uint32_t data_len);
302
void write_at_position(int position, uint32_t value);
318
void q_append(const char c)
320
Ptr[str_length++] = c;
322
void q_append(const uint32_t n)
324
int4store(Ptr + str_length, n);
327
void q_append(double d)
329
float8store(Ptr + str_length, d);
332
void q_append(double *d)
334
float8store(Ptr + str_length, *d);
337
void q_append(const char *data, uint32_t data_len)
339
memcpy(Ptr + str_length, data, data_len);
340
str_length += data_len;
343
void write_at_position(int position, uint32_t value)
345
int4store(Ptr + position,value);
348
void qs_append(const char *str, uint32_t len);
349
void qs_append(double d);
350
void qs_append(double *d);
351
inline void qs_append(const char c)
356
void qs_append(int i);
357
void qs_append(uint32_t i);
304
359
/* Inline (general) functions used by the protocol functions */
339
bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str,
342
} /* namespace drizzled */
344
bool operator==(const drizzled::String &s1, const drizzled::String &s2);
345
bool operator!=(const drizzled::String &s1, const drizzled::String &s2);
348
#endif /* DRIZZLED_SQL_STRING_H */
394
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str,
397
return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
401
bool operator==(const String &s1, const String &s2);
402
bool operator!=(const String &s1, const String &s2);
405
#endif /* DRIZZLE_SERVER_SQL_STRING_H */