Lion789
Lion789

Reputation: 4482

How to store this into SQLite Android?

Hey so I am new to using sql dbs, (mongodb / nosql fan here)... and I am trying to create an app on Android and store the information usually stored in a db for a website on the device, from what I understand I should use SQLite? (any objections let me know). When wanting to show info on a website would I be calling a get or can I just make the query calls right on the activity screen?

Lastly, this is an example of the information, and I wanted to know how I would store this as I heard that it only accepts integers, strings, and doubles?

Here is the db info needed to be stored:

Stored: {
        id: 2322d2ej2j2k, (unique)
        name: Animals, (unique)
        languages: [english, spanish],
        order: [a, b, c, d, e, f, ...],
        words: [{english: hello, spanish: hola}, {english: thanks, spanish: gracias},  ...],
        date_created: new Date()
        }

Also, for the order of letters, I want to be able to say that the order can be for letters in other languages too.

Upvotes: 0

Views: 122

Answers (1)

igorski
igorski

Reputation: 954

I'm unsure what you mean with "wanting to show info on a wesbite would I be calling a get", as the SQLite database would be stored in a sandboxed location belonging to your app, you wouldn't be making HTTP requests but talking directly to the database.

I can suggest looking into : android.database.sqlite.SQLiteOpenHelper and extend it to create a wrapper for android.database.sqlite.SQLiteDatabase for the most common CRUD operations.

While it's true that SQLite is more limited in data types (and querying operations) as full-on SQL, I find it more than adequate for most data operations. For complex Objects / nested values (like the "words"-property you describe in your question) I'd serialize these types of data into a String/JSON and reassemble it back into an actual Java Array/Object when reading it back from the database.

I prefer to think of records as entities in this sense and create a Model (extending your SQLiteOpenHelper implementation) which wraps the QSL CRUD functions to work with Java Objects and convert these to and from the data types supported by the SQLite database (i.e. create an abstraction layer such as "saveRecord" which accepts a Java value Object described the properties you posted in your question, but internally converts it to a more friendly format for storage, likewise a "getRecord" which returns a Java value Object created from the stored data).

Upvotes: 1

Related Questions