~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Stewart Smith
  • Date: 2009-12-02 06:01:21 UTC
  • mto: (1237.1.2 push)
  • mto: This revision was merged to the branch mainline in revision 1238.
  • Revision ID: stewart@flamingspork.com-20091202060121-68gyfqifqcjcmi2v
my_end() no longer requires an argument (we removed them all)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 * @file This file implements the Field class and API
23
23
 */
24
24
 
25
 
#include "config.h"
 
25
#include "drizzled/server_includes.h"
26
26
#include <errno.h>
27
 
#include <float.h>
28
27
#include "drizzled/sql_select.h"
29
28
#include "drizzled/error.h"
30
29
#include "drizzled/field/str.h"
42
41
#include "drizzled/field/timestamp.h"
43
42
#include "drizzled/field/datetime.h"
44
43
#include "drizzled/field/varstring.h"
45
 
#include "drizzled/time_functions.h"
46
 
#include "drizzled/internal/m_string.h"
47
 
 
48
 
namespace drizzled
49
 
{
50
44
 
51
45
/*****************************************************************************
52
46
  Instansiate templates and static variables
53
47
*****************************************************************************/
54
48
 
 
49
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
 
50
template class List<CreateField>;
 
51
template class List_iterator<CreateField>;
 
52
#endif
 
53
 
55
54
static enum_field_types
56
55
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
57
56
{
366
365
  return (str < strend);
367
366
}
368
367
 
369
 
void *Field::operator new(size_t size)
370
 
{
371
 
  return memory::sql_alloc(size);
372
 
}
373
 
 
374
 
void *Field::operator new(size_t size, memory::Root *mem_root)
375
 
{
376
 
  return alloc_root(mem_root, static_cast<uint32_t>(size));
377
 
}
378
 
 
379
368
enum_field_types Field::field_type_merge(enum_field_types a,
380
369
                                         enum_field_types b)
381
370
{
406
395
  return pack_length();
407
396
}
408
397
 
 
398
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
399
{
 
400
  return field_metadata;
 
401
}
 
402
 
 
403
uint32_t Field::row_pack_length()
 
404
{
 
405
  return 0;
 
406
}
 
407
 
 
408
int Field::save_field_metadata(unsigned char *first_byte)
 
409
{
 
410
  return do_save_field_metadata(first_byte);
 
411
}
 
412
 
409
413
uint32_t Field::data_length()
410
414
{
411
415
  return pack_length();
586
590
  table_name= &table_arg->alias;
587
591
}
588
592
 
 
593
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
 
594
{
 
595
  const CHARSET_INFO * const cs= &my_charset_bin;
 
596
  uint32_t length;
 
597
  int64_t value= val_int();
 
598
 
 
599
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
 
600
    return 0;
 
601
  length= (uint32_t) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
 
602
                                                MY_INT64_NUM_DECIMAL_DIGITS,
 
603
                                                unsigned_val ? 10 : -10,
 
604
                                                value);
 
605
  val_buffer->length(length);
 
606
  return val_buffer;
 
607
}
 
608
 
589
609
/// This is used as a table name when the table structure is not set up
590
610
Field::Field(unsigned char *ptr_arg,
591
611
             uint32_t length_arg,
641
661
  }
642
662
}
643
663
 
 
664
int Field::compatible_field_size(uint32_t field_metadata)
 
665
{
 
666
  uint32_t const source_size= pack_length_from_metadata(field_metadata);
 
667
  uint32_t const destination_size= row_pack_length();
 
668
  return (source_size <= destination_size);
 
669
}
 
670
 
644
671
int Field::store(const char *to, 
645
672
                 uint32_t length,
646
673
                 const CHARSET_INFO * const cs,
706
733
  return(result);
707
734
}
708
735
 
 
736
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
 
737
{
 
738
  return length;
 
739
}
 
740
 
 
741
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
 
742
                    uint32_t, bool)
 
743
{
 
744
  return cmp(a,b);
 
745
}
 
746
 
 
747
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
 
748
{
 
749
  return cmp(ptr,b);
 
750
}
 
751
 
709
752
my_decimal *Field::val_decimal(my_decimal *)
710
753
{
711
754
  /* This never have to be called */
716
759
 
717
760
void Field::make_field(SendField *field)
718
761
{
719
 
  if (orig_table && orig_table->s->getSchemaName() && *orig_table->s->getSchemaName())
 
762
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
720
763
  {
721
 
    field->db_name= orig_table->s->getSchemaName();
 
764
    field->db_name= orig_table->s->db.str;
722
765
    field->org_table_name= orig_table->s->table_name.str;
723
766
  }
724
767
  else
803
846
  return store(buff, length, &my_charset_bin);
804
847
}
805
848
 
806
 
bool Field::optimize_range(uint32_t idx, uint32_t)
 
849
bool Field::optimize_range(uint32_t idx, uint32_t part)
807
850
{
808
 
  return test(table->index_flags(idx) & HA_READ_RANGE);
 
851
  return test(table->cursor->index_flags(idx, part, 1) & HA_READ_RANGE);
809
852
}
810
853
 
811
 
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
 
854
Field *Field::new_field(MEM_ROOT *root, Table *new_table, bool)
812
855
{
813
856
  Field *tmp;
814
857
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
821
864
  tmp->part_of_key.reset();
822
865
  tmp->part_of_sortkey.reset();
823
866
  tmp->unireg_check= Field::NONE;
824
 
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
 
867
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
825
868
  tmp->reset_fields();
826
869
  return tmp;
827
870
}
828
871
 
829
 
Field *Field::new_key_field(memory::Root *root, Table *new_table,
 
872
Field *Field::new_key_field(MEM_ROOT *root, Table *new_table,
830
873
                            unsigned char *new_ptr,
831
874
                            unsigned char *new_null_ptr,
832
875
                            uint32_t new_null_bit)
841
884
  return tmp;
842
885
}
843
886
 
844
 
Field *Field::clone(memory::Root *root, Table *new_table)
 
887
Field *Field::clone(MEM_ROOT *root, Table *new_table)
845
888
{
846
889
  Field *tmp;
847
890
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
885
928
  return 1;
886
929
}
887
930
 
 
931
/*
 
932
  Make a field from the .frm file info
 
933
*/
888
934
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
889
935
{
890
936
  switch (type) {
918
964
}
919
965
 
920
966
Field *make_field(TableShare *share,
921
 
                  memory::Root *root,
 
967
                  MEM_ROOT *root,
922
968
                  unsigned char *ptr,
923
969
                  uint32_t field_length,
924
970
                  bool is_nullable,
1111
1157
      set_warning(level, code, cuted_increment))
1112
1158
  {
1113
1159
    char str_nr[22];
1114
 
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
 
1160
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
1115
1161
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1116
1162
                                 ts_type, field_name);
1117
1163
  }
1128
1174
  {
1129
1175
    /* DBL_DIG is enough to print '-[digits].E+###' */
1130
1176
    char str_nr[DBL_DIG + 8];
1131
 
    uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
 
1177
    uint32_t str_len= sprintf(str_nr, "%g", nr);
1132
1178
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
1133
1179
                                 field_name);
1134
1180
  }
1159
1205
  else
1160
1206
    table->clearWriteSet(field_index);
1161
1207
}
1162
 
 
1163
 
} /* namespace drizzled */