I'm using SQLite3 for the first time in my project. I've followed a couple of different tutorials and have managed to get everything working, apart from querying my table.
This is the code direct from one tutorial, Swift 3 which is outdated as the .fromCString doesn't exist:
let rowData = UnsafePointer<CChar>(sqlite3_column_text(dateStatement, 1))
let finalString = String.fromCString(rowData)
This is my current code (with surrounding context) from an updated tutorial but still no luck.
var dateStatement: OpaquePointer?
let dateQuery = "SELECT * FROM StarLineTable"
if sqlite3_prepare(db, dateQuery, -1, &dateStatement, nil) != SQLITE_OK {
print("error preparing for search")
}
while sqlite3_step(dateStatement) == SQLITE_ROW {
let rowData = sqlite3_column_text(dateStatement, 1)
let finalString = String(cString: rowData)
print(finalString)
}
This gives: Value of optional type 'UnsafePointer?' must be unwrapped to a value of type 'UnsafePointer'
I'm probably missing something really simple - not even sure my question is correct as to what I need. Any help would be greatly appreciated!
- I've tried the following solution but get: Type 'String' has no member 'fromCString' Issue with UnsafePointer<Uint8> in SQLite project in Swift