使用ORDER BY时数据类型不匹配错误 [英] data type mismatch error when using ORDER BY

查看:96
本文介绍了使用ORDER BY时数据类型不匹配错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用本地sqlite数据库的android应用.

I've got an android app using a local sqlite database.

private SQLiteDatabase mDb;

当我运行此查询时,我会根据需要在pid等于id的行上获取我的Cursor:

when I run this query I get my Cursor over rows with pid equal to id, as desired:

mDb.query(true, PT_TABLE, new String[] {KEY_PID, KEY_TID}, 
    KEY_PID+" = "+id, null, null, null, null, null);        

当我运行以下查询以获取相同的结果集时(按pid排序),我得到" android.database.sqlite.SQLiteException:数据类型不匹配"

when I run the following query, aiming to get that same result set, ordered by pid I get "android.database.sqlite.SQLiteException: datatype mismatch"

mDb.query(true, PT_TABLE, new String[] {KEY_PID, KEY_TID}, 
    KEY_PID+" = "+id, null, null, null, null, KEY_PID+" DESC");

有什么想法吗?

推荐答案

看起来您有点混为一谈.根据

It looks like you got just a little mixed up. According to the SQLiteDatabase.query documentation, the last argument is the LIMIT clause. The second to last is the ORDER BY clause.

Cursor query (boolean distinct, 
            String table, 
            String[] columns, 
            String selection, 
            String[] selectionArgs, 
            String groupBy, 
            String having, 
            String orderBy, // <-- ORDER BY
            String limit)

编辑

但是,还有另一个

But, there is also another SQLiteDatabase.query where ORDER BY would be last

Cursor query (String table, 
            String[] columns, 
            String selection, 
            String[] selectionArgs, 
            String groupBy, 
            String having, 
            String orderBy)

这篇关于使用ORDER BY时数据类型不匹配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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