https://kotlinlang.org logo
#exposed
Title
# exposed
j

Jaap Beetstra

04/02/2024, 8:33 AM
Is there a good way to force Exposed to escape a column name? My DB server was just upgraded from 10.4 to 10.11, and now my query fails on a column named ‘offset’. Apparently this was added as a keyword in MariaDB 10.6, but the most recent Connector/J driver does not return it in DatabaseMetaData.getSQLKeywords() yet, so Exposed does not escape it.
p

Phil Richardson

04/03/2024, 10:51 AM
Can you not just provide the columns name already quoted?
Copy code
val _offset = varchar("`offset`", length = 42)
j

Jaap Beetstra

04/03/2024, 11:11 AM
That seems to work, except for
SchemaUtils.createMissingTablesAndColumns(..)
which does not detect that the column already exists. But I can live without that, so it is probably the best solution for now, thanks.
c

Chantal Loncle

04/04/2024, 3:25 AM
Hi @Jaap Beetstra You could also provide the column name in regular quotes (
"\"offset\""
), which forces Exposed to create an identifier wrapped in backticks for MariaDB. It produces an identifier that looks like:
Copy code
`"offset"`
but this resolved the issue with
createMissingTablesAndColumns()
on my end. If you know that there are plans for the connector to return 'offset' as a keyword, great. But if not, please consider opening a ticket on YouTrack with all relevant details, so we can look into it and add the keyword(s) to our vendor-specific map (used alongside returned metadata values).
j

Jaap Beetstra

04/04/2024, 8:41 AM
Hi @Chantal Loncle, thanks for the suggestion about the regular quotes, I’ll give it a try. The MariaDB connector should get an update, I submitted an issue earlier and it is already fixed and scheduled for the next version (3.4.0). https://jira.mariadb.org/browse/CONJ-1170
👍 1