Is there a good way to force Exposed to escape a c...
# exposed
j
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
Can you not just provide the columns name already quoted?
Copy code
val _offset = varchar("`offset`", length = 42)
j
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
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
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