SecureDatabaseResultSet

public class SecureDatabaseResultSet

Executing queries returns a SecureDatabaseResultSetProtocol compliant object if successful, and throws an error upon failure.

You typically use a while() loop to iterate through the results of your query. You also need to “step” from one record to the next. The easiest way to do this is by using this code:

do {
   let rs: SecureDatabaseResultSetProtocol = try db.executeQuery("SELECT * FROM myTable")
   defer {
       rs.close()
   }

   while try rs.next() {
       //retrieve values for each record
   }
} catch let error {
   logger.error("An error occurred while executing a query on the database.", error: error)
}
  • Executed query

    Declaration

    Swift

    public var query: String { get }
  • Closes the result set.

    Declaration

    Swift

    public func close()
  • Retrieve next row for result set.

    Note

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

    Throws

    SecureStorageError.BackingStoreError if an error occured while retrieving rows. code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).

    Sample

    do {
       let rs: SecureDatabaseResultSetProtocol = try db.executeQuery("SELECT * FROM myTable")
       defer {
           rs.close()
       }
       while try rs.next() {
           //retrieve values for each record
       }
    } catch let error {
       logger.error("An error occurred while executing a query.", error: error)
    }
    

    Declaration

    Swift

    public func next() throws -> Bool

    Return Value

    true if row was successfully retrieved, false if end of result set reached.

  • Whether the last call to next() succeeded in retrieving another record, false if not.

    Warning

    The hasNext property must follow a call to next(). If the previous database interaction was something other than a call to next(), then this method may return false, whether there is another row of data or not.

    Declaration

    Swift

    public var hasNext: Bool { get }

    Return Value

    true if there are more rows in the result set, false if not.

  • Integer value of the number of columns in the result set.

    Declaration

    Swift

    public var columnCount: Int { get }
  • Dictionary mapping column names to numeric index.

    Declaration

    Swift

    public var columnNameToIndexMap: [String : Int] { get }
  • Column index for column name

    Declaration

    Swift

    public func columnIndex(forColumnName columnName: String) -> Int

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    Zero-based index for column. -1 if the column name does not exist.

  • Column name for column index

    Declaration

    Swift

    public func columnName(forColumnIndex columnIndex: Int) -> String?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    columnName String value of the name of the column. nil if the column index does not exist.

  • Is the column NULL?

    Declaration

    Swift

    public func isColumnValueNull(forColumnIndex columnIndex: Int) -> Bool

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    true if column is NULL or if the index does not exist, false if not NULL.

  • Is the column NULL?

    Declaration

    Swift

    public func isColumnValueNull(forColumnName columnName: String) -> Bool

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    true if column is NULL, false if not NULL.

  • row

    Returns a dictionary of the row results mapped to case sensitive keys of the column names. Columns that have a NULL value are represented by nil.

    Note

    This returns an empty dictionary prior to the first call to next() on this result set.

    Declaration

    Swift

    public var row: [String : NSCoding?] { get }
  • Result set integer value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func int(forColumnName columnName: String) -> Int?

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    Int value of the result set’s column. nil if the column is NULL.

  • Result set integer value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func int(forColumnIndex columnIndex: Int) -> Int?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    Int value of the result set’s column. nil if the column is NULL.

  • Result set 64 bit integer value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func int64(forColumnName columnName: String) -> Int64?

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    Int64 value of the result set’s column. nil if the column is NULL.

  • Result set 64 bit integer value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func int64(forColumnIndex columnIndex: Int) -> Int64?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    Int64 value of the result set’s column. nil if the column is NULL.

  • Result set 64 bit unsigned integer value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func uint64(forColumnName columnName: String) -> UInt64?

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    UInt64 value of the result set’s column. nil if the column is NULL.

  • Result set 64 bit unsigned integer value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func uint64(forColumnIndex columnIndex: Int) -> UInt64?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    UInt64 value of the result set’s column. nil if the column is NULL.

  • Result set double value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func double(forColumnName columnName: String) -> Double?

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    Double value of the result set’s column. nil if the column is NULL.

  • Result set double value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func double(forColumnIndex columnIndex: Int) -> Double?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    Double value of the result set’s column. nil if the column is NULL.

  • Result set boolean value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func bool(forColumnName columnName: String) -> Bool?

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    Bool value of the result set’s column. nil if the column is NULL.

  • Result set bool value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func bool(forColumnIndex columnIndex: Int) -> Bool?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    Bool value of the result set’s column. nil if the column is NULL.

  • Result set string value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func string(forColumnName columnName: String) -> String?

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    String value of the result set’s column. nil if the column is NULL.

  • Result set string value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func string(forColumnIndex columnIndex: Int) -> String?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    String value of the result set’s column. nil if the column is NULL.

  • Result set date value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func date(forColumnName columnName: String) -> Date?

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    Date value of the result set’s column. nil if the column is NULL.

  • Result set date value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func date(forColumnIndex columnIndex: Int) -> Date?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    Date value of the result set’s column. nil if the column is NULL.

  • Result set data value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func data(forColumnName columnName: String) -> Data?

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    Data value of the result set’s column. nil if the column is NULL.

  • Result set data value for column.

    Note

    Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except NULL values which are returned as nil.

    Declaration

    Swift

    public func data(forColumnIndex columnIndex: Int) -> Data?

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    Data value of the result set’s column. nil if the column is NULL.

  • Result set object value for column.

    Declaration

    Swift

    public func object<T>(forColumnName columnName: String) throws -> T? where T : SQLiteDatatypeBridgeable

    Parameters

    columnName

    String value of the name of the column.

    Return Value

    SQLiteDatatypeBridgeable compliant value of the result set’s column. If the column was NULL, this returns nil.

  • Result set object for column.

    Declaration

    Swift

    public func object<T>(forColumnIndex columnIndex: Int) throws -> T? where T : SQLiteDatatypeBridgeable

    Parameters

    columnIndex

    Zero-based index for column.

    Return Value

    SQLiteDatatypeBridgeable compliant value of the result set’s column. If the column was NULL, this returns nil.