• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Check number of rows affected by SQLite query

Greum

Well-Known Member
Is there a way to check the number of rows that a SQLite query has affected? For instance on delete I want to be able to report that No, 1, 2 etc records were deleted.

I've looked at try ... catch ... but that just tells me the query ran, not how many records (if any) were deleted.
 
Hm, good question. Best I could come up with is a C library interface to SQLite, which does this

https://www.sqlite.org/c3ref/changes.html

But no Android/Java equivalent.

You could first do a SELECT, using the same criteria as your DELETE statement. Count how many records are returned.
 
Thanks LV. I've been searching for a solution for hours. It's something I could do easily in PHP :) I hadn't thought of a C library but the SELECT option looks like being my best bet.
 
I would say that's a bit of a limitation for SQLite there. Other databases set a variable which you can look at, to get the number of rows affected by the most recent query.
 
Indeed. Maybe it's the implementation.

It seems a PITA just to get the count with a rawQuery o_O
 
Well I guess it is 'Lite', hence it's missing a few features of more sophisticated databases. :p
 
Back
Top Bottom