~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/sql_string.cc

Merged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
  {
50
50
    free();
51
51
    if (!(Ptr=(char*) my_malloc(arg_length,MYF(MY_WME))))
52
 
      return TRUE;
 
52
      return true;
53
53
    Alloced_length=arg_length;
54
54
    alloced=1;
55
55
  }
56
56
  Ptr[0]=0;
57
 
  return FALSE;
 
57
  return false;
58
58
}
59
59
 
60
60
 
77
77
        Alloced_length=len;
78
78
      }
79
79
      else
80
 
        return TRUE;                            // Signal error
 
80
        return true;                            // Signal error
81
81
    }
82
82
    else if ((new_ptr= (char*) my_malloc(len,MYF(MY_WME))))
83
83
    {
89
89
      alloced=1;
90
90
    }
91
91
    else
92
 
      return TRUE;                      // Signal error
 
92
      return true;                      // Signal error
93
93
  }
94
94
  Ptr[alloc_length]=0;                  // This make other funcs shorter
95
 
  return FALSE;
 
95
  return false;
96
96
}
97
97
 
98
98
bool String::set(int64_t num, CHARSET_INFO *cs)
100
100
  uint l=20*cs->mbmaxlen+1;
101
101
 
102
102
  if (alloc(l))
103
 
    return TRUE;
 
103
    return true;
104
104
  str_length=(uint32) (cs->cset->int64_t10_to_str)(cs,Ptr,l,-10,num);
105
105
  str_charset=cs;
106
 
  return FALSE;
 
106
  return false;
107
107
}
108
108
 
109
109
bool String::set(uint64_t num, CHARSET_INFO *cs)
111
111
  uint l=20*cs->mbmaxlen+1;
112
112
 
113
113
  if (alloc(l))
114
 
    return TRUE;
 
114
    return true;
115
115
  str_length=(uint32) (cs->cset->int64_t10_to_str)(cs,Ptr,l,10,num);
116
116
  str_charset=cs;
117
 
  return FALSE;
 
117
  return false;
118
118
}
119
119
 
120
120
bool String::set(double num,uint decimals, CHARSET_INFO *cs)
146
146
    Alloced_length=0;                           // Force realloc
147
147
    return realloc(str_length);
148
148
  }
149
 
  return FALSE;
 
149
  return false;
150
150
}
151
151
 
152
152
bool String::copy(const String &str)
153
153
{
154
154
  if (alloc(str.str_length))
155
 
    return TRUE;
 
155
    return true;
156
156
  str_length=str.str_length;
157
157
  bmove(Ptr,str.Ptr,str_length);                // May be overlapping
158
158
  Ptr[str_length]=0;
159
159
  str_charset=str.str_charset;
160
 
  return FALSE;
 
160
  return false;
161
161
}
162
162
 
163
163
bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
164
164
{
165
165
  if (alloc(arg_length))
166
 
    return TRUE;
 
166
    return true;
167
167
  if ((str_length=arg_length))
168
168
    memcpy(Ptr,str,arg_length);
169
169
  Ptr[arg_length]=0;
170
170
  str_charset=cs;
171
 
  return FALSE;
 
171
  return false;
172
172
}
173
173
 
174
174
 
206
206
      my_charset_same(from_cs, to_cs) ||
207
207
      ((from_cs == &my_charset_bin) &&
208
208
       (!(*offset=(arg_length % to_cs->mbminlen)))))
209
 
    return FALSE;
210
 
  return TRUE;
 
209
    return false;
 
210
  return true;
211
211
}
212
212
 
213
213
 
245
245
 
246
246
  uint32 aligned_length= arg_length + offset;
247
247
  if (alloc(aligned_length))
248
 
    return TRUE;
 
248
    return true;
249
249
  
250
250
  /*
251
251
    Note, this is only safe for little-endian UCS-2.
258
258
  /* str_length is always >= 0 as arg_length is != 0 */
259
259
  str_length= aligned_length;
260
260
  str_charset= cs;
261
 
  return FALSE;
 
261
  return false;
262
262
}
263
263
 
264
264
 
271
271
  if (!offset) /* All characters are complete, just copy */
272
272
  {
273
273
    set(str, arg_length, cs);
274
 
    return FALSE;
 
274
    return false;
275
275
  }
276
276
  return copy_aligned(str, arg_length, offset, cs);
277
277
}
294
294
  }
295
295
  uint32 new_length= to_cs->mbmaxlen*arg_length;
296
296
  if (alloc(new_length))
297
 
    return TRUE;
 
297
    return true;
298
298
  str_length=copy_and_convert((char*) Ptr, new_length, to_cs,
299
299
                              str, arg_length, from_cs, errors);
