File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -151,12 +151,22 @@ public final class Connection {
151
151
public var totalChanges : Int {
152
152
Int ( sqlite3_total_changes ( handle) )
153
153
}
154
-
155
- /// The user version of the database.
154
+
155
+ /// Gets the user version of the database.
156
+ /// See SQLite [PRAGMA user_version](https://sqlite.org/pragma.html#pragma_user_version)
157
+ /// - Returns: the user version of the database
158
+ public func getUserVersion( ) throws -> Int32 ? {
159
+ guard let userVersion = try scalar ( " PRAGMA user_version " ) as? Int64 else {
160
+ return nil
161
+ }
162
+ return Int32 ( userVersion)
163
+ }
164
+
165
+ /// Sets the user version of the database.
156
166
/// See SQLite [PRAGMA user_version](https://sqlite.org/pragma.html#pragma_user_version)
157
- public var userVersion : Int32 {
158
- get { return Int32 ( try ! scalar ( " PRAGMA user_version " ) as! Int64 ) }
159
- set { try ! run ( " PRAGMA user_version = \( newValue ) " ) }
167
+ /// - Parameter userVersion: the new user version of the database
168
+ public func setUserVersion ( to userVersion : Int32 ) throws {
169
+ try run ( " PRAGMA user_version = \( userVersion ) " )
160
170
}
161
171
162
172
// MARK: - Execute
Original file line number Diff line number Diff line change @@ -96,6 +96,11 @@ class ConnectionTests: SQLiteTestCase {
96
96
XCTAssertEqual ( 2 , db. totalChanges)
97
97
}
98
98
99
+ func test_userVersion( ) {
100
+ try ! db. setUserVersion ( to: 2 )
101
+ XCTAssertEqual ( 2 , try ! db. getUserVersion ( ) !)
102
+ }
103
+
99
104
func test_prepare_preparesAndReturnsStatements( ) {
100
105
_ = try ! db. prepare ( " SELECT * FROM users WHERE admin = 0 " )
101
106
_ = try ! db. prepare ( " SELECT * FROM users WHERE admin = ? " , 0 )
You can’t perform that action at this time.
0 commit comments