QueryResult
open class QueryResult : ObjectBase
Holds a data query and its result value. Allows conversion of the result to optional/required/list values for basic, complex and entity types.
-
Construct a new query result.
Declaration
Swift
public init(query: DataQuery, result: DataValue?, status: Int = (200 as Int), error: DataServiceError? = nil)
Parameters
query
Data query.
result
Result value.
status
Result status (using HTTP status codes).
error
Error, if the query failed, otherwise
nil
. -
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func basicList() throws -> DataValueList
Return Value
The basic list for this result.
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func byteStream() throws -> ByteStream
Return Value
The byte stream for this result.
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func charStream() throws -> CharStream
Return Value
The character stream for this result.
-
Check if the
result
is valid with respect to thequery
. A result will be considered invalid if it is missing properties that were expected according to the use ofDataQuery.select
orDataQuery.expand
in thequery
.Throws
QueryResultException
if the result is definitely not valid.Declaration
Swift
open func check(fixOptions: Int = (0 as Int)) throws
Parameters
fixOptions
Flags for fixing invalid OData payload
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func complexList() throws -> ComplexValueList
Return Value
The complex list for this result.
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func count() throws -> Int64
Return Value
The “count” for this result.
-
Throws
QueryResultException
if the result does not have the expected type.See also
EntityValueList.deltaLink
.Declaration
Swift
open func deltaLink() throws -> String?
Return Value
The “delta link” for this result.
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func deltaStream() throws -> DeltaStream
Return Value
The delta stream for this result.
-
Throws
QueryResultException
if the result does not have the expected type.Example using proxy classes
open func entityListExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .orderBy(Customer.companyName) let customers = try service.fetchCustomers(matching: query) for customer in customers { self.showCustomer(customer) } }
Example using dynamic API
open func entityListExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let customerEntityType = customersEntitySet.entityType let customerIDProperty = customerEntityType.property(withName: "CustomerID") let companyNameProperty = customerEntityType.property(withName: "CompanyName") let contactNameProperty = customerEntityType.property(withName: "ContactName") let query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).orderBy(companyNameProperty) let customers = try service.executeQuery(query).entityList() for customer in customers { self.showCustomer(customer) } }
Declaration
Swift
open func entityList() throws -> EntityValueList
Return Value
The entity list for this result.
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func entityStream() throws -> EntityStream
Return Value
The entity stream for this result.
-
Error if
status
does not represent a successful response.Declaration
Swift
open var error: DataServiceError? { get }
-
Throws
QueryResultException
if the result does not have an inline “total count”.Declaration
Swift
open func inlineCount() throws -> Int64
Return Value
The inline “total count” for this result.
-
Throws
QueryResultException
if the result does not have the expected type.See also
EntityValueList.nextLink
.Declaration
Swift
open func nextLink() throws -> String?
Return Value
The “next link” for this result.
-
Throws
QueryResultException
if the result does not have the expected type.See also
EntityValueList.nextLink
.Declaration
Swift
open func nextQuery() throws -> DataQuery
Return Value
The “next query” for this result. The query will have a non-
nil
URL if this result includes a nextLink. -
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func optionalBasic() throws -> DataValue?
Return Value
The optional basic value of this result.
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func optionalComplex() throws -> ComplexValue?
Return Value
The optional complex value of this result.
-
Throws
QueryResultException
if the result does not have the expected type.Example using proxy classes
open func optionalEntityExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .orderBy(Customer.companyName).top(1) if let customer = try Single.optional(service.fetchCustomers(matching: query)) { self.showCustomer(customer) } }
Example using dynamic API
open func optionalEntityExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let customerEntityType = customersEntitySet.entityType let customerIDProperty = customerEntityType.property(withName: "CustomerID") let companyNameProperty = customerEntityType.property(withName: "CompanyName") let contactNameProperty = customerEntityType.property(withName: "ContactName") let query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).orderBy(companyNameProperty).top(1) if let customer = try service.executeQuery(query).optionalEntity() { self.showCustomer(customer) } }
Declaration
Swift
open func optionalEntity() throws -> EntityValue?
Return Value
The optional entity value of this result.
-
Data query.
Declaration
Swift
open var query: DataQuery { get }
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func requiredBasic() throws -> DataValue
Return Value
The required basic value of this result.
-
Throws
QueryResultException
if the result does not have the expected type.Declaration
Swift
open func requiredComplex() throws -> ComplexValue
Return Value
The required complex value of this result.
-
Throws
QueryResultException
if the result does not have the expected type.Example using proxy classes
open func requiredEntityExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .orderBy(Customer.companyName).top(1) let customer = try service.fetchCustomer(matching: query) self.showCustomer(customer) }
Example using dynamic API
open func requiredEntityExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let customerEntityType = customersEntitySet.entityType let customerIDProperty = customerEntityType.property(withName: "CustomerID") let companyNameProperty = customerEntityType.property(withName: "CompanyName") let contactNameProperty = customerEntityType.property(withName: "ContactName") let query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).orderBy(companyNameProperty).top(1) let customer = try service.executeQuery(query).requiredEntity() self.showCustomer(customer) }
Declaration
Swift
open func requiredEntity() throws -> EntityValue
Return Value
The required entity value of this result.
-
Result status (e.g. HTTP status code 200 = OK).
Declaration
Swift
open var status: Int { get }