Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ASCII parameter binding #4274

Merged
merged 1 commit into from
Sep 18, 2020

Conversation

gjdanis
Copy link
Contributor

@gjdanis gjdanis commented Sep 14, 2020

Q A
Type improvement
BC Break no
Fixed issues #4263

Summary

Implements the changes proposed in #4263.

@gjdanis gjdanis mentioned this pull request Sep 14, 2020
.gitignore Outdated Show resolved Hide resolved
@greg0ire
Copy link
Member

You should use git rebase -i origin/3.0.x and drop any commit related to .idea, as asked in #4274 (comment)

Also, please associate your email address with your Github account, or change the
email in your commits to an address already associated with it. If you do not
want to expose your personal email address, you may use
[email protected], that way we can still reach you through Github.
Additionally, you will get credit for this contribution on your Github profile.

.gitignore Outdated Show resolved Hide resolved
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs/en/reference/types.rst should be updated, shouldn't it?

ci/travis/install-mssql-pdo_sqlsrv.sh Outdated Show resolved Hide resolved
src/ParameterType.php Outdated Show resolved Hide resolved
tests/Types/AsciiStringTest.php Outdated Show resolved Hide resolved
tests/Functional/Types/StringBindingTest.php Outdated Show resolved Hide resolved
@gjdanis gjdanis force-pushed the gdanis_support_varchar_binding_3.0 branch from 354736d to 3fc29f5 Compare September 16, 2020 13:26
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work so far!

Besides a couple of comments below, it'd be nice to have another functional test at the driver level that would demonstrate the newly introduced type will work on all platforms, not only on the ones that actually support the new binding type.

See BinaryTest for the reference.

src/Types/AsciiStringType.php Outdated Show resolved Hide resolved
tests/Functional/Types/StringBindingTest.php Outdated Show resolved Hide resolved
tests/Types/AsciiStringTest.php Outdated Show resolved Hide resolved
tests/Functional/Types/StringBindingTest.php Outdated Show resolved Hide resolved
tests/Functional/Types/StringBindingTest.php Outdated Show resolved Hide resolved
src/Platforms/AbstractPlatform.php Outdated Show resolved Hide resolved
src/Types/AsciiType.php Outdated Show resolved Hide resolved
tests/Functional/Types/AsciiTest.php Outdated Show resolved Hide resolved
tests/Platforms/SQLServerPlatformTest.php Outdated Show resolved Hide resolved
tests/Types/AsciiTest.php Outdated Show resolved Hide resolved
src/ParameterType.php Outdated Show resolved Hide resolved
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Please address the remaining comments and squash. It should be good to go.

src/Types/Type.php Outdated Show resolved Hide resolved
docs/en/reference/types.rst Outdated Show resolved Hide resolved
docs/en/reference/types.rst Outdated Show resolved Hide resolved
src/ParameterType.php Outdated Show resolved Hide resolved
@gjdanis gjdanis force-pushed the gdanis_support_varchar_binding_3.0 branch from 4601eab to c6b5fdb Compare September 17, 2020 21:20
morozov
morozov previously approved these changes Sep 17, 2020
@greg0ire
Copy link
Member

greg0ire commented Sep 18, 2020

I'm afraid I don't 100% understand the issue yet. In your example:

$statement = $connection->prepare(
   'SELECT * FROM ... WHERE myVarcharColumn = :value' -- will bind as N'...'
);

What exactly dictates that :value will be bound as N'…'? What does myVarcharColumn definition look like?

@gjdanis
Copy link
Contributor Author

gjdanis commented Sep 18, 2020

@greg0ire the driver code prepends the N character. If you use SQL Server Profiler you can see that the SQL that is sent to the server includes it. The actual code for this can be found here: https://github.com/microsoft/msphpsql/blob/5f76f838e5d44ca951a44bec6be1af05fae4bd93/source/pdo_sqlsrv/pdo_dbh.cpp#L1565

Here's my conversation with the developers of the driver about this isssue. There's also an RFC about this issue from the PDO maintainers which explains why they added other types for string binding.

In my example, we'd have a something like this:

CREATE TABLE #ExampleTable (
  ID INT NOT NULL,
  VarcharColumn VARCHAR(30) NOT NULL
)

CREATE NONCLUSTERED INDEX IX_ExampleTable_VarcharColumn
  ON #ExampleTable (VarcharColumn)

If we have a query like this:

SELECT *
FROM #ExampleTable
WHERE VarcharColumn = N'value'

We won't be able to use the index on VarcharColumn because the value we're binding for will require a type conversation for the values of the column we're querying.

If we bind with 'value', however, the types are the same and there's no conversation (and we're able to use the index as expected).

