Re: Db transactions and locking

2014-11-28 Thread Ian Kelly
On Nov 27, 2014 4:39 PM, "Chris Angelico" wrote: > > On Fri, Nov 28, 2014 at 5:02 AM, Ian Kelly wrote: > > On Nov 27, 2014 4:26 AM, "Frank Millman" wrote: > >> All Python database adaptors that I have used start a transaction when you > >> open a cursor. I have just re-read DB-API 2.0, and I can

Re: Db transactions and locking

2014-11-27 Thread Chris Angelico
On Fri, Nov 28, 2014 at 5:57 PM, Frank Millman wrote: > cur.execute('commit') tells the database to commit the transaction, but the > adaptor is not aware of this, so does not reset. Therefore the next command > does not trigger starting a new transaction. > > I have now learned another lesson - n

Re: Db transactions and locking

2014-11-27 Thread Frank Millman
"Frank Millman" wrote in message news:m5924d$nbq$1...@ger.gmane.org... > > > This seems to confirm what I thought, but then I continued, and was > surprised at the result. > > I can repeat these lines at will - > > cur.execute('SELECT * FROM mytable') - 4 > conn.commit() - 3 > > But if I do thi

Re: Db transactions and locking

2014-11-27 Thread Chris Angelico
On Fri, Nov 28, 2014 at 4:44 PM, Frank Millman wrote: > There seems to be a difference between conn.commit() and > cur.execute('commit'), which leaves the connection in a different state. Yes, if a connection library offers a way to commit/roll back, it's usually best to use that. > However, for

Re: Db transactions and locking

2014-11-27 Thread Frank Millman
"Dennis Lee Bieber" wrote in message news:4loe7at2ls7tfq0oe041ru9svvsm8ak...@4ax.com... > On Thu, 27 Nov 2014 12:24:39 +0200, "Frank Millman" > declaimed the following: > > >>All Python database adaptors that I have used start a transaction when you >>open a cursor. I have just re-read DB-API 2

Re: Db transactions and locking

2014-11-27 Thread Chris Angelico
On Fri, Nov 28, 2014 at 5:02 AM, Ian Kelly wrote: > On Nov 27, 2014 4:26 AM, "Frank Millman" wrote: >> All Python database adaptors that I have used start a transaction when you >> open a cursor. I have just re-read DB-API 2.0, and I cannot see anything >> that specifies this behaviour, but AFAIC

Re: Db transactions and locking

2014-11-27 Thread Ian Kelly
On Nov 27, 2014 4:26 AM, "Frank Millman" wrote: > All Python database adaptors that I have used start a transaction when you > open a cursor. I have just re-read DB-API 2.0, and I cannot see anything > that specifies this behaviour, but AFAICT this is what happens. I don't know how others work, b

Re: Db transactions and locking

2014-11-27 Thread Chris Angelico
On Thu, Nov 27, 2014 at 9:24 PM, Frank Millman wrote: > "PostgreSQL by default commits between each statement unless you explicitly > start a transaction." > > All Python database adaptors that I have used start a transaction when you > open a cursor. I have just re-read DB-API 2.0, and I cannot s

Db transactions and locking

2014-11-27 Thread Frank Millman
Hi all I just learned something about database transactions, locking, and DB-API 2.0. I wondered why a PostgreSQL statement was hanging. On investigation, it was waiting to acquire a lock. On further investigation, the lock was held by a simple SELECT statement. This surprised me. I got a clu