drh | 62c6819 | 2000-05-30 00:51:26 +0000 | [diff] [blame] | 1 | # Copyright (c) 1999, 2000 D. Richard Hipp |
| 2 | # |
| 3 | # This program is free software; you can redistribute it and/or |
| 4 | # modify it under the terms of the GNU General Public |
| 5 | # License as published by the Free Software Foundation; either |
| 6 | # version 2 of the License, or (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | # General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public |
| 14 | # License along with this library; if not, write to the |
| 15 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | # Boston, MA 02111-1307, USA. |
| 17 | # |
| 18 | # Author contact information: |
| 19 | # drh@hwaci.com |
| 20 | # http://www.hwaci.com/drh/ |
| 21 | # |
| 22 | #*********************************************************************** |
| 23 | # This file implements regression tests for SQLite library. The |
| 24 | # focus of this file is testing the DELETE FROM statement. |
| 25 | # |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame^] | 26 | # $Id: delete.test,v 1.3 2000/06/03 18:06:53 drh Exp $ |
drh | 62c6819 | 2000-05-30 00:51:26 +0000 | [diff] [blame] | 27 | |
| 28 | set testdir [file dirname $argv0] |
| 29 | source $testdir/tester.tcl |
| 30 | |
| 31 | # Try to delete from a non-existant table. |
| 32 | # |
| 33 | do_test delete-1.1 { |
| 34 | set v [catch {execsql {DELETE FROM test1}} msg] |
| 35 | lappend v $msg |
| 36 | } {1 {no such table: test1}} |
| 37 | |
| 38 | # Try to delete from sqlite_master |
| 39 | # |
| 40 | do_test delete-2.1 { |
| 41 | set v [catch {execsql {DELETE FROM sqlite_master}} msg] |
| 42 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 43 | } {1 {table sqlite_master may not be modified}} |
drh | 62c6819 | 2000-05-30 00:51:26 +0000 | [diff] [blame] | 44 | |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame^] | 45 | # Delete selected entries from a table with and without an index. |
| 46 | # |
| 47 | do_test delete-3.1a { |
| 48 | execsql {CREATE TABLE table1(f1 int, f2 int)} |
| 49 | execsql {INSERT INTO table1 VALUES(1,2)} |
| 50 | execsql {INSERT INTO table1 VALUES(2,4)} |
| 51 | execsql {INSERT INTO table1 VALUES(3,8)} |
| 52 | execsql {INSERT INTO table1 VALUES(4,16)} |
| 53 | execsql {SELECT * FROM table1 ORDER BY f1} |
| 54 | } {1 2 2 4 3 8 4 16} |
| 55 | do_test delete-3.1b { |
| 56 | execsql {DELETE FROM table1 WHERE f1=3} |
| 57 | execsql {SELECT * FROM table1 ORDER BY f1} |
| 58 | } {1 2 2 4 4 16} |
| 59 | do_test delete-3.1c { |
| 60 | execsql {CREATE INDEX index1 ON table1(f1)} |
| 61 | execsql {DELETE FROM table1 WHERE f1=3} |
| 62 | execsql {SELECT * FROM table1 ORDER BY f1} |
| 63 | } {1 2 2 4 4 16} |
| 64 | do_test delete-3.1d { |
| 65 | execsql {DELETE FROM table1 WHERE f1=2} |
| 66 | execsql {SELECT * FROM table1 ORDER BY f1} |
| 67 | } {1 2 4 16} |
drh | 62c6819 | 2000-05-30 00:51:26 +0000 | [diff] [blame] | 68 | |
| 69 | |
| 70 | finish_test |