~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Brian Aker
  • Date: 2011-02-14 05:47:07 UTC
  • mto: This revision was merged to the branch mainline in revision 2167.
  • Revision ID: brian@tangent.org-20110214054707-61nsqgg1g4w1zhx1
Merge in all changes for current_session, etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*/
26
26
 
27
27
#include "config.h"
 
28
 
28
29
#include <drizzled/error.h>
29
30
#include <drizzled/table.h>
30
31
#include <drizzled/session.h>
 
32
#include <drizzled/current_session.h>
31
33
 
32
 
#include <drizzled/field/str.h>
33
 
#include <drizzled/field/num.h>
 
34
#include <drizzled/copy_field.h>
34
35
#include <drizzled/field/blob.h>
35
 
#include <drizzled/field/enum.h>
36
 
#include <drizzled/field/null.h>
37
36
#include <drizzled/field/date.h>
 
37
#include <drizzled/field/datetime.h>
38
38
#include <drizzled/field/decimal.h>
39
 
#include <drizzled/field/real.h>
40
39
#include <drizzled/field/double.h>
 
40
#include <drizzled/field/enum.h>
 
41
#include <drizzled/field/epoch.h>
41
42
#include <drizzled/field/int32.h>
42
43
#include <drizzled/field/int64.h>
43
 
#include <drizzled/field/num.h>
44
 
#include <drizzled/field/timestamp.h>
45
 
#include <drizzled/field/datetime.h>
 
44
#include <drizzled/field/null.h>
 
45
#include <drizzled/field/num.h>
 
46
#include <drizzled/field/num.h>
 
47
#include <drizzled/field/real.h>
 
48
#include <drizzled/field/str.h>
46
49
#include <drizzled/field/varstring.h>
47
50
 
48
51
namespace drizzled
180
183
    field->reset();
181
184
    return 0;
182
185
  }
 
186
 
183
187
  if (no_conversions)
184
188
    return -1;
185
189
 
188
192
    when set to NULL (TIMESTAMP fields which allow setting to NULL
189
193
    are handled by first check).
190
194
  */
191
 
  if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
 
195
  if (field->is_timestamp())
192
196
  {
193
 
    ((Field_timestamp*) field)->set_time();
 
197
    ((field::Epoch::pointer) field)->set_time();
194
198
    return 0;                                   // Ok to set time to NULL
195
199
  }
 
200
 
196
201
  field->reset();
197
202
  if (field == field->getTable()->next_number_field)
198
203
  {
199
204
    field->getTable()->auto_increment_field_not_null= false;
200
205
    return 0;                             // field is set in fill_record()
201
206
  }
 
207
 
202
208
  if (field->getTable()->in_use->count_cuted_fields == CHECK_FIELD_WARN)
203
209
  {
204
210
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
205
211
    return 0;
206
212
  }
 
213
 
207
214
  if (!field->getTable()->in_use->no_errors)
208
215
    my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
 
216
 
209
217
  return -1;
210
218
}
211
219
 
278
286
  if (*copy->from_null_ptr & copy->from_bit)
279
287
  {
280
288
    /* Same as in set_field_to_null_with_conversions() */
281
 
    ((Field_timestamp*) copy->to_field)->set_time();
 
289
    ((field::Epoch::pointer) copy->to_field)->set_time();
282
290
  }
283
291
  else
 
292
  {
284
293
    (copy->do_copy2)(copy);
 
294
  }
285
295
}
286
296
 
287
297
 
294
304
    copy->to_field->reset();
295
305
  }
296
306
  else
 
307
  {
297
308
    (copy->do_copy2)(copy);
 
309
  }
298
310
}
299
311
 
300
312
 
362
374
 
363
375
static void do_field_decimal(CopyField *copy)
364
376
{
365
 
  my_decimal value;
 
377
  type::Decimal value;
366
378
  copy->to_field->store_decimal(copy->from_field->val_decimal(&value));
367
379
}
368
380
 
375
387
static void do_cut_string(CopyField *copy)
376
388
{
377
389
  const CHARSET_INFO * const cs= copy->from_field->charset();
378
 
  memcpy(copy->to_ptr,copy->from_ptr,copy->to_length);
 
390
  memcpy(copy->to_ptr, copy->from_ptr, copy->to_length);
379
391
 
380
392
  /* Check if we loosed any important characters */
381
393
  if (cs->cset->scan(cs,
452
464
  {
453
465
    length= copy->to_length - 1;
454
466
    if (copy->from_field->getTable()->in_use->count_cuted_fields)
 
467
    {
455
468
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
456
469
                                  ER_WARN_DATA_TRUNCATED, 1);
 
470
    }
457
471
  }
458
472
  *(unsigned char*) copy->to_ptr= (unsigned char) length;
459
473
  memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
473
487
  if (length < from_length)
474
488
  {
475
489
    if (current_session->count_cuted_fields)
 
490
    {
476
491
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
477
492
                                  ER_WARN_DATA_TRUNCATED, 1);
 
493
    }
478
494
  }
479
495
  *copy->to_ptr= (unsigned char) length;
480
496
  memcpy(copy->to_ptr + 1, from_ptr, length);
488
504
  {
489
505
    length=copy->to_length-HA_KEY_BLOB_LENGTH;
490
506
    if (copy->from_field->getTable()->in_use->count_cuted_fields)
 
507
    {
491
508
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
492
509
                                  ER_WARN_DATA_TRUNCATED, 1);
 
510
    }
493
511
  }
494
512
  int2store(copy->to_ptr,length);
495
513
  memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, copy->from_ptr + HA_KEY_BLOB_LENGTH,
510
528
  if (length < from_length)
511
529
  {
512
530
    if (current_session->count_cuted_fields)
 
531
    {
513
532
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
514
533
                                  ER_WARN_DATA_TRUNCATED, 1);
 
534
    }
515
535
  }
516
536
  int2store(copy->to_ptr, length);
517
537
  memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
611
631
    }
612
632
    else
613
633
    {
614
 
      if (to_field->type() == DRIZZLE_TYPE_TIMESTAMP)
 
634
      if (to_field->is_timestamp())
615
635
      {
616
636
        do_copy= do_copy_timestamp;               // Automatic timestamp
617
637
      }
655
675
    if (from_length != to_length || !compatible_db_low_byte_first)
656
676
    {
657
677
      // Correct pointer to point at char pointer
658
 
      to_ptr+= to_length - to->getTable()->getShare()->blob_ptr_size;
659
 
      from_ptr+= from_length- from->getTable()->getShare()->blob_ptr_size;
 
678
      to_ptr+= to_length - to->getTable()->getShare()->sizeBlobPtr();
 
679
      from_ptr+= from_length- from->getTable()->getShare()->sizeBlobPtr();
660
680
      return do_copy_blob;
661
681
    }
662
682
  }
839
859
    return to->store(result.c_ptr_quick(),result.length(),from->charset());
840
860
  }
841
861
  else if (from->result_type() == REAL_RESULT)
 
862
  {
842
863
    return to->store(from->val_real());
 
864
  }
843
865
  else if (from->result_type() == DECIMAL_RESULT)
844
866
  {
845
 
    my_decimal buff;
 
867
    type::Decimal buff;
846
868
    return to->store_decimal(from->val_decimal(&buff));
847
869
  }
848
870
  else
 
871
  {
849
872
    return to->store(from->val_int(), test(from->flags & UNSIGNED_FLAG));
 
873
  }
850
874
}
851
875
 
852
876
} /* namespace drizzled */