SFSmartStoreDatabaseManager Class Reference

Inherits from NSObject
Declared in SFSmartStoreDatabaseManager.h

Overview

The NSError domain for SmartStore database errors.

Other Methods

+ sharedManager

Gets the shared instance of the database manager for the current user.

+ (SFSmartStoreDatabaseManager *)sharedManager

Declared In

SFSmartStoreDatabaseManager.h

+ sharedManagerForUser:

Gets the shared instance of the database manager for the given user.

+ (SFSmartStoreDatabaseManager *)sharedManagerForUser:(SFUserAccount *)user

Parameters

user

The user associated with the database manager.

Declared In

SFSmartStoreDatabaseManager.h

+ sharedGlobalManager

Gets the shared instance of the database manager of global stores.

+ (SFSmartStoreDatabaseManager *)sharedGlobalManager

Declared In

SFSmartStoreDatabaseManager.h

+ removeSharedManagerForUser:

Removes the shared database manager associated with the given user.

+ (void)removeSharedManagerForUser:(SFUserAccount *)user

Parameters

user

The user configured for the shared database manager.

Declared In

SFSmartStoreDatabaseManager.h

– persistentStoreExists:

Whether the store with the given name exists.

- (BOOL)persistentStoreExists:(NSString *)storeName

Parameters

storeName

The name of the store to query.

Return Value

YES if the store exists, NO otherwise.

Declared In

SFSmartStoreDatabaseManager.h

– openStoreDatabaseWithName:key:salt:error:

Creates or opens an existing store DB.

- (nullable FMDatabase *)openStoreDatabaseWithName:(NSString *)storeName key:(NSString *)key salt:(nullable NSString *)salt error:(NSError **)error

Parameters

storeName

The name of the store to create or open.

key

The encryption key associated with the store.

salt

String used when the database header is stored in plain text for Shared mode.

error

Returned if there’s an error with the process.

Return Value

The FMDatabase instance representing the DB, or nil if the create/open failed.

Declared In

SFSmartStoreDatabaseManager.h

– openStoreQueueWithName:key:salt:error:

Creates or opens an existing store DB.

- (nullable FMDatabaseQueue *)openStoreQueueWithName:(NSString *)storeName key:(NSString *)key salt:(nullable NSString *)salt error:(NSError **)error

Parameters

storeName

The name of the store to create or open.

key

The encryption key associated with the store.

salt

String used when the database header is stored in plain text for Shared mode.

error

Returned if there’s an error with the process.

Return Value

The FMDatabaseQueue instance to access the DB, or nil if the create/open failed.

Declared In

SFSmartStoreDatabaseManager.h

– encryptDb:name:key:salt:error:

Encrypts an existing unencrypted database.

- (FMDatabase *)encryptDb:(FMDatabase *)db name:(NSString *)storeName key:(NSString *)key salt:(nullable NSString *)salt error:(NSError **)error

Parameters

db

The DB to encrypt.

storeName

The name of the store representing the DB.

key

The encryption key to be used for encrypting the database.

salt

String used when the database header is stored in plain text for Shared mode.

error

Returned if there’s an error with encrypting the data.

Return Value

The newly-encrypted DB, or the original DB if the encryption fails at any point in the process.

Declared In

SFSmartStoreDatabaseManager.h

+ encryptDbWithStoreName:storePath:key:salt:error:

Encrypts an existing store

+ (BOOL)encryptDbWithStoreName:(NSString *)storeName storePath:(NSString *)storePath key:(NSString *)key salt:(nullable NSString *)salt error:(NSError **)error

Parameters

storeName

The name of the store representing the DB.

storePath

The path specifying the store location.

key

The encryption key to be used for encrypting the database.

salt

String used when the database header is stored in plain text for Shared mode.

error

Returned if there’s an error with encrypting the data.

Return Value

YES if the encryption was successful, or NO if the encryption fails at any point in the process.

Declared In

SFSmartStoreDatabaseManager.h

– unencryptDb:name:oldKey:salt:error:

Unencrypts an encrypted database, back to plaintext.

- (FMDatabase *)unencryptDb:(FMDatabase *)db name:(NSString *)storeName oldKey:(NSString *)oldKey salt:(nullable NSString *)salt error:(NSError **)error

Parameters

db

The database to unencrypt.

storeName

The name of the store associated with the DB.

oldKey

The original encryption key of the database.

