Merge pull request #27 from steveoh/master

Upgrade for Cordova 1.8.x
This commit is contained in:
Chris Brody 2012-06-17 12:42:54 -07:00
commit 910134d217
2 changed files with 19 additions and 11 deletions

View File

@ -28,7 +28,7 @@ do ->
opts = undefined opts = undefined
unless @dbPath of @openDBs unless @dbPath of @openDBs
@openDBs[@dbPath] = true @openDBs[@dbPath] = true
PhoneGap.exec success, error, "SQLitePlugin", "open", [ @dbPath ] cordova.exec success, error, "SQLitePlugin", "open", [ @dbPath ]
SQLitePlugin::close = (success, error) -> SQLitePlugin::close = (success, error) ->
console.log "SQLitePlugin.prototype.close" console.log "SQLitePlugin.prototype.close"
@ -36,7 +36,7 @@ do ->
if @dbPath of @openDBs if @dbPath of @openDBs
delete @openDBs[@dbPath] delete @openDBs[@dbPath]
PhoneGap.exec null, null, "SQLitePlugin", "close", [ @dbPath ] cordova.exec null, null, "SQLitePlugin", "close", [ @dbPath ]
get_unique_id = -> get_unique_id = ->
id = new Date().getTime() id = new Date().getTime()
@ -181,7 +181,7 @@ do ->
error txself, res error txself, res
transaction_callback_queue[@trans_id]["success"] = successcb transaction_callback_queue[@trans_id]["success"] = successcb
transaction_callback_queue[@trans_id]["error"] = errorcb 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: # required for callbacks:
root.SQLitePluginTransaction = SQLitePluginTransaction root.SQLitePluginTransaction = SQLitePluginTransaction

View File

@ -10,8 +10,8 @@ package com.phonegap.plugin.sqlitePlugin;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import com.phonegap.api.Plugin; import org.apache.cordova.api.Plugin;
import com.phonegap.api.PluginResult; import org.apache.cordova.api.PluginResult;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.*; import android.database.sqlite.*;
@ -49,7 +49,7 @@ public class SQLitePlugin extends Plugin {
// TODO: Do we want to allow a user to do this, since they could get // TODO: Do we want to allow a user to do this, since they could get
// to other app databases? // to other app databases?
if (action.equals("setStorage")) { if (action.equals("setStorage")) {
this.setStorage(args.getString(0)); this.setStorage(args.getString(0), false);
} else if (action.equals("open")) { } else if (action.equals("open")) {
this.openDatabase(args.getString(0), "1", this.openDatabase(args.getString(0), "1",
"database", 5000000); "database", 5000000);
@ -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) {
if(preLoaded)
this.path = "/data/data/" + appPackage + "/databases/"; 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);
} }