Wrapper classes for using SQLite on iPhone/Cocoa

Information on using SQLite for local storage on Cocoa isn’t all that easy to find. The best resource, as always, is Google, and you can find a few tutorials with step by step instructions and code samples on how to use it. Well, here’s another basic step by step set of instructions, but rather than including code samples, I have written a couple of wrapper classes for creating databases, making queries, and getting results.

Steps:

1: Include the SQLite framework in your project. It’s usually located somewhere like “/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.1.sdk/usr/lib/libsqlite3.0.dylib” (why is developer in there twice?)

2: Create a base sqlite database file, and modify SQLite.m so that the filename method refers to it. Place it in your main resource path. This will be copied out of your bundle into your application’s Documents directory. If you need help on creating one of these and managing it, there is a fantastic FireFox extension that does it for you!

3: Add the source files to your project.

Usage can be as simple as:


SQLiteResult *result = [SQLite query:@"SELECT * from test;"];
NSArray *row = [result.rows objectAtIndex:0];
NSString *firstValue = [row objectAtIndex:0];

NSArray columnNames contains NSStrings of all the names.
NSArray columnTypes contains NSStrings of all the types.
NSArray rows contains NSArrays, where each of these contains NSStrings of all the row values in that row.

Attached Files:

VN:F [1.9.22_1171]
Rating: 4.7/5 (10 votes cast)
VN:F [1.9.22_1171]
Rating: +5 (from 7 votes)
Wrapper classes for using SQLite on iPhone/Cocoa, 4.7 out of 5 based on 10 ratings

2 thoughts on “Wrapper classes for using SQLite on iPhone/Cocoa”

  1. OMG, you rock. You just saved me two weeks that I will probably waste on booze.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: +2 (from 2 votes)
  2. Great…..

    This is really a great help, you saved my at least 2-3 weeks.
    Thanks ….

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: +1 (from 1 vote)

Leave a Reply