FMResultSet

@interface FMResultSet : NSObject

Represents the results of executing a query on an FMDatabase .

See also

  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, retain, nullable) FMDatabase *parentDB

    Swift

    var parentDB: FMDatabase? { get set }

Properties

  • Executed query

    Declaration

    Objective-C

    @property (retain, nullable) NSString *query;

    Swift

    var query: String? { get set }
  • NSMutableDictionary mapping column names to numeric index

    Declaration

    Objective-C

    @property (readonly) NSMutableDictionary *_Nonnull columnNameToIndexMap;

    Swift

    var columnNameToIndexMap: NSMutableDictionary { get }
  • FMStatement used by result set.

    Declaration

    Objective-C

    @property (retain, nullable) FMStatement *statement;

    Swift

    var statement: FMStatement? { get set }

Creating and closing a result set

  • Close result set

    Declaration

    Objective-C

    - (void)close;

    Swift

    func close()

Iterating through the result set

  • Retrieve next row for result set.

    You must always invoke next or nextWithError before attempting to access the values returned in a query, even if you’re only expecting one.

    See

    hasAnotherRow

    Declaration

    Objective-C

    - (BOOL)next;

    Swift

    func next() -> Bool

    Return Value

    YES if row successfully retrieved; NO if end of result set reached

  • Retrieve next row for result set.

    You must always invoke next or nextWithError before attempting to access the values returned in a query, even if you’re only expecting one.

    See

    hasAnotherRow

    Declaration

    Objective-C

    - (BOOL)nextWithError:(NSError *_Nullable *_Nullable)outErr;

    Swift

    func nextWithError() throws

    Parameters

    outErr

    A ‘NSError’ object to receive any error object (if any).

    Return Value

    ‘YES’ if row successfully retrieved; ‘NO’ if end of result set reached

  • Perform SQL statement.

    See

    hasAnotherRow

    Declaration

    Objective-C

    - (BOOL)step;

    Swift

    func step() -> Bool

    Return Value

    ‘YES’ if successful; ‘NO’ if not.

  • Perform SQL statement.

    See

    hasAnotherRow

    Declaration

    Objective-C

    - (BOOL)stepWithError:(NSError *_Nullable *_Nullable)outErr;

    Swift

    func stepWithError() throws

    Parameters

    outErr

    A ‘NSError’ object to receive any error object (if any).

    Return Value

    ‘YES’ if successful; ‘NO’ if not.

  • Did the last call to <next> succeed in retrieving another row?

    See

    next

    Warning

    The hasAnotherRow method must follow a call to <next>. If the previous database interaction was something other than a call to next, then this method may return NO, whether there is another row of data or not.

    Declaration

    Objective-C

    - (BOOL)hasAnotherRow;

    Swift

    func hasAnotherRow() -> Bool

    Return Value

    ‘YES’ if there is another row; ‘NO’ if not.

