Mar 142008

After asking on the MacRumors forums I was pointed back to FMDB that I had looked at a couple of days ago. FMDB is a Cocoa wrapper for SQLite3. I had a look at it, and after my initial difficulties, I found that I was trying a way to complicated way to use it for my iPhone applications. To add FMDB, simply do the following:

  • in XCode in your project window, rightclick your “Classes” and Add -> “New Group”, call it FMDB
  • drag the files from src in the FMDB package into the new group
  • Rightclick Frameworks, Add -> “Existing frameworks”, select /Developer/Platforms/Aspen.platform/Developer/SDKs/Aspen1.2.sdk/usr/lib/libsqlite3.dylib and press “Add”
  • Compile, smile and start using it :-)
 Posted by at 4:08 am

16 comments on “SQLite for iPhone SDK

  1. Josh E on said:

    Hi Niklas,

    Thanks for the tip!

    I’m particularly interested in accessing the sqlite databases where Apple stores sms messages and call histories. Have any idea’s there?


  2. niklas on said:

    Sorry, I haven’t looked at accessing the rest of the system, I’m just working within the applications I’m writing at the moment

  3. Oskar on said:

    I’m quite a newb so thanks for the tips, but after following these steps I get this Xcode error:

    duplicate symbol _main in …/fmdb.o and …/main.o

    I already have a file with a main method, so how do I include FMDB?

  4. Oskar on said:

    Ah, nevermind, I looked at the source closer and realized that fmdb.o is not part of the actual FMDB wrapper.

  5. Oskar on said:

    Nevermind, I checked out the source more and realized that fmdb.m is not part of the wrapper itself.

  6. Seb on said:

    Thanks for posting that info. I have been trying to figure out how to use SQLite on iPhone for a while now. I’ll give it a shot and report back.

  7. Marco Papa on said:

    The SQLite sample from the beta 5 iPhone SDL uses this frameworrk instead:


    BTW, people that are thinking about accessing other parts of the system implemented as SQLite databases are out of luck. Each iPhone application is limited to its own “sandbox” and that’s it.

  8. steve on said:


    I just started with with objective-c/cocoa/iPhone SDK and trying to get the FMDB wrapper working but when I try and compile a fresh project it says:

    error: Cocoa/Cocoa.h not found

    Any help would be greatly appreciated.

  9. niklas on said:

    Make sure you’ve got the Cocoa framework included in your project

  10. icoco on said:

    hi, how to create a table from iphone ?

  11. Brian Armstrong on said:

    I’m getting the same error that Oskar had on March 18, namely:

    duplicate symbol _main in …/fmdb.o and …/main.o

    How do I fix this? I’m using XCode 3.1.


  12. niklas on said:

    You seem to have two definitions of the function main(). Try removing one of them

  13. Matt on said:

    Has anyone had a EXC_BAD_ACCESS error with this? I’ve spent almost 3 hours trying to figure it out to no avail.

    I completed the steps above, checked to ensure my database is being created, however my app fails when trying to run a query.

    Thanks for your help,

  14. Nik on said:

    Sounds like you’re calling a non-existent method or a method on an object that has been deallocated or similar

  15. Matt on said:

    Yep, dumb mistake… The example code I followed left out the all important [db open] call.

  16. Francesco on said:

    Hello! I’ve a problem using FMDB…I have a valid sqlite file database added to the project. I’m using the DB file from Sqlite Book project example from Apple.
    The program open the database but don’t find the table inside the DB.
    FMResultSet *rs = [db executeQuery:@”SELECT author, copyright FROM book WHERE pk= ?”, code];
    It returns ever DB Error: 1 “no such table: book”

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>