Add an SQLite database to an iPhone app

First of all you need to create your database.
From the command line create your db file.

sqlite3 mydb.db

Then create the tables within your database

CREATE TABLE tags (id int(5), name varchar(255), created_at datetime, updated_at datetime);

Repeat that for any tables that you want in your database.

Then you need to include the database file in your project. Add the existing database file to your project as you would any other existing file.

Next you will have to link in the framework to interact with the database. This can be found under you current iPhone SDK folder.

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/lib/libsqlite3.0.dylib

Finally you have to include the header file sqlite3.h from

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/include/sqlite3.h

It should now be possible to write code to access your sqlite database from within your iPhone application.

Leave a Comment