~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merge Stewart's dead code removal

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"
 
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
 
#include <drizzled/charset_info.h>
26
 
#include <drizzled/type/decimal.h>
27
 
#include <drizzled/table.h>
28
 
 
29
26
using namespace std;
30
27
 
31
 
namespace drizzled
32
 
{
33
 
 
34
28
/**
35
29
  Change a number to format '3,333,333,333.000'.
36
30
 
39
33
 
40
34
const int FORMAT_MAX_DECIMALS= 30;
41
35
 
 
36
Item_func_format::Item_func_format(Item *org, Item *dec)
 
37
: Item_str_func(org, dec)
 
38
{
 
39
}
 
40
 
42
41
void Item_func_format::fix_length_and_dec()
43
42
{
44
43
  collation.set(default_charset());
79
78
  if (args[0]->result_type() == DECIMAL_RESULT ||
80
79
      args[0]->result_type() == INT_RESULT)
81
80
  {
82
 
    type::Decimal dec_val, rnd_dec, *res;
 
81
    my_decimal dec_val, rnd_dec, *res;
83
82
    res= args[0]->val_decimal(&dec_val);
84
83
    if ((null_value=args[0]->null_value))
85
84
      return 0;
86
 
    class_decimal_round(E_DEC_FATAL_ERROR, res, dec, false, &rnd_dec);
87
 
    class_decimal2string(&rnd_dec, 0, str);
 
85
    my_decimal_round(E_DEC_FATAL_ERROR, res, dec, false, &rnd_dec);
 
86
    my_decimal2string(E_DEC_FATAL_ERROR, &rnd_dec, 0, 0, 0, str);
88
87
    str_length= str->length();
89
88
    if (rnd_dec.sign())
90
89
      str_length--;
138
137
  args[1]->print(str, query_type);
139
138
  str->append(')');
140
139
}
141
 
 
142
 
} /* namespace drizzled */