This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Vitaminus Maximus
Recipients Vitaminus Maximus
Date 2016-01-07.18:57:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452193029.87.0.593726838819.issue26043@psf.upfronthosting.co.za>
In-reply-to
Content
Let me provide a completely reproducible code, which demonstrates the issue:

    >>> import sqlite3
    >>> cnx = sqlite3.connect("mytest.db")
    >>> cnx.isolation_level = None
    >>> cursor = cnx.cursor()
    >>> cnx.execute("BEGIN")
    <sqlite3.Cursor object at 0x7f0ab0923490>
    >>> cursor.execute("CREATE TABLE test_table (id integer)")
    <sqlite3.Cursor object at 0x7f0ab0923420>
    >>> cursor.execute("CREATE UNIQUE INDEX id_primary ON test_table(id)")
    <sqlite3.Cursor object at 0x7f0ab0923420>
    >>> cursor.execute("INSERT INTO test_table (id) VALUES (1),(2),(3)")
<sqlite3.Cursor object at 0x7f0ab0923420>
    >>> cursor.execute("CREATE TABLE test_table_2(id_fk integer, txt text,  FOREIGN KEY (id_fk) REFERENCES test_table(id) ON DELETE CASCADE)")
    <sqlite3.Cursor object at 0x7f0ab0923420>
    >>> cursor.execute("INSERT INTO test_table_2 (id_fk, txt) VALUES (1,\"one\"),(2,\"two\"),(3,\"three\")")
    <sqlite3.Cursor object at 0x7f0ab0923420>
    >>> res = cursor.execute("SELECT * FROM test_table_2")
    >>> res
    <sqlite3.Cursor object at 0x7f0ab0923420>
    >>> for r in res:
    ...     print(r)
    ...
    (1, 'one')
    (2, 'two')
    (3, 'three')
    >>> cursor.execute("PRAGMA foreign_keys = ON")
    <sqlite3.Cursor object at 0x7f0ab0923420>
    >>> cursor.execute("DELETE FROM test_table WHERE id = 1")
    <sqlite3.Cursor object at 0x7f0ab0923420>
    >>> res = cursor.execute("SELECT * FROM test_table_2")
    >>> for r in res:
    ...     print(r)
    ...
    (1, 'one')
    (2, 'two')
    (3, 'three')

As you can see, even though I explicitly set isolation_level, start transaction and specify PRAGMA foreign_keys = ON, it does not work. The expected behaviour is that when I run the last SELECT command, it should return only two rows (because a "parent" raw with id = 1 was deleted). By the way, if I run these commands in pure sqlite prompt, then I get what I expect to see.
History
Date User Action Args
2016-01-07 18:57:09Vitaminus Maximussetrecipients: + Vitaminus Maximus
2016-01-07 18:57:09Vitaminus Maximussetmessageid: <1452193029.87.0.593726838819.issue26043@psf.upfronthosting.co.za>
2016-01-07 18:57:09Vitaminus Maximuslinkissue26043 messages
2016-01-07 18:57:09Vitaminus Maximuscreate