Skip to content

Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures #3494

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

Merged
merged 1 commit into from
Mar 21, 2019

Conversation

morozov
Copy link
Member

@morozov morozov commented Mar 19, 2019

Q A
Type improvement
BC Break yes

This breaking change is needed to enforce the type of $start natively. Additionally, all function arguments that accept an SQL expression will be type-hinted as string or ?string, regardless of which SQL type they represent. Function arguments have been rename closer to their SQL analogs.

/**
* {@inheritDoc}
*/
public function getSubstringExpression($value, $from, $length = null)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the same as the default implementation.

@@ -96,28 +96,26 @@ public function getTrimExpression(string $str, int $mode = TrimMode::UNSPECIFIED

/**
* {@inheritDoc}
*
* SQLite only supports the 2 parameter variant of this function
Copy link
Member Author

Choose a reason for hiding this comment

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

This is obsolete.

Copy link
Member

Choose a reason for hiding this comment

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

Do we know since when? We should probably require SQLite to be at least newer than X

@@ -332,7 +332,6 @@ public function testGeneratesSQLSnippets()
self::assertEquals("'1987/05/02' - 10 YEAR", $this->platform->getDateSubYearsExpression("'1987/05/02'", 10));
self::assertEquals(' WITH RR USE AND KEEP UPDATE LOCKS', $this->platform->getForUpdateSQL());
self::assertEquals('LOCATE(substring_column, string_column)', $this->platform->getLocateExpression('string_column', 'substring_column'));
self::assertEquals('LOCATE(substring_column, string_column)', $this->platform->getLocateExpression('string_column', 'substring_column'));
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a duplicate of the above.

* @param int|false $startPos Position to start at, beginning of string by default.
*
* @return string
* @param string $string String to locate the substring in, SQL expression.
Copy link
Member

Choose a reason for hiding this comment

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

This comment is unclear to me - can you rephrase it, please?

Copy link
Member Author

@morozov morozov Mar 19, 2019

Choose a reason for hiding this comment

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

This is the best I could come up with. Otherwise, it was "The SQL expression which represents the string in which the substring should be located". And this "The SQL expression which represents" will be in a lot of places. Is that better?

Copy link
Member

Choose a reason for hiding this comment

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

Aha, the wording "sql expression" put after the comma did confuse me

Copy link
Member Author

Choose a reason for hiding this comment

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

So what do you recommend?

Copy link
Member

Choose a reason for hiding this comment

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

"SQL expression producing the haystack" or something like that?

*
* @return string
* @param string $string String to locate the substring in, SQL expression.
* @param string $substring Substring to locate, SQL expression.
Copy link
Member

Choose a reason for hiding this comment

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

I think a better naming could be "needle"

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'd keep it closer to the SQL naming, not to PHP. Otherwise, it'd have to be $haystack and $needle.

* @return string
* @param string $string String to locate the substring in, SQL expression.
* @param string $substring Substring to locate, SQL expression.
* @param string|null $start Position to start at, SQL expression. Defaults to the beginning of the string.
Copy link
Member

Choose a reason for hiding this comment

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

Alao confusing - why is this a string? Could we maybe add example usages?

Copy link
Member Author

@morozov morozov Mar 19, 2019

Choose a reason for hiding this comment

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

Because it's an SQL expression, not a value (see the test). It could be a reference to another column in the query or a function call or whatever else. There will be a lot of changes like this in the API. Not sure if we want to put an example in every occurrence. What would you suggest?

*
* @return string
* @param string $string String to get a substring in, SQL expression.
* @param string $start Position to start at, SQL expression.
Copy link
Member

Choose a reason for hiding this comment

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

Similar to the above, start being a string is confusing to me - we'll need usage examples, IMO

Copy link
Member Author

@morozov morozov Mar 19, 2019

Choose a reason for hiding this comment

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

There are more than 40 methods in this class which accept SQL expressions. We do need some explanation but it doesn't have to be a phpDoc example for every one of them. Maybe it could be some footnote or a link to the online documentation?

I'd like to leave the doc block in a good enough shape and proceed with the code changes. I hope, someone could join later and improve the documentation as well.

@@ -96,28 +96,26 @@ public function getTrimExpression(string $str, int $mode = TrimMode::UNSPECIFIED

/**
* {@inheritDoc}
*
* SQLite only supports the 2 parameter variant of this function
Copy link
Member

Choose a reason for hiding this comment

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

Do we know since when? We should probably require SQLite to be at least newer than X

@morozov
Copy link
Member Author

morozov commented Mar 19, 2019

Do we know since when? We should probably require SQLite to be at least newer than X

No, but at least since 2008.

@morozov morozov requested a review from Ocramius March 19, 2019 15:55
@morozov morozov requested a review from Majkl578 March 20, 2019 15:18
@morozov
Copy link
Member Author

morozov commented Mar 21, 2019

@Ocramius do you still have any concerns or we can proceed?

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.

Let's proceed 👍

@Ocramius Ocramius self-assigned this Mar 21, 2019
@Ocramius Ocramius added this to the 3.0.0 milestone Mar 21, 2019
@Ocramius Ocramius merged commit 8dba786 into doctrine:develop Mar 21, 2019
@morozov morozov deleted the get-locate-expr branch March 22, 2019 01:17
morozov pushed a commit that referenced this pull request Apr 16, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit that referenced this pull request May 6, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit that referenced this pull request May 23, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit to morozov/dbal that referenced this pull request May 31, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit that referenced this pull request Jun 13, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit that referenced this pull request Jun 27, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit that referenced this pull request Jun 27, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit that referenced this pull request Jun 27, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit to morozov/dbal that referenced this pull request Aug 26, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
morozov pushed a commit that referenced this pull request Nov 2, 2019
Modified AbstractPlatform::getLocateExpression() and ::getSubstringExpression() signatures
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 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.

2 participants