Retrieving information from result set

  • How many columns in result set

    Declaration

    Objective-C

    @property (nonatomic, readonly) int columnCount;

    Swift

    var columnCount: Int32 { get }

    Return Value

    Integer value of the number of columns.

  • Column index for column name

    Declaration

    Objective-C

    - (int)columnIndexForName:(nonnull NSString *)columnName;

    Swift

    func columnIndex(forName columnName: String) -> Int32

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    Zero-based index for column.

  • Column name for column index

    Declaration

    Objective-C

    - (NSString *_Nullable)columnNameForIndex:(int)columnIdx;

    Swift

    func columnName(for columnIdx: Int32) -> String?

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    columnName NSString value of the name of the column.

  • Result set integer value for column.

    Declaration

    Objective-C

    - (int)intForColumn:(nonnull NSString *)columnName;

    Swift

    func int(forColumn columnName: String) -> Int32

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    int value of the result set’s column.

  • Result set integer value for column.

    Declaration

    Objective-C

    - (int)intForColumnIndex:(int)columnIdx;

    Swift

    func int(forColumnIndex columnIdx: Int32) -> Int32

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    int value of the result set’s column.

  • Result set long value for column.

    Declaration

    Objective-C

    - (long)longForColumn:(nonnull NSString *)columnName;

    Swift

    func long(forColumn columnName: String) -> Int

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    long value of the result set’s column.

  • Result set long value for column.

    Declaration

    Objective-C

    - (long)longForColumnIndex:(int)columnIdx;

    Swift

    func long(forColumnIndex columnIdx: Int32) -> Int

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    long value of the result set’s column.

  • Result set long long int value for column.

    Declaration

    Objective-C

    - (long long)longLongIntForColumn:(nonnull NSString *)columnName;

    Swift

    func longLongInt(forColumn columnName: String) -> Int64

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    long long int value of the result set’s column.

  • Result set long long int value for column.

    Declaration

    Objective-C

    - (long long)longLongIntForColumnIndex:(int)columnIdx;

    Swift

    func longLongInt(forColumnIndex columnIdx: Int32) -> Int64

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    long long int value of the result set’s column.

  • Result set unsigned long long int value for column.

    Declaration

    Objective-C

    - (unsigned long long)unsignedLongLongIntForColumn:
        (nonnull NSString *)columnName;

    Swift

    func unsignedLongLongInt(forColumn columnName: String) -> UInt64

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    unsigned long long int value of the result set’s column.

  • Result set unsigned long long int value for column.

    Declaration

    Objective-C

    - (unsigned long long)unsignedLongLongIntForColumnIndex:(int)columnIdx;

    Swift

    func unsignedLongLongInt(forColumnIndex columnIdx: Int32) -> UInt64

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    unsigned long long int value of the result set’s column.

  • Result set BOOL value for column.

    Declaration

    Objective-C

    - (BOOL)boolForColumn:(nonnull NSString *)columnName;

    Swift

    func bool(forColumn columnName: String) -> Bool

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    BOOL value of the result set’s column.

  • Result set BOOL value for column.

    Declaration

    Objective-C

    - (BOOL)boolForColumnIndex:(int)columnIdx;

    Swift

    func bool(forColumnIndex columnIdx: Int32) -> Bool

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    BOOL value of the result set’s column.

  • Result set double value for column.

    Declaration

    Objective-C

    - (double)doubleForColumn:(nonnull NSString *)columnName;

    Swift

    func double(forColumn columnName: String) -> Double

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    double value of the result set’s column.

  • Result set double value for column.

    Declaration

    Objective-C

    - (double)doubleForColumnIndex:(int)columnIdx;

    Swift

    func double(forColumnIndex columnIdx: Int32) -> Double

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    double value of the result set’s column.

  • Result set NSString value for column.

    Declaration

    Objective-C

    - (NSString *_Nullable)stringForColumn:(nonnull NSString *)columnName;

    Swift

    func string(forColumn columnName: String) -> String?

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    String value of the result set’s column.

  • Result set NSString value for column.

    Declaration

    Objective-C

    - (NSString *_Nullable)stringForColumnIndex:(int)columnIdx;

    Swift

    func string(forColumnIndex columnIdx: Int32) -> String?

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    String value of the result set’s column.

  • Result set NSDate value for column.

    Declaration

    Objective-C

    - (NSDate *_Nullable)dateForColumn:(nonnull NSString *)columnName;

    Swift

    func date(forColumn columnName: String) -> Date?

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    Date value of the result set’s column.

  • Result set NSDate value for column.

    Declaration

    Objective-C

    - (NSDate *_Nullable)dateForColumnIndex:(int)columnIdx;

    Swift

    func date(forColumnIndex columnIdx: Int32) -> Date?

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    Date value of the result set’s column.

  • Result set NSData value for column.

    This is useful when storing binary data in table (such as image or the like).

    Declaration

    Objective-C

    - (NSData *_Nullable)dataForColumn:(nonnull NSString *)columnName;

    Swift

    func data(forColumn columnName: String) -> Data?

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    Data value of the result set’s column.

  • Result set NSData value for column.

    Declaration

    Objective-C

    - (NSData *_Nullable)dataForColumnIndex:(int)columnIdx;

    Swift

    func data(forColumnIndex columnIdx: Int32) -> Data?

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    Data value of the result set’s column.

  • Result set (const unsigned char *) value for column.

    Declaration

    Objective-C

    - (const unsigned char *_Nullable)UTF8StringForColumn:
        (nonnull NSString *)columnName;

    Swift

    func utf8String(forColumn columnName: String) -> UnsafePointer<UInt8>?

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    (const unsigned char *) value of the result set’s column.

  • Deprecated

    Use UTF8StringForColumn instead

    Undocumented

    Declaration

    Objective-C

    - (const unsigned char * _Nullable)UTF8StringForColumnName:(NSString*)columnName __deprecated_msg("Use UTF8StringForColumn instead");

    Swift

    func utf8String(forColumnName columnName: String) -> UnsafePointer<UInt8>?
  • Result set (const unsigned char *) value for column.

    Declaration

    Objective-C

    - (const unsigned char *_Nullable)UTF8StringForColumnIndex:(int)columnIdx;

    Swift

    func utf8String(forColumnIndex columnIdx: Int32) -> UnsafePointer<UInt8>?

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    (const unsigned char *) value of the result set’s column.

  • Result set object for column.

    See

    objectForKeyedSubscript:

    Declaration

    Objective-C

    - (id _Nullable)objectForColumn:(nonnull NSString *)columnName;

    Swift

    func object(forColumn columnName: String) -> Any?

    Parameters

    columnName

    Name of the column.

    Return Value

    Either NSNumber , NSString , NSData , or NSNull . If the column was NULL , this returns [NSNull null] object.

  • Deprecated

    Use objectForColumn instead

    Undocumented

    Declaration

    Objective-C

    - (id _Nullable)objectForColumnName:(NSString*)columnName __deprecated_msg("Use objectForColumn instead");

    Swift

    func object(forColumnName columnName: String) -> Any?
  • Result set object for column.

    See

    objectAtIndexedSubscript:

    Declaration

    Objective-C

    - (id _Nullable)objectForColumnIndex:(int)columnIdx;

    Swift

    func object(forColumnIndex columnIdx: Int32) -> Any?

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    Either NSNumber , NSString , NSData , or NSNull . If the column was NULL , this returns [NSNull null] object.

  • Result set object for column.

    This method allows the use of the “boxed” syntax supported in Modern Objective-C. For example, by defining this method, the following syntax is now supported:

    id result = rs[@"employee_name"];
    

    This simplified syntax is equivalent to calling:

    id result = [rs objectForKeyedSubscript:@"employee_name"];
    

    which is, it turns out, equivalent to calling:

    id result = [rs objectForColumnName:@"employee_name"];
    

    Declaration

    Objective-C

    - (id _Nullable)objectForKeyedSubscript:(nonnull NSString *)columnName;

    Swift

    subscript(columnName: String) -> Any? { get }

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    Either NSNumber , NSString , NSData , or NSNull . If the column was NULL , this returns [NSNull null] object.

  • Result set object for column.

    This method allows the use of the “boxed” syntax supported in Modern Objective-C. For example, by defining this method, the following syntax is now supported:

    id result = rs[0];
    

    This simplified syntax is equivalent to calling:

    id result = [rs objectForKeyedSubscript:0];
    

    which is, it turns out, equivalent to calling:

    id result = [rs objectForColumnName:0];
    

    Declaration

    Objective-C

    - (id _Nullable)objectAtIndexedSubscript:(int)columnIdx;

    Swift

    subscript(columnIdx: Int32) -> Any? { get }

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    Either NSNumber , NSString , NSData , or NSNull . If the column was NULL , this returns [NSNull null] object.

  • Result set NSData value for column.

    Warning

    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.

    Declaration

    Objective-C

    - (NSData *_Nullable)dataNoCopyForColumn:(nonnull NSString *)columnName;

    Swift

    func dataNoCopy(forColumn columnName: String) -> Data?

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    Data value of the result set’s column.

  • Result set NSData value for column.

    Warning

    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.

    Declaration

    Objective-C

    - (NSData *_Nullable)dataNoCopyForColumnIndex:(int)columnIdx;

    Swift

    func dataNoCopy(forColumnIndex columnIdx: Int32) -> Data?

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    Data value of the result set’s column.

  • Is the column NULL ?

    Declaration

    Objective-C

    - (BOOL)columnIndexIsNull:(int)columnIdx;

    Swift

    func columnIndexIsNull(_ columnIdx: Int32) -> Bool

    Parameters

    columnIdx

    Zero-based index for column.

    Return Value

    YES if column is NULL ; NO if not NULL .

  • Is the column NULL ?

    Declaration

    Objective-C

    - (BOOL)columnIsNull:(nonnull NSString *)columnName;

    Swift

    func columnIsNull(_ columnName: String) -> Bool

    Parameters

    columnName

    NSString value of the name of the column.

    Return Value

    YES if column is NULL ; NO if not NULL .

  • Returns a dictionary of the row results mapped to case sensitive keys of the column names.

    Warning

    The keys to the dictionary are case sensitive of the column names.

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) NSDictionary *resultDictionary;

    Swift

    var resultDictionary: [AnyHashable : Any]? { get }
  • Deprecated

    Use resultDictionary instead

    Returns a dictionary of the row results

    See

    resultDictionary

    Warning

    Deprecated: Please use <resultDictionary> instead. Also, beware that <resultDictionary> is case sensitive!

    Declaration

    Objective-C

    - (NSDictionary *_Nullable)resultDict;

    Swift

    func resultDict() -> [AnyHashable : Any]?

Key value coding magic

  • Performs setValue to yield support for key value observing.

    Declaration

    Objective-C

    - (void)kvcMagic:(nonnull id)object;

    Swift

    func kvcMagic(_ object: Any)

    Parameters

    object

    The object for which the values will be set. This is the key-value-coding compliant object that you might, for example, observe.

Binding values

  • Bind array of values to prepared statement.

    Declaration

    Objective-C

    - (BOOL)bindWithArray:(nonnull NSArray *)array;

    Swift

    func bind(with array: [Any]) -> Bool

    Parameters

    array

    Array of values to bind to SQL statement.

  • Bind dictionary of values to prepared statement.

    Declaration

    Objective-C

    - (BOOL)bindWithDictionary:(nonnull NSDictionary *)dictionary;

    Swift

    func bind(with dictionary: [AnyHashable : Any]) -> Bool

    Parameters

    dictionary

    Dictionary of values to bind to SQL statement.