Re: odd transaction behavior
Federico Di Gregorio <fog-NGVKUo/i/[email protected]> Mon, 22 Mar 2010 18:39:52 +0100
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On 22/03/2010 17:43, Kerri Reno wrote:
> Hello all! I'm a newbie to this mailing list but I've been using
> psycopg for quite a while. I hope you can help me!
>
> I recently changed our isolation level from 'READ COMMIT' to
> 'AUTOCOMMIT' and have seen some odd behavior when I want to post a
> multiple line transaction. I am using
> 'conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)'
>
>
in the connection class to make all transactions auto commit. Then I am
> using cursor.execute('BEGIN') to start a longer transaction. Is this
> what I should be doing? Because conn.commit() doesn't seem to work
> on these longer transactions. BUT, if I do cursor.execute('commit'),
> then the transactions are posted. Should conn.commit() work? If so,
> what am I doing wrong? This is a viable way to commit the data, but
> I'm just wondering if it is the 'correct' way.
If you switch transactions off (by ISOLATION_LEVEL_AUTOCOMMIT) then you
have two options:
1) to not use transactions
2) as you discovered, manage transactions by yourself issuing BEGIN,
COMMIT and ABORT commands using execute()
Sincerely, I don't like (2). If you want transactions, choose the
appropriate transaction isolation level, be pythonic and let psycopg do
its work (it will start a transaction before your first query and just
after you call .commit() or .rollback() on the connection).
If you decide to manage transactions by yourself then avoid to call
.commit() or .rollback(), because psycopg is not supposed to know what's
you're doing and won't oblige to your command.
federico
--
Federico Di Gregorio fog-NGVKUo/i/[email protected]
I filosofi son come i sociologi: il mondo non lo capiscono. -- A.R.M.
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc
(application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkunq2gACgkQvcCgrgZGjesmOgCfayNAaDUS5+WRe2ZYZhWTC8be 2AEAnjrxTWJCCBKd9i1sQm9iTN0YN/o7 =dLaj -----END PGP SIGNATURE-----