Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Delete/Drop Database

I have an app with an local database. It checks an remote server and downloads an newer database file if the remote one is newer.
But now i need to use the new one. So i would like to drop the already installed one or force using the new one when using the Database.install call. How can i do this?

— asked March 17th 2010 by Jan Renz
  • database
  • mobile
0 Comments

5 Answers

  • So you just need to know how to drop the DB, or you need to check to see if the downloaded db is newer?

    sqlite drop example:
    db.execute("DROP TABLE IF EXISTS mydb");

    — answered March 17th 2010 by rob rhyne
    permalink
    0 Comments
  • Yeah but i would like to drop the complete database. I already checked the source code, and this function is the in the core but it seems you cant access it through the API..

    I guess this should be on the wish list for a future release..

    — answered March 18th 2010 by Jan Renz
    permalink
    0 Comments
  • Jan,
    Did you find out how to drop the DB? I'd like to do the same thing. I tried the sqlite example from Rob, but that gives me a syntax error in Titanium mobile.

    — answered March 23rd 2010 by Bruce Martin
    permalink
    0 Comments
  • How's this? (Android)

    var f = Titanium.Filesystem.getFile('file:///data/data/' + Ti.App.getID() + '/databases', db_name);
    f.deleteFile();

    — answered June 27th 2011 by Kaori Furihata
    permalink
    0 Comments
  • You should put a table in the database with a versionnumber, and compare the versionnumber of the database with the versionnumber of the remote server.

    Not tested, but I think it should be something like this:

    var db = Ti.Database.open('database');
    var dbCheck = db.execute('SELECT id, version FROM dbcheck WHERE id=?',1);
    
    while (dbCheck.isValidRow()){
        var dbId = dbCheck.fieldByName('id');
        var dbControle = dbCheck.fieldByName('version');
    
        if (dbControle < VERSIONNUMER_OF_REMOTE_SERVER){
        var outofdate = true;
        } else {
        var outofdate = false;
        };
        dbCheck.next();
    };
    dbCheck.close();
    
    if(outofdate == true){
    //delete old database code here
    //install new database code here
    };
    

    Let us know if it worked

    — answered January 9th 2013 by Jesse R
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.