1

An error occurs when I try to add mulitple rows to the sqlite database. With a single row theres no problem. Additionally the app crashes due to this on a samsung galaxy s2, but not on a nexus.

Heres the code for creating the table:

 private static final String DATABASE_CREATE = "create table "
        + TABLE_AWARDS + "(" + COLUMN_ID
        + " integer primary key autoincrement, " + COLUMN_TITLE
        + " text not null, " + COLUMN_DESCRIPTION + " text not null, "
        + COLUMN_TYPE + " integer not null, " + COLUMN_ACHIEVED
        + " integer not null " + ");";

And the code which inserts the rows into the table:

 private static final String DATABASE_INSERT = "INSERT into  awards (title, description, type, achieved) VALUES "
        + "('Speed maximum', 'Stay', 1 , 0),"
        + "('Speed maximum', 'under 130 km/h', 2 , 0);";

According to the answer of the stackoverflow question you've given me the syntax should be:

private static final String DATABASE_INSERT = "INSERT into  'awards' "+
        "SELECT 'Speed maximum' AS 'title', 'under 150 km/h' AS 'description', 1 AS 'type', 0 AS 'achieved'"
            +" UNION SELECT 'Speed maximum', 'under 130 km/h', 2 , 0"
            +" UNION SELECT 'Speed maximum', 'under 100 km/h', 3 , 0";

But this doesn't work either.

Chris
  • 1,072
  • 2
  • 17
  • 39

2 Answers2

0

In eclipse go to debug mode put a break point after your query and at run-time see the value of strings like DATABASE_INSERT , post it here or you can see the error there itself.

android2013
  • 415
  • 2
  • 5
0
  1. Please try change the names of columns.
  2. To insert best solution is using insertOrThrow method (read in internet).
  3. Please give me your full code of class extensing SQLiteOpenHelper.
  4. Give logcat log please.
TN888
  • 7,235
  • 9
  • 42
  • 82