~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

mergeĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
using namespace std;
26
 
 
27
 
namespace drizzled
28
 
{
 
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
29
28
 
30
29
/**
31
30
  Change a number to format '3,333,333,333.000'.
35
34
 
36
35
const int FORMAT_MAX_DECIMALS= 30;
37
36
 
 
37
Item_func_format::Item_func_format(Item *org, Item *dec)
 
38
: Item_str_func(org, dec)
 
39
{
 
40
}
 
41
 
38
42
void Item_func_format::fix_length_and_dec()
39
43
{
40
44
  collation.set(default_charset());
78
82
    my_decimal dec_val, rnd_dec, *res;
79
83
    res= args[0]->val_decimal(&dec_val);
80
84
    if ((null_value=args[0]->null_value))
81
 
      return 0;
 
85
      return 0; /* purecov: inspected */
82
86
    my_decimal_round(E_DEC_FATAL_ERROR, res, dec, false, &rnd_dec);
83
87
    my_decimal2string(E_DEC_FATAL_ERROR, &rnd_dec, 0, 0, 0, str);
84
88
    str_length= str->length();
89
93
  {
90
94
    double nr= args[0]->val_real();
91
95
    if ((null_value=args[0]->null_value))
92
 
      return 0;
 
96
      return 0; /* purecov: inspected */
93
97
    nr= my_double_round(nr, (int64_t) dec, false, false);
94
98
    /* Here default_charset() is right as this is not an automatic conversion */
95
99
    str->set_real(nr, dec, default_charset());
96
 
    if (nr == numeric_limits<double>::quiet_NaN())
 
100
    if (isnan(nr))
97
101
      return str;
98
102
    str_length=str->length();
99
103
    if (nr < 0)
134
138
  args[1]->print(str, query_type);
135
139
  str->append(')');
136
140
}
137
 
 
138
 
} /* namespace drizzled */