an-rahulpandey / cordova-plugin-dbcopy Goto Github PK
View Code? Open in Web Editor NEWCopy SQLite Database from www folder to default app database location
License: Apache License 2.0
Copy SQLite Database from www folder to default app database location
License: Apache License 2.0
Yes, I know you say it's untested.
I have a use case where I need to download some largish pre-populated databases on a regular basis. The databases get saved to the file system using cordova file and then dbcopy copyDbFromStorage puts it into the database directory. sqlite-storage is being used to read from the database.
Anyway, it seems to work okay on IOS but fails on Android. The copy works but there is no data in the database after it gets opened. After some debugging I believe it's related to a line of code in DatabaseHelper.createdatabase. Commenting out the call to getReadableDatabase() seems to solve the problem. Not sure what the purpose of that call is but perhaps you can consider it as a fix.
`
public void createdatabase(File dbPath, String source, final CallbackContext callbackContext) throws IOException {
// Log.d("CordovaLog","Inside CreateDatabase = "+dbPath);
// this.getReadableDatabase();
try {
copyDatabase(dbPath, source, callbackContext);
} catch (IOException e) {
throw new Error(
"Create Database Exception ============================ "
+ e);
}
}
`
I want all my plugins to be specified in my cordova config.xml
Currently, I put <plugin name="cordova-plugin-dbcopy" spec="~1.0.3" />
in my config.xml
.
However, this causes cordova to complain:
Discovered plugin "cordova-plugin-dbcopy" in config.xml. Installing to the project
Fetching plugin "cordova-plugin-dbcopy@~1.0.3" via npm
Plugin "me.rahul.plugins.sqlDB" already installed on android.
Plugin "me.rahul.plugins.sqlDB" already installed on ios.
I'm not sure, but I suspect if you change the plugin id it will allow this use case to work without having to check the npmjs plugin repository on each build.
Thanks for this plugin!
window.plugins.sqlDB.copyDbFromStorage('newyork.mbtiles', location, 'file:///storage/emulated/0//Uptour/map/newyork.mbtiles', isDeleteOldDb, function(success) {
resolve(success);
}, function(error) {
console.log(error, 'hgjk');
reject(error);
});
throws 400 DB Not Present in www folder
Hi,
I'm using copyDbFromStorage to copy a database from a location
under cordova.file.dataDirectory but the copy does not work. The
success callback is being called with ' JSON error' passed to it.
Thanks
I got the following error building v 2.1.0 for a Cordova app
\platforms\android\src\me\rahul\plugins\sqlDB\sqlDB.java:129: error: local variable dbName is accessed from within inner class; needs to be declared final
myInput = cordova.getActivity().getAssets().open("www/" + dbName);
v 2.0.0 works fine
I'm using jdk1.8.0_131
Anyone else encountered this?
Thanks
Andy
I've done some tests with the brand new Android 9. According to the logs, everything is fine. But when sqlite opens the DB, it's empty.
This seems to be the default behaviour of sqlite to create a new db if the db is not found during opening. This makes me think that the copyDbFromStorage does not copy the file.
Any ideas of how to debug that? It works fine from Android 4.3 to 8.1. It just fails on Android 9.
When i tried the following
window.plugins.sqlDB.copy("demo.db.sqlite",0,function() {
console.log("db read")
db = $cordovaSQLite.openDB({name : 'demo.db.sqlite',location : 'default'});
}, function(error) {
console.log("error in copy db")
db = $cordovaSQLite.openDB("demo.db");
})
It is giving me following error
i think i am specifying the location.. isn't it ? Or am i doing anything wrong ?
I've been trying to identify the issue for past 8 hours - my code works correctly on Android ionic view, however iOS is throwing
"undefined is not an object (evaluating 'window.plugins.sqlDB.copy') "
I tried wrapping it in a timeout (as there is an issue of delayed loading of plugins in ionic view) with as much as 5 seconds delay, to no avail.
I've installed the plugin via :
cordova plugin add https://github.com/an-rahulpandey/cordova-plugin-dbcopy.git
My code in app.js
.run(function($ionicPlatform, $rootScope, $ionicHistory, $state, $mdDialog, $mdBottomSheet, $cordovaPush, $cordovaSQLite, DB, $timeout,$ionicLoading, $window) {
$ionicPlatform.ready(function(){
$timeout(function(){
try{
window.plugins.sqlDB.copy("mydb.db",0, function () {
alert('ok')
console.log("copy ok")
},function(e){
alert(e)
console.log("copy fail")
console.log(e)
});
}catch(e){
alert(e);
console.log(e);
console.log(e.stack);
console.log(e.line);
}
}, 5000);
})
})
I have wrapped my function withing $ionicPlatform function. I don't know if their is any other way to use this plugin in ionic framework. It return the error window.plugins is undefined. Any help will be appreciated.
Problem with the Android version. It is working fine on iOS.
I am working with two database. One large database used read-only, the other smaller one in read/write mode. So I am starting the copy procedure of two databases. Once they are copied I open them and start working.
This does not work as the plugin seems to use a global variable 'dbname' to store the name of the database. I am discovering the following behavior:
As a temporary fix I do this
This will work.
Hi rahul I got the plugin to work and its logging that the data base is copied but when i try to run a Select query it is not getting execute and it does not return any log just stops there.
But when i run an insert query its logging
code: 0
message: "sqlite3_prepare_v2 failure: file is encrypted or is not a database"
i am taking a backup from mysql as CSIR_DB.mysql and then renaming it as CSIR_DB.db and have pasted the file in www folder
I tried it with out coping the data base created the data base and manually inserted the data and fetched it its working fine then. The error only exists when i copy the data base
on windows running on device
my logs of android monitor
09-28 12:31:59.925 829-952/? D/PersonaManagerService: needVerificationForPackage com.CSIR.CSIR_Directory
09-28 12:32:01.345 18164-18164/? I/Finsky: [1] com.google.android.vending.verifier.v.b(194): Verification complete: id=267, package_name=com.CSIR.CSIR_Directory
09-28 12:32:02.235 829-952/? I/MyContainer: package (com.CSIR.CSIR_Directory) installed with seinfo=default
09-28 12:32:02.245 237-237/? E/installd: install: '/data/data/com.CSIR.CSIR_Directory': normal app
09-28 12:32:02.245 829-952/? W/MyContainer: assignseinfovalue, = com.CSIR.CSIR_Directory = default = 1023 = 0,501-1023
09-28 12:32:02.265 237-237/? E/installd: creating libsymlink '/data/data/com.CSIR.CSIR_Directory/lib'
09-28 12:32:03.115 829-952/? D/PackageManager: Sending to user 0: act=android.intent.action.PACKAGE_ADDED dat=package:com.CSIR.CSIR_Directory flg=0x4000000 Bundle[{android.intent.extra.UID=10296, android.intent.extra.user_handle=0}]
09-28 12:32:03.225 829-829/? D/RCPManagerService: App Installed with packageNAme = com.CSIR.CSIR_Directory
09-28 12:32:03.295 3992-3992/? E/BroadcastChangedPackage.java: [ (BroadcastChangedPackage.java:94)#A ] putPackageList result [{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"u":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"},{"r":"com.CSIR.CSIR_Directory"},{"i":"com.CSIR.CSIR_Directory"}]
09-28 12:32:03.415 829-829/? D/BackupManagerService: Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.CSIR.CSIR_Directory flg=0x4000010 (has extras) }
09-28 12:32:04.005 829-939/? I/CrashAnrDetector: onPackageAdded : com.CSIR.CSIR_Directory
09-28 12:32:04.405 18164-18164/? I/Finsky: [1] com.google.android.finsky.utils.bn.run(1302): Package state data is missing for com.CSIR.CSIR_Directory
09-28 12:32:04.425 18276-19880/? I/UpdateIcingCorporaServi: Updating corpora: APPS=com.CSIR.CSIR_Directory, CONTACTS=MAYBE
09-28 12:32:05.655 829-1642/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.CSIR.CSIR_Directory
09-28 12:32:05.715 19923-19923/? E/dalvikvm: >>>>> com.CSIR.CSIR_Directory [ userId:0 | appId:10296 ]
09-28 12:32:05.805 829-2104/? D/ThermalMonitor: Foreground Application Changed: com.CSIR.CSIR_Directory
09-28 12:32:08.835 19923-19996/? V/info: Open sqlite db: /data/data/com.CSIR.CSIR_Directory/databases/CSIR_DB.db
09-28 12:32:08.845 19923-19996/? D/dalvikvm: Trying to load lib /data/app-lib/com.CSIR.CSIR_Directory-1/libsqlc-native-driver.so 0x425e69c8
09-28 12:32:08.845 19923-19996/? D/dalvikvm: Added shared lib /data/app-lib/com.CSIR.CSIR_Directory-1/libsqlc-native-driver.so 0x425e69c8
09-28 12:32:08.845 19923-19996/? D/dalvikvm: No JNI_OnLoad found in /data/app-lib/com.CSIR.CSIR_Directory-1/libsqlc-native-driver.so 0x425e69c8, skipping init
Hello and good times.
I use this plugin.
I include this scripts to my application :
and copy and past this code :
window.plugins.sqlDB.copy("shia.sqlite",success,error);
but after run my application , this error showed in console :
TypeError: window.plugins is undefined
window.plugins.sqlDB.copy("shia.sqlite",success,error);
The LICENSE file specifies GPL, which will not work for many users, while plugin.xml specifies Apache 2.0 which is much better. Can you please make one consistent statement which license you want to publish under?
I am maintaining the Cordova-sqlite-storage plugin and this project could help many users. If you choose MIT and/or Apache 2.0, I will add a link to this project from the Cordova-sqlite-storage, Cordova-sqlcipher-adapter, and cordova-sqlite-evfree projects.
Thanks!
Any plan to add windows 10 support?
By the way, many thanks for this plugin :)
Hi,
I can successfully copy database from resources folder under ios, but Android for some reason only gives
error message
Error = "Error"
I copied my database to platforms/android/assets/mydb.db but for some reason its not working.
Do I need to put some permissions first in the config.xml or I'm just putting the db in the wrong spot?
thank you Rahul!
davor
Since the last update from this plugin I am having trouble building the app for Android using the Ionic framework. When I remove this plugin the build is working fine.
I'm getting the following error:
BUILD FAILED in 4s
27 actionable tasks: 1 executed, 26 up-to-date
Error: cmd: Command failed with exit code 1 Error output:
C:\path\to\project\platforms\android\src\me\rahul\plugins\sqlDB\sqlDB.java:129: error: local variable dbName is accessed from within inner class; needs to be declared final
myInput = cordova.getActivity().getAssets().open("www/" + dbName);
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
FAILURE: Build failed with an exception.
Hello,
When pre-filled sqlite db size is too big, after it was copied. The application has two databases file. So this has problem with the application size. Could you can add a new move functionality (copy and remove source file).
For ex: Before sqlite installed app size : 25MB, pre-filled sqlite db size : 20MB.
When the application installed the app size reached the 65MB. (app size + source sqlite + copeid sqlite).
Thanks in advance.
Mentioned in the issue #38 (comment) here's are my concerns regarding the backup/restore process. What would be great is if there was a function for checking a database exists on a path. The current logic for importing/restoring a database is this:
And it works until at the step 3 there is the db in the storage. But if there's no db at the path then the default db is already removed and the app crashes.
The solution would be to have a function like isDbInStorage()
which could be called before the whole process to check if there's anything to import/restore.
I suppose I could achieve this using the file plugin from cordova, but it seems that the function could be just built in the dbcopy plugin and the file plugin wouldn't be required for just this one function.
What do you think?
Tried with android, worked perfectly
Building with ios generates the following warning:
warning: no rule to process file '/Volumes/BEN/IonicCordovaProject1/IonicCordovaProject1/platforms/ios/IonicCordovaProject1/Plugins/me.rahul.plugins.sqlDB/sqlDB.h' of type sourcecode.c.h for architecture i386
Tried uninstalling/reinstalling, no luck so far
I am trying to implement following tutorial but with no success so far . No error log or anything is thrown back. Please suggest me where I might be wrong .
https://www.thepolyglotdeveloper.com/2015/01/deploy-ionic-framework-app-pre-filled-sqlite-db/
I am using following sample chinook.db
(http://www.sqlitetutorial.net/sqlite-sample-database/)
I am using Ionic framework to build for android. Also please tell me where exactly to put my prepopulated db or sqlite file. I am using this location as of now
platforms/android/assets
Using the following code, everything works correctly on android but on ios even the alerts are not firing!!
window.plugins.sqlDB.copy("mydba.db", 0, function() { $rootScope.base = $cordovaSQLite.openDB({name: "mydba.db", location: 'default'}); alert('Copied'); }, function(error) { alert(error.message); $rootScope.base = $cordovaSQLite.openDB({name: "mydba.db", location: 'default'}); });
Am I doing something wrong or does the plugin don't support ios?
PS: tested on ipad and iphone
Do you planning to add Windows Phone (8) support?
I have the following code, and tested in the a android device. Somehow the erorr is showing "OK"
May I know what is the problem ?
window.plugins.sqlDB.copy("School.db", function () {
alert('Sucess');
db1 = $cordovaSQLite.openDB("School.db");
}, function (error) {
alert("There was an error copying the database: " + JSON.stringify(error));
});
Hi,
I'm trying to replace database from ios app old version. Success function is called when I call sqlDB.remove but when I try to use sqlDB.copy to copy the new database file I receive:
016-10-25 08:47:11.813452 MyApp[592:107663] ERROR: [Sync]: Database copy error! {"message":"Error Domain=NSCocoaErrorDomain Code=516 \"“app.db” couldn’t be copied to “LocalDatabase” because an item with the same name already exists.\" UserInfo={NSSourceFilePathErrorKey=/var/containers/Bundle/Application/725E-4A7E-A8A4-0F7ED7930D34/MyApp.app/www/app.db, NSUserStringVariant=(\n Copy\n), NSDestinationFilePath=/var/mobile/Containers/Data/Application/5298-4E04-9CAB-C44307FA7287/Library/LocalDatabase/app.db, NSFilePath=/var/containers/Bundle/Application/725E-4A7E-A8A4-0F7ED7930D34/MyApp.app/www/app.db, NSUnderlyingError=0x17404c570 {Error Domain=NSPOSIXErrorDomain Code=17 \"File exists\"}}","code":516}
My code:
var dbName = 'app.db',
dbVersionKey = 'db:version',
dbVersion = '1.0',
dbCurrentVersion = $window.localStorage.getItem(dbVersionKey) || null;
if((ionic.Platform.isIOS() || ionic.Platform.isAndroid())) {
if($window.plugins && $window.plugins.sqlDB) {
var dbLocation = ionic.Platform.isIOS()? 2: 0;
$window.plugins.sqlDB.copy(dbName, dbLocation,
function copySuccess(){
console.debug(': Database has been successfully copied.');
$window.localStorage.setItem(dbVersionKey, dbVersion);
deferred.resolve();
}, function copyError() {
if(dbCurrentVersion != dbVersion) {
console.debug(': Removing database...', dbCurrentVersion);
$window.plugins.sqlDB.remove(dbName, dbLocation,
function removedSuccess() {
console.debug('Database has been successfully deleted.');
$window.plugins.sqlDB.copy(dbName, dbLocation,
function copySuccess(){
console.debug('Database has been successfully copied.');
$window.localStorage.setItem(dbVersionKey, dbVersion);
deferred.resolve();
}, function copyError(err) {
console.error('Database copy error!', err);
deferred.reject();
});
}, function removedError(err) {
console.error('Database remove error!', err);
deferred.reject();
});
} else {
console.debug('Database file is already updated.');
deferred.resolve();
}
});
} else {
console.error('Missing sqlDB plugin.');
deferred.reject();
}
}
My test device is Android 5.0 and I'm trying to utilize the copyDbToStorage() function to make a backup of my database, but each way I try the plugin reports error:
{"message":"/storage/sdcard1/Android/data/com.appbundleid: open failed: EISDIR (Is a directory)","code":400}
I call this function this way:
window.plugins.sqlDB.copyDbToStorage('appDB.db', 0, '/storage/sdcard1/Android/data/com.appbundleid/',
function() {
console.log('SUCCESS')
},
function(e) {
console.log('@@@@ ERROR ', JSON.stringify(e))
});
Could you please give a working example of this?
Hi Rahul
I am taking a backup from mySQL as populated.sql and then changing its extension as .db
i am getting an error as
There was an error copying the database: {"message":"File already exists","code":516}
these are the steps that did.
These are the things that I tried
All of the above returned the same error.
my code
window.plugins.sqlDB.copy("populated.db",1, function() {
db = $cordovaSQLite.openDB({name: "populated.db", location: 1});
}, function(error) {
console.error("There was an error copying the database: " +JSON.stringify(error));
db = $cordovaSQLite.openDB({name: "populated.db", location: 1});
});
my logs
There was an error copying the database: {"message":"File already exists","code":516} (index):28
OPEN database: populated.db (index):28
OPEN database: populated.db - OK (index):28
DB opened: populated.db
monitoring logs from chrome device inspect
adb logcat and android monitors are give infinite logs and I am unable to find logs related to this plugin
Running my app on a actual device and not on an emulator
Hi,
I'm trying to use your plugin to copy the database for the further use, as I understand this is the easiest way to use the custom prepopulated databases in the application.
I've already managed doing the copy, but hope you would help me with the other questions as well :)
The questions are the next:
Looking forward for your answers.
Regards,
Hi,
When I push my application to the Ionic Dashboard, the www is not copied and so the database is not available when I run it from Ionic View. In Xcode and Android Studio, my test builds work perfectly. Is there a way to copy the database from the resources or src > assets folder?
Thanks.
Hi,
Thanks for dedicating building cool stuff. I placed SQlite file in www folder and used dbcopy plugin 1.02 version in my Cordova iOS app (I am using Visual Studio Tools for Apache Cordova CTP 3.1 which supports up to Cordova version 4.1.2.) I used Phonegap Build cloud service to build the ipa file. However, when I uploaded the required files to Phonegap Build, it showed that 1.02 version is not supported. Currently, Phonegap Build only supports 1.0.0 version. So I replaced the plugin to 1.0.0 and compiled the project via the Phonegap Build. Now in my iPhone, when the app ran to the window.plugins.sqlDB.copy function, it popped up an error something like .... Cocoa error 260 .... and .... No such file or directory ... (except for the db name, I used exactly same code as you put in the document.)
I wonder if it is because that the 1.0.0 version needs the database to be placed in a Resource folder of the iOS app but I placed the db file in the www folder. If so, could you please ask Phonegap to support your 1.02 version? I used Phonegap Build cloud service because our organization doesn't want to buy a mac machine.
Thanks!
Hi,
I have a case where I have some static catalog information in db I'm shipping with my app, eventually I need to update this db when I ship new version of my app.
What would be the best way to overwrite existing db? I was thinking in case of error just delete the existing db and repeat copyDB function again, I guess that would work right? Do you think its possible to add a parameter in the Copy function to 'true' if we want to overwrite existing, so you could handle that in the back automatically? default would be 'false'
Thank you for creating this plugin!!
Davor
I have this code
window.plugins.sqlDB.copy("test.db", function() {
console.log('OK');
}, function(error) {
console.error("There was an error copying the database: " + error);
});
When i put a wrong database (test2.db for example) I have nothing. but when all is ok, i have:
error There was an error copying the database: File Copied
I use the ios emulator with ionic.
any idea?
Hi @an-rahulpandey thank you for this awesome plugin, but I found an issue when using function sqlDB.copy(). I have a code like below :
console.log('Copying database');
window.plugins.sqlDB.copy("myDB.db", function() {
console.log('Opening database');
db = $cordovaSQLite.openDB("myDB.db");
console.log('Testing query');
MyObj.count("").then(function(result) {
console.error("Count Result: " + JSON.stringify(result));
})
}, function(error) {
console.error("There was an error copying the database: " + error);
db = $cordovaSQLite.openDB("myDB.db");
});
when I run the application and watch the logcat. it looks like the application never execute $cordovaSQLite.openDB("myDB.db"); because I only see the console log 'Copying database' I didn't see the console log 'Opening database' and also for error message.
I am guessing there is a problem during copy db process but I didn't know what the error is. Could you please give me an advice ?? thanks.
Hi,
I want to copy my database.db from 'storage/sdcard0/myfolder/database.db' to default data locaion. How can I do it?
Thank a lot.
Hi
Can you guide me to use this plugin in commandline ?
window.plugins is always undefined to me.
using the SQLItePlugin in iOS is possible to disable iCloud backup specifying the "location:2" parameter to open a prepopulated database:
db = sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
With this configuration dbcopy doesn't see the original database and so calling sqlDB.copy() or sqlDB.remove() doesn't work as expected.
Any solution?
PS: thanks for the plugin!
We are trying to Copy Database from Device Storage but there is no any status return
I would be great if this plugin were able to copy from an HTTP location
Can you please help me how to install this plugin into my workspace..Im working on android phonegap
Hi,
This is a great plugin, however I wanted to ask if there is a way to check if the database already exists before trying to copy it over?
Thank you
Hello,
I use this plugin to ship prepopulated db in my IOS app.
The problem is the destination folder: iCloud synced documents folder ! My last submission in appStore was rejectd because my db should not be in that folder. The best position for db should be cache directory or noSync library folder, but at the moment i cannot choose the destination of the copy.
On my android 4.4.2 phone (LG G3 S) it doesnt work. Here is information from logcat:
D/CordovaLog( 2618): DatabasePath = /data/data/com.KartaKontroli/databases/baza.db&&&& dbname = baza.db&&&&DB Exists =false
D/CordovaLog( 2618): Inside CreateDatabase = /data/data/com.KartaKontroli/databases/baza.db
D/CordovaLog( 2618): Inside copydatabase = /data/data/com.KartaKontroli/databases/baza.dbdbname = baza.db
D/CordovaLog( 2618): Inside copydatabase = /data/data/com.KartaKontroli/databases/baza.dbdbname = baza.db
when I try to run database once again it report that database exist but when I try to make query to the database it doesnt work. On iOS it works fine.
I tried to install it on windows via npm but igot the following error
Error: Failed to fetch plugin https://github.com/an-rahulpandey/cordova-plugin-dbcopy.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: cmd: Command failed with exit code 1 Error output:
npm ERR! code ENOGIT
npm ERR! No git binary found in $PATH
npm ERR!
npm ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\prodigy\AppData\Roaming\npm-cache_logs\2017-08-22T13_22_53_304Z-debug.log
i can Copy database from Device Storage But getting one issue
"attempt to write a readonly database (code 1032)"
Hi,
thanks for this great plugin. I use it on Android and there is no problem, but when i tried to use on Ipad (IOS 9.2), it says "TypeError: undefined is not an object (evaluating 'window.plugins.sqlDB') ".
I write <script src="../plugins/cordova-plugin-dbcopy/www/sqlDB.js"></script> to init but i dont know why this doesn´t work. I use Inte XDK to test the aplicatión i´m doing.
¿Do you know what would be?
Thank you very much.
Hi Rahul,
in xcode I receive this warning when I create a debug-build:
warning: no rule to process file '/Library/WebServer/Documents/rcs/dev/platforms/ios/Myapp/Plugins/me.rahul.plugins.sqlDB/sqlDB.h' of type sourcecode.c.h for architecture arm64
Might this also be the reason why my copied database is empty?
I only have problems with iOS. Android is absolutely ok!
Thanks a lot for this plugin. I hope you can help me to make it run in my environment.
This is my cordova_plugins.js:
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/cordova-plugin-dbcopy/www/sqlDB.js",
"id": "cordova-plugin-dbcopy.sqlDB",
"pluginId": "cordova-plugin-dbcopy",
"clobbers": [
"window.plugins.sqlDB"
]
},
{
"file": "plugins/cordova-sqlite-storage/www/SQLitePlugin.js",
"id": "cordova-sqlite-storage.SQLitePlugin",
"pluginId": "cordova-sqlite-storage",
"clobbers": [
"SQLitePlugin"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
"cordova-plugin-dbcopy": "1.0.4",
"cordova-plugin-whitelist": "1.3.0",
"cordova-sqlite-storage": "1.4.8"
}
// BOTTOM OF METADATA
});
I can't copy the db cuz I'm getting TypeError: Cannot read property 'sqlDB' of undefined
I saw this in other issues but I'm using Chrome, that supports websql.
Hi,
I Followed your instructions and its copied the database , which has one table...when i pulled that db and checked , I had seen that there is no tables in that..
Hi
When my program run in first time, that is crashed after execute bellow line:
window.plugins.sqlDB.copy("shia.sqlite",copysuccess,copyerror);
And in the next runs this alert displayed:
database error : File already exist code : 516
Can you help me?
I have an IOS tablet app and the copy function works great, the inital db gets copied to the .../appliction/.../documents folder which works. but when i try to use the .remove() function I get an error "File Doesn't Exists".
When my app starts i copy an initial seed db. window.plugins.sqlDB.copy("Access.db", copysuccess, copyerror); which works. But if i try,
function () {
db.close();
window.plugins.sqlDB.remove("access.db", function () {
setTimeout(function () { alert('Successfully reinitialized. Please restart the application.'); }, 2000)
}, function (e) { console.log('Error removing the db. Error: ' + JSON.stringify(e)) });
};
i get the file doesn't exists error.
I think the plugin need a fstat or status function that returns the following about the destination file: 1) whether the file exists in the destination, and 2) the data time created, and 3) the date time last modified.
App initial installation is the simple case, but there are some additional requirements for App update.
Case 1) The database loaded from www initial installation never changes. Once it is copied to the destination we never want to copy it again. The plugin handles this case now.
Case 2) The database loaded from www needs to overwrite the destination database when the App is updated, but we don't want to do this copy each time the App starts. We only want to do it when the App is updated. If we could get the last modified datetime of the destination file we would be able to tell if the copy needed to be done.
The App update situation can become much more complex if a database contains some data that came from the developer and other data that is from the end user. In that case some kind of merge operation has to be done instead of a copy. But it is probably best to simply avoid this case by always putting end user data in a different database than data that comes from the developer.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.