an-rahulpandey / cordova-plugin-dbcopy

Copy SQLite Database from www folder to default app database location
Apache License 2.0
89 stars 47 forks source link

There was an error copying the database: {"message":"File already exists","code":516} #30

Closed khanSufiyan closed 7 years ago

khanSufiyan commented 7 years ago

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. 1) I pasted the file as "populated" (and not as "populated.db" as i assumes "db" is an extension) in platforms\android\assets\ 2) tried to copy the db as window.plugins.sqlDB.copy("populated.db",1, function() {...

These are the things that I tried 1) Renamed the database file to as populated2 in assets folder. and tried to copy it 2)Removed the db file using window.plugins.sqlDB.remove("populated.db", 1,function(){... 3)Renamed the file as "populated.db" in assets folder and then tried to copy aswindow.plugins.sqlDB.copy("populated.db",1, function() {... 4)Stored the data base as populated .sql and copied it as window.plugins.sqlDB.copy("populated.sql",1, function() {... 5)Tried removing the database by window.plugins.sqlDB.remove("populated.sql",1, function() {... returned a success message and again tried to copy. 6)Tried on multiple devices.

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

an-rahulpandey commented 7 years ago

To find the log in monitor plugin, you have to set the filter for your application id. Also DB needs to be pasted inside www directory rather than just the assets folder. Run this command in terminal or cmd prompt

adb shell run-as yourapplication.id

It will open the adb shell with your application directory. Then cd to databases directory and see if it's shows the database there.

On 23-Sep-2016 3:52 PM, "khanSufiyan" notifications@github.com wrote:

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. 1) I pasted the file as "populated" (and not as "populated.db" as i assumes "db" is an extension) in platforms\android\assets\ 2) tried to copy the db as window.plugins.sqlDB.copy("populated.db",1, function() {...

These are the things that I tried 1) Renamed the database file to as populated2 in assets folder. and tried to copy it 2)Removed the db file using window.plugins.sqlDB.remove("populated.db", 1,function(){... 3)Renamed the file as "populated.db" in assets folder and then tried to copy aswindow.plugins.sqlDB.copy("populated.db",1, function() {... 3)Stored the data base as populated .sql and copied it as window.plugins.sqlDB.copy("populated.sql",1, function() {... 4)Tried on multiple devices.

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/an-rahulpandey/cordova-plugin-dbcopy/issues/30, or mute the thread https://github.com/notifications/unsubscribe-auth/ACQo2Dc_QIP9HI0qIy3rLc8Sg7X02QPMks5qs6h4gaJpZM4KE0-0 .

khanSufiyan commented 7 years ago

Thanks for you reply rahul. I pasted it in the www directory but the data base is getting deleted when i build the app

an-rahulpandey commented 7 years ago

You have to paste it in the www folder which is present in your root of the project, not inside the platforms/assets/www

khanSufiyan commented 7 years ago

I pasted the .db file in the root directory still the error persists here is my log

09-27 17:19:28.014 829-1357/? W/ActivityManager: Force finishing activity com.CSIR.CSIR_Directory/.CordovaApp 09-27 17:19:28.104 829-829/? D/CrashAnrDetector: processName: com.CSIR.CSIR_Directory 09-27 17:19:28.114 829-829/? D/CrashAnrDetector: broadcastEvent : com.CSIR.CSIR_Directory data_app_crash 09-27 17:19:30.024 16240-16386/? I/Icing: doRemovePackageData com.CSIR.CSIR_Directory 09-27 17:19:30.634 829-1642/? I/ActivityManager: Process com.CSIR.CSIR_Directory (pid 16824) (adj 11) has died. 09-27 17:19:31.984 829-1358/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.CSIR.CSIR_Directory 09-27 17:19:32.044 17108-17108/? E/dalvikvm: >>>>> com.CSIR.CSIR_Directory [ userId:0 | appId:10261 ] 09-27 17:19:32.164 829-2104/? D/ThermalMonitor: Foreground Application Changed: com.CSIR.CSIR_Directory 09-27 17:19:35.764 17108-17304/? V/info: Open sqlite db: /data/data/com.CSIR.CSIR_Directory/databases/CSIR_DB.db 09-27 17:19:35.764 17108-17304/? D/dalvikvm: Trying to load lib /data/app-lib/com.CSIR.CSIR_Directory-1/libsqlc-native-driver.so 0x425e7bd0 09-27 17:19:35.784 17108-17304/? D/dalvikvm: Added shared lib /data/app-lib/com.CSIR.CSIR_Directory-1/libsqlc-native-driver.so 0x425e7bd0 09-27 17:19:35.784 17108-17304/? D/dalvikvm: No JNI_OnLoad found in /data/app-lib/com.CSIR.CSIR_Directory-1/libsqlc-native-driver.so 0x425e7bd0, skipping init 09-27 17:19:37.064 16394-16424/? I/UpdateIcingCorporaServi: Updating corpora: APPS=com.CSIR.CSIR_Directory, CONTACTS=MAYBE

khanSufiyan commented 7 years ago

hey finally go it it working thanks for this great plugin thanks for helping me out