~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/field.h

  • Committer: Monty Taylor
  • Date: 2008-07-09 15:52:52 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 112.
  • Revision ID: monty@inaugust.com-20080709155252-lnzmxxje1g40z3a7
Warning fixes. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
  virtual String *val_str(String*,String *)=0;
128
128
  String *val_int_as_str(String *val_buffer, my_bool unsigned_flag);
129
129
  /*
130
 
   str_needs_quotes() returns true if the value returned by val_str() needs
 
130
   str_needs_quotes() returns TRUE if the value returned by val_str() needs
131
131
   to be quoted when used in constructing an SQL query.
132
132
  */
133
 
  virtual bool str_needs_quotes() { return false; }
 
133
  virtual bool str_needs_quotes() { return FALSE; }
134
134
  virtual Item_result result_type () const=0;
135
135
  virtual Item_result cmp_type () const { return result_type(); }
136
136
  virtual Item_result cast_to_int_type () const { return result_type(); }
163
163
  /*
164
164
    This method is used to return the size of the data in a row-based
165
165
    replication row record. The default implementation of returning 0 is
166
 
    designed to allow fields that do not use metadata to return true (1)
 
166
    designed to allow fields that do not use metadata to return TRUE (1)
167
167
    from compatible_field_size() which uses this function in the comparison.
168
168
    The default value for field metadata for fields that do not have 
169
169
    metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
283
283
   */
284
284
  size_t last_null_byte() const {
285
285
    size_t bytes= do_last_null_byte();
286
 
    assert(bytes <= table->s->null_bytes);
 
286
    DBUG_PRINT("debug", ("last_null_byte() ==> %ld", (long) bytes));
 
287
    DBUG_ASSERT(bytes <= table->s->null_bytes);
287
288
    return bytes;
288
289
  }
289
290
 
297
298
    use field->val_int() for comparison.  Used to optimize clauses like
298
299
    'a_column BETWEEN date_const, date_const'.
299
300
  */
300
 
  virtual bool can_be_compared_as_longlong() const { return false; }
 
301
  virtual bool can_be_compared_as_longlong() const { return FALSE; }
301
302
  virtual void free() {}
302
303
  virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
303
304
                           bool keep_type);
391
392
  */
392
393
  uchar *pack(uchar *to, const uchar *from)
393
394
  {
 
395
    DBUG_ENTER("Field::pack");
394
396
    uchar *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
395
 
    return(result);
 
397
    DBUG_RETURN(result);
396
398
  }
397
399
 
398
400
  virtual const uchar *unpack(uchar* to, const uchar *from,
402
404
  */
403
405
  const uchar *unpack(uchar* to, const uchar *from)
404
406
  {
 
407
    DBUG_ENTER("Field::unpack");
405
408
    const uchar *result= unpack(to, from, 0U, table->s->db_low_byte_first);
406
 
    return(result);
 
409
    DBUG_RETURN(result);
407
410
  }
408
411
 
409
412
  virtual uchar *pack_key(uchar* to, const uchar *from,
445
448
  virtual bool get_time(MYSQL_TIME *ltime);
446
449
  virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
447
450
  virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
448
 
  virtual bool has_charset(void) const { return false; }
 
451
  virtual bool has_charset(void) const { return FALSE; }
449
452
  virtual void set_charset(CHARSET_INFO *charset_arg __attribute__((__unused__)))
450
453
  { }
451
454
  virtual enum Derivation derivation(void) const
492
495
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
493
496
  }
494
497
 
 
498
#ifndef DBUG_OFF
 
499
  /* Print field value into debug trace, in NULL-aware way. */
 
500
  void dbug_print()
 
501
  {
 
502
    if (is_real_null())
 
503
      fprintf(DBUG_FILE, "NULL");
 
504
    else
 
505
    {
 
506
      char buf[256];
 
507
      String str(buf, sizeof(buf), &my_charset_bin);
 
508
      str.length(0);
 
509
      String *pstr;
 
510
      pstr= val_str(&str);
 
511
      fprintf(DBUG_FILE, "'%s'", pstr->c_ptr_safe());
 
512
    }
 
513
  }
 
514
#endif
 
515
 
495
516
  /* Hash value */
496
517
  virtual void hash(ulong *nr, ulong *nr2);
497
518
  friend bool reopen_table(THD *,struct st_table *,bool);
590
611
  uint32 max_display_length() { return field_length; }
591
612
  friend class Create_field;
592
613
  my_decimal *val_decimal(my_decimal *);
593
 
  virtual bool str_needs_quotes() { return true; }
 
614
  virtual bool str_needs_quotes() { return TRUE; }
594
615
  bool compare_str_field_flags(Create_field *new_field, uint32 flags);
595
616
  uint is_equal(Create_field *new_field);
596
617
};
813
834
  }
