Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 2: userVersion gone #194

Closed
patr1ck opened this issue Sep 7, 2015 · 4 comments
Closed

Swift 2: userVersion gone #194

patr1ck opened this issue Sep 7, 2015 · 4 comments

Comments

@patr1ck
Copy link
Contributor

patr1ck commented Sep 7, 2015

I see in the swift-2 branch that getting and setting the userVersion was removed. Would you accept a PR that brought this back or was this intentionally left out?

Thanks for your hard work!

@stephencelis
Copy link
Owner

@patr1ck I want to rethink a more unified PRAGMA interface, but haven't had time to finalize it yet. In the meantime, this should get you where you need to be:

extension Database {
    public var userVersion: Int {
        get { return Int(scalar("PRAGMA user_version") as! Int64) }
        set { try! run("PRAGMA user_version = \(newValue)") }
    }
}

@patr1ck
Copy link
Contributor Author

patr1ck commented Sep 8, 2015

Cool, makes sense. Thank you!

@violabg
Copy link

violabg commented Oct 13, 2015

I did try to use the extension above but then when I try to set the value of userVersion I get this error:

fatal error: 'try!' expression unexpectedly raised an error: attempt to write a readonly database

even if I explicitly use try! Connection(localPdfDbPath.relativePath!, readonly:false)

@mikemee
Copy link
Collaborator

mikemee commented Jan 10, 2016

I've just confirmed that extension appears to be working in the current release version so I'm closing this out. (PS: @stephencelis I love how easy it is to add this functionality via the extension!)

@violabg, I tried the playground example below and everything seemed to behave as expected. E.g. I set readonly to be true and it was able to read ok and failed on writing. Then I set it false, and I was able to update it. If you can make this fail and/or have more info, please re-open with some details. Thanks!

import SQLite

let db = try! Connection("foo.sqlite", readonly: false)
db.trace { print($0) }

extension Connection {
    public var userVersion: Int {
        get { return Int(scalar("PRAGMA user_version") as! Int64) }
        set { try! run("PRAGMA user_version = \(newValue)") }
    }
}

db.userVersion = 7
print(db.userVersion)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants