~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to sql/my_decimal.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005-2006 MySQL AB
 
1
/*
 
2
   Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
   This program is free software; you can redistribute it and/or modify
4
5
   it under the terms of the GNU General Public License as published by
11
12
 
12
13
   You should have received a copy of the GNU General Public License
13
14
   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
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
15
17
 
16
18
#include "mysql_priv.h"
17
19
#include <time.h>
95
97
    UNSIGNED. Hence the buffer for a ZEROFILLed value is the length
96
98
    the user requested, plus one for a possible decimal point, plus
97
99
    one if the user only wanted decimal places, but we force a leading
98
 
    zero on them. Because the type is implicitly UNSIGNED, we do not
99
 
    need to reserve a character for the sign. For all other cases,
100
 
    fixed_prec will be 0, and my_decimal_string_length() will be called
101
 
    instead to calculate the required size of the buffer.
 
100
    zero on them, plus one for the '\0' terminator. Because the type
 
101
    is implicitly UNSIGNED, we do not need to reserve a character for
 
102
    the sign. For all other cases, fixed_prec will be 0, and
 
103
    my_decimal_string_length() will be called instead to calculate the
 
104
    required size of the buffer.
102
105
  */
103
106
  int length= (fixed_prec
104
107
               ? (fixed_prec + ((fixed_prec == fixed_dec) ? 1 : 0) + 1)
109
112
  result= decimal2string((decimal_t*) d, (char*) str->ptr(),
110
113
                         &length, (int)fixed_prec, fixed_dec,
111
114
                         filler);
 
115
  str->set_charset(&my_charset_bin);
112
116
  str->length(length);
113
117
  return check_result(mask, result);
114
118
}
249
253
  int i, end;
250
254
  char buff[512], *pos;
251
255
  pos= buff;
252
 
  pos+= my_sprintf(buff, (buff, "Decimal: sign: %d  intg: %d  frac: %d  { ",
253
 
                          dec->sign(), dec->intg, dec->frac));
 
256
  pos+= sprintf(buff, "Decimal: sign: %d  intg: %d  frac: %d  { ",
 
257
                dec->sign(), dec->intg, dec->frac);
254
258
  end= ROUND_UP(dec->frac)+ROUND_UP(dec->intg)-1;
255
259
  for (i=0; i < end; i++)
256
 
    pos+= my_sprintf(pos, (pos, "%09d, ", dec->buf[i]));
257
 
  pos+= my_sprintf(pos, (pos, "%09d }\n", dec->buf[i]));
 
260
    pos+= sprintf(pos, "%09d, ", dec->buf[i]);
 
261
  pos+= sprintf(pos, "%09d }\n", dec->buf[i]);
258
262
  fputs(buff, DBUG_FILE);
259
263
}
260
264
 
275
279
 
276
280
const char *dbug_decimal_as_string(char *buff, const my_decimal *val)
277
281
{
278
 
  int length= DECIMAL_MAX_STR_LENGTH;
 
282
  int length= DECIMAL_MAX_STR_LENGTH + 1;     /* minimum size for buff */
279
283
  if (!val)
280
284
    return "NULL";
281
285
  (void)decimal2string((decimal_t*) val, buff, &length, 0,0,0);