SQLite没有这样的专栏

时间:2017-10-27 12:30:36

标签: android sql database android-sqlite

创建数据库以保存标题,内容和内容时,我没有收到此类列异常。按日期降序排序,我已多次检查,无法知道原因。我的代码是

public void onCreate(SQLiteDatabase sqLiteDatabase) {
    //create our table
    String CREATE_WISHES_TABLE = "CREATE TABLE " + Constants.TABLE_NAME + "(" +
                                  Constants.KEY_ID + " INTEGER PRIMARY KEY, " +
                                Constants.TITLE_NAME + " TEXT, " +
                                Constants.CONTENT_NAME + " TEXT, " +
                                Constants.DATE_NAME + "  LONG);";
    sqLiteDatabase.execSQL(CREATE_WISHES_TABLE);

}

我的查询语句如下:

public ArrayList<MyWish> getWishes() {

    String selectQuery = "SELECT * FROM " + Constants.TABLE_NAME;

    SQLiteDatabase sqLiteDatabase = this.getReadableDatabase();

    Cursor cursor = sqLiteDatabase.query(Constants.TABLE_NAME, new String[]{Constants.KEY_ID, Constants.TITLE_NAME, Constants.CONTENT_NAME,
                    Constants.DATE_NAME}, null, null, null, null, Constants.DATE_NAME + "DESC");
}

我在logcat中收到错误如下

10-27 17:18:04.272  E/SQLiteLog: (1) no such column: recorddateDESC
10-27 17:18:04.274  E/AndroidRuntime: FATAL EXCEPTION: main`
Caused by: android.database.sqlite.SQLiteException: no such column: recorddateDESC (code 1): , while compiling: SELECT _id, title, content, recorddate FROM wishes ORDER BY recorddateDESC
                                                                          `

4 个答案:

答案 0 :(得分:5)

Caused by: android.database.sqlite.SQLiteException: no such column:
  

SQLite异常,指示SQL解析时出错   或执行。

您应该在 DESC 部分添加额外的空格

纠正 SELECT 声明。

 Cursor cursor = sqLiteDatabase.query(Constants.TABLE_NAME, new String[]{Constants.KEY_ID, Constants.TITLE_NAME, Constants.CONTENT_NAME,
                Constants.DATE_NAME}, null, null, null, null, Constants.DATE_NAME + " DESC ");

然后 Clean-Rebuild-Run

答案 1 :(得分:2)

您必须在表名和&#34; DESC&#34;

之间添加一个空格
public ArrayList<MyWish> getWishes() {

String selectQuery = "SELECT * FROM " + Constants.TABLE_NAME;

SQLiteDatabase sqLiteDatabase = this.getReadableDatabase();

Cursor cursor = sqLiteDatabase.query(Constants.TABLE_NAME, new String[]{Constants.KEY_ID, Constants.TITLE_NAME, Constants.CONTENT_NAME,
                Constants.DATE_NAME}, null, null, null, null, Constants.DATE_NAME + " DESC");

答案 2 :(得分:2)

cbind(dfL, TF = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE)) # A tibble: 90 x 4 # Groups: id, shift [9] id shift PM TF <dbl> <chr> <dbl> <lgl> 1 0 PM01 NA FALSE 2 0 PM01 -3 FALSE 3 0 PM01 NA FALSE 4 0 PM01 -2 FALSE 5 0 PM01 -1 FALSE 6 0 PM01 1 FALSE 7 0 PM01 NA FALSE 8 0 PM01 NA FALSE 9 0 PM01 NA FALSE 10 0 PM01 -2 FALSE # ... with 80 more rows 之间添加额外空格。如果它仍然显示相同的错误

  

卸载并安装您的应用程序。

答案 3 :(得分:0)

除了此处的其他答案外,在触发器中定义列时也会发生这种情况。例如,如果您在尝试删除行时看到它,请在该表中查找错误的删除触发器。