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

Small optimization to use strpos instead of preg_match #319

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Contributor

GromNaN commented Nov 22, 2012

Use strpos instead of preg_match to detect LIKE comparison.

In addition, this prevent from WTF effect in case someone want to use something like:

$query->filterByTitle('%foo*%');

I can add a test on that.

Owner

willdurand commented Nov 22, 2012

You should add a test ;)

@staabm staabm commented on the diff Nov 23, 2012

src/Propel/Generator/Builder/Om/QueryBuilder.php
@@ -871,7 +871,9 @@ public function filterBy$colPhpName(\$$variableName = null, \$comparison = null)
if (null === \$comparison) {
if (is_array(\$$variableName)) {
\$comparison = Criteria::IN;
- } elseif (preg_match('/[\%\*]/', \$$variableName)) {
@staabm

staabm Nov 23, 2012

Member

don't know if it matters, but mysql also supports _ in LIKE for matching exactly one character:
http://dev.mysql.com/doc/refman/5.1/en/string-comparison-functions.html

dont know if this is SQL standard or MySQL specific

@GromNaN

GromNaN Nov 23, 2012

Contributor

I don't know if it's SQL standard, but I think we should not use _ to detect LIKE comparison as it is very common for slugs.

Contributor

GromNaN commented Nov 23, 2012

Just modified tests.

@willdurand willdurand closed this May 11, 2013

@krichprollsch krichprollsch pushed a commit to krichprollsch/Propel2 that referenced this pull request Nov 23, 2013

@K-Phoen K-Phoen Fix: port of the PR #319 from Propel cdcab7d

@krichprollsch krichprollsch pushed a commit to krichprollsch/Propel2 that referenced this pull request Nov 23, 2013

@willdurand willdurand Merge pull request #162 from K-Phoen/port-pr-319
Fix: port of the PR #319 from Propel
31c63a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment