~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Joe Daly
  • Date: 2010-06-08 03:11:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1614.
  • Revision ID: skinny.moey@gmail.com-20100608031113-wt8o9k2bbyawwazs
add missing guard in header

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
 
25
25
#include "config.h"
 
26
#include <cstdio>
26
27
#include <errno.h>
27
28
#include <float.h>
28
29
#include "drizzled/sql_select.h"
373
374
 
374
375
void *Field::operator new(size_t size, memory::Root *mem_root)
375
376
{
376
 
  return alloc_root(mem_root, static_cast<uint32_t>(size));
 
377
  return mem_root->alloc_root(static_cast<uint32_t>(size));
377
378
}
378
379
 
379
380
enum_field_types Field::field_type_merge(enum_field_types a,
664
665
 
665
666
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
666
667
{
667
 
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->s->db_low_byte_first);
 
668
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->getShare()->db_low_byte_first);
668
669
  return(result);
669
670
}
670
671
 
702
703
 
703
704
const unsigned char *Field::unpack(unsigned char* to, const unsigned char *from)
704
705
{
705
 
  const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
 
706
  const unsigned char *result= unpack(to, from, 0U, table->getShare()->db_low_byte_first);
706
707
  return(result);
707
708
}
708
709
 
716
717
 
717
718
void Field::make_field(SendField *field)
718
719
{
719
 
  if (orig_table && orig_table->s->getSchemaName() && *orig_table->s->getSchemaName())
 
720
  if (orig_table && orig_table->getShare()->getSchemaName() && *orig_table->getShare()->getSchemaName())
720
721
  {
721
 
    field->db_name= orig_table->s->getSchemaName();
722
 
    field->org_table_name= orig_table->s->table_name.str;
 
722
    field->db_name= orig_table->getMutableShare()->getSchemaName();
 
723
    field->org_table_name= orig_table->getMutableShare()->getTableName();
723
724
  }
724
725
  else
725
726
    field->org_table_name= field->db_name= "";
754
755
  return i;
755
756
}
756
757
 
757
 
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
 
758
uint32_t Field::fill_cache_field(CacheField *copy)
758
759
{
759
760
  uint32_t store_length;
760
761
  copy->str=ptr;
764
765
  {
765
766
    copy->blob_field=(Field_blob*) this;
766
767
    copy->strip=0;
767
 
    copy->length-= table->s->blob_ptr_size;
 
768
    copy->length-= table->getShare()->blob_ptr_size;
768
769
    return copy->length;
769
770
  }
770
771
  else
811
812
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
812
813
{
813
814
  Field *tmp;
814
 
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
 
815
  if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
815
816
    return 0;
816
817
 
817
818
  if (tmp->table->maybe_null)
844
845
Field *Field::clone(memory::Root *root, Table *new_table)
845
846
{
846
847
  Field *tmp;
847
 
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
 
848
  if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
848
849
  {
849
850
    tmp->init(new_table);
850
851
    tmp->move_field_offset((ptrdiff_t) (new_table->record[0] -
851
 
                                           new_table->s->default_values));
 
852
                                           new_table->getDefaultValues()));
852
853
  }
853
854
  return tmp;
854
855
}
917
918
  return 0;                                     // This shouldn't happen
918
919
}
919
920
 
920
 
Field *make_field(TableShare *share,
921
 
                  memory::Root *root,
922
 
                  unsigned char *ptr,
923
 
                  uint32_t field_length,
924
 
                  bool is_nullable,
925
 
                  unsigned char *null_pos,
926
 
                  unsigned char null_bit,
927
 
                  uint8_t decimals,
928
 
                  enum_field_types field_type,
929
 
                  const CHARSET_INFO * field_charset,
930
 
                  Field::utype unireg_check,
931
 
                  TYPELIB *interval,
932
 
                  const char *field_name)
933
 
