Best SQLite practices on the iPhone [closed] Best SQLite practices on the iPhone [closed] sqlite sqlite

Best SQLite practices on the iPhone [closed]


Measure your app's memory footprint and look for leaks in Instruments. Then try it after invoking sqlite3_exec with:

  • pragma cache_size=1

and/or

  • pragma synchronous=0

YMMV. There are reports of performance boosts, large reductions in RAM usage, and fewer leaks. However, be careful about making adjustments without understanding the impact (for example, synchronous turns off flushing which speeds things up by a lot, but can cause DB corruption if the phone is power-cycled at the wrong time).

More here: http://www.sqlite.org/pragma.html


I can recommend using FMDB as a nice Cocoa SQLite wrapper.


Off the top of my head:

  • Use Transactions.
  • Make sure your SQL leverages tables in the correct order.
  • Don't add indexes you're not entirely sure you need.

Perhaps not only specific to iPhone but to embedded devices there are some great tips here.

This link pertains to an older version of SQLite but still proves useful.

Lastly this Stack Question also has some good info.

We use SQLite with a .Net Compact Framework Application currently and it's performance is fantastic and we've spent a bit of time optimizing but not nearly as much as we could.

Best of luck.