Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

update sqlite databse from a remotely hosted db

$
0
0

i have a sqlite db which comes with the app that holds 6 tables, installing on first use is no problem but i'd like to be able to have a system where the user can update the db without me having to do an app update to itunes (i'll worry about android version once i've sussed this part)

ideally i'd like to be able to just update the tables individually - i can do this on one of the sqlite dbs as it only has one table and a small number of columns using a delete and replace eg:

function getUpdate(page){
    var xhr = Titanium.Network.createHTTPClient();
    xhr.timeout = 1000000;
    xhr.onerror = function(e){
        // if something goes worng
    };
 
    xhr.onload = function(){
 
var jsonObject = JSON.parse(this.responseText);
        var db = Ti.Database.open('stations');
        db.execute('DELETE FROM stations');
 
        for (var i = 0; i < jsonObject.length; i++) {
 
            var aa = jsonObject[i].id;
            var bb = jsonObject[i].version;
            var cc = jsonObject[i].trackid;
            var dd = jsonObject[i].name;
            var ee = jsonObject[i].alias;
            var ff = jsonObject[i].stream;
            var gg = jsonObject[i].logo;
            var hh = jsonObject[i].tag;
            var ii = jsonObject[i].comment1;
            var jj = jsonObject[i].comment2;
 
            var rs = db.execute('REPLACE INTO stations (id,version,trackid,name,alias,stream,logo,tag,comment1,comment2) \
            VALUES (?,?,?,?,?,?,?,?,?,?)', aa, bb, cc, dd, ee, ff, gg, hh, ii,jj);
        }
        db.close();
    };
 
    var endPoint = 'http://foo/update.php';
 
    xhr.open('GET',endPoint);
    xhr.send();
}
where update.php queries the mysql db and creates a json array

the problem is that the table i want to update has nearly 200 unique column names, which i obviously don't want to have to type out as above

i have tried this i found but i just get the error info on the device

update.addEventListener('click',function(){
 
     Ti.API.info("update clicked");
 
    var xhr = Ti.Network.createHTTPClient({
    onload: function() {
        var db = Ti.Database.install('update.sqlite','dbname');
        var file = db.getFile();
        db.close();
        file.write(this.responseData);
        var db = Ti.Database.install('update.sqlite','dbname);
        db.close();
 
        Ti.API.info("update installed?");
 
    },
    onerror: function() {
        Ti.API.info("error update");
    },
    timeout: 5000
});
 
xhr.open("GET", "http://foo.com//update.sqlite");
xhr.send();
 
    });
any ideas - to simply get at least the main db updated before i worry about updating a table within the sqlite db - (if this makes sense ? :)

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>