First, I would ensure you are only opening 1 connection to the database,
this would mean that you are passing the DbAdapter to Zend_Db_Table
either in the constructor of via Zend_Db_Table::setDefaultAdapter($db);
Next, I would check your log files in pgsql to see if there are any
settings that are forcing commit regardless of your calling
beginTransaction().
Beyond that, there is not alot of magic going on with Zend_Db. your
$db->beginTrasnaction() is effectively calling PDO's beginTransaction().
Hope this helps,
Ralph
Have a look here:
http://us2.php.net/manual/en/pdo.transactions.php
andeeh wrote:
> Hi All,
>
> I have a curious problem with a data import I'm doing into Postgres using
> zend db. Might be a Postgres issue, but I'd like to ask here first for
> opinions, in case I'm missing something. I'm reading a spreadsheet and using
> Zend_Form to crunch each row (filter and validate) and then I'm using
> Zend_Db_Table.save() to save the row. It works great as I'm avoiding writing
> a single line of SQL.
>
> So imagine I have 600 saves (INSERTs into postgres) to do in the code below,
> and at attempt 234 we have an exception. Obviously you'd expect a rollback
> of the last 233 INSERTs. Trouble is that my rollback is not working. It
> seems to me that because the save() method calls a SELECT on the inserted
> record immediately after insert, that the transaction block can no longer be
> rolled back. Anyone seen this behaviour? I'm aware that there is an insert()
> method that would bypass the extra SELECT performed by save(), but that
> requires a bit of extra work to clean the data before inserting. I would not
> have expected the $db->rollback() to fail anyway, but it does.
>
> The postgres log shows something like this:
>
> BEGIN
> INSERT
> SELECT
> INSERT
> SELECT
> (repeat INSERT SELECT a few hundred times)
> Error blah blah
> ROLLBACK
>
> But the ROLLBACK does not take effect. It's my windows development machine
> and it's Posgres 8.3. See my simplified code snippet below.
>
> regards,
> Andy
>
> *********
> $db->beginTransaction();
> $error = false;
>
> for($i=0; $i<$rowCount; $i++)
> {
> try
> {
> $data = $rows[$i];
>
> if($form->isValid($data))
> {
> $row = $table->createRow($data);
> $ID = $row->save();
> }
> else
> {
> $error = true;
> $db->rollBack();
> break;
> }
>
> }
> catch (Exception $e)
> {
> $error = true;
> $db->rollBack();
> break;
> }
> }
>
> if(!$error) $db->commit();
>
没有评论:
发表评论