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

时间:2014-09-01 17:34:33   收藏:0   阅读:351

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

原文:http://www.cnblogs.com/owner/p/3949399.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!