SQLDelight in Android: Getting Started

Aug 3 2021 Kotlin 1.4, Android 11, Android Studio 4.1

Part 1: Preparation & Setup

7. Use Grouping Statements

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 6. Add Functions to Tables Next episode: 8. Utilize Transactions & Rollbacks

This video was last updated on Aug 3 2021

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

If you have followed along with the sample app until this point, there are only two functions missing before the UI is completely functional, and we can find them in the CollectionDetailViewModel.

insert {
}
insert {
+    INSERT INTO bug(name, description)
+    VALUES (:name, :description);
}
insert {
    INSERT INTO bug(name, description)
    VALUES (:name, :description);

+    INSERT INTO bugAttributes(bugId, size, weight, attack, defense)
+    VALUES (..., :size, :weight, :attack, :defense);
}
insert {
    INSERT INTO bug(name, description)
    VALUES (:name, :description);

    INSERT INTO bugAttributes(bugId, size, weight, attack, defense)
-    VALUES (...), :size, :weight, :attack, :defense);
+    VALUES ((SELECT last_insert_rowid()), :size, :weight, :attack, :defense);
}
fun addBug(
    name: String,
    description: String?,
    size: String,
    weight: String,
    attack: Int,
    defense: Int
) {
    database.bugQueries.insert(name, description, size, weight, attack, defense)
}