Zhong Liu
Posts: 0
Joined: Tue Jun 17, 2014 3:27 am

how to submit data in SQLite to online database

Hello,
In my app, users may use it to capture photo even when there is no network connection, the data is stored in local SQLite, I need write a backend process on mobile device to search those data to be submitted, and submitted them when the network connection is available.
Could someone give me an example code to achieve this? Thank you.

Zhong Liu
Posts: 0
Joined: Tue Jun 17, 2014 3:27 am

how to submit data in SQLite to online database

I will try it, thank you, Evgene.

Nathan Morin
Posts: 0
Joined: Thu Sep 05, 2013 6:12 am

how to submit data in SQLite to online database

Hi Evgene-

How does that tutorial (from your link) work with SQLite? I have a SQLite database that I need to push the cloud database like Zhong Liu. I am having trouble using that tutorial to do so. Can you help?

Cheers,

Nathan

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

how to submit data in SQLite to online database

That link does not use the SQLite, but stores the information in localStorage (HTML5). But you can use the same code, with some adjustments to make it work with SQLite:

precode
// Start synchronization of tasks with cloud
function startSynchronization() {
var isOnline = localStorage.getItem('_isOnline');
if (isOnline == 1) {
var task;

Code: Select all

     // Deleting 
     var tasks = localStorage.getItem('_tasksToDelete'); 
     if (tasks) { 
         var tasksArr = eval('([' + tasks + '])'); 
         while (tasksArr.length) { 
             task = tasksArr.shift(); 
             if (task.id) { 
                 delete_service.execute({data:{object_id: task.id}}); 
             } 
         } 
         localStorage.setItem('_tasksToDelete', ''); 
     } 

     // Creating 
     tasks = localStorage.getItem('_tasksToCreate'); 
     if (tasks) { 
         var tasksArr1 = eval('([' + tasks + '])'); 
         while (tasksArr.length) { 
             task = tasksArr.shift(); 
             if (task.name) { 
                 create_service.execute({data:{task: task.name}}); 
             } 
         } 
         localStorage.setItem('_tasksToCreate', ''); 
     } 
 } 
 listServiceExecute(); 

}
/code/pre

Using the above, you would collect all info within the SQLite database into an array and sync it with the Cloud. Instead of using the JSON.

This link should help with creating the database :)

http://docs.phonegap.com/en/3.1.0/cor...

Nathan Morin
Posts: 0
Joined: Thu Sep 05, 2013 6:12 am

how to submit data in SQLite to online database

Thanks for the response. I asked my question after successfully creating an SQLite database and trying to use the code above. So I am looking for more than what was posted.

You mentioned "with some adjustments to make it work with SQLite" and this is what I am stuck on.

However, I would like to create service that pushes data from the SQLite database to the cloud. I am able to do the reverse. That is I am able to populate the local SQLite database with entries from the cloud. Now I would like to push new entires made to the SQLite database to the cloud. Do you know how I would do this?

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

how to submit data in SQLite to online database

You would use the code above, but instead of coming from the localStorage, you would get the data from the SQLite, put it into a object (JSON). Create the services to amend, remove, and add records.

All you are doing is replacing the localStorage variable with the JSON object you receive from the SQLite. That is the adjustment. I do not know your data layout, but within the local database, you would have tables to remove, amend and create, and within each you would have the needed data. create the functions like the link above, and cycle through the JSON Object, instead of the object stored in localStorage in that example.

Return to “Issues”