Pragmas, foreign keys in sqlite3?

Discussion in 'Python' started by llanitedave, Mar 15, 2012.

  1. llanitedave

    llanitedave Guest

    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?
     
    llanitedave, Mar 15, 2012
    #1
    1. Advertising

  2. On Thu, 15 Mar 2012 09:59:54 -0700 (PDT), llanitedave
    <> 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
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Mar 15, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H5N1
    Replies:
    0
    Views:
    472
  2. Harry George
    Replies:
    9
    Views:
    746
    sonal
    Jun 13, 2006
  3. hairamki

    pragmas with example

    hairamki, Feb 2, 2006, in forum: C++
    Replies:
    3
    Views:
    313
    Default User
    Feb 2, 2006
  4. sandeep

    #pragmas for portability

    sandeep, Jul 18, 2010, in forum: C Programming
    Replies:
    13
    Views:
    809
    Eric Sosman
    Aug 7, 2010
  5. tuser

    Get a list of all pragmas

    tuser, Aug 30, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    105
    tuser
    Aug 30, 2006
Loading...

Share This Page