Rename QueryArguments to StatementArguments

This commit is contained in:
Gwendal Roué committed 2015-08-20 08:14:17 +02:00
1 parent 26b2353782
commit 3d4c86d4ee
13 files changed
+99 -92

No files matched your search

@@ -51,7 +51,7 @@ class SelectStatementTests : GRDBTestCase {
}
}
func testArrayQueryArguments() {
func testArrayStatementArguments() {
assertNoError {
dbQueue.inDatabase { db in
let statement = db.selectStatement("SELECT COUNT(*) FROM persons WHERE age < ?")
@@ -62,7 +62,7 @@ class SelectStatementTests : GRDBTestCase {
}
}
func testQueryArgumentsSetterWithArray() {
func testStatementArgumentsSetterWithArray() {
assertNoError {
dbQueue.inDatabase { db in
let statement = db.selectStatement("SELECT COUNT(*) FROM persons WHERE age < ?")
@@ -76,26 +76,26 @@ class SelectStatementTests : GRDBTestCase {
}
}
func testDictionaryQueryArguments() {
func testDictionaryStatementArguments() {
assertNoError {
dbQueue.inDatabase { db in
let statement = db.selectStatement("SELECT COUNT(*) FROM persons WHERE age < :age")
// TODO: why is this explicit type declaration required?
let ageDicts: [[String: DatabaseValueConvertible?]] = [["age": 20], ["age": 30], ["age": 40], ["age": 50]]
let counts = ageDicts.map { statement.fetchOne(Int.self, arguments: QueryArguments($0))! }
let ageDicts = [["age": 20], ["age": 30], ["age": 40], ["age": 50]]
let counts = ageDicts.map { statement.fetchOne(Int.self, arguments: StatementArguments($0))! }
XCTAssertEqual(counts, [1,2,2,3])
}
}
}
func testQueryArgumentsSetterWithDictionary() {
func testStatementArgumentsSetterWithDictionary() {
assertNoError {
dbQueue.inDatabase { db in
let statement = db.selectStatement("SELECT COUNT(*) FROM persons WHERE age < :age")
// TODO: why is this explicit type declaration required?
let ageDicts: [[String: DatabaseValueConvertible?]] = [["age": 20], ["age": 30], ["age": 40], ["age": 50]]
let counts = ageDicts.map { (ageDict: [String: DatabaseValueConvertible?]) -> Int in
statement.arguments = QueryArguments(ageDict)
statement.arguments = StatementArguments(ageDict)
return statement.fetchOne(Int.self)!
}
XCTAssertEqual(counts, [1,2,2,3])
@@ -68,7 +68,7 @@ class UpdateStatementTests : GRDBTestCase {
}
}
func testArrayQueryArguments() {
func testArrayStatementArguments() {
assertNoError {
try dbQueue.inTransaction { db in
@@ -79,7 +79,7 @@ class UpdateStatementTests : GRDBTestCase {
["😀"],
]
for person in persons {
try statement.execute(arguments: QueryArguments(person))
try statement.execute(arguments: StatementArguments(person))
}
return .Commit
@@ -96,7 +96,7 @@ class UpdateStatementTests : GRDBTestCase {
}
}
func testQueryArgumentsSetterWithArray() {
func testStatementArgumentsSetterWithArray() {
assertNoError {
try dbQueue.inTransaction { db in
@@ -107,7 +107,7 @@ class UpdateStatementTests : GRDBTestCase {
["😀"],
]
for person in persons {
statement.arguments = QueryArguments(person)
statement.arguments = StatementArguments(person)
try statement.execute()
}
@@ -125,7 +125,7 @@ class UpdateStatementTests : GRDBTestCase {
}
}
func testDictionaryQueryArguments() {
func testDictionaryStatementArguments() {
assertNoError {
try dbQueue.inTransaction { db in
@@ -136,7 +136,7 @@ class UpdateStatementTests : GRDBTestCase {
["name": "😀"],
]
for person in persons {
try statement.execute(arguments: QueryArguments(person))
try statement.execute(arguments: StatementArguments(person))
}
return .Commit
@@ -153,7 +153,7 @@ class UpdateStatementTests : GRDBTestCase {
}
}
func testQueryArgumentsSetterWithDictionary() {
func testStatementArgumentsSetterWithDictionary() {
assertNoError {
try dbQueue.inTransaction { db in
@@ -164,7 +164,7 @@ class UpdateStatementTests : GRDBTestCase {
["name": "😀"],
]
for person in persons {
statement.arguments = QueryArguments(person)
statement.arguments = StatementArguments(person)
try statement.execute()
}
+6 -6
View File
@@ -74,14 +74,14 @@
56CC3C931B43BF0100A9A534 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC3C921B43BF0100A9A534 /* Configuration.swift */; };
56CC3C951B43C0E600A9A534 /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC3C941B43C0E600A9A534 /* DatabaseMigrator.swift */; };
56CC3C9B1B4464AE00A9A534 /* RowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC3C9A1B4464AE00A9A534 /* RowModel.swift */; };
56E4BB811B45373600FD324B /* QueryArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E4BB801B45373600FD324B /* QueryArguments.swift */; };
56E4BB811B45373600FD324B /* StatementArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E4BB801B45373600FD324B /* StatementArguments.swift */; };
56E5D7D41B4D3FEE00430942 /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 56E5D7CA1B4D3FED00430942 /* GRDB.framework */; };
56E5D7FE1B4D422E00430942 /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC3773F319C8CBB3004FCF85 /* GRDB.framework */; };
56E5D8041B4D424400430942 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; };
56E5D8181B4D435D00430942 /* GRDBTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5623E0901B4AFACC00B20B7F /* GRDBTestCase.swift */; };
56E5D82C1B4D437600430942 /* GRDB.h in Headers */ = {isa = PBXBuildFile; fileRef = DC3773F819C8CBB3004FCF85 /* GRDB.h */; settings = {ATTRIBUTES = (Public, ); }; };
56E5D82D1B4D438800430942 /* GRDB-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; };
56E5D82E1B4D43FA00430942 /* QueryArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E4BB801B45373600FD324B /* QueryArguments.swift */; };
56E5D82E1B4D43FA00430942 /* StatementArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E4BB801B45373600FD324B /* StatementArguments.swift */; };
56E5D82F1B4D43FA00430942 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC3C921B43BF0100A9A534 /* Configuration.swift */; };
56E5D8301B4D43FA00430942 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565E191D1B42B2B600D32814 /* Database.swift */; };
56E5D8311B4D43FA00430942 /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CC3C941B43C0E600A9A534 /* DatabaseMigrator.swift */; };
@@ -164,7 +164,7 @@
56CC3C941B43C0E600A9A534 /* DatabaseMigrator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMigrator.swift; sourceTree = "<group>"; };
56CC3C9A1B4464AE00A9A534 /* RowModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowModel.swift; sourceTree = "<group>"; };
56E1524B1B43FD5B00EE27AA /* TODO.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = TODO.md; sourceTree = "<group>"; };
56E4BB801B45373600FD324B /* QueryArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryArguments.swift; sourceTree = "<group>"; };
56E4BB801B45373600FD324B /* StatementArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArguments.swift; sourceTree = "<group>"; };
56E5D7CA1B4D3FED00430942 /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
56E5D7D31B4D3FEE00430942 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
56E5D7F91B4D422D00430942 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -410,11 +410,11 @@
56CC3C8E1B43A5A700A9A534 /* DatabaseQueue.swift */,
564E0B151B4D901300EBC9F6 /* DatabaseValue.swift */,
5699AE5E1B42E59F00C35172 /* DatabaseValueConvertible.swift */,
56E4BB801B45373600FD324B /* QueryArguments.swift */,
5699AE581B42CD7800C35172 /* Row.swift */,
56CC3C9A1B4464AE00A9A534 /* RowModel.swift */,
5699AE5A1B42D3DC00C35172 /* SelectStatement.swift */,
5699AE561B42C34A00C35172 /* Statement.swift */,
56E4BB801B45373600FD324B /* StatementArguments.swift */,
5699AE5C1B42D49C00C35172 /* UpdateStatement.swift */,
DC37743319C8CFCE004FCF85 /* Supporting Files */,
);
@@ -614,7 +614,7 @@
files = (
56E5D8301B4D43FA00430942 /* Database.swift in Sources */,
56E5D82F1B4D43FA00430942 /* Configuration.swift in Sources */,
56E5D82E1B4D43FA00430942 /* QueryArguments.swift in Sources */,
56E5D82E1B4D43FA00430942 /* StatementArguments.swift in Sources */,
56E5D8341B4D43FA00430942 /* RowModel.swift in Sources */,
56E5D8311B4D43FA00430942 /* DatabaseMigrator.swift in Sources */,
56B8F4491B4E1C7800C24296 /* DatabaseError.swift in Sources */,
@@ -716,7 +716,7 @@
565E191E1B42B2B600D32814 /* Database.swift in Sources */,
5699AE5B1B42D3DC00C35172 /* SelectStatement.swift in Sources */,
56CC3C9B1B4464AE00A9A534 /* RowModel.swift in Sources */,
56E4BB811B45373600FD324B /* QueryArguments.swift in Sources */,
56E4BB811B45373600FD324B /* StatementArguments.swift in Sources */,
9E903FA81B82729400A63DA0 /* DatabaseChanges.swift in Sources */,
564E0B141B4D8FC100EBC9F6 /* DatabaseError.swift in Sources */,
);
+2 -2
View File
@@ -30,7 +30,7 @@ public struct Configuration {
// MARK: - Utilities
/// A tracing function that logs SQL statements
public static func logSQL(sql: String, arguments: QueryArguments?) {
public static func logSQL(sql: String, arguments: StatementArguments?) {
NSLog("GRDB: %@", sql)
if let arguments = arguments {
NSLog("GRDB: arguments %@", arguments.description)
@@ -45,7 +45,7 @@ public struct Configuration {
- parameter sql: An SQL query
- parameter arguments: Eventual query arguments.
*/
public typealias TraceFunction = (sql: String, arguments: QueryArguments?) -> Void
public typealias TraceFunction = (sql: String, arguments: StatementArguments?) -> Void
/// If true, the database has support for foreign keys.
public var foreignKeysEnabled: Bool
+7 -7
View File
@@ -87,7 +87,7 @@ public final class Database {
- returns: A DatabaseChanges.
- throws: A DatabaseError whenever a SQLite error occurs.
*/
public func execute(sql: String, arguments: QueryArguments? = nil) throws -> DatabaseChanges {
public func execute(sql: String, arguments: StatementArguments? = nil) throws -> DatabaseChanges {
let statement = try updateStatement(sql)
return try statement.execute(arguments: arguments)
}
@@ -289,7 +289,7 @@ extension Database {
- parameter arguments: Optional query arguments.
- returns: A lazy sequence of rows.
*/
public func fetchRows(sql: String, arguments: QueryArguments? = nil) -> AnySequence<Row> {
public func fetchRows(sql: String, arguments: StatementArguments? = nil) -> AnySequence<Row> {
return selectStatement(sql).fetchRows(arguments: arguments)
}
@@ -302,7 +302,7 @@ extension Database {
- parameter arguments: Optional query arguments.
- returns: An array of rows.
*/
public func fetchAllRows(sql: String, arguments: QueryArguments? = nil) -> [Row] {
public func fetchAllRows(sql: String, arguments: StatementArguments? = nil) -> [Row] {
return Array(fetchRows(sql, arguments: arguments))
}
@@ -315,7 +315,7 @@ extension Database {
- parameter arguments: Optional query arguments.
- returns: An optional row.
*/
public func fetchOneRow(sql: String, arguments: QueryArguments? = nil) -> Row? {
public func fetchOneRow(sql: String, arguments: StatementArguments? = nil) -> Row? {
return fetchRows(sql, arguments: arguments).generate().next()
}
}
@@ -337,7 +337,7 @@ extension Database {
- parameter arguments: Optional query arguments.
- returns: A lazy sequence of values.
*/
public func fetch<Value: DatabaseValueConvertible>(type: Value.Type, _ sql: String, arguments: QueryArguments? = nil) -> AnySequence<Value?> {
public func fetch<Value: DatabaseValueConvertible>(type: Value.Type, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence<Value?> {
return selectStatement(sql).fetch(type, arguments: arguments)
}
@@ -352,7 +352,7 @@ extension Database {
- parameter arguments: Optional query arguments.
- returns: An array of values.
*/
public func fetchAll<Value: DatabaseValueConvertible>(type: Value.Type, _ sql: String, arguments: QueryArguments? = nil) -> [Value?] {
public func fetchAll<Value: DatabaseValueConvertible>(type: Value.Type, _ sql: String, arguments: StatementArguments? = nil) -> [Value?] {
return Array(fetch(type, sql, arguments: arguments))
}
@@ -367,7 +367,7 @@ extension Database {
- parameter arguments: Optional query arguments.
- returns: An optional value.
*/
public func fetchOne<Value: DatabaseValueConvertible>(type: Value.Type, _ sql: String, arguments: QueryArguments? = nil) -> Value? {
public func fetchOne<Value: DatabaseValueConvertible>(type: Value.Type, _ sql: String, arguments: StatementArguments? = nil) -> Value? {
if let first = fetch(type, sql, arguments: arguments).generate().next() {
// one row containing an optional value
return first
+3 -3
View File
@@ -40,10 +40,10 @@ public struct DatabaseError : ErrorType {
// MARK: Not public
/// The query arguments that yielded the error (if relevant).
/// Not public because the QueryArguments class has no public method.
let arguments: QueryArguments?
/// Not public because the StatementArguments class has no public method.
let arguments: StatementArguments?
init(code: Int32, message: String? = nil, sql: String? = nil, arguments: QueryArguments? = nil) {
init(code: Int32, message: String? = nil, sql: String? = nil, arguments: StatementArguments? = nil) {
self.code = Int(code)
self.message = message
self.sql = sql
+12 -12
View File
@@ -494,7 +494,7 @@ public class RowModel {
func insertStatement(db: Database) throws -> UpdateStatement {
// INSERT
let insertStatement = try DataMapper.insertStatement(db, tableName: databaseTable.name, insertedColumns: Array(storedDatabaseDictionary.keys))
insertStatement.arguments = QueryArguments(storedDatabaseDictionary.values)
insertStatement.arguments = StatementArguments(storedDatabaseDictionary.values)
return insertStatement
}
@@ -517,7 +517,7 @@ public class RowModel {
// Update
let updateStatement = try DataMapper.updateStatement(db, tableName: databaseTable.name, updatedColumns: Array(updatedDictionary.keys), conditionColumns: Array(primaryKeyDictionary.keys))
updateStatement.arguments = QueryArguments(Array(updatedDictionary.values) + Array(primaryKeyDictionary.values))
updateStatement.arguments = StatementArguments(Array(updatedDictionary.values) + Array(primaryKeyDictionary.values))
return updateStatement
}
@@ -529,7 +529,7 @@ public class RowModel {
// Delete
let deleteStatement = try DataMapper.deleteStatement(db, tableName: databaseTable.name, conditionColumns: Array(primaryKeyDictionary.keys))
deleteStatement.arguments = QueryArguments(primaryKeyDictionary.values)
deleteStatement.arguments = StatementArguments(primaryKeyDictionary.values)
return deleteStatement
}
@@ -541,7 +541,7 @@ public class RowModel {
// Fetch
let selectStatement = DataMapper.selectStatement(db, tableName: databaseTable.name, conditionColumns: Array(primaryKeyDictionary.keys))
selectStatement.arguments = QueryArguments(primaryKeyDictionary.values)
selectStatement.arguments = StatementArguments(primaryKeyDictionary.values)
return selectStatement
}
@@ -554,7 +554,7 @@ public class RowModel {
// Fetch
let existsStatement = DataMapper.existsStatement(db, tableName: databaseTable.name, conditionColumns: Array(primaryKeyDictionary.keys))
existsStatement.arguments = QueryArguments(primaryKeyDictionary.values)
existsStatement.arguments = StatementArguments(primaryKeyDictionary.values)
return existsStatement
}
@@ -666,7 +666,7 @@ extension Database {
- returns: A lazy sequence of row models.
*/
public func fetch<RowModel: GRDB.RowModel>(type: RowModel.Type, _ sql: String, arguments: QueryArguments? = nil) -> AnySequence<RowModel> {
public func fetch<RowModel: GRDB.RowModel>(type: RowModel.Type, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence<RowModel> {
return selectStatement(sql).fetch(type, arguments: arguments)
}
@@ -682,7 +682,7 @@ extension Database {
- returns: An array of row models.
*/
public func fetchAll<RowModel: GRDB.RowModel>(type: RowModel.Type, _ sql: String, arguments: QueryArguments? = nil) -> [RowModel] {
public func fetchAll<RowModel: GRDB.RowModel>(type: RowModel.Type, _ sql: String, arguments: StatementArguments? = nil) -> [RowModel] {
return Array(fetch(type, sql, arguments: arguments))
}
@@ -698,7 +698,7 @@ extension Database {
- returns: An optional row model.
*/
public func fetchOne<RowModel: GRDB.RowModel>(type: RowModel.Type, _ sql: String, arguments: QueryArguments? = nil) -> RowModel? {
public func fetchOne<RowModel: GRDB.RowModel>(type: RowModel.Type, _ sql: String, arguments: StatementArguments? = nil) -> RowModel? {
if let first = fetch(type, sql, arguments: arguments).generate().next() {
// one row containing an optional value
return first
@@ -770,7 +770,7 @@ extension Database {
let whereSQL = " AND ".join(dictionary.keys.map { column in "\(column.quotedDatabaseIdentifier)=?" })
let sql = "SELECT * FROM \(table.name.quotedDatabaseIdentifier) WHERE \(whereSQL)"
return selectStatement(sql).fetchOne(type, arguments: QueryArguments(dictionary.values))
return selectStatement(sql).fetchOne(type, arguments: StatementArguments(dictionary.values))
}
}
@@ -792,7 +792,7 @@ extension SelectStatement {
- returns: A lazy sequence of row models.
*/
public func fetch<RowModel: GRDB.RowModel>(type: RowModel.Type, arguments: QueryArguments? = nil) -> AnySequence<RowModel> {
public func fetch<RowModel: GRDB.RowModel>(type: RowModel.Type, arguments: StatementArguments? = nil) -> AnySequence<RowModel> {
let rowSequence = fetchRows(arguments: arguments)
return AnySequence { () -> AnyGenerator<RowModel> in
let rowGenerator = rowSequence.generate()
@@ -825,7 +825,7 @@ extension SelectStatement {
- returns: An array of row models.
*/
public func fetchAll<RowModel: GRDB.RowModel>(type: RowModel.Type, arguments: QueryArguments? = nil) -> [RowModel] {
public func fetchAll<RowModel: GRDB.RowModel>(type: RowModel.Type, arguments: StatementArguments? = nil) -> [RowModel] {
return Array(fetch(type, arguments: arguments))
}
@@ -841,7 +841,7 @@ extension SelectStatement {
- returns: An optional row model.
*/
public func fetchOne<RowModel: GRDB.RowModel>(type: RowModel.Type, arguments: QueryArguments? = nil) -> RowModel? {
public func fetchOne<RowModel: GRDB.RowModel>(type: RowModel.Type, arguments: StatementArguments? = nil) -> RowModel? {
if let first = fetch(type, arguments: arguments).generate().next() {
// one row containing an optional value
return first
+6 -6
View File
@@ -105,7 +105,7 @@ extension SelectStatement {
- parameter arguments: Optional query arguments.
- returns: A lazy sequence of rows.
*/
public func fetchRows(arguments arguments: QueryArguments? = nil) -> AnySequence<Row> {
public func fetchRows(arguments arguments: StatementArguments? = nil) -> AnySequence<Row> {
if let arguments = arguments {
self.arguments = arguments
}
@@ -160,7 +160,7 @@ extension SelectStatement {
- parameter arguments: Optional query arguments.
- returns: An array of rows.
*/
public func fetchAllRows(arguments arguments: QueryArguments? = nil) -> [Row] {
public func fetchAllRows(arguments arguments: StatementArguments? = nil) -> [Row] {
return Array(fetchRows(arguments: arguments))
}
@@ -174,7 +174,7 @@ extension SelectStatement {
- returns: An optional row.
*/
public func fetchOneRow(arguments arguments: QueryArguments? = nil) -> Row? {
public func fetchOneRow(arguments arguments: StatementArguments? = nil) -> Row? {
return fetchRows(arguments: arguments).generate().next()
}
}
@@ -194,7 +194,7 @@ extension SelectStatement {
- returns: A lazy sequence of values.
*/
public func fetch<Value: DatabaseValueConvertible>(type: Value.Type, arguments: QueryArguments? = nil) -> AnySequence<Value?> {
public func fetch<Value: DatabaseValueConvertible>(type: Value.Type, arguments: StatementArguments? = nil) -> AnySequence<Value?> {
let rowSequence = fetchRows(arguments: arguments)
return AnySequence { () -> AnyGenerator<Value?> in
let rowGenerator = rowSequence.generate()
@@ -220,7 +220,7 @@ extension SelectStatement {
- returns: An array of values.
*/
public func fetchAll<Value: DatabaseValueConvertible>(type: Value.Type, arguments: QueryArguments? = nil) -> [Value?] {
public func fetchAll<Value: DatabaseValueConvertible>(type: Value.Type, arguments: StatementArguments? = nil) -> [Value?] {
return Array(fetch(type, arguments: arguments))
}
@@ -236,7 +236,7 @@ extension SelectStatement {
- returns: An optional value.
*/
public func fetchOne<Value: DatabaseValueConvertible>(type: Value.Type, arguments: QueryArguments? = nil) -> Value? {
public func fetchOne<Value: DatabaseValueConvertible>(type: Value.Type, arguments: StatementArguments? = nil) -> Value? {
if let optionalValue = fetch(type, arguments: arguments).generate().next() {
// one row containing an optional value
return optionalValue
+5 -5
View File
@@ -40,10 +40,10 @@ public class Statement {
public var sql: String
/// The query arguments
public var arguments: QueryArguments? {
public var arguments: StatementArguments? {
didSet {
reset() // necessary before applying new arguments
clearQueryArguments()
clearArguments()
if let arguments = arguments {
arguments.bindInStatement(self)
}
@@ -96,7 +96,7 @@ public class Statement {
}
}
// Exposed for QueryArguments. Don't make this one public unless we keep the arguments property in sync.
// Exposed for StatementArguments. Don't make this one public unless we keep the arguments property in sync.
final func bind(value: DatabaseValueConvertible?, atIndex index: Int) {
let databaseValue = value?.databaseValue ?? .Null
let code: Int32
@@ -120,7 +120,7 @@ public class Statement {
}
}
// Exposed for QueryArguments. Don't make this one public unless we keep the arguments property in sync.
// Exposed for StatementArguments. Don't make this one public unless we keep the arguments property in sync.
final func bind(value: DatabaseValueConvertible?, forKey key: String) {
let index = Int(sqlite3_bind_parameter_index(sqliteStatement, ":\(key)"))
guard index > 0 else {
@@ -138,7 +138,7 @@ public class Statement {
}
// Don't make this one public or internal unless we keep the arguments property in sync.
private func clearQueryArguments() {
private func clearArguments() {
let code = sqlite3_clear_bindings(sqliteStatement)
if code != SQLITE_OK {
fatalDatabaseError(DatabaseError(code: code, message: database.lastErrorMessage, sql: sql))
@@ -25,24 +25,24 @@
import Foundation
/**
SQL queries can have arguments:
SQL statements can have arguments:
INSERT INTO persons (name, age) VALUES (?, ?)
INSERT INTO persons (name, age) VALUES (:name, :age)
To fill question mark arguments, feed QueryArguments with an array:
To fill question mark arguments, feed StatementArguments with an array:
db.execute("INSERT ... (?, ?)", arguments: QueryArguments(["Arthur", 41]))
db.execute("INSERT ... (?, ?)", arguments: StatementArguments(["Arthur", 41]))
Array literals are automatically converted to QueryArguments:
Array literals are automatically converted to StatementArguments:
db.execute("INSERT ... (?, ?)", arguments: ["Arthur", 41])
To fill named arguments, feed QueryArguments with a dictionary:
To fill named arguments, feed StatementArguments with a dictionary:
db.execute("INSERT ... (:name, :age)", arguments: QueryArguments(["name": "Arthur", "age": 41]))
db.execute("INSERT ... (:name, :age)", arguments: StatementArguments(["name": "Arthur", "age": 41]))
Dictionary literals are automatically converted to QueryArguments:
Dictionary literals are automatically converted to StatementArguments:
db.execute("INSERT ... (:name, :age)", arguments: ["name": "Arthur", "age": 41])
@@ -50,7 +50,7 @@ GRDB.swift only supports colon-prefixed named arguments, even though SQLite
supports other syntaxes. See https://www.sqlite.org/lang_expr.html#varparam for
more information.
*/
public struct QueryArguments {
public struct StatementArguments {
// MARK: - Positional Arguments
@@ -58,14 +58,14 @@ public struct QueryArguments {
Initializes arguments from a sequence of optional values.
let values: [String?] = ["foo", "bar", nil]
db.execute("INSERT ... (?,?,?)", arguments: QueryArguments(values))
db.execute("INSERT ... (?,?,?)", arguments: StatementArguments(values))
- parameter sequence: A sequence of optional values that adopt the
DatabaseValueConvertible protocol.
- returns: A QueryArguments.
- returns: A StatementArguments.
*/
public init<Sequence: SequenceType where Sequence.Generator.Element == Optional<DatabaseValueConvertible>>(_ sequence: Sequence) {
impl = QueryArgumentsArrayImpl(values: Array(sequence))
impl = StatementArgumentsArrayImpl(values: Array(sequence))
}
/**
@@ -75,10 +75,10 @@ public struct QueryArguments {
protocol, NSNull, NSNumber or NSString. A fatal error is thrown otherwise.
let values: NSArray = ["foo", "bar", "baz"]
db.execute("INSERT ... (?,?,?)", arguments: QueryArguments(values))
db.execute("INSERT ... (?,?,?)", arguments: StatementArguments(values))
- parameter array: An NSArray
- returns: A QueryArguments.
- returns: A StatementArguments.
*/
public init(_ array: NSArray) {
// IMPLEMENTATION NOTE
@@ -91,11 +91,11 @@ public struct QueryArguments {
// ["Barbara"],
// ]
// for person in persons {
// try statement.execute(QueryArguments(person)) // Avoid an error here
// try statement.execute(StatementArguments(person)) // Avoid an error here
// }
var values = [DatabaseValueConvertible?]()
for item in array {
values.append(QueryArguments.valueFromAnyObject(item))
values.append(StatementArguments.valueFromAnyObject(item))
}
self.init(values)
}
@@ -107,7 +107,7 @@ public struct QueryArguments {
Initializes arguments from a dictionary of optional values.
let values: [String: String?] = ["firstName": nil, "lastName": "Miller"]
db.execute("INSERT ... (:firstName, :lastName)", arguments: QueryArguments(values))
db.execute("INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values))
GRDB.swift only supports colon-prefixed named arguments, even though SQLite
supports other syntaxes. See https://www.sqlite.org/lang_expr.html#varparam
@@ -115,10 +115,10 @@ public struct QueryArguments {
- parameter dictionary: A dictionary of optional values that adopt the
DatabaseValueConvertible protocol.
- returns: A QueryArguments.
- returns: A StatementArguments.
*/
public init(_ dictionary: [String: DatabaseValueConvertible?]) {
impl = QueryArgumentsDictionaryImpl(dictionary: dictionary)
impl = StatementArgumentsDictionaryImpl(dictionary: dictionary)
}
/**
@@ -128,14 +128,14 @@ public struct QueryArguments {
protocol, NSNull, NSNumber or NSString. A fatal error is thrown otherwise.
let values: NSDictionary = ["firstName": "Arthur", "lastName": "Miller"]
db.execute("INSERT ... (?,?,?)", arguments: QueryArguments(values))
db.execute("INSERT ... (?,?,?)", arguments: StatementArguments(values))
GRDB.swift only supports colon-prefixed named arguments, even though SQLite
supports other syntaxes. See https://www.sqlite.org/lang_expr.html#varparam
for more information.
- parameter dictionary: An NSDictionary
- returns: A QueryArguments.
- returns: A StatementArguments.
*/
public init(_ dictionary: NSDictionary) {
// IMPLEMENTATION NOTE
@@ -148,12 +148,12 @@ public struct QueryArguments {
// ["name": "Barbara"],
// ]
// for person in persons {
// try statement.execute(QueryArguments(person)) // Avoid an error here
// try statement.execute(StatementArguments(person)) // Avoid an error here
// }
var values = [String: DatabaseValueConvertible?]()
for (key, item) in dictionary {
if let key = key as? String {
values[key] = QueryArguments.valueFromAnyObject(item)
values[key] = StatementArguments.valueFromAnyObject(item)
} else {
fatalError("Not a String key: \(key)")
}
@@ -164,7 +164,7 @@ public struct QueryArguments {
// MARK: - Not Public
let impl: QueryArgumentsImpl
let impl: StatementArgumentsImpl
// Supported usage: Statement.arguments property
//
@@ -175,10 +175,10 @@ public struct QueryArguments {
}
// MARK: - QueryArgumentsArrayImpl
// MARK: - StatementArgumentsArrayImpl
/// Support for positional arguments
private struct QueryArgumentsArrayImpl : QueryArgumentsImpl {
private struct StatementArgumentsArrayImpl : StatementArgumentsImpl {
let values: [DatabaseValueConvertible?]
init(values: [DatabaseValueConvertible?]) {
@@ -202,10 +202,10 @@ public struct QueryArguments {
}
// MARK: - QueryArgumentsDictionaryImpl
// MARK: - StatementArgumentsDictionaryImpl
/// Support for named arguments
private struct QueryArgumentsDictionaryImpl : QueryArgumentsImpl {
private struct StatementArgumentsDictionaryImpl : StatementArgumentsImpl {
let dictionary: [String: DatabaseValueConvertible?]
init(dictionary: [String: DatabaseValueConvertible?]) {
@@ -286,17 +286,17 @@ public struct QueryArguments {
}
// The protocol for QueryArguments underlying implementation
protocol QueryArgumentsImpl : CustomStringConvertible {
// The protocol for StatementArguments underlying implementation
protocol StatementArgumentsImpl : CustomStringConvertible {
func bindInStatement(statement: Statement)
}
// MARK: - ArrayLiteralConvertible
extension QueryArguments : ArrayLiteralConvertible {
extension StatementArguments : ArrayLiteralConvertible {
/**
Returns a QueryArguments from an array literal:
Returns a StatementArguments from an array literal:
db.selectRows("SELECT ...", arguments: ["Arthur", 41])
*/
@@ -308,9 +308,9 @@ extension QueryArguments : ArrayLiteralConvertible {
// MARK: - DictionaryLiteralConvertible
extension QueryArguments : DictionaryLiteralConvertible {
extension StatementArguments : DictionaryLiteralConvertible {
/**
Returns a QueryArguments from a dictionary literal:
Returns a StatementArguments from a dictionary literal:
db.selectRows("SELECT ...", arguments: ["name": "Arthur", "age": 41])
*/
@@ -326,7 +326,7 @@ extension QueryArguments : DictionaryLiteralConvertible {
// MARK: - CustomStringConvertible
extension QueryArguments : CustomStringConvertible {
extension StatementArguments : CustomStringConvertible {
/// A textual representation of `self`.
public var description: String {
return impl.description
+1 -1
View File
@@ -43,7 +43,7 @@ public final class UpdateStatement : Statement {
- returns: A DatabaseChanges.
- throws: A DatabaseError whenever a SQLite error occurs.
*/
public func execute(arguments arguments: QueryArguments? = nil) throws -> DatabaseChanges {
public func execute(arguments arguments: StatementArguments? = nil) throws -> DatabaseChanges {
if let arguments = arguments {
self.arguments = arguments
}
+1 -1
View File
@@ -633,7 +633,7 @@ try dbQueue.inTransaction { db in
]
for person in persons {
let changes = try statement.execute(arguments: QueryArguments(person))
let changes = try statement.execute(arguments: StatementArguments(person))
changes.changedRowCount // The number of rows changed by the statement.
changes.insertedRowID // The inserted Row ID.
}
+7
View File
@@ -1,6 +1,13 @@
Release Notes
=============
## Next Release
**Breaking changes**
- `QueryArguments` has been renamed `StatementArguments`.
## 0.8.0
**New**