Reham
Reham

Reputation: 1986

Error: attempt to write a readonly database in sql 3 for IPhone

I'm trying to update values in SQL3 Database in my Iphone Application. But it keeps showing me this Error: Error: attempt to write a readonly database Any Help??

This is the update code:

  - (void)updateAlarms:(AlarmsBean *)todoItem//TodoItem: (AlarmsBean*)todoItem
  {
NSLog(@"UPDATE");
if (updateAlarmsStatement == NULL)
{
    NSLog(@"updateAlarmsStatement == NULL ");
    sqlite3_prepare_v2(database, 
                       "UPDATE T1 SET A2 = ?, A3 = ?, A4 = ? , A5 = ? , A6 = ? , A7 = ?    WHERE A1 = 1",
                       -1, 
                       &updateAlarmsStatement, 
                       NULL);
    NSLog(@"updateAlarmsStatement == NULL ");
}
if (updateAlarmsStatement == NULL)
{
    NSLog(@"AHMAD updateAlarmsStatement == NULL ");


}
NSLog(@"after if  ");
sqlite3_reset(updateAlarmsStatement);
sqlite3_bind_text(updateAlarmsStatement, 1, [todoItem.AA2 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(updateAlarmsStatement, 2, todoItem.AA3);
sqlite3_bind_text(updateAlarmsStatement, 3, [todoItem.AA4 UTF8String], -1, SQLITE_TRANSIENT);

sqlite3_bind_int(updateAlarmsStatement, 4, todoItem.AA5);

sqlite3_bind_text(updateAlarmsStatement, 5, [todoItem.AA6 UTF8String], -1, SQLITE_TRANSIENT);

sqlite3_bind_int(updateAlarmsStatement, 6, todoItem.AA7);
sqlite3_bind_int(updateAlarmsStatement, 7, todoItem.AA1);
sqlite3_step(updateAlarmsStatement);


if(sqlite3_step(updateAlarmsStatement) != SQLITE_DONE ) {
    NSLog( @"Save Error: %s", sqlite3_errmsg(database) );
}
else {
    sqlite3_reset(updateAlarmsStatement);
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Record update" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    alert = nil;

}

}

Upvotes: 0

Views: 1026

Answers (1)

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

you need to copy your database file to document directory and use it from there before making any write attempts. you cannot write to any object in your application resources.

please check if you are doing so..

Upvotes: 2

Related Questions