From: drh Date: Sat, 27 Feb 2016 19:03:22 +0000 (+0000) Subject: More compact implementation of PRAGMA onconflict, and some test cases. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fpragma-onconflict;p=thirdparty%2Fsqlite.git More compact implementation of PRAGMA onconflict, and some test cases. FossilOrigin-Name: 3e5d38f5b37da08a3d4704c23a51399624e3ecab --- diff --git a/manifest b/manifest index cfdf895f82..80b1c9ac57 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\s"PRAGMA\sonconflict=FAIL"\sstatement\sto\schange\sthe\sdefault\nON\sCONFLICT\salgorithm\sto\ssomething\sother\sthan\sABORT. -D 2016-02-27T17:16:34.701 +C More\scompact\simplementation\sof\sPRAGMA\sonconflict,\sand\ssome\stest\scases. +D 2016-02-27T19:03:22.754 F Makefile.in 4e90dc1521879022aa9479268a4cd141d1771142 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 4f319afb7c049d40aff7af6e8c4e7cc2ba18e079 @@ -342,7 +342,7 @@ F src/parse.y c3ce2c4a7cbf0b699239be6b2a945c5cb51875e2 F src/pcache.c 647bb53a86b7bbcf55ad88089b3ea5a9170b90df F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545 F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 -F src/pragma.c f8f9bf11e2cb362d3a81264b7795ca89a8f695d9 +F src/pragma.c b9d960d385968789ea79e28dd44a62ed57ad9208 F src/pragma.h 0639ea9901f8a22433a94ca8b0f35921d6ac2306 F src/prepare.c 22df6171aec1d86904ed2ad30c2348a5748aa04e F src/printf.c 63e6fb12bbe702dd664dc3703776c090383a5a26 @@ -920,6 +920,7 @@ F test/null.test 0dcce4f04284ec66108c503327ad6d224c0752b3 F test/numcast.test 5d126f7f581432e86a90d1e35cac625164aec4a1 F test/numindex1.test 20a5450d4b056e48cd5db30e659f13347a099823 F test/offset1.test f06b83657bcf26f9ce805e67450e189e282143b2 +F test/onconflict1.test c03c755a2efda1c8d6e74e15f04e16ac14f0acba F test/openv2.test 0d3040974bf402e19b7df4b783e447289d7ab394 F test/orderby1.test 4d22a7c75f6a83fc1f188cc7bb5192285fdf2552 F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04 @@ -1451,10 +1452,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3c36948f16b58fe8042c37d0df634308b4e48217 -R 60015793d5c7a8b9994caa990b084503 -T *branch * pragma-onconflict -T *sym-pragma-onconflict * -T -sym-trunk * +P 3a0c347cca58fdaefd1b3644ba1649a5b4ebe91f +R 58122bd2911f76c0eb3005cd77e413fa U drh -Z 2a9189a9e71cee0c4156061d04e62711 +Z eb55459b1b74d5d83abb570469162143 diff --git a/manifest.uuid b/manifest.uuid index 3c0f43e458..0061de6c50 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3a0c347cca58fdaefd1b3644ba1649a5b4ebe91f \ No newline at end of file +3e5d38f5b37da08a3d4704c23a51399624e3ecab \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 84d65a2f9e..a40c077db0 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1903,15 +1903,13 @@ void sqlite3Pragma( ** Set the default conflict handling algorithm. */ case PragTyp_ONCONFLICT: { - const char *zRes = "ABORT"; - if( zRight ){ - if( sqlite3StrICmp(zRight,"FAIL")==0 ) db->dfltOnError = OE_Fail; - if( sqlite3StrICmp(zRight,"ABORT")==0 ) db->dfltOnError = OE_Abort; - if( sqlite3StrICmp(zRight,"ROLLBACK")==0 ) db->dfltOnError = OE_Rollback; - } - switch( db->dfltOnError ){ - case OE_Fail: zRes = "FAIL"; break; - case OE_Rollback: zRes = "ROLLBACK"; break; + static const char *azMode[] = { "ABORT", "FAIL", "ROLLBACK" }; + static const u8 aeMode[] = { OE_Abort, OE_Fail, OE_Rollback }; + const char *zRes = 0; + int i; + for(i=0; idfltOnError = aeMode[i]; + if( db->dfltOnError==aeMode[i] ) zRes = azMode[i]; } returnSingleText(v, "onconflict", zRes); break; diff --git a/test/onconflict1.test b/test/onconflict1.test new file mode 100644 index 0000000000..15557eda80 --- /dev/null +++ b/test/onconflict1.test @@ -0,0 +1,99 @@ +# 2016-02-27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file focuses on the PRAGMA onconflict statement. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix onconflict1 + +do_execsql_test 100 { + PRAGMA onconflict; +} {ABORT} +do_execsql_test 110 { + PRAGMA onconflict=Rollback; +} {ROLLBACK} +do_execsql_test 120 { + PRAGMA onconflict=fail; +} {FAIL} +do_execsql_test 130 { + PRAGMA onconflict=whatever; +} {FAIL} +do_execsql_test 140 { + PRAGMA onconflict=abort; +} {ABORT} + +do_catchsql_test 200 { + CREATE TABLE t1(a, b UNIQUE); + INSERT INTO t1(a,b) VALUES(1,1),(2,2),(3,3),(98,98),(99,99); + BEGIN; + UPDATE t1 SET a=100 WHERE a=101; + UPDATE t1 SET b=10; +} {1 {UNIQUE constraint failed: t1.b}} +do_execsql_test 201 { + SELECT a, b FROM t1 ORDER BY a; +} {1 1 2 2 3 3 98 98 99 99} + +do_catchsql_test 210 { + PRAGMA onconflict=FAIL; + UPDATE t1 SET b=10; +} {1 {UNIQUE constraint failed: t1.b}} +do_execsql_test 211 { + SELECT a, b FROM t1 ORDER BY a; +} {1 10 2 2 3 3 98 98 99 99} + +do_catchsql_test 220 { + ROLLBACK; + BEGIN; + PRAGMA onconflict=ROLLBACK; + UPDATE t1 SET b=10; +} {1 {UNIQUE constraint failed: t1.b}} +do_execsql_test 221 { + SELECT a, b FROM t1 ORDER BY a; +} {1 1 2 2 3 3 98 98 99 99} +do_catchsql_test 222 { + ROLLBACK +} {1 {cannot rollback - no transaction is active}} + +do_catchsql_test 300 { + PRAGMA onconflict=ABORT; + BEGIN; + INSERT INTO t1(a,b) VALUES(4,4),(5,1),(6,6); +} {1 {UNIQUE constraint failed: t1.b}} +do_execsql_test 301 { + SELECT a, b FROM t1 ORDER BY a; +} {1 1 2 2 3 3 98 98 99 99} + +do_catchsql_test 310 { + PRAGMA onconflict=ROLLBACK; + INSERT INTO t1(a,b) VALUES(4,4),(5,1),(6,6); +} {1 {UNIQUE constraint failed: t1.b}} +do_execsql_test 311 { + SELECT a, b FROM t1 ORDER BY a; +} {1 1 2 2 3 3 98 98 99 99} +do_catchsql_test 312 { + ROLLBACK +} {1 {cannot rollback - no transaction is active}} + +do_catchsql_test 320 { + PRAGMA onconflict=FAIL; + BEGIN; + INSERT INTO t1(a,b) VALUES(4,4),(5,1),(6,6); +} {1 {UNIQUE constraint failed: t1.b}} +do_execsql_test 321 { + SELECT a, b FROM t1 ORDER BY a; +} {1 1 2 2 3 3 4 4 98 98 99 99} +do_catchsql_test 322 { + ROLLBACK +} {0 {}} + +finish_test