Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

RecordExists and NoRecordExists is not reusable for validate different values #178

@AndrejAndb

Description

@AndrejAndb

Custom modification in method for debug: https://github.com/zendframework/zend-validator/blob/master/src/Db/AbstractDb.php#L321

    protected function query($value)
    {
        $sql = new Sql($this->getAdapter());
        $select = $this->getSelect();
        $statement = $sql->prepareStatementForSqlObject($select);
        $parameters = $statement->getParameterContainer();
        $parameters['where1'] = $value; // <- PROBLEM
        echo $statement->getSql() . "\n"; // <- DEBUG
        $result = $statement->execute();
        return $result->current();
    }

test case:

        $validator = new RecordExists([
            'table'   => 'tags',
            'field'   => 'id',
            'adapter' => $this->getEvent()->getApplication()->getServiceManager()->get('DBSiteAdapter')
        ]);
        print_r($validator->isValid(1)); echo "\n";
        print_r($validator->isValid(2)); echo "\n";

result:

SELECT "tags"."id" AS "id" FROM "tags" WHERE "id" = :where1
1
SELECT "tags"."id" AS "id" FROM "tags" WHERE "id" = :where2
PDO EXCEPTION: SQLSTATE[HY093]: Invalid parameter number: :where1

as we see, in next call we have :where2 instead :where1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions