~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/my_decimal.cc

  • Committer: Brian Aker
  • Date: 2008-07-15 06:45:16 UTC
  • Revision ID: brian@tangent.org-20080715064516-fnbq7kowh7w57bxj
Merge Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
 
16
#include "mysql_priv.h"
17
17
#include <time.h>
18
 
#include <drizzled/drizzled_error_messages.h>
19
 
 
20
 
 
 
18
 
 
19
 
 
20
#ifndef MYSQL_CLIENT
21
21
/**
22
22
  report result of decimal operation.
23
23
 
36
36
  case E_DEC_OK:
37
37
    break;
38
38
  case E_DEC_TRUNCATED:
39
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
40
 
                        ER_WARN_DATA_TRUNCATED, ER(ER_WARN_DATA_TRUNCATED),
 
39
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
40
                        WARN_DATA_TRUNCATED, ER(WARN_DATA_TRUNCATED),
41
41
                        "", (long)-1);
42
42
    break;
43
43
  case E_DEC_OVERFLOW:
44
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
44
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
45
45
                        ER_TRUNCATED_WRONG_VALUE,
46
46
                        ER(ER_TRUNCATED_WRONG_VALUE),
47
47
                        "DECIMAL", "");
48
48
    break;
49
49
  case E_DEC_DIV_ZERO:
50
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
50
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
51
51
                        ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));
52
52
    break;
53
53
  case E_DEC_BAD_NUM:
54
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
54
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
55
55
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
56
56
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
57
57
                        "decimal", "", "", (long)-1);
85
85
    @retval E_DEC_OOM
86
86
*/
87
87
 
88
 
int my_decimal2string(uint32_t mask, const my_decimal *d,
89
 
                      uint32_t fixed_prec, uint32_t fixed_dec,
 
88
int my_decimal2string(uint mask, const my_decimal *d,
 
89
                      uint fixed_prec, uint fixed_dec,
90
90
                      char filler, String *str)
91
91
{
92
92
  /*
135
135
    E_DEC_OVERFLOW
136
136
*/
137
137
 
138
 
int my_decimal2binary(uint32_t mask, const my_decimal *d, unsigned char *bin, int prec,
 
138
int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec,
139
139
                      int scale)
140
140
{
141
141
  int err1= E_DEC_OK, err2;
174
174
    E_DEC_OOM
175
175
*/
176
176
 
177
 
int str2my_decimal(uint32_t mask, const char *from, uint32_t length,
178
 
                   const CHARSET_INFO * charset, my_decimal *decimal_value)
 
177
int str2my_decimal(uint mask, const char *from, uint length,
 
178
                   CHARSET_INFO *charset, my_decimal *decimal_value)
179
179
{
180
180
  char *end, *from_end;
181
181
  int err;
183
183
  String tmp(buff, sizeof(buff), &my_charset_bin);
184
184
  if (charset->mbminlen > 1)
185
185
  {
186
 
    uint32_t dummy_errors;
187
 
    tmp.copy(from, length, charset, &my_charset_utf8_general_ci, &dummy_errors);
 
186
    uint dummy_errors;
 
187
    tmp.copy(from, length, charset, &my_charset_latin1, &dummy_errors);
188
188
    from= tmp.ptr();
189
189
    length=  tmp.length();
190
190
    charset= &my_charset_bin;
196
196
    /* Give warning if there is something other than end space */
197
197
    for ( ; end < from_end; end++)
198
198
    {
199
 
      if (!my_isspace(&my_charset_utf8_general_ci, *end))
 
199
      if (!my_isspace(&my_charset_latin1, *end))
200
200
      {
201
201
        err= E_DEC_TRUNCATED;
202
202
        break;
208
208
}
209
209
 
210
210
 
211
 
my_decimal *date2my_decimal(DRIZZLE_TIME *ltime, my_decimal *dec)
 
211
my_decimal *date2my_decimal(MYSQL_TIME *ltime, my_decimal *dec)
212
212
{
213
213
  int64_t date;
214
214
  date = (ltime->year*100L + ltime->month)*100L + ltime->day;
215
 
  if (ltime->time_type > DRIZZLE_TIMESTAMP_DATE)
 
215
  if (ltime->time_type > MYSQL_TIMESTAMP_DATE)
216
216
    date= ((date*100L + ltime->hour)*100L+ ltime->minute)*100L + ltime->second;
217
217
  if (int2my_decimal(E_DEC_FATAL_ERROR, date, false, dec))
218
218
    return dec;
225
225
}
226
226
 
227
227
 
228
 
void my_decimal_trim(uint32_t *precision, uint32_t *scale)
 
228
void my_decimal_trim(ulong *precision, uint *scale)
229
229
{
230
230
  if (!(*precision) && !(*scale))
231
231
  {
239
239
/* routines for debugging print */
240
240
#define DIG_PER_DEC1 9
241
241
#define ROUND_UP(X)  (((X)+DIG_PER_DEC1-1)/DIG_PER_DEC1)
 
242
 
 
243
#endif /*MYSQL_CLIENT*/