-
Notifications
You must be signed in to change notification settings - Fork 2
/
SQLQueryOperation.swift
42 lines (36 loc) · 1.45 KB
/
SQLQueryOperation.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Created by Jeffrey Roberts on 7/18/15.
// Copyright (c) 2015 NimbleNoggin.io. All rights reserved.
//
import Foundation
import SwiftyBeaver
@objc
public class SQLQueryOperation : SQLiteOperation {
private let logger = SwiftyBeaver.self
public var groupBy:String?
public var having:String?
public var projection:[String]?
public var sort:String?
public override init(database: SQLiteDatabase, statementBuilder: SQLStatementBuilder) {
super.init(database: database, statementBuilder: statementBuilder)
}
public func executeQuery() throws -> Cursor {
guard let table = self.tableName else {
throw SQLError.MissingTableName
}
let statement = self.statementBuilder.buildSelectStatement(table,
projection: self.projection,
selection: self.selection,
groupBy: self.groupBy,
having: self.having,
sort: self.sort)
let hasNamedParameters = self.namedSelectionArgs != nil
if hasNamedParameters {
logger.debug("Executing \(statement) with named parameters: \(self.namedSelectionArgs)")
return try self.database.executeQuery(statement, parameters:self.namedSelectionArgs)
} else {
logger.debug("Executing \(statement) with parameters: \(self.selectionArgs)")
return try self.database.executeQuery(statement, parameters:self.selectionArgs)
}
}
}