27
27
#include "config.h"
28
29
#include <drizzled/error.h>
29
30
#include <drizzled/table.h>
30
31
#include <drizzled/session.h>
32
#include <drizzled/current_session.h>
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>
188
192
when set to NULL (TIMESTAMP fields which allow setting to NULL
189
193
are handled by first check).
191
if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
195
if (field->is_timestamp())
193
((Field_timestamp*) field)->set_time();
197
((field::Epoch::pointer) field)->set_time();
194
198
return 0; // Ok to set time to NULL
197
202
if (field == field->getTable()->next_number_field)
199
204
field->getTable()->auto_increment_field_not_null= false;
200
205
return 0; // field is set in fill_record()
202
208
if (field->getTable()->in_use->count_cuted_fields == CHECK_FIELD_WARN)
204
210
field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
207
214
if (!field->getTable()->in_use->no_errors)
208
215
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
375
387
static void do_cut_string(CopyField *copy)
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);
380
392
/* Check if we loosed any important characters */
381
393
if (cs->cset->scan(cs,
453
465
length= copy->to_length - 1;
454
466
if (copy->from_field->getTable()->in_use->count_cuted_fields)
455
468
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
456
469
ER_WARN_DATA_TRUNCATED, 1);
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)
475
489
if (current_session->count_cuted_fields)
476
491
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
477
492
ER_WARN_DATA_TRUNCATED, 1);
479
495
*copy->to_ptr= (unsigned char) length;
480
496
memcpy(copy->to_ptr + 1, from_ptr, length);
489
505
length=copy->to_length-HA_KEY_BLOB_LENGTH;
490
506
if (copy->from_field->getTable()->in_use->count_cuted_fields)
491
508
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
492
509
ER_WARN_DATA_TRUNCATED, 1);
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)
512
530
if (current_session->count_cuted_fields)
513
532
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
514
533
ER_WARN_DATA_TRUNCATED, 1);
516
536
int2store(copy->to_ptr, length);
517
537
memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
655
675
if (from_length != to_length || !compatible_db_low_byte_first)
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;
839
859
return to->store(result.c_ptr_quick(),result.length(),from->charset());
841
861
else if (from->result_type() == REAL_RESULT)
842
863
return to->store(from->val_real());
843
865
else if (from->result_type() == DECIMAL_RESULT)
846
868
return to->store_decimal(from->val_decimal(&buff));
849
872
return to->store(from->val_int(), test(from->flags & UNSIGNED_FLAG));
852
876
} /* namespace drizzled */