Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; '#if': 0.07; 'result,': 0.07; '%s",': 0.09; 'data:': 0.09; 'exit': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '%s,': 0.16; '(x,': 0.16; 'adapter': 0.16; 'deletes': 0.16; 'message-id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'record?': 0.16; 'subject:failed': 0.16; 'throw': 0.16; 'exception': 0.16; 'commit': 0.19; 'url:home': 0.24; 'mon,': 0.24; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'installed': 0.27; 'database,': 0.30; 'errors': 0.30; "i'm": 0.30; 'program,': 0.31; 'subject:time': 0.33; 'table': 0.34; 'could': 0.34; 'add': 0.35; 'charset:us-ascii': 0.36; 'received:76': 0.38; 'ahead': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'quote': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'new': 0.61; 'you.': 0.62; 'field': 0.63; 'happen': 0.63; 'details': 0.65; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Updating a filename's counter value failed each time Date: Mon, 17 Jun 2013 22:01:29 -0400 Organization: IISS Elusive Unicorn References: <5eevr89n3cqg6k948pvqqhtfhfj4s0tnk5@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-27-103.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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371520901 news.xs4all.nl 15873 [2001:888:2000:d::a6]:39050 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48588 On Mon, 17 Jun 2013 21:42:00 -0400, Dennis Lee Bieber declaimed the following: I'm not going to inflict the group with the whole quote again, but... What does the documentation for your db-api adapter (hmmm... have I even installed one on my new computer ) indicate may happen if you get an exception when adding a record? Hopefully it leaves the choice of rollback vs commit up to you. In pseudo-code: con = db.connect(...) cur = con.cursor() for f in data: if f not in somelist: cur.execute("delete from table where field = %s", f) con.commit() #make deletes permanent in database for f in otherdata: cur.execute("select * from table where field = %s", f) #while a try/except:pass might have the same result, #if you don't check for details it could hide OTHER errors if not cur.fetchall(): #record not found in database, go ahead and add it cur.execute("insert into table (x, y, z) values (%s, %s, %s)", (a, b, c) ) con.commit() If you don't commit, and just exit the program, the database will throw away all your changes. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/