Skip to content
Fahim Farook edited this page Aug 8, 2014 · 24 revisions
  • 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:

  • Do you plan to add support for SQLite's bind API methods?

    No. Currently, there are no plans to add support for the bind methods since you can easily create an SQL statement with variables by simply creating a String with the appropriate variable values inserted where necessary. For example:

      let name = "John"  
      let sql = "SELECT * FROM clients WHERE name='\(name)'"  
    
  • But what about strings with single quotes in them, like John's Name? How can you insert them via SQLiteDB without using the bind API calls?

    That's what the esc method in SQLiteDB is for :) That method returns a quoted and escaped string - so you don't have to even enclose the resulting string in quotes like in the above example. Here's an example:

      let db = SQLiteDB.sharedInstance()
      let name = db.esc("John's Name")
      let sql = "SELECT * FROM clients WHERE name=\(name)"
    
  • When I run a query, the results seem to be an array of SQLRow. How do I get at the actual data?

    As mentioned in the read me, an SQLiteDB query returns an array of SQLRow objects. Each SQLRow object contains one or more SQLColumn objects for each column of data. You can access the SQLColumn objects by subscripting the SQLRow object based on the column name:

      let arr = db.query("SELECT * FROM products")
      let row = arr[0]
      let col = arr["name"]
    

    But the above only returns an SQLColumn object in the col variable. How do you get a String value? Or a value as some other data type like Int, Double etc.?

    If you check the code for SQLColumn, you'll notice that it has built-in variables for returning the underlying data as a specific type - string, integer, asDouble, data, and date. These variables return the column's value as a native data type - like this:

      let str = col.string
    

    The above returns the value of the SQLColumn object named col as a String.

    Note: Currently, the various data type methods for SQLColumn return data for a given type only if the underlying SQLite database column was of that type. The methods do not convert from one type to another. For instance, if tye acutal data in the SQLite database was an integer value, then you will not get a String representation of the data by using SQLColumn's string variable. You'll simply get an empty string.

  • 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.

  • I used SQLiteDB before but after an update I get an error saying "String does not have a member positionOf" - what's wrong?

    Originally, some additional String methods were provided as part of the SQLiteDB.swift file. They have now been moved to their own separate String-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.

  • 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.

Clone this wiki locally