0

I have a table name, inside a database, called (ie) : ARI5-v006

The minus sign appears to be a problem.

Here's the query code:

String table_name="ARI5-v006";
Cursor dataCount = bdd.rawQuery("select * from " + table_name, null);

It causes an error.

Here's the logcat:

Caused by: android.database.sqlite.SQLiteException: near "-": syntax error (code 1): , while compiling: select * from ARI5-v006

I've tried add quote to the table_name.... but not working.

Any idea?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
morbak
  • 317
  • 4
  • 17
  • 1
    http://stackoverflow.com/questions/3694276/what-are-valid-table-names-in-sqlite – PeterMmm Sep 11 '14 at 07:32
  • Make back ticks arround the table name. – Jens Sep 11 '14 at 07:34
  • I've do this: `Cursor dataCount = bdd.rawQuery("select * from " + "'"+table_name+"'", null);` but LogCat said the table isn't found: `android.database.sqlite.SQLiteException: no such table: ARI5-v006 (code 1): , while compiling: select * from 'ARI5-v006'`. – morbak Sep 11 '14 at 07:49

1 Answers1

2

You can:

  1. Change the table name and use '_' instead of '-'
  2. Try quoting the table name in square braces. Ex: "select * from [ARI5-v006]" --> bdd.rawQuery("select * from [" + table_name + "]", null);