~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.h

pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
macros.
Add PANDORA_DRIZZLE_BUILD to run the extra checks that drizzle needs that 
plugins would also need to run so we can just use that macro in generated
external plugin builds.
Added support to register_plugins for external plugin building.
Renamed register_plugins.py to pandora-plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
16
 
#ifndef DRIZZLE_SERVER_SQL_STRING_H
17
 
#define DRIZZLE_SERVER_SQL_STRING_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 Sun Microsystems
 
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; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef DRIZZLED_SQL_STRING_H
 
21
#define DRIZZLED_SQL_STRING_H
18
22
 
19
23
/* This file is originally from the mysql distribution. Coded by monty */
20
24
 
21
 
#ifdef USE_PRAGMA_INTERFACE
22
 
#pragma interface                       /* gcc class implementation */
23
 
#endif
24
25
 
25
26
#ifndef NOT_FIXED_DEC
26
 
#define NOT_FIXED_DEC                   31
 
27
#define NOT_FIXED_DEC                   (uint8_t)31
27
28
#endif
28
29
 
 
30
#include <drizzled/common.h>
 
31
#include <mysys/iocache.h>
 
32
#include <stdlib.h>
 
33
#include <string.h>
 
34
 
29
35
class String;
30
 
int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
31
 
String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
32
 
uint32_t copy_and_convert(char *to, uint32_t to_length, const CHARSET_INFO * const to_cs,
33
 
                        const char *from, uint32_t from_length,
34
 
                        const CHARSET_INFO * const from_cs, uint *errors);
35
 
uint32_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
36
 
                               char *to, uint to_length,
37
 
                               const CHARSET_INFO * const from_cs,
38
 
                               const char *from, uint from_length,
39
 
                               uint nchars,
40
 
                               const char **well_formed_error_pos,
41
 
                               const char **cannot_convert_error_pos,
42
 
                               const char **from_end_pos);
43
 
size_t my_copy_with_hex_escaping(const CHARSET_INFO * const cs,
44
 
                                 char *dst, size_t dstlen,
45
 
                                 const char *src, size_t srclen);
 
36
 
 
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
 
 
53
#if defined(__cplusplus)
 
54
}
 
55
#endif
46
56
 
