当用户在线或离线时,我正在使用可创建的应用程序,因此我使用了sqlite
数据库,因此当我从表中检索数据时,我无法在这里检索数据是我的数据提取代码>
func get_sub_element_offline_data(){
self.subelementOfflineData.removeAll()
let fileURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
.appendingPathComponent("EOBA.sqlite")
if sqlite3_open(fileURL.path, &db) != SQLITE_OK {
print("error opening database")
}
let queryString = "SELECT * FROM Sub_ElementList_NEW1 WHERE element_id = \(elementID)"
var stmt:OpaquePointer?
if sqlite3_prepare(db, queryString, -1, &stmt, nil) != SQLITE_OK{
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("error preparing insert: \(errmsg)")
return
}
while(sqlite3_step(stmt) == SQLITE_ROW){ //here while statement not able to execute
let id = sqlite3_column_int(stmt, 0)
let element_id = String(cString: sqlite3_column_text(stmt, 1))
let sub_elements_id = String(cString: sqlite3_column_text(stmt, 2))
let fk_elements_id = String(cString: sqlite3_column_text(stmt, 3))
let title = String(cString: sqlite3_column_text(stmt, 4))
print(id)
print(element_id)
print(sub_elements_id)
print(fk_elements_id)
print(title)
subelementOfflineData.append(SubElementOfflineModel(id: Int(id), sub_elements_id: String(describing: sub_elements_id), title: String(describing: title)))
do {
let jsonData = try JSONEncoder().encode(subelementOfflineData)
let jsonString = String(data: jsonData, encoding: .utf8)!
print(jsonString)
} catch {
print(error)
}
}
}
我正在基于元素列表获取数据,我检查同一表中是否存在元素ID,但仍然无法获取数据
所以请为此提供帮助