I'm using swift 3 and I'd like to be able to loop through all the tables in my sqlite database. Is there an easy function to do this? I just want to retrieve the table names.
Asked
Active
Viewed 4,443 times
2
-
1you need to fire a sql query to find all table names in db and sql query is not restricted to swift, ovj-c or any other language. You can do it in all. – Mahendra Apr 12 '17 at 10:28
-
The important question is what framework you are using to communicate between swift and sqlite – luk2302 Apr 12 '17 at 10:29
-
pod 'SQLite.swift', '~> 0.11.3' this is the pod I'm using the Sqlite.swift framework made by stephencelis https://github.com/stephencelis/SQLite.swift – Richard Thompson Apr 12 '17 at 10:31
-
@RichardG how would I write a direct SQL query to get these names? – Richard Thompson Apr 12 '17 at 10:31
1 Answers
7
In sqlite database schema is sqlite_master table. It contains name of all the schema (table, Indexes, Views, etc).
to see a list of the tables in the SQLLite database, Command is ".tables". and equivalent SQlite query to get all table names is :
select name from sqlite_master where type='table'
You can use SQL wrapper class for swift 3.0 to execute above query and fetch result.

PlusInfosys
- 3,416
- 1
- 19
- 33