FMPQuery

Description

The FMPQuery class is used to describe data request.

class FMPQuery

Properties

Property Description

database

Database.
var database: FMPDatabase? { get }
query SQL query to database.
var query: String { get }
isResumable Use download resumption on request to server.
var isResumable: Bool { get set }

pathForResume

The path to folder in the application directory, which will store download resumption files.
var pathForResume: String { get set }

Methods

Method Description

download(transactions:completion:)

Load table data to database.
func download(transactions: [FMPTransaction] = [], completion: @escaping FMPRequestResponsesHandler)

Parameters:

  • transactions. List of transactions used in requests.

  • completion. Closing expression containing method execution result.

get() Execute SQL query to database. It returns the NSDictionary dictionary with database records.
func get() -> [NSDictionary]?

Examples

Enable/disable download resumption:

// Build an instance of the FMPQuery class. For details see examples for FMPQuery.Builder.
let query: FMPQuery = fmp.query.build()
  
// Set path to folder in the local directory for download resumption files
query.pathForResume = "path"
//Enable download resumption
query.isResumable = true
  
// Disable download resumption
query.isResumable = false

Load table data to database:

// Build an instance of the FMPQuery class. For details see examples for FMPQuery.Builder.
let query: FMPQuery = fmp.query.build()
  
// Load data of resources specified in query
query.download() { (responses) in
    if !responses.map({ $0.success }).contains(false) {
        // All data of resources specified in query is successfully loaded to database
    } else {
        // Display error codes and descriptions
        responses.compactMap({ $0.error }).forEach {
            print($0.code, $0.description)
        }
    }
}
  
// Load data with transaction specification
let transaction: FMPTransaction
query.download(transactions: [transaction]) { (responses) in
    if !responses.map({ $0.success }).contains(false) {
        // All data of resources specified in query is successfully loaded to database
    } else {
        // Display error codes and descriptions
        responses.compactMap({ $0.error }).forEach {
            print($0.code, $0.description)
        }
    }
}

Execute SQL query:

// Build an instance of the FMPQuery class. For details see examples for FMPQuery.Builder.
let query: FMPQuery = fmp.query.build()
  
// Get result of SQL query to database
let sqlResult: [NSDictionary]? = query.get()

See also:

FMPWrapper Framework | Classes