mirror of
https://github.com/moparisthebest/PhoneGap-SQLitePlugin-Android
synced 2024-11-14 04:55:04 -05:00
commit
910134d217
@ -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
|
||||
|
@ -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.*;
|
||||
|
||||
@ -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);
|
||||
@ -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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user