0

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 .

  • You are overthinking it. Just make the android read from an SQLite database on the SDCard. Replace the SQLite db, on the SDCard, with the new one created by C# as and when neccesary. – IAmGroot Mar 05 '17 at 18:00
  • Tnx but this kind of replacing is a challenging part for me ,at least. And let me explain that security is an important thing since it's an app of giving exams so there should not be any databases after one exam is finished . – Pedram Yazdipoor Mar 06 '17 at 16:05

2 Answers2

0

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.

Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
  • unfortunately I cant change the generations of the C# software because this project must be done in the way I mentioned . – Pedram Yazdipoor Mar 05 '17 at 17:40
  • Then what is your question about? Regardless, somehow you need to create a database and that is easily done with DDL. What does the C# software produce? – Peri Hartman Mar 05 '17 at 20:18
  • As I mentioned my question topic before, I am not in a position to change anything with the output of C# software and if I was I didn't know how to . I am required to read a sqlite database every time when a different exam is going to be done . I know about DDL and I think we call it Queries. But I will be given a complete sqlite with two or three tables to be read in my app – Pedram Yazdipoor Mar 06 '17 at 16:12
  • I understand you have some sort of "given" output from your C# app. I don't know what a "complete sqlite" is. I presume you are getting DDL. If so, I have shown you how to build the sqlite database from the DDL you are given. If this is not going to work for you, please explain. – Peri Hartman Mar 06 '17 at 20:15
  • let me explain it easier . I have to use this kind of ddl to create tables as u mentioned . but what I say is, I have to read a sqlite database with 3 tables . The c# software generates sqlite and my app will read this output . I didnt know how to read this sqlite file after installing the app that If I have understood it correctly the process is like restoring the given database with filing(java filing) . Let me appreciate this attention from you . Tnx – Pedram Yazdipoor Mar 08 '17 at 15:06
  • Can you add to your original post? Please provide a sample of the output of the C# software. Also, please explain: are you trying to figure out how to read a file? Or are you trying to figure out how to convert the file contents to something usable by sqlite? Or is it some other problem? – Peri Hartman Mar 08 '17 at 18:52
0

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.

Community
  • 1
  • 1
Simulant
  • 19,190
  • 8
  • 63
  • 98