From 8a7389f27605475130623636741c7549b7301453 Mon Sep 17 00:00:00 2001 From: shane Date: Fri, 10 Oct 2008 06:01:59 +0000 Subject: [PATCH] Initial test cases for the new LIMIT/OFFSET support for DELETE/UPDATE. (CVS 5789) FossilOrigin-Name: d9f5e15ca00d4d54dc395926e4c9171f1d24982a --- manifest | 11 +- manifest.uuid | 2 +- test/wherelimit.test | 275 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 282 insertions(+), 6 deletions(-) create mode 100644 test/wherelimit.test diff --git a/manifest b/manifest index b56f9b95a8..63ec8ad82c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updated\sLIMIT\ssupport\sfor\sDELETE/UPDATE.\s\sOmit\soption\schanged\sto\sSQLITE_ENABLE_UPDATE_DELETE_LIMIT.\s(CVS\s5788) -D 2008-10-10T04:34:16 +C Initial\stest\scases\sfor\sthe\snew\sLIMIT/OFFSET\ssupport\sfor\sDELETE/UPDATE.\s(CVS\s5789) +D 2008-10-10T06:02:00 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 7fc26e087207e7a4a7723583dbd7997477af3b13 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -617,6 +617,7 @@ F test/where3.test 97d3936e6a443b968f1a61cdcc0f673252000e94 F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 F test/where6.test 42c4373595f4409d9c6a9987b4a60000ad664faf +F test/wherelimit.test 3464395714151cdce9f7f28a19d2cf344bd934c8 F test/zeroblob.test 792124852ec61458a2eb527b5091791215e0be95 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 @@ -643,7 +644,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P c2cf9d60d6626844193b008a37e4417aa0a0f323 -R dbb64f376591fe1fef8fc7d76b6610d5 +P c10e8a3c7ab7f21c95f24d0aba590f5b18a4b028 +R b166ba9a18f5976ff7ef273258c21d55 U shane -Z b0043e2235752f0517ee1d3e5441bcb7 +Z b86642ea37c63f597875144fc2ecff76 diff --git a/manifest.uuid b/manifest.uuid index 5c1c844ba5..95e681999b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c10e8a3c7ab7f21c95f24d0aba590f5b18a4b028 \ No newline at end of file +d9f5e15ca00d4d54dc395926e4c9171f1d24982a \ No newline at end of file diff --git a/test/wherelimit.test b/test/wherelimit.test new file mode 100644 index 0000000000..5352d6fcdc --- /dev/null +++ b/test/wherelimit.test @@ -0,0 +1,275 @@ +# 2008 October 6 +# +# 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. The +# focus of this file is testing the LIMIT ... OFFSET ... clause +# of UPDATE and DELETE statements. +# +# $Id: wherelimit.test,v 1.1 2008/10/10 06:02:00 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc create_test_data {size} { + # Build some test data + # + execsql { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x int, y int); + BEGIN; + } + for {set i 1} {$i<=$size} {incr i} { + for {set j 1} {$j<=$size} {incr j} { + execsql "INSERT INTO t1 VALUES([expr {$i}],[expr {$j}])" + } + } + execsql { + COMMIT; + } + return {} +} + +ifcapable {update_delete_limit} { + + # check syntax error support + do_test wherelimit-0.1 { + catchsql {DELETE FROM t1 ORDER BY x} + } {1 {ORDER BY without LIMIT on DELETE}} + do_test wherelimit-0.2 { + catchsql {DELETE FROM t1 WHERE x=1 ORDER BY x} + } {1 {ORDER BY without LIMIT on DELETE}} + do_test wherelimit-0.3 { + catchsql {UPDATE t1 SET y=1 WHERE x=1 ORDER BY x} + } {1 {ORDER BY without LIMIT on UPDATE}} + + # no AS on table sources + do_test wherelimit-0.4 { + catchsql {DELETE FROM t1 AS a WHERE x=1} + } {1 {near "AS": syntax error}} + do_test wherelimit-0.5 { + catchsql {UPDATE t1 AS a SET y=1 WHERE x=1} + } {1 {near "AS": syntax error}} + + # check deletes w/o where clauses but with limit/offsets + create_test_data 5 + do_test wherelimit-1.0 { + execsql {SELECT count(*) FROM t1} + } {25} + do_test wherelimit-1.1 { + execsql {DELETE FROM t1} + execsql {SELECT count(*) FROM t1} + } {0} + create_test_data 5 + do_test wherelimit-1.2 { + execsql {DELETE FROM t1 LIMIT 5} + execsql {SELECT count(*) FROM t1} + } {20} + do_test wherelimit-1.3 { + # limit 5 + execsql {DELETE FROM t1 ORDER BY x LIMIT 5} + execsql {SELECT count(*) FROM t1} + } {15} + do_test wherelimit-1.4 { + # limit 5, offset 2 + execsql {DELETE FROM t1 ORDER BY x LIMIT 5 OFFSET 2} + execsql {SELECT count(*) FROM t1} + } {10} + do_test wherelimit-1.5 { + # limit 5, offset -2 + execsql {DELETE FROM t1 ORDER BY x LIMIT 5 OFFSET -2} + execsql {SELECT count(*) FROM t1} + } {5} + do_test wherelimit-1.6 { + # limit -5 (no limit), offset 2 + execsql {DELETE FROM t1 ORDER BY x LIMIT 2, -5} + execsql {SELECT count(*) FROM t1} + } {2} + do_test wherelimit-1.7 { + # limit 5, offset -2 (no offset) + execsql {DELETE FROM t1 ORDER BY x LIMIT -2, 5} + execsql {SELECT count(*) FROM t1} + } {0} + create_test_data 5 + do_test wherelimit-1.8 { + # limit -5 (no limit), offset -2 (no offset) + execsql {DELETE FROM t1 ORDER BY x LIMIT -2, -5} + execsql {SELECT count(*) FROM t1} + } {0} + create_test_data 3 + do_test wherelimit-1.9 { + # limit 5, offset 2 + execsql {DELETE FROM t1 ORDER BY x LIMIT 2, 5} + execsql {SELECT count(*) FROM t1} + } {4} + do_test wherelimit-1.10 { + # limit 5, offset 5 + execsql {DELETE FROM t1 ORDER BY x LIMIT 5 OFFSET 5} + execsql {SELECT count(*) FROM t1} + } {4} + do_test wherelimit-1.11 { + # limit 50, offset 30 + execsql {DELETE FROM t1 ORDER BY x LIMIT 50 OFFSET 30} + execsql {SELECT count(*) FROM t1} + } {4} + do_test wherelimit-1.12 { + # limit 50, offset 30 + execsql {DELETE FROM t1 ORDER BY x LIMIT 30, 50} + execsql {SELECT count(*) FROM t1} + } {4} + do_test wherelimit-1.13 { + execsql {DELETE FROM t1 ORDER BY x LIMIT 50 OFFSET 50} + execsql {SELECT count(*) FROM t1} + } {4} + + + create_test_data 6 + do_test wherelimit-2.0 { + execsql {SELECT count(*) FROM t1} + } {36} + do_test wherelimit-2.1 { + execsql {DELETE FROM t1 WHERE x=1} + execsql {SELECT count(*) FROM t1} + } {30} + create_test_data 6 + do_test wherelimit-2.2 { + execsql {DELETE FROM t1 WHERE x=1 LIMIT 5} + execsql {SELECT count(*) FROM t1} + } {31} + do_test wherelimit-2.3 { + # limit 5 + execsql {DELETE FROM t1 WHERE x=1 ORDER BY x LIMIT 5} + execsql {SELECT count(*) FROM t1} + } {30} + do_test wherelimit-2.4 { + # limit 5, offset 2 + execsql {DELETE FROM t1 WHERE x=2 ORDER BY x LIMIT 5 OFFSET 2} + execsql {SELECT count(*) FROM t1} + } {26} + do_test wherelimit-2.5 { + # limit 5, offset -2 + execsql {DELETE FROM t1 WHERE x=2 ORDER BY x LIMIT 5 OFFSET -2} + execsql {SELECT count(*) FROM t1} + } {24} + do_test wherelimit-2.6 { + # limit -5 (no limit), offset 2 + execsql {DELETE FROM t1 WHERE x=3 ORDER BY x LIMIT 2, -5} + execsql {SELECT count(*) FROM t1} + } {20} + do_test wherelimit-2.7 { + # limit 5, offset -2 (no offset) + execsql {DELETE FROM t1 WHERE x=3 ORDER BY x LIMIT -2, 5} + execsql {SELECT count(*) FROM t1} + } {18} + do_test wherelimit-2.8 { + # limit -5 (no limit), offset -2 (no offset) + execsql {DELETE FROM t1 WHERE x=4 ORDER BY x LIMIT -2, -5} + execsql {SELECT count(*) FROM t1} + } {12} + create_test_data 6 + do_test wherelimit-2.9 { + # limit 5, offset 2 + execsql {DELETE FROM t1 WHERE x=5 ORDER BY x LIMIT 2, 5} + execsql {SELECT count(*) FROM t1} + } {32} + do_test wherelimit-2.10 { + # limit 5, offset 5 + execsql {DELETE FROM t1 WHERE x=6 ORDER BY x LIMIT 5 OFFSET 5} + execsql {SELECT count(*) FROM t1} + } {31} + do_test wherelimit-2.11 { + # limit 50, offset 30 + execsql {DELETE FROM t1 WHERE x=1 ORDER BY x LIMIT 50 OFFSET 30} + execsql {SELECT count(*) FROM t1} + } {31} + do_test wherelimit-2.12 { + # limit 50, offset 30 + execsql {DELETE FROM t1 WHERE x=2 ORDER BY x LIMIT 30, 50} + execsql {SELECT count(*) FROM t1} + } {31} + do_test wherelimit-2.13 { + execsql {DELETE FROM t1 WHERE x=3 ORDER BY x LIMIT 50 OFFSET 50} + execsql {SELECT count(*) FROM t1} + } {31} + + + create_test_data 6 + do_test wherelimit-3.0 { + execsql {SELECT count(*) FROM t1} + } {36} + do_test wherelimit-3.1 { + execsql {UPDATE t1 SET y=1 WHERE x=1} + execsql {SELECT count(*) FROM t1 WHERE y=1} + } {11} + create_test_data 6 + do_test wherelimit-3.2 { + execsql {UPDATE t1 SET y=1 WHERE x=1 LIMIT 5} + execsql {SELECT count(*) FROM t1 WHERE y=1} + } {10} + do_test wherelimit-3.3 { + # limit 5 + execsql {UPDATE t1 SET y=2 WHERE x=2 ORDER BY x LIMIT 5} + execsql {SELECT count(*) FROM t1 WHERE y=2} + } {9} + create_test_data 6 + do_test wherelimit-3.4 { + # limit 5, offset 2 + execsql {UPDATE t1 SET y=2 WHERE x=2 ORDER BY x LIMIT 5 OFFSET 2} + execsql {SELECT count(*) FROM t1 WHERE y=1} + } {6} + do_test wherelimit-3.5 { + # limit 5, offset -2 + execsql {UPDATE t1 SET y=2 WHERE x=2 ORDER BY x LIMIT 5 OFFSET -2} + execsql {SELECT count(*) FROM t1 WHERE y=1} + } {5} + do_test wherelimit-3.6 { + # limit -5 (no limit), offset 2 + execsql {UPDATE t1 SET y=3 WHERE x=3 ORDER BY x LIMIT 2, -5} + execsql {SELECT count(*) FROM t1 WHERE y=3} + } {8} + do_test wherelimit-3.7 { + # limit 5, offset -2 (no offset) + execsql {UPDATE t1 SET y=3 WHERE x=3 ORDER BY x LIMIT -2, 5} + execsql {SELECT count(*) FROM t1 WHERE y=3} + } {10} + + do_test wherelimit-3.8 { + # limit -5 (no limit), offset -2 (no offset) + execsql {UPDATE t1 SET y=4 WHERE x=4 ORDER BY x LIMIT -2, -5} + execsql {SELECT count(*) FROM t1 WHERE y=4} + } {9} + create_test_data 6 + do_test wherelimit-3.9 { + # limit 5, offset 2 + execsql {UPDATE t1 SET y=4 WHERE x=5 ORDER BY x LIMIT 2, 5} + execsql {SELECT count(*) FROM t1 WHERE y=4} + } {9} + do_test wherelimit-3.10 { + # limit 5, offset 5 + execsql {UPDATE t1 SET y=4 WHERE x=6 ORDER BY x LIMIT 5 OFFSET 5} + execsql {SELECT count(*) FROM t1 WHERE y=1} + } {6} + do_test wherelimit-3.11 { + # limit 50, offset 30 + execsql {UPDATE t1 SET y=1 WHERE x=1 ORDER BY x LIMIT 50 OFFSET 30} + execsql {SELECT count(*) FROM t1 WHERE y=1} + } {6} + do_test wherelimit-3.12 { + # limit 50, offset 30 + execsql {UPDATE t1 SET y=1 WHERE x=2 ORDER BY x LIMIT 30, 50} + execsql {SELECT count(*) FROM t1 WHERE y=1} + } {6} + do_test wherelimit-3.13 { + execsql {UPDATE t1 SET y=1 WHERE x=3 ORDER BY x LIMIT 50 OFFSET 50} + execsql {SELECT count(*) FROM t1 WHERE y=1} + } {6} + +} + +finish_test