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

Remove hard dependency on PDO #2958

Merged
merged 13 commits into from
Jan 25, 2018
Merged

Remove hard dependency on PDO #2958

merged 13 commits into from
Jan 25, 2018

Conversation

morozov
Copy link
Member

@morozov morozov commented Jan 1, 2018

The first part of the pull request (prior to the commits labeled [BC]) contains the non-breaking changes which should be back-ported to master. The remaining part contains the removal of the dependency and breaking API changes.

Fixes: #2953.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

Overall, I understand why this is being attempted, but I don't think users will benefit much from it, as most of our users do in fact use PDO, so the rest shouldn't have a problem with keeping it installed.

What I see though, is using bitmasks to define bound parameter types, which is problematic when we consider things like multi-dimensional parameters. This doesn't affect low-level API, but it is one of the pain-points of our API (binding with Connection::PARAM_INT_ARRAY, for example).

I'm not sure if that's relevant to this patch though.

UPGRADE.md Outdated
@@ -1,3 +1,9 @@
# Upgrade to NEXT
Copy link
Member

Choose a reason for hiding this comment

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

Should we open develop?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's open develop, get everything merged there and then back-port the relevant pieces to master.

Copy link
Contributor

Choose a reason for hiding this comment

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

Develop already exists here, it just needs rebase.

@@ -147,30 +146,38 @@ public function getIterator()
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $_ = null, $__ = null)
Copy link
Member

Choose a reason for hiding this comment

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

Should we deprecate those parameters?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should. This particular commit should only go to develop. Initially, I wanted to get rid of them entirely but here's the trick:

  1. DBAL\PDOStatement extends PDOStatement and implements ResultStatement, both of which declare fetch().
  2. It looks impossible to use a custom PDO statement class which doesn't extend PDOStatement since PDO instantiates it without calling constructor (this is my current understanding, I may be wrong).
  3. Therefore, the declaration of ResultStatement::fetch() and all its implementors should be compatible with PDOStatement::fetch().

I'd love to be able to rework DBAL\PDOStatement extends PDOStatement into a composition and get rid of those parameters entirely but it's technically challenging. Any ideas?

@@ -75,14 +75,14 @@ class Connection implements DriverConnection
*
* @var integer
*/
const PARAM_INT_ARRAY = 101;
const PARAM_INT_ARRAY = Statement::PARAM_INT + self::ARRAY_PARAM_OFFSET;
Copy link
Member

Choose a reason for hiding this comment

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

Is + intentional? Shouldn't this be |?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it is an offset... didn't see that.


/**
* Represents an array of strings to be expanded by Doctrine SQL parsing.
*
* @var integer
*/
const PARAM_STR_ARRAY = 102;
const PARAM_STR_ARRAY = Statement::PARAM_STR + self::ARRAY_PARAM_OFFSET;
Copy link
Member

Choose a reason for hiding this comment

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

Is + intentional? Shouldn't this be |?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it is an offset... didn't see that.

@@ -19,6 +19,8 @@

namespace Doctrine\DBAL\Driver;

use PDO;
Copy link
Member

Choose a reason for hiding this comment

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

Probably to be removed

@@ -20,6 +20,7 @@
namespace Doctrine\DBAL\Portability;

use Doctrine\DBAL\Cache\QueryCacheProfile;
use PDO;
Copy link
Member

Choose a reason for hiding this comment

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

To be removed, I'd say. Use the FQCN in the docblock

@@ -27,6 +29,29 @@
*/
class PDOStatement extends \PDOStatement implements Statement
Copy link
Member

Choose a reason for hiding this comment

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

In this case we keep the dependency?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? This class will be only loaded if a PDO driver is used in runtime. Currently, all tests pass w/o the PDO extension loaded.

@morozov
Copy link
Member Author

morozov commented Jan 1, 2018

@Ocramius added this to the 2.7.0 milestone

This pull request is meant to be split in two parts:

  1. All commits prior to the ones marked as [BC] go to master and the next minor release.
  2. The rest goes to develop.

Or the other way around: everything goes to develop, then non-breaking changes get ported to master. The second approach should be better maintainable IMO.

@morozov
Copy link
Member Author

morozov commented Jan 1, 2018

oci runtime error: exec failed: container_linux.go:265: starting container process caused "could not create session key: disk quota exceeded"

