Abstraction for sql functions/expresions like REGEXP #534

Closed
c33s opened this Issue Feb 5, 2014 · 4 comments

Projects

None yet

2 participants

@c33s
c33s commented Feb 5, 2014

in the sluggable behavior it was already hacked in: propelorm/Propel#721

        $platform = $this->getTable()->getDatabase()->getPlatform();
        if ($platform instanceof PgsqlPlatform) {
            $script .= "->where('q." . $this->getColumnForParameter('slug_column')->getPhpName() . " ' . (\$alreadyExists ? '~*' : '=') . ' ?', \$alreadyExists ? '^' . \$slug2 . '[0-9]+$' : \$slug2)";
        } elseif ($platform instanceof MssqlPlatform) {
            $script .= "->where('q." . $this->getColumnForParameter('slug_column')->getPhpName() . " ' . (\$alreadyExists ? 'like' : '=') . ' ?', \$alreadyExists ? '^' . \$slug2 . '[0-9]+$' : \$slug2)";
        } elseif ($platform instanceof OraclePlatform) {
            $script .= "->where((\$alreadyExists ? 'REGEXP_LIKE(' : '') . 'q." . $this->getColumnForParameter('slug_column')->getPhpName() . " ' . (\$alreadyExists ? ',' : '=') . ' ?' . (\$alreadyExists ? ')' : ''), \$alreadyExists ? '^' . \$slug2 . '[0-9]+$' : \$slug2)";
        } else {
            $script .= "->where('q." . $this->getColumnForParameter('slug_column')->getPhpName() . " ' . (\$alreadyExists ? 'REGEXP' : '=') . ' ?', \$alreadyExists ? '^' . \$slug2 . '[0-9]+$' : \$slug2)";
        }

there are also some discussions if it is necessary to use REGEXP or to rollback to the old behavior which is not using this function.
nevertheless would it be a great improvement to have an abstraction to such functions and expressions.

@marcj
Member
marcj commented Apr 16, 2014

Oh, this has been fixed with dd599ce

@marcj marcj closed this Apr 16, 2014
@c33s
c33s commented Apr 16, 2014

this is not really a fix for this issue.
it is all about abstraction. i think its no solution to solve a special function regex with another special function length
as discussed in the other ticket, length is not compatible with mssql. so again i stand for an abstaction for many special functions used in propel.

same for the other ticket i created: #261

i think it would be good to have more abstractions of such functions

@marcj
Member
marcj commented Apr 16, 2014

We have already abstracted regex and lengths as you see in my commit. See adapter classes for more information. Propel is a ORM, not a plain DBAL.

@c33s
c33s commented Apr 16, 2014

oh, my fault.
nice one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment