-1

Working in symfony 1.4, with Propel for my ORM (not sure how to find the version of Propel).

In a unit test of an object with a unique constraint in the database, I test for the exception being caught:

try {
  $room1a->save();
  // Shouldn't have saved, so shouldn't have an id
  $t->ok(!$room1a->getId(), "Failed to save duplicate room");
} catch (Exception $e) {
  $t->ok($e, "Threw exception on creating duplicate room");
}

but if I then correct the duplication and try again, thus

$room1a->setCode('1a');
$room1a->save();
$t->ok($room1a->getId()), "Saved this time");

I get "Unable to get sequence id":

     PropelException: Unable to get sequence id. [wrapped:                
  SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current        
  transaction is aborted, commands ignored until end of transaction    
  block]                                                               
  (in                                                                  
  lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/BasePeer.php
  on line 264)  

I've tried recreating the object (i.e. a new Room object) and saving it, with the same result; it appears that there is a state in the connection (?) which needs resetting.

The only way round I've found is to roll back the transaction and begin a new one.

4

1 回答 1

0

我找到了答案:事务应该是这样工作的。

我将单元测试脚本包装在事务中,以免更改数据库,而且我没有意识到引发约束错误会中止事务。

对我来说有点烦人,因为我必须开始一个新事务并再次设置数据,以进行后续测试。

于 2012-05-26T21:34:50.880 回答