Has anyone else ran into issues with the generated...
# squarelibraries
z
Has anyone else ran into issues with the generated query files when using SqlDelight 2.0.0?
Ive reported it here already, but thought Id at least check here too. Seems like noone else has encountered this yet, which makes me think its an issue on my end of things
h
Are you sure you are using sqldelight gradle plugin 2.0.0 too? The generated code does not look like 2.0.0.
z
I believe I am!
sqldelight = { id = 'app.cash.sqldelight', version.ref = 'sqldelight' }
(sqldelight is 2.0.0)
h
Okay, this is just a common error when people have problem with code gen. The linked issue does not really create a reproducer, so it is hard to say what is the bug without a reproducer.
z
Hm, do you happen to have any snippet that shows how 2.0.0 generated code looks like? Seems like a good indicator about where the issue lies, but at the same time it really looks like Im using 2.0.0 already: resolutionStrategy { eachPlugin { if (requested.id.namespace == 'app.cash') { println(requested.version) // prints 2.0.0 } } }
h
What’s the exact error message?
I thought I changed the constructor of Query in 2.0.0, but the change was only about notify listeners, so the code looks fine.
z
Just a whole lot more of the same thing from my screenshot really.
Expecting member declaration
Function declaration must have a name
Unresolved reference: cursor
Id guess that some ( or { is misplaced and results in everything after it being incorrect.
Or rather, the Query class is incorrectly imported, I think? abstract class Query<out RowType : Any>( mapper: (SqlCursor) -> RowType, ) Is what gets called, hence the parameters dont fit:
Copy code
Query(−1_744_723_024, arrayOf("profileSql"), driver, "Profile.sq", "all",
    "SELECT * FROM profileSql") { cursor ->
  mapper(
    profileSqlAdapter.idAdapter.decode(cursor.getString(0)!!),
    profileSqlAdapter.themeAdapter.decode(cursor.getString(1)!!),
    profileSqlAdapter.currencyAdapter.decode(cursor.getString(2)!!),
    cursor.getString(3)?.let { profileSqlAdapter.selectedAccountIdAdapter.decode(it) }
  )
}
Taking another function that works as an example, heres a "FindQuery":
Copy code
public fun <T : Any> find(id: Id, mapper: (
  id: Id,
  theme: Theme,
  currency: Currency,
  selectedAccountId: Id?,
) -> T): Query<T> = FindQuery(id) { cursor ->
  mapper(
    profileSqlAdapter.idAdapter.decode(cursor.getString(0)!!),
    profileSqlAdapter.themeAdapter.decode(cursor.getString(1)!!),
    profileSqlAdapter.currencyAdapter.decode(cursor.getString(2)!!),
    cursor.getString(3)?.let { profileSqlAdapter.selectedAccountIdAdapter.decode(it) }
  )
}
I suspect that the generic Query above should in fact be something like AllQuery?
Fwiw, much of the generated code resembles the old SqlDelight code - but queries are now placed in their own files, I suppose thats enough proof to verify that Im actually on 2.0.0.
I found the Query functions
fun <RowType : Any> Query(..)
that the generated code tries to call. I wonder if the issue is related to the wrong function being looked up with the Query invocation? At least when looking at the code, it brings me to the abstract class instead of the function. Heres the intended query function:
Copy code
fun <RowType : Any> Query(
  identifier: Int,
  queryKeys: Array<out String>,
  driver: SqlDriver,
  fileName: String,
  label: String,
  query: String,
  mapper: (SqlCursor) -> RowType,
): Query<RowType> {
  return SimpleQuery(identifier, queryKeys, driver, fileName, label, query, mapper)
}
And heres the abstract class that the code points me to:
Copy code
abstract class Query<out RowType : Any>(
  mapper: (SqlCursor) -> RowType,
)
And some more digging... if I tweak the generated code ever so slightly (remove a character and add it again) then it compiles. Que?
Probably related to the generated minus sign? Generated: − When I type a minus sign, I get this: - (I can edit the generated build files with this, and they compile)
h
Which locale do you use? There is/was a similar problem: https://github.com/cashapp/sqldelight/issues/4515 using Swedish
z
Thanks for the link, Im also using the Swedish locale!
🇸🇪 1
Not how I intended to spend 7 hours today, but now that were here, thanks for being a part of the journey! Ill change my OS settings, hopefully that works until the underlying issue is fixed.
h
Maybe you could also try to configure the Gradle task:
doFirst { Locale.set(Root) }
and
doLast { Locale.set(Swedish) }
but I don’t know if this works with the Gradle workers. But would be a better workaround than changing your OS settings, if it does work.
z
Thank you, that works too! And now I can compile my project again 🙏🏽