1

Is it safe for my iOS application to depend on the functionality of specific pragma statements when interfacing with a SQLite database?

According to the SQLite documentation:

Specific pragma statements may be removed and others added in future releases of SQLite. There is no guarantee of backwards compatibility.

However, according to this upvoted SO answer:

You can use a pragma to get the indexed columns:

PRAGMA index_info(index-name);

And this one to get the column names for a table:

PRAGMA table_info(table-name);

My specific use case is that I would like my iOS application to check if a specific column exists before making a query via the FMDB SQLite wrapper. I am afraid that using PRAGMA table_info(table-name) may give unexpected results in a hypothetical future release of iOS that includes a newer version of SQLite in which the maintainers decided to drop support for this pragma statement.

Community
  • 1
  • 1
tboyce12
  • 1,449
  • 14
  • 28
  • Another option would be to try to prepare a statement that queries just that one column of a table. If the prepare statement fails, you know the column isn't there. Perhaps do this check once at app startup. – rmaddy May 07 '14 at 22:20
  • Thanks for the input. That is what I'm planning to do for now (i.e. `SELECT column-name FROM table-name LIMIT 1` and check for error). – tboyce12 May 07 '14 at 22:25

1 Answers1

1

I'd be more inclined to use:

FMResultSet* results = [database executeQuery:@"SELECT * FROM tableName LIMIT 0"];
if([[results columnNameToIndexMap] containsObject:@"testColumn"])
David Berry
  • 40,941
  • 12
  • 84
  • 95