~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Monty Taylor
  • Date: 2008-11-17 07:23:53 UTC
  • mto: (589.1.3 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081117072353-tc8ykdsycno0cc5u
Split out a little more code. Removed table_list.h from common_includes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "sql_select.h"
29
29
#include <errno.h>
30
30
#include <drizzled/error.h>
 
31
#include <drizzled/virtual_column_info.h>
31
32
 
32
33
 
33
34
/*****************************************************************************
555
556
}
556
557
 
557
558
 
558
 
/**
559
 
  Detect Item_result by given field type of UNION merge result.
560
 
 
561
 
  @param field_type  given field type
562
 
 
563
 
  @return
564
 
    Item_result (type of internal MySQL expression result)
565
 
*/
566
 
 
567
559
Item_result Field::result_merge_type(enum_field_types field_type)
568
560
{
569
561
  assert(field_type <= DRIZZLE_TYPE_MAX);
570
562
  return field_types_result_type[field_type];
571
563
}
572
564
 
 
565
 
 
566
bool Field::eq(Field *field)
 
567
{
 
568
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
 
569
          null_bit == field->null_bit);
 
570
}
 
571
 
 
572
 
 
573
uint32_t Field::pack_length() const
 
574
{
 
575
  return field_length;
 
576
}
 
577
 
 
578
 
 
579
uint32_t Field::pack_length_in_rec() const
 
580
{
 
581
  return pack_length();
 
582
}
 
583
 
 
584
 
 
585
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
586
{
 
587
  return field_metadata;
 
588
}
 
589
 
 
590
 
 
591
uint32_t Field::row_pack_length()
 
592
{
 
593
  return 0;
 
594
}
 
595
 
 
596
 
 
597
int Field::save_field_metadata(unsigned char *first_byte)
 
598
{
 
599
  return do_save_field_metadata(first_byte);
 
600
}
 
601
 
 
602
 
 
603
uint32_t Field::data_length()
 
604
{
 
605
  return pack_length();
 
606
}
 
607
 
 
608
 
 
609
uint32_t Field::used_length()
 
610
{
 
611
  return pack_length();
 
612
}
 
613
 
 
614
 
 
615
uint32_t Field::sort_length() const
 
616
{
 
617
  return pack_length();
 
618
}
 
619
 
 
620
 
 
621
uint32_t Field::max_data_length() const
 
622
{
 
623
  return pack_length();
 
624
}
 
625
 
 
626
 
 
627
int Field::reset(void)
 
628
{
 
629
  memset(ptr, 0, pack_length());
 
630
  return 0;
 
631
}
 
632
 
 
633
 
 
634
void Field::reset_fields()
 
635
{}
 
636
 
 
637
 
 
638
void Field::set_default()
 
639
{
 
640
  my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
 
641
  memcpy(ptr, ptr + l_offset, pack_length());
 
642
  if (null_ptr)
 
643
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
644
}
 
645
 
 
646
 
 
647
bool Field::binary() const
 
648
{
 
649
  return 1;
 
650
}
 
651
 
 
652
 
 
653
bool Field::zero_pack() const
 
654
{
 
655
  return 1;
 
656
}
 
657
 
 
658
 
 
659
enum ha_base_keytype Field::key_type() const
 
660
{
 
661
  return HA_KEYTYPE_BINARY;
 
662
}
 
663
 
 
664
 
 
665
uint32_t Field::key_length() const
 
666
{
 
667
  return pack_length();
 
668
}
 
669
 
 
670
 
 
671
enum_field_types Field::real_type() const
 
672
{
 
673
  return type();
 
674
}
 
675
 
 
676
 
 
677
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
 
678
{
 
679
  return cmp(a, b);
 
680
}
 
681
 
 
682
 
 
683
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
 
684
{
 
685
  return memcmp(a,b,pack_length());
 
686
}
 
687
 
 
688
 
 
689
int Field::cmp_offset(uint32_t row_offset)
 
690
{
 
691
  return cmp(ptr,ptr+row_offset);
 
692
}
 
693
 
 
694
 
 
695
int Field::cmp_binary_offset(uint32_t row_offset)
 
696
{
 
697
  return cmp_binary(ptr, ptr+row_offset);
 
698
}
 
699
 
 
700
 
 
701
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
 
702
{
 
703
  return cmp(a, b);
 
704
}
 
705
 
 
706
 
 
707
int Field::key_cmp(const unsigned char *str, uint32_t)
 
708
{
 
709
  return cmp(ptr,str);
 
710
}
 
711
 
 
712
 
 
713
uint32_t Field::decimals() const
 
714
{
 
715
  return 0;
 
716
}
 
717
 
 
718
 
 
719
bool Field::is_null(my_ptrdiff_t row_offset)
 
720
{
 
721
  return null_ptr ?
 
722
    (null_ptr[row_offset] & null_bit ? true : false) :
 
723
    table->null_row;
 
724
}
 
725
 
 
726
 
 
727
bool Field::is_real_null(my_ptrdiff_t row_offset)
 
728
{
 
729
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
 
730
}
 
731
 
 
732
 
 
733
bool Field::is_null_in_record(const unsigned char *record)
 
734
{
 
735
  if (!null_ptr)
 
736
    return false;
 
737
  return test(record[(uint32_t) (null_ptr -table->record[0])] &
 
738
              null_bit);
 
739
}
 
740
 
 
741
 
 
742
bool Field::is_null_in_record_with_offset(my_ptrdiff_t offset)
 
743
{
 
744
  if (!null_ptr)
 
745
    return false;
 
746
  return test(null_ptr[offset] & null_bit);
 
747
}
 
