Titanium Community Questions & Answer Archive

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

From PhoneGap to Titanium Mobile

Hello,

i created my first app in the beginning of 2010 with PhoneGap and local SQLite Database. Now i want to make an update for this App with Titanium Mobile. Is there a solutions to use the SQLite Database from the installed old app and merge it to the new version of the app. I want to use the same App ID, so the user can comfortable update the app.

Best regards

Thorsten

— asked November 19th 2010 by Thorsten Marx
  • iphone
  • phonegap
  • sqlite
0 Comments

4 Answers

  • You can give the name of the file of the database in ti. I think you can use the same file in both applications and use the PG database in your Ti app.

    — answered November 19th 2010 by Peter Griffin
    permalink
    0 Comments
  • I tried this, but i don't know the correct path to the sqlite database file. The database was created by the PhoneGap app in the webbrowser context.

    — answered November 19th 2010 by Thorsten Marx
    permalink
    0 Comments
  • >Is there a solutions to use the SQLite Database from the installed old app and merge it to the new version of the app. I want to use the same App ID, so the user can comfortable update the app.

    The devices sandbox an application and prohibit it from accessing the resources (including databases) from another application. The potentially saving grace here is it sounds like you want to replace an existing application written in phoneGap with one written in titanium.

    Off-hand, I do not know what will happen to the various application subfolders created by phoneGap when you install the new application. I suspect they will stay intact, but you will have to test that theory.

    You will have to determine where phoneGap stores its databases, and what it calls them. You may be able to do that by just examining the finder folder view at /Users/(user)/Library/Application Support/iPhone Simulator/4.x/Applications/(app ID)/Library and its children or siblings.

    Once you do that, start with a copy of the phonegap application installed in the simulator then install the titanium version. Recheck the folders in finder to make sure the old database is still present at the previous path.

    If it is, then in your app.js startup code, you need to create a filesystem object reference to the old database. Either examine the logic in the Kitchen Sink example filesystem.js, or post back here with the exact path and filename where phonegap stored your old database.

    Once you have that file object reference, you need a second reference to where titanium would store the same database. Let's say you wanted to call the database MyDatabase in titanium; you can get that with:

    var dbName = "MyDatabase";
    var newDB = Ti.Filesystem.getFile( Ti.Filesystem.applicationSupportDirectory + '/database/' + dbName + '.sql');
    

    You'll have to figure out the path to the phonegap database and get a file object reference to it. Then do something like this after the above code:

    var oldDB = Ti.Filesystem.getFile( ... you need to find this path ... );
    if ( oldDB.exists() && ( !newDB.exists() ) {
        newDB.write( oldDB.read() );
        oldDB.deleteFile();   // optional
    }
    

    Hope this helps,
    Doug

    — answered November 19th 2010 by Doug Handy
    permalink
    0 Comments
  • > tried this, but i don't know the correct path to the sqlite database file. The database was created by the PhoneGap app in the webbrowser context.

    I can't give you a direct answer either. Either run the app in PhoneGap in the simulator then examine the simulator folder contents as described in my first reply, or ask on the phonegap google group where the databases are stored and what they are called.

    Post that back here and we can try to help more.

    — answered November 19th 2010 by Doug Handy
    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.