我做從Kohana的3.2框架的SQL事務在PHP在PostgreSQL 9.0什麼導致我的SQL事務中止沒有php注意到?
我得到一個異常
Database_Exception [ 0 ]: ERROR: current transaction is aborted, commands ignored until end of transaction block [ SELECT c.* FROM contents c WHERE c.content_id = 129 AND EXISTS(SELECT NULL FROM contents tmp WHERE tmp.content_id = c.content_id AND c.content_id = 129 GROUP BY tmp.content_id HAVING MAX(tmp.version) = c.version) ]
我奇怪,因爲這意味着我的一些SQL在此之前的一個失敗,因此沒有更多的SQL語句被接受。然而,我將所有的SQL調用放在try/catch塊中,並在重新拋出之前對catch進行回滾。
,所以我不應該看到這個異常的權利?而不是指望之前看到一個,這無疑會破壞開始與...
我添加記錄到我的PHP數據庫驅動的交易,並記錄了遵循導致該問題的SQL語句。下面的最後一條SELECT語句是我上面例外中引用的那條語句。
在異常聲明之前的語句是一個INSERT,它可能是擾流板的一個很好的候選者,但是當我手動運行所有這些語句時,它們都會正確通過。
UPDATE "articles"
SET article_id = 126, title = 'abc', blurb = 'abc article blurb'
WHERE "article_id" = 126
SELECT c.* FROM contents c
WHERE c.content_id = 127
AND EXISTS(
SELECT NULL FROM contents tmp
WHERE tmp.content_id = c.content_id AND c.content_id = 127
GROUP BY tmp.content_id HAVING MAX(tmp.version) = c.version
)
SELECT c.* FROM contents c
WHERE c.content_id = 128 AND EXISTS(
SELECT NULL FROM contents tmp
WHERE tmp.content_id = c.content_id AND c.content_id = 128
GROUP BY tmp.content_id HAVING MAX(tmp.version) = c.version
)
INSERT INTO "contents"
("blurb", "content", "content_id", "content_type_id", "title", "author_id", "version", "editor_id")
VALUES
('postit art', 'FEATURE_IMG_david-chan-drawing_IMG_0221.JPG', 128, 2, 'david chan drawing', 5, 2, 4)
SELECT c.* FROM contents c
WHERE c.content_id = 129 AND EXISTS(
SELECT NULL FROM contents tmp
WHERE tmp.content_id = c.content_id AND c.content_id = 129
GROUP BY tmp.content_id HAVING MAX(tmp.version) = c.version
)
是什麼導致我的事務中止?
的感謝!追捕管理員後,我發現kohana的數據庫調用last_val()失敗,因爲我有一個多鍵表。 –