pod 'FMDBTool'
self.databaseQueue = [TYDatebaseQueueFactory sharedDatabaseQueueWithPath:DocumentsDirectory withDatabaseName:BOOK_DB_NAME];
NSString *sqlString = [NSString stringWithFormat:@"select * from %@ order by updateTime",@"mytablename"];
NSArray *bookArray = [self executeQueryWithSql:sqlString inDatabaseQueue:self.databaseQueue itemConvertBlock:^id(FMResultSet *rs) {
TYBookShelfInfo *contentInfo = [[self class] convertResultSetToBookShelfInfo:rs];
return contentInfo;
}];
NSArray *resultArr = [self executeQueryWithUsingBlock:^FMResultSet *(FMDatabase *db){
return [db executeQuery:sql];
} inDatabaseQueue:self.databaseQueue itemConvertBlock:^id(FMResultSet *rs) {
NSInteger val = [rs intForColumn:@"dfs"];
return @(val);
}];
[self executeQueryWithSql:sql inDatabaseQueue:self.databaseQueue itemClass:[CellModel class] mappingBlock:^void(TYMappingObject *mappingObject) {
[mappingObject setColumnName:@"t_id" mappingToPorpertyName:@"tid"];
[mappingObject setColumnName:@"t_title" mappingToPorpertyName:@"title"];
[mappingObject setColumnName:@"t_count" mappingToPorpertyName:@"count"];
[mappingObject setColumnName:@"t_time" mappingToPorpertyName:@"curTime" valueBlock:^id(NSString *propertyName, id value) {
NSTimeInterval cur = 0;
if (value && [value respondsToSelector:@selector(doubleValue)]) {
cur = [value doubleValue];
}
if (cur > 0) {
return [NSDate dateWithTimeIntervalSince1970:cur];
}
return nil;
}];
}];
[self executeUpdateWithSql:sqlstr inDatabaseQueue:self.databaseQueue];
或者通过block执行更新操作
[self executeUpdateUsingBlock:^BOOL(FMDatabase*db)){
return [db executeUpdate:sql];
} inDatabaseQueue:self.databaseQueue];
NSString *updateSql = [NSString stringWithFormat:@"UPDATE %@ SET %@ = ? WHERE %@ = ?", BOOK_TABLE_4_0, BOOK_SHELF_INDEX,@"contentId"];
[self executeTransactionInDatabaseQueue:self.databaseQueue withExecuteBlock:^(FMDatabase *db){
for (int i = 0; i < bookShelfInfos.count; i++) {
TYBookShelfInfo*bookshelfInfo = [bookShelfInfos objectAtIndex:i];
BOOL b = [db executeUpdate:updateSql,@(bookshelfInfo.bookshelfIndex), bookshelfInfo.contentID];
PLog(b?@"更新顺序号成功:%@":@"更新顺序号失败:%@",updateSql);
}
}];
FMDBTool使用 MIT 许可证,详情见 LICENSE 文件。