-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix incompatible types in generated bind* and cursor.get* statements #2110
Conversation
| database.data_Adapter.boolean2Adapter.decode(cursor.getLong(2)!! == 1L), | ||
| cursor.getLong(3)?.let { database.data_Adapter.boolean3Adapter.decode(it == 1L) }, | ||
| cursor.getLong(4)!!.toByte(), | ||
| cursor.getLong(5)?.toByte(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With DialectType#decode(…)
this should actually be cursor.getLong(5)?.let { it.toByte() }
. The reason it is like this is that the default adapters are intercepting it before DialectType#decode(…)
can. I think this is fine atm, as we're planning on removing the default adapters (#2056) and the generated code is basically the same.
@@ -351,6 +357,243 @@ class MutatorQueryTypeTest { | |||
|""".trimMargin()) | |||
} | |||
|
|||
@Test fun `types bind fine in HSQL`(dialect: DialectPreset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for how verbose all these tests are 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its np, i mostly find them important for tracking regressions than reviewing for codegen
fun decode(value: CodeBlock): CodeBlock = value | ||
|
||
fun encode(value: CodeBlock): CodeBlock = value | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to have the decode
and encode
functions on the DialectType
itself instead of in IntermediateType
to move the dialect specific kotlin types knowledge out of DialectType
, and to allow different dialects to decode or encode their types how they wish (inspired by ResultSet
in Java). Lmk if moving it somewhere else makes more sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dope, thank you
@@ -351,6 +357,243 @@ class MutatorQueryTypeTest { | |||
|""".trimMargin()) | |||
} | |||
|
|||
@Test fun `types bind fine in HSQL`(dialect: DialectPreset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its np, i mostly find them important for tracking regressions than reviewing for codegen
For example, when binding
SMALLINT
, it is (currently) bound withbindLong(smallint)
, butSMALLINT
is implicitlykotlin.Short
. With this PR we'd dobindLong(smallint.toShort())
for this to compile.This feels like a pretty major bug as all of the non-SQLite dialects we support will fail unless you only use a specific subset of the supported dialect types (e.g.,
BIGINT
is implicitlykotlin.Long
, so there's no type conversion to do there).