~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/str/format.cc

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include "format.h"
22
 
 
23
 
#include <limits>
24
 
 
25
 
#include <drizzled/charset_info.h>
26
 
#include <drizzled/type/decimal.h>
27
 
#include <drizzled/table.h>
28
 
 
29
 
using namespace std;
30
 
 
31
 
namespace drizzled
32
 
{
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include CMATH_H
 
23
#include <drizzled/function/str/format.h>
 
24
 
 
25
#if defined(CMATH_NAMESPACE)
 
26
using namespace CMATH_NAMESPACE;
 
27
#endif
33
28
 
34
29
/**
35
30
  Change a number to format '3,333,333,333.000'.
39
34
 
40
35
const int FORMAT_MAX_DECIMALS= 30;
41
36
 
 
37
Item_func_format::Item_func_format(Item *org, Item *dec)
 
38
: Item_str_func(org, dec)
 
39
{
 
40
}
 
41
 
42
42
void Item_func_format::fix_length_and_dec()
43
43
{
44
44
  collation.set(default_charset());
79
79
  if (args[0]->result_type() == DECIMAL_RESULT ||
80
80
      args[0]->result_type() == INT_RESULT)
81
81
  {
82
 
    type::Decimal dec_val, rnd_dec, *res;
 
82
    my_decimal dec_val, rnd_dec, *res;
83
83
    res= args[0]->val_decimal(&dec_val);
84
84
    if ((null_value=args[0]->null_value))
85
 
      return 0;
86
 
    class_decimal_round(E_DEC_FATAL_ERROR, res, dec, false, &rnd_dec);
87
 
    class_decimal2string(&rnd_dec, 0, str);
 
85
      return 0; /* purecov: inspected */
 
86
    my_decimal_round(E_DEC_FATAL_ERROR, res, dec, false, &rnd_dec);
 
87
    my_decimal2string(E_DEC_FATAL_ERROR, &rnd_dec, 0, 0, 0, str);
88
88
    str_length= str->length();
89
89
    if (rnd_dec.sign())
90
90
      str_length--;
93
93
  {
94
94
    double nr= args[0]->val_real();
95
95
    if ((null_value=args[0]->null_value))
96
 
      return 0;
 
96
      return 0; /* purecov: inspected */
97
97
    nr= my_double_round(nr, (int64_t) dec, false, false);
98
98
    /* Here default_charset() is right as this is not an automatic conversion */
99
99
    str->set_real(nr, dec, default_charset());
100
 
    if (nr == numeric_limits<double>::quiet_NaN())
 
100
    if (isnan(nr))
101
101
      return str;
102
102
    str_length=str->length();
103
103
    if (nr < 0)
138
138
  args[1]->print(str, query_type);
139
139
  str->append(')');
140
140
}
141
 
 
142
 
} /* namespace drizzled */