Best Cocoa/Objective-C Wrapper Library for SQLite on iPhone

IphoneObjective CCocoa TouchSqlite

Iphone Problem Overview


I'm developing for the iPhone and am looking for a good Cocoa/Objective-C library for working with SQLite. I don't want to use the standard procedural SQLite C API. I see options at sqlite.org under the Objective-C section, but am not sure which is the best in terms of library API design, stability, and functionality. I'd like to use something that's actively being developed and hopefully will be around for a while. Anyone have suggestions based on experience using one?

Thanks

Iphone Solutions


Solution 1 - Iphone

I personally use FMDB, and the last update to it was yesterday.

Solution 2 - Iphone

I'm also a fan of FMDatabase, although I've had to customize my own version of it. My apps use a layer around it I wrote called ArchDBObject that transparently converts objects to and from a database representation; I'm thinking about releasing it in some form, but I haven't really decided how yet.

In any case, FMDatabase can be had at <https://github.com/ccgus/fmdb>;.

Solution 3 - Iphone

The simplest I've found is this one https://github.com/misato/SQLiteManager4iOS

SQLiteManager by Ester Sanchez.

Using it is basically like this:

NSArray *results = [dbManager getRowsForQuery:@"SELECT * FROM table WHERE id = 1"];

results is an array containing dictionaries. Each dictionary is a single returned row where the keys are the names of each column in the table.

After that you can do things like this:

NSDictionary *aPerson = [results objectAtIndex:0];
NSString *firstName = aPerson[@"firstName"];
NSString *email = aPerson[@"email"];

Solution 4 - Iphone

FMDB is nice because it's the lightest way to not have to deal with the C calls and type conversions, while still giving you full access to the SQL.

The thing I generally do not like about object-relational wrappers is that you get too distant from the SQL being generated and that's when performance can start to suffer.

Solution 5 - Iphone

I spent the last few hours looking at the options -- haven't been in production with any of these yet, so YMMV.

The lightest weight wrapper I found was here:

http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/

I don't know if it has an official name. It's just 1 class, and it abstracts the nastiness of the SQLite api, while leaving the value of working directly with SQL. The learning curve is 5 minutes, assuming you know SQL already. Since it's so small, I can imagine it would be easy to fix anything that might go wrong with it.

Solution 6 - Iphone

If you want, you could also have a look at the following repository that provides a set of classes that can be used to create SQL statements and provides a simple way to handle a SQLite database connection. It is located at https://github.com/ziminji/objective-c-sql-query-builder

Solution 7 - Iphone

I have a simple ORM on top of FDBM here http://code.google.com/p/chibiorm/.

With it, you can use raw SQL when you wish, return any SQL as a dict list, or use the nice OO style.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpfeilbrView Question on Stackoverflow
Solution 1 - IphoneccgusView Answer on Stackoverflow
Solution 2 - IphoneBecca Royal-GordonView Answer on Stackoverflow
Solution 3 - IphoneAccatyycView Answer on Stackoverflow
Solution 4 - IphoneKendall Helmstetter GelnerView Answer on Stackoverflow
Solution 5 - IphoneVineel ShahView Answer on Stackoverflow
Solution 6 - IphoneZiminjiView Answer on Stackoverflow
Solution 7 - IphonemamcxView Answer on Stackoverflow