Anyone, have you seen these errors before? Looks irrelevant.

@Majkl578
Copy link
Contributor

Majkl578 commented Jan 1, 2018

Travis is messed up today, other build failed due to MySQL not starting...

@morozov
Copy link
Member Author

morozov commented Jan 1, 2018

[…] but I don't think users will benefit much from it, as most of our users do in fact use PDO, so the rest shouldn't have a problem with keeping it installed.

@Ocramius the hard dependency hardens the adoption of the DBAL by existing projects. Particularly, SugarCRM is migrating its DB layer to DBAL. It supports several DB platforms but doesn't use or support PDO. Currently, it depends on v2.5 and uses a PDO shim to avoid requiring the extension.

The absence of a dependency on PDO makes the upgrade from a non-DBAL-based version to the DBAL-based seamless. Otherwise, the customers will be required to have PDO installed for no reason.

@morozov
Copy link
Member Author

morozov commented Jan 1, 2018

What I see though, is using bitmasks to define bound parameter types, which is problematic when we consider things like multi-dimensional parameters. This doesn't affect low-level API, but it is one of the pain-points of our API (binding with Connection::PARAM_INT_ARRAY, for example).

Could you elaborate? I was thinking about replacing Connection::PARAM_INT_ARRAY with Statement::PARAM_INT | Statement::PARAM_ARRAY. Otherwise, we have related constants in different classes. But this is outside of the scope. We can do that in 3.0 before or after getting this pull request merged.

@Ocramius
Copy link
Member

Ocramius commented Jan 1, 2018

@morozov ACK on adoption.

As for the PARAM_INT_ARRAY question, that was indeed feature creep: let's leave it out.

@morozov morozov force-pushed the issues/2953 branch 2 times, most recently from b048689 to 965353c Compare January 3, 2018 00:03
@morozov morozov changed the base branch from master to develop January 3, 2018 07:07
@morozov morozov force-pushed the issues/2953 branch 5 times, most recently from b92f436 to cc7a6ce Compare January 4, 2018 02:54
@morozov
Copy link
Member Author

morozov commented Jan 4, 2018

@Ocramius please take a look. Instead of removing additional arguments from the fetch() and fetchAll() methods I replaced them with ...$args (see #2527 (comment)). Therefore, there's no need to deprecate them. Callers will be able to keep passing them as they did but implementors will have to change their signatures accordingly.

@Ocramius
Copy link
Member

Ocramius commented Jan 4, 2018

@morozov for 3.0, wouldn't it be better for us to take ownership of the fetch and fetchAll signatures?

@morozov
Copy link
Member Author

morozov commented Jan 4, 2018

We could. I just don’t have an idea of a better set of signatures. We still need to be able to take variable set of arguments depending on the mode. Do you have any concrete idea?

@Ocramius
Copy link
Member

Ocramius commented Jan 4, 2018

Nope, no better ideas so far :-\

.travis.yml Outdated
@@ -306,6 +306,11 @@ jobs:
if: type = pull_request
php: 7.2
script:
- |
Copy link
Member

Choose a reason for hiding this comment

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

Should be gone after a rebase, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

I’ll remove it manually if it doesn’t. I tested the fix here. Gonna rebase develop and this branch tomorrow.

@Majkl578
Copy link
Contributor

I'm really happy we decided to stick with the FetchMode and ParameterType classes with unprefixed/unsuffixed constant names, it really makes more sense this way. 🎉

@morozov morozov deleted the issues/2953 branch January 25, 2018 23:04
@morozov morozov modified the milestones: 2.7.0, 3.0.0 Apr 4, 2018
@morozov morozov restored the issues/2953 branch December 30, 2019 01:11
morozov added a commit to morozov/dbal that referenced this pull request Dec 30, 2019
morozov added a commit to morozov/dbal that referenced this pull request Dec 30, 2019
morozov added a commit to morozov/dbal that referenced this pull request Dec 30, 2019
…ion to avoid having to replicate the \PDOStatement interface in ResultStatement
morozov added a commit to morozov/dbal that referenced this pull request Dec 30, 2019
morozov added a commit to morozov/dbal that referenced this pull request Dec 30, 2019
@morozov morozov deleted the issues/2953 branch January 17, 2020 00:58
@morozov morozov modified the milestones: 4.0.0, 3.0.0 Aug 15, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 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.

6 participants