Skip to content

Commit

Permalink
Merge pull request #29 from zhenian/master
Browse files Browse the repository at this point in the history
support drop table
  • Loading branch information
tangqiaoboy committed Aug 15, 2016
2 parents be23a3c + e89c525 commit 7ac052d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions YTKKeyValueStore/YTKKeyValueStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

- (void)clearTable:(NSString *)tableName;

- (void)dropTable:(NSString *)tableName;

- (void)close;

///************************ Put&Get methods *****************************************
Expand Down
16 changes: 16 additions & 0 deletions YTKKeyValueStore/YTKKeyValueStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ PRIMARY KEY(id)) \

static NSString *const DELETE_ITEMS_WITH_PREFIX_SQL = @"DELETE from %@ where id like ? ";

static NSString *const DROP_TABLE_SQL = @" DROP TABLE '%@' ";

+ (BOOL)checkTableName:(NSString *)tableName {
if (tableName == nil || tableName.length == 0 || [tableName rangeOfString:@" "].location != NSNotFound) {
debugLog(@"ERROR, table name: %@ format error.", tableName);
Expand Down Expand Up @@ -144,6 +146,20 @@ - (void)clearTable:(NSString *)tableName {
}
}

- (void)dropTable:(NSString *)tableName {
if ([YTKKeyValueStore checkTableName:tableName] == NO) {
return;
}
NSString * sql = [NSString stringWithFormat:DROP_TABLE_SQL, tableName];
__block BOOL result;
[_dbQueue inDatabase:^(FMDatabase *db) {
result = [db executeUpdate:sql];
}];
if (!result) {
debugLog(@"ERROR, failed to drop table: %@", tableName);
}
}

- (void)putObject:(id)object withId:(NSString *)objectId intoTable:(NSString *)tableName {
if ([YTKKeyValueStore checkTableName:tableName] == NO) {
return;
Expand Down

0 comments on commit 7ac052d

Please sign in to comment.