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

批量插入数组model的时候,下面的方法放在子线程就OK了 #1

Open
zjjzmw1 opened this issue Mar 8, 2017 · 4 comments

Comments

@zjjzmw1
Copy link

zjjzmw1 commented Mar 8, 2017

  • (void)fl_insertModelArr:(NSArray *)modelArr autoCloseDB:(BOOL)autoCloseDB complete:(void(^)(FLFMDBQueueManager *manager, BOOL flag))complete{
    __block BOOL success = true;
    __weak typeof(self) weakSelf = self;
    FLDISPATCH_ASYNC_GLOBAL(^{
    __strong typeof(weakSelf) strongSelf = weakSelf;
    //把任务包装到事务里
    [FLCURRENTDBQUEUE inTransaction:^(FMDatabase *db, BOOL *rollback){
    success = [strongSelf fl_insert:db modelArr:modelArr autoCloseDB:YES];
    complete(strongSelf,success);
    //如果有错误 返回
    if (!success){
    *rollback = YES;
    return;
    }
    }];
    });
    }
@gitkong
Copy link
Owner

gitkong commented Mar 9, 2017

是在子线程处理的FLDISPATCH_ASYNC_GLOBAL

@zjjzmw1
Copy link
Author

zjjzmw1 commented Mar 9, 2017

这个FLDISPATCH_ASYNC_GLOBAL 是我给你添加的,你的代码没有这句

@gitkong
Copy link
Owner

gitkong commented Mar 10, 2017

😯谢谢~

@PengJiang520
Copy link

这边插入数据库的时候是必须添加FLDBID这个字段的吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants