~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.h

  • Committer: Brian Aker
  • Date: 2009-10-01 22:56:26 UTC
  • mto: (1154.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1155.
  • Revision ID: brian@gaz-20091001225626-sb1pdykpxlnkheaj
Remove Factory/make scheduler work like everything else.

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 */
 
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
 */
15
19
 
16
20
#ifndef DRIZZLE_SERVER_SQL_STRING_H
17
21
#define DRIZZLE_SERVER_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
  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
46
59
 
47
60
class String
48
61
{
50
63
  uint32_t str_length,Alloced_length;
51
64
  bool alloced;
52
65
  const CHARSET_INFO *str_charset;
 
66
 
53
67
public:
54
68
  String()
55
 
  { 
56
 
    Ptr=0; str_length=Alloced_length=0; alloced=0; 
57
 
    str_charset= &my_charset_bin; 
 
69
  {
 
70
    Ptr=0; str_length=Alloced_length=0; alloced=0;
 
71
    str_charset= &my_charset_bin;
58
72
  }
59
73
  String(uint32_t length_arg)
60
 
  { 
61
 
    alloced=0; Alloced_length=0; (void) real_alloc(length_arg); 
 
74
  {
 
75
    alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
62
76
    str_charset= &my_charset_bin;
63
77
  }
64
78
  String(const char *str, const CHARSET_INFO * const cs)
65
 
  { 
66
 
    Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
 
79
  {
 
80
    Ptr=(char*) str; str_length=(uint32_t) strlen(str); Alloced_length=0; alloced=0;
67
81
    str_charset=cs;
68
82
  }
69
83
  String(const char *str,uint32_t len, const CHARSET_INFO * const cs)
70
 
  { 
 
84
  {
71
85
    Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
72
86
    str_charset=cs;
73
87
  }
74
88
  String(char *str,uint32_t len, const CHARSET_INFO * const cs)
75
 
  { 
 
89
  {
76
90
    Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
77
91
    str_charset=cs;
78
92
  }
79
93
  String(const String &str)
80
 
  { 
 
94
  {
81
95
    Ptr=str.Ptr ; str_length=str.str_length ;
82
 
    Alloced_length=str.Alloced_length; alloced=0; 
 
96
    Alloced_length=str.Alloced_length; alloced=0;
83
97
    str_charset=str.str_charset;
84
98
  }
85
99
  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)))
 
100
  { return (void*) alloc_root(mem_root, (uint32_t) size); } 
 
101
  static void operator delete(void *, size_t)
89
102
  { TRASH(ptr_arg, size); }
90
 
  static void operator delete(void *ptr_arg __attribute__((unused)),
91
 
                              MEM_ROOT *mem_root __attribute__((unused)))
 
103
  static void operator delete(void *, MEM_ROOT *)
92
104
  { /* never called */ }
93
 
  ~String() { free(); }
 
105
  ~String();
94
106
 
95
107
  inline void set_charset(const CHARSET_INFO * const charset_arg)
96
108
  { str_charset= charset_arg; }
105
117
  inline const char *ptr() const { return Ptr; }
106
118
  inline char *c_ptr()
107
119
  {
108
 
    if (!Ptr || Ptr[str_length])                /* Should be safe */
 
120
    if (str_length == Alloced_length)
109
121
      (void) realloc(str_length);
 
122
    else
 
123
      Ptr[str_length]= 0;
 
124
    
110
125
    return Ptr;
111
126
  }
112
127
  inline char *c_ptr_quick()
123
138
      (void) realloc(str_length);
124
139
    return Ptr;
125
140
  }
 
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
  {
161
177
  { return set_int(num, false, cs); }
162
178
  bool set(uint64_t num, const CHARSET_INFO * const cs)
163
179
  { return set_int((int64_t)num, true, cs); }
164
 
  bool set_real(double num,uint decimals, const CHARSET_INFO * const cs);
 
180
  bool set_real(double num,uint32_t decimals, const CHARSET_INFO * const cs);
165
181
 
166
182
  /*
167
183
    PMG 2004.11.12
172
188
    statement to be run on the remote server, and have a comma after each.
173
189
    When the list is complete, I "chop" off the trailing comma
174
190
 
175
 
    ex. 
176
 
      String stringobj; 
 
191
    ex.
 
192
      String stringobj;
177
193
      stringobj.append("VALUES ('foo', 'fi', 'fo',");
178
194
      stringobj.chop();
179
195
      stringobj.append(")");
183
199
    VALUES ('foo', 'fi', 'fo',
184
200
    VALUES ('foo', 'fi', 'fo'
185
201
    VALUES ('foo', 'fi', 'fo')
186
 
      
 
202
 
187
203
  */
188
204
  inline void chop()
189
205
  {
190
 
    Ptr[str_length--]= '\0'; 
 
206
    Ptr[str_length--]= '\0';
191
207
  }
192
208
 
193
209
  inline void free()
196
212
    {
197
213
      alloced=0;
198
214
      Alloced_length=0;
199
 
      my_free(Ptr,MYF(0));
 
215
      ::free(Ptr);
200
216
      Ptr=0;
201
217
      str_length=0;                             /* Safety */
202
218
    }
214
230
    if (arg_length < Alloced_length)
215
231
    {
216
232
      char *new_ptr;
217
 
      if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,MYF(0))))
 
233
      if (!(new_ptr=(char*) ::realloc(Ptr,arg_length)))
218
234
      {
219
235
        Alloced_length = 0;
220
236
        real_alloc(arg_length);
232
248
    if (&s != this)
233
249
    {
234
250
      /*
235
 
        It is forbidden to do assignments like 
 
251
        It is forbidden to do assignments like
236
252
        some_string = substring_of_that_string
237
253
       */
238
254
      assert(!s.uses_buffer_owned_by(this));
249
265
  static bool needs_conversion(uint32_t arg_length,
250
266
                               const CHARSET_INFO * const cs_from, const CHARSET_INFO * const cs_to,
251
267
                               uint32_t *offset);
252
 
  bool copy_aligned(const char *s, uint32_t arg_length, uint32_t offset,
253
 
                    const CHARSET_INFO * const cs);
254
268
  bool set_or_copy_aligned(const char *s, uint32_t arg_length, const CHARSET_INFO * const cs);
255
269
  bool copy(const char*s,uint32_t arg_length, const CHARSET_INFO * const csfrom,
256
 
            const CHARSET_INFO * const csto, uint *errors);
 
270
            const CHARSET_INFO * const csto, uint32_t *errors);
257
271
  bool append(const String &s);
258
272
  bool append(const char *s);
259
273
  bool append(const char *s,uint32_t arg_length);
260
274
  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, 
 
275
  bool append_with_prefill(const char *s, uint32_t arg_length,
263
276
                           uint32_t full_length, char fill_char);
264
277
  int strstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
265
278
  int strrstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
279
292
    }
280
293
    return 0;
281
294
  }
282
 
  bool fill(uint32_t max_length,char fill);
283
295
  friend int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
284
296
  friend int stringcmp(const String *a,const String *b);
285
297
  friend String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
327
339
    int4store(Ptr + position,value);
328
340
  }
329
341
 
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
342
  /* Inline (general) functions used by the protocol functions */
342
343
 
343
344
  inline char *prep_append(uint32_t arg_length, uint32_t step_alloc)
373
374
  }
374
375
};
375
376
 
376
 
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str, 
 
377
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str,
377
378
                                           char *end)
378
379
{
379
380
  return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
380
381
}
381
382
 
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);
 
383
extern "C++" {
 
384
bool operator==(const String &s1, const String &s2);
 
385
bool operator!=(const String &s1, const String &s2);
392
386
}
393
387
 
394
388
#endif /* DRIZZLE_SERVER_SQL_STRING_H */