zio / zio-quill

Compile-time Language Integrated Queries for Scala
https://zio.dev/zio-quill
Apache License 2.0
2.15k stars 348 forks source link

Problem with Aliasing columns with with sql keywords #2738

Open MalkaSteinberg opened 1 year ago

MalkaSteinberg commented 1 year ago

Version: 4.6.0: Module: quill-jdbc: Database: Sql Server:

I have a field in my table name 'TO'. When running a select statement quill runs this: select a."to" as to from email a

I would expect that quill would wrap the to as follows: select a."to" as [to] from email a

quill should be responsible for escaping reserved sql words.

@getquill/maintainers

joelsonoda commented 1 year ago

@MalkaSteinberg , I don't know if you found a workaround for this, but in our projects we have extended the context

trait NamingSqlServerJdbcContext extends SqlServerJdbcContext:

  override def tokenizeColumnAlias(strategy: NamingStrategy, column: String): String =
    strategy.column(column)

  override def tokenizeFixedColumn(strategy: NamingStrategy, column: String): String =
    strategy.column(column)

  override def tokenizeTableAlias(strategy: NamingStrategy, table: String): String =
    strategy.table(table)

  override def tokenizeIdentName(strategy: NamingStrategy, name: String): String =
    strategy.default(name)

If the naming strategy doesn't quote the column alias, fixed column and table alias, those should be quoted as well.