~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-05-23 17:13:03 UTC
  • mfrom: (1034.1.8 merge)
  • Revision ID: brian@gaz-20090523171303-d28xhutqic0xe2b4
Merge Brian

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