~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_string.cc

  • Committer: Brian Aker
  • Date: 2008-07-11 00:33:12 UTC
  • mfrom: (51.1.83 remove-dbug)
  • Revision ID: brian@tangent.org-20080711003312-f4sf5n2z3obor1u8
Comming Jay's merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
  {
47
47
    free();
48
48
    if (!(Ptr=(char*) my_malloc(arg_length,MYF(MY_WME))))
49
 
      return TRUE;
 
49
      return true;
50
50
    Alloced_length=arg_length;
51
51
    alloced=1;
52
52
  }
53
53
  Ptr[0]=0;
54
 
  return FALSE;
 
54
  return false;
55
55
}
56
56
 
57
57
 
74
74
        Alloced_length=len;
75
75
      }
76
76
      else
77
 
        return TRUE;                            // Signal error
 
77
        return true;                            // Signal error
78
78
    }
79
79
    else if ((new_ptr= (char*) my_malloc(len,MYF(MY_WME))))
80
80
    {
86
86
      alloced=1;
87
87
    }
88
88
    else
89
 
      return TRUE;                      // Signal error
 
89
      return true;                      // Signal error
90
90
  }
91
91
  Ptr[alloc_length]=0;                  // This make other funcs shorter
92
 
  return FALSE;
 
92
  return false;
93
93
}
94
94
 
95
95
bool String::set_int(longlong num, bool unsigned_flag, CHARSET_INFO *cs)
98
98
  int base= unsigned_flag ? 10 : -10;
99
99
 
100
100
  if (alloc(l))
101
 
    return TRUE;
 
101
    return true;
102
102
  str_length=(uint32) (cs->cset->longlong10_to_str)(cs,Ptr,l,base,num);
103
103
  str_charset=cs;
104
 
  return FALSE;
 
104
  return false;
105
105
}
106
106
 
107
107
bool String::set_real(double num,uint decimals, CHARSET_INFO *cs)
129
129
    Alloced_length=0;                           // Force realloc
130
130
    return realloc(str_length);
131
131
  }
132
 
  return FALSE;
 
132
  return false;
133
133
}
134
134
 
135
135
bool String::copy(const String &str)
136
136
{
137
137
  if (alloc(str.str_length))
138
 
    return TRUE;
 
138
    return true;
139
139
  str_length=str.str_length;
140
140
  bmove(Ptr,str.Ptr,str_length);                // May be overlapping
141
141
  Ptr[str_length]=0;
142
142
  str_charset=str.str_charset;
143
 
  return FALSE;
 
143
  return false;
144
144
}
145
145
 
146
146
bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
147
147
{
148
148
  if (alloc(arg_length))
149
 
    return TRUE;
 
149
    return true;
150
150
  if ((str_length=arg_length))
151
151
    memcpy(Ptr,str,arg_length);
152
152
  Ptr[arg_length]=0;
153
153
  str_charset=cs;
154
 
  return FALSE;
 
154
  return false;
155
155
}
156
156
 
157
157
 
189
189
      my_charset_same(from_cs, to_cs) ||
190
190
      ((from_cs == &my_charset_bin) &&
191
191
       (!(*offset=(arg_length % to_cs->mbminlen)))))
192
 
    return FALSE;
193
 
  return TRUE;
 
192
    return false;
 
193
  return true;
194
194
}
195
195
 
196
196
 
224
224
{
225
225
  /* How many bytes are in incomplete character */
226
226
  offset= cs->mbmaxlen - offset; /* How many zeros we should prepend */
227
 
  DBUG_ASSERT(offset && offset != cs->mbmaxlen);
 
227
  assert(offset && offset != cs->mbmaxlen);
228
228
 
229
229
  uint32 aligned_length= arg_length + offset;
230
230
  if (alloc(aligned_length))
231
 
    return TRUE;
 
231
    return true;
232
232
  
233
233
  /*
234
234
    Note, this is only safe for big-endian UCS-2.
241
241
  /* str_length is always >= 0 as arg_length is != 0 */
242
242
  str_length= aligned_length;
243
243
  str_charset= cs;
244
 
  return FALSE;
 
244
  return false;
245
245
}
246
246
 
247
247
 
254
254
  if (!offset) /* All characters are complete, just copy */
255
255
  {
256
256
    set(str, arg_length, cs);
257
 
    return FALSE;
 
257
    return false;
258
258
  }
259
259
  return copy_aligned(str, arg_length, offset, cs);
260
260
}
277
277
  }
278
278
  uint32 new_length= to_cs->mbmaxlen*arg_length;
279
279
  if (alloc(new_length))
280
 
    return TRUE;
 
280
    return true;
281
281
  str_length=copy_and_convert((char*) Ptr, new_length, to_cs,
282
282
                              str, arg_length, from_cs, errors);
283
283
  str_charset=to_cs;
