Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'case.': 0.05; 'enabled.': 0.07; 'subject:sqlite3': 0.07; 'python': 0.09; 'effect.': 0.09; 'method:': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'suggest': 0.11; 'downstream': 0.16; 'placeholder': 0.16; 'variable.': 0.16; 'wrote:': 0.17; 'working.': 0.17; 'variable': 0.20; 'putting': 0.20; 'keys': 0.22; '15,': 0.23; "i've": 0.23; 'seems': 0.23; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'change,': 0.27; "doesn't": 0.28; "i'm": 0.29; 'worked': 0.30; 'returned': 0.30; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; "skip:' 20": 0.32; 'print': 0.32; 'skip:s 30': 0.33; 'curious': 0.33; 'docs': 0.33; 'turns': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'robert': 0.35; 'open': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; "didn't": 0.36; 'test': 0.36; 'should': 0.36; 'execute': 0.37; 'does': 0.37; 'why': 0.37; 'previous': 0.37; 'quite': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'url:docs': 0.38; 'several': 0.39; 'your': 0.60; 'first': 0.61; 'times': 0.63; 'more': 0.63; 'foreign': 0.72; 'day': 0.73; '2013': 0.84; 'descriptive': 0.84; 'difference.': 0.84 Newsgroups: comp.lang.python Date: Tue, 15 Jan 2013 07:51:33 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.162.99.34; posting-account=aw7wEQoAAACnaP8vftI9MyiC9NfXNJyr References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 66.162.99.34 MIME-Version: 1.0 Subject: Re: sqlite3 puzzle From: llanitedave To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: llanitedave , python-list 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: , Message-ID: Lines: 74 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358265106 news.xs4all.nl 6944 [2001:888:2000:d::a6]:38000 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36858 On Tuesday, January 15, 2013 6:36:51 AM UTC-8, Rob Day wrote: > On 15 January 2013 07:09, llanitedave wrote: > > > > > So I put the following test code in my initialization method: > > > > > > # open database file > > > self.geologger_db = sqlite3.connect('geologger.mgc') > > > self.db_cursor = self.geologger_db.cursor() > > > self.foreign_key_status = self.db_cursor.execute("PRAGMA foreign_keys = ON") > > > self.foreign_key_status = self.foreign_key_status.fetchone() > > > > > > print self.foreign_key_status > > > > > > I ran this several times while I was arranging the downstream queries, and each time it returned '(1,)', which means foreign keys is enabled. > > > > > > But I was using a variable named 'cmd1' as a placeholder until I changed the name to > > > the more descriptive 'self.foreign_key_status'. Since I made the name change, however, > > > the code only returns 'None'. Reverting to the previous variable name has no effect. > > > > Hmm - your code doesn't quite match up with the docs at > > http://docs.python.org/2/library/sqlite3.html. That seems to suggest > > that you should call fetchone() on the cursor, not on the result of > > execute(). > > > > Does the following work? > > > > # open database file > > self.geologger_db = sqlite3.connect('geologger.mgc') > > self.db_cursor = self.geologger_db.cursor() > > self.db_cursor.execute("PRAGMA foreign_keys = ON") > > print self.db_cursor.fetchone() > > > > > > -- > > Robert K. Day > > robert.day@merton.oxon.org Thanks for the suggestion, Rob, but that didn't make any difference. I've never had an issue with putting the execute object into a variable and calling "fetch" on that variable. I can accept reality if it turns out that foreign keys simply isn't enabled on the Python distribution of sqlite, although I don't know why that should be the case. I'm just curious as to why it worked at first and then stopped working.