~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/decimal.cc

  • Committer: Joe Daly
  • Date: 2010-01-06 02:20:42 UTC
  • mto: This revision was merged to the branch mainline in revision 1267.
  • Revision ID: skinny.moey@gmail.com-20100106022042-8ov23wc4aq8f9k7d
rename hash_algorithm to algorithm

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/table.h>
26
26
#include <drizzled/session.h>
27
27
 
28
 
namespace drizzled
29
 
{
30
 
 
31
28
extern my_decimal decimal_zero;
32
29
 
33
30
/****************************************************************************
124
121
 
125
122
bool Field_decimal::store_value(const my_decimal *decimal_value)
126
123
{
127
 
  int error= my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
128
 
                                         decimal_value, ptr, precision, dec);
129
 
  if (warn_if_overflow(error))
 
124
  int error= 0;
 
125
 
 
126
  if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
 
127
                                         decimal_value, ptr, precision, dec)))
130
128
  {
131
 
    if (error != E_DEC_TRUNCATED)
132
 
    {
133
 
      my_decimal buff;
134
 
      set_value_on_overflow(&buff, decimal_value->sign());
135
 
      my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
136
 
    }
 
129
    my_decimal buff;
 
130
    set_value_on_overflow(&buff, decimal_value->sign());
 
131
    my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
137
132
    error= 1;
138
133
  }
139
134
  return(error);
152
147
                           ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
153
148
                           from, length, charset_arg,
154
149
                           &decimal_value)) &&
155
 
      getTable()->in_use->abort_on_warning)
 
150
      table->in_use->abort_on_warning)
156
151
  {
157
152
    /* Because "from" is not NUL-terminated and we use %s in the ER() */
158
153
    String from_as_str;
159
154
    from_as_str.copy(from, length, &my_charset_bin);
160
155
 
161
 
    push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
156
    push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
162
157
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
163
158
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
164
159
                        "decimal", from_as_str.c_ptr(), field_name,
165
 
                        (uint32_t) getTable()->in_use->row_count);
 
160
                        (uint32_t) table->in_use->row_count);
166
161
 
167
162
    return(err);
168
163
  }
182
177
      String from_as_str;
183
178
      from_as_str.copy(from, length, &my_charset_bin);
184
179
 
185
 
      push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
180
      push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
186
181
                          ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
187
182
                          ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
188
183
                          "decimal", from_as_str.c_ptr(), field_name,
189
 
                          (uint32_t) getTable()->in_use->row_count);
 
184
                          (uint32_t) table->in_use->row_count);
190
185
      my_decimal_set_zero(&decimal_value);
191
186
 
192
187
      break;
218
213
    if (check_overflow(err))
219
214
      set_value_on_overflow(&decimal_value, decimal_value.sign());
220
215
    /* Only issue a warning if store_value doesn't issue an warning */
221
 
    getTable()->in_use->got_warning= 0;
 
216
    table->in_use->got_warning= 0;
222
217
  }
223
218
  if (store_value(&decimal_value))
224
219
    err= 1;
225
 
  else if (err && !getTable()->in_use->got_warning)
 
220
  else if (err && !table->in_use->got_warning)
226
221
    err= warn_if_overflow(err);
227
222
  return(err);
228
223
}
241
236
    if (check_overflow(err))
242
237
      set_value_on_overflow(&decimal_value, decimal_value.sign());
243
238
    /* Only issue a warning if store_value doesn't issue an warning */
244
 
    getTable()->in_use->got_warning= 0;
 
239
    table->in_use->got_warning= 0;
245
240
  }
246
241
  if (store_value(&decimal_value))
247
242
    err= 1;
248
 
  else if (err && not getTable()->in_use->got_warning)
 
243
  else if (err && !table->in_use->got_warning)
249
244
    err= warn_if_overflow(err);
250
245
  return err;
251
246
}
358
353
}
359
354
 
360
355
 
 
356
/**
 
357
  Check to see if field size is compatible with destination.
 
358
 
 
359
  This method is used in row-based replication to verify that the slave's
 
360
  field size is less than or equal to the master's field size. The
 
361
  encoded field metadata (from the master or source) is decoded and compared
 
362
  to the size of this field (the slave or destination).
 
363
 
 
364
  @param   field_metadata   Encoded size in field metadata
 
365
 
 
366
  @retval 0 if this field's size is < the source field's size
 
367
  @retval 1 if this field's size is >= the source field's size
 
368
*/
 
369
int Field_decimal::compatible_field_size(uint32_t field_metadata)
 
370
{
 
371
  int compatible= 0;
 
372
  uint32_t const source_precision= (field_metadata >> 8U) & 0x00ff;
 
373
  uint32_t const source_decimal= field_metadata & 0x00ff;
 
374
  uint32_t const source_size= my_decimal_get_binary_size(source_precision,
 
375
                                                         source_decimal);
 
376
  uint32_t const destination_size= row_pack_length();
 
377
  compatible= (source_size <= destination_size);
 
378
  if (compatible)
 
379
    compatible= (source_precision <= precision) &&
 
380
      (source_decimal <= decimals());
 
381
  return (compatible);
 
382
}
 
383
 
 
384
 
361
385
uint32_t Field_decimal::is_equal(CreateField *new_field_ptr)
362
386
{
363
387
  return ((new_field_ptr->sql_type == real_type()) &&
423
447
  return from+len;
424
448
}
425
449
 
426
 
} /* namespace drizzled */