I am faced with problem:
Caused by: android.database.sqlite.SQLiteException: near "SELECT": syntax error (code 1): , while compiling: SELECT tags FROM appDb_table_project WHERE SELECT DISTINCT tags
I have:
public static final String DB_NAME = "appDbProject";
public static final int DB_VERSION = 1;
public static final String DB_TABLE = "appDb_table_project";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_DESCRIPTION = "description";
public static final String COLUMN_TAGS = "tags";
public SQLiteDatabase mDB;
public Cursor getTags() {
String[] column = new String[] { COLUMN_TAGS };
//return mDB.query(DB_TABLE, column, "SELECT DISTINCT tags", null, null, null, null);
//return mDB.query(true, DB_TABLE, new String[] { COLUMN_TAGS }, null, null, COLUMN_TAGS, null, null, null);
//String query ="SELECT DISTINCT tags FROM appDb_table_staff";
//return mDB.rawQuery(query, null);
return mDB.query(true, DB_TABLE, new String[] { COLUMN_TAGS }, null, null, COLUMN_TAGS, null, null, null);
}
I'm trying to use SELECT DISTINCT statement for my data in field "tags" and put it into String[], but I did not get.
Cursor cursor = db.getTags();
String[] array = new String[cursor.getCount()];
int i = 0;
while (cursor.moveToNext()) {
String tag = cursor.getString(cursor.getColumnIndex("tags"));
array[i] = tag;
i++;
}
String[] from = array;
int[] to = new int[] { R.id.textViewTags };
I tried different options, but forever I get this error in this line and inside of my method "getTags":
Cursor cursor = db.getTags();
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire