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


Groups > comp.lang.python > #72801

Re: How to use SQLite (sqlite3) more efficiently

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'interfaces': 0.04; 'context': 0.07; 'tries': 0.07; 'exit': 0.09; 'imply': 0.09; 'okay': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spec': 0.09; 'subject:How': 0.10; 'python': 0.11; 'changes': 0.15; '"with"': 0.16; 'blocked': 0.16; 'message-id:@4ax.com': 0.16; 'operation,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:sqlite3': 0.16; 'url:sqlite': 0.16; 'usable': 0.16; 'do.': 0.18; 'all,': 0.19; 'commit': 0.19; 'thu,': 0.19; 'later': 0.20; 'starts': 0.20; 'code,': 0.22; 'select': 0.22; 'putting': 0.22; "aren't": 0.24; 'necessary.': 0.24; 'url:home': 0.24; 'somewhere': 0.26; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'subject:) ': 0.29; "doesn't": 0.30; 'database,': 0.30; 'statement': 0.30; "i'm": 0.30; 'implicit': 0.31; 'object.': 0.31; 'there.': 0.32; 'probably': 0.32; 'says': 0.33; 'url:python': 0.33; 'style': 0.33; 'maybe': 0.34; "i'd": 0.34; 'subject: (': 0.35; 'connection': 0.35; 'transaction': 0.35; 'something': 0.35; 'johnson': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'accessing': 0.36; 'object,': 0.36; 'skip:> 10': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'url:org': 0.36; 'should': 0.36; 'turn': 0.37; 'connections': 0.38; 'url:library': 0.38; 'to:addr :python-list': 0.38; 'anything': 0.39; 'does': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'transaction.': 0.60; 'new': 0.61; 'subject:more': 0.64; 'different': 0.65; 'close': 0.67; 'useful.': 0.68; 'default': 0.69; 'safe': 0.72; 'closes': 0.84; 'different.': 0.84; 'not...': 0.84; 'url:latest': 0.91; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: How to use SQLite (sqlite3) more efficiently
Date Thu, 05 Jun 2014 20:42:16 -0400
Organization IISS Elusive Unicorn
References <5390ABF2.5020805@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-108-79-221-43.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
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.10793.1402015344.18130.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402015344 news.xs4all.nl 2948 [2001:888:2000:d::a6]:33687
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72801

Show key headers only | View raw


On Thu, 05 Jun 2014 13:42:10 -0400, R Johnson
<ps16thypresenceisfullnessofjoy@gmail.com> declaimed the following:


> >        While /maybe/ not required for a SELECT operation, I'd put a
> >conn.commit() somewhere in there before the return(s). The standard for
> > Python DB-API interfaces is that auto-commit is turned off -- meaning the
> > SELECT has started a database transaction.
>
>I don't exactly understand why conn.commit() should be called there. I 
>thought it's only necessary to call it when the database has been 
>changed, which a SELECT call doesn't do. Am I misunderstanding something 
>here?
>

	For a single process accessing the database, maybe not... But DB-API
does not do auto-commit, which means the select probably starts a
transaction, putting SQLite3 into a shared-read lock. Any other
connection/cursor that tries to commit a change will be blocked waiting for
all the shared-read connections to commit or rollback.

http://www.sqlite.org/lockingv3.html
{Note: while SQLite3 default is auto-commit, the DB-API spec for Python
says NO auto-commit, so opening a connection should implicitly also turn
off auto-commit}

https://pysqlite.readthedocs.org/en/latest/sqlite3.html#controlling-transactions
Does imply that it only starts a transaction on a statement that will
change the database contents... But I'd prefer to play safe -- after all,
if one later changes to a different DBMS, the transaction start point may
be different.


> > >        with conn:
> >
> >         This isn't really doing anything useful. You aren't opening a new
> > connection object, so there isn't really anything to close on block 
>exit.
>
>See 
>https://docs.python.org/2/library/sqlite3.html#using-the-connection-as-a-context-manager. 
>I removed it from my code, though, because it doesn't really seem necessary.
>
	Okay -- mea culpa... I'd not encountered that style of "context
manager"... I'm used to something that uses the "with" to "open" an object,
and the context exit closes said object. Not something where the object
hangs around in a usable state, but an implicit commit() is performed.

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Thread

Re: How to use SQLite (sqlite3) more efficiently Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-06-05 20:42 -0400

csiph-web