Get Android db path separately from SQLiteDatabase.openOrCreateDatabase()

This commit is contained in:
Chris Brody 2012-12-17 20:38:47 +01:00
parent 102d732102
commit c24726173f

View File

@ -11,8 +11,12 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File;
import java.lang.Number; import java.lang.Number;
import java.util.HashMap;
import org.apache.cordova.api.CordovaPlugin; import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CallbackContext;
@ -20,8 +24,6 @@ import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.*; import android.database.sqlite.*;
import java.util.HashMap;
import android.util.Log; import android.util.Log;
public class SQLitePlugin extends CordovaPlugin public class SQLitePlugin extends CordovaPlugin
@ -150,8 +152,14 @@ public class SQLitePlugin extends CordovaPlugin
*/ */
private void openDatabase(String db, String version, String display_name, long size) private void openDatabase(String db, String version, String display_name, long size)
{ {
SQLiteDatabase myDb = //SQLiteDatabase myDb =
this.cordova.getActivity().getApplicationContext().openOrCreateDatabase(db + ".db", Context.MODE_PRIVATE, null); // this.cordova.getActivity().getApplicationContext().openOrCreateDatabase(db + ".db", Context.MODE_PRIVATE, null);
File dbFile = this.cordova.getActivity().getDatabasePath(db + ".db");
Log.v("info", "Open sqlite db: " + dbFile.getAbsolutePath());
SQLiteDatabase myDb = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
myDbMap.put(db, myDb); myDbMap.put(db, myDb);
} }