Android uses provider to query tables that are not exposed in the same database

Source: Internet
Author: User

"Original" Reprint please Cabernet blog address http://www.cnblogs.com/scarecrow-blog/p/6266042.html

Personal feeling this is a bug in Android provider, nonsense less say directly on the code

1      Publicstring getcanonicaladdresses (String recipient_ids) {2String[] Ids=recipient_ids.split ("");3System.out.println ("Recipient_ids:" +recipient_ids);4String addressresult= "";5          for(inti = 0; i < ids.length; i++) {6Cursor cur=readsmsactivity. This. Getcontentresolver (). Query (Uri.parse ("content://mms/"), 7                     Newstring[]{"* from canonical_addresses where _id=" +ids[i].tostring () + "--"},NULL,NULL,NULL);8             if(Cur.getcount () >0){9                  while(Cur.movetonext ()) {TenString _id=cur.getstring (Cur.getcolumnindex ("_id")); OneString address=cur.getstring (Cur.getcolumnindex ("Address")); Aaddressresult+= "{" +_id+ "," +address+ "}"; -                 } -             } the         } -         returnAddressresult; -}

Looking at lines 6th and 7th, MMS provider actually queries MMS-related content and does not provide canonical-address query functionality. However, the above writing, through the query method into the parameters of the projection directly write almost the entire query statement, and after the "-" to realize the direct query of the DB through MMS provider canonical_addresses table function.

Principle:

As we all know, projection is usually the name of each column in the table to be looked up, so the SQL statement that was finally spelled out to execute in the database is similar to the SELECT projection from table where ....

But here the projection is completely replaced with another complete statement, so the final spell looks roughly like the select * from canonical_addresses where _id= "2"-the From table where ....

The "--" in Sql is the meaning of the comment. This method is the use of this point, the original provider through the URI-qualified query statement into another query statement, thus obtaining a private table query results.

Android uses provider to query tables that are not exposed in the same database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.