伙计们,我的片段有问题。我还必须说我是新手。我正在尝试将数据插入到 sqlite。但我一直失败,因为 sqlite_step == sqlite_done 一直返回 false 。我在这里做错什么了吗。我以前做过类似的事情,而且效果很好。以下是代码
sqlite3_stmt *statement;
const char *dbpath = [_databasePath UTF8String];
if(sqlite3_open(dbpath, &_db) == SQLITE_OK){
NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO userInfo (name, email, username, password) VALUES (\"%@\",\"%@\",\"%@\",\"%@\")", self.txtName.text, self.txtEmail.text, self.txtUsername.text, self.txtPassword.text];
if([self validateRegistration])
{
const char *insert_statement = [insertSQL UTF8String];
sqlite3_prepare_v2(_db, insert_statement, -1, &statement, NULL);
if(sqlite3_step(statement) == SQLITE_DONE){
[self showUIAlertWithMessage:@"User added to the database" andTitle:@"Message"];
self.txtName.text = @"";
self.txtEmail.text = @"";
self.txtUsername.text = @"";
self.txtPassword.text = @"";
self.txtConfirmPassword.text = @"";
}else{
[self showUIAlertWithMessage:@"Failed to add the user" andTitle:@"Error"];
}
sqlite3_finalize(statement);
sqlite3_close(_db);
}
}