SQLite

Check-in [659c551d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Do not commit an "OR FAIL" statement that causes foriegn key constraint violations.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 659c551dcc374a0d349ba9419f692e3363839e11d791a17cc35fa1854a674a51
User & Date: dan 2019-05-07 19:44:11
Context
2019-05-07
20:06
Generate all records for INSERT or UPDATE prior to running foreign key constraint checks, since the FK checks might modify the datatype of registers used to generate the records. Fix for ticket [e63cbcfd3378afe6980d6]. (check-in: 3c75605b user: drh tags: trunk)
19:44
Do not commit an "OR FAIL" statement that causes foriegn key constraint violations. (check-in: 659c551d user: dan tags: trunk)
17:47
Strive to prevent harmless compiler warnings in GCC 4.8.5. (check-in: 8b6691f6 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
          db->autoCommit = 1;
          p->nChange = 0;
        }
      }
    }

    /* Check for immediate foreign key violations. */
    if( p->rc==SQLITE_OK ){
      sqlite3VdbeCheckFk(p, 0);
    }
  
    /* If the auto-commit flag is set and this is the only active writer 
    ** VM, then we do either a commit or rollback of the current transaction. 
    **
    ** Note: This block also runs if one of the special errors handled 







|







2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
          db->autoCommit = 1;
          p->nChange = 0;
        }
      }
    }

    /* Check for immediate foreign key violations. */
    if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
      sqlite3VdbeCheckFk(p, 0);
    }
  
    /* If the auto-commit flag is set and this is the only active writer 
    ** VM, then we do either a commit or rollback of the current transaction. 
    **
    ** Note: This block also runs if one of the special errors handled 

Changes to test/fkey7.test.

78
79
80
81
82
83
84




































85
    INSERT INTO c4 VALUES(1), (2), (3);

    ANALYZE;
    INSERT INTO p4(id) VALUES(4);
  }
}





































finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    INSERT INTO c4 VALUES(1), (2), (3);

    ANALYZE;
    INSERT INTO p4(id) VALUES(4);
  }
}


do_execsql_test 4.0 {
  PRAGMA foreign_keys = true;
  CREATE TABLE parent(
    p PRIMARY KEY
  );
  CREATE TABLE child(
    c UNIQUE REFERENCES parent(p)
  );
}

do_catchsql_test 4.1 {
  INSERT OR FAIL INTO child VALUES(123), (123);
} {1 {FOREIGN KEY constraint failed}}

do_execsql_test 4.2 {
  SELECT * FROM child;
} {}

do_execsql_test 4.3 {
  PRAGMA foreign_key_check;
} {}

do_catchsql_test 4.4 {
  INSERT INTO parent VALUES(123);
  INSERT OR FAIL INTO child VALUES(123), (123);
} {1 {UNIQUE constraint failed: child.c}}

do_execsql_test 4.5 {
  SELECT * FROM child;
} {123}

do_execsql_test 4.6 {
  PRAGMA foreign_key_check;
} {}

finish_test