Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'explicitly': 0.05; 'subject:Python': 0.06; 'concurrently': 0.07; 'tool,': 0.07; 'created,': 0.09; 'default;': 0.09; 'postgresql,': 0.09; 'subject:2.7': 0.09; 'api': 0.11; 'cc:addr:python-list': 0.11; 'python': 0.11; 'wrote': 0.14; "wouldn't": 0.14; '23,': 0.16; 'command,': 0.16; 'command.': 0.16; 'decision,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ought': 0.16; 'qualifying': 0.16; 'skip:n 70': 0.16; 'throw': 0.16; 'unexpectedly': 0.16; 'unlikely': 0.16; 'demonstrate': 0.16; 'folks': 0.16; 'ignore': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'command': 0.22; 'settings': 0.22; 'issue.': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'addressed.': 0.29; 'message-id:@mail.gmail.com': 0.30; 'went': 0.31; 'that.': 0.31; 'enforce': 0.31; 'keys': 0.31; 'purely': 0.31; 'checking': 0.33; 'entirely': 0.33; 'actual': 0.34; 'table': 0.34; 'possible.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'edge': 0.36; 'sequence': 0.36; 'view,': 0.36; "didn't": 0.36; 'should': 0.36; 'too': 0.37; 'remote': 0.38; 'nov': 0.38; 'pm,': 0.38; 'track': 0.38; 'though,': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'commands': 0.60; 'up,': 0.60; 'stand': 0.64; 'more': 0.64; 'bothered': 0.68; 'frank': 0.68; 'lose': 0.68; 'default': 0.69; 'foreign': 0.74; 'cut': 0.74; 'grew': 0.84; "it'd": 0.84; 'to:none': 0.92; 'acknowledge': 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=KVDlyYJoM8ai4QsMaqsRO7k6dyXh8/XM2irgCCivcH4=; b=HiPGTish5Mb9rb7T9KV/CkLRvxXsAxS+xpJLPsW4gOvvyvOjRcX8QAq1ZaPW/J8s7/ MXL3sg0e/IH/qhqZYV4Ws4AAEYLgoWnG/k28e7leBsb9lyqn3bchOuLSiOMUegDdb1+V SkMyKPgL9xbOtTvdewJK9QmlosRP65X81H2P14RAOQyLfj6F5tH1IgHz8iUo8lzrAlI6 4136rQIFDofc34MjzJ+83nwZhr1BF5kH5MW2DAp0IJOeQMiqrvQvg6wwNYMElE7YqlD5 LNjkFYO0qO6UF2NrOwgte2s1R548FHw+ZYB8tJP/qHtJreSpX3veiQi9CUVigmH4r5TY MUvw== MIME-Version: 1.0 X-Received: by 10.107.134.39 with SMTP id i39mr12454930iod.53.1416731504990; Sun, 23 Nov 2014 00:31:44 -0800 (PST) In-Reply-To: References: <5d474a87-e2a5-43d3-b07c-4a1194880b4d@googlegroups.com> <54716987.7040301@gmail.com> Date: Sun, 23 Nov 2014 19:31:44 +1100 Subject: Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert 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.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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416731513 news.xs4all.nl 2956 [2001:888:2000:d::a6]:41053 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 3718186060 X-Received-Bytes: 6185 Xref: csiph.com comp.lang.python:81345 On Sun, Nov 23, 2014 at 7:21 PM, Frank Millman wrote: > "Chris Angelico" wrote in message > news:CAPTjJmp4Y5zowWn5yFtJutKO4H5jVtqLaNtWqEpA6B35xNdsNA@mail.gmail.com... >> >> Entirely possible. I never did track down the actual cause of the >> SQLite3 issues my students were having; though I suspect it's not >> purely a Python API issue. I tried to demonstrate the concept of >> foreign keys using the sqlite3 command line tool, and did a sequence >> of commands which ought to have failed, but didn't. > > The default is for sqlite3 to ignore foreign key contraints. > > To enable them, add the following - > > pragma foreign_keys = on; > > It works for me. Thanks, I went poking around briefly but didn't find that pragma. I still stand by my view, though, that constraint checking should be active by default; you have to explicitly create them anyway, so it's not like you'd unexpectedly lose heaps of performance. And even if it is costly, the default settings should be for reliability, more than performance; if you want to cut corners to speed things up, that's your decision, but that should be something you have to explicitly ask for. It'd be nice to have a warning or at least informational: "Foreign key constraint created, but constraint checking is inactive". Would mean folks like me, who grew up on IBM's DB2 and now use PostgreSQL, wouldn't be so confused by "why did that not throw an error". > Unfortunately it has a limitation, which they acknowledge but they say is > unlikely to be addressed. You can access more than one database concurrently > by using the 'attach' command, and qualifying a remote tablename as > {database} dot {tablename}. You can then include the remote table in any sql > command. However, it will not enforce foreign key constraints across > databases. That's more of an edge case; I wouldn't be too bothered by that. ChrisA