~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/string_functions/format.cc

Fix merge issues with 1.0 CC fix.

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
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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 <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
 
20
#include <config.h>
 
21
#include "format.h"
 
22
 
 
23
#include <limits>
 
24
 
 
25
#include <drizzled/charset.h>
 
26
#include <drizzled/type/decimal.h>
 
27
#include <drizzled/table.h>
 
28
 
 
29
using namespace std;
 
30
 
 
31
namespace drizzled
 
32
{
28
33
 
29
34
/**
30
35
  Change a number to format '3,333,333,333.000'.
34
39
 
35
40
const int FORMAT_MAX_DECIMALS= 30;
36
41
 
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
 
    my_decimal dec_val, rnd_dec, *res;
 
82
    type::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; /* 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);
 
85
      return 0;
 
86
    class_decimal_round(E_DEC_FATAL_ERROR, res, dec, false, &rnd_dec);
 
87
    class_decimal2string(&rnd_dec, 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; /* purecov: inspected */
 
96
      return 0;
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 (isnan(nr))
 
100
    if (nr == numeric_limits<double>::quiet_NaN())
101
101
      return str;
102
102
    str_length=str->length();
103
103
    if (nr < 0)
130
130
}
131
131
 
132
132
 
133
 
void Item_func_format::print(String *str, enum_query_type query_type)
 
133
void Item_func_format::print(String *str)
134
134
{
135
135
  str->append(STRING_WITH_LEN("format("));
136
 
  args[0]->print(str, query_type);
 
136
  args[0]->print(str);
137
137
  str->append(',');
138
 
  args[1]->print(str, query_type);
 
138
  args[1]->print(str);
139
139
  str->append(')');
140
140
}
 
141
 
 
142
} /* namespace drizzled */