Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

delete query for iphone sqlite
#1

Code:
-(IBAction)deleteinfo {
    NSString *dbpath=[self getdbpath];

    if( sqlite3_open([dbpath UTF8String], &database) == SQLITE_OK ) {
        // Create Query String.
        NSString* sqlStatement = [NSString stringWithFormat:@"DELETE
        FROM Details WHERE name ='%@'", [NSString
        stringWithFormat:select2.text]];

        if( sqlite3_prepare_v2(database, [sqlStatement UTF8String],
        -1, &deleteStmt, NULL) == SQLITE_OK ) {
            if( sqlite3_step(deleteStmt) == SQLITE_DONE ) {
                NSLog( @"Item with url: %@ was deleted",select2.text);
            }
            else {
                NSLog( @"DeleteFromDataBase: Failed from sqlite3_step.
                Error is: %s", sqlite3_errmsg(database) );
            }
        }
        else {
            NSLog( @"DeleteFromDataBase: Failed from
            sqlite3_prepare_v2. Error is: %s", sqlite3_errmsg(database) );
        }

        // Finalize and close database.
        sqlite3_finalize(deleteStmt);
        sqlite3_close(database);
    }
    else {
        NSLog( @"DeleteFromDataBase: Error While opening database.
        Error: %s\n", sqlite3_errmsg(database) );
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)