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

Usage of colon in a comment tries to bind it as a variable #47

Open
busches opened this issue Dec 2, 2021 · 3 comments
Open

Usage of colon in a comment tries to bind it as a variable #47

busches opened this issue Dec 2, 2021 · 3 comments
Labels

Comments

@busches
Copy link

busches commented Dec 2, 2021

If I execute a query that has a comment that contains a colon, kotliquery attempts to use that colon as a bind parameter and we get the following error:

The column index is out of range: 1, number of columns: 0.
org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.
	at org.postgresql.jdbc.PgPreparedStatement.setNull(PgPreparedStatement.java:192)
	at kotliquery.Session.populateParams$lambda-1(Session.kt:291)
	at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
	at kotliquery.Session.populateParams(Session.kt:91)
	at kotliquery.Session.createPreparedStatement(Session.kt:116)
	at kotliquery.Session.execute(Session.kt:204)
	at kotliquery.action.ExecuteQueryAction.runWithSession(ExecuteQueryAction.kt:9)
	at kotliquery.Session.run(Session.kt:231)

Reproduction:

val sql = """
-- Some dumb comment :shrug:
SELECT 1;
"""

val url = "jdbc:postgresql://$host:$port/$database"
val dbSession = sessionOf(url, username, password)

using(dbSession) { session ->
    session.run(queryOf(sql, emptyMap()).asExecute)
}

Executing the same code straight against Postgres does not fail, as the commented out code is properly ignored.

Kotliquery version: 1.6.1

@seratch seratch added the bug label Feb 22, 2022
@seratch
Copy link
Owner

seratch commented Feb 22, 2022

Hi @busches, thanks for reporting this issue. To resolve this issue, the named parameter feature #10 should have great consideration of comments.

@busches
Copy link
Author

busches commented Feb 22, 2022

Yea, I'm not following what you mean. This is a bug in the named parameter feature.

@seratch
Copy link
Owner

seratch commented Feb 22, 2022

I'm not following what you mean

Oh, was my comment confusing? To make my above comment clearer, I meant that the named parameter feature should be improved to support comment parts properly. I'm sure that we are on the same page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants