scylladb / gocqlx

All-In-One: CQL query builder, ORM and migration tool
Apache License 2.0
929 stars 122 forks source link

Support for uppercase table name #168

Open PeterIvanov opened 4 years ago

PeterIvanov commented 4 years ago

https://github.com/scylladb/gocqlx/blob/master/qb/select.go#L83 https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/ucase-lcase_r.html

Unless enclosed in double quotation mark, identifier is case-insensitive. Currently, construrct like this:

table.New(table.Metadata{
  Name:    "aBc", 
  ...
})

doesn't work unless you manually add quotes to name, which is creepy and seems likely to break something in the future. Possibly, the same problem exists for some other identifiers.

The solution seems to be to always enclose identifiers in double quotation mark in generated statements.

mmatczuk commented 4 years ago

OK, so what is the use-case you have multiple tables with similar names like Abc and aBc?

PeterIvanov commented 4 years ago

My particular use-case is that the table name is provided externally, the table itself happens to have uppercase letters in its name, so queries provided by (for example) table.Table::Insert() fail.

PeterIvanov commented 4 years ago

https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/ucase-lcase_r.html Table 'What Works and What Doesn't' here describes the issue some more. If a table is created with uppercase characters, queries with lowercase name (or with uppercase name, unquoted) won't work.

mmatczuk commented 4 years ago

Adding that for tables names is trivial, adding for fields is more complicated. Would you mind sending a PR?

PeterIvanov commented 4 years ago

I'm not sure there isn't some subtle issues here or backwards compatibility concern that I'm not aware of, hence the issue, not a PR. Yes, I'll consider sending a PR. Just thought it is a good thing to report this as an issue right away.