Path: csiph.com!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.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.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'suppress': 0.07; 'table.': 0.07; 'cc:addr:python-list': 0.09; 'skipping': 0.09; 'anyway': 0.11; '16:03': 0.16; '23,': 0.16; '24,': 0.16; 'conn': 0.16; 'conn.close()': 0.16; 'error).': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'investigate': 0.16; 'query,': 0.16; 'query.': 0.16; 'wrote:': 0.16; 'found,': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'do.': 0.22; 'not,': 0.22; 'so.': 0.22; 'assuming': 0.22; 'explicit': 0.22; 'select': 0.23; 'insert': 0.23; 'header:In- Reply-To:1': 0.24; 'mon,': 0.24; 'script': 0.25; 'chris': 0.26; 'error': 0.27; 'mostly': 0.27; 'message-id:@mail.gmail.com': 0.27; 'values': 0.28; 'initial': 0.28; 'currently,': 0.29; 'unique,': 0.29; 'print': 0.30; 'that.': 0.30; 'transaction': 0.30; 'normally': 0.30; 'probably': 0.31; 'skip:s 30': 0.31; 'run': 0.33; 'url:python': 0.33; 'received:google.com': 0.35; 'ones': 0.35; 'could': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'urls': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'wanted': 0.37; 'wrong': 0.38; 'someone': 0.38; 'end': 0.39; 'subject:the': 0.39; 'takes': 0.39; 'from:': 0.39; 'subject:with': 0.40; 'some': 0.40; 'care': 0.60; 'your': 0.60; "you'll": 0.61; 'notified': 0.62; 'more': 0.63; 'different': 0.63; 'risk': 0.68; 'race': 0.72; 'sunday': 0.72; 'integrity': 0.76; 'sounds': 0.76; '(ie': 0.84; 'cecil': 0.84; 'chrisa': 0.84; 'westerhof': 0.84; 'subject:this': 0.85; 'to:none': 0.91; '9:00': 0.91; 'results,': 0.91; 'safe.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=y7VvtLVNffgZ8tik9g6AXuAzFGDio3d/7S8gH2340Yw=; b=cUHWbO5gS6CCmydgbWeDMkCXRzLzK+GPxkJUZDSfoe4xOVzwK9p/vIe6O+Z1qs2NMk 1ULN3L5aVMQpbGSDyWtoc+LrhEdjRiV6QjafwkxG/gWibTpqJjXbRviQ7Pw0sjmSt419 zjvHvxfVLlawNR1Ruzldx0pp5SfoppCGDT0UVfPn6kqCgAJrFd6G3r9YK53gxG8yQIsY mhEWTDDae64ufronhoz7lPdHWL1jZSrr8aOtHOoRVTK8yjxfzPkBhdEqsVMdCu1w+BkD VjEYTUDEc+lbvr6VkuuVtEtdXazYWFgFBG56szFig8YtH5DcOWpJ+vMAKxORLjpp6NeI GD2g== MIME-Version: 1.0 X-Received: by 10.107.12.166 with SMTP id 38mr16405890iom.157.1440415603234; Mon, 24 Aug 2015 04:26:43 -0700 (PDT) In-Reply-To: <87bndxkl3e.fsf@Equus.decebal.nl> References: <871teum9c2.fsf@Equus.decebal.nl> <87bndxkl3e.fsf@Equus.decebal.nl> Date: Mon, 24 Aug 2015 21:26:43 +1000 Subject: Re: Is this the way to go with SQLite From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440415612 news.xs4all.nl 23812 [2001:888:2000:d::a6]:58016 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95609 On Mon, Aug 24, 2015 at 9:00 PM, Cecil Westerhof wrote: > On Sunday 23 Aug 2015 16:03 CEST, Chris Angelico wrote: > >> On Sun, Aug 23, 2015 at 11:18 PM, Cecil Westerhof wrote: >>> Also an URL is unique, so I need to check that if it is found, the >>> values are the same as the ones I wanted to insert. >> >> And if they aren't? Currently, all you do is print out a message and >> continue on; what happens if you get the same URL coming up more >> than once? > > That is all what I want at the moment: to get notified when an URL has > two different descriptions. It is just a script to do an initial fill > of the table. When run again I do not insert the URLs that are already > in the database. But just skipping is not enough, when it has a > different description I did something wrong and should investigate > that. Sounds to me like you mostly want an error, but in some cases, you'll suppress the error (ie it's exactly the same description and datestamp). >> 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. > > I start with: > conn = sqlite3.connect('links.sqlite') > c = conn.cursor() > > and end with: > conn.commit() > conn.close() > > Taken from: > https://docs.python.org/2/library/sqlite3.html > > This takes care of the transaction, or not? Yep, I think so. If not, you should be able to ensure transactional integrity by simply adding an explicit "BEGIN" query. ChrisA