如何使用 Sqlite 管理器将数据添加到数据库中

How do I add data into a database using Sqlite manager

我想执行插入查询查询工作正常当我们称这个 InsUpdateDelData 它 return false 然后数据没有插入

- (IBAction)addToCart:(id)sender {

    AppDelegate *obj = (AppDelegate *)[[UIApplication sharedApplication]delegate] ;
    NSString *insert = @"ahmadyarimran@yahoo.com" ;


    NSString *insertSQL = [NSString stringWithFormat:
    @"INSERT INTO   cart_user(user_id,product_price,product_type,categories_type,product_images,description) values('%@','%@','%@','%@','%@','%@')",insert,handBegsImages.product_price,handBegsImages.product_tagline,handbegCategoriess.handbegid,handBegsImages.main_image,handBegsImages.product_description];
    BOOL abc = [obj InsUpdateDelData:insertSQL];
     NSLog(@"print the value of abc %@=", abc) ;
    if (abc == TRUE) {
      NSLog(@"@ Data was Inserted");
    }
    else{
          [Utility showAlertView:@"Plz try again message" message:@"Again"  viewcontroller:self];
    }
     }


 -(BOOL)InsUpdateDelData:(NSString*)SqlStr
{
    if([SqlStr isEqual:@""])
        return NO;

    BOOL RetrunValue;
    RetrunValue = NO;
    const char *sql = [SqlStr cStringUsingEncoding:NSUTF8StringEncoding];
    sqlite3_stmt *stmt;
    if (sqlite3_prepare_v2(database, sql, -1, &stmt, nil) == SQLITE_OK)
        RetrunValue = YES;

    if(RetrunValue == YES)
    {
        if(sqlite3_step(stmt) != SQLITE_DONE) {

        }
        sqlite3_finalize(stmt);
    }
    return RetrunValue;
}

如果 InsUpdateDelData return 编辑了 NO,那么这意味着 sqlite3_prepare_v2 没有 return SQLITE_OK。如果你想知道为什么它没有 return SQLITE_OK,那么在 sqlite3_prepare_v2 失败后立即记录错误,但在调用任何其他 SQLite 函数之前:

NSLog(@"err=%s", sqlite3_errmsg(database));