From 3a851b85372f05c9ddc7678ae9a3282f397e16e7 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 16 Jun 2012 17:53:36 -0600 Subject: [PATCH 1/4] updated imports for cordova 1.8.x --- .../src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java b/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java index fc2e536..96fb958 100755 --- a/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java +++ b/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java @@ -10,8 +10,8 @@ package com.phonegap.plugin.sqlitePlugin; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import com.phonegap.api.Plugin; -import com.phonegap.api.PluginResult; +import org.apache.cordova.api.Plugin; +import org.apache.cordova.api.PluginResult; import android.database.Cursor; import android.database.sqlite.*; From 5c55e10ff1114bcbaf292655f4915e2b2e1ccd93 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 16 Jun 2012 18:08:31 -0600 Subject: [PATCH 2/4] Updating to Cordova 1.8.x replacing PhoneGap with cordova --- Android/assets/www/SQLitePlugin-orig.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Android/assets/www/SQLitePlugin-orig.coffee b/Android/assets/www/SQLitePlugin-orig.coffee index 493e956..e61139e 100644 --- a/Android/assets/www/SQLitePlugin-orig.coffee +++ b/Android/assets/www/SQLitePlugin-orig.coffee @@ -28,7 +28,7 @@ do -> opts = undefined unless @dbPath of @openDBs @openDBs[@dbPath] = true - PhoneGap.exec success, error, "SQLitePlugin", "open", [ @dbPath ] + cordova.exec success, error, "SQLitePlugin", "open", [ @dbPath ] SQLitePlugin::close = (success, error) -> console.log "SQLitePlugin.prototype.close" @@ -36,7 +36,7 @@ do -> if @dbPath of @openDBs delete @openDBs[@dbPath] - PhoneGap.exec null, null, "SQLitePlugin", "close", [ @dbPath ] + cordova.exec null, null, "SQLitePlugin", "close", [ @dbPath ] get_unique_id = -> id = new Date().getTime() @@ -181,7 +181,7 @@ do -> error txself, res transaction_callback_queue[@trans_id]["success"] = successcb transaction_callback_queue[@trans_id]["error"] = errorcb - PhoneGap.exec null, null, "SQLitePlugin", "executeSqlBatch", transaction_queue[@trans_id] + cordova.exec null, null, "SQLitePlugin", "executeSqlBatch", transaction_queue[@trans_id] # required for callbacks: root.SQLitePluginTransaction = SQLitePluginTransaction From 8c0701442859cb8864deb897608760359df0b23e Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 16 Jun 2012 23:28:40 -0600 Subject: [PATCH 3/4] 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. --- .../plugin/sqlitePlugin/SQLitePlugin.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java b/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java index 96fb958..b70ff3b 100755 --- a/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java +++ b/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java @@ -136,18 +136,26 @@ public class SQLitePlugin extends Plugin { * For example, application "com.phonegap.demo.Demo" would save its database * 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 * The application package. + * @param preLoaded + * If db was loaded with project or downloaded externally */ - public void setStorage(String appPackage) { - this.path = "/data/data/" + appPackage + "/databases/"; + public void setStorage(String appPackage, Boolean preLoaded) { + if(preLoaded) + this.path = "/data/data/" + appPackage + "/databases/"; + else + this.path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/"; } /** * Open database. * * @param db - * The name of the database + * The name of the database including its extension. * @param version * The version * @param display_name @@ -167,10 +175,10 @@ public class SQLitePlugin extends Plugin { if (this.path == null) { Package pack = this.ctx.getClass().getPackage(); 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); } From 919c8e1725e3d6138eeb404da787218affaf2d9d Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 16 Jun 2012 23:32:08 -0600 Subject: [PATCH 4/4] missed a usage. --- Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java b/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java index b70ff3b..b9ebcd6 100755 --- a/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java +++ b/Android/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java @@ -49,7 +49,7 @@ public class SQLitePlugin extends Plugin { // TODO: Do we want to allow a user to do this, since they could get // to other app databases? if (action.equals("setStorage")) { - this.setStorage(args.getString(0)); + this.setStorage(args.getString(0), false); } else if (action.equals("open")) { this.openDatabase(args.getString(0), "1", "database", 5000000);