salt

String used when the database header is stored in plain text for Shared mode.

error

Returned if there’s an error during the process.

Return Value

The unencrypted database, or the original encrypted database if the process fails at any point.

Declared In

SFSmartStoreDatabaseManager.h

+ unencryptDbWithStoreName:storePath:key:salt:error:

Unencrypts an encrypted store, back to plaintext.

+ (BOOL)unencryptDbWithStoreName:(NSString *)storeName storePath:(NSString *)storePath key:(NSString *)key salt:(nullable NSString *)salt error:(NSError **)error

Parameters

storeName

The name of the store associated with the DB.

storePath

The path specifying the store location.

key

The original encryption key of the database.

salt

String used when the database header is stored in plain text for Shared mode.

error

Returned if there’s an error during the process.

Return Value

YES if the existing store was successfully unencrypted, or NO if the process fails at any point.

Declared In

SFSmartStoreDatabaseManager.h

– createStoreDir:

Creates the directory for the store, on the filesystem.

- (BOOL)createStoreDir:(NSString *)storeName

Parameters

storeName

The name of the store to be created.

Return Value

YES if the call completed with no errors, NO otherwise.

Declared In

SFSmartStoreDatabaseManager.h

– protectStoreDirIfNeeded:protection:

Sets filesystem protection on the store DB file, directory and ancestor directories.

- (BOOL)protectStoreDirIfNeeded:(NSString *)storeName protection:(NSString *)protection

Parameters

storeName

The store associated with the protection.

protection

The file system protection desired.

Return Value

YES if the call completes without errors, NO otherwise.

Declared In

SFSmartStoreDatabaseManager.h

– removeStoreDir:

Removes the store directory and all of its contents from the filesystem.

- (void)removeStoreDir:(NSString *)storeName

Parameters

storeName

The store associated with the request.

Declared In

SFSmartStoreDatabaseManager.h

– allStoreNames

All of the store names associated with this application.

- (NSArray *)allStoreNames

Return Value

All of the store names associated with this application.

Declared In

SFSmartStoreDatabaseManager.h

– fullDbFilePathForStoreName:

The full filesystem path to the database with the given store name.

- (NSString *)fullDbFilePathForStoreName:(NSString *)storeName

Parameters

storeName

The name of the store (excluding paths).

Return Value

Full filesystem path for the store DB file.

Declared In

SFSmartStoreDatabaseManager.h

+ verifyDatabaseAccess:error:

Verifies that the database contents for the given DB can be read.

+ (BOOL)verifyDatabaseAccess:(FMDatabase *)dbPath error:(NSError **)error

Parameters

dbPath

The instance of the database to read.

error

The output NSError parameter that will be populated in the event of an error.

Return Value

YES if the database can be read.

Declared In

SFSmartStoreDatabaseManager.h

Extension Methods

  user

@property (nonatomic, strong) SFUserAccount *user

  isGlobalManager

@property (nonatomic, assign) BOOL isGlobalManager

– storeDirectoryForStoreName:

The name of the store.

- (NSString *)storeDirectoryForStoreName:(NSString *)storeName

Parameters

storeName

The name of the store.

Return Value

The filesystem diretory containing for the given store name

Declared In

SFSmartStoreDatabaseManager+Internal.h

– rootStoreDirectory

The root directory where all the SmartStore DBs live.

- (NSString *)rootStoreDirectory

Return Value

The root directory where all the SmartStore DBs live.

Declared In

SFSmartStoreDatabaseManager+Internal.h

– encryptOrUnencryptDb:name:oldKey:newKey:salt:error:

- (FMDatabase *)encryptOrUnencryptDb:(FMDatabase *)db name:(NSString *)storeName oldKey:(NSString *)oldKey newKey:(NSString *)newKey salt:(NSString *)salt error:(NSError **)error

+ openDatabaseWithPath:key:salt:error:

+ (FMDatabase *)openDatabaseWithPath:(NSString *)dbPath key:(NSString *)key salt:(NSString *)salt error:(NSError **)error

+ encryptOrUnencryptDb:name:path:oldKey:newKey:salt:error:

+ (FMDatabase *)encryptOrUnencryptDb:(FMDatabase *)db name:(NSString *)storeName path:(NSString *)storePath oldKey:(NSString *)oldKey newKey:(NSString *)newKey salt:(NSString *)salt error:(NSError **)error