Reputation: 1253
I have a PhoneGap application installed on Android that accesses a SQL database. If I uninstall the application and then try to reinstall it I get a security error saying I can't access the database file. If I remove this database file through App/Settings, then I can reinstall the app and it works fine.
I would like to automatically remove the database when the app is uninstalled so I (or another user) can re-install without having to go into Settings.
Any ideas of how to do this?
Upvotes: 1
Views: 1101
Reputation: 640
I guess that you are using SQLite I used it once but I have problems with porting my application to ios then I use this kind of database that Phonegap provide its pretty easy to use:
http://docs.phonegap.com/en/2.2.0/cordova_storage_storage.md.html#Storage
And you can delete your database with this query:
db = window.openDatabase("TSSE", "1.0", "TSSE_DB", 200000);
db.transaction(populateDB, errorCB, successCB);
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DB_name');
tx.executeSql('CREATE TABLE IF NOT EXISTS DB_name (id, name, password, money)');
}
Upvotes: 0
Reputation: 77
Here is the LogCat data when the error occurs, I omitted some stuff that I thought was unrelated to this issue, hopefully I didn't miss anything:
11-27 18:10:52.859: I/dalvikvm(32482): Could not find method android.webkit.WebView.<init>, referenced from method org.apache.cordova.CordovaWebView.<init>
11-27 18:10:52.859: W/dalvikvm(32482): VFY: unable to resolve direct method 3200: Landroid/webkit/WebView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;IZ)V
11-27 18:10:52.859: D/dalvikvm(32482): VFY: replacing opcode 0x70 at 0x0001
11-27 18:10:52.859: D/dalvikvm(32482): VFY: dead code 0x0004-005b in Lorg/apache/cordova/CordovaWebView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;IZ)V
11-27 18:10:52.898: I/CordovaLog(32482): Changing log level to DEBUG(3)
11-27 18:10:52.898: I/CordovaLog(32482): Found preference for useBrowserHistory=true
11-27 18:10:52.898: D/CordovaLog(32482): Found preference for useBrowserHistory=true
11-27 18:10:52.898: I/CordovaLog(32482): Found preference for exit-on-suspend=false
11-27 18:10:52.898: D/CordovaLog(32482): Found preference for exit-on-suspend=false
11-27 18:10:52.898: D/JsMessageQueue(32482): Set native->JS mode to 2
11-27 18:10:52.906: D/DroidGap(32482): DroidGap.init()
11-27 18:10:52.906: D/CordovaWebView(32482): >>> loadUrl(file:///android_asset/www/index.html)
11-27 18:10:52.906: D/PluginManager(32482): init()
11-27 18:10:52.914: D/CordovaWebView(32482): >>> loadUrlNow()
11-27 18:10:52.914: D/DroidGap(32482): Resuming the App
11-27 18:10:52.921: D/SoftKeyboardDetect(32482): Ignore this event
11-27 18:10:52.953: D/DroidGap(32482): onMessage(onPageStarted,file:///android_asset/www/index.html)
11-27 18:10:52.953: D/SoftKeyboardDetect(32482): Ignore this event
11-27 18:10:52.960: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:52.992: D/SoftKeyboardDetect(32482): Ignore this event
11-27 18:10:53.015: D/szipinf(32482): Initializing inflate state
11-27 18:10:53.015: D/szipinf(32482): Initializing zlib to inflate
11-27 18:10:53.023: D/szipinf(32482): Initializing inflate state
11-27 18:10:53.023: D/szipinf(32482): Initializing zlib to inflate
11-27 18:10:53.039: D/szipinf(32482): Initializing inflate state
11-27 18:10:53.039: D/szipinf(32482): Initializing inflate state
11-27 18:10:53.039: D/szipinf(32482): Initializing zlib to inflate
11-27 18:10:53.039: D/szipinf(32482): Initializing zlib to inflate
11-27 18:10:53.164: I/ActivityManager(520): Displayed com.example.ezbrzy_homework_planner/.EzBrzy_Main: +407ms
11-27 18:10:53.398: D/dalvikvm(520): GC_CONCURRENT freed 1451K, 27% free 12851K/17543K, external 9751K/11799K, paused 3ms+8ms
11-27 18:10:54.054: D/Cordova(32482): onPageFinished(file:///android_asset/www/index.html)
11-27 18:10:54.054: D/DroidGap(32482): onMessage(onNativeReady,null)
11-27 18:10:54.054: D/DroidGap(32482): onMessage(onPageFinished,file:///android_asset/www/index.html)
11-27 18:10:54.070: I/Database(32482): sqlite returned: error code = 14, msg = cannot open file at source line 25467
11-27 18:10:54.085: D/DroidGap(32482): onMessage(networkconnection,wifi)
11-27 18:10:54.093: D/DroidGap(32482): onMessage(spinner,stop)
11-27 18:10:54.093: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:54.234: I/Database(32482): sqlite returned: error code = 23, msg = not authorized
11-27 18:10:54.304: D/dalvikvm(32482): GC_EXTERNAL_ALLOC freed 595K, 44% free 3534K/6279K, external 2755K/2773K, paused 30ms
11-27 18:10:54.328: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:55.539: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:56.062: D/DroidGap(32482): onMessage(spinner,stop)
11-27 18:10:57.164: I/Database(32482): sqlite returned: error code = 1, msg = no such table: assignments
11-27 18:10:57.218: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:58.414: I/gralloc(520): Allocated 0x660072 size 6488161
It works fine if I just change the db name to something else. Now I can't even clear the app data on the device and get the old name to run again (on droid razr)...
Upvotes: 1