mirror of
https://gitee.com/shuto/cordova-plugin-dbcopy.git
synced 2024-10-06 09:42:06 +08:00
copyDBFromStorage add delete old db flag
This commit is contained in:
parent
0f80bab1aa
commit
3696cae806
@ -72,7 +72,8 @@ public class sqlDB extends CordovaPlugin {
|
|||||||
} else if (action.equalsIgnoreCase("copyDbFromStorage")) {
|
} else if (action.equalsIgnoreCase("copyDbFromStorage")) {
|
||||||
String db = args.getString(0);
|
String db = args.getString(0);
|
||||||
String src = args.getString(2);
|
String src = args.getString(2);
|
||||||
this.copyDbFromStorage(db, src, callbackContext);
|
boolean deletedb = args.getBoolean(3);
|
||||||
|
this.copyDbFromStorage(db, src, deletedb, callbackContext);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
plresult = new PluginResult(PluginResult.Status.INVALID_ACTION);
|
plresult = new PluginResult(PluginResult.Status.INVALID_ACTION);
|
||||||
@ -138,7 +139,7 @@ public class sqlDB extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyDbFromStorage(String db, String src, final CallbackContext callbackContext) {
|
private void copyDbFromStorage(String db, String src, boolean deletedb, final CallbackContext callbackContext) {
|
||||||
File source;
|
File source;
|
||||||
if (src.indexOf("file://") != -1) {
|
if (src.indexOf("file://") != -1) {
|
||||||
source = new File(src.replace("file://", ""));
|
source = new File(src.replace("file://", ""));
|
||||||
@ -147,7 +148,22 @@ public class sqlDB extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (source.exists()) {
|
if (source.exists()) {
|
||||||
this.copyDB(db, source.getAbsolutePath(), callbackContext);
|
if (deletedb) {
|
||||||
|
File path = cordova.getActivity().getDatabasePath(db);
|
||||||
|
Boolean fileExists = path.exists();
|
||||||
|
if (fileExists) {
|
||||||
|
boolean deleted = path.delete();
|
||||||
|
if (deleted) {
|
||||||
|
this.copyDB(db, source.getAbsolutePath(), callbackContext);
|
||||||
|
} else {
|
||||||
|
sendPluginResponse(400, "Unable to Delete", true, callbackContext);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sendPluginResponse(404, "Old DB Doesn't Exists", true, callbackContext);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.copyDB(db, source.getAbsolutePath(), callbackContext);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sendPluginResponse(404, "Invalid DB Source Location", true, callbackContext);
|
sendPluginResponse(404, "Invalid DB Source Location", true, callbackContext);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user