~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/my_decimal.cc

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

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);
60
60
    my_error(ER_OUT_OF_RESOURCES, MYF(0));
61
61
    break;
62
62
  default:
63
 
    assert(0);
 
63
    DBUG_ASSERT(0);
64
64
  }
65
65
  return result;
66
66
}
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
 
  int64_t date;
 
213
  longlong 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
 
  if (int2my_decimal(E_DEC_FATAL_ERROR, date, false, dec))
 
217
  if (int2my_decimal(E_DEC_FATAL_ERROR, date, FALSE, dec))
218
218
    return dec;
219
219
  if (ltime->second_part)
220
220
  {
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
  {
236
236
}
237
237
 
238
238
 
 
239
#ifndef DBUG_OFF
239
240
/* routines for debugging print */
 
241
 
240
242
#define DIG_PER_DEC1 9
241
243
#define ROUND_UP(X)  (((X)+DIG_PER_DEC1-1)/DIG_PER_DEC1)
 
244
 
 
245
/* print decimal */
 
246
void
 
247
print_decimal(const my_decimal *dec)
 
248
{
 
249
  int i, end;
 
250
  char buff[512], *pos;
 
251
  pos= buff;
 
252
  pos+= my_sprintf(buff, (buff, "Decimal: sign: %d  intg: %d  frac: %d  { ",
 
253
                          dec->sign(), dec->intg, dec->frac));
 
254
  end= ROUND_UP(dec->frac)+ROUND_UP(dec->intg)-1;
 
255
  for (i=0; i < end; i++)
 
256
    pos+= my_sprintf(pos, (pos, "%09d, ", dec->buf[i]));
 
257
  pos+= my_sprintf(pos, (pos, "%09d }\n", dec->buf[i]));
 
258
  fputs(buff, DBUG_FILE);
 
259
}
 
260
 
 
261
 
 
262
/* print decimal with its binary representation */
 
263
void
 
264
print_decimal_buff(const my_decimal *dec, const uchar* ptr, int length)
 
265
{
 
266
  print_decimal(dec);
 
267
  fprintf(DBUG_FILE, "Record: ");
 
268
  for (int i= 0; i < length; i++)
 
269
  {
 
270
    fprintf(DBUG_FILE, "%02X ", (uint)((uchar *)ptr)[i]);
 
271
  }
 
272
  fprintf(DBUG_FILE, "\n");
 
273
}
 
274
 
 
275
 
 
276
const char *dbug_decimal_as_string(char *buff, const my_decimal *val)
 
277
{
 
278
  int length= DECIMAL_MAX_STR_LENGTH;
 
279
  if (!val)
 
280
    return "NULL";
 
281
  (void)decimal2string((decimal_t*) val, buff, &length, 0,0,0);
 
282
  return buff;
 
283
}
 
284
 
 
285
#endif /*DBUG_OFF*/
 
286
 
 
287
 
 
288
#endif /*MYSQL_CLIENT*/