SQLite User Forum

Delete all rows from a "without rowid" table will get a wrong number of changed rows
Login

Delete all rows from a "without rowid" table will get a wrong number of changed rows

(1) By anonymous on 2021-06-03 10:51:59 [source]

Reproduce:

  1. Create a table with "without rowid"
  2. Insert some data to the table
  3. Use "delete from tablename" to delete all the rows from the table
  4. Use "select changes()" to get the number of changed rows, the number is 0, which is not correct
$ sqlite3 --version
3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ealt1

Is this a bug or a feature?

Test code:

create table test (id integer primary key not null)without rowid;
insert into test values(1);
delete from test;
select changes(); -- print: 0, which is not correct

drop table test;

create table test (id integer primary key not null)without rowid;
insert into test values(1);
delete from test where 1=1; -- add a where condition solved this problum
select changes(); -- print: 1, correct

drop table test;

create table test (id integer primary key not null); -- remove "without rowid"
insert into test values(1);
delete from test;
select changes(); -- print: 1, correct

(2) By anonymous on 2021-06-03 17:52:58 in reply to 1 [link] [source]

In 1adfca6019, your test case results in a segment fault.

In 39e32187, the problem exists.

Looking forward to the developer's explanation.

(3) By Richard Hipp (drh) on 2021-06-03 18:53:11 in reply to 1 [link] [source]

Bug. Fixed at check-in 820ae3b117c2d8c1.