views:

145

answers:

1

I am programming an Xcode iPhone app and utilizing sqlite. In an effort to delete all rows from a table, I receive the warning above when I build my code. Does anyone have any suggestions on how to fix this? Thanks

- (void) deleteData {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory
                                stringByAppendingPathComponent:@"myDatabase.sqlite"];
    if (sqlite3_open([writableDBPath UTF8String], &database) == SQLITE_OK) {

    [database executeNonQuery:@"DELETE FROM test;"];
    }

    [database release];

}
+1  A: 

Assuming

sqlite3 *database;

somewhere all up ins, it should be noted that sqlite3_open() doesn't create an Objective-C object; it creates an sqlite3 database handle, which is, if memory serves, a struct packed in a pointer. It can, in other words, not receive Objective-C messages. * does not an object make.

Williham Totland
Ok, do you have any idea on how this code should be modified so that I can communicate with the object to delete the records from the table?
Leland usher
You'll need to use the C API for SQLite and generate the appropriate SQL statements. For tutorials on how to do this, see http://www.mobileorchard.com/iphone-sqlite-tutorials-and-libraries/ . If you really want to handle this in an object-oriented fashion, I highly recommend using Core Data instead of bare SQLite.
Brad Larson