Skip to content

Commit 219cf50

Browse files
committed
fixed behavior
added more tests
1 parent 51203e5 commit 219cf50

File tree

7 files changed

+306
-428
lines changed

7 files changed

+306
-428
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release notes
22

3+
## 1.1.0
4+
- Fixed multiple `GROUP BY` not working
5+
- Improved tests
6+
37
## 1.0.0
48
- Fixed crashed
59
- Now is **mandatory** to specify `ORDER BY` when using `LIMIT`

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ val query = """
6363
SELECT distinct $ARTIST_ID, $ARTIST, count(*) as songs, count(distinct $ALBUM_ID) as albums
6464
FROM ${Media.EXTERNAL_CONTENT_URI}
6565
WHERE $IS_PODCAST = 0
66-
GROUP BY $ARTIST_ID AND $ARTIST
66+
GROUP BY $ARTIST_ID
6767
HAVING songs >= 5 AND albums >= 2
6868
ORDER BY $ARTIST_KEY DESC
6969
LIMIT 10
@@ -81,7 +81,7 @@ contentResolver.query(
8181
"count(*) as songs",
8282
"count(distinct $ALBUM_ID) as albums"
8383
),
84-
selection = "$IS_PODCAST = 0 ) GROUP BY $ARTIST_ID AND $ARTIST AND HAVING (songs >= 5 AND albums >= 2",
84+
selection = "$IS_PODCAST = 0 ) GROUP BY $ARTIST_ID HAVING (songs >= 5 AND albums >= 2",
8585
selectionArgs = null,
8686
sortOrder = "$ARTIST_KEY DESC LIMIT 20 OFFSET 2"
8787
)

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ class MainActivity : AppCompatActivity() {
1313
super.onCreate(savedInstanceState)
1414
setContentView(R.layout.activity_main)
1515

16-
var start = System.currentTimeMillis()
16+
example()
17+
}
18+
19+
20+
private fun example(){
1721
var query = """
1822
SELECT *
1923
FROM ${MediaStore.Audio.Media.EXTERNAL_CONTENT_URI}
2024
""".trimIndent()
2125

22-
var cursor = contentResolver.querySql(query)
23-
cursor.close()
24-
25-
val time1 = System.currentTimeMillis() - start
26-
start = System.currentTimeMillis()
26+
contentResolver.querySql(query).close()
2727

2828
query = """
2929
SELECT distinct $ARTIST_ID, $ARTIST, count(*) as songs, count(distinct $ALBUM_ID) as albums
@@ -36,7 +36,7 @@ class MainActivity : AppCompatActivity() {
3636
OFFSET 2
3737
""".trimIndent()
3838

39-
cursor = contentResolver.querySql(query)
39+
val cursor = contentResolver.querySql(query)
4040
val result = mutableListOf<Artist>()
4141
while (cursor.moveToNext()){
4242
val item = Artist(
@@ -48,10 +48,9 @@ class MainActivity : AppCompatActivity() {
4848
result.add(item)
4949
}
5050

51-
val time2 = System.currentTimeMillis() - start
52-
5351
cursor.close()
5452
}
53+
5554
}
5655

5756
data class Artist(

library/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ android {
77
defaultConfig {
88
minSdkVersion 16
99
targetSdkVersion 28
10-
// sdk_version, major, minor, fixes
11-
versionCode 28_1_0_10
12-
versionName "1.0"
10+
// sdk_version, major, minor, patch(1st)beta(2nd)
11+
versionCode 28_1_1_0
12+
versionName "1.1.0"
1313

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

0 commit comments

Comments
 (0)