~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-17 00:08:20 UTC
  • mto: (1126.9.3 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090917000820-urd6p46qngi1okjp
Updated calls to some dtrace probes to cast the parameter to const char *
appropriately. Also, removed the additional variable in places that I was
using.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
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
22
22
 
23
23
/* This file is originally from the mysql distribution. Coded by monty */
24
24
 
25
 
#include <drizzled/common.h>
26
 
#include <cassert>
27
 
#include <cstdlib>
28
 
#include <cstring>
29
 
#include <string>
30
25
 
31
26
#ifndef NOT_FIXED_DEC
32
27
#define NOT_FIXED_DEC                   (uint8_t)31
33
28
#endif
34
29
 
35
 
namespace drizzled
36
 
{
 
30
#include <drizzled/common.h>
 
31
#include <mysys/iocache.h>
 
32
#include <stdlib.h>
 
33
#include <string.h>
37
34
 
38
35
class String;
39
36
 
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;
44
 
 
45
 
std::string String_to_std_string(String const& s);
46
 
String* set_String_from_std_string(String* s, std::string const& cs);
47
 
 
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,
55
 
                                 uint32_t nchars,
56
 
                                 const char **well_formed_error_pos,
57
 
                                 const char **cannot_convert_error_pos,
58
 
                                 const char **from_end_pos);
59
 
 
 
37
#if defined(__cplusplus)
 
38
extern "C" {
 
39
#endif
 
40
 
 
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 well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
 
45
                                   char *to, uint32_t to_length,
 
46
                                   const CHARSET_INFO * const from_cs,
 
47
                                   const char *from, uint32_t from_length,
 
48
                                   uint32_t nchars,
 
49
                                   const char **well_formed_error_pos,
 
50
                                   const char **cannot_convert_error_pos,
 
51
                                   const char **from_end_pos);
 
52
  size_t my_copy_with_hex_escaping(const CHARSET_INFO * const cs,
 
53
                                   char *dst, size_t dstlen,
 
54
                                   const char *src, size_t srclen);
 
55
 
 
56
#if defined(__cplusplus)
 
57
}
 
58
#endif
60
59
 
61
60
class String
62
61
{
66
65
  const CHARSET_INFO *str_charset;
67
66
 
68
67
public:
69
 
  String();
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);
75
 
 
76
 
  static void *operator new(size_t size, memory::Root *mem_root);
 
68
  String()
 
69
  {
 
70
    Ptr=0; str_length=Alloced_length=0; alloced=0;
 
71
    str_charset= &my_charset_bin;
 
72
  }
 
73
  String(uint32_t length_arg)
 
74
  {
 
75
    alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
 
76
    str_charset= &my_charset_bin;
 
77
  }
 
78
  String(const char *str, const CHARSET_INFO * const cs)
 
79
  {
 
80
    Ptr=(char*) str; str_length=(uint32_t) strlen(str); Alloced_length=0; alloced=0;
 
81
    str_charset=cs;
 
82
  }
 
83
  String(const char *str,uint32_t len, const CHARSET_INFO * const cs)
 
84
  {
 
85
    Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
 
86
    str_charset=cs;
 
87
  }
 
88
  String(char *str,uint32_t len, const CHARSET_INFO * const cs)
 
89
  {
 
90
    Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
 
91
    str_charset=cs;
 
92
  }
 
93
  String(const String &str)
 
94
  {
 
95
    Ptr=str.Ptr ; str_length=str.str_length ;
 
96
    Alloced_length=str.Alloced_length; alloced=0;
 
97
    str_charset=str.str_charset;
 
98
  }
 
99
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
100
  { return (void*) alloc_root(mem_root, (uint32_t) size); } 
77
101
  static void operator delete(void *, size_t)
78
 
  { }
79
 
  static void operator delete(void *, memory::Root *)
80
 
  { }
 
102
  { TRASH(ptr_arg, size); }
 
103
  static void operator delete(void *, MEM_ROOT *)
 
104
  { /* never called */ }
81
105
  ~String();
82
106
 
83
107
  inline void set_charset(const CHARSET_INFO * const charset_arg)
97
121
      (void) realloc(str_length);
98
122
    else
99
123
      Ptr[str_length]= 0;
100
 
 
 
124
    
101
125
    return Ptr;
102
126
  }
103
127
  inline char *c_ptr_quick()
114
138
      (void) realloc(str_length);
115
139
    return Ptr;
116
140
  }
117
 
  inline char *c_str()
118
 
  {
119
 
    if (Ptr && str_length < Alloced_length)
120
 
      Ptr[str_length]=0;
121
 
    else
122
 
      (void) realloc(str_length);
123
 
    return Ptr;
124
 
  }
