I am using cpp and -lsqlite3 to handle some data. I just wanted to ask about a query that will return the number of columns of a specific table in sqlite. Is it possible to find out?
Asked
Active
Viewed 520 times
1
-
1https://stackoverflow.com/questions/4301320/how-to-count-number-of-columns-in-a-table-in-sqlite – nicomp Dec 31 '20 at 14:46
-
[Docs](https://www.sqlite.org/pragma.html#pragma_table_info) have the answer. – Manuel Dec 31 '20 at 14:52
1 Answers
2
With sufficiently recent SQLite version:
select count(*)
from pragma_table_info('tableName')
If it doesn't have to be a SQL query but could be an API call, then a) prepare a query select * from tableName
(just prepare, you don't need to actually execute it), then call sqlite3_column_count
on the resulting statement handle.

Igor Tandetnik
- 50,461
- 4
- 56
- 85