ios - 在sqlite数据库中插入数据的问题

标签 ios sqlite

这就是我尝试在 sqlite 数据库中添加数据的方法,一切正常,但数据没有添加到数据库中我不明白为什么你可以引用代码并告诉我我做错了什么

    sqlite3_stmt *stmt;
    int x;

    char *update = "insert into PersonNamesAndBirthDates (Names,Birthdates,Phonenumber,Email,Profilepic) values(?,?,?,?,?);";
    x = sqlite3_prepare_v2(database1, update, -1, &stmt, nil);

    if (x == SQLITE_OK)
    {
        NSLog(@"PersonName is -->%@",[NSString stringWithFormat:@"%@",[_Namebarray objectAtIndex:0]]);
        NSLog(@"BirthDates is -->%@",[NSString stringWithFormat:@"%@",[_Birthdatebarray objectAtIndex:0]]);
        NSLog(@"BirthDates is -->%@",[NSString stringWithFormat:@"%@",[_Phonearray objectAtIndex:0]]);
        NSLog(@"BirthDates is -->%@",[NSString stringWithFormat:@"%@",[_Emailarray objectAtIndex:0]]);
        // if else will come here for checking weather images has added or not if added then store Yes Image if not then simply No image for default image.


        sqlite3_bind_text(stmt, 1, [[NSString stringWithFormat:@"%@",[_Namebarray objectAtIndex:0]] UTF8String],-1, NULL);
        sqlite3_bind_text(stmt, 2, [[NSString stringWithFormat:@"%@",[_Birthdatebarray objectAtIndex:0]] UTF8String],-1, NULL);
        sqlite3_bind_text(stmt, 3, [[NSString stringWithFormat:@"%@",[_Phonearray objectAtIndex:0]] UTF8String],-1, NULL);
        sqlite3_bind_text(stmt, 4, [[NSString stringWithFormat:@"%@",[_Emailarray objectAtIndex:0]] UTF8String],-1, NULL);
        if(selectImage.image)
        {
            sqlite3_bind_text(stmt, 5, [[NSString stringWithFormat:@"%@",[_arrayOfPaths objectAtIndex:0]] UTF8String],-1, NULL);
        }
        else{
            sqlite3_bind_text(stmt, 5, [[NSString stringWithFormat:@"%@",@"No Image"] UTF8String],-1, NULL);
        }
    }
    if (sqlite3_step(stmt) != SQLITE_DONE){}
    NSLog(@"Error: ");
    sqlite3_finalize(stmt);

最佳答案

我在你的代码中没有看到任何错误,请检查你的数据库是否像这样打开

if (sqlite3_open(dbpath, &database1) == SQLITE_OK)

关于ios - 在sqlite数据库中插入数据的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16186503/

相关文章:

Android SQLite 列_id 错误,

ios - 我如何为 iOS 克隆/复制某种 UIView?

c - 从 sqlite 中检索字符串形式的数字并转换为 int

iOS UiCollectionView - 使用自定义 UiCollectionViewLayout 重新加载数据

ios - 将 .cer 转换为 .p12

java - 创建使用 Sqlite DB 的 eclipse 项目的 .jar

java - Java 中的 DriverManager.getConnection 使用相对路径

python - 如何使用 SQLAlchemy 将外键约束正确添加到 SQLite 数据库

ios - NSPredicate 正则表达式错误

ios - NSDictionary 和 JSON 值