~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.cc

  • Committer: Monty Taylor
  • Date: 2010-09-28 17:45:19 UTC
  • mfrom: (1799.1.6 build)
  • Revision ID: mordred@inaugust.com-20100928174519-y6ie2f3wa4t6o669
Rollup patch with several bugfixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1426
1426
      field_metadata->set_type(message::internalFieldTypeToFieldProtoType(current_field->type()));
1427
1427
    }
1428
1428
 
1429
 
    /*
1430
 
     * The below really should be moved into the Field API and Record API.  But for now
1431
 
     * we do this crazy pointer fiddling to figure out if the current field
1432
 
     * has been updated in the supplied record raw byte pointers.
1433
 
     */
1434
 
    const unsigned char *old_ptr= (const unsigned char *) old_record + (ptrdiff_t) (current_field->ptr - in_table->getInsertRecord()); 
1435
 
    const unsigned char *new_ptr= (const unsigned char *) new_record + (ptrdiff_t) (current_field->ptr - in_table->getInsertRecord()); 
1436
 
 
1437
 
    uint32_t field_length= current_field->pack_length(); /** @TODO This isn't always correct...check varchar diffs. */
1438
 
 
1439
 
    if (memcmp(old_ptr, new_ptr, field_length) != 0)
 
1429
    if (isFieldUpdated(current_field, in_table, old_record, new_record))
1440
1430
    {
1441
1431
      /* Field is changed from old to new */
1442
1432
      field_metadata= header->add_set_field_metadata();
1479
1469
     * UPDATE t1 SET counter = counter + 1 WHERE id IN (1,2);
1480
1470
     *
1481
1471
     * We will generate two UpdateRecord messages with different set_value byte arrays.
1482
 
     *
1483
 
     * The below really should be moved into the Field API and Record API.  But for now
1484
 
     * we do this crazy pointer fiddling to figure out if the current field
1485
 
     * has been updated in the supplied record raw byte pointers.
1486
1472
     */
1487
 
    const unsigned char *old_ptr= (const unsigned char *) old_record + (ptrdiff_t) (current_field->ptr - in_table->getInsertRecord()); 
1488
 
    const unsigned char *new_ptr= (const unsigned char *) new_record + (ptrdiff_t) (current_field->ptr - in_table->getInsertRecord()); 
1489
 
 
1490
 
    uint32_t field_length= current_field->pack_length(); /** @TODO This isn't always correct...check varchar diffs. */
1491
 
 
1492
 
    if (memcmp(old_ptr, new_ptr, field_length) != 0)
 
1473
    if (isFieldUpdated(current_field, in_table, old_record, new_record))
1493
1474
    {
1494
1475
      /* Store the original "read bit" for this field */
1495
1476
      bool is_read_set= current_field->isReadSet();
1541
1522
  }
1542
1523
}
1543
1524
 
 
1525
bool TransactionServices::isFieldUpdated(Field *current_field,
 
1526
                                         Table *in_table,
 
1527
                                         const unsigned char *old_record,
 
1528
                                         const unsigned char *new_record)
 
1529
{
 
1530
  /*
 
1531
   * The below really should be moved into the Field API and Record API.  But for now
 
1532
   * we do this crazy pointer fiddling to figure out if the current field
 
1533
   * has been updated in the supplied record raw byte pointers.
 
1534
   */
 
1535
  const unsigned char *old_ptr= (const unsigned char *) old_record + (ptrdiff_t) (current_field->ptr - in_table->getInsertRecord());
 
1536
  const unsigned char *new_ptr= (const unsigned char *) new_record + (ptrdiff_t) (current_field->ptr - in_table->getInsertRecord());
 
1537
 
 
1538
  uint32_t field_length= current_field->pack_length(); /** @TODO This isn't always correct...check varchar diffs. */
 
1539
 
 
1540
  bool old_value_is_null= current_field->is_null_in_record(old_record);
 
1541
  bool new_value_is_null= current_field->is_null_in_record(new_record);
 
1542
 
 
1543
  bool isUpdated= false;
 
1544
  if (old_value_is_null != new_value_is_null)
 
1545
  {
 
1546
    if ((old_value_is_null) && (! new_value_is_null)) /* old value is NULL, new value is non NULL */
 
1547
    {
 
1548
      isUpdated= true;
 
1549
    }
 
1550
    else if ((! old_value_is_null) && (new_value_is_null)) /* old value is non NULL, new value is NULL */
 
1551
    {
 
1552
      isUpdated= true;
 
1553
    }
 
1554
  }
 
1555
 
 
1556
  if (! isUpdated)
 
1557
  {
 
1558
    if (memcmp(old_ptr, new_ptr, field_length) != 0)
 
1559
    {
 
1560
      isUpdated= true;
 
1561
    }
 
1562
  }
 
1563
  return isUpdated;
 
1564
}  
 
1565
 
1544
1566
message::Statement &TransactionServices::getDeleteStatement(Session *in_session,
1545
1567
                                                            Table *in_table,
1546
1568
                                                            uint32_t *next_segment_id)