查询android系统数据库 自定义sql语句 办法

Cursor draftCursor = mResolver.query(Uri.parse("content://sms"), 
                new String[] {"canonical_addresses.address " +
                        "from sms,threads,canonical_addresses " +
                        "where sms.thread_id=threads._id and threads.recipient_ids=canonical_addresses._id and sms._id ='" + 
                        String.valueOf(target_message_id) + "' --"},
                null, null, null);

有点耍滑头,是吧,用到了sql语句中注释符号“--”

这样我们就将这个语句转化为了:

select canonical_addresses.address from sms,threads,canonical_addresses where sms.thread_id=threads._id and threads.recipient_ids=canonical_addresses._id and sms._id = 'target_message_id' -- from sms

在sql语句解析的时候,--from sms是不予解析的,所以就成功执行了前面的联合查询操作而得到了我们想要的canonical_addresses表中的address数据。

引用原文:http://blog.csdn.net/zhangzh332/article/details/6396985

原文地址:https://www.cnblogs.com/owner/p/3949399.html