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.BackingStoreErrorif an error occured while retrieving rows.codecorresponds 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 -> BoolReturn Value
trueif row was successfully retrieved,falseif end of result set reached. -
Whether the last call to
next()succeeded in retrieving another record,falseif not.Declaration
Swift
public var hasNext: Bool { get }Return Value
trueif there are more rows in the result set,falseif not.
-
Integer value of the number of columns in the result set.
Declaration
Swift
public var columnCount: Int { get } -
Dictionarymapping 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) -> IntParameters
columnNameStringvalue 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
columnIndexZero-based index for column.
Return Value
columnName
Stringvalue of the name of the column.nilif the column index does not exist. -
Is the column
NULL?Declaration
Swift
public func isColumnValueNull(forColumnIndex columnIndex: Int) -> BoolParameters
columnIndexZero-based index for column.
Return Value
trueif column isNULLor if the index does not exist,falseif notNULL. -
Is the column
NULL?Declaration
Swift
public func isColumnValueNull(forColumnName columnName: String) -> BoolParameters
columnNameStringvalue of the name of the column.Return Value
trueif column isNULL,falseif notNULL.
-
Returns a dictionary of the row results mapped to case sensitive keys of the column names. Columns that have a
NULLvalue are represented bynil.Note
This returns an empty dictionary prior to the first call tonext()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
NULLvalues which are returned asnil.Declaration
Swift
public func int(forColumnName columnName: String) -> Int?Parameters
columnNameStringvalue of the name of the column.Return Value
Intvalue of the result set’s column.nilif the column isNULL. -
Result set integer value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func int(forColumnIndex columnIndex: Int) -> Int?Parameters
columnIndexZero-based index for column.
Return Value
Intvalue of the result set’s column.nilif the column isNULL. -
Result set 64 bit integer value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func int64(forColumnName columnName: String) -> Int64?Parameters
columnNameStringvalue of the name of the column.Return Value
Int64value of the result set’s column.nilif the column isNULL. -
Result set 64 bit integer value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func int64(forColumnIndex columnIndex: Int) -> Int64?Parameters
columnIndexZero-based index for column.
Return Value
Int64value of the result set’s column.nilif the column isNULL. -
Result set 64 bit unsigned integer value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func uint64(forColumnName columnName: String) -> UInt64?Parameters
columnNameStringvalue of the name of the column.Return Value
UInt64value of the result set’s column.nilif the column isNULL. -
Result set 64 bit unsigned integer value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func uint64(forColumnIndex columnIndex: Int) -> UInt64?Parameters
columnIndexZero-based index for column.
Return Value
UInt64value of the result set’s column.nilif the column isNULL. -
Result set double value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func double(forColumnName columnName: String) -> Double?Parameters
columnNameStringvalue of the name of the column.Return Value
Doublevalue of the result set’s column.nilif the column isNULL. -
Result set double value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func double(forColumnIndex columnIndex: Int) -> Double?Parameters
columnIndexZero-based index for column.
Return Value
Doublevalue of the result set’s column.nilif the column isNULL.
-
Result set boolean value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func bool(forColumnName columnName: String) -> Bool?Parameters
columnNameStringvalue of the name of the column.Return Value
Boolvalue of the result set’s column.nilif the column isNULL. -
Result set bool value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func bool(forColumnIndex columnIndex: Int) -> Bool?Parameters
columnIndexZero-based index for column.
Return Value
Boolvalue of the result set’s column.nilif the column isNULL.
-
Result set string value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func string(forColumnName columnName: String) -> String?Parameters
columnNameStringvalue of the name of the column.Return Value
Stringvalue of the result set’s column.nilif the column isNULL. -
Result set string value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func string(forColumnIndex columnIndex: Int) -> String?Parameters
columnIndexZero-based index for column.
Return Value
Stringvalue of the result set’s column.nilif the column isNULL.
-
Result set date value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func date(forColumnName columnName: String) -> Date?Parameters
columnNameStringvalue of the name of the column.Return Value
Datevalue of the result set’s column.nilif the column isNULL. -
Result set date value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func date(forColumnIndex columnIndex: Int) -> Date?Parameters
columnIndexZero-based index for column.
Return Value
Datevalue of the result set’s column.nilif the column isNULL.
-
Result set data value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func data(forColumnName columnName: String) -> Data?Parameters
columnNameStringvalue of the name of the column.Return Value
Datavalue of the result set’s column.nilif the column isNULL. -
Result set data value for column.
Note
Values are casted according to https://www.sqlite.org/c3ref/column_blob.html, except
NULLvalues which are returned asnil.Declaration
Swift
public func data(forColumnIndex columnIndex: Int) -> Data?Parameters
columnIndexZero-based index for column.
Return Value
Datavalue of the result set’s column.nilif the column isNULL.
-
Result set object value for column.
Declaration
Swift
public func object<T>(forColumnName columnName: String) throws -> T? where T : SQLiteDatatypeBridgeableParameters
columnNameStringvalue of the name of the column.Return Value
SQLiteDatatypeBridgeablecompliant value of the result set’s column. If the column wasNULL, this returnsnil. -
Result set object for column.
Declaration
Swift
public func object<T>(forColumnIndex columnIndex: Int) throws -> T? where T : SQLiteDatatypeBridgeableParameters
columnIndexZero-based index for column.
Return Value
SQLiteDatatypeBridgeablecompliant value of the result set’s column. If the column wasNULL, this returnsnil.