748
 
 
749
 
 
750
void Field::set_null(my_ptrdiff_t row_offset)
 
751
{
 
752
  if (null_ptr)
 
753
    null_ptr[row_offset]|= null_bit;
 
754
}
 
755
 
 
756
 
 
757
void Field::set_notnull(my_ptrdiff_t row_offset)
 
758
{
 
759
  if (null_ptr)
 
760
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
 
761
}
 
762
 
 
763
 
 
764
bool Field::maybe_null(void)
 
765
{
 
766
  return null_ptr != 0 || table->maybe_null;
 
767
}
 
768
 
 
769
 
 
770
bool Field::real_maybe_null(void)
 
771
{
 
772
  return null_ptr != 0;
 
773
}
 
774
 
 
775
 
 
776
size_t Field::last_null_byte() const
 
777
{
 
778
  size_t bytes= do_last_null_byte();
 
779
  assert(bytes <= table->getNullBytes());
 
780
  return bytes;
 
781
}
 
782
 
 
783
 
573
784
/*****************************************************************************
574
785
  Static help functions
575
786
*****************************************************************************/
576
787
 
577
 
 
578
 
/**
579
 
  Check whether a field type can be partially indexed by a key.
580
 
 
581
 
  This is a static method, rather than a virtual function, because we need
582
 
  to check the type of a non-Field in mysql_alter_table().
583
 
 
584
 
  @param type  field type
585
 
 
586
 
  @retval
587
 
    true  Type can have a prefixed key
588
 
  @retval
589
 
    false Type can not have a prefixed key
590
 
*/
591
 
 
592
788
bool Field::type_can_have_key_part(enum enum_field_types type)
593
789
{
594
790
  switch (type) {
629
825
}
630
826
 
631
827
 
 
828
void Field::init(Table *table_arg)
 
829
{
 
830
  orig_table= table= table_arg;
 
831
  table_name= &table_arg->alias;
 
832
}
 
833
 
 
834
 
632
835
#ifdef NOT_USED
633
836
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
634
837
{
709
912
 
710
913
/// This is used as a table name when the table structure is not set up
711
914
Field::Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
712
 
             unsigned char null_bit_arg,
713
 
             utype unireg_check_arg, const char *field_name_arg)
 
915
             unsigned char null_bit_arg,
 
916
             utype unireg_check_arg, const char *field_name_arg)
714
917
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
715
918
   table(0), orig_table(0), table_name(0),
716
919
   field_name(field_name_arg),
717
920
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
718
921
   part_of_sortkey(0), unireg_check(unireg_check_arg),
719
 
   field_length(length_arg), null_bit(null_bit_arg), 
 
922
   field_length(length_arg), null_bit(null_bit_arg),
720
923
   is_created_from_null_item(false),
721
924
   vcol_info(NULL), is_stored(true)
722
925
{
756
959
  memcpy(ptr,ptr+row_offset,pack_length());
757
960
  if (null_ptr)
758
961
  {
759
 
    *null_ptr= (unsigned char) ((null_ptr[0] & (unsigned char) ~(uint32_t) null_bit) | (null_ptr[row_offset] & (unsigned char) null_bit));
 
962
    *null_ptr= (unsigned char) ((null_ptr[0] &
 
963
                                 (unsigned char) ~(uint32_t) null_bit) |
 
964
                                (null_ptr[row_offset] &
 
965
                                 (unsigned char) null_bit));
760
966
  }
761
967
}
762
968
 
774
980
   Check to see if field size is compatible with destination.
775
981
 
776
982
   This method is used in row-based replication to verify that the slave's
777
 
   field size is less than or equal to the master's field size. The 
 
983
   field size is less than or equal to the master's field size. The
778
984
   encoded field metadata (from the master or source) is decoded and compared
779
 
   to the size of this field (the slave or destination). 
 
985
   to the size of this field (the slave or destination).
780
986
 
781
987
   @param   field_metadata   Encoded size in field metadata
782
988
 
791
997
}
792
998
 
793
999
 
794
 
int Field::store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
1000
int Field::store(const char *to, uint32_t length,
 
1001
                 const CHARSET_INFO * const cs,
795
1002
                 enum_check_fields check_level)
796
1003
{
797
1004
  int res;
850
1057
  return to+length;
851
1058
}
852
1059
 
 
1060
 
 
1061
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
 
1062
{
 
1063
  unsigned char *result= this->pack(to, from, UINT32_MAX,
 
1064
                                    table->s->db_low_byte_first);
 
1065
  return(result);
 
1066
}
 
1067
 
 
1068
 
853
1069
/**
854
1070
   Unpack a field from row data.
855
1071
 
912
1128
}
913
1129
 
914
1130
 
 
1131
const unsigned char *Field::unpack(unsigned char* to,
 
1132
                                   const unsigned char *from)
 
1133
{
 
1134
  const unsigned char *result= unpack(to, from, 0U,
 
1135
                                      table->s->db_low_byte_first);
 
1136
  return(result);
 
1137
}
 
1138
 
 
1139
 
 
1140
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
 
1141
{
 
1142
  return length;
 
1143
}
 
1144
 
 
1145
 
 
1146
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
 
1147
                    uint32_t, bool)
 
1148
{
 
1149
  return cmp(a,b);
 
1150
}
 
1151
 
 
1152
 
 
1153
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
 
1154
{
 
1155
  return cmp(ptr,b);
 
1156
}
 
1157
 
 
1158
 
915
1159
my_decimal *Field::val_decimal(my_decimal *)
916
1160
{
917
1161
  /* This never have to be called */