小编Ale*_*u D的帖子

Cordova使用事务将大文件导入数据库

我有一个大约17 MB的txt文件,我必须解析,逐行拆分,然后使用事务将其添加到数据库中.如果文件太大而我尝试打开它,应用程序将耗尽内存,所以我尝试将其分片读取然后将每个片段导入数据库.由于交易,在DB中输入的数据不正确.使用的代码有一部分:

await file_reader.resolveLocalFilesystemUrl(path + file).then(async (file_entry: any) => {

  await file_entry.file(async (file) => {

    let reader = new FileReader();

     reader.onprogress = async (reader_result: any) => {

       let loaded = _.cloneDeep(reader_result.loaded);
       let total = _.cloneDeep(reader_result.total);
       let is_last_element: boolean = _.cloneDeep(loaded == total);
       let i: number = 0;
       let document_length = this.sync_parser.getReaderLength();
       let event_type: number = this.sync_parser.getEventType();

       content = iconv.encode(reader.result, encoding).toString();

       await this.db.db.transaction(async (database: any) => {
         while (document_length >= i) {
           if (event_type == SyncParserIo.START_TAG) {
             this.table = await this.newHeader(this.sync_parser.getName()); …
Run Code Online (Sandbox Code Playgroud)

sql transactions cordova typescript ionic-framework

5
推荐指数
1
解决办法
52
查看次数

标签 统计

cordova ×1

ionic-framework ×1

sql ×1

transactions ×1

typescript ×1