125
141
  void append_identifier(const char *name, uint32_t length);
126
142
 
127
143
  void set(String &str,uint32_t offset,uint32_t arg_length)
128
144
  {
129
145
    assert(&str != this);
130
146
    free();
131
 
    Ptr= str.ptr()+offset; str_length=arg_length; alloced=0;
 
147
    Ptr=(char*) str.ptr()+offset; str_length=arg_length; alloced=0;
132
148
    if (str.Alloced_length)
133
149
      Alloced_length=str.Alloced_length-offset;
134
150
    else
138
154
  inline void set(char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
139
155
  {
140
156
    free();
141
 
    Ptr= str; str_length=Alloced_length=arg_length ; alloced=0;
 
157
    Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0;
142
158
    str_charset=cs;
143
159
  }
144
160
  inline void set(const char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
145
161
  {
146
162
    free();
147
 
    Ptr= const_cast<char*>(str);
148
 
    str_length=arg_length; Alloced_length=0 ; alloced=0;
 
163
    Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
149
164
    str_charset=cs;
150
165
  }
151
166
  bool set_ascii(const char *str, uint32_t arg_length);
153
168
  {
154
169
    if (!alloced)
155
170
    {
156
 
      Ptr= str; str_length= Alloced_length= arg_length;
 
171
      Ptr=(char*) str; str_length=Alloced_length=arg_length;
157
172
    }
158
 
    str_charset= cs;
 
173
    str_charset=cs;
159
174
  }
160
175
  bool set_int(int64_t num, bool unsigned_flag, const CHARSET_INFO * const cs);
161
176
  bool set(int64_t num, const CHARSET_INFO * const cs)
162
177
  { return set_int(num, false, cs); }
163
178
  bool set(uint64_t num, const CHARSET_INFO * const cs)
164
 
  { return set_int(static_cast<int64_t>(num), true, cs); }
 
179
  { return set_int((int64_t)num, true, cs); }
165
180
  bool set_real(double num,uint32_t decimals, const CHARSET_INFO * const cs);
166
181
 
167
182
  /*
215
230
    if (arg_length < Alloced_length)
216
231
    {
217
232
      char *new_ptr;
218
 
      if (!(new_ptr= reinterpret_cast<char*>(::realloc(Ptr,arg_length))))
 
233
      if (!(new_ptr=(char*) ::realloc(Ptr,arg_length)))
219
234
      {
220
235
        Alloced_length = 0;
221
236
        real_alloc(arg_length);
294
309
    q_*** methods writes values of parameters itself
295
310
    qs_*** methods writes string representation of value
296
311
  */
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);
 
312
  void q_append(const char c)
 
313
  {
 
314
    Ptr[str_length++] = c;
 
315
  }
 
316
  void q_append(const uint32_t n)
 
317
  {
 
318
    int4store(Ptr + str_length, n);
 
319
    str_length += 4;
 
320
  }
 
321
  void q_append(double d)
 
322
  {
 
323
    float8store(Ptr + str_length, d);
 
324
    str_length += 8;
 
325
  }
 
326
  void q_append(double *d)
 
327
  {
 
328
    float8store(Ptr + str_length, *d);
 
329
    str_length += 8;
 
330
  }
 
331
  void q_append(const char *data, uint32_t data_len)
 
332
  {
 
333
    memcpy(Ptr + str_length, data, data_len);
 
334
    str_length += data_len;
 
335
  }
 
336
 
 
337
  void write_at_position(int position, uint32_t value)
 
338
  {
 
339
    int4store(Ptr + position,value);
 
340
  }
303
341
 
304
342
  /* Inline (general) functions used by the protocol functions */
305
343
 
336
374
  }
337
375
};
338
376
 
339
 
bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str,
340
 
                             char *end);
341
 
 
342
 
} /* namespace drizzled */
343
 
 
344
 
bool operator==(const drizzled::String &s1, const drizzled::String &s2);
345
 
bool operator!=(const drizzled::String &s1, const drizzled::String &s2);
346
 
 
347
 
 
348
 
#endif /* DRIZZLED_SQL_STRING_H */
 
377
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str,
 
378
                                           char *end)
 
379
{
 
380
  return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
 
381
}
 
382
 
 
383
extern "C++" {
 
384
bool operator==(const String &s1, const String &s2);
 
385
bool operator!=(const String &s1, const String &s2);
 
386
}
 
387
 
 
388
#endif /* DRIZZLE_SERVER_SQL_STRING_H */