SQLDelight in Android: Getting Started

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

Part 1: Preparation & Setup

07. Use Grouping Statements

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. Add Functions to Tables Next episode: 08. Utilize Transactions & Rollbacks

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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)
}