{"action":"opened","issue":{"url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/1125","repository_url":"https://api.github.com/repos/Raizlabs/DBFlow","labels_url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/1125/labels{/name}","comments_url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/1125/comments","events_url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/1125/events","html_url":"https://github.com/Raizlabs/DBFlow/issues/1125","id":198137770,"number":1125,"title":"4.0.0-beta3 - Using content URI path segments returns null cursor","user":{"login":"jtrollkarl","id":5025614,"avatar_url":"https://avatars.githubusercontent.com/u/5025614?v=3","gravatar_id":"","url":"https://api.github.com/users/jtrollkarl","html_url":"https://github.com/jtrollkarl","followers_url":"https://api.github.com/users/jtrollkarl/followers","following_url":"https://api.github.com/users/jtrollkarl/following{/other_user}","gists_url":"https://api.github.com/users/jtrollkarl/gists{/gist_id}","starred_url":"https://api.github.com/users/jtrollkarl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtrollkarl/subscriptions","organizations_url":"https://api.github.com/users/jtrollkarl/orgs","repos_url":"https://api.github.com/users/jtrollkarl/repos","events_url":"https://api.github.com/users/jtrollkarl/events{/privacy}","received_events_url":"https://api.github.com/users/jtrollkarl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-30T11:43:21Z","updated_at":"2016-12-30T11:43:21Z","closed_at":null,"body":"DBFlow Version: 4.0.0-beta3\r\nIssue Kind (Bug/Question): Issue with using content URI path segments\r\n\r\nDescription: \r\nI am trying to retrieve only specific rows which contain the following matching fields: `dateInserted` and `mealType` with the content URI `foodItemsDateType` . However, when using this URI, the cursor always returns `null`\r\n\r\nHere is all my code, including the test I wrote in Robolectric:\r\n\r\nFoodsDatabase.class\r\n\r\n```\r\n@ContentProvider(\r\n        authority = FoodsDatabase.AUTHORITY,\r\n    database = FoodsDatabase.class,\r\n    baseContentUri = FoodsDatabase.BASE_CONTENT_URI)\r\n@Database(name = FoodsDatabase.NAME, version = FoodsDatabase.VERSION)\r\npublic class FoodsDatabase {\r\n\r\n    public static final String NAME = \"FoodsDatabase\";\r\n    public static final int VERSION = 4;\r\n    public static final String AUTHORITY = \"com.example.jay.caloriedagger.provider\";\r\n    public static final String BASE_CONTENT_URI = \"content://\";\r\n\r\n\r\n    private static Uri buildUri(String... paths) {\r\n        Uri.Builder builder = Uri.parse(FoodsDatabase.BASE_CONTENT_URI + FoodsDatabase.AUTHORITY).buildUpon();\r\n        for (String path : paths) {\r\n            builder.appendPath(path);\r\n        }\r\n        Log.d(\"URI BUILDER\", builder.build().toString());\r\n        return builder.build();\r\n    }\r\n\r\n    @TableEndpoint(name = DayProviderModel.ENDPOINT, contentProvider = FoodsDatabase.class)\r\n    public static class DayProviderModel{\r\n\r\n        public static final String ENDPOINT = \"Day\";\r\n        \r\n        @ContentUri(path = ENDPOINT, type = ContentUri.ContentType.VND_MULTIPLE + ENDPOINT)\r\n        public static final Uri CONTENT_URI = buildUri(ENDPOINT);\r\n        \r\n    }\r\n\r\n\r\n    @TableEndpoint(name = FoodItemProviderModel.ENDPOINT, contentProvider = FoodsDatabase.class)\r\n    public static class FoodItemProviderModel{\r\n\r\n        public static final String ENDPOINT = \"FoodItem\";\r\n\r\n        @ContentUri(path = ENDPOINT, type = ContentUri.ContentType.VND_MULTIPLE + ENDPOINT)\r\n        public static final Uri CONTENT_URI = buildUri(ENDPOINT);\r\n\r\n        @ContentUri(\r\n                type = ContentUri.ContentType.VND_MULTIPLE,\r\n                path = \"FoodItem/#/#\",\r\n                segments = {@ContentUri.PathSegment(segment = 1, column = \"dateInserted\"),\r\n                            @ContentUri.PathSegment(segment = 2, column = \"mealType\")\r\n                }\r\n        )\r\n        public static Uri foodItemsDateType_URI(String date, String mealType){\r\n            return buildUri(date, mealType);\r\n        }\r\n\r\n    }\r\n}\r\n```\r\nFoodItem.class\r\n\r\n```\r\n@Table(database = FoodsDatabase.class)\r\npublic class FoodItem extends BaseModel{\r\n\r\n    @PrimaryKey(autoincrement = true)\r\n    long id;\r\n\r\n    @Column\r\n    long foodId;\r\n\r\n    @Column\r\n    String dateInserted;\r\n\r\n    @Column\r\n    String mealType;\r\n\r\n    @Column\r\n    String name;\r\n\r\n\r\n    public String getDateInserted() {\r\n        return dateInserted;\r\n    }\r\n\r\n    public void setDateInserted(String dateInserted) {\r\n        this.dateInserted = dateInserted;\r\n    }\r\n\r\n    public long getId() {\r\n        return id;\r\n    }\r\n\r\n    public void setId(long id) {\r\n        this.id = id;\r\n    }\r\n\r\n    public String getMealType() {\r\n        return mealType;\r\n    }\r\n\r\n    public void setMealType(String mealType) {\r\n        this.mealType = mealType;\r\n    }\r\n\r\n    public String getName() {\r\n        return name;\r\n    }\r\n\r\n    public void setName(String name) {\r\n        this.name = name;\r\n    }\r\n\r\n    public long getFoodId() {\r\n        return foodId;\r\n    }\r\n\r\n    public void setFoodId(long foodId) {\r\n        this.foodId = foodId;\r\n    }\r\n}\r\n```\r\n\r\nRobolectric test class:\r\n\r\n```\r\n@RunWith(RobolectricTestRunner.class)\r\n@Config(constants = BuildConfig.class, sdk = 23)\r\npublic class ContentProviderTest {\r\n\r\n    private ContentResolver mContentResolver;\r\n    private Day day;\r\n    String date = \"TESTDATE\";\r\n\r\n    @Before\r\n    public void setUp(){\r\n        FlowManager.init(ShadowApplication.getInstance().getApplicationContext());\r\n        Robolectric.buildContentProvider(FoodsDatabase_Provider.class);\r\n        mContentResolver = RuntimeEnvironment.application.getContentResolver();\r\n\r\n        day = new Day();\r\n        day.setDate(date);\r\n        day.save();\r\n\r\n        FoodItem foodItem = new FoodItem();\r\n        foodItem.setDateInserted(date);\r\n        foodItem.setMealType(\"Breakfast\");\r\n\r\n        for (int i = 0; i < 5; i++){\r\n            foodItem.insert();\r\n        }\r\n    }\r\n\r\n    @After\r\n    public void cleanUp(){\r\n        Delete.tables(Day.class, FoodItem.class);\r\n        FlowManager.destroy();\r\n    }\r\n\r\n    @Test\r\n    public void contentProvider_isStable(){\r\n        ContentProviderClient client = mContentResolver.acquireContentProviderClient(FoodsDatabase.AUTHORITY);\r\n        assertTrue(shadowOf(client).isStable());\r\n    }\r\n\r\n\r\n    @Test\r\n    @RequiresApi(16)\r\n    public void contentProvider_isUnstable(){\r\n        ContentProviderClient client = mContentResolver.acquireUnstableContentProviderClient(FoodsDatabase.AUTHORITY);\r\n        assertFalse(shadowOf(client).isStable());\r\n    }\r\n\r\n    @Test\r\n    public void contentProvider_insert_delete() throws Exception{\r\n        ContentProviderClient client = mContentResolver.acquireContentProviderClient(FoodsDatabase.AUTHORITY);\r\n\r\n        //Get all days with date = \"TESTDATE\"\r\n        Cursor c = ContentUtils.query(mContentResolver, FoodsDatabase.DayProviderModel.CONTENT_URI, ConditionGroup.clause()\r\n                .and(Condition.column(   Day_Table.date.getNameAlias()).eq(date)), null, null);\r\n        assertEquals(1, c.getCount());\r\n\r\n        //Get food items where dateInserted = \"TESTDATE\"\r\n        c = ContentUtils.query(mContentResolver, FoodsDatabase.FoodItemProviderModel.CONTENT_URI, ConditionGroup.clause()\r\n        .and(Condition.column(FoodItem_Table.dateInserted.getNameAlias()).eq(date)), null, null);\r\n        assertEquals(5, c.getCount());\r\n\r\n        //Get only rows with dateInserted = \"TESTDATE\" and mealType = \"Breakfast\"\r\n        c = ContentUtils.query(mContentResolver, FoodsDatabase.FoodItemProviderModel.foodItemsDateType_URI(date, \"Breakfast\"),\r\n                ConditionGroup.clause(), null);\r\n        assertEquals(5, c.getCount());\r\n\r\n        //Delete day obj from database\r\n        ContentUtils.delete(mContentResolver, FoodsDatabase.DayProviderModel.CONTENT_URI, day);\r\n        c = ContentUtils.query(mContentResolver, FoodsDatabase.DayProviderModel.CONTENT_URI, ConditionGroup.clause(), null);\r\n\r\n        System.out.println(\"After delete there are: \"+ c.getCount()+ \" rows.\");\r\n        assertEquals(0, c.getCount());\r\n\r\n    }\r\n}\r\n```\r\n```\r\n        c = ContentUtils.query(mContentResolver, FoodsDatabase.FoodItemProviderModel.foodItemsDateType_URI(date, \"Breakfast\"),\r\n                ConditionGroup.clause(), null);\r\n        assertEquals(5, c.getCount());\r\n```\r\nThe assert shown above is what returns `null` in my test class.\r\n"}}
{"actor":{"display_login":"jtrollkarl"}}