Fixed
Status Update
Comments
yb...@google.com <yb...@google.com> #2
You can write a dao query that'll query the sequence table:
I've not tried but this should work:
interface Dao {
@Query("SELECT seq FROM sqlite_sequence WHERE name = :tableName")
suspend fun getSequenceNumber(tableName:String) : Long?
}
Keep in mind that you cannot use this to check emptyness since seq number will not be reset if an item is deleted. One way to do it is to do a count query with limit 1.
interface Dao {
@Query("SELECT COUNT(*) FROM targetTable LIMIT 1")
suspend fun hasItems() : Boolean
}
I don't think this is worth creating an API for.
lb...@gmail.com <lb...@gmail.com> #3
@2 Seems to work well, but had to use this instead:
@Suppress("AndroidUnresolvedRoomSqlReference")
@Dao
abstract class SpecialDao {
@Query("SELECT seq FROM sqlite_sequence WHERE name = :tableName")
abstract fun getSequenceNumber(tableName: String): Long?
}
Maybe yours work too, but I just don't know how to use it.
Is this the official way to check it out though? Is there a more standard way to do it?
The IDE has put error on the code so I had to suppress it...
@Suppress("AndroidUnresolvedRoomSqlReference")
@Dao
abstract class SpecialDao {
@Query("SELECT seq FROM sqlite_sequence WHERE name = :tableName")
abstract fun getSequenceNumber(tableName: String): Long?
}
Maybe yours work too, but I just don't know how to use it.
Is this the official way to check it out though? Is there a more standard way to do it?
The IDE has put error on the code so I had to suppress it...
yb...@google.com <yb...@google.com> #4
Looks like an IDE bug. moving to the studio team. Studio sql parser should allow built in tables in queries.
be...@google.com <be...@google.com>
ko...@google.com <ko...@google.com>
ko...@google.com <ko...@google.com>
lb...@gmail.com <lb...@gmail.com> #5
What was fixed ? The IDE error?
ko...@google.com <ko...@google.com> #6
Yes, AS doesn't highlight sqlite_sequence table and it's columns as error. Additionally there is code completion for column's names.
Fix should be in 4.1 Canary 8.
lb...@gmail.com <lb...@gmail.com> #7
@6 Nice.
Description
This could be useful in case you want to check if the table has ever got anything into it, or was always empty.