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

Already on GitHub? Sign in to your account

Parameter parsing fixes #309

Merged
merged 1 commit into from May 9, 2013

Conversation

Projects
None yet
7 participants
Contributor

lstrojny commented Apr 21, 2013

Fix for #301 has been reverted to address http://www.doctrine-project.org/jira/browse/DBAL-496. This fix addresses both issues in a consistent manner and ads a few more tests.

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-501

We use Jira to track the state of pull requests and the versions they got
included in.

@stof stof commented on the diff Apr 21, 2013

lib/Doctrine/DBAL/SQLParserUtils.php
+ if (isset($paramsOrTypes[$paramName])) {
+ return $paramsOrTypes[$paramName];
+ }
+
+ // Hash keys can be prefixed with a colon for compatibility
+ if (isset($paramsOrTypes[':' . $paramName])) {
+ return $paramsOrTypes[':' . $paramName];
+ }
+
+ if (null !== $defaultValue) {
+ return $defaultValue;
+ }
+
+ if ($isParam) {
+ throw SQLParserUtilsException::missingParam($paramName);
+ } else {
@stof

stof Apr 21, 2013

Member

no need for else as the if throws an exception

@lstrojny

lstrojny Apr 21, 2013

Contributor

Mutual exclusiveness is better communicated that way. That's why there is an else.

@stof

stof Apr 27, 2013

Member

but it does not follow our coding standards

Member

lsmith77 commented Apr 21, 2013

using this branch I was able to successfully run the Jackalope Doctrine DBAL test suite with MySQL. Note for SQLite I wasnt able to run the test suite since it seems like drop FK statements are no longer ignored which makes the DB rest (https://github.com/jackalope/jackalope-doctrine-dbal/blob/master/src/Jackalope/Transport/DoctrineDBAL/RepositorySchema.php#L120) in our test suite fail:

PHP Fatal error:  Uncaught exception 'Doctrine\DBAL\DBALException' with message 'Sqlite platform does not support alter foreign key.' in /Users/lsmith/htdocs/cmf-sandbox/vendor/jackalope/jackalope-doctrine-dbal/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php:646

but that is another story :-/

@beberlei beberlei commented on the diff Apr 21, 2013

lib/Doctrine/DBAL/SQLParserUtils.php
+ * @param string $paramName The name of the parameter (without a colon in front)
+ * @param array $paramsOrTypes A hash of parameters or types
+ * @param bool $isParam
+ * @param mixed $defaultValue An optional default value. If omitted, an exception is thrown
+ *
+ * @throws SQLParserUtilsException
+ * @return mixed
+ */
+ static private function extractParam($paramName, $paramsOrTypes, $isParam, $defaultValue = null)
+ {
+ if (isset($paramsOrTypes[$paramName])) {
+ return $paramsOrTypes[$paramName];
+ }
+
+ // Hash keys can be prefixed with a colon for compatibility
+ if (isset($paramsOrTypes[':' . $paramName])) {
@beberlei

beberlei Apr 21, 2013

Owner

wait, so PDO supports $stmt->bindParam(':foo', $val); instead of $stmt->bindParam('foo', $val);

@lsmith77

lsmith77 Apr 21, 2013

Member

yes .. it supports both

@lstrojny

lstrojny Apr 21, 2013

Contributor

Yep, that was the root cause of the compatibility break with the Jackalope DBAL component.

@beberlei

beberlei Apr 21, 2013

Owner

I didn't know that, hence that code was never tested. :)

@FabioBatSilva FabioBatSilva commented on the diff Apr 21, 2013

lib/Doctrine/DBAL/SQLParserUtils.php
@@ -199,4 +200,35 @@ static private function getUnquotedStatementFragments($statement)
return $fragments[1];
}
+
+ /**
+ * @param string $paramName The name of the parameter (without a colon in front)
+ * @param array $paramsOrTypes A hash of parameters or types
+ * @param bool $isParam
+ * @param mixed $defaultValue An optional default value. If omitted, an exception is thrown
+ *
+ * @throws SQLParserUtilsException
+ * @return mixed
+ */
+ static private function extractParam($paramName, $paramsOrTypes, $isParam, $defaultValue = null)
@FabioBatSilva

FabioBatSilva Apr 21, 2013

Owner

Could you break it into extractParam and extractType ?

@lstrojny

lstrojny Apr 21, 2013

Contributor

Thought about that as well but it isn't really worth introducing another redirection (another method) or duplicating the extraction code.

@FabioBatSilva

FabioBatSilva Apr 21, 2013

Owner

I'd vote for using two methods here.
This one breaks the single responsibility principle.

Contributor

lstrojny commented Apr 22, 2013

@beberlei could you advise on where to go from here?

Owner

beberlei commented Apr 22, 2013

@lstrojny thinking about the SRP violation, a solution would be three methods,l but not sure if this is necessary here. Pondering with the problem... :)

Contributor

lstrojny commented Apr 22, 2013

Sure, three methods would work extractType, extractParam, and doExtract. But this code is complex as hell as it is, no need to add more. I was even thinking about inlining the whole conditions to spare a few method calls (as n can get pretty large potentially).

@beberlei beberlei merged commit 38f0d51 into doctrine:master May 9, 2013

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment