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


Groups > comp.lang.python > #36863

Re: sqlite3 puzzle

From inq1ltd <inq1ltd@inqvista.com>
Subject Re: sqlite3 puzzle
Date 2013-01-15 11:54 -0500
References <a8e71415-57fc-4284-82fe-fae0a6670a67@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.546.1358270827.2939.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Monday, January 14, 2013 11:09:28 PM llanitedave wrote:
> I'm trying to get an application working in Python 2.7 and wx.Python which
> contains an embedded sqlite3 file.  There are a few tables with foreign
> keys defined.  In looking at the sqlite3 documentation, it says
> 
> "Assuming the library is compiled with foreign key constraints enabled, it
> must still be enabled by the application at runtime, using the PRAGMA
> foreign_keys command." It goes on to say that foreign keys must be enabled
> separately for each connection, which is fine as my app has only one.
> 
> 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.
> 
> Yes, I'm closing the connection with self.db_cursor.close() at the end of
> each run.
> 
> According to the sqlite3 website, getting no return value, not even a '0',
> means that "the version of SQLite you are using does not support foreign
> keys (either because it is older than 3.6.19 or because it was compiled
> with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined)."
> 
> How can that be a compilation issue when it worked previously?  Does this
> somehow relate to it being a Python plugin instance?
> 
> I'm very confused.

I haven't run this myself but after 

self.foreign_key_status.fetchone()

try :
 self.geologger_db.commit()

then close the db

jimonlinux






Back to comp.lang.python | Previous | NextPrevious 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