diff options
author | August Mueller <gus@flyingmeat.com> | 2015-06-17 19:52:17 +0300 |
---|---|---|
committer | August Mueller <gus@flyingmeat.com> | 2015-06-17 19:52:17 +0300 |
commit | d0c9dafb9ff40a4eda1617da03c86b4783dcc22d (patch) | |
tree | eb91b73167098fc9f3ea0c01df17eb0534e0932d | |
parent | 12ac4595bc62927b75ade01144e3ae7c7dedbac4 (diff) | |
parent | ca28671462522ab4d2479313f65c86747fe87ff3 (diff) |
Merge branch 'master' of git://github.com/sechel/fmdb into sechel-master
-rw-r--r-- | Tests/FMDatabaseTests.m | 19 | ||||
-rw-r--r-- | fmdb.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme | 96 | ||||
-rw-r--r-- | src/fmdb/FMDatabase.h | 5 | ||||
-rw-r--r-- | src/fmdb/FMDatabase.m | 5 | ||||
-rw-r--r-- | src/fmdb/FMDatabaseQueue.h | 11 | ||||
-rw-r--r-- | src/fmdb/FMDatabaseQueue.m | 10 |
6 files changed, 141 insertions, 5 deletions
diff --git a/Tests/FMDatabaseTests.m b/Tests/FMDatabaseTests.m index 8cb54e7..461acba 100644 --- a/Tests/FMDatabaseTests.m +++ b/Tests/FMDatabaseTests.m @@ -68,6 +68,25 @@ } +- (void)testOpenWithVFS +{ + // create custom vfs + sqlite3_vfs vfs = *sqlite3_vfs_find(NULL); + vfs.zName = "MyCustomVFS"; + XCTAssertEqual(SQLITE_OK, sqlite3_vfs_register(&vfs, 0)); + // use custom vfs to open a in memory database + FMDatabase *db = [[FMDatabase alloc] initWithPath:@":memory:"]; + [db openWithFlags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE vfs:@"MyCustomVFS"]; + XCTAssertFalse([db hadError], @"Open with a custom VFS should have succeeded"); +} + +- (void)testFailOnOpenWithUnknownVFS +{ + FMDatabase *db = [[FMDatabase alloc] initWithPath:@":memory:"]; + [db openWithFlags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE vfs:@"UnknownVFS"]; + XCTAssertTrue([db hadError], @"Should have failed"); +} + - (void)testFailOnUnopenedDatabase { [self.db close]; diff --git a/fmdb.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/fmdb.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme new file mode 100644 index 0000000..23ed8cf --- /dev/null +++ b/fmdb.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Scheme + LastUpgradeVersion = "0630" + version = "1.3"> + <BuildAction + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + <BuildActionEntries> + <BuildActionEntry + buildForTesting = "YES" + buildForRunning = "YES" + buildForProfiling = "NO" + buildForArchiving = "NO" + buildForAnalyzing = "YES"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "BF5D041518416BB2008C5AA9" + BuildableName = "Tests.xctest" + BlueprintName = "Tests" + ReferencedContainer = "container:fmdb.xcodeproj"> + </BuildableReference> + </BuildActionEntry> + </BuildActionEntries> + </BuildAction> + <TestAction + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + shouldUseLaunchSchemeArgsEnv = "YES" + buildConfiguration = "Debug"> + <Testables> + <TestableReference + skipped = "NO"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "BF5D041518416BB2008C5AA9" + BuildableName = "Tests.xctest" + BlueprintName = "Tests" + ReferencedContainer = "container:fmdb.xcodeproj"> + </BuildableReference> + </TestableReference> + </Testables> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "BF5D041518416BB2008C5AA9" + BuildableName = "Tests.xctest" + BlueprintName = "Tests" + ReferencedContainer = "container:fmdb.xcodeproj"> + </BuildableReference> + </MacroExpansion> + </TestAction> + <LaunchAction + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + launchStyle = "0" + useCustomWorkingDirectory = "NO" + buildConfiguration = "Debug" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + allowLocationSimulation = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "BF5D041518416BB2008C5AA9" + BuildableName = "Tests.xctest" + BlueprintName = "Tests" + ReferencedContainer = "container:fmdb.xcodeproj"> + </BuildableReference> + </MacroExpansion> + <AdditionalOptions> + </AdditionalOptions> + </LaunchAction> + <ProfileAction + shouldUseLaunchSchemeArgsEnv = "YES" + savedToolIdentifier = "" + useCustomWorkingDirectory = "NO" + buildConfiguration = "Release" + debugDocumentVersioning = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "BF5D041518416BB2008C5AA9" + BuildableName = "Tests.xctest" + BlueprintName = "Tests" + ReferencedContainer = "container:fmdb.xcodeproj"> + </BuildableReference> + </MacroExpansion> + </ProfileAction> + <AnalyzeAction + buildConfiguration = "Debug"> + </AnalyzeAction> + <ArchiveAction + buildConfiguration = "Release" + revealArchiveInOrganizer = "YES"> + </ArchiveAction> +</Scheme> diff --git a/src/fmdb/FMDatabase.h b/src/fmdb/FMDatabase.h index 1ddfa79..1aec77d 100644 --- a/src/fmdb/FMDatabase.h +++ b/src/fmdb/FMDatabase.h @@ -194,7 +194,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary - (BOOL)open; -/** Opening a new database connection with flags +/** Opening a new database connection with flags and an optional virtual file system (VFS) @param flags one of the following three values, optionally combined with the `SQLITE_OPEN_NOMUTEX`, `SQLITE_OPEN_FULLMUTEX`, `SQLITE_OPEN_SHAREDCACHE`, `SQLITE_OPEN_PRIVATECACHE`, and/or `SQLITE_OPEN_URI` flags: @@ -210,6 +210,8 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary The database is opened for reading and writing, and is created if it does not already exist. This is the behavior that is always used for `open` method. + If vfs is given the value is passed to the vfs parameter of sqlite3_open_v2. + @return `YES` if successful, `NO` on error. @see [sqlite3_open_v2()](http://sqlite.org/c3ref/open.html) @@ -219,6 +221,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary #if SQLITE_VERSION_NUMBER >= 3005000 - (BOOL)openWithFlags:(int)flags; +- (BOOL)openWithFlags:(int)flags vfs:(NSString *)vfsName; #endif /** Closing a database connection diff --git a/src/fmdb/FMDatabase.m b/src/fmdb/FMDatabase.m index a8678e9..9169554 100644 --- a/src/fmdb/FMDatabase.m +++ b/src/fmdb/FMDatabase.m @@ -151,11 +151,14 @@ #if SQLITE_VERSION_NUMBER >= 3005000 - (BOOL)openWithFlags:(int)flags { + return [self openWithFlags:flags vfs:nil]; +} +- (BOOL)openWithFlags:(int)flags vfs:(NSString *)vfsName; { if (_db) { return YES; } - int err = sqlite3_open_v2([self sqlitePath], &_db, flags, NULL /* Name of VFS module to use */); + int err = sqlite3_open_v2([self sqlitePath], &_db, flags, [vfsName UTF8String]); if(err != SQLITE_OK) { NSLog(@"error opening!: %d", err); return NO; diff --git a/src/fmdb/FMDatabaseQueue.h b/src/fmdb/FMDatabaseQueue.h index 34c0750..82d4586 100644 --- a/src/fmdb/FMDatabaseQueue.h +++ b/src/fmdb/FMDatabaseQueue.h @@ -117,6 +117,17 @@ - (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags; +/** Create queue using path and specified flags. + + @param aPath The file path of the database. + @param openFlags Flags passed to the openWithFlags method of the database + @param vfsName The name of a custom virtual file system + + @return The `FMDatabaseQueue` object. `nil` on error. + */ + +- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName; + /** Returns the Class of 'FMDatabase' subclass, that will be used to instantiate database object. Subclasses can override this method to return specified Class of 'FMDatabase' subclass. diff --git a/src/fmdb/FMDatabaseQueue.m b/src/fmdb/FMDatabaseQueue.m index ccf31fb..3cdecdc 100644 --- a/src/fmdb/FMDatabaseQueue.m +++ b/src/fmdb/FMDatabaseQueue.m @@ -51,7 +51,7 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey return [FMDatabase class]; } -- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags { +- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName { self = [super init]; @@ -61,7 +61,7 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey FMDBRetain(_db); #if SQLITE_VERSION_NUMBER >= 3005000 - BOOL success = [_db openWithFlags:openFlags]; + BOOL success = [_db openWithFlags:openFlags vfs:vfsName]; #else BOOL success = [_db open]; #endif @@ -81,10 +81,14 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey return self; } +- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags { + return [self initWithPath:aPath flags:openFlags vfs:nil]; +} + - (instancetype)initWithPath:(NSString*)aPath { // default flags for sqlite3_open - return [self initWithPath:aPath flags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE]; + return [self initWithPath:aPath flags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE vfs:nil]; } - (instancetype)init { |