yahoo / squidb

SquiDB is a SQLite database library for Android and iOS
https://github.com/yahoo/squidb/wiki
Apache License 2.0
1.31k stars 132 forks source link

Question: is it possible to use a specific database file, and also upload it later? #157

Closed AndroidDeveloperLB closed 8 years ago

AndroidDeveloperLB commented 8 years ago

Suppose I have a database file (which I got from somewhere over the Internet) that I want squidb to handle, is it possible?

My guess is that I need to use "getDatabasePath" for the class that extends "SquidDatabase". But then what's the purpose of getName?

Is it also safe to later upload the file? I mean, if the file is locked by the library, how can I tell it to release its hooks on it (if I even need it) to upload the file?

sbosley commented 8 years ago

You would have to put the file in the path expected by Android. Override getName() to return just the file name, and copy the file to the path returned by getDatabasePath(). getDatabasePath() is not meant to be overridden; it's just a getter -- use it to figure out where Android expects the file to exist.

For squidb's purposes, calling close() on your SquidDatabase and implementing some kind of mechanism to make sure that no other threads are accessing the database during file manipulation time should be enough to safely access it. Note though that SQLite uses auxiliary files as well. These are generally cleaned up when the db is closed, but they may linger in some edge cases (crashes, etc) -- see https://www.sqlite.org/tempfiles.html. In such edge cases, it may not be the case that uploading the single db file will be enough to open the db. If you want to upload the entire database, you would probably have to make sure squidb isn't using it, but might also have to figure out what the other auxiliary files are named and upload them as well. Exposing those files is not something that squidb does since operating on them directly is generally not great practice, so you will need to figure out a way to access whatever those files are apart from squidb in order to do that.

jdkoren commented 8 years ago

Alternatively, don't upload the database file directly. Upload the data in some other format (JSON, etc), and only the data you really need to send.