Suggestion: PG::Connection#complile#726
Conversation
2cd9444 to
b0a2666
Compare
b0a2666 to
6b746e9
Compare
|
That sounds like a great idea! It's because I manually inserted too many parameters into too many queries from rails debug log in order to execute it in |
.. to replace code specific to the classes derived from PG::TypeMap. Also: - Deny binary format in SQL text - Make BinaryString working
|
I added a commit to use generic PG::TypeMap methods only and regarding binary data and binary format. The method name "compile" is not very specific. Is it used in any other database driver? How sounds |
|
@larskanis thank you. |
I don't have any strong preferences regarding this. |
This adds type casts like "::bytea" to the escaped and embedded values. To make that possible the OID => type name mapping is needed. It can be given as explicit CoderMapsBundle, is retrieved from BasicTypeMap* or retrieved from the database. Also allow `type_map` to be provided like `exec_params` allows. This patch changes `compile` to `embed_params` to be more specific. This patch changes the tests to compare `exec(embed_params())` to `exec_params()`. That ensures the processing by the database server is the same. Since binary format encoders are not usable for embedding into SQL text, this patch changes boolean encoders to text. There's no value in using a binary encoder for query parameters. It's not measurable faster than text for boolean type.
…rings This issue was raised by a rails test: test/cases/adapters/postgresql/bytea_test.rb:114
|
🎉 With the latest change the whole activerecord test suite runs through with only 2 expected errors, when I change the following AR lines to got through |
|
@larskanis thank you for your effort and covering cases I was not aware of. |
Introduce
PG::Connection#complilethat take sql string and position parameters and compiles it into a plain sql. I couldn't find another way how to do it using built-in tools. The motivation behind this implementation:The downside of this implementation is that it can't reliably encode binary data into a string representation except some common cases like with booleans, but do we need them at all?