Multi-table queries in SQL ContentProvider

Source: Internet
Author: User

Reference: http://www.eoeandroid.com/thread-550720-1-1.html

 /*** Multi-table query *@paramCompanyID Search by Company ID *@return         */         PublicArraylist<menuitemmodel>querymultitable (String companyid) {//projection represents the columns returned by the query resultsstring[] Projection = {                                "Menutreeitems." +Menutreeitemsmodelids.itemid,"Menutreeitems." +Menutreeitemsmodelids.companyid,"Menutreeitems." +Menutreeitemsmodelids.descriptions,"Menutreeitems." +Menutreeitemsmodelids.fileid,"Menutreeitems." +menutreeitemsmodelids.isdeleted,"Menutreeitems." +Menutreeitemsmodelids.itemtype,"Menutreeitems." +Menutreeitemsmodelids.name,"Menutreeitems." +Menutreeitemsmodelids.parentitemid,"Menutreeitems." +Menutreeitemsmodelids.rowversion,"Filedetails." +basecolumns._id,"Filedetails." +Filedetailsids.extension,"Filedetails." +Filedetailsids.file_name}; //here the URI of the multi-table query is the Focus Content_uri (URI of the current table)
"Filedetails" (represents the table name for another table)
Content://athority/table1/table2Uri uri = Uri.withappendedpath (Content_uri, "Filedetails");
Cursor C=NULL; Contentproviderclient Client=mcontentresolver.acquirecontentproviderclient (mulitablecontentprovider.authority); Try{C= Client.query (URI, projection, menuitemmodelids.companyid+ "=" +companyid,NULL,NULL); } Catch(RemoteException e) {e.printstacktrace (); } //create ArrayList to hold dataArraylist<menuitemmodel> dataList =NewArraylist<menuitemmodel>(); //move the pointer to the first rowC.movetofirst (); while(!C.isafterlast ()) {String ItemId=c.getstring (C.getcolumnindex (basecolumns._id)); String Parentitemid=c.getstring (C.getcolumnindex (Menutreeitemsmodelids.parentitemid)); String name=c.getstring (C.getcolumnindex (menutreeitemsmodelids.name)); String Descriptions=c.getstring (C.getcolumnindex (menutreeitemsmodelids.descriptions)); String fileId=c.getstring (C.getcolumnindex (Menutreeitemsmodelids.fileid)); String ItemType=c.getstring (C.getcolumnindex (Menutreeitemsmodelids.itemtype));//String CompanyID = c.getstring (C.getcolumnindex (Roomandtabletreeitemsmodelids.name));String rowVersion =c.getstring (C.getcolumnindex (menutreeitemsmodelids.rowversion)); String isDeleted=c.getstring (C.getcolumnindex (menutreeitemsmodelids.isdeleted)); String FileName=c.getstring (C.getcolumnindex (filedetailsids.file_name)); Menuitemmodel Model=NewMenuitemmodel (); Model.setitemid (ITEMID); Model.setparentitemid (Parentitemid); Model.setname (name); Model.setdescriptions (descriptions); Model.setfileid (FILEID); Model.setitemtype (ItemType); Model.setrowversion (rowVersion); Model.setisdeleted (isDeleted); Model.setfilename (FileName); Datalist.add (model); C.movetonext (); } c.close (); returndataList; }

Multi-table queries in SQL ContentProvider

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.