Skip to content
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

RawRowMapper not mapping correctly Boolean values in Postgres 11.5 using Kotlin #177

Open
ropjov opened this issue Sep 28, 2020 · 0 comments

Comments

@ropjov
Copy link

ropjov commented Sep 28, 2020

Description

When using the rawRowMapper and raw queries on PSQL, the boolean values are not mapped correctly, but when creating the query through query builder it works.

Environment

OS: Ubuntu
IDE: IntellIJ
Language: Kotlin 1.4
OrmLite versions:
compile group: 'com.j256.ormlite', name: 'ormlite-core', version: '5.1'
compile group: 'com.j256.ormlite', name: 'ormlite-jdbc', version: '5.1'
DB connector: compile group: 'org.postgresql', name: 'postgresql', version: '9.3-1100-jdbc4'

How to reproduce

  1. Create a Postgres database and a table with the following schema
CREATE TABLE test(
    id SERIAL NOT NULL PRIMARY KEY,
   is_enabled BOOLEAN NOT NULL DEFAULT TRUE
);
  1. Create its connection source in code: i.e.
    val testServiceConnection: ConnectionSource? = JdbcConnectionSource(testServiceDBString, testServiceDBUser, testServiceDBPassword)

  2. Create the model:

@DatabaseTable(tableName = "test")
data class Test(
    @Generated
    @DatabaseField(generatedId = true, columnName = "id")
    var id: Int,

    @DatabaseField(columnName = "is_enabled")
    var isEnabled: Boolean
) {
    private constructor() : this(
        -1,
        true
    )
}

  1. Insert two elements to the table, one true and one false

  2. Create the DAO and two queries:

    private val dao: Dao<Test, Int> =
        DaoManager.createDao(ORMLiteConnections.testServiceDBORM, Test::class.java)

    fun getAll(): List<Test> {
       return userDao.queryBuilder().query()
    }

    fun getAllRaw(): List<Test> {
       val returnList: MutableList<Test> = emptyMutableList()
       userDao.queryRaw("SELECT * FROM test", dao.rawRowMapper).forEach { returnList.add(it) }
       return returnList
    }
  1. Execute both and see that in the first one, the result is correct, but on the second one it is not
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant