Код: Выделить всё
let db = Database.openDatabase()
let insertStatementString = "INSERT INTO SignupDetails VALUES (\((self.txtUsername.text!.trimmingCharacters(in: .whitespaces))), \((self.txtPassword.text!.trimmingCharacters(in: .whitespaces))))"
Database.insertIntoSignupDetails(db: db, insertStatementString: insertStatementString)
sqlite3_close(db)
Я создал таблицу как показано ниже:-
Код: Выделить всё
let db = Database.openDatabase()
let createTableString =
"""
CREATE TABLE IF NOT EXISTS SignupDetails(
username CHAR(255),
password CHAR(255));
"""
Database.createTable(db: (db != nil) ? db : OpaquePointer(UserDefaults.standard.object(forKey: Constant.db) as! String), createTableString: createTableString)
sqlite3_close(db)
Код: Выделить всё
static func createTable(db: OpaquePointer?, createTableString: String) {
var createTableStatement: OpaquePointer? = nil
if sqlite3_prepare_v2(db, createTableString, -1, &createTableStatement, nil) == SQLITE_OK {
if sqlite3_step(createTableStatement) == SQLITE_DONE {
print("table created.")
} else {
print("table could not be created.")
}
} else {
print("CREATE TABLE statement could not be prepared.")
}
sqlite3_finalize(createTableStatement)
}
получаю ошибку, показанную ниже: -
Код:-
Код: Выделить всё
var insertStatement: OpaquePointer?
guard sqlite3_prepare_v2(db, insertStatementString, -1, &insertStatement, nil) == SQLITE_OK else {
let errmsg = String(cString: sqlite3_errmsg(db))
print("failure preparing: \(errmsg)")
return
}
if sqlite3_step(insertStatement) == SQLITE_OK {
print("Successfully inserted row.")
} else {
print("Could not insert row.")
}
sqlite3_finalize(insertStatement)
сбой подготовки: неверный параметр или другое неправильное использование API
Подробнее здесь: https://stackoverflow.com/questions/541 ... hile-inser