Joe Rakhimov
Joe Rakhimov

Reputation: 5083

Table count in SQLite

I copied existing SQLite database from assets to databases folder. When I tried to retrieve data from one of table(gloss) it is giving an error:

android.database.sqlite.SQLiteException: no such table: gloss: , while compiling: SELECT DISTINCT id, fk, lang, value FROM gloss WHERE value like '%a%'

I want to make sure that all tables are copied to new db inside 'data/data/package/databases/' How to get count of tables in SQLite db?

Upvotes: 0

Views: 1541

Answers (2)

amalBit
amalBit

Reputation: 12181

Thanks to @CL from the comments:

String SQL_GET_ALL_TABLES = "SELECT count(*) FROM sqlite_master 
                                   WHERE type = 'table' AND 
                                         name != 'android_metadata' AND 
                                         name != 'sqlite_sequence';"
return db.compileStatement(SQL_GET_ALL_TABLES).simpleQueryForLong();

Upvotes: 3

Luis Lavieri
Luis Lavieri

Reputation: 4109

Why are you moving it from /assets? To count tables you should use this query:

SELECT count(*) FROM sqlite_master 
WHERE type = 'table' AND name != 'android_metadata' AND name != 'sqlite_sequence';

Edit**

It seems that my implementation was wrong. Use the query with the other answer.

Upvotes: 3

Related Questions