Skip to content

Commit d1395af

Browse files
committed
added tests
updated readme and changelog fixed erroneous behavior updated version to stable
1 parent f75132a commit d1395af

File tree

10 files changed

+547
-69
lines changed

10 files changed

+547
-69
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
# Release notes
2+
3+
## 1.0.0
4+
- Fixed crashed
5+
- Now is **mandatory** to specify `ORDER BY` when using `LIMIT`
6+
- Now is **mandatory** to specify `WHERE` when using `GROUP BY`
7+
- Now throws an exception when using `HAVING` without `GROUP BY`
8+
- Now throws an exception when using `OFFSET` without `LIMIT`
9+
- Added tests
10+
11+
## 1.0.0-beta02
12+
- Renamed `contentResolver.queryParser(..)` to `contentResolver.querySql(..)` for better discoverability
13+
214
## 1.0.0-beta01
3-
- first release
15+
- First release

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Allows to write SQL statements instead of using `contentResolver.query(...)`.
1818
The library add an extension function to ContentResolver named
1919
`querySql(query: String, selectionArgs: Array<String>? = null)`
2020

21+
###Limitations
22+
When using `LIMIT` keyword, you need to specify also `ORDER BY`.<p>
23+
When using `GROUP BY` keyword, you need to specify also `WHERE`.
24+
2125
##Getting started
2226
Step 1. Add the JitPack repository to your build file
2327
Add it in your root build.gradle at the end of repositories:

app/src/androidTest/java/dev/olog/contentresolversql/example/ExampleInstrumentedTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.olog.contentresolversql.example
22

3+
import android.provider.MediaStore
34
import androidx.test.InstrumentationRegistry
45
import androidx.test.runner.AndroidJUnit4
56

@@ -21,4 +22,17 @@ class ExampleInstrumentedTest {
2122
val appContext = InstrumentationRegistry.getTargetContext()
2223
assertEquals("dev.olog.contentresolversql", appContext.packageName)
2324
}
25+
26+
@Test
27+
fun assertSimpleQuery(){
28+
val appContext = InstrumentationRegistry.getTargetContext()
29+
30+
31+
32+
var cursor = appContext.contentResolver.query(
33+
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
34+
null, null, null, null
35+
)
36+
}
37+
2438
}

app/src/main/java/dev/olog/contentresolversql/example/MainActivity.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.olog.contentresolversql.example
22

3-
import android.net.Uri
43
import android.os.Bundle
54
import android.provider.MediaStore
65
import android.provider.MediaStore.Audio.AlbumColumns.ARTIST
@@ -14,6 +13,7 @@ class MainActivity : AppCompatActivity() {
1413
super.onCreate(savedInstanceState)
1514
setContentView(R.layout.activity_main)
1615

16+
var start = System.currentTimeMillis()
1717
var query = """
1818
SELECT *
1919
FROM ${MediaStore.Audio.Media.EXTERNAL_CONTENT_URI}
@@ -22,6 +22,9 @@ class MainActivity : AppCompatActivity() {
2222
var cursor = contentResolver.querySql(query)
2323
cursor.close()
2424

25+
val time1 = System.currentTimeMillis() - start
26+
start = System.currentTimeMillis()
27+
2528
query = """
2629
SELECT distinct $ARTIST_ID, $ARTIST, count(*) as songs, count(distinct $ALBUM_ID) as albums
2730
FROM ${MediaStore.Audio.Media.EXTERNAL_CONTENT_URI}
@@ -33,7 +36,6 @@ class MainActivity : AppCompatActivity() {
3336
OFFSET 2
3437
""".trimIndent()
3538

36-
contentResolver.query(Uri.parse(""), null, null, null, null)
3739
cursor = contentResolver.querySql(query)
3840
val result = mutableListOf<Artist>()
3941
while (cursor.moveToNext()){
@@ -46,6 +48,8 @@ class MainActivity : AppCompatActivity() {
4648
result.add(item)
4749
}
4850

51+
val time2 = System.currentTimeMillis() - start
52+
4953
cursor.close()
5054
}
5155
}

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
minSdkVersion 16
99
targetSdkVersion 28
1010
// sdk_version, major, minor, fixes
11-
versionCode 28_1_0_02
12-
versionName "1.0-beta02"
11+
versionCode 28_1_0_10
12+
versionName "1.0"
1313

1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515

library/src/androidTest/java/dev/olog/contentresolversql/ExampleInstrumentedTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)