Which type to use to store values that are in an Arraylist<> in an Sqlite table?

Asked

Viewed 54 times

1

I have the following table in Sqlite:

db.execSQL("create table amc(_id integer primary key autoincrement, nome text not null, contratada text not null, tipo text not null, data text not null, respostas integer not null, resultado float);");

The field respostas is the following list ArrayList<Integer> respostas = new ArrayList<>(); how can I save the values of this ArrayList<> on my table amc in the field respostas?

Would it be possible?

  • Will your list array store integers? create an integer column

  • @Andersonhenrique Yes, this is already done. I entered more information in my question.

  • 1

    I imagine it would be better to create another table to store the answers. You will need to link using an id (fk / pk) with the amc table. The question is whether you have a limited number of answers.Since they will be a field for each answer in the Answers table.

  • Do not change the content of the question, if you have a new question, ask a new one.

  • Is there no need to create another table? If there is not, try to rearrange it there to play in varchar even

1 answer

2


VARCHAR, there is no other way, you will have to convert and manage it in the database both to write and to read.

There are some strategies you can use, the most common is to separate each element by comma.

Sqlite is fantastic, flexible, but leaves it all on its own to do on hand.

Depending on the case the BLOB may be more appropriate.

Typing of the Sqlite.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.