284
 
  return FALSE;
 
284
  return false;
285
285
}
286
286
 
287
287
 
325
325
  else
326
326
  {
327
327
    if (realloc(max_length))
328
 
      return TRUE;
 
328
      return true;
329
329
    bfill(Ptr+str_length,max_length-str_length,fill_char);
330
330
    str_length=max_length;
331
331
  }
332
 
  return FALSE;
 
332
  return false;
333
333
}
334
334
 
335
335
void String::strip_sp()
343
343
  if (s.length())
344
344
  {
345
345
    if (realloc(str_length+s.length()))
346
 
      return TRUE;
 
346
      return true;
347
347
    memcpy(Ptr+str_length,s.ptr(),s.length());
348
348
    str_length+=s.length();
349
349
  }
350
 
  return FALSE;
 
350
  return false;
351
351
}
352
352
 
353
353
 
358
358
bool String::append(const char *s,uint32 arg_length)
359
359
{
360
360
  if (!arg_length)
361
 
    return FALSE;
 
361
    return false;
362
362
 
363
363
  /*
364
364
    For an ASCII incompatible string, e.g. UCS-2, we need to convert
368
368
    uint32 add_length=arg_length * str_charset->mbmaxlen;
369
369
    uint dummy_errors;
370
370
    if (realloc(str_length+ add_length))
371
 
      return TRUE;
 
371
      return true;
372
372
    str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
373
373
                                  s, arg_length, &my_charset_latin1,
374
374
                                  &dummy_errors);
375
 
    return FALSE;
 
375
    return false;
376
376
  }
377
377
 
378
378
  /*
379
379
    For an ASCII compatinble string we can just append.
380
380
  */
381
381
  if (realloc(str_length+arg_length))
382
 
    return TRUE;
 
382
    return true;
383
383
  memcpy(Ptr+str_length,s,arg_length);
384
384
  str_length+=arg_length;
385
 
  return FALSE;
 
385
  return false;
386
386
}
387
387
 
388
388
 
410
410
    uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
411
411
    uint dummy_errors;
412
412
    if (realloc(str_length + add_length)) 
413
 
      return TRUE;
 
413
      return true;
414
414
    str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
415
415
                                  s, arg_length, cs, &dummy_errors);
416
416
  }
417
417
  else
418
418
  {
419
419
    if (realloc(str_length + arg_length)) 
420
 
      return TRUE;
 
420
      return true;
421
421
    memcpy(Ptr + str_length, s, arg_length);
422
422
    str_length+= arg_length;
423
423
  }
424
 
  return FALSE;
 
424
  return false;
425
425
}
426
426
 
427
427
 
428
428
bool String::append(IO_CACHE* file, uint32 arg_length)
429
429
{
430
430
  if (realloc(str_length+arg_length))
431
 
    return TRUE;
 
431
    return true;
432
432
  if (my_b_read(file, (uchar*) Ptr + str_length, arg_length))
433
433
  {
434
434
    shrink(str_length);
435
 
    return TRUE;
 
435
    return true;
436
436
  }
437
437
  str_length+=arg_length;
438
 
  return FALSE;
 
438
  return false;
439
439
}
440
440
 
441
441
bool String::append_with_prefill(const char *s,uint32 arg_length,
444
444
  int t_length= arg_length > full_length ? arg_length : full_length;
445
445
 
446
446
  if (realloc(str_length + t_length))
447
 
    return TRUE;
 
447
    return true;
448
448
  t_length= full_length - arg_length;
449
449
  if (t_length > 0)
450
450
  {
452
452
    str_length=str_length + t_length;
453
453
  }
454
454
  append(s, arg_length);
455
 
  return FALSE;
 
455
  return false;
456
456
}
457
457
 
458
458
uint32 String::numchars()
553
553
      if (diff)
554
554
      {
555
555
        if (realloc(str_length+(uint32) diff))
556
 
          return TRUE;
 
556
          return true;
557
557
        bmove_upp((uchar*) Ptr+str_length+diff, (uchar*) Ptr+str_length,
558
558
                  str_length-offset-arg_length);
559
559
      }
562
562
    }
563
563
    str_length+=(uint32) diff;
564
564
  }
565
 
  return FALSE;
 
565
  return false;
566
566
}
567
567
 
568
568
 
572
572
  if (Alloced_length < str_length + space_needed)
573
573
  {
574
574
    if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
575
 
      return TRUE;
 
575
      return true;
576
576
  }
577
 
  return FALSE;
 
577
  return false;
578
578
}
579
579
 
580
580
void String::qs_append(const char *str, uint32 len)
814
814
    }
815
815
  }
816
816
 
817
 
  DBUG_ASSERT(FALSE); // Should never get to here
 
817
  assert(false); // Should never get to here
818
818
  return 0;           // Make compiler happy
819
819
}
820
820