Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

ResultSet.columnNames order does not match ResultSet order #61

Closed
@Zwergal

Description

@Zwergal

Hi,

i found a Bug in the order of the columnnames in a result.
Here is a small example to reproduce the bug:

import com.github.mauricio.async.db.postgresql.PostgreSQLConnection
import com.github.mauricio.async.db.postgresql.util.URLParser
import com.github.mauricio.async.db.util.ExecutorServiceUtils.CachedExecutionContext
import com.github.mauricio.async.db.{RowData, QueryResult, Connection}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}

object BugExample {

  def main(args: Array[String]) {

    val configuration = URLParser.parse("jdbc:postgresql://localhost:5432/testdb?user=postgres&password=test")
    val connection: Connection = new PostgreSQLConnection(configuration)

    Await.result(connection.connect, 5 seconds)
    val sql = "SELECT id, username, age, email, firstname, lastname FROM person"
    val future: Future[QueryResult] = connection.sendQuery(sql)

    val mapResult: Future[Any] = future.map(queryResult => {
      queryResult.rows match {
        case Some(resultSet) => {
          println("SQL-Query: " + sql)
          println("resultSet columnNames : " + resultSet.columnNames.mkString("[", ",", "]"))
          println("resultSet columnValues: " + resultSet.head.mkString("[", ",", "]"))
          val row : RowData = resultSet.head
          row(0)
        }
        case None => -1
      }
    })

    val result = Await.result( mapResult, 5 seconds )

    println(result)

    connection.disconnect
  }
}

You need a postgresql database installed with a database "testdb" and the following table:

CREATE TABLE public.person (
                id bigserial,
                username VARCHAR NOT NULL UNIQUE,
                firstname VARCHAR NOT NULL,
                lastname VARCHAR NOT NULL,
                email VARCHAR NOT NULL UNIQUE,
                age BIGINT NOT NULL,
                PRIMARY KEY (id)
);

INSERT INTO person(
            username, firstname, lastname, email, age)
    VALUES ('test', 'John', 'Doe', 'jd@example.com', 26);

When you run the example you get the following output:

SQL-Query: SELECT id, username, age, email, firstname, lastname FROM person
resultSet columnNames : [email,username,firstname,age,lastname,id]
resultSet columnValues: [1,test,26,jd@example.com,John,Doe]

As you can see, the order from the columnnames does not match the order of the resultSet values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions