Ticket #1326 (closed defect: worksforme)

Opened 11 months ago

Last modified 10 months ago

delete() on an empty query deletes all records but does not return the number of deleted rows

Reported by: francois Owned by: romanb
Priority: minor Milestone:
Component: Query/Hydration Version: 1.0.0
Severity: Keywords:
Cc: Has Test: no
Status: Pending Core Response Has Patch: no

Description

It seems that delete() called on an empty Doctrine_Query does the deletion of all records but does not return the number of affected rows. Here is a test case:

function createTestData()
{
  // Reinitialize all
  Doctrine_Query::create()->delete()->from('Article')->execute();
  $article1 = new Article();
  $article1->setTitle('foo2');
  $article1->save();
  $article2 = new Article();
  $article2->setTitle('foo3');
  $article2->save();
}

// Create test data and check count
createTestData();
echo Doctrine_Query::create()->from('Article')->count();
=> 2

// Delete all with no WHERE clause
$nbDeleted = Doctrine_Query::create()->
  delete()->
  from('Article')->
  execute();
echo $nbDeleted
=> 0 // WRONG
// check count
echo Doctrine_Query::create()->from('Article')->count();
=> 0 // But everything is deleted, as requested

// Create test data and check count
createTestData();
echo Doctrine_Query::create()->from('Article')->count();
=> 2

// Delete some with one WHERE clause
$nbDeleted = Doctrine_Query::create()->
  delete()->
  from('Article')->
  where('Title = ?', array('foo2'))->
  execute();
echo $nbDeleted
=> 1 // OK
// check count
echo Doctrine_Query::create()->from('Article')->count();
=> 1 // OK

// Create test data and check count
createTestData();
echo Doctrine_Query::create()->from('Article')->count();
=> 2

// Delete all with one always true WHERE clause
$nbDeleted = Doctrine_Query::create()->
  delete()->
  from('Article')->
  where('1 = 1')->
  execute();
echo $nbDeleted
=> 2 // OK
// check count
echo Doctrine_Query::create()->from('Article')->count();
=> 0 // OK

Change History

Changed 10 months ago by jwage

If it is not an empty query does it return the number of affected rows as expected?

Changed 10 months ago by francois

yes

Changed 10 months ago by jwage

  • version changed from 0.11 to 1.0
  • milestone changed from Unknown to 1.0.0-RC2

Changed 10 months ago by jwage

  • status changed from new to closed
  • resolution set to worksforme

Added coverage in r4864

Francois, can you help me reproduce this? I am not able to reproduce it in the test suite. Re-open if you're able to help me out.

Changed 10 months ago by anonymous

  • milestone New deleted

Milestone New deleted

Note: See TracTickets for help on using tickets.