在我的IOS应用程序中,我使用FMDB数据库来存储数据。我在检索数据时遇到问题。实际上在我的应用程序的最后一页,当我点击" sendtowatch"按钮,应保存数据,同时应检索数据,以便数据可以显示在我的手表应用程序中。我正在运行的应用程序的屏幕截图如下。我的源代码如下
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)
}
}
}
}
答案 0 :(得分:0)
愿这会帮到你
让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 ='2016年8月20日'和时间= '12:14'''