300
300
  str_charset=to_cs;
301
 
  return FALSE;
 
301
  return false;
302
302
}
303
303
 
304
304
 
342
342
  else
343
343
  {
344
344
    if (realloc(max_length))
345
 
      return TRUE;
 
345
      return true;
346
346
    bfill(Ptr+str_length,max_length-str_length,fill_char);
347
347
    str_length=max_length;
348
348
  }
349
 
  return FALSE;
 
349
  return false;
350
350
}
351
351
 
352
352
void String::strip_sp()
360
360
  if (s.length())
361
361
  {
362
362
    if (realloc(str_length+s.length()))
363
 
      return TRUE;
 
363
      return true;
364
364
    memcpy(Ptr+str_length,s.ptr(),s.length());
365
365
    str_length+=s.length();
366
366
  }
367
 
  return FALSE;
 
367
  return false;
368
368
}
369
369
 
370
370
 
375
375
bool String::append(const char *s,uint32 arg_length)
376
376
{
377
377
  if (!arg_length)
378
 
    return FALSE;
 
378
    return false;
379
379
 
380
380
  /*
381
381
    For an ASCII incompatible string, e.g. UCS-2, we need to convert
385
385
    uint32 add_length=arg_length * str_charset->mbmaxlen;
386
386
    uint dummy_errors;
387
387
    if (realloc(str_length+ add_length))
388
 
      return TRUE;
 
388
      return true;
389
389
    str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
390
390
                                  s, arg_length, &my_charset_latin1,
391
391
                                  &dummy_errors);
392
 
    return FALSE;
 
392
    return false;
393
393
  }
394
394
 
395
395
  /*
396
396
    For an ASCII compatinble string we can just append.
397
397
  */
398
398
  if (realloc(str_length+arg_length))
399
 
    return TRUE;
 
399
    return true;
400
400
  memcpy(Ptr+str_length,s,arg_length);
401
401
  str_length+=arg_length;
402
 
  return FALSE;
 
402
  return false;
403
403
}
404
404
 
405
405
 
427
427
    uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
428
428
    uint dummy_errors;
429
429
    if (realloc(str_length + add_length)) 
430
 
      return TRUE;
 
430
      return true;
431
431
    str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
432
432
                                  s, arg_length, cs, &dummy_errors);
433
433
  }
434
434
  else
435
435
  {
436
436
    if (realloc(str_length + arg_length)) 
437
 
      return TRUE;
 
437
      return true;
438
438
    memcpy(Ptr + str_length, s, arg_length);
439
439
    str_length+= arg_length;
440
440
  }
441
 
  return FALSE;
 
441
  return false;
442
442
}
443
443
 
444
444
 
445
445
bool String::append(IO_CACHE* file, uint32 arg_length)
446
446
{
447
447
  if (realloc(str_length+arg_length))
448
 
    return TRUE;
 
448
    return true;
449
449
  if (my_b_read(file, (uchar*) Ptr + str_length, arg_length))
450
450
  {
451
451
    shrink(str_length);
452
 
    return TRUE;
 
452
    return true;
453
453
  }
454
454
  str_length+=arg_length;
455
 
  return FALSE;
 
455
  return false;
456
456
}
457
457
 
458
458
bool String::append_with_prefill(const char *s,uint32 arg_length,
461
461
  int t_length= arg_length > full_length ? arg_length : full_length;
462
462
 
463
463
  if (realloc(str_length + t_length))
464
 
    return TRUE;
 
464
    return true;
465
465
  t_length= full_length - arg_length;
466
466
  if (t_length > 0)
467
467
  {
469
469
    str_length=str_length + t_length;
470
470
  }
471
471
  append(s, arg_length);
472
 
  return FALSE;
 
472
  return false;
473
473
}
474
474
 
475
475
uint32 String::numchars()
570
570
      if (diff)
571
571
      {
572
572
        if (realloc(str_length+(uint32) diff))
573
 
          return TRUE;
 
573
          return true;
574
574
        bmove_upp((uchar*) Ptr+str_length+diff, (uchar*) Ptr+str_length,
575
575
                  str_length-offset-arg_length);
576
576
      }
579
579
    }
580
580
    str_length+=(uint32) diff;
581
581
  }
582
 
  return FALSE;
 
582
  return false;
583
583
}
584
584
 
585
585
 
589
589
  if (Alloced_length < str_length + space_needed)
590
590
  {
591
591
    if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
592
 
      return TRUE;
 
592
      return true;
593
593
  }
594
 
  return FALSE;
 
594
  return false;
595
595
}
596
596
 
597
597
void String::qs_append(const char *str, uint32 len)