I have a db, and I want to add a column to it if it doesn't exist. How do I do that with sqlite.swift API?
标签:
sqlite.swift
相关问题
- Problem with SQLite.swift after migration to Swift
- How to insert into Sqlite with optional parameters
- Adding an Xcode subproject: Shouldn't all the
- How to access an FTS table in SQLite.swift using t
- How to create a Type-Safe custom function in SQLit
相关文章
- How to access an FTS table in SQLite.swift using t
- How to create a Type-Safe custom function in SQLit
- How to create a filter that does the SQL equivalen
- sqlite.swift linked library or also embedded?
- Add “blocking” to Swift for-loop
- iOS: How to copy pre-seeded database at the first
- Using transactions to insert is throwing errors Sq
- SQLite/SQLite-Bridging.h not found in SQLite.swift
The correct way for swift 2.0 is following:
Generally you'll want to have a migration path if you're adding new columns to existing tables. You can use the
userVersion
attribute to manage versions of your database schema:You can also, as Max suggested, use
ifNotExists:
at thecreate(table:…)
level:But for adding new columns, you have to parse an unwieldy PRAGMA statement:
Not nearly as readable (or recommended), but if you're dealing with a legacy database, maybe necessary.
Be sure to read the ALTER TABLE documentation for more complicated alterations.