Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加了数据库支持指定文件路径,满足多用户多库的文件层级结构 #34

Merged
merged 3 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -47,7 +47,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