• sql ContentProvider中的多表查询


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

     /**
             * 多表查询
             * @param companyId 根据公司id查询
             * @return
             */
            public  ArrayList<MenuItemModel> queryMultiTable(String companyId) {
                    //projection代表查询结果返回的列
                    String[] 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};
                    //在这里多表查询的URI是重点CONTENT_URI(当前表的URI)          
              //"filedetails"(代表另一张表的表名)
              // content://athority/table1/table2
    Uri 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(); } //创建ArrayList用来存放数据 ArrayList<MenuItemModel> dataList = new ArrayList<MenuItemModel>(); //将指针移动到第一行 c.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 = new MenuItemModel(); 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(); return dataList; }
  • 相关阅读:
    泊松盘采样(Poisson Disk Sampling)生成均匀随机点
    JSON神器之jq使用指南指北
    SSH(sshd)终极安全加固指南
    rocketmq 搭建配置
    SQL 片段: select top 100
    安装netframework4.8 或 .net 4.6.2 时 弹出“已处理证书链,但是在不受信任提供程序信任的根证书中终止”错误的解决方法
    win7 离线安装 vs2019 出现闪退解决办法(非常实用)
    在win7 上安装 Visual Studio 2019 步骤 及 vs2019离线安装包
    VMware 宿主机与虚拟机之间 共享剪切板 失效问题
    安装netframework4.8弹出“已处理证书链,但是在不受信任提供程序信任的根证书中终止”错误的解决方法
  • 原文地址:https://www.cnblogs.com/wjw334/p/4309406.html
Copyright © 2020-2023  润新知