@@ -26,13 +26,13 @@ class Statement {
26
26
27
27
init ( _ connection: Connection , _ SQL: String ) throws { self . connection = connection}
28
28
29
- public func bind( _ values: Binding ? ... ) -> Statement { return Statement ( connection , " " ) }
30
- public func bind( _ values: [ Binding ? ] ) -> Statement { return Statement ( connection , " " ) }
31
- public func bind( _ values: [ String : Binding ? ] ) -> Statement { return Statement ( connection , " " ) }
29
+ public func bind( _ values: Binding ? ... ) -> Statement { return self }
30
+ public func bind( _ values: [ Binding ? ] ) -> Statement { return self }
31
+ public func bind( _ values: [ String : Binding ? ] ) -> Statement { return self }
32
32
33
- @discardableResult public func run( _ bindings: Binding ? ... ) throws -> Statement { return Statement ( connection , " " ) }
34
- @discardableResult public func run( _ bindings: [ Binding ? ] ) throws -> Statement { return Statement ( connection , " " ) }
35
- @discardableResult public func run( _ bindings: [ String : Binding ? ] ) throws -> Statement { return Statement ( connection , " " ) }
33
+ @discardableResult public func run( _ bindings: Binding ? ... ) throws -> Statement { return self }
34
+ @discardableResult public func run( _ bindings: [ Binding ? ] ) throws -> Statement { return self }
35
+ @discardableResult public func run( _ bindings: [ String : Binding ? ] ) throws -> Statement { return self }
36
36
37
37
public func scalar( _ bindings: Binding ? ... ) throws -> Binding ? { return nil }
38
38
public func scalar( _ bindings: [ Binding ? ] ) throws -> Binding ? { return nil }
@@ -42,13 +42,13 @@ class Statement {
42
42
class Connection {
43
43
public func execute( _ SQL: String ) throws { }
44
44
45
- public func prepare( _ statement: String , _ bindings: Binding ? ... ) throws -> Statement { return Statement ( self , " " ) }
46
- public func prepare( _ statement: String , _ bindings: [ Binding ? ] ) throws -> Statement { return Statement ( self , " " ) }
47
- public func prepare( _ statement: String , _ bindings: [ String : Binding ? ] ) throws -> Statement { return Statement ( self , " " ) }
45
+ public func prepare( _ statement: String , _ bindings: Binding ? ... ) throws -> Statement { return try Statement ( self , " " ) }
46
+ public func prepare( _ statement: String , _ bindings: [ Binding ? ] ) throws -> Statement { return try Statement ( self , " " ) }
47
+ public func prepare( _ statement: String , _ bindings: [ String : Binding ? ] ) throws -> Statement { return try Statement ( self , " " ) }
48
48
49
- @discardableResult public func run( _ statement: String , _ bindings: Binding ? ... ) throws -> Statement { return Statement ( self , " " ) }
50
- @discardableResult public func run( _ statement: String , _ bindings: [ Binding ? ] ) throws -> Statement { return Statement ( self , " " ) }
51
- @discardableResult public func run( _ statement: String , _ bindings: [ String : Binding ? ] ) throws -> Statement { return Statement ( self , " " ) }
49
+ @discardableResult public func run( _ statement: String , _ bindings: Binding ? ... ) throws -> Statement { return try Statement ( self , " " ) }
50
+ @discardableResult public func run( _ statement: String , _ bindings: [ Binding ? ] ) throws -> Statement { return try Statement ( self , " " ) }
51
+ @discardableResult public func run( _ statement: String , _ bindings: [ String : Binding ? ] ) throws -> Statement { return try Statement ( self , " " ) }
52
52
53
53
public func scalar( _ statement: String , _ bindings: Binding ? ... ) throws -> Binding ? { return nil }
54
54
public func scalar( _ statement: String , _ bindings: [ Binding ? ] ) throws -> Binding ? { return nil }
@@ -57,9 +57,9 @@ class Connection {
57
57
58
58
// --- tests ---
59
59
60
- func test_sqlite_swift_api( db: Connection ) {
60
+ func test_sqlite_swift_api( db: Connection ) throws {
61
61
let localString = " user "
62
- let remoteString = try ! String ( contentsOf: URL ( string: " http://example.com/ " ) !)
62
+ let remoteString = try String ( contentsOf: URL ( string: " http://example.com/ " ) !)
63
63
let remoteNumber = Int ( remoteString) ?? 0
64
64
65
65
let unsafeQuery1 = remoteString
@@ -89,11 +89,11 @@ func test_sqlite_swift_api(db: Connection) {
89
89
let stmt3 = try db. prepare ( varQuery, remoteString) // GOOD
90
90
try stmt3. run ( )
91
91
92
- let stmt4 = Statement ( db, localString) // GOOD
93
- stmt4. run ( )
92
+ let stmt4 = try Statement ( db, localString) // GOOD
93
+ try stmt4. run ( )
94
94
95
- let stmt5 = Statement ( db, remoteString) // BAD
96
- stmt5. run ( )
95
+ let stmt5 = try Statement ( db, remoteString) // BAD
96
+ try stmt5. run ( )
97
97
98
98
// --- more variants ---
99
99
@@ -106,28 +106,28 @@ func test_sqlite_swift_api(db: Connection) {
106
106
let stmt8 = try db. prepare ( unsafeQuery1, [ " username " : " " ] ) // BAD
107
107
try stmt8. run ( )
108
108
109
- db. run ( unsafeQuery1, " " ) // BAD
109
+ try db. run ( unsafeQuery1, " " ) // BAD
110
110
111
- db. run ( unsafeQuery1, [ " " ] ) // BAD
111
+ try db. run ( unsafeQuery1, [ " " ] ) // BAD
112
112
113
- db. run ( unsafeQuery1, [ " username " : " " ] ) // BAD
113
+ try db. run ( unsafeQuery1, [ " username " : " " ] ) // BAD
114
114
115
- db. scalar ( unsafeQuery1, " " ) // BAD
115
+ try db. scalar ( unsafeQuery1, " " ) // BAD
116
116
117
- db. scalar ( unsafeQuery1, [ " " ] ) // BAD
117
+ try db. scalar ( unsafeQuery1, [ " " ] ) // BAD
118
118
119
- db. scalar ( unsafeQuery1, [ " username " : " " ] ) // BAD
119
+ try db. scalar ( unsafeQuery1, [ " username " : " " ] ) // BAD
120
120
121
121
let stmt9 = try db. prepare ( varQuery) // GOOD
122
- stmt9. bind ( remoteString) // GOOD
123
- stmt9. bind ( [ remoteString] ) // GOOD
124
- stmt9. bind ( [ " username " : remoteString] ) // GOOD
122
+ try stmt9. bind ( remoteString) // GOOD
123
+ try stmt9. bind ( [ remoteString] ) // GOOD
124
+ try stmt9. bind ( [ " username " : remoteString] ) // GOOD
125
125
try stmt9. run ( remoteString) // GOOD
126
126
try stmt9. run ( [ remoteString] ) // GOOD
127
127
try stmt9. run ( [ " username " : remoteString] ) // GOOD
128
128
try stmt9. scalar ( remoteString) // GOOD
129
129
try stmt9. scalar ( [ remoteString] ) // GOOD
130
130
try stmt9. scalar ( [ " username " : remoteString] ) // GOOD
131
131
132
- Statement ( db, remoteString) . run ( ) // BAD
132
+ try Statement ( db, remoteString) . run ( ) // BAD
133
133
}
0 commit comments