SQLite is a small SQL database engine and it makes a good fit for iPhone apps. You can create a SQLite database and its tables using Base app: http://menial.co.uk/software/base/. Base is a lightweight Mac OS X application.
In order to use a SQLite database in an iPhone app you need to add it as a resource into the project: right click on Resources, then “Add > Existing Files …”. You will probably use the SQLite C API, so you need to add the corresponding Framework too: right-click Frameworks, then “Add > Existing Frameworks …” and select libsqlite3.0.dylib (/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/lib/libsqlite3.0.dylib). Don’t forget to include the necessary header file in every class that will use the SQLite C API: #include <sqlite3.h>.
When your iPhone application launches for the first time you’ll need to copy the SQLite database to the Documents directory (under your application’s path).
Before performing any query on the database you have to open it with sqlite3_open() (applicationDidFinishLaunching: method is a good place for this). The database should be closed with sqlite3_close(), when the application ends (applicationWillTerminate: method).
Functions that you will often use are: sqlite3_prepare(), sqlite3_step(), sqlite3_column_…(), sqlite3_finalize(). For a complete list of functions see http://www.sqlite.org/c3ref/funclist.html.


Good post Radu :)
Yes, good post Radu.
<>
Where will the db file be (initially) on the iPhone to be copied to the the Documants directory?
Andrew, you can access it like this:
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@”name.db”];
Dear all,
I am creating an iPhone application, I need to store the details in the iPhone. The best option which I thought was using SQLite.
I would like to know the steps for adding the sqlite database to the iphone, as its working fine on the simulator.
Similarly I would like to transfer the same data to remote server. Whats the best option for the second process.
Regards,
CP Kataray.
The database is included in the application. So if it work in the simulator, it will work on the device too.
If you haven’t implemented too much of your data logic yet, you might want to consider using CoreData. It provides an easy (visual) way to define your models and you can chose the backed storage method from SQLite, XML or binary files.
Regarding the remote server, if you want to push data from the device to the server, you will need a database on the server and some sort of webservice (you can create it using RubyOnRails or PHP) to write to the database.
Per your discussion above on using Menial and/or CoreData Managed Objects in setting up a SQLite database, do you suggest I use Menial to create the tables, relationship et. al, and to populate the database with the data I want to display, or should I use CoreData to create the schema and then somehow (perhaps you can explain) attach to the data that I put into the database using Menial?
Thoughts?
Great stuff, btw. And I’m VERY impressed with the development tools and skill set you folks have at SurgeWorks.
Kind regards,
John