m4dc4p / haskelldb

A library for building re-usable and composable SQL queries.
BSD 3-Clause "New" or "Revised" License
101 stars 17 forks source link

[Postgresql] Quote literals and escape strings by default #32

Closed useronym closed 5 years ago

useronym commented 5 years ago

Not sure if this should be merged, but I thought I'd give the option.

The problem is that if someone decides in their database schema to use identifiers (for tables or columns) which are psql-reserved keywords (such as user or group), haskelldb will currently fail to generate the proper queries. These identifiers must be quoted with ". This patch quotes all identifiers to be on the safe side, perhaps it could be adapted to only quote psql-reserved keywords.

The second change is to prepend E to all string literals, thus enabling proper interpretation of control characters.

Credits for this code should go to @chrisdone.

m4dc4p commented 5 years ago

This is fantastic. Would you be able to add a test to test\TestCases.hs?

useronym commented 5 years ago

Sure! I'll have a go at it later this week.

m4dc4p commented 5 years ago

I'm going to merge this now - if you have a chance to add tests, please do so.

useronym commented 5 years ago

Yeah sorry, I looked into it during the weekend and realized there's not simple way to run the tests with stack, plus there is some nontrivial setup involved regarding the database.

m4dc4p commented 5 years ago

No worries, thanks for your contribution!