{
934
 
  if(! root)
935
 
    root= current_mem_root();
936
 
 
937
 
  if (! is_nullable)
938
 
  {
939
 
    null_pos=0;
940
 
    null_bit=0;
941
 
  }
942
 
  else
943
 
  {
944
 
    null_bit= ((unsigned char) 1) << null_bit;
945
 
  }
946
 
 
947
 
  switch (field_type) 
948
 
  {
949
 
  case DRIZZLE_TYPE_DATE:
950
 
  case DRIZZLE_TYPE_DATETIME:
951
 
  case DRIZZLE_TYPE_TIMESTAMP:
952
 
    field_charset= &my_charset_bin;
953
 
  default: break;
954
 
  }
955
 
 
956
 
  if (field_type == DRIZZLE_TYPE_VARCHAR ||
957
 
      field_type == DRIZZLE_TYPE_BLOB ||
958
 
      field_type == DRIZZLE_TYPE_ENUM)
959
 
  {
960
 
    if (field_type == DRIZZLE_TYPE_VARCHAR)
961
 
      return new (root) Field_varstring(ptr,field_length,
962
 
                                  HA_VARCHAR_PACKLENGTH(field_length),
963
 
                                  null_pos,null_bit,
964
 
                                  field_name,
965
 
                                  share,
966
 
                                  field_charset);
967
 
 
968
 
    if (field_type == DRIZZLE_TYPE_BLOB)
969
 
    {
970
 
      return new (root) Field_blob(ptr,
971
 
                                   null_pos,
972
 
                                   null_bit,
973
 
                                   field_name,
974
 
                                   share,
975
 
                                   calc_pack_length(DRIZZLE_TYPE_LONG, 0),
976
 
                                   field_charset);
977
 
    }
978
 
 
979
 
    if (interval)
980
 
    {
981
 
      return new (root) Field_enum(ptr,
982
 
                                   field_length,
983
 
                                   null_pos,
984
 
                                   null_bit,
985
 
                                   field_name,
986
 
                                   get_enum_pack_length(interval->count),
987
 
                                   interval,
988
 
                                   field_charset);
989
 
    }
990
 
  }
991
 
 
992
 
  switch (field_type)
993
 
  {
994
 
  case DRIZZLE_TYPE_DECIMAL:
995
 
    return new (root) Field_decimal(ptr,
996
 
                                    field_length,
997
 
                                    null_pos,
998
 
                                    null_bit,
999
 
                                    unireg_check,
1000
 
                                    field_name,
1001
 
                                    decimals,
1002
 
                                    false,
1003
 
                                    false /* is_unsigned */);
1004
 
  case DRIZZLE_TYPE_DOUBLE:
1005
 
    return new (root) Field_double(ptr,
1006
 
                                   field_length,
1007
 
                                   null_pos,
1008
 
                                   null_bit,
1009
 
                                   unireg_check,
1010
 
                                   field_name,
1011
 
                                   decimals,
1012
 
                                   false,
1013
 
                                   false /* is_unsigned */);
1014
 
  case DRIZZLE_TYPE_LONG:
1015
 
    return new (root) Field_long(ptr,
1016
 
                                 field_length,
1017
 
                                 null_pos,
1018
 
                                 null_bit,
1019
 
                                 unireg_check,
1020
 
                                 field_name,
1021
 
                                 false,
1022
 
                                 false /* is_unsigned */);
1023
 
  case DRIZZLE_TYPE_LONGLONG:
1024
 
    return new (root) Field_int64_t(ptr,
1025
 
                                    field_length,
1026
 
                                    null_pos,
1027
 
                                    null_bit,
1028
 
                                    unireg_check,
1029
 
                                    field_name,
1030
 
                                    false,
1031
 
                                    false /* is_unsigned */);
1032
 
  case DRIZZLE_TYPE_TIMESTAMP:
1033
 
    return new (root) Field_timestamp(ptr,
1034
 
                                      field_length,
1035
 
                                      null_pos,
1036
 
                                      null_bit,
1037
 
                                      unireg_check,
1038
 
                                      field_name,
1039
 
                                      share,
1040
 
                                      field_charset);
1041
 
  case DRIZZLE_TYPE_DATE:
1042
 
    return new (root) Field_date(ptr,
1043
 
                                 null_pos,
1044
 
                                 null_bit,
1045
 
                                 field_name,
1046
 
                                 field_charset);
1047
 
  case DRIZZLE_TYPE_DATETIME:
1048
 
    return new (root) Field_datetime(ptr,
1049
 
                                     null_pos,
1050
 
                                     null_bit,
1051
 
                                     field_name,
1052
 
                                     field_charset);
1053
 
  case DRIZZLE_TYPE_NULL:
1054
 
    return new (root) Field_null(ptr,
1055
 
                                 field_length,
1056
 
                                 field_name,
1057
 
                                 field_charset);
1058
 
  default: // Impossible (Wrong version)
1059
 
    break;
1060
 
  }
1061
 
  return 0;
1062
 
}
1063
 
 
1064
921
/*****************************************************************************
1065
922
 Warning handling
1066
923
*****************************************************************************/