Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81669

Re: Db transactions and locking

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.046
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; 'cursor': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sense,': 0.16; 'commit': 0.19; 'result.': 0.19; 'seems': 0.21; 'command': 0.22; 'reset': 0.22; 'tells': 0.24; 'initial': 0.24; 'header:X-Complaints-To:1': 0.27; 'database,': 0.30; 'lines': 0.31; 'another': 0.32; 'guess': 0.33; 'not.': 0.33; 'connection': 0.35; 'transaction': 0.35; 'but': 0.35; 'there': 0.35; 'next': 0.36; 'two': 0.37; 'starting': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'transaction.': 0.60; 'new': 0.61; 'confirm': 0.64; 'different': 0.65; 'between': 0.67; 'frank': 0.68; 'started.': 0.68; 'therefore': 0.72; 'repeat': 0.74; 'state.': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Re: Db transactions and locking
Date Fri, 28 Nov 2014 08:57:07 +0200
References <m56u4s$baa$1@ger.gmane.org> <4loe7at2ls7tfq0oe041ru9svvsm8aksik@4ax.com> <m5924d$nbq$1@ger.gmane.org>
X-Gmane-NNTP-Posting-Host 197.86.210.253
X-MSMail-Priority Normal
X-Newsreader Microsoft Outlook Express 6.00.3790.4657
X-RFC2646 Format=Flowed; Response
X-MimeOLE Produced By Microsoft MimeOLE V6.00.3790.4913
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16396.1417157839.18130.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417157839 news.xs4all.nl 2873 [2001:888:2000:d::a6]:37327
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81669

Show key headers only | View raw


"Frank Millman" <frank@chagford.com> 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 this -
>
> cur.execute('SELECT * FROM mytable') - 4
> cur.execute('commit') - 3
>
> cur.execute('SELECT * FROM mytable') - 3
> cur.execute('commit') - 3
>
> There seems to be a difference between conn.commit() and 
> cur.execute('commit'), which leaves the connection in a different state.
>

On reflection, this makes sense, and also 'proves' that my initial theory of 
the adaptor starting a transaction on opening a cursor must be wrong.

My guess now is that the connection is in one of two states - a transaction 
is active, or it is not. If a command is issued, and a transaction is not 
active, then a transaction is started. If a conn.commit() or a 
conn.rollback() is issued, the command is passed up to the database, and the 
connection state is reset to not active.

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 - never use cur.execute('commit'), always 
use conn.commit()

Frank


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Db transactions and locking "Frank Millman" <frank@chagford.com> - 2014-11-28 08:57 +0200

csiph-web