Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
253 lines (171 sloc) 12.1 KB
Zip, nada, zilch. Got any ideas?
If you would like to contribute some code- awesome! I just ask that you make it conform to the coding conventions already set in here, and to add a couple of tests for your new code to fmdb.m. And of course, the code should be of general use to more than just a couple of folks. Send your patches to
Added an "extra" folder which contains additional things which might be useful for programmers, but which I don't think should be part of the standard classes. At this time- there's only a single category in there which will load and save an on disk database to an in memory database. Thanks to Peter Carr who provided these additions!
Lazy init of columnNameToIndexMap in FMResultSet, and you are now able to use it before asking for any rows first. Thanks to Daniel Dickison for the patch!
Now resetting cached statements before executing a query on them (as well as resetting them at the close of a result set). There was an issue where if you used the same query twice without closing the result set of the first one, you would get results back from the previous query, or maybe an exhausted result set. Thanks to note173 on github for pointing out the problem.
Changed up how the binding count is calculated when passing a dictionary for named parameter support. Thanks to Samuel Chen for pointing out the problem.
Added keyed and indexed subscript support to FMResultSet- so you can do use the fancy boxed syntax against it (rs[@"foo"] & rs[0]). Thanks to Robert Ryan for the patches!
Fixed some problems when compiling with ARC against the 10.8 SDK (patch from Geoffrey Foster!).
Changed up the behavior of binding empty NSData objects ([NSData data]). It will now insert an empty value, rather than a null value- which is consistent with [NSMutableData data] and empty strings (see for a discussion on this). Thanks to Jens Alfke for pointing this out!
Deprecated columnExists:columnName: in favor of columnExists:inTableWithName:
Remembered to update the changes notes. I've been forgetting to do this recently.
Deprecated resultDict and replaced it with resultDictionary on FMResultSet. Slight change in behavior as well- resultDictionary will return case sensitive keys.
Fixed a problem with getTableSchema: not working with table names that start with a number.
Changed up FMDatabasePool so that you can't "pop" it from a pool anymore. I just consider this too risky- use the block based functions instead.
Also provided a good reason in main.m for why you should use FMDatabaseQueue instead. Search for "ONLY_USE_THE_POOL_IF_YOU_ARE_DOING_READS".
I consider this branch 2.0 at this point- I'll let it bake for a couple of days, then push it to the main repo.
Added a new method to FMDatabase to make custom functions out of a block:
- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(sqlite3_context *context, int argc, sqlite3_value **argv))block
Check out the function "testSQLiteFunction" in main.m for an example.
Added methods for named parameters, using keys from an NSDictionary (Thanks to Drarok Ithaqua for the patches!)
Changed FMDatabase's "- (BOOL)update:(NSString*)sql error:(NSError**)outErr bind:(id)bindArgs, ... " to "- (BOOL)update:(NSString*)sql withErrorAndBindings:(NSError**)outErr, ..." as the previous method didn't actually work as advertised in the way it was written. Thanks to @jaekwon for pointing this out.
Changed some methods to properties. Hello 2011.
Added a warning when you try and use a database that wasn't opened. Hacked together based on patches from Drarok Ithaqua.
Fixed a problem under GC where leaked statments were keeping a database from closing. Patch from Chris Dolan.
Added + (BOOL)isThreadSafe to FMDatabase. It'll let you know if the version of SQLite you are running is compiled with it's thread safe options. THIS DOES NOT MEAN FMDATABASE IS THREAD SAFE. I haven't done a review of it for this case, so I'm just saying.
Added a method to validate a SQL statement.
Added a method to retrieve the number of columns in a result set.
Added two methods to execute queries and updates with NSString-style format specifiers.
Thanks to Dave DeLong for the patches!
Added compatibility with garbage collection.
When an FMDatabase is closed, all open FMResultSets pertaining to that database are also closed.
- (id) objectForColumnIndex:(int)columnIdx;
- (id) objectForColumnName:(NSString*)columnName;
Changes by Dave DeLong.
The -(int)changes; method on FMDatabase is a bit more robust now, and there's a new static library target. And if a database path is nil, we now open up a :memory: database. Patch from Pascal Pfiffner!
Happy New Year!
Now checking for SQLITE_LOCKED along with SQLITE_BUSY when trying to perform a query. Patch from Jeff Meininger!
Fixed some compiler warnings (thanks to Casey Fleser!)
Added and updated some new methods to take NSError** params.
Only execute the assertion macros if NS_BLOCK_ASSERTIONS is not set. Patch from David E. Wheeler!
The signature for FMDatabase's executeQuery* methods now return FMResultSet instead if id. Patch from Augie Fackler!
Added resultDict to FMResultSet, which returns a dictionary of column values. Thanks to Pascal Pfiffner for the patch!
Cleaned up some formatting.
Changed up FMDatabase's close method to return a boolean, and fixed a compiler warning when compiling in 64bit land. Thanks to Jens Alfke for the patches!
dateForQuery which works like the other fooForQuery methods. Thanks to Matt Stevens for the patch!
FMDB now checks for longLongValue in NSNumbers passed for selects or updates, and binds that value to an sqlite int64
Thanks for the patch from Brian Stern!
renamed getDataBaseSchema: to getSchema. It didn't actually use the param. whooops.
- (id)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments;
- (BOOL) executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments;
These two methods now point to:
- (id) executeQuery:(NSString*)sql withArgumentsInArray:(NSArray*)arrayArgs orVAList:(va_list)args;
- (BOOL) executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray*)arrayArgs orVAList:(va_list)args;
because the vargs were causing headaches in 64bit land, and on the iphone, and it's fragile n' stuff.
- (FMResultSet*) getTableSchema:(NSString*)tableName;
- (BOOL) columnExists:(NSString*)tableName columnName:(NSString*)columnName;
to FMDatabaseAdditions. Patch from OZLB
Disabled the following FMDatabaseAdditions when compiled as 64 bit:
- (id)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments;
- (BOOL) executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments;
Since they crash, I just print out a warning now. Got a patch to fix it? Send it to
- (BOOL) tableExists:(NSString*)tableName;
- (FMResultSet*) getDataBaseSchema:(NSString*)tableName;
to FMDatabaseAdditions. Patch from OZLB
- (BOOL) openWithFlags:(int)flags;
To FMDatabase, which allows you to open up the database with certain flags for sqlite 3.5+
Thanks to Dan Wright for the addition.
- (const unsigned char *) UTF8StringForColumnIndex:(int)columnIdx;
- (const unsigned char *) UTF8StringForColumnName:(NSString*)columnName;
to FMResultSet, patch from Nathan Stitt.
- (id)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments;
- (BOOL) executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments;
thanks to code from Phong Long.
Fix to FMResultSet's - (BOOL) hadError, as it was returning true for SQLITE_ROW & SQLITE_DONE, which aren't actually errors.
- (BOOL) hasAnotherRow; which lets you know if there is another row waiting in the result set.
Thanks to code from Dave DeLong.
replaced sqlite3_prepare calls with sqlite3_prepare_v2, since it's shiny and new.
Now making sure not to call any assembly if on the iphone (asm{ trap }).
Tested on 10.6. It works. Not that I didn't expect it not to- but you never know…
stringForColumnIndex, stringForColumn, dataForColumnIndex, dataForColumn, dataNoCopyForColumnIndex, and dataNoCopyForColumn now return nil if a null value was inserted into its table row. dateForColumnIndex already did this.
Also added the following methods to test if a column is null or not:
- (BOOL) columnIndexIsNull:(int)columnIdx
- (BOOL) columnIsNull:(NSString*)columnName
And finally, just general code cleanup + refactoring. Happy Cinco de Mayo!
added columnNameForIndex: to FMResultSet which returns the column name for the given index.
dateForColumnIndex: now returns null, if a null value was inserted into its table row. Patch by Robbie Hanson.
Now importing unistd.h, which the absence of was causing some problems on the iPhone. Reported by multiple people, but Hal Mueller actually got me to make the change.
Added (int)changes; to FMDatabase. From the sqlite docs: "This function returns the number of database rows that were changed (or inserted or deleted) by the most recent SQL statement."
Patch contributed by Tracy Harton
Added dataNoCopyForColumn: and dataNoCopyForColumnIndex: to FMResultSet.
If you are going to use this data after you iterate over the next row, or after you close the
result set, make sure to make a copy of the data first (or just use dataForColumn/dataForColumnIndex)
If you don't, you're going to be in a world of hurt when you try and use the data.
Some changes to make Clang's static analysis happy ( (patch provided by Matt Comi)
Added longLongIntForColumn: and longLongIntForColumnIndex: to FMResultSet. (patch provided by Will Cosgrove)
Added a check for NSNull in bindObject, which works just like passing nil does (patch provided by Robert Tolar Haining)
Removed the block keeping you from performing updates or selects while going through a result set.
Some bug fixes + warning fixes from Brian Stern (thanks again Brian!)
Fixed a crasher in FMResultSet's close where if the parent DB was already released, the result set would be talking to a bad address and fmdb went boom. (thanks to Brian Stern for the patch)
Thanks to Zach Wily for the return of FMDatabaseAdditions!
Removed all exceptions, now you should use [db hadError] to check for an error. I hate (ns)exceptions, I'm not sure why I put them in.
Moved to google code.
Various little cleanup thingies.
Thanks to Kris Markel for some extra trace outputs, and a fix where the database would be locked if it was too busy.
Thanks to Daniel Pasco and Bil Moorehead for catching a problem where the column names lookup table was created on every row iteration. Doh!
FMDatabase will now cache statements if you turn it on using shouldCacheStatements:YES. In theory, this should speed things up. Test it out, let me know if it makes things good for ya.
Note: This is pretty new code, so it hasn't gone through a lot of testing... you've been warned. (seems to work though!)
Fixed a problemo that kept it from compiling for the iPhone (Thanks to Sam Steele for the patch)
questions? comments? patches? Send them to
Something went wrong with that request. Please try again.