-
Notifications
You must be signed in to change notification settings - Fork 150
FAQs
-
How do I create a blank SQLite database?
You can use something like the SQLite Manager extension for Firefox. Or, you can use any of the commonly available SQLite front end tools such as:
-
How about strings with single quotes in them, like
John's Name
? How can you insert them in to an SQLite database?Simply use the
parameters
parameter which is there for both thequery
andexecute
methods. Here's an example:let db = SQLiteDB.shared let name = "John's Name" let sql = "SELECT * FROM clients WHERE name=?" let data = db.query(sql:sql, parameters:[name])
-
When I run a query, the results seem to be an array of Swift Dictionaries. How do I get at the actual data?
As mentioned in the read me, an
SQLiteDB
query returns an array of Dictionaries. Each Dictionary contains one or more key-value pairs for each column of data. You can access the data for a given column by subscripting the Dictionary based on the column name:let arr = db.query(sql:"SELECT * FROM products") let row = arr[0] let col = row["name"] as? String
-
How do I check the contents of the database in my app so that I can make sure that the data is correct?
If you look at the SQLiteDB source, you’ll notice that a copy of the DB is made to the Documents folder on the device. So, you just need to find the simulator location on your hard drive (you can use SimPholders or a similar app to do this easily - or you can dump the Documents folder path to the console via your app when you start the app) and then look inside the Documents folder at that location. There should be a data.db file there and that’s the SQLite database that you’re looking for.
-
When I build and run my project which uses SQLiteDB, I get an error in the console which says: "SQLiteDB - failed to copy writable version of DB!". Or, I get an alert in the application which says: "failed to prepare SQL: Error: out of memory". What's wrong?
That error message is usually an indication that you didn't include an SQLite file with the appropriate name (
data.db
, as mentioned in the documentation) in your project, or, that you did include an SQLite file but it was not set to be copied to the device as part of a project target by assigning a project target to the database file as mentioned in the read me. -
I used SQLiteDB before but after an update I get an error saying "
String
does not have a memberpositionOf
" - what's wrong?Originally, some additional
String
methods were provided as part of theSQLiteDB.swift
file. They have now been moved to their own separateString-Extras.swift
file. When new files are added to the source, remember to add them to your own project as well. If you only use the original files, you will get errors. -
Will SQLiteDB work under OS X?
As of the 25th of September 2014, it mostly should. I do not use SQLiteDB myself under OS X and so the changes are experimental at the moment. They might also require some additional code changes/updates on your part to get it working correctly.
Do note that I will not be updating the code to fix new bugs due to changes to the Swift language as quickly as I do with iOS, for OS X compatibility.
-
Can you explain the Swift functionality/code that you've used in SQLiteDB?
I released SQLiteDB so that it can be of use to others who are facing the same issues in interfacing with SQLite databases using Swift. But unfortunately, I do not have the time to explain Swift functionality to you. Please go through the relevant Apple documentation such as this.
-
I'm using Xcode 6 beta 3 (or beta 2, or any beta which is older than the latest release) and my project will not compile with SQLiteDB. What's wrong?
I usually update SQLiteDB to the latest Xcode beta version within a day or so of the new beta being released. So if you are on an older version of Xcode 6 beta, your code may not work until you upgrade to the latest version. Or, you can go through the commit notes to see which version supports your version of Xcode and use the code from that particular commit.
-
Nothing's working after upgrading to the latest Xcode 6 beta! What do I do?
Since Swift is still heavily under development by Apple, things will change and this can result in things breaking. I will be fixing SQLiteDB to comply with the latest Apple changes as soon as I can. So first check if I've actually pushed in some changes since the last time first :)
If I haven't fixed the issues yet, please be patient. I'll fix them as soon as I can.