jeudi 21 janvier 2016

(Android, SQLite) DELETE statement with LIMIT clause

I'm trying to get to grips with SQLite under Android (I'm already familiar with MySQL).

In MySQL I could have a table thus...

mysql> select * from calls;
+----+---------------------+
| id | time                |
+----+---------------------+
|  2 | 2016-01-21 11:29:09 |
|  3 | 2016-01-21 11:29:10 |
|  4 | 2016-01-21 11:29:10 |
|  5 | 2016-01-21 11:29:10 |
|  6 | 2016-01-21 11:29:10 |
|  7 | 2016-01-21 11:29:11 |
|  8 | 2016-01-21 11:29:11 |
|  9 | 2016-01-21 11:29:11 |
+----+---------------------+

And use this delete statement to remove the oldest record...

DELETE FROM calls ORDER BY time LIMIT 1;

What is the Android/SQLite best practice for doing this? I would have tried to use db.execSQL() function to run the query directly but the Android SDK docs say that this is bad practice for security reasons.

How do I articulate this delete request using db.delete(...)? That function only has WHERE arguments, and I'm not using WHERE.

Aucun commentaire:

Enregistrer un commentaire