Skip to content

Conversation

@prolic
Copy link
Member

@prolic prolic commented Feb 26, 2017

see prooph/event-store#267

the event store PR is required for travis to turn green.

@prolic
Copy link
Member Author

prolic commented Feb 26, 2017

/cc @oqq

Copy link
Member

@oqq oqq left a comment

Choose a reason for hiding this comment

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

👍

if (null === $factory) {
$factory = $this->getDefaultReadModelProjectionFactory();
if (null !== $filter) {
$where[] = '`real_stream_name` = :filter ';
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary space on the end of string

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

}

if ($regex && false === @preg_match("/$filter/", '')) {
if (false === @preg_match("/$filter/", '')) {
Copy link
Member

Choose a reason for hiding this comment

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

error suppression, you know. ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

register and unregister error handler for a single line of code is much slower I think.

Copy link
Member

@oqq oqq Feb 26, 2017

Choose a reason for hiding this comment

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

The whole test could be omitted and simply catched from mysql.
ERROR 1139 (42000): Got error '%s' from regexp

Not sure about postgre.

Copy link
Member

Choose a reason for hiding this comment

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

This would also fail with an empty $filter string.
preg_match("//", ''); is fine, but
SELECT 1 REGEXP '' ERROR 1139 (42000): Got error 'empty (sub)expression' from regexp

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 can catch error code from postgres 2201B to check for invalid regex.
Mysql error code 42000 "Got error 'empty (sub)expression' from regexp" works for empty string, but another invalid regex is accepted without error. Another thing is error code 42000 in MySql is used for different reasons. Really bad.

So we can make this change for postgres, but not MySql so much.

Copy link
Member

Choose a reason for hiding this comment

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

What is the result for invalid regex.. no result? Thats bad :(

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, it just returns empty result, no error code at all.

Copy link
Member

Choose a reason for hiding this comment

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

sadly.. than this extra call is necessary :(
But $filter should not be empty, too. To protect for that sql error.

Copy link
Member Author

Choose a reason for hiding this comment

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

already done.

$where[] = '`real_stream_name` = :filter ';
$values[':filter'] = $filter;
}
$where[] = '`real_stream_name` REGEXP :filter ';
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary space

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

if (null === $factory) {
$factory = $this->getDefaultReadModelProjectionFactory();
if (null !== $filter) {
$where[] = 'real_stream_name = :filter ';
Copy link
Member

Choose a reason for hiding this comment

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

space..

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

$where[] = 'real_stream_name = :filter ';
$values[':filter'] = $filter;
}
$where[] = 'real_stream_name ~ :filter ';
Copy link
Member

Choose a reason for hiding this comment

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

space..

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

public function fetchProjectionStreamPositions(string $name): array
{
$query = <<<SQL
SELECT position FROM $this->projectionsTable
Copy link
Member

Choose a reason for hiding this comment

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

backticks

Copy link
Member Author

Choose a reason for hiding this comment

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

Postgres does not allow backticks

public function fetchProjectionState(string $name): array
{
$query = <<<SQL
SELECT state FROM $this->projectionsTable
Copy link
Member

Choose a reason for hiding this comment

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

backticks

Copy link
Member Author

Choose a reason for hiding this comment

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

Postgres does not allow backticks

$this->expectException(InvalidArgumentException::class);

$eventStore = $this->prophesize(EventStore::class);
$connection = $this->prophesize(\PDO::class);
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary backslash on \PDO

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

$this->expectException(InvalidArgumentException::class);

$eventStore = $this->prophesize(EventStore::class);
$connection = $this->prophesize(\PDO::class);
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary backslash \PDO

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

$this->expectException(InvalidArgumentException::class);

$eventStore = $this->prophesize(EventStore::class);
$connection = $this->prophesize(\PDO::class);
Copy link
Member

Choose a reason for hiding this comment

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

unnecessary backslash

Copy link
Member Author

Choose a reason for hiding this comment

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

ok


if (! empty($whereCondition)) {
$whereCondition = 'WHERE ' . $whereCondition;
$whereCondition = 'WHERE ' . implode(' AND ', $where);
Copy link
Member

Choose a reason for hiding this comment

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

Could be

$whereCondition = 'WHERE `name` = :filter';
$values[':filter'] = $filter;


if (! empty($whereCondition)) {
$whereCondition = 'WHERE ' . $whereCondition;
$whereCondition = 'WHERE ' . implode(' AND ', $where);
Copy link
Member

Choose a reason for hiding this comment

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

Could be

$whereCondition = 'WHERE name = :filter';
$values[':filter'] = $filter;

@prolic prolic merged commit e5d8d61 into master Mar 1, 2017
@prolic prolic deleted the projection_manager branch March 1, 2017 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants