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


Groups > comp.lang.python > #21693 > unrolled thread

Pragmas, foreign keys in sqlite3?

Started byllanitedave <llanitedave@veawb.coop>
First post2012-03-15 09:59 -0700
Last post2012-03-15 16:21 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Pragmas, foreign keys in sqlite3? llanitedave <llanitedave@veawb.coop> - 2012-03-15 09:59 -0700
    Re: Pragmas, foreign keys in sqlite3? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-03-15 16:21 -0400

#21693 — Pragmas, foreign keys in sqlite3?

Fromllanitedave <llanitedave@veawb.coop>
Date2012-03-15 09:59 -0700
SubjectPragmas, foreign keys in sqlite3?
Message-ID<41621d5f-072f-41e5-a880-57d78a298250@j5g2000yqm.googlegroups.com>
Several questions here, but they're related.

I'm trying to incorporate an sqlite3 database that was created using
Sqliteman1.2.2.  I don't know what version of sqlite3 that one uses,
but it seems to have ignored any attempts to create foreign keys for
its tables.

I'm using Python 2.7.2, and I know that the sqlite3 version that it
contains is 3.7.7.  Therefore, it should be able to handle foreign
keys.  Where I'm clueless is about how to get that information out of
it, and how to implement or add foreign keys to existing tables.

Is there some way to use the sqlite PRAGMA command from within python?

I tried connecting to the database and got

>>> cr.execute('''PRAGMA foreign_keys;''')
<sqlite3.Cursor object at 0xb7335720>

 using "inspect.getmembers()" I got a huge list of everything; it lets
me see that there's no foreign key created, but I can't get that
particular tuple separated out, and I have no idea how to add them.

Do I need to recreate the entire database structure from scratch?

[toc] | [next] | [standalone]


#21709

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-03-15 16:21 -0400
Message-ID<mailman.699.1331842892.3037.python-list@python.org>
In reply to#21693
On Thu, 15 Mar 2012 09:59:54 -0700 (PDT), llanitedave
<llanitedave@veawb.coop> declaimed the following in
gmane.comp.python.general:

> it, and how to implement or add foreign keys to existing tables.
>
	For the most part, SQLite3 doesn't permit any modification to
existing tables; one basically dumps the data, deletes the table,
redefines it with needed changes, reloads the data.
 
> Is there some way to use the sqlite PRAGMA command from within python?
> 
> I tried connecting to the database and got
> 
> >>> cr.execute('''PRAGMA foreign_keys;''')
> <sqlite3.Cursor object at 0xb7335720>
>
	No surprise there... If any data is returned, you'll need to do a
cr.fetch() (or .fetchall() ).

> Do I need to recreate the entire database structure from scratch?

	As mentioned above... essentially...
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web