一切都在代码中,但不会在SQLite db中保存数据。有人可以帮忙吗?

在下面找到我的代码:

-(IBAction)signin:(id)sender{
    NSLog(@"%@",perDas.string1);
    nameString=[[NSString alloc]initWithString:perDas.string1];
     statusString=[[NSString alloc]initWithFormat:@"IN"];
    {
        NSLog(@"passed");
        sqlite3_stmt    *statement;

        const char *dbpath = [perDas.databasePath UTF8String];

        if (sqlite3_open(dbpath, &database) == SQLITE_OK)
        {
            NSLog(@"pass");
            NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO status  VALUES (\"%@\", \"%@\", datetime(), \"%@\")", nameString, statusString,empString];
            NSLog(@"%@",insertSQL);
            const char *insert_stmt = [insertSQL UTF8String];

            sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL);

            sqlite3_finalize(statement);
            sqlite3_close(database);

    }
    }}

提前致谢

最佳答案

您应该检查您的sql语句是否正确:

if (sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL) == SQLITE_OK) {
...
}

如果仅插入行集的子集,请使用以下INSERT语句形式:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

关于iphone - 没有在SQLite中保存数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11049363/

10-09 08:05