47
57
class String
48
58
{
50
60
  uint32_t str_length,Alloced_length;
51
61
  bool alloced;
52
62
  const CHARSET_INFO *str_charset;
 
63
 
53
64
public:
54
65
  String()
55
 
  { 
56
 
    Ptr=0; str_length=Alloced_length=0; alloced=0; 
57
 
    str_charset= &my_charset_bin; 
 
66
  {
 
67
    Ptr=0; str_length=Alloced_length=0; alloced=0;
 
68
    str_charset= &my_charset_bin;
58
69
  }
59
70
  String(uint32_t length_arg)
60
 
  { 
61
 
    alloced=0; Alloced_length=0; (void) real_alloc(length_arg); 
 
71
  {
 
72
    alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
62
73
    str_charset= &my_charset_bin;
63
74
  }
64
75
  String(const char *str, const CHARSET_INFO * const cs)
65
 
  { 
66
 
    Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
 
76
  {
 
77
    Ptr=(char*) str; str_length=(uint32_t) strlen(str); Alloced_length=0; alloced=0;
67
78
    str_charset=cs;
68
79
  }
69
80
  String(const char *str,uint32_t len, const CHARSET_INFO * const cs)
70
 
  { 
 
81
  {
71
82
    Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
72
83
    str_charset=cs;
73
84
  }
74
85
  String(char *str,uint32_t len, const CHARSET_INFO * const cs)
75
 
  { 
 
86
  {
76
87
    Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
77
88
    str_charset=cs;
78
89
  }
79
90
  String(const String &str)
80
 
  { 
 
91
  {
81
92
    Ptr=str.Ptr ; str_length=str.str_length ;
82
 
    Alloced_length=str.Alloced_length; alloced=0; 
 
93
    Alloced_length=str.Alloced_length; alloced=0;
83
94
    str_charset=str.str_charset;
84
95
  }
85
96
  static void *operator new(size_t size, MEM_ROOT *mem_root)
86
 
  { return (void*) alloc_root(mem_root, (uint) size); }
87
 
  static void operator delete(void *ptr_arg __attribute__((unused)),
88
 
                              size_t size __attribute__((unused)))
 
97
  { return (void*) alloc_root(mem_root, (uint32_t) size); } 
 
98
  static void operator delete(void *, size_t)
89
99
  { TRASH(ptr_arg, size); }
90
 
  static void operator delete(void *ptr_arg __attribute__((unused)),
91
 
                              MEM_ROOT *mem_root __attribute__((unused)))
 
100
  static void operator delete(void *, MEM_ROOT *)
92
101
  { /* never called */ }
93
 
  ~String() { free(); }
 
102
  ~String();
94
103
 
95
104
  inline void set_charset(const CHARSET_INFO * const charset_arg)
96
105
  { str_charset= charset_arg; }
105
114
  inline const char *ptr() const { return Ptr; }
106
115
  inline char *c_ptr()
107
116
  {
108
 
    if (!Ptr || Ptr[str_length])                /* Should be safe */
 
117
    if (str_length == Alloced_length)
109
118
      (void) realloc(str_length);
 
119
    else
 
120
      Ptr[str_length]= 0;
 
121
    
110
122
    return Ptr;
111
123
  }
112
124
  inline char *c_ptr_quick()
123
135
      (void) realloc(str_length);
124
136
    return Ptr;
125
137
  }
 
138
  void append_identifier(const char *name, uint32_t length);
126
139
 
127
140
  void set(String &str,uint32_t offset,uint32_t arg_length)
128
141
  {
161
174
  { return set_int(num, false, cs); }
162
175
  bool set(uint64_t num, const CHARSET_INFO * const cs)
163
176
  { return set_int((int64_t)num, true, cs); }
164
 
  bool set_real(double num,uint decimals, const CHARSET_INFO * const cs);
 
177
  bool set_real(double num,uint32_t decimals, const CHARSET_INFO * const cs);
165
178
 
166
179
  /*
167
180
    PMG 2004.11.12
172
185
    statement to be run on the remote server, and have a comma after each.
173
186
    When the list is complete, I "chop" off the trailing comma
174
187
 
175
 
    ex. 
176
 
      String stringobj; 
 
188
    ex.
 
189
      String stringobj;
177
190
      stringobj.append("VALUES ('foo', 'fi', 'fo',");
178
191
      stringobj.chop();
179
192
      stringobj.append(")");
183
196
    VALUES ('foo', 'fi', 'fo',
184
197
    VALUES ('foo', 'fi', 'fo'
185
198
    VALUES ('foo', 'fi', 'fo')
186
 
      
 
199
 
187
200
  */
188
201
  inline void chop()
189
202
  {
190
 
    Ptr[str_length--]= '\0'; 
 
203
    Ptr[str_length--]= '\0';
191
204
  }
192
205
 
193
206
  inline void free()
196
209
    {
197
210
      alloced=0;
198
211
      Alloced_length=0;
199
 
      my_free(Ptr,MYF(0));
 
212
      ::free(Ptr);
200
213
      Ptr=0;
201
214
      str_length=0;                             /* Safety */
202
215
    }
214
227
    if (arg_length < Alloced_length)
215
228
    {
216
229
      char *new_ptr;
217
 
      if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,MYF(0))))
 
230
      if (!(new_ptr=(char*) ::realloc(Ptr,arg_length)))
218
231
      {
219
232
        Alloced_length = 0;
220
233
        real_alloc(arg_length);
232
245
    if (&s != this)
233
246
    {
234
247
      /*
235
 
        It is forbidden to do assignments like 
 
248
        It is forbidden to do assignments like
236
249
        some_string = substring_of_that_string
237
250
       */
238
251
      assert(!s.uses_buffer_owned_by(this));
249
262
  static bool needs_conversion(uint32_t arg_length,
250
263
                               const CHARSET_INFO * const cs_from, const CHARSET_INFO * const cs_to,
251
264
                               uint32_t *offset);
252
 
  bool copy_aligned(const char *s, uint32_t arg_length, uint32_t offset,
253
 
                    const CHARSET_INFO * const cs);
254
265
  bool set_or_copy_aligned(const char *s, uint32_t arg_length, const CHARSET_INFO * const cs);
255
266
  bool copy(const char*s,uint32_t arg_length, const CHARSET_INFO * const csfrom,
256
 
            const CHARSET_INFO * const csto, uint *errors);
 
267
            const CHARSET_INFO * const csto, uint32_t *errors);
257
268
  bool append(const String &s);
258
269
  bool append(const char *s);
259
270
  bool append(const char *s,uint32_t arg_length);
260
271
  bool append(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs);
261
 
  bool append(IO_CACHE* file, uint32_t arg_length);
262
 
  bool append_with_prefill(const char *s, uint32_t arg_length, 
 
272
  bool append_with_prefill(const char *s, uint32_t arg_length,
263
273
                           uint32_t full_length, char fill_char);
264
274
  int strstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
265
275
  int strrstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
279
289
    }
280
290
    return 0;
281
291
  }
282
 
  bool fill(uint32_t max_length,char fill);
283
292
  friend int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
284
293
  friend int stringcmp(const String *a,const String *b);
285
294
  friend String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
327
336
    int4store(Ptr + position,value);
328
337
  }
329
338
 
330
 
  void qs_append(const char *str, uint32_t len);
331
 
  void qs_append(double d);
332
 
  void qs_append(double *d);
333
 
  inline void qs_append(const char c)
334
 
  {
335
 
     Ptr[str_length]= c;
336
 
     str_length++;
337
 
  }
338
 
  void qs_append(int i);
339
 
  void qs_append(uint i);
340
 
 
341
339
  /* Inline (general) functions used by the protocol functions */
342
340
 
343
341
  inline char *prep_append(uint32_t arg_length, uint32_t step_alloc)
373
371
  }
374
372
};
375
373
 
376
 
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str, 
 
374
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str,
377
375
                                           char *end)
378
376
{
379
377
  return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
380
378
}
381
379
 
382
 
inline
383
 
bool operator==(const String &s1, const String &s2)
384
 
{
385
 
  return stringcmp(&s1,&s2) == 0;
386
 
}
387
 
 
388
 
inline
389
 
bool operator!=(const String &s1, const String &s2)
390
 
{
391
 
  return !(s1 == s2);
392
 
}
393
 
 
394
 
#endif /* DRIZZLE_SERVER_SQL_STRING_H */
 
380
extern "C++" {
 
381
bool operator==(const String &s1, const String &s2);
 
382
bool operator!=(const String &s1, const String &s2);
 
383
}
 
384
 
 
385
#endif /* DRIZZLED_SQL_STRING_H */