Hard work
Hard work

Reputation: 45

Find number of columns in a table | Sqlite3

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?

Upvotes: 1

Views: 1089

Answers (1)

Igor Tandetnik
Igor Tandetnik

Reputation: 52471

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.

Upvotes: 2

Related Questions