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

Add public api for Doctrine QueryBuilder and ExpressionBuilder #17413

Merged
merged 10 commits into from
Jul 22, 2015

Conversation

nickvergessen
Copy link
Contributor

Replaces #17383

Related to #12502

cc @LukasReschke @DeepDiver1975 @schiesbn @Raydiation

@MorrisJobke
Copy link
Contributor

Looks good so far :)

@DeepDiver1975
Copy link
Member

Great first shot - any chance to get quoting handled within the wrapper as well?
@nickvergessen

@MorrisJobke
Copy link
Contributor

Great first shot - any chance to get quoting handled within the wrapper as well?
@nickvergessen

I would say this PR is big enough. We should not add more features to this one.

@LukasReschke
Copy link
Member

I would say this PR is big enough. We should not add more features to this one.

Mhm. If it is a new public API I'd say we should first decide if we want quoting or not. If we do then we should do it right at the first time before others rely on the behaviour.

@DeepDiver1975
Copy link
Member

If we do then we should do it right at the first time before others rely on the behaviour.

yes

@MorrisJobke
Copy link
Contributor

Ah okay ... got it :( 🙈 I completely misunderstood that thing ...

@nickvergessen
Copy link
Contributor Author

I shall have a look after finishing the walk through my emails and other open tasks

$connection = \OC::$server->getDatabaseConnection();
$query = $connection->createQueryBuilder();
$query = $connection->getQueryBuilder();
Copy link
Contributor

Choose a reason for hiding this comment

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

Which one is the Doctrine thing? create or get? Just for an overview

Copy link
Contributor Author

Choose a reason for hiding this comment

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

create is doctrine, get is OC

@nickvergessen
Copy link
Contributor Author

Okay, there are some problems which I found, while having a quick look/thought:

E.g. andX:

     *     // (u.type = ?) AND (u.role = ?)
     *     $expr->andX('u.type = ?', 'u.role = ?'));

Can be fixed by forcing the use of $expr->eq() and $expr->neq()

However, that method itself has the problem as well:

     *     // u.id = ?
     *     $expr->eq('u.id', '?');

Theory case okay, back to practise:

$expr->eq('column', 'strangestring')

Should we escape the second string?

This can be prevented by forcing the use of $expr->literal() and parameter usage.
We could therefor go ahead and force the use of literal/parameter (make it return classes in our implementation), and then quote everything that is not from our literal/parameter class.


Conclusion

Sounds doable, I shall go ahead and do that.

@nickvergessen nickvergessen force-pushed the public-api-querybuilder branch 3 times, most recently from f521dd9 to ee9a026 Compare July 15, 2015 13:34
@nickvergessen
Copy link
Contributor Author

Tests failed due to a bug in Doctrine/DBAL which is already fixed since January but has not yet been released: doctrine/dbal#782

@nickvergessen
Copy link
Contributor Author

@nickvergessen
Copy link
Contributor Author

@nickvergessen
Copy link
Contributor Author

Quoting is now included
Existing usages of the querybuilder have been adjusted to use the new one with auto-quoting ( #17381 is using the old one again, so either of them needs to be merged quickly ;) )

Ready for review and merge @DeepDiver1975 @LukasReschke @MorrisJobke

@nickvergessen
Copy link
Contributor Author

Open question from IRC:

Should we break the existing createQueryBuilder() method that exists on the \Doctrine\DBAL\Connection we extend?
The method is not in our API, I could also rename the method getQueryBuilder() to create, so we always return the version with auto-quoting, however that might break existing usages that apps did (although it was not allowed in theory)

I don't think it's worth the troubles it may cause.

@MorrisJobke
Copy link
Contributor

I don't think it's worth the troubles it may cause.

Correct. It was used by some apps ... better keep it compatible now but maybe have a future version of create... which adds a log entry and still returns the doctrine one.

Alternative: Maybe also worth to add to the app code checker. ;)

@nickvergessen
Copy link
Contributor Author

Okay, sounds like a plan. Will make a wrapper and add a debug log entry.

Alternative: Maybe also worth to add to the app code checker. ;)

Sadly enough, this is exactly the one case that is not covered ;)

@scrutinizer-notifier
Copy link

A new inspection was created.

@ghost
Copy link

ghost commented Jul 21, 2015

@rullzer
Copy link
Contributor

rullzer commented Jul 22, 2015

Very awesome! Also awesome that the existing code is converted (I wrote some of that).
It is huge now but I think all the stuff is covered. 👍

@MorrisJobke
Copy link
Contributor

Looks good and a smoke test also just went fine 👍

MorrisJobke added a commit that referenced this pull request Jul 22, 2015
Add public api for Doctrine QueryBuilder and ExpressionBuilder
@MorrisJobke MorrisJobke merged commit 296ed4c into master Jul 22, 2015
@MorrisJobke MorrisJobke deleted the public-api-querybuilder branch July 22, 2015 15:29
@lock lock bot locked as resolved and limited conversation to collaborators Aug 11, 2019
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.

7 participants