814
835
};
815
836
 
 
837
class Field_medium :public Field_num {
 
838
public:
 
839
  Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
840
              uchar null_bit_arg,
 
841
              enum utype unireg_check_arg, const char *field_name_arg,
 
842
              bool zero_arg, bool unsigned_arg)
 
843
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
844
               unireg_check_arg, field_name_arg,
 
845
               0, zero_arg,unsigned_arg)
 
846
    {}
 
847
  enum Item_result result_type () const { return INT_RESULT; }
 
848
  enum_field_types type() const { return MYSQL_TYPE_INT24;}
 
849
  enum ha_base_keytype key_type() const
 
850
    { return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; }
 
851
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
852
  int store(double nr);
 
853
  int store(longlong nr, bool unsigned_val);
 
854
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
 
855
  double val_real(void);
 
856
  longlong val_int(void);
 
857
  String *val_str(String*,String *);
 
858
  bool send_binary(Protocol *protocol);
 
859
  int cmp(const uchar *,const uchar *);
 
860
  void sort_string(uchar *buff,uint length);
 
861
  uint32 pack_length() const { return 3; }
 
862
  void sql_type(String &str) const;
 
863
  uint32 max_display_length() { return 8; }
 
864
 
 
865
  virtual uchar *pack(uchar* to, const uchar *from,
 
866
                      uint max_length, bool low_byte_first)
 
867
  {
 
868
    return Field::pack(to, from, max_length, low_byte_first);
 
869
  }
 
870
 
 
871
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
872
                              uint param_data, bool low_byte_first)
 
873
  {
 
874
    return Field::unpack(to, from, param_data, low_byte_first);
 
875
  }
 
876
};
 
877
 
 
878
 
816
879
class Field_long :public Field_num {
817
880
public:
818
881
  Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
925
988
  void sort_string(uchar *buff,uint length);
926
989
  uint32 pack_length() const { return 8; }
927
990
  void sql_type(String &str) const;
928
 
  bool can_be_compared_as_longlong() const { return true; }
 
991
  bool can_be_compared_as_longlong() const { return TRUE; }
929
992
  uint32 max_display_length() { return 20; }
930
993
  virtual uchar *pack(uchar* to, const uchar *from,
931
994
                      uint max_length __attribute__((__unused__)),
1112
1175
  void sort_string(uchar *buff,uint length);
1113
1176
  uint32 pack_length() const { return 4; }
1114
1177
  void sql_type(String &str) const;
1115
 
  bool can_be_compared_as_longlong() const { return true; }
 
1178
  bool can_be_compared_as_longlong() const { return TRUE; }
1116
1179
  bool zero_pack() const { return 0; }
1117
1180
  void set_time();
1118
1181
  virtual void set_default()
1170
1233
  String *val_str(String*,String *);
1171
1234
  bool send_binary(Protocol *protocol);
1172
1235
  void sql_type(String &str) const;
1173
 
  bool can_be_compared_as_longlong() const { return true; }
 
1236
  bool can_be_compared_as_longlong() const { return TRUE; }
1174
1237
};
1175
1238
 
1176
1239
 
1203
1266
  void sort_string(uchar *buff,uint length);
1204
1267
  uint32 pack_length() const { return 3; }
1205
1268
  void sql_type(String &str) const;
1206
 
