Deleting data from SQLite3 iPhone SDK?

Hey, How can I delete data from SQLite3 iPhone SDK? I am able to insert data into the database by using this code:

-(void)insertRecordIntoTableNamed:(NSString *)tableName
                   withField1:(NSString *)field1
                  field1Value:(NSString*)field1Value
                    andField2:(NSString *)field2
                  field2Value:(NSString *)field2Value
{
    NSString *sql = [NSString stringWithFormat:@"INSERT OR REPLACE INTO '%@' ('%@' , '%@')     VALUES ('%@','%@')",tableName,field1,field2, field1Value,field2Value];
    char *err;      
    if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
        sqlite3_close(db);
        NSAssert(0,@"error updating table.");
    }
} 

I think I have to change something in NSString *sql but I can't figure out what do I have to change it to.

Thanks.

Answers


You need to use an SQL DELETE statement:

NSString *sql = [NSString stringWithFormat:@"DELETE FROM '%@' WHERE '%@' = '%@'", tableName, field1, field1Value];

The WHERE clause, of course, depends on what you want to delete from tableName.


Need Your Help

downloading a file from a web directory

php security http authentication .htaccess

i have a form which allows the user to upload some files to a folder.

Counting objects in an array (Javascript)

javascript arrays

I have an array made of unlimited number of objects. These objects have the same structure. If I console.log my whole array I get something like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.