greg0ire
greg0ire previously approved these changes Sep 18, 2020
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think I got this right thanks to your explanation: when using the new ascii type, PDO::SQLSRV_ENCODING_SYSTEM will be used which means, "bind as 8-bit chars", which in turns means the driver will not add the N that would result in the implicit cast of the column values to utf-8

@greg0ire
Copy link
Member

Should this target 2.11.x or is there a BC-break somewhere in there?

@gjdanis
Copy link
Contributor Author

gjdanis commented Sep 18, 2020

@greg0ire I think it could target 2.11.x but a previous conversation with @morozov asked that I move it to 3.0.x: #4270 (comment)

Let me know if I should retarget.

@greg0ire
Copy link
Member

He was asking you to target to 3.0.x, but that retarget was from master… @morozov should we re-evaluate this? I see no reason to postpone this to 3.0.x when we could have it in 2.11.x .

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few extra comments while you wait for a decision on the target branch

src/Platforms/AbstractPlatform.php Outdated Show resolved Hide resolved
src/Platforms/SQLServer2012Platform.php Outdated Show resolved Hide resolved
src/Types/AsciiStringType.php Outdated Show resolved Hide resolved
@morozov
Copy link
Member

morozov commented Sep 18, 2020

@morozov should we re-evaluate this? I see no reason to postpone this to 3.0.x when we could have it in 2.11.x .

I don't see a problem having it in 2.11.x I asked for 3.0.x because I didn't foresee it being ready before 2.11.0 is released and didn't want it to be a blocker.

@gjdanis if you want to retarget the PR, please do not open a new one. Edit and rebase this one instead.

@gjdanis gjdanis changed the base branch from 3.0.x to 2.11.x September 18, 2020 19:43
@gjdanis gjdanis dismissed stale reviews from greg0ire and morozov September 18, 2020 19:43

The base branch was changed.

@gjdanis gjdanis changed the base branch from 2.11.x to 3.0.x September 18, 2020 19:44
@greg0ire greg0ire force-pushed the gdanis_support_varchar_binding_3.0 branch from c6b5fdb to 3b8c8f9 Compare September 18, 2020 20:11
greg0ire
greg0ire previously approved these changes Sep 18, 2020
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gjdanis I addressed the changes for you, LGTM

@morozov
Copy link
Member

morozov commented Sep 18, 2020

@gjdanis it would be at least the same amount of work or even more. If you want this to be released in 2.11.0, we should retarget this PR against 2.11.x. I can do this myself.

@gjdanis
Copy link
Contributor Author

gjdanis commented Sep 18, 2020

@morozov I feel like there should be 2.11.x version of this code so that large codebases that are reliant on 2.0 versions of this library can benefit from the change without having to refactor their code to be 3.0.x compliant. If you're offering to do this work, I'll take you up on the offer 👍

@morozov morozov force-pushed the gdanis_support_varchar_binding_3.0 branch from 3b8c8f9 to 7b58fd2 Compare September 18, 2020 22:22
@morozov morozov changed the base branch from 3.0.x to 2.11.x September 18, 2020 22:23
@morozov morozov closed this Sep 18, 2020
@morozov morozov reopened this Sep 18, 2020
@morozov
Copy link
Member

morozov commented Sep 18, 2020

@gjdanis please see if the rebased PR looks do you.

Copy link
Contributor Author

@gjdanis gjdanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morozov changes LGTM - thanks for the work to rebase!

@morozov morozov added this to the 2.11.0 milestone Sep 18, 2020
@morozov morozov changed the title Support varchar binding Support ASCII parameter binding Sep 18, 2020
@morozov morozov merged commit 2f3d9bb into doctrine:2.11.x Sep 18, 2020
@morozov
Copy link
Member

morozov commented Sep 18, 2020

Thanks, @gjdanis!

@morozov morozov linked an issue Sep 18, 2020 that may be closed by this pull request
@greg0ire
Copy link
Member

greg0ire commented Sep 19, 2020

Strategy for the merge-up:

  1. merge 2.11.x as it was before merging this PR (so git merge cce615a9e)
  2. merge this PR as it was before the rebase ( git merge 3b8c8f9f6)
  3. merge 2.11.x as it is/was after merging this PR, but discard changes (git merge -s ours 2f3d9bb61)
  4. if 2.11.x moved since then, merge it.

Will try this soon.

