You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
data classCheckingAccount (
valid:Int,
valdepositAmount:Int?,
valdepositRate:Double?
)
Generated queries
@Throws(SQLException::class)
overridefuncreateCheckingAccount(depositAmount:Int?, depositRate:Double?): CheckingAccount? {
return conn.prepareStatement(createCheckingAccount).use { stmt ->
stmt.setInt(1, depositAmount)
stmt.setDouble(2, depositRate)
val results = stmt.executeQuery()
if (!results.next()) {
returnnull
}
val ret =CheckingAccount(
results.getInt(1),
results.getInt(2),
results.getDouble(3)
)
if (results.next()) {
throwSQLException("expected one row in result set, but got many")
}
ret
}
Errors
Compile Error
The JDBC methods .setInt and .setDouble expect non-nullable primitive types. Since the arguments passed into createCheckingAccount are nullable, this code cannot compile.
Runtime Errors
Additionally, .getInt and .getDouble will return 0 and 0.0 if it is null in the row. These should be null. But I am not directly running into this issue today.
Proposed Changes
Compile Errors
We need to check if the fields are null. If they are, set the parameter with stmt.setNull(1, Types.INTEGER). For example
Environment
postgresql
sqlc-gen-kotlin_1.2.0.wasm
/22b437ecaea66417bbd3b958339d9868ba89368ce542c936c37305acf373104b
Issue
Setup
I have the following migration.
I have the following query,
Generated Code
The generated model
Generated queries
Errors
Compile Error
The JDBC methods
.setInt
and.setDouble
expect non-nullable primitive types. Since the arguments passed intocreateCheckingAccount
are nullable, this code cannot compile.Runtime Errors
Additionally,
.getInt
and.getDouble
will return0
and0.0
if it isnull
in the row. These should be null. But I am not directly running into this issue today.Proposed Changes
Compile Errors
We need to check if the fields are null. If they are, set the parameter with
stmt.setNull(1, Types.INTEGER)
. For exampleThe text was updated successfully, but these errors were encountered: