我已经使用以下查询在sqlite db中创建表
let createTableQuery = """
CREATE TABLE Image(
Id INTEGER PRIMARY KEY AUTOINCREMENT, image BLOB);
"""
使用以下方法在“图像”表中插入数据
let insertStatementString = "INSERT INTO Image (image) VALUES (?);"
func insert() {
var insertStatement: OpaquePointer? = nil
if sqlite3_prepare_v2(db, insertStatementString, -1, &insertStatement, nil) == SQLITE_OK {
let image = UIImage.init(named: "item1.png")
let data = UIImagePNGRepresentation(image!)! as NSData
sqlite3_bind_blob(insertStatement, 2, data.bytes, Int32(data.length), SQLITE_TRANSIENT)
if sqlite3_step(insertStatement) == SQLITE_DONE {
print("Successfully inserted row.")
} else {
print("Could not insert row.")
}
} else {
print("INSERT statement could not be prepared.")
}
sqlite3_finalize(insertStatement)
}
当我调用此方法时,它会打印“成功插入行”。但是,当我使用DB Browser for Sqlite打开数据库时,图像列的值为NULL。
任何人都可以帮忙。