Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36856

Re: sqlite3 puzzle

References <a8e71415-57fc-4284-82fe-fae0a6670a67@googlegroups.com>
Date 2013-01-15 14:36 +0000
Subject Re: sqlite3 puzzle
From Rob Day <robert.day@merton.oxon.org>
Newsgroups comp.lang.python
Message-ID <mailman.540.1358260620.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 15 January 2013 07:09, llanitedave <llanitedave@veawb.coop> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

sqlite3 puzzle llanitedave <llanitedave@veawb.coop> - 2013-01-14 23:09 -0800
  Re: sqlite3 puzzle Rob Day <robert.day@merton.oxon.org> - 2013-01-15 14:36 +0000
    Re: sqlite3 puzzle llanitedave <llanitedave@veawb.coop> - 2013-01-15 07:51 -0800
      Re: sqlite3 puzzle Rob Day <robert.day@merton.oxon.org> - 2013-01-15 17:13 +0000
        Re: sqlite3 puzzle llanitedave <llanitedave@veawb.coop> - 2013-01-15 12:29 -0800
          Re: sqlite3 puzzle Rob Day <robert.day@merton.oxon.org> - 2013-01-15 22:27 +0000
            Re: sqlite3 puzzle llanitedave <llanitedave@veawb.coop> - 2013-01-15 14:46 -0800
            Re: sqlite3 puzzle llanitedave <llanitedave@veawb.coop> - 2013-01-15 14:46 -0800
        Re: sqlite3 puzzle llanitedave <llanitedave@veawb.coop> - 2013-01-15 12:29 -0800
    Re: sqlite3 puzzle llanitedave <llanitedave@veawb.coop> - 2013-01-15 07:51 -0800
  Re: sqlite3 puzzle inq1ltd <inq1ltd@inqvista.com> - 2013-01-15 11:54 -0500

csiph-web