PDO_DBLIB: Quote LOB arguments as binary literals#10343
PDO_DBLIB: Quote LOB arguments as binary literals#10343NattyNarwhal wants to merge 2 commits intophp:masterfrom
Conversation
If the user is specifying a PDO::PARAM_LOB, there's a good chance that it's a binary file (i.e. an image), that is too fragile to survive in a string, as escaping it is insufficient. Because PDO_DBLIB relies on PDO to fill in a parameterized query and submits the filled string to the server, it ends up mangling the query. This adds logic in the PDO_DBLIB quoter to handle binary parameters by using the SQL Server binary literal syntax (a hex string that begins with `0x`). This resolves the issue because PDO consults the quoter for filling in the query string.
This makes sure that a PDO::PARAM_LOB parameter gets converted to a binary literal when doing the substitution for the query.
|
After discussing this with Derrick, we brought up the possibility of putting this behind a constant (PDO_DBLIB specific, but could be useful for other drivers?) or a feature flag (in the connection string, INI options should be avoided). Also worth mentioning that the Postgres PDO driver does special-case binary strings in the quoter under |
|
Someone emailed me about wanting a PARAM_BINARY in PDO_ODBC, to work around driver issues with strings as inputs/outputs for binary columns. I'm tempted to generalize this for other drivers. |
Original text: >If the user is specifying a PDO::PARAM_LOB, there's a good chance >that it's a binary file (i.e. an image), that is too fragile to >survive in a string, as escaping it is insufficient. Because >PDO_DBLIB relies on PDO to fill in a parameterized query and >submits the filled string to the server, it ends up mangling the >query. > >This adds logic in the PDO_DBLIB quoter to handle binary parameters >by using the SQL Server binary literal syntax (a hex string that >begins with `0x`). This resolves the issue because PDO consults the >quoter for filling in the query string.
Original text: >If the user is specifying a PDO::PARAM_LOB, there's a good chance >that it's a binary file (i.e. an image), that is too fragile to >survive in a string, as escaping it is insufficient. Because >PDO_DBLIB relies on PDO to fill in a parameterized query and >submits the filled string to the server, it ends up mangling the >query. > >This adds logic in the PDO_DBLIB quoter to handle binary parameters >by using the SQL Server binary literal syntax (a hex string that >begins with `0x`). This resolves the issue because PDO consults the >quoter for filling in the query string.
If the user is specifying a PDO::PARAM_LOB, there's a good chance that it's a binary file (i.e. an image), that is too fragile to survive in a string, as escaping it is insufficient. Because PDO_DBLIB relies on PDO to fill in a parameterized query and submits the filled string to the server, it ends up mangling the query.
This adds logic in the PDO_DBLIB quoter to handle binary parameters by using the SQL Server binary literal syntax (a hex string that begins with
0x). This resolves the issue because PDO consults the quoter for filling in the query string.I've also added a unit test for this.
Questions not raised in the commit:
PDO::PARAM_LOBthe best option for this? I picked this because the end-user I was working with (as did I) expected binary behaviour out of it, but that might be too much of an assumption, especially since there's not really LOBs involved, just binaries. Would aPARAM_BINARYmake sense? If so, as a modifier or its own type? Added to base PDO or just DBLIB?Resolves GH-10312.