mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-04 00:13:20 +08:00
Ticket 136: window.openDatabase() in Android 3.0 throws SECURITY_ERR (most code written by Simon MacDonald - I just tested and checked in)
When you call window.openDatabase() on an Android 3.0 device you get and error something like this: E/Web Console( 1791): SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent. Simon worked with Pat for a bit and they think this is a WebKit or Android/WebKit interaction bug. In the meantime this fix determines if you are on Android 3.0 and uses Droid_DB if so.
This commit is contained in:
parent
44945f9d5e
commit
673a8871df
@ -389,7 +389,7 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
||||||
window.droiddb = new DroidDB();
|
window.droiddb = new DroidDB();
|
||||||
}
|
}
|
||||||
if (typeof window.openDatabase === "undefined") {
|
if ((typeof window.openDatabase === "undefined") || (navigator.userAgent.indexOf("Android 3.0") != -1)) {
|
||||||
setupDroidDB();
|
setupDroidDB();
|
||||||
} else {
|
} else {
|
||||||
window.openDatabase_orig = window.openDatabase;
|
window.openDatabase_orig = window.openDatabase;
|
||||||
|
45
framework/src/com/phonegap/Storage.java
Normal file → Executable file
45
framework/src/com/phonegap/Storage.java
Normal file → Executable file
@ -21,6 +21,12 @@ import android.database.sqlite.*;
|
|||||||
*/
|
*/
|
||||||
public class Storage extends Plugin {
|
public class Storage extends Plugin {
|
||||||
|
|
||||||
|
// Data Definition Language
|
||||||
|
private static final String ALTER = "alter";
|
||||||
|
private static final String CREATE = "create";
|
||||||
|
private static final String DROP = "drop";
|
||||||
|
private static final String TRUNCATE = "truncate";
|
||||||
|
|
||||||
SQLiteDatabase myDb = null; // Database object
|
SQLiteDatabase myDb = null; // Database object
|
||||||
String path = null; // Database path
|
String path = null; // Database path
|
||||||
String dbName = null; // Database name
|
String dbName = null; // Database name
|
||||||
@ -83,7 +89,7 @@ public class Storage extends Plugin {
|
|||||||
* @return T=returns value
|
* @return T=returns value
|
||||||
*/
|
*/
|
||||||
public boolean isSynch(String action) {
|
public boolean isSynch(String action) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,20 +165,39 @@ public class Storage extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public void executeSql(String query, String[] params, String tx_id) {
|
public void executeSql(String query, String[] params, String tx_id) {
|
||||||
try {
|
try {
|
||||||
Cursor myCursor = this.myDb.rawQuery(query, params);
|
if (isDDL(query)) {
|
||||||
this.processResults(myCursor, tx_id);
|
this.myDb.execSQL(query);
|
||||||
myCursor.close();
|
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', '');");
|
||||||
} catch (SQLiteException ex) {
|
}
|
||||||
|
else {
|
||||||
|
Cursor myCursor = this.myDb.rawQuery(query, params);
|
||||||
|
this.processResults(myCursor, tx_id);
|
||||||
|
myCursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLiteException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
System.out
|
System.out.println("Storage.executeSql(): Error=" + ex.getMessage());
|
||||||
.println("Storage.executeSql(): Error=" + ex.getMessage());
|
|
||||||
|
|
||||||
// Send error message back to JavaScript
|
// Send error message back to JavaScript
|
||||||
this.sendJavascript("droiddb.fail('" + ex.getMessage() + "','"
|
this.sendJavascript("droiddb.fail('" + ex.getMessage() + "','" + tx_id + "');");
|
||||||
+ tx_id + "');");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see the the query is a Data Definintion command
|
||||||
|
*
|
||||||
|
* @param query to be executed
|
||||||
|
* @return true if it is a DDL command, false otherwise
|
||||||
|
*/
|
||||||
|
private boolean isDDL(String query) {
|
||||||
|
String cmd = query.toLowerCase();
|
||||||
|
if (cmd.startsWith(DROP) || cmd.startsWith(CREATE) || cmd.startsWith(ALTER) || cmd.startsWith(TRUNCATE)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process query results.
|
* Process query results.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user