@morozov morozov self-assigned this Sep 23, 2020
rgrellmann added a commit to Rossmann-IT/dbal that referenced this pull request Mar 7, 2021
Release [2.11.0](https://github.com/doctrine/dbal/milestone/77)

2.11.0
======

- Total issues resolved: **7**
- Total pull requests resolved: **55**
- Total contributors: **8**

Improvement,Prepared Statements,SQL Server,Types,pdo_sqlsrv,sqlsrv
------------------------------------------------------------------

 - [4274: Support ASCII parameter binding](doctrine#4274) thanks to @gjdanis

Documentation
-------------

 - [4271: Add explanation about implicit indexes](doctrine#4271) thanks to @greg0ire

Deprecation,Error Handling
--------------------------

 - [4253: Deprecate DBAL\DBALException in favor of DBAL\Exception](doctrine#4253) thanks to @morozov

CI
--

 - [4251: Setup automatic release workflow](doctrine#4251) thanks to @greg0ire

Deprecation,Schema Managers
---------------------------

 - [4230: Deprecate the functionality of dropping client connections when dropping a database](doctrine#4230) thanks to @morozov

Deprecation,Platforms
---------------------

 - [4229: Deprecate more AbstractPlatform methods](doctrine#4229) thanks to @morozov
 - [4132: Deprecate AbstractPlatform::fixSchemaElementName()](doctrine#4132) thanks to @morozov

Improvement,Test Suite
----------------------

 - [4215: Remove test group configuration leftovers](doctrine#4215) thanks to @morozov
 - [4080: Update PHPUnit to 9.2](doctrine#4080) thanks to @morozov
 - [4079: Forward compatibility with PHPUnit 9.3](doctrine#4079) thanks to @morozov
 - [3923: Removed performance tests](doctrine#3923) thanks to @morozov

Deprecation,Schema
------------------

 - [4213: Deprecate the Synchronizer package](doctrine#4213) thanks to @morozov

Blocker,Improvement,PHP,Test Suite
----------------------------------

 - [4201: Update PHPUnit to 9.3](doctrine#4201) thanks to @morozov

Blocker,PHP,Test Suite
----------------------

 - [4196: The test suite uses the deprecated at() matcher](doctrine#4196) thanks to @morozov

Connections,Deprecation,Documentation
-------------------------------------

 - [4175: Additional deprecation note for PrimaryReplicaConnection::query()](doctrine#4175) thanks to @morozov

Connections,Deprecation,Prepared Statements
-------------------------------------------

 - [4165: Deprecated usage of wrapper components as implementations of driver-level interfaces](doctrine#4165) thanks to @morozov
 - [4020: Deprecated Connection::project(), Statement::errorCode() and errorInfo()](doctrine#4020) thanks to @morozov

Connections,Deprecation
-----------------------

 - [4163: Deprecate duplicate and ambiguous wrapper connection methods](doctrine#4163) thanks to @morozov

Error Handling,Improvement,Types
--------------------------------

 - [4145: Add TypeRegistry constructor](doctrine#4145) thanks to @morozov

Deprecation,Drivers,Improvement,pdo_mysql,pdo_oci,pdo_pgsql,pdo_sqlite,pdo_sqlsrv
---------------------------------------------------------------------------------

 - [4144: Deprecate classes in Driver\PDO* namespaces](doctrine#4144) thanks to @morozov

Connections,Documentation,Improvement
-------------------------------------

 - [4139: Mark connection constructors internal](doctrine#4139) thanks to @morozov

Deprecation,Drivers,Error Handling
----------------------------------

 - [4137: Deprecate driver exception conversion APIs](doctrine#4137) thanks to @morozov
 - [4112: Deprecate DriverException::getErrorCode()](doctrine#4112) thanks to @morozov

Configuration,Connections,Deprecation,Error Handling
----------------------------------------------------

 - [4134: Deprecate some DBALException factory methods](doctrine#4134) thanks to @morozov

Code Style,Documentation
------------------------

 - [4133: Fix more issues introduced by the deprecation of driver classes](doctrine#4133) thanks to @morozov

BC Break,Drivers,Error Handling,pdo_sqlsrv,sqlsrv
-------------------------------------------------

 - [4131: Restore the PortWithoutHost exception parent class](doctrine#4131) thanks to @morozov

Code Style,Improvement,Static Analysis
--------------------------------------

 - [4123: Remove the no longer needed error suppressions](doctrine#4123) thanks to @morozov

Deprecation,Drivers,Error Handling,Improvement
----------------------------------------------

 - [4118: Deprecate ExceptionConverterDriver](doctrine#4118) thanks to @morozov

Bug,Connections,Improvement,Prepared Statements
-----------------------------------------------

 - [4117: Fixes for the recently introduced driver-level deprecations](doctrine#4117) thanks to @morozov

Connections,Deprecation,Platform Detection
------------------------------------------

 - [4114: Deprecate ServerInfoAwareConnection#requiresQueryForServerVersion() as an implementation detail](doctrine#4114) thanks to @morozov

Deprecation,Prepared Statements,SQL Parser,oci8
-----------------------------------------------

 - [4110: Mark non-interface OCI8 driver methods internal](doctrine#4110) thanks to @morozov

Connections,Deprecation,Drivers,Improvement,Prepared Statements
---------------------------------------------------------------

 - [4100: Deprecate inconsistently and ambiguously named driver-level classes](doctrine#4100) thanks to @morozov

Connections,Improvement
-----------------------

 - [4092: Remove Connection::$isConnected](doctrine#4092) thanks to @morozov

Configuration,Connections
-------------------------

 - [4086: Mark Connection::getParams() internal](doctrine#4086) thanks to @morozov

Bug,Drivers,ibm_db2
-------------------

 - [4085: The IBM DB2 driver Exception class must implement the DriverException interface](doctrine#4085) thanks to @morozov

PHP
---

 - [4078: Bump PHP requirement to 7.3 as of DBAL 2.11.0](doctrine#4078) thanks to @morozov

Connections,Databases,Deprecation,Drivers
-----------------------------------------

 - [4068: Deprecate Driver::getDatabase()](doctrine#4068) thanks to @morozov

Deprecation,Improvement,Portability
-----------------------------------

 - [4061: Deprecated platform-specific portability mode constants](doctrine#4061) thanks to @morozov

 - [4054: &doctrine#91;doctrineGH-4052&doctrine#93; Deprecate MasterSlaveConnection and rename to PrimaryReplicaConnection](doctrine#4054) thanks to @beberlei and @albe
 - [4017: Improve help of dbal:run-sql command](doctrine#4017) thanks to @ostrolucky

Code Style,Improvement
----------------------

 - [4050: Update doctrine/coding-standard to 8.0](doctrine#4050) thanks to @morozov

Cache,Deprecation,Improvement,Prepared Statements
-------------------------------------------------

 - [4049: Replace forward-compatible ResultStatement interfaces with Result](doctrine#4049) thanks to @morozov

Cache,Improvement,Prepared Statements
-------------------------------------

 - [4048: Make caching layer not rely on closeCursor()](doctrine#4048) thanks to @morozov

Deprecation,Improvement,Prepared Statements
-------------------------------------------

 - [4037: Introduce Statement::fetchFirstColumn()](doctrine#4037) thanks to @morozov
 - [4019: Deprecated the concept of the fetch mode](doctrine#4019) thanks to @morozov

Bug,Documentation,Improvement,Prepared Statements
-------------------------------------------------

 - [4034: Additional changes based on the discussion in doctrine#4007](doctrine#4034) thanks to @morozov

Connections,Console,Improvement
-------------------------------

 - [3956: allow using multiple connections for CLI commands](doctrine#3956) thanks to @dmaicher

Deprecation,Logging
-------------------

 - [3935: Deprecate EchoSQLLogger](doctrine#3935) thanks to @morozov

Improvement,Packaging
---------------------

 - [3924: Actualize the content of the .gitattributes file](doctrine#3924) thanks to @morozov

Azure,Deprecation,Drivers,Drizzle,MariaDB,Platforms,PostgreSQL,SQL Anywhere,SQL Server,Sharding,pdo_ibm
-------------------------------------------------------------------------------------------------------

 - [3905: Deprecate the usage of the legacy platforms and drivers](doctrine#3905) thanks to @morozov

Deprecation,Query
-----------------

 - [3864: CompositeExpression and()/or() factory methods](doctrine#3864) thanks to @BenMorel
 - [3853: Deprecate calling QueryBuilder methods with an array argument](doctrine#3853) thanks to @BenMorel and @morozov

Deprecation,Tools
-----------------

 - [3861: Deprecated the usage of the Version class](doctrine#3861) thanks to @morozov

Improvement,Query
-----------------

 - [3852: First parameter of ExpressionBuilder::and/or() mandatory](doctrine#3852) thanks to @BenMorel

Deprecation,Improvement,Query
-----------------------------

 - [3851: Rename andX() / orX() methods](doctrine#3851) thanks to @BenMorel
 - [3850: Prepare CompositeExpression for immutability](doctrine#3850) thanks to @BenMorel

# gpg: Signature made Mon Sep 21 01:47:31 2020
# gpg:                using DSA key 1BEDEE0A820BC30D858F9F0C2C3A645671828132
# gpg: Can't check signature: No public key

# Conflicts:
#	README.md
#	lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php
#	lib/Doctrine/DBAL/Driver/OCI8/Driver.php
#	lib/Doctrine/DBAL/Version.php
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support true VARCHAR binding to prevent implicit conversions?
3 participants