My question can be considered as a continuation of What is the difference between inserting data using ContentValues and Raw SQL in SQLite Android?
My question is more towards: Which is more common for programmers? Or is it a question of what kind of projects they are working on? I notice that all the examples I see in a google search uses contentvalues rather than SQL. Is there a reason for this? Perhaps SQL is no longer in fashion. Or is this due to the more recent Android studio?
ContentValues are used in combination with the convenience (simple to use) methods, such as the SQLiteDatabase
insertmethod that reliably builds the appropriate SQL (including passing values via parameters).They correctly enclose such values.
They cater for many scenarios are very convenient and also reliable. They may also do additional work that a single execSQL will not do, that is return a value.
For the
insertconvenience method the value returned, is a long (Long in Kotlin) and is the rowid of the inserted row or -1 if the row was not inserted but the conflict was trapped (insertincludesOR IGNOREso unique, null and check constraints do not result in an error condition).The coding is probably tidier.
SQL is still used, it's just that it is written on your behalf by the convenience methods. It certainly does not hurt to have a good understanding of SQL.