Issue regarding Retrieving data from FMDB Database

ios swift fmdb

78 просмотра

1 ответ

In my IOS app I am using FMDB Database to store data. I am having problem while retrieving data. Actually in last page of my app, when i click on "sendtowatch" button, the data should be saved and at the same time it should be retrieved so that the data can be displayed in my watch app. The screenshot of my running app is below .My source code below is

screenshot of my running app screenshot

 @IBAction func sendToWatch(sender: AnyObject) {


    let ticketDB = FMDatabase(path: databasePath as String)
    if ticketDB.open()
    {

        let insertSQL = "INSERT INTO TICKET (image, ticket_category, ticket_type, date, time) VALUES ('\(display_image.image!)', '\(ticket_category.text!)', '\(ticket_type_name.text!)', '\(ticket_date.text!)', '\(ticket_time.text!)')"

        let result = ticketDB.executeUpdate(insertSQL,withArgumentsInArray: nil)

        if !result
        {

            print("Error: \(ticketDB.lastErrorMessage())")

        } else
        {

            let alt = PMAlertController(title: "Success!", description: "Your data is saved to Database!", image: UIImage(named: ""), style: .Alert)

            alt.addAction(PMAlertAction(title: "OK!", style: .Default, action: { (ACTION) -> Void in

                let ticketDB = FMDatabase(path: self.databasePath as String)
                if ticketDB.open()
                {

                    let querySQL = "SELECT * FROM TICKET"

                    let result: FMResultSet? = ticketDB.executeQuery(querySQL, withArgumentsInArray: nil)

                    if let result = result
                    {
                        self.ticketDataArray = NSMutableArray()
                        while result.next()
                        {
                            let ticketInfo = NSMutableDictionary()

                           ticketInfo.setObject(result.stringForColumn("image"), forKey: "image")
                            ticketInfo.setObject(result.stringForColumn("ticket_category"), forKey: "ticket_category")
                            ticketInfo.setObject(result.stringForColumn("ticket_type"), forKey: "ticket_type")
                            ticketInfo.setObject(result.stringForColumn("date"), forKey: "date")
                            ticketInfo.setObject(result.stringForColumn("time"), forKey: "time")
                            self.ticketDataArray.addObject(ticketInfo)

                        }

                    }else{
                       print("Error: \(ticketDB.lastErrorMessage())")

                    }

                ticketDB.close()

                }


            }))

            self.presentViewController(alt, animated: true, completion: nil)
            print(databasePath)

        }
    }


 }

 }
Автор: Nishant Narola Источник Размещён: 08.11.2019 10:59

Ответы (1)


0 плюса

May this will help you

let select_query = "SELECT * FROM TICKET WHERE image=' size {400, 400} orientation 0 scale 1.000000' AND ticket_category='Bus' AND ticket_type='sssss' AND date='Aug 20, 2016' AND time='12:14 PM'"

Автор: Maulik Pandya Размещён: 20.08.2016 07:37
Вопросы из категории :
32x32