NathanaelA / nativescript-sqlite

SQLite Bindng for NativeScript
MIT License
160 stars 53 forks source link

Copydatabase with path in the name goes wrong on iOS #135

Closed JohanBeumer closed 4 years ago

JohanBeumer commented 5 years ago

When on iOS calling copyDatabase with a path in the name, the destination is set wrong. Basically the destination should always be fs.knownFolders.documents().path + databasename without path.

NathanaelA commented 5 years ago

I think you misunderstood why the code is the way it is. If you are passing a name with a path in to the copy database, that is where you want to put the actual database. So I move the path part into the path, and then just leave the "name" part so I can get it from the assets.

You can open DB files from other locations especially if you are using encrypted databases. ;-)

JohanBeumer commented 5 years ago

Indeed I misunderstood the code the way it is. I was under the impression I was passing the the source database name. On Android it works that way on iOS it doesn't, hence the PR.

"If you are passing a name with a path in to the copy database, that is where you want to put the actual database".

For iOS this means you have to pass in a full path. For Android passing in a full path won't work as the passed in path is prepended with 'fsModule.knownFolders.currentApp().path'.

In my case I pass in a relative path 'app/assets/database/db.sqlite' which I expect to be used as the source. This works on Android. On iOS it fails as the destination is set to that same passed in relative path and copying fails.

As on iOS the destination path is set to fs.knownFolders.documents().path if you pass in just a databasename, I thought I set it as the destination in al situations.

Is this the case or am I going wrong somewhere?

NathanaelA commented 5 years ago

I'll have to double check the code; both should be the same; but I accepted a PR for Copy Database in the past, that might have broken it...

The idea is: Just pass in the name it copies it to the default database directory. If you pass the path with the name, it uses that as the location to put it... :grinning:

NathanaelA commented 5 years ago

You are correct, the code on the Android side does seem to be broken for this idea... I'll have to fix it... :grinning:

NathanaelA commented 4 years ago

This issue has been fixed on the android side. I totally forgot about it until I was handling the other PRs.