func setupDatabase() {
NSLog("start setupDatabase")
var rc: Int32
var stmt: OpaquePointer?
let createTableString = "CREATE TABLE Test (id INTEGER, field1 Char(255), field2 Char(255))"
rc = sqlite3_prepare_v2(db, createTableString, -1, &stmt, nil)
if rc == SQLITE_OK {
rc = sqlite3_step(stmt)
if rc != SQLITE_DONE {
NSLog("'Test' table is not created: \(rc)")
return
}
} else {
NSLog("CREATE TABLE statement is not prepared: \(rc)")
return
}
sqlite3_finalize(stmt)
// Also working:
// rc = sqlite3_exec(db, createTableString, nil, nil, nil)
// if rc != SQLITE_OK {
// NSLog("Execution of create table error: \(rc)")
// return
// }
NSLog("✅ Table 'Test' created")
}