Path: csiph.com!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'clause': 0.07; 'column': 0.07; 'message-id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'throw': 0.09; 'anyway': 0.11; 'applies': 0.15; 'error).': 0.16; 'foul': 0.16; 'query,': 0.16; 'reasonable.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sqlite3': 0.16; 'violated': 0.16; 'duplicate': 0.18; 'merge': 0.18; 'url:home': 0.18; '(in': 0.18; '2015': 0.20; 'aug': 0.20; 'do.': 0.22; 'assuming': 0.22; 'defined': 0.23; '(or': 0.23; 'insert': 0.23; 'mon,': 0.24; '(which': 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; 'error': 0.27; 'question': 0.27; 'values': 0.28; 'looks': 0.29; 'index,': 0.29; 'itself,': 0.29; "i'm": 0.30; 'transaction': 0.30; 'code': 0.30; 'branch': 0.30; 'normally': 0.30; 'probably': 0.31; 'table': 0.32; 'could': 0.35; 'replace': 0.35; "isn't": 0.35; 'supports': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'there,': 0.37; 'received:org': 0.37; 'charset :us-ascii': 0.37; 'someone': 0.38; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'field': 0.60; 'your': 0.60; 'behavior': 0.61; 'risk': 0.68; 'race': 0.72; 'sounds': 0.76; '+1000,': 0.84; '>of': 0.84; 'subject:this': 0.85; 'edition': 0.86; 'dennis': 0.91; 'results,': 0.91; 'received:108': 0.93; 'safe.': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Is this the way to go with SQLite Date: Sun, 23 Aug 2015 12:17:20 -0400 Organization: IISS Elusive Unicorn References: <871teum9c2.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-68-178-61.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.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440346653 news.xs4all.nl 23784 [2001:888:2000:d::a6]:57388 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95595 On Mon, 24 Aug 2015 00:03:53 +1000, Chris Angelico declaimed the following: >Otherwise, looks reasonable. I'm normally expecting to see this kind >of "query, and if it isn't there, insert" code to have an UPDATE in >its other branch (which makes it into a classic upsert or merge >operation - what MySQL calls "INSERT... ON DUPLICATE KEY UPDATE"), or >else throw an error (in which case the cleanest way is to put a unique >key on the column in question and let the database throw the error). >The risk normally is of a race condition; you could execute your >SELECT query, find no results, and then have someone else insert one >just a moment before you do. But with SQLite, you're probably assuming >no other writers anyway - an assumption which (I think) you can >mandate simply by opening a transaction and holding it through the >full update procedure - which would make this safe. > SQLite3 supports the non-standard INSERT OR REPLACE ... (or one can do INSERT OR IGNORE; the OR XXX has a number of values that are allowed to control behavior... BUT the OR clause only applies if a UNIQUE constraint would be violated by the INSERT action... So if the field is not a unique index, no foul is detected) Looking at the 2nd Edition DGtoSQLite, it sounds like the conflict behavior can be defined on the table itself, turning all INSERT statements into INSERT OR xxx for the table -- and one can thereby forgo any UPDATE statements {Heh... And Firebird has UPDATE OR INSERT} -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/