Create table in Sqlite with array

Asked

Viewed 205 times

1

I am creating a Sqlite Database and I have 2 tables, a LIST table and other PRODUCTS.
The LIST table beyond the fields ID numeric, NOME text, has a PRODUCTS ARRAYLIST.
Already the PRODUCTS table only has ID numeric, NOME text, IMAGEM drawable.

My question is how to create the LIST table in Sqlite, if SQLITE types allowed do not include Arraylists?

  • It seems to me that you are trying to turn classes into tables. This doesn’t work. You have to adapt. The question is a little confusing, as much as I want to help, I can’t because I don’t understand exactly what you’re doing, I don’t have enough information, and I don’t know what your real doubt is. If you get better, I’ll answer.

  • @bigown, I’m making an app, in which each list contains a set of products and in which the user can always add more products, hence the question of the array. Your suggestion is that instead of having an array have only the PRODUCT ID in the LIST table (in addition to what I already have, list ID and List name)? I could explain myself?

  • Unfortunately we can not understand the problem you are having, the information is very truncated. It might help if you put the application code, the Sqlite structure.

2 answers

0

This table that you call the list must have a name like: customers, products, people, airplanes, cars, etc. Name your table in Sqlite and only after you have records inside it can you create a list of this table in Java.

Assuming you have created a car table that has its id fields and name then:

 - ID     NOME
 - 1      OMEGA
 - 2      PASSAT
 - 3      FUSCA

Once done, just a list with the class Util in Java:

List<Carros> lista_de_carros = new ArrayList<Carros>();

0

Sqlite does not have the type Arraylist because it makes no sense.
The Arraylist is a type that represents a list and a list is represented, in Sqlite(and not only), by a table.

Thus, you should have a table for the list(s) and another for the items in each list.

It’ll be something like this:

| Listas |
|________|
| Id     |
| Nome   |
|  ...   |
|  ...   |
|________|

|   Itens   |
|___________|
| Id        |
| ListaId   |
| ProdutoId |
| Quantidade|
|    ...    |
|    ...    |
|___________|

The fields ListaId and ProdutoId should be declared as Foreignkey with reference to the tables Lists and Products, respectively.

Browser other questions tagged

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