[英]How to detect a failed transaction in neo4j-php-client
我在PHP 5.6.24上使用帶有Neo4j 3.0.4的graphaware / neo4j-php-client 4.5.1。
我不明白如何確定交易是否失敗。
例如,我嘗試刪除仍具有關系的節點。 如果我在此簡單查詢中運行DELETE:
$client->run
(
'MATCH (node { name: {name} }) DELETE node',
[ 'name' => 'Fred' ]
);
…我收到此異常,這是我期望的行為:
[GraphAware\Neo4j\Client\Exception\Neo4jException]
org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException:
Cannot delete node<31>, because it still has relationships.
To delete this node, you must first delete its relationships.
但是,當我將相同的查詢包裝在事務中時:
$transaction = $client->transaction();
$transaction->push
(
'MATCH (node { name: {name} }) DELETE node',
[ 'name' => 'Fred' ]
);
$results = $transaction->commit();
foreach ($results as $result)
{
$summary = $result->summarize();
$stats = $summary->updateStatistics();
printf("Nodes deleted: %d\n", $stats->nodesDeleted());
}
printf("Transaction status: %s\n", $transaction->status());
…Neo4j不會刪除節點,但是我看到了這個(建議成功),而不是出現異常:
Nodes deleted: 1
Transaction status: COMMITED
我是否缺少任何東西,或者這是一個錯誤? 提前致謝!
謝謝,
這實際上是一個錯誤,我已經在https://github.com/graphaware/neo4j-php-client/commit/af8f01475a3cf63549498449574eb9c4bb8e7254中修復了
包括此修復程序在內的4.5.3版本應在幾分鍾后就可以在Packagist上使用。
請測試並報告。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.