[Tutor] sqlite3: turning on foreign key support thru python
Wayne Werner
waynejwerner at gmail.com
Mon Dec 19 00:15:10 CET 2011
On Fri, Dec 16, 2011 at 1:43 PM, 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
>
If you're mucking about in the interactive prompt, and you just want to see
the results quickly you can just turn it into a tuple or a list (list would
be less typing):
print(list(rows))
or just
list(rows)
HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111218/9757aab9/attachment-0001.html>
More information about the Tutor
mailing list