Skip to content

Commit 9a9ab67

Browse files
committed
Fixed #12 AsyncResultSet's columnIndex should be 1-origin to be compatible with JDBC
1 parent 9a09a7b commit 9a9ab67

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

core/src/main/scala/scalikejdbc/async/internal/AsyncResultSetImpl.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ private[scalikejdbc] class AsyncResultSetImpl(rows: IndexedSeq[RowData])
3838

3939
// WrappedResultSet API
4040

41-
override def any(columnIndex: Int): Any = currentRow.map(_.apply(columnIndex)).orNull[Any]
41+
override def any(columnIndex: Int): Any = {
42+
// To be compatible with JDBC, index should be 1-origin
43+
// But postgresql-async/mysql-async is 0-origin
44+
val index0origin = columnIndex - 1
45+
currentRow.map(_.apply(index0origin)).orNull[Any]
46+
}
47+
4248
override def any(columnLabel: String): Any = currentRow.map(_.apply(columnLabel)).orNull[Any]
4349

4450
override def bigDecimal(columnIndex: Int): java.math.BigDecimal = any(columnIndex) match {

core/src/test/scala/sample/PostgreSQLSampleSpec.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ class PostgreSQLSampleSpec extends FlatSpec with ShouldMatchers with DBSettings
1313
val createdTime = DateTime.now.withMillisOfSecond(0)
1414
val al = AsyncLover.syntax("al")
1515

16+
it should "count" in {
17+
val countFuture: Future[Long] = AsyncDB.withPool { implicit s =>
18+
withSQL { select(sqls.count).from(AsyncLover as al) }.map(_.long(1)).single.future().map(_.get)
19+
}
20+
val c = Await.result(countFuture, 5.seconds)
21+
c should be > 0L
22+
}
23+
1624
it should "select a single value" in {
1725
val resultFuture: Future[Option[AsyncLover]] = AsyncDB.withPool { implicit s =>
1826
withSQL { select.from(AsyncLover as al).where.eq(al.id, 1) }.map(AsyncLover(al)).single.future()

0 commit comments

Comments
 (0)