Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone sqlite3 locked, can only read, not write
    text
    copied!<p>So I have been working on this project for a short while now. I have no problems with reading data from the DB, and formatting it into UITableViews and what not. But now I am wanting also to write to the DB as well. The problem is I keep getting a "Database is Locked" error from sqlite. After messing around with the original version I had the face-palm moment by realizing my database was in the bundle and therefore not writable. So I relocated the DB to the Apps Documents folder, which is writeable. But now I still get the same "Database is Locked" sql error. I only open and close the DB when necessary. And as far as I can tell, I don't leave it open anywhere. Below is the code where I am wanting to do updates. Any thoughts?</p> <pre><code> - (BOOL) loanBookTo:(NSString *)newborrower{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"books.sqlite"]; if([[NSFileManager defaultManager] fileExistsAtPath:path]){ NSLog(@"File Exists at: %@", path); } if (sqlite3_open([path UTF8String], &amp;database) == SQLITE_OK) { NSString *mySQL = @"UPDATE BOOKS SET LOANED = 1, BORROWER = \"&lt;BORROWER&gt;\" where ISBN = \"&lt;ISBN&gt;\""; mySQL = [mySQL stringByReplacingOccurrencesOfString:@"&lt;ISBN&gt;" withString:self.isbn]; mySQL = [mySQL stringByReplacingOccurrencesOfString:@"&lt;BORROWER&gt;" withString:newborrower]; const char *sql = [mySQL UTF8String]; char* errmsg; sqlite3_exec(database, sql, NULL, NULL, &amp;errmsg); // Q. Database is locked. Why? // A. Because it is in the Bundle and is ReadOnly. // Need to write a copy to the Doc folder. // Database is Locked error gets spit out here. printf(errmsg); sqlite3_close(database); } return NO; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload