SQLite没有这样的专栏 [英] SQLite no such column

查看:106
本文介绍了SQLite没有这样的专栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建用于保存标题,内容和内容的数据库时,我没有此类列异常按日期降序排序,我已经检查了很多次,无法知道原因.我的代码是

I'm getting no such column exception when creating database to save title, content & sort it by date descending order, i've checked many times and unable to know the reason. My code is

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中遇到如下错误

I'm getting the error in logcat as follows

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
                                                                          `

推荐答案

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

SQLite异常,指示SQL解析存在错误 或执行.

A SQLite exception that indicates there was an error with SQL parsing or execution.

您应该在 DESC 部分中添加额外的 SPACE .

整理 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 .

Then Clean-Rebuild-Run.

这篇关于SQLite没有这样的专栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