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

Refactor callers of String.toVertxPgClientPreparedSql to work for different DBs #23

Open
ShreckYe opened this issue Jan 18, 2025 · 0 comments

Comments

@ShreckYe
Copy link
Member

ShreckYe commented Jan 18, 2025

The formats of prepared SQLs for PostgreSQL and MySQL are different in Vert.x SQL Client. The function String.toVertxPgClientPreparedSql should not be called for MySQL. Ideally, this function should be moved to the "postgresql" module.

PostgreSQL:

SELECT * FROM users WHERE id=$1

MySQL:

SELECT * FROM users WHERE id=?

The function:

@ExperimentalEvscApi
fun String.toVertxPgClientPreparedSql(): String {
val stringBuilder = StringBuilder(length * 2)
var i = 1
for (c in this)
if (c == '?') stringBuilder.append('$').append(i++)
else stringBuilder.append(c)
return stringBuilder.toString()
}

@ShreckYe ShreckYe changed the title Refactor String.toVertxPgClientPreparedSql to work for different DBs Refactor callers of String.toVertxPgClientPreparedSql to work for different DBs Jan 18, 2025
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