|
|
@@ -20,6 +20,7 @@
|
|
|
@implementation FMDatabaseQueue
|
|
|
|
|
|
@synthesize path = _path;
|
|
|
+@synthesize openFlags = _openFlags;
|
|
|
|
|
|
+ (instancetype)databaseQueueWithPath:(NSString*)aPath {
|
|
|
|
|
|
@@ -30,7 +31,16 @@ + (instancetype)databaseQueueWithPath:(NSString*)aPath {
|
|
|
return q;
|
|
|
}
|
|
|
|
|
|
-- (instancetype)initWithPath:(NSString*)aPath {
|
|
|
++ (instancetype)databaseQueueWithPath:(NSString*)aPath flags:(int)openFlags {
|
|
|
+
|
|
|
+ FMDatabaseQueue *q = [[self alloc] initWithPath:aPath flags:openFlags];
|
|
|
+
|
|
|
+ FMDBAutorelease(q);
|
|
|
+
|
|
|
+ return q;
|
|
|
+}
|
|
|
+
|
|
|
+- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags {
|
|
|
|
|
|
self = [super init];
|
|
|
|
|
|
@@ -39,7 +49,11 @@ - (instancetype)initWithPath:(NSString*)aPath {
|
|
|
_db = [FMDatabase databaseWithPath:aPath];
|
|
|
FMDBRetain(_db);
|
|
|
|
|
|
+#if SQLITE_VERSION_NUMBER >= 3005000
|
|
|
+ if (![_db openWithFlags:openFlags]) {
|
|
|
+#else
|
|
|
if (![_db open]) {
|
|
|
+#endif
|
|
|
NSLog(@"Could not create database queue for path %@", aPath);
|
|
|
FMDBRelease(self);
|
|
|
return 0x00;
|
|
|
@@ -48,11 +62,18 @@ - (instancetype)initWithPath:(NSString*)aPath {
|
|
|
_path = FMDBReturnRetained(aPath);
|
|
|
|
|
|
_queue = dispatch_queue_create([[NSString stringWithFormat:@"fmdb.%@", self] UTF8String], NULL);
|
|
|
+ _openFlags = openFlags;
|
|
|
}
|
|
|
|
|
|
return self;
|
|
|
}
|
|
|
|
|
|
+- (instancetype)initWithPath:(NSString*)aPath {
|
|
|
+
|
|
|
+ // default flags for sqlite3_open
|
|
|
+ return [self initWithPath:aPath flags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE];
|
|
|
+}
|
|
|
+
|
|
|
- (void)dealloc {
|
|
|
|
|
|
FMDBRelease(_db);
|
|
|
@@ -81,7 +102,11 @@ - (FMDatabase*)database {
|
|
|
if (!_db) {
|
|
|
_db = FMDBReturnRetained([FMDatabase databaseWithPath:_path]);
|
|
|
|
|
|
- if (![_db open]) {
|
|
|
+#if SQLITE_VERSION_NUMBER >= 3005000
|
|
|
+ if (![_db openWithFlags:_openFlags]) {
|
|
|
+#else
|
|
|
+ if (![db open])
|
|
|
+#endif
|
|
|
NSLog(@"FMDatabaseQueue could not reopen database for path %@", _path);
|
|
|
FMDBRelease(_db);
|
|
|
_db = 0x00;
|