简体   繁体   English

“SELECT”附近:语法错误(代码 1)

[英]Near "SELECT": syntax error (code 1)

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.我正在尝试对字段“标签”中的数据使用 SELECT DISTINCT 语句并将其放入 String[],但我没有得到。

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":我尝试了不同的选项,但在这一行和我的方法“getTags”中我永远得到这个错误:

Cursor cursor = db.getTags();

What am I doing wrong?我究竟做错了什么?

upd:更新:

Code that is actually being executed: code 1 code 2实际正在执行的代码代码 1代码 2

Simply change the following line:只需更改以下行:

SELECT tags FROM appDb_table_project WHERE SELECT DISTINCT tags

to

SELECT tags FROM appDb_table_project

Try add " space "尝试添加“空格”

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);
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM