~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Jay Pipes
  • Date: 2009-06-11 05:42:17 UTC
  • mto: This revision was merged to the branch mainline in revision 1061.
  • Revision ID: jpipes@serialcoder-20090611054217-tftdcifxxrnhjh90
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "drizzled/sql_bitmap.h"
32
32
#include "drizzled/sql_list.h"
33
33
#include "drizzled/structs.h"
34
 
#include "drizzled/table.h"
35
34
 
36
35
#include <string>
37
36
 
348
347
    return false;
349
348
  }
350
349
  virtual void free() {}
351
 
  virtual Field *new_field(MEM_ROOT *root, Table *new_table,
 
350
  virtual Field *new_field(MEM_ROOT *root, 
 
351
                           Table *new_table,
352
352
                           bool keep_type);
353
353
  virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
354
 
                               unsigned char *new_ptr, unsigned char *new_null_ptr,
 
354
                               unsigned char *new_ptr, 
 
355
                               unsigned char *new_null_ptr,
355
356
                               uint32_t new_null_bit);
356
357
  /** This is used to generate a field in Table from TableShare */
357
358
  Field *clone(MEM_ROOT *mem_root, Table *new_table);
358
359
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
359
360
  {
360
 
    ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
 
361
    ptr= ptr_arg;
 
362
    null_ptr= null_ptr_arg;
 
363
    null_bit= null_bit_arg;
361
364
  }
362
365
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
363
 
  virtual void move_field_offset(my_ptrdiff_t ptr_diff)
 
366
  virtual void move_field_offset(ptrdiff_t ptr_diff)
364
367
  {
365
 
    ptr=ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
 
368
    ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
366
369
    if (null_ptr)
367
 
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
 
370
      null_ptr= ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
368
371
  }
369
372
  virtual void get_image(unsigned char *buff, uint32_t length, const CHARSET_INFO * const)
370
373
  {
747
750
  }
748
751
};
749
752
 
750
 
/**
751
 
 * Class representing a field in a CREATE TABLE statement
752
 
 */
753
 
class Create_field :public Sql_alloc
754
 
{
755
 
public:
756
 
  const char *field_name;
757
 
  const char *change;                   // If done with alter table
758
 
  const char *after;                    // Put column after this one
759
 
  LEX_STRING comment;                   // Comment for field
760
 
  Item  *def;                           // Default value
761
 
  enum  enum_field_types sql_type;
762
 
  /*
763
 
    At various stages in execution this can be length of field in bytes or
764
 
    max number of characters.
765
 
  */
766
 
  uint32_t length;
767
 
  /*
768
 
    The value of `length' as set by parser: is the number of characters
769
 
    for most of the types, or of bytes for BLOBs or numeric types.
770
 
  */
771
 
  uint32_t char_length;
772
 
  uint32_t  decimals, flags, pack_length, key_length;
773
 
  Field::utype unireg_check;
774
 
  TYPELIB *interval;                    // Which interval to use
775
 
  List<String> interval_list;
776
 
  const CHARSET_INFO *charset;
777
 
  Field *field;                         // For alter table
778
 
 
779
 
  uint8_t       interval_id;    // For rea_create_table
780
 
  uint32_t      offset,pack_flag;
781
 
 
782
 
  Create_field() :after(0) {}
783
 
  Create_field(Field *field, Field *orig_field);
784
 
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
785
 
  Create_field *clone(MEM_ROOT *mem_root) const
786
 
    { return new (mem_root) Create_field(*this); }
787
 
  void create_length_to_internal_length(void);
788
 
 
789
 
  inline enum column_format_type column_format() const
790
 
  {
791
 
    return (enum column_format_type)
792
 
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
793
 
  }
794
 
 
795
 
  /* Init for a tmp table field. To be extended if need be. */
796
 
  void init_for_tmp_table(enum_field_types sql_type_arg,
797
 
                          uint32_t max_length, uint32_t decimals,
798
 
                          bool maybe_null, bool is_unsigned);
799
 
 
800
 
  /**
801
 
    Initialize field definition for create.
802
 
 
803
 
    @param session                   Thread handle
804
 
    @param fld_name              Field name
805
 
    @param fld_type              Field type
806
 
    @param fld_length            Field length
807
 
    @param fld_decimals          Decimal (if any)
808
 
    @param fld_type_modifier     Additional type information
809
 
    @param fld_default_value     Field default value (if any)
810
 
    @param fld_on_update_value   The value of ON UPDATE clause
811
 
    @param fld_comment           Field comment
812
 
    @param fld_change            Field change
813
 
    @param fld_interval_list     Interval list (if any)
814
 
    @param fld_charset           Field charset
815
 
 
816
 
    @retval
817
 
      false on success
818
 
    @retval
819
 
      true  on error
820
 
  */
821
 
  bool init(Session *session,
822
 
            char *field_name,
823
 
            enum_field_types type,
824
 
            char *length,
825
 
            char *decimals,
826
 
            uint32_t type_modifier,
827
 
            Item *default_value,
828
 
            Item *on_update_value,
829
 
            LEX_STRING *comment,
830
 
            char *change,
831
 
            List<String> *interval_list,
832
 
            const CHARSET_INFO * const cs,
833
 
            uint32_t uint_geom_type,
834
 
            enum column_format_type column_format);
835
 
};
836
 
 
837
 
/**
838
 
 * A class for sending field information to the client
 
753
#include "drizzled/create_field.h"
 
754
 
 
755
/**
 
756
 * A class for sending field information to a client.
 
757
 *
 
758
 * @details
 
759
 *
 
760
 * Send_field is basically a stripped-down POD class for
 
761
 * representing basic information about a field...
839
762
 */
840
763
class Send_field 
841
764
{
842
765
public:
843
766
  const char *db_name;
844
 
  const char *table_name,*org_table_name;
845
 
  const char *col_name,*org_col_name;
 
767
  const char *table_name;
 
768
  const char *org_table_name;
 
769
  const char *col_name;
 
770
  const char *org_col_name;
846
771
  uint32_t length;
847
 
  uint32_t charsetnr, flags, decimals;
 
772
  uint32_t charsetnr;
 
773
  uint32_t flags;
 
774
  uint32_t decimals;
848
775
  enum_field_types type;
849
776
  Send_field() {}
850
777
};
861
788
  typedef void Copy_func(Copy_field*);
862
789
  Copy_func *get_copy_func(Field *to, Field *from);
863
790
public:
864
 
  unsigned char *from_ptr,*to_ptr;
865
 
  unsigned char *from_null_ptr,*to_null_ptr;
 
791
  unsigned char *from_ptr;
 
792
  unsigned char *to_ptr;
 
793
  unsigned char *from_null_ptr;
 
794
  unsigned char *to_null_ptr;
866
795
  bool *null_row;
867
 
  uint32_t      from_bit,to_bit;
868
 
  uint32_t from_length,to_length;
869
 
  Field *from_field,*to_field;
 
796
  uint32_t from_bit;
 
797
  uint32_t to_bit;
 
798
  uint32_t from_length;
 
799
  uint32_t to_length;
 
800
  Field *from_field;
 
801
  Field *to_field;
870
802
  String tmp;                                   // For items
871
803
 
872
804
  Copy_field() {}