0

I have the following query:

cursor = helper.getReadableDatabase().rawQuery("select _id, Likert-Skala from "+inAd+" where Name like ?" ,
            new String[] { "%" + str2 + "%" });

Now, I get a "no such table" error for Likert-Skala. However, if I do this:

Cursor c = helper.getReadableDatabase().rawQuery("SELECT * FROM "+inAd+" ",  null);
    DatabaseUtils.dumpCursor(c);

Then my result is, for instance:

09-30 18:42:11.212: I/System.out(907):    Likert-Skala=1.63

So the table is clearly there, and there is no typo. Anyone have an Idea?

newnewbie
  • 993
  • 2
  • 11
  • 26
  • 2
    i think the issue is your column name has a hyphen, which SQLite probably interprets as subtraction between two other terms. – Karakuri Sep 30 '14 at 23:03
  • if that is so, then why is the error message: "No such column: Likert Skala"? and when I ask for all the columns, "Likert-Skala" comes out fine? – newnewbie Sep 30 '14 at 23:05
  • I think you are passing the wrong string it should be: "SELECT _id FROM Likert-Skala" +inAd+ "WHERE Name like ?" – Juniar Sep 30 '14 at 23:35
  • Because it thinks you are selecting an expression `(Likert - Skala)`, rather than a name "Likert-Skala". It tries to find an operand with the name "Likert" and subtract another operand with the name "Skala". I suggest renaming your columns to not include characters that sqlite may interpret as operators. – Karakuri Oct 01 '14 at 00:26

1 Answers1

1

You might have to do away with the "-" sign. Otherwise this should be fine:

String sql = "SELECT _id FROM Likert-Skala WHERE Name like ?";
String[] str = {"%" + str2 + "%"};
Cursor cursor = this.helper.getReadableDatabase().rawQuery(sql, str); 
Juniar
  • 1,269
  • 1
  • 15
  • 24
  • @newnewbie I came to understand that Likert_Skala is valid with "_" sign or [Likert-Skala] is valid with "[ ..]" brackets. Here is the link: http://stackoverflow.com/questions/3694276/what-are-valid-table-names-in-sqlite – Juniar Oct 01 '14 at 01:23