Permalink
Browse files

adding methods to allow easily reading 'BOOLEAN' columns created by R…

…ails3/ActiveRecord. They store them as t/f characters rather than 0/1 ints.
  • Loading branch information...
1 parent be9cbd1 commit 09e2378ac7470de9eb72afc9a37ed93cc7bf0436 @coryosborn coryosborn committed Dec 14, 2011
Showing with 12 additions and 0 deletions.
  1. +4 −0 src/FMResultSet.h
  2. +8 −0 src/FMResultSet.m
View
@@ -55,6 +55,10 @@
- (BOOL)boolForColumn:(NSString*)columnName;
- (BOOL)boolForColumnIndex:(int)columnIdx;
+// Added by Cory Osborn because the Rails SQLite adapter stores bools as t/f characters rather than 0/1
+- (BOOL)railsBoolForColumn:(NSString*)columnName;
+- (BOOL)railsBoolForColumnIndex:(int)columnIdx;
+
- (double)doubleForColumn:(NSString*)columnName;
- (double)doubleForColumnIndex:(int)columnIdx;
View
@@ -234,6 +234,14 @@ - (BOOL)boolForColumnIndex:(int)columnIdx {
return ([self intForColumnIndex:columnIdx] != 0);
}
+- (BOOL)railsBoolForColumn:(NSString*)columnName {
+ return [self railsBoolForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (BOOL)railsBoolForColumnIndex:(int)columnIdx {
+ return ([@"t" isEqualToString:[self stringForColumnIndex:columnIdx]]);
+}
+
- (double)doubleForColumn:(NSString*)columnName {
return [self doubleForColumnIndex:[self columnIndexForName:columnName]];
}

0 comments on commit 09e2378

Please sign in to comment.