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

时间:2015-05-09 14:21:52

标签: ios objective-c sqlite sqlitemanager

我想执行插入查询,当我们调用此InsUpdateDelData时,查询工作正常,返回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;
}

1 个答案:

答案 0 :(得分:0)

如果from kivy.app import App from kivy.uix.button import Button from kivy.uix.popup import Popup from kivy.uix.label import Label class TestApp(App): def build(self): return Button(text="show", on_press=self.anim_btn) def anim_btn(self, *args): popup = Popup(title='Test popup', content=Label(text='Hello world'), size_hint=(None, None), size=(400, 400), background = 'atlas://data/images/defaulttheme/button_pressed' ).open() if __name__ == "__main__": TestApp().run() 返回InsUpdateDelData,则表示NO未返回sqlite3_prepare_v2。如果您想知道为什么它没有返回SQLITE_OK,那么在SQLITE_OK失败后立即记录错误,但在调用任何其他SQLite函数之前:

sqlite3_prepare_v2