[Tutor] sqlite3: turning on foreign key support thru python

Monte Milanuk memilanuk at gmail.com
Fri Dec 16 21:21:46 CET 2011


That helped immensely... I was trying some different things trying to get
at the results, but it never occurred to me to try iterating over it.  The
bit about some objects being iterable and some not is good to know!

Thanks,

Monte

On Fri, Dec 16, 2011 at 11:43 AM, Modulok <modulok at gmail.com> wrote:

> >> How do I tell if it succeeded (short of trying an operation that should
> be
> >> blocked by foreign keys)?  How do I use that cursor object returned by
> the
> >> pragma query to tell if its a '1' (on) or a '0' (off) and verify the
> state?
>
>
> The cursor object contains the result set. It's a python generator object.
> (Or
> at least a generator interface.) You have to iterate over it in order to
> see
> the resulting rows which are stored as a tuple. Not all operations return a
> result row. (For example, conn.execute('pragma foreign_keys=ON' will
> return a
> cursor object, but it won't generate any result rows, as there were
> none returned by the database.)
>
> To see the result of your second command, do something like this::
>
>    rows = conn.execute('pragma foreign_keys')
>    for r in rows:
>        print r
>
>
> You'll then see something like this when foreign keys are turned on::
>
>    (1,)
>
> Or this when they're turned off::
>
>    (0,)
>
> Hope that helps.
> -Modulok-
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111216/d2bf47d5/attachment.html>


More information about the Tutor mailing list