Skip to content

Commit

Permalink
Merge pull request #34 from Corotata/master
Browse files Browse the repository at this point in the history
添加了数据库支持指定文件路径,满足多用户多库的文件层级结构
  • Loading branch information
casatwy authored Jul 20, 2016
2 parents 8fdabfc + a0cb819 commit a6b5205
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CTPersistance/CTPersistance/Database/CTPersistanceDataBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ - (instancetype)initWithDatabaseName:(NSString *)databaseName error:(NSError *__
self.databaseName = databaseName;
self.databaseFilePath = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:databaseName];

BOOL isFileExists = [[NSFileManager defaultManager] fileExistsAtPath:self.databaseFilePath];
NSString *checkFilePath = [self.databaseFilePath stringByDeletingLastPathComponent];
NSFileManager *defaultFileManager = [NSFileManager defaultManager];
if (![defaultFileManager fileExistsAtPath:checkFilePath]) {
[defaultFileManager createDirectoryAtPath:checkFilePath withIntermediateDirectories:YES attributes:nil error:nil];
}

BOOL isFileExists = [defaultFileManager fileExistsAtPath:self.databaseFilePath];

const char *path = [self.databaseFilePath UTF8String];
int result = sqlite3_open_v2(path, &_database,
Expand Down
5 changes: 5 additions & 0 deletions CTPersistance/Test/TestModel/Table/TestTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ - (NSString *)tableName

- (NSString *)databaseName
{
//you can use like:
return @"testdatabase.sqlite";

//Or
//return @"User/Shopping/testdatabase.sqlite";

}

- (NSDictionary *)columnInfo
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ go to `Build Phases` and add `sqlite3` into your library list.
#pragma mark - CTPersistanceTableProtocol
- (NSString *)databaseName
{
return @"TestDataBase.sqlite";
//you can use like:
return @"testdatabase.sqlite";

//Or
//return @"User/Shopping/testdatabase.sqlite";
}

- (NSString *)tableName
Expand Down

0 comments on commit a6b5205

Please sign in to comment.