I have setup a new project using GreenDAO, was able to generate with ExampleDAO using DaoGenerator. Everything works fine.
I also have a prepopulated sqlite database shipped in android assets folder, on app run, it is being copied to android database system path.
Now I want to integrate with SqlCipher, to have my database encrypted... If anybody can help or give example app, that would be a great help.
Please let me know if these solutions work for you:
A sample project with the integration:
https://github.com/ywenblocker/GreenDao-SQLCipher
Here is the original thread with all discussion about how to implement it:
https://github.com/greenrobot/greenDAO/issues/6
Edit:
After removing the private libraries from the build path, and adding them again, I found a not implemented method of DevOpenHelper:
sDaoMaster = new DaoMaster(sDevOpenHelper.getWritableDatabase("secret-key"));
There was no such method implemented on the sample project, unfortunately it looks like you should implement the getWritable and getReadable methods all by yourself. Without these modifications you would get a non-encrypted database, as shown by screenshoots below:
Device ScreenShot:
Database snapshot:
Related
I have an Android app where I use a SQLIte DataBase. I am using the app and the DB is already big. Now I want to give this app with its DB to my coworkers. Where and How to put the DB for release? I have the DB in my phone but I need it in assets folder. I was trying but it doesn't work. I tried to copy the DB directly however I read that Android compress files in that folder. Please, any solution, thank you in advance.
http://blog.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Visit this link. It contains the easiest and well described answer for your question.
You can use emulator Like GenyMotion and any other emulator. Run your app on emulator then just go to Android Studio->Tools->Android Device Monitor Then select the emulator and in the file Explorer you can find your db file . and then export from the device and export to your desktop. here you can give it to any one.
You can use your own SQLite database by adding it to assets folder. The best way is to use Android SQLiteAssetHelper. Better than reinventing the wheel.
Here the excerpts from its readme:
An Android helper class to manage database creation and version
management using an application's raw asset files.
This class provides developers with a simple way to ship their Android
app with an existing SQLite database (which may be pre-populated with
data) and to manage its initial creation and any upgrades required
with subsequent version releases.
It is implemented as an extension to SQLiteOpenHelper, providing an
efficient way for ContentProvider implementations to defer opening and
upgrading the database until first use.
Rather than implementing the onCreate() and onUpgrade() methods to
execute a bunch of SQL statements, developers simply include
appropriately named file assets in their project's assets directory.
These will include the initial SQLite database file for creation and
optionally any SQL upgrade scripts.
I'm working with Visual Studio 2013 and the Cordova Tools package.
I have most of my app working, and I'm now ready to add the DB logic. I have a DB full of quotes, and I need to tie that into the app.
Following this link: adding dynamic data with SQLite
I was able to get SQLite to talk to a DB (using the sqlitePlugin) However, I can't figure out how to use a pre-populated DB. It always created a new empty DB. I've found several articles on the web that keep saying "put the db in the www folder"... but the Cordova project doesn't have a www folder.
Putting the SQLite DB file in the root doesn't work, and I tried using a path and putting it in a sub-dir. No luck there either.
Has anyone been able to make this work?
Old question, but I will answer to serve as a reference: I solved this problem by changing the plugin. Previously, I was using plugin cordova-sqlite-storage (https://github.com/litehelpers/Cordova-sqlite-storage), but it doesn't copy the prepopulated database. It always creates an empty one.
After days of fighting, I uninstalled the plugin and installed this one: cordova-plugin-sqlite (https://www.npmjs.com/package/cordova-plugin-sqlite). This one works like a charm, it will copy the DB in the www folder to the device. Just follow the instructions and don't forget the createFromLocation parameter.
The strange bit it that both plugins are from the same author, and both seem to be active projects. Go figure.
Old question, but I will answer to serve as a reference (2)!
Pre-populated SQLite is supported by cordova-sqlite-ext project.
The steps are simple:
put the database file in the www directory and open the database like: www/sample.db
Then, use:
var db = window.sqlitePlugin.openDatabase({name: "sample.db", createFromLocation: 1});
More information: https://github.com/litehelpers/cordova-sqlite-ext#pre-populated-databases
Many sites and answers point to use Cordova-sqlite-storage for this. In fact, this feature was in this project, but it was moved to Cordova-sqlite-ext (they are from the same creator).
I don't recomend using cordova-plugin-sqlite. It is deprecated.
Im REALLY struggling to get a pre baked db4o database to work inside my android app.
If i include it in the /res/raw folder then read it, it doesn't work.
If i copy it to the app_data or sdcard then try and read it, it will act as if im opening a new database and provide me with 0 entries on queries.
I was previously just creating all my entries when the app was first opened but as the db grew, so did the creation time to unsustainable levels.
I would really, really appreciated any help you can give me. It would be perfect if i can include my pre-populated db4o file in the app.
Additional Info:
I have double checked the db4o file with ome and theres no issue with the db creation on my local machine.
Thanks in advance.
If any one falls into the same trap as me here's the answer:
On android the class is injected into the db4o db with the package name prefixed to the class name by defualt. So accessing from another application will look be looking for +.
I am trying to build an app that uses an already created db ... I already found a tutorial on
how to copy it to the corect location so it can be used by a ContentProvider.But the problem
is that I also need to protect that data ...I already found SQLCipher which is supposed to
protected the db ... but none of the samples I found mentions on how to copy your own. I
keep gettin an error the ContentProvider was not found .. .
Ok I found the solution I managed to build my database using either an sqlCipher tool or either exporting the db as SQLite commands and then creating the new Ciphered database using the SQLCipher libs...and getReadableDatabse and getWritableDatabase did not work for me I had to use openDatabase and pass RWR FLAG it is strange that SQLCipher implements them because I couldn't get them to work ... do not know if I have been clear enough ... if anyone else has this problem he can let me know.
Some of my users are reporting that they cannot correctly open sqlite databases created in Android using sqlite jdbc or other tools like sqlite browser (http://sourceforge.net/projects/sqlitebrowser/).
Here is an example database with the problem:
http://pocket-for-android.1047292.n5.nabble.com/Desktop-Version-Screenshots-Work-In-Progress-tp4383220p4456017.html
This sqlite db was created on a HTC Sensation, running Android 2.3.3 and Sense 3.0.
The exact problem is that if you look at the file in a text editor you can see a bunch of tables being created but if you try and run "select * from groups;" you will get an SQLException: file is encrypted or is not a database.
I have tried using "select sqlite_version;" to see if it is a versioning issue - the sqlite browser says 3.6.18.but different tools give me different version numbers... not sure what is going on with that.
I should also point out that my app copies the db directly from the device (/data/data/com.citc.wallet/databases/wallet.db) onto Dropbox.
Any help would be really appreciated.
The solution was that the zentus project is not working with the latest versions of SQLite.
Fortunately someone is keeping a fork maintained here: http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC
All I had to do was replace the jar with the xerial one and it all worked. Xerial sqlite jdbc is in my opinion the best way of connecting to SQLite in Java (I tried several of the libs).
I am also getting the same problem.
But once I have changed the database name it resolved.
So, just try it by creating new database