sqlite.swift

How to get a list of column names with Sqlite.swift?

我与影子孤独终老i 提交于 2019-12-07 05:35:59
问题 For debugging purposes I am trying to get a simple list of the column names in my SQLite table. I am using the SQLite.swift framework. My question is more specific than How to get a list of column names on sqlite3 / iPhone? so I am creating a new question. Using try db.execute("PRAGMA table_info(table_name);") by applying this answer to the documentation didn't work for me (nothing happened). 回答1: Assuming you already have a database connection called db set up, to get a list of the column

Sqlite.swift create dynamic complex queries

允我心安 提交于 2019-12-06 12:51:53
I have 1 table with multiple columns. On the app, we are looking forward to add 4 dynamic filters like (cat, size, color,shape). We know we can create a filter to sqllite like so: user = user.select(name) .filter((color == "Blue") && (size = "Big") && (cat="a") && (shape="round")) .order(name.asc, name) // ORDER BY "email" DESC, "name" .limit(5, offset: 0) But what happens if a filter, let's say that for color we want to search for all colors. Then, .filter((color == "?????") && (size = "Big") && (cat="a") && (shape="round")) Any ideas on how to create dynamic filters for this case? The filter

Using transactions to insert is throwing errors Sqlite.swift

陌路散爱 提交于 2019-12-06 12:07:05
I have created a Database class as so: class Database { static let instance = Database() private let categories = Table("Category") private var db: Connection? let cat_id = Expression<String>("id") let cat_name = Expression<String>("name") private init() { let path = NSSearchPathForDirectoriesInDomains( .documentDirectory, .userDomainMask, true ).first! do { db = try Connection("\(path)/SalesPresenterDatabase.sqlite3") createTable() } catch { print("error") } } func createTable() { do{ try self.db!.run(self.categories.create(ifNotExists: true) { table in table.column(self.cat_id) table.column

How to access an FTS table in SQLite.swift using the IN condition

一曲冷凌霜 提交于 2019-12-06 02:59:14
I'm trying to query an FTS table using SQLite.swift. Previously I have done it in Android . The essence of what I am trying to do is this : SELECT * FROM t2 WHERE id IN (SELECT docid FROM fts_table WHERE col_text MATCH 'something') From the SQLite.swift documentation I see the IN condition can be written like this : users.filter([1, 2, 3, 4, 5].contains(id)) // SELECT * FROM "users" WHERE ("id" IN (1, 2, 3, 4, 5)) And virtual tables can be queried like this : let wonderfulEmails = emails.match("wonder*") // SELECT * FROM "emails" WHERE "emails" MATCH 'wonder*' let replies = emails.filter

How to get a list of column names with Sqlite.swift?

最后都变了- 提交于 2019-12-05 09:56:25
For debugging purposes I am trying to get a simple list of the column names in my SQLite table. I am using the SQLite.swift framework . My question is more specific than How to get a list of column names on sqlite3 / iPhone? so I am creating a new question. Using try db.execute("PRAGMA table_info(table_name);") by applying this answer to the documentation didn't work for me (nothing happened). Suragch Assuming you already have a database connection called db set up, to get a list of the column names, you can use the following code: do { let tableInfo = Array(try db.prepare("PRAGMA table_info

Adding an Xcode subproject: Shouldn't all the source files get copied?

二次信任 提交于 2019-12-05 08:34:29
I am manually adding the SQLite.swift subproject to my project. As the directions indicated, I copied the .xcodeproj file to my project. This allows me see all the source files (unlike this SO question ). Everything seemed like it was working fine. However, I discovered that the source files of that subproject were not copied to my project. They are still in original location where I downloaded them. Is this by design? What if I want to share my project source code with other people in the future? They won't have the subproject source that is necessary for my project to work. If I do need to

iOS SQLite.swift, regarding upgrade of app?

↘锁芯ラ 提交于 2019-12-05 03:28:45
Regarding the magnificent and amazing SQLite.swift, I'm wondering You have an app in the app store, v7. There's an upgrade to v8. User X does upgrade v7 to v8 using the app store. Say in v8, we have slightly changed one of the sql tables, perhaps add a column or rename a column. Should anything or must anything special be done in SQLite.swift in this case? What's the SQLite.swift way to handle that? (In for example, Android there's a handy onUpgrade concept in their helper class ... which comes with it's own set of complex issues.) CL. The implementation of SQLiteOpenHelper is quite simple: db

Can I cast Int64 directly into Int?

£可爱£侵袭症+ 提交于 2019-12-04 15:34:32
问题 I've been using SQLite.swift lately to build my app database. And I'm defining all my INTEGER columns with a Int64 type, like the documentation explains. But every once in a while I need that Int64 to be just Int . So my question is, if I do this: //Create a table with Int instead of Int64 let test_id = Expression<Int>("test_id") let tests = db["tests"] db.create(table: tests, ifNotExists: true){ t in t.column(test_id) } class func insertTest(t: Int) -> Int{ //insert.rowid returns an Int64

How do I check if a column exist before adding it

♀尐吖头ヾ 提交于 2019-12-01 04:24:05
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? 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: if db.userVersion < 1 { db.create(table: users) { t in t.column(id, primaryKey: true) t.column(email, unique: true) } db.userVersion = 1 } if db.userVersion < 2 { db.alter(table: users, add: name) db.alter(table: users, add: age) db.userVersion = 2 } You can also, as Max suggested, use ifNotExists: at the create

How do I check if a column exist before adding it

爱⌒轻易说出口 提交于 2019-12-01 02:22:19
问题 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? 回答1: 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: if db.userVersion < 1 { db.create(table: users) { t in t.column(id, primaryKey: true) t.column(email, unique: true) } db.userVersion = 1 } if db.userVersion < 2 { db.alter(table: users, add: name) db.alter