2

When I do this in Android:

sqlite> SELECT * FROM secure WHERE name='mock_location' OR value=2.2 ORDER BY value ASC;

I get this:

44|mock_location|1
56|facelock_liveliness_recognition_threshold|2.2

But I want the column names for (*) in the first row, like this:

_id|name|value
44|mock_location|1
56|facelock_liveliness_recognition_threshold|2.2

How can I do that in a single query?

dbc
  • 104,963
  • 20
  • 228
  • 340
JohnyTex
  • 3,323
  • 5
  • 29
  • 52
  • If you are use it with Cursor . You can get it by java code – Krish Apr 28 '17 at 16:34
  • I can't use Cursor because I am trying to construct the cursor. – JohnyTex May 02 '17 at 07:09
  • Are you using CursorFactory ? – Krish May 02 '17 at 08:08
  • I am extending AbstractCursor. – JohnyTex May 02 '17 at 08:54
  • What is your exact requirement? – Krish May 02 '17 at 09:10
  • When query is executed from within the ContentProvider, I issue a CLI call that returns the result above. However I need to construct a cursor to return, and it needs to not only point to the results but also to the column names. However, I don't want to issue another query just for that, so I figure I could parse the column names directly from the result if I could get them from there. – JohnyTex May 02 '17 at 09:48
  • if you are launching `sqlite3` tool so it means you are getting the data from your local filesytem, so why dont you simply do that using `SQLiteDatabase` ? – pskink May 02 '17 at 10:07
  • Because I need superuser permission, and as far as I know, I can only do that via command line, right? – JohnyTex May 02 '17 at 10:12
  • 3
    try `.headers on` – pskink May 02 '17 at 10:22
  • Can I issue in one-shot command line call? – JohnyTex May 02 '17 at 10:23
  • never tried, but i think that should work, just separate them with `\n` (or `\r\n`) – pskink May 02 '17 at 10:25
  • Related [How to get a list of column names on Sqlite3 database?](https://stackoverflow.com/q/947215/3744182), specifically [this answer](https://stackoverflow.com/a/48756911/3744182) by Sam Houston. – dbc Mar 26 '23 at 00:52

1 Answers1

2

I did this and it works:

sqlite3 -header /data/data/com.android.providers.settings/databases/settings.db "SELECT * FROM secure WHERE name='mock_location' OR value=2.2 ORDER BY value ASC;"
JohnyTex
  • 3,323
  • 5
  • 29
  • 52