Skip to content

Index: Cursor starts at 0, Statement starts at 1 #3265

@hfhbd

Description

@hfhbd

SQLDelight Version

2.0.0-SNAPSHOT

Application Operating System

JVM

Describe the Bug

open class JdbcCursor(val resultSet: ResultSet) : SqlCursor {
  override fun getString(index: Int): String? = resultSet.getString(index + 1) // index is zero-based
open class JdbcPreparedStatement(
  private val preparedStatement: PreparedStatement
) : SqlPreparedStatement {
  override fun bindBytes(index: Int, bytes: ByteArray?) {
    if (bytes == null) {
      preparedStatement.setNull(index, Types.BLOB) // JDBC setNull/setBytes is one-based
    } else {
      preparedStatement.setBytes(index, bytes)
    }
  }

In the SqlCursor the index is zero-based, so JdbcCursor needs to increment it for JDBC api.
in SqlPreparedStatement the index uses 1, 2, 3, so JdbcPreparedStatement does not need increase.

Expected: All indexes are either zero based or all one-based.

Stacktrace

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions