1

I have all these Strings like "TEXT", "INTEGER" and so on for a text or an integer.

Is there any method to add an integer array or a float array?

Thanks!

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_TABLE = "CREATE TABLE " + TABLE + "("
            + ID + " INTEGER PRIMARY KEY,"
            + ACCOUNT + " TEXT,"
            + TYPE + " INTEGER,"
            + AMOUNT + " INTEGER,"
            + YEAR + " INTEGER,"
            + MONTH + " INTEGER,"
            + DAY + " INTEGER,"
            + EXTRA + " TEXT"  + ")";
    db.execSQL(CREATE_TABLE);
}
KodingKid
  • 971
  • 9
  • 14
kimv
  • 1,569
  • 4
  • 16
  • 26
  • Maybe another table containing the array values and the primary key of that table would be foreign key in your existing table? – KodingKid Nov 10 '14 at 09:05

3 Answers3

3

There is no way to store array. But you can do it other way.

To Store : Convert array with comma separated string and store that. (Read Convert String[] to comma separated string in java)

To Retrieve : Convert comma separated string into array. (Read How to split a comma-separated string?)

Community
  • 1
  • 1
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
2

While waiting somebody giving a better answer, you might want to try mine.

I usually save a short array (never tried for long arrays like 100+ items) just with ,

For example :

1,3,5,6,7

And then i will use split method, and add those values to a List<Integer>

Blaze Tama
  • 10,828
  • 13
  • 69
  • 129
2

The more SQL way would be to create a one-to-many relationship, and store the arrays as entries on the 'many' table.

urandom
  • 1,147
  • 2
  • 12
  • 21