I am trying to check the user_version of the sqlite DB. I have an admin tool to bump the version, but I don't understand the syntax of the pragma statement. I am expecting to test the value in an if-statement. Can someone provide a code sample? When I embed the pragma statement in my objective-c code, the compiler throws an error.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
I figured it out with the inspiration from newtover, digging into FMDB and re-reading the sqlite3 documentation (it is still very vague in my opinion). This code returns the value that I bumped in the admin tool when I make notable changes to the schema that require migration.
I have a similar method for the schema version where the sql-statement is changed to
"PRAGMA schema_version;"
If you are using FMDB wrapper (which is recommended if you don't want to deal with C handler interface of sqlite)
Use
To read current user_version user
Documentation:
http://ccgus.github.io/fmdb/html/Categories/FMDatabase+FMDatabaseAdditions.html
This answer is basically copy of this answer: https://stackoverflow.com/a/27807125/1364174
Pragma statements can not be used within other statements (there are no references to pragma-stmt from other statements).
But you can use the user_version value by making two requests: querying pragma and using the selected value as literal in the next query.
UPD: if you are interested in PRAGMA syntax, it is rather simple:
That is the result will come as a row with a single value.
If you are interested in a way to issue statements to SQLite in objective-c, try looking at neighbour questions: example. Unfortunatelly, I've never coded in objective-c.