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
I get an error when running the following piece of code.
From what I managed to deduce, a piece of code is executed in object SqliteDbType in the insertReturning method (val id = idCodec.readSingle(rs) ) and instead of the ID it returns the number of the created row.
Code Sample
//> using scala 3.6.2
//> using dep com.augustnagro::magnum:1.3.1
//> using dep com.zaxxer:HikariCP:6.2.1
//> using dep org.xerial:sqlite-jdbc:3.47.1.0
//CREATE TABLE test (
// id TEXT PRIMARY KEY,
// value INTEGER NOT NULL
//);
import com.augustnagro.magnum.*
import com.zaxxer.hikari.HikariDataSource
@SqlName("test")
@Table(SqliteDbType, SqlNameMapper.CamelToSnakeCase)
case class TestRow(id: String, value: Int)
class TestRepo extends Repo[TestRow, TestRow, String]
@main
def main(): Unit =
println("Hello world!")
val ds = HikariDataSource()
ds.setJdbcUrl("jdbc:sqlite:database.db")
transact(ds):
new TestRepo()
.insertReturning(TestRow(id = "testId", value = 1))
Stacktrace:
Hello world!
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" com.augustnagro.magnum.SqlException: Error executing query:
INSERT INTO test (id, value) VALUES (?, ?)
SELECT * FROM test WHERE id = ?
With message:
java.util.NoSuchElementException: None.get
at com.augustnagro.magnum.util$package$.handleQuery(util.scala:350)
at com.augustnagro.magnum.SqliteDbType$$anon$1.insertReturning(SqliteDbType.scala:158)
at com.augustnagro.magnum.Repo.insertReturning(Repo.scala:44)
at main$package$.main$$anonfun$1(main.scala:29)
at com.augustnagro.magnum.util$package$.transact$$anonfun$1(util.scala:38)
at scala.util.Using$.resource(Using.scala:296)
at com.augustnagro.magnum.util$package$.transact(util.scala:44)
at com.augustnagro.magnum.util$package$.transact(util.scala:47)
at main$package$.main(main.scala:28)
at main.main(main.scala:19)
Caused by: java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:627)
at scala.None$.get(Option.scala:626)
at com.augustnagro.magnum.SqliteDbType$$anon$1.insertReturning$$anonfun$1$$anonfun$1(SqliteDbType.scala:158)
at com.augustnagro.magnum.util$package$.timed(util.scala:193)
at com.augustnagro.magnum.SqliteDbType$$anon$1.insertReturning$$anonfun$1(SqliteDbType.scala:158)
at scala.util.Using$Manager.scala$util$Using$Manager$$manage(Using.scala:202)
at scala.util.Using$Manager$.apply(Using.scala:255)
... 9 more
The text was updated successfully, but these errors were encountered:
Sorry for the delay @polkx & @riccardomerolla , was away for the holidays. When implementing insertReturning, I (sanely) assumed that it was returning the generated integer ID. However, that does not appear to be true.
The xerial/sqlite-jdbc driver doesn't appear to support this usecase at all:
I get an error when running the following piece of code.
From what I managed to deduce, a piece of code is executed in object
SqliteDbType
in theinsertReturning
method (val id = idCodec.readSingle(rs)
) and instead of the ID it returns the number of the created row.Code Sample
Stacktrace:
The text was updated successfully, but these errors were encountered: