Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: third_party/sqlite/src/test/fkey1.test

Issue 1610963002: Import SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/test/filectrl.test ('k') | third_party/sqlite/src/test/fkey2.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 2001 September 15 1 # 2001 September 15
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 PRAGMA foreign_key_list(t9); 114 PRAGMA foreign_key_list(t9);
115 } 115 }
116 } [concat \ 116 } [concat \
117 {0 0 t5 d {} {SET DEFAULT} CASCADE NONE} \ 117 {0 0 t5 d {} {SET DEFAULT} CASCADE NONE} \
118 {0 1 t5 e {} {SET DEFAULT} CASCADE NONE} \ 118 {0 1 t5 e {} {SET DEFAULT} CASCADE NONE} \
119 ] 119 ]
120 do_test fkey1-3.5 { 120 do_test fkey1-3.5 {
121 sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 121 sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0
122 } {0 0 0} 122 } {0 0 0}
123 123
124 # Stress the dequoting logic. The first test is not so bad.
125 do_execsql_test fkey1-4.0 {
126 PRAGMA foreign_keys=ON;
127 CREATE TABLE "xx1"("xx2" TEXT PRIMARY KEY, "xx3" TEXT);
128 INSERT INTO "xx1"("xx2","xx3") VALUES('abc','def');
129 CREATE TABLE "xx4"("xx5" TEXT REFERENCES "xx1" ON DELETE CASCADE);
130 INSERT INTO "xx4"("xx5") VALUES('abc');
131 INSERT INTO "xx1"("xx2","xx3") VALUES('uvw','xyz');
132 SELECT 1, "xx5" FROM "xx4";
133 DELETE FROM "xx1";
134 SELECT 2, "xx5" FROM "xx4";
135 } {1 abc}
136
137 # This case is identical to the previous except the "xx" in each name
138 # is changed to a single escaped double-quote character.
139 do_execsql_test fkey1-4.1 {
140 PRAGMA foreign_keys=ON;
141 CREATE TABLE """1"("""2" TEXT PRIMARY KEY, """3" TEXT);
142 INSERT INTO """1"("""2","""3") VALUES('abc','def');
143 CREATE TABLE """4"("""5" TEXT REFERENCES """1" ON DELETE CASCADE);
144 INSERT INTO """4"("""5") VALUES('abc');
145 INSERT INTO """1"("""2","""3") VALUES('uvw','xyz');
146 SELECT 1, """5" FROM """4";
147 DELETE FROM """1";
148 SELECT 2, """5" FROM """4";
149 } {1 abc}
150 do_execsql_test fkey1-4.2 {
151 PRAGMA table_info="""1";
152 } {0 {"2} TEXT 0 {} 1 1 {"3} TEXT 0 {} 0}
153
154 #-------------------------------------------------------------------------
155 #
156 do_execsql_test fkey1-5.1 {
157 CREATE TABLE t11(
158 x INTEGER PRIMARY KEY,
159 parent REFERENCES t11 ON DELETE CASCADE
160 );
161 INSERT INTO t11 VALUES (1, NULL), (2, 1), (3, 2);
162 } {}
163
164 # The REPLACE part of this statement deletes the row (2, 1). Then the
165 # DELETE CASCADE caused by deleting that row removes the (3, 2) row. Which
166 # would have been the parent of the new row being inserted. Causing an
167 # FK violation.
168 #
169 do_catchsql_test fkey1-5.2 {
170 INSERT OR REPLACE INTO t11 VALUES (2, 3);
171 } {1 {FOREIGN KEY constraint failed}}
172
173 # A similar test to the above.
174 do_execsql_test fkey1-5.3 {
175 CREATE TABLE Foo (
176 Id INTEGER PRIMARY KEY,
177 ParentId INTEGER REFERENCES Foo(Id) ON DELETE CASCADE, C1
178 );
179 INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (1, null, 'A');
180 INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (2, 1, 'A-2-1');
181 INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (3, 2, 'A-3-2');
182 INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (4, 3, 'A-4-3');
183 }
184 do_catchsql_test fkey1-5.4 {
185 INSERT OR REPLACE INTO Foo(Id, ParentId, C1) VALUES (2, 3, 'A-2-3');
186 } {1 {FOREIGN KEY constraint failed}}
187
124 finish_test 188 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/filectrl.test ('k') | third_party/sqlite/src/test/fkey2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698