~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field.h

  • Committer: Toru Maesaka
  • Date: 2008-07-17 05:10:40 UTC
  • mto: (202.1.1 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: dev@torum.net-20080717051040-jbt1rx0ncmfwfs79
ripped out blob from field.cc/.h and placed in field/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1404
1404
};
1405
1405
 
1406
1406
 
1407
 
class Field_blob :public Field_longstr {
1408
 
protected:
1409
 
  uint packlength;
1410
 
  String value;                         // For temporaries
1411
 
public:
1412
 
  Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
1413
 
             enum utype unireg_check_arg, const char *field_name_arg,
1414
 
             TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs);
1415
 
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1416
 
             CHARSET_INFO *cs)
1417
 
    :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1418
 
                   NONE, field_name_arg, cs),
1419
 
    packlength(4)
1420
 
  {
1421
 
    flags|= BLOB_FLAG;
1422
 
  }
1423
 
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1424
 
             CHARSET_INFO *cs, bool set_packlength)
1425
 
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1426
 
                   NONE, field_name_arg, cs)
1427
 
  {
1428
 
    flags|= BLOB_FLAG;
1429
 
    packlength= 4;
1430
 
    if (set_packlength)
1431
 
    {
1432
 
      uint32 l_char_length= len_arg/cs->mbmaxlen;
1433
 
      packlength= l_char_length <= 255 ? 1 :
1434
 
                  l_char_length <= 65535 ? 2 :
1435
 
                  l_char_length <= 16777215 ? 3 : 4;
1436
 
    }
1437
 
  }
1438
 
  Field_blob(uint32 packlength_arg)
1439
 
    :Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
1440
 
    packlength(packlength_arg) {}
1441
 
  enum_field_types type() const { return MYSQL_TYPE_BLOB;}
1442
 
  enum ha_base_keytype key_type() const
1443
 
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
1444
 
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1445
 
  int  store(double nr);
1446
 
  int  store(int64_t nr, bool unsigned_val);
1447
 
  double val_real(void);
1448
 
  int64_t val_int(void);
1449
 
  String *val_str(String*,String *);
1450
 
  my_decimal *val_decimal(my_decimal *);
1451
 
  int cmp_max(const uchar *, const uchar *, uint max_length);
1452
 
  int cmp(const uchar *a,const uchar *b)
1453
 
    { return cmp_max(a, b, ~0L); }
1454
 
  int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length);
1455
 
  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
1456
 
  int key_cmp(const uchar *,const uchar*);
1457
 
  int key_cmp(const uchar *str, uint length);
1458
 
  uint32 key_length() const { return 0; }
1459
 
  void sort_string(uchar *buff,uint length);
1460
 
  uint32 pack_length() const
1461
 
  { return (uint32) (packlength+table->s->blob_ptr_size); }
1462
 
 
1463
 
  /**
1464
 
     Return the packed length without the pointer size added. 
1465
 
 
1466
 
     This is used to determine the size of the actual data in the row
1467
 
     buffer.
1468
 
 
1469
 
     @returns The length of the raw data itself without the pointer.
1470
 
  */
1471
 
  uint32 pack_length_no_ptr() const
1472
 
  { return (uint32) (packlength); }
1473
 
  uint row_pack_length() { return pack_length_no_ptr(); }
1474
 
  uint32 sort_length() const;
1475
 
  virtual uint32 max_data_length() const
1476
 
  {
1477
 
    return (uint32) (((uint64_t) 1 << (packlength*8)) -1);
1478
 
  }
1479
 
  int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; }
1480
 
  void reset_fields() { bzero((uchar*) &value,sizeof(value)); }
1481
 
#ifndef WORDS_BIGENDIAN
1482
 
  static
1483
 
#endif
1484
 
  void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number, bool low_byte_first);
1485
 
  void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number)
1486
 
  {
1487
 
    store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
1488
 
  }
1489
 
  inline void store_length(uint32 number)
1490
 
  {
1491
 
    store_length(ptr, packlength, number);
1492
 
  }
1493
 
 
1494
 
  /**
1495
 
     Return the packed length plus the length of the data. 
1496
 
 
1497
 
     This is used to determine the size of the data plus the 
1498
 
     packed length portion in the row data.
1499
 
 
1500
 
     @returns The length in the row plus the size of the data.
1501
 
  */
