简体   繁体   English

使用来自科尔多瓦服务器的大型json数据将数据插入android sqlite数据库的最佳方法

[英]best way to insert data into android sqlite database using large json data coming from server using cordova

I am new to Cordova. 我是科尔多瓦的新手。 I am working on a hybrid app(Targeting Android OS) where on request database tables are populated from the json data coming from the server. 我正在开发一个混合应用程序(Targeting Android OS),其中应要求的数据库表是根据来自服务器的json数据填充的。

Now my problem is when the json data was lesser, insertion was faster. 现在我的问题是当json数据较少时,插入速度更快。 Now the JSON data size is around 40MB which i am sending from the server in Gzip format, so the device is able to download the json data faster, but it is taking a lot of time to insert the data into the database tables, even sometimes it hangs. 现在,我以Gzip格式从服务器发送的JSON数据大小约为40MB,因此该设备能够更快地下载json数据,但是将数据插入数据库表中需要花费很多时间,甚至有时它挂了。

Sometimes device closes the application while inserting data into the sqlite database. 有时设备在将数据插入sqlite数据库时关闭应用程序。 I think, the insertion is taking a lot of memory which crashes the app. 我认为插入操作会占用大量内存,导致应用崩溃。

var tx = window.sqlitePlugin.openDatabase({ name: "database_name.db" });


tx.transaction(function(db) {
    $.each(result[i],function(j,field){
        var insert_gen_code_desc = "insert or replace  into  table-name ( id , pk_code_group , pk_code , description , created_by , created_on , updated_by , updated_on , last_update , status , lastupdate , sl_no, upload_status ) values ("+result[i][j][0]['id']+",'"+result[i][j][0]['pk_code_group']+"','"+result[i][j][0]['pk_code']+"','"+result[i][j][0]['description']+"','"+result[i][j][0]['created_by']+"','"+result[i][j][0]['created_on']+"','"+result[i][j][0]['updated_by']+"','"+result[i][j][0]['updated_on']+"',"+result[i][j][0]['last_update']+",'"+result[i][j][0]['STATUS']+"','"+result[i][j][0]['lastupdate']+"',"+result[i][j][0]['sl_no']+",'0')";
db.executeSql(insert_gen_code_desc);
});
},errorCallback, successCallback);

Can someone tell me what i am doing wrong because of which my app is getting crashed while inserting large amount of data into the table or suggest me some way for faster insertion using less memory(RAM). 有人可以告诉我我在做什么错,因为在向表中插入大量数据时我的应用程序崩溃了,还是可以建议我用更少的内存(RAM)更快地插入。

Note: I am using com.brodysoft.sqlitePlugin plugin for sqlite database operations. 注意:我正在使用com.brodysoft.sqlitePlugin插件进行sqlite数据库操作。

This is a known limitation. 这是一个已知的限制。 The version at https://github.com/litehelpers/Cordova-sqlite-enterprise-free (which has a different licensing scheme) can handle larger transactions. https://github.com/litehelpers/Cordova-sqlite-enterprise-free上的版本(具有不同的许可方案)可以处理更大的交易。 As a workaround, you can simply store the data using smaller, multiple transactions. 解决方法是,您可以使用较小的多个事务简单地存储数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM