1

好的,所以我正在尝试将数据库合并到登录/注册屏幕中,无论我尝试了什么,它都不会执行 INSERT 语句。.sqlite 文件包含在“支持文件”中,并且也包含在其中。这是一些示例代码...

-(IBAction)registerButtonPressed:(id)sender {
NSLog(@"New username: %@ New password: %@", theNewUsername.text, theNewPassword.text);

sqlite3_stmt *statement;
const char *dbpath = [dbPathString UTF8String];

if (sqlite3_open(dbpath, &loginDB) == SQLITE_OK)
{
    // this is the command to be executed
    NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO users(username, password, coins) "
                        "VALUES (\"%@\", \"%@\", \"%d\")", username.text, password.text, 0];
    const char *insert_stmt = [insertSQL UTF8String];
    sqlite3_prepare_v2(loginDB, insert_stmt, -1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE)
    {
        NSLog(@"Contact added");
        username.text = @"";
        password.text = @"";
    }
    else {
        NSLog(@"Failed to add contact");
    }
    sqlite3_finalize(statement);
    sqlite3_close(loginDB);
}
else {
    NSLog(@"Failed to open database");
}
}

我只收到返回“无法添加联系人”

4

0 回答 0