1502
 
  uint32 get_packed_size(const uchar *ptr_arg, bool low_byte_first)
1503
 
    {return packlength + get_length(ptr_arg, packlength, low_byte_first);}
1504
 
 
1505
 
  inline uint32 get_length(uint row_offset= 0)
1506
 
  { return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
1507
 
  uint32 get_length(const uchar *ptr, uint packlength, bool low_byte_first);
1508
 
  uint32 get_length(const uchar *ptr_arg)
1509
 
  { return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
1510
 
  void put_length(uchar *pos, uint32 length);
1511
 
  inline void get_ptr(uchar **str)
1512
 
    {
1513
 
      memcpy_fixed((uchar*) str,ptr+packlength,sizeof(uchar*));
1514
 
    }
1515
 
  inline void get_ptr(uchar **str, uint row_offset)
1516
 
    {
1517
 
      memcpy_fixed((uchar*) str,ptr+packlength+row_offset,sizeof(char*));
1518
 
    }
1519
 
  inline void set_ptr(uchar *length, uchar *data)
1520
 
    {
1521
 
      memcpy(ptr,length,packlength);
1522
 
      memcpy_fixed(ptr+packlength,&data,sizeof(char*));
1523
 
    }
1524
 
  void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
1525
 
    {
1526
 
      uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
1527
 
      store_length(ptr_ofs, packlength, length);
1528
 
      memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*));
1529
 
    }
1530
 
  inline void set_ptr(uint32 length, uchar *data)
1531
 
    {
1532
 
      set_ptr_offset(0, length, data);
1533
 
    }
1534
 
  uint get_key_image(uchar *buff,uint length, imagetype type);
1535
 
  void set_key_image(const uchar *buff,uint length);
1536
 
  void sql_type(String &str) const;
1537
 
  inline bool copy()
1538
 
  {
1539
 
    uchar *tmp;
1540
 
    get_ptr(&tmp);
1541
 
    if (value.copy((char*) tmp, get_length(), charset()))
1542
 
    {
1543
 
      Field_blob::reset();
1544
 
      return 1;
1545
 
    }
1546
 
    tmp=(uchar*) value.ptr();
1547
 
    memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
1548
 
    return 0;
1549
 
  }
1550
 
  virtual uchar *pack(uchar *to, const uchar *from,
1551
 
                      uint max_length, bool low_byte_first);
1552
 
  uchar *pack_key(uchar *to, const uchar *from,
1553
 
                  uint max_length, bool low_byte_first);
1554
 
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
1555
 
                                 uint max_length, bool low_byte_first);
1556
 
  virtual const uchar *unpack(uchar *to, const uchar *from,
1557
 
                              uint param_data, bool low_byte_first);
1558
 
  const uchar *unpack_key(uchar* to, const uchar *from,
1559
 
                          uint max_length, bool low_byte_first);
1560
 
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
1561
 
               my_bool insert_or_update);
1562
 
  int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
1563
 
  uint packed_col_length(const uchar *col_ptr, uint length);
1564
 
  uint max_packed_col_length(uint max_length);
1565
 
  void free() { value.free(); }
1566
 
  inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); }
1567
 
  friend int field_conv(Field *to,Field *from);
1568
 
  uint size_of() const { return sizeof(*this); }
1569
 
  bool has_charset(void) const
1570
 
  { return charset() == &my_charset_bin ? false : true; }
1571
 
  uint32 max_display_length();
1572
 
  uint is_equal(Create_field *new_field);
1573
 
  inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
1574
 
  inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
1575
 
private:
1576
 
  int do_save_field_metadata(uchar *first_byte);
1577
 
};
1578
 
 
1579
 
 
1580
1407
class Field_enum :public Field_str {
1581
1408
protected:
1582
1409
  uint packlength;
1772
1599
int set_field_to_null(Field *field);
1773
1600
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
1774
1601
 
 
1602
bool
 
1603
check_string_copy_error(Field_str *field,
 
1604
                        const char *well_formed_error_pos,
 
1605
                        const char *cannot_convert_error_pos,
 
1606
                        const char *end,
 
1607
                        CHARSET_INFO *cs);
1775
1608
/*
1776
1609
  The following are for the interface with the .frm file
1777
1610
*/