1

I have used SQLite.swift plugin to drop tables and truncate the tables, but it does not work in device. The code can be executed by simulator, but not ios devices:

            for row in db.prepare("SELECT name FROM sqlite_master WHERE type='table' and name != 'sqlite_sequence'")
            {
                let tableName = row[0] as String
                tableName_container.append(tableName);
            }
            for item in tableName_container {
                db.scalar("DELETE FROM '"+item+"'")
//                db.scalar("DROP TABLE IF EXISTS "+item+";")
            }
            for item in tableName_container {
                db.scalar("DROP TABLE IF EXISTS '"+item+"'")
            }
//            db.scalar("DROP TABLE event")
            for row11 in db.prepare("SELECT name FROM sqlite_master WHERE type='table' and name != 'sqlite_sequence'")
            {
                let tmp_col = row11[0] as String
                let count = db.scalar("Select count(*) From "+tmp_col+" ;")
                println(count)
            }
Jacky Shek
  • 953
  • 1
  • 11
  • 35
  • What's the actual error/failure? What line triggers it? What version of Xcode/Swift/iOS are you running? How recently have you updated SQLite.swift? What's "item", etc., and where is it assigned? Please provide as much context and detail as possible. It's really difficult for us to troubleshoot as is when we can't even run the code ourselves. – stephencelis Mar 30 '15 at 15:47
  • There is no error, but i fix it with "db.execute" function. Thank you very much. – Jacky Shek Mar 31 '15 at 03:20
  • I'd love to fix an actual issue you're facing if possible. If there's no error could you explain how it failed or provide more context for a repro? – stephencelis Mar 31 '15 at 04:50
  • I am busy in this week, i post my problem detail on this weekend. Sorry for that. – Jacky Shek Apr 01 '15 at 01:16
  • I have not put the sqlite file to the Documents directory and that could be the reason why i get this problem. – Jacky Shek Apr 08 '15 at 02:06

1 Answers1

1

You can easlity configure SQLite with swift using single ton class as well.

You just need to pass your query in related function's argument.

You would be needed methodToInsertUpdateDeleteDatafunction from below.

Refer

https://github.com/hasyapanchasara/SQLite_SingleManagerClass

Method to create database

func methodToCreateDatabase() -> NSURL?{} 

Method to insert, update and delete data

func methodToInsertUpdateDeleteData(strQuery : String) -> Bool{}

Method to select data

func methodToSelectData(strQuery : String) -> NSMutableArray{}
Hasya
  • 9,792
  • 4
  • 31
  • 46