  bool can_be_compared_as_longlong() const { return true; }
 
1269
  bool can_be_compared_as_longlong() const { return TRUE; }
1207
1270
  bool zero_pack() const { return 1; }
1208
1271
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1209
1272
  bool get_time(MYSQL_TIME *ltime);
1240
1303
  void sort_string(uchar *buff,uint length);
1241
1304
  uint32 pack_length() const { return 3; }
1242
1305
  void sql_type(String &str) const;
1243
 
  bool can_be_compared_as_longlong() const { return true; }
 
1306
  bool can_be_compared_as_longlong() const { return TRUE; }
1244
1307
  bool zero_pack() const { return 1; }
1245
1308
};
1246
1309
 
1278
1341
  void sort_string(uchar *buff,uint length);
1279
1342
  uint32 pack_length() const { return 8; }
1280
1343
  void sql_type(String &str) const;
1281
 
  bool can_be_compared_as_longlong() const { return true; }
 
1344
  bool can_be_compared_as_longlong() const { return TRUE; }
1282
1345
  bool zero_pack() const { return 1; }
1283
1346
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1284
1347
  bool get_time(MYSQL_TIME *ltime);
1339
1402
  uint size_of() const { return sizeof(*this); }
1340
1403
  enum_field_types real_type() const { return MYSQL_TYPE_STRING; }
1341
1404
  bool has_charset(void) const
1342
 
  { return charset() == &my_charset_bin ? false : true; }
 
1405
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
1343
1406
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1344
1407
  virtual uint get_key_image(uchar *buff,uint length, imagetype type);
1345
1408
private:
1427
1490
  uint size_of() const { return sizeof(*this); }
1428
1491
  enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
1429
1492
  bool has_charset(void) const
1430
 
  { return charset() == &my_charset_bin ? false : true; }
 
1493
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
1431
1494
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1432
1495
  Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
1433
1496
                       uchar *new_ptr, uchar *new_null_ptr,
1602
1665
  friend int field_conv(Field *to,Field *from);
1603
1666
  uint size_of() const { return sizeof(*this); }
1604
1667
  bool has_charset(void) const
1605
 
  { return charset() == &my_charset_bin ? false : true; }
 
1668
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
1606
1669
  uint32 max_display_length();
1607
1670
  uint is_equal(Create_field *new_field);
1608
1671
  inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
1655
1718
                      uint part __attribute__((__unused__)))
1656
1719
  { return 0; }
1657
1720
  bool eq_def(Field *field);
1658
 
  bool has_charset(void) const { return true; }
 
1721
  bool has_charset(void) const { return TRUE; }
1659
1722
  /* enum and set are sorted as integers */
1660
1723
  CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
1661
1724
private:
1678
1741
      flags=(flags & ~ENUM_FLAG) | SET_FLAG;
1679
1742
    }
1680
1743
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1681
 
  int  store(double nr) { return Field_set::store((longlong) nr, false); }
 
1744
  int  store(double nr) { return Field_set::store((longlong) nr, FALSE); }
1682
1745
  int  store(longlong nr, bool unsigned_val);
1683
1746
 
1684
1747
  virtual bool zero_pack() const { return 1; }
1685
1748
  String *val_str(String*,String *);
1686
1749
  void sql_type(String &str) const;
1687
1750
  enum_field_types real_type() const { return MYSQL_TYPE_SET; }
1688
 
  bool has_charset(void) const { return true; }
 
1751
  bool has_charset(void) const { return TRUE; }
1689
1752
};
1690
1753
 
1691
1754