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

Ionic 4 problem copy database.db #64

Open nicowxdvd opened 4 years ago

nicowxdvd commented 4 years ago

I have an app on ionic 4 with angular, with a populated bd. but when copying the BD I get error 400, if I run the app again I get error 516. I don't know what to do to make it work well. here my code

init() { this.platform.ready().then((readySource) => { console.log('Platform ready from', readySource); // Platform now ready, execute any required native code this.sqliteDbCopy.copy("database.db", 0) .then((res: any) => console.log(' t ' + res)) .catch((error: any) => console.error(error)); });

}

If I put the bd in the www folder, executing the run android command will delete the file

Captura de Pantalla 2020-03-19 a la(s) 15 22 07

Exerlol commented 4 years ago

@an-rahulpandey Hi there, first of all thanks for a great plugin, I'm having exactly same problem as nicowxdvd, putting db file inside www folder and running ionic cordova build android / ionic cordova emulate android will remove it from www folder... Any suggestion how to work around this?

an-rahulpandey commented 4 years ago

@nicowxdvd What is the full error you get when you receive error code 400? 516 means db already exists at the location. @Exerlol you can try creating a hook which can copy the db

kgajjar44 commented 4 years ago

@nicowxdvd your database file location is incorrect you have to place database in ionic android or iOS platform under www folder below are location for the same:

  1. Android - platforms/android/app/src/main/assets/www
  2. iOS - platforms/ios/www

You can copy to this particular location using config.xml resource-file tag for each platform

  1. Android - <resource-file src="dblocationinproject" target="app/src/main/assets/www/database.db" />
  2. iOS - <resource-file src="dblocationinproject" target="../../www/database.db" />

For example I can see in your screenshot your database location is: src/www/database.db