added another parameter to switch file path logic for where a database can be. Could probably do in try/catch but ... also removed dependency on .db in code. ".db" is not always the extension of a sqlite database so it shouldn't be hard coded. user can specify in calling code.

This commit is contained in:
steve 2012-06-16 23:28:40 -06:00
parent 5c55e10ff1
commit 8c07014428

View File

@ -136,18 +136,26 @@ public class SQLitePlugin extends Plugin {
* For example, application "com.phonegap.demo.Demo" would save its database * For example, application "com.phonegap.demo.Demo" would save its database
* files in "/data/data/com.phonegap.demo/databases/" directory. * files in "/data/data/com.phonegap.demo/databases/" directory.
* *
* When a file is downloaded using a FileTransfer it is placed on the sd
* memory card.
*
* @param appPackage * @param appPackage
* The application package. * The application package.
* @param preLoaded
* If db was loaded with project or downloaded externally
*/ */
public void setStorage(String appPackage) { public void setStorage(String appPackage, Boolean preLoaded) {
this.path = "/data/data/" + appPackage + "/databases/"; if(preLoaded)
this.path = "/data/data/" + appPackage + "/databases/";
else
this.path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
} }
/** /**
* Open database. * Open database.
* *
* @param db * @param db
* The name of the database * The name of the database including its extension.
* @param version * @param version
* The version * The version
* @param display_name * @param display_name
@ -167,10 +175,10 @@ public class SQLitePlugin extends Plugin {
if (this.path == null) { if (this.path == null) {
Package pack = this.ctx.getClass().getPackage(); Package pack = this.ctx.getClass().getPackage();
String appPackage = pack.getName(); String appPackage = pack.getName();
this.setStorage(appPackage); this.setStorage(appPackage, false);
} }
this.dbName = this.path + db + ".db"; this.dbName = this.path + db;
this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null); this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null);
} }