Android Sqlite Changing Database? - android

I am a beginner android learner who has been given a very challenging but interesting project to do . I have to write a program to give different quizes but the difficult part is the changing database. Any teacher who wants to use it write his questions in a C# software then it generates a sqlite database as an output to be given to the android app and then the teacher will be able to give different exams from his students on their android phones . The point is students install the apk just once and from that time on, they just be given the sqlite file to be read by their android app . how is it possible to read sqlite in a way like mentioned?
Tnx in advance .

Your C# program needs to generate DDL, which you can then execute in your Android app. Your Android code might look something like this:
String ddl = "CREATE TABLE [Quiz] (" +
"[id] INTEGER NOT NULL ON CONFLICT ROLLBACK PRIMARY KEY, " +
"[question] CHAR NOT NULL)";
db.execSQL (ddl);
If you want to see samples of DDL, install Sqlite on on your development machine and install a sql tool, such as SQLite Expert, to create and view a database.

In general I think this is not a good design approach. It would be easier to read the quiz data from a HTTP-Request. But if you are not in a position to change the requirements you are searching for an approach to import a sql-backup at runtime like described here:
https://stackoverflow.com/a/6542214/1515052
If this does not fit your needs exactly, you should do your research first, start an implementation and rephrase your question where exactly lies your problem.

Related

How to generate SQLite entity relationship diagram from database file

I am trying to reverse engineering to a database file that an android application generates. It gives me a SQLite file in .db extension. I tried pass it through SQLite Browser and it gets me the tables, but no relationships also every table givesme "id" for primary key. Any help or suggestions on how to approach this would be great, thanks!
After extensive search, I found that you can do it without running a server using DBVisualizer.
After you install DBVisualizer, import your database, then expand the database connection which is on the left under Connections, expand schema then double click Tables. Switch to References tab in the pane on the right and you'll have your diagram.
I have also found about SchemaCrawler which is free and open source unlike DBVisualizer and also doesn't require running a server, but have yet to get it to work. You can follow this guide if you wish to use this instead.
Example of ER diagram generated by DBVisualizer
The quickest way to do this is by using the SchemaCrawler web application. If you need to keep your database private, you can use the approach suggested by #freshpasta
In the MySQL workbench select Database option from the menus available on the top of the screen,there you will get reverse engineer option. Click on it then select your server and database on which you want to create ER diagram and click next.
A bit late but if you got IntelliJ IDE product you can connect to your "Database" and generate a diagram for it.
https://www.jetbrains.com/help/pycharm/creating-diagrams.html
Note: IntelliJ is paid tool,so you may need a paid version for this trick
Or just enable free trial till you do this task.
References
https://www.jetbrains.com/products/compare/?product=idea&product=idea-ce
https://www.jetbrains.com/datagrip/features/

How to store Data for my application

I'm really new to programming apps - so this question might sound a bit strange:
I'm trying to program an app in android studio, where people can upload different things (basically strings and links put together in some kind of "package") and other peoble can then decide what "packages" they want to add inside their app. However after downloading, this data should be stored on their device and not just in the memory of the phone so that they can use it after restarting the app (and also if theres no internet connection). Do you have any idea what would be the best way to store this data both on the phone and in a database and how to synchronize the data on the phone with the selected data from the database. I really dont want to know how to do this exactly but would rather like some basic ideas and maybe you could tell me what kinds of stuff i should learn in order to succeed and what kind of database would be best here (firebase, MYSQL,..)?
Thanks a lot,
Andi
First of all you should decide what DB you are going to use.
In my opinion all RDBMs are good, but using Sqlite in order to achieve best performance on android devices is a good idea.
In your case you need server-side DB and application too.
(Depend on the scenario and framework you use can be different (sql,mysql,PostgreSQL,oracle,...)).
About how to sync local database with server-side you can download new DB from server and replace it with previous one, if you need previous user data you can have 2 different table and update one by downloading it from server, and save id or any identical row from specific package that already saved by user.
These are some question has been already answered in Stackoverflow
java - How to update table in sqlite?
java - SQLite in Android How to update a specific row
Create SQLite database in android
If you are talking about local databases. Go for Realm or look up a good ORM on github (Object relational mapping, you dont have to write SQL queries explicitly) .
I would suggest Realm which is very fast and user friendly.

How can I save many sentences efficiently in Android?

I am developing an app for Android which will have many sentences organized with categories. Besides, this app must upgrade the sentences with a mysql database.
My question is: How can I save many sentences efficiently?
I have thought creating a sqlite database in my pc and add it to the app project. Is that possible?
Maybe, could I do another thing?
Like you said; create your database using sqlite on desktop and then include it in your application in the \assets folder. Use it normally in your application.
Remember to always us _id as the primary key in your tables.
For more details check this blog post

How to check SQLite file consistency (health check)

I am using a SQLite database file in my Android application that is created from several pieces stored in the assets folder by using the following approach:
ReignDesign - Using your own SQLite database in Android applications
On completion of the assemby process I would like to check if the database was correctly merged. The following approaches crossed my mind:
MD5 hash comparison
Checking table existence and entry counts
Which approach would you recommend? Is there a better way?
Thanks,
Philipp
http://www.sqlite.org/pragma.html#pragma_integrity_check.
In Api 11, SQLiteDatabase has a method isDatabaseIntegrityOk for checking integrity of SQLite databases :
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#isDatabaseIntegrityOk()
And source code is avaible here :
https://github.com/android/platform_frameworks_base/blob/ics-mr1-release/core/java/android/database/sqlite/SQLiteDatabase.java#L2585
It's easy to backport on old devices.
I had a similar situation in an application I'm developing. There are a variety of ways of doing it; but in the end I stopped worrying about what exactly and how to best measure database integrity, and instead focused on 'is my database usable by my application'.
So basically I test whether: 1) I can open the SQLite database properly 2) I can perform queries on the database and 3) Whether the result for a pre-defined query returns what is expected.
So basically: include a table with a record of known ID that gives a value that you know, then try to read that value. Checking the table count can't hope.
That said I'm hoping someone here with a good knowledge of DB systems will explain a) exactly what PRAGMA integrity_check does and b) how reliable it is and how efficient it is compared with manual table checks.
I would prefer second approach on the first one both with respect to performance and ease of coding.

android database issue

I am new to android.
I have an application where i am calculating the loan amount based on salary. For that I have a database of salary,Tax and medicare column. The tax and medicare depends upon the salary bracket. I want to know how to create the database and access it through the coding.
If any good sample code example is there please give the link.
Thanks in advance.
Here you can find a simple and straight forward tutorial from anddev.
Summarize from the tutorial:
Description: We'll need to to the
following things:
Create a DataBase (generally this is done just once)
Open the DataBase
Create a Table (generally this is done just once)
Insert some Datasets
Query for some Datasets
Close the Database
Android uses the SQLITE database Read up on it here: http://www.screaming-penguin.com/node/7742
I assume you have read the official Android developer guide. If not, there is a wealth of information about doing anything and everything you'd want on an Android device.
Since Android uses SQLite as it's internal database, I'd suggest reading documentation about it + the data storage part of Android guide.
These would be good starting points.
You may try this simple tutorial with nice graphics illustration.

Categories

Resources