4

I'm implementing an application for Mac OS X to easily access to SQLite databases. Since the user will be able to work on more files at the same time, I opted for a document based application.

Most books and tutorials explain how to create and read data in such a context from a file using NSData. My app, instead, should rely on the SQLite library for that purpose. What are the methods I should override in order to do this?

showerapps
  • 252
  • 2
  • 10

1 Answers1

3

Only -[NSDocument readFromURL:ofType:error:]. I suppose every change is saved automatically (SQLite), so you don't need a save action.

I have also done this and I liked it pretty much.


For example:

- (BOOL)readFromURL:(NSURL *)URL ofType:(NSString *)type error:(NSError **)error {
  if (sqlite3_open_v2([[URL path] UTF8String], &db, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK) {
    sqlite3_close(db);
    return NO;
  }
  return YES;
}
  • I realize this is a very old post, but have you had any kind of problems with SQLite file corruption caused by NSDocument doing things to your document behind your back? Does your NSDocument use a package bundle to contain the SQLite, WAL, and SHM files? – Tap Forms Nov 09 '16 at 00:49