doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.94k stars 2.52k forks source link

BasicEntityPersister getInsertSQL() wrong value in openswoole #10709

Closed PsmaDev closed 1 year ago

PsmaDev commented 1 year ago

`/**

This "if" brtoke down stateles in case of using openswoole.

In case of changing table prefix this check return wrong sql if multiple requests for tables with different prefix: https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/cookbook/sql-table-prefixes.html The easiest fix just remove this 3 lines:

if ($this->insertSql !== null) { return $this->insertSql; }

derrabus commented 1 year ago

I'm really sorry, but I don't understand your request. Can you elaborate a bit more on…

PsmaDev commented 1 year ago

Openswoole is not dying after each request like php-fpm. So first request $this->insertSql is null and it generated, next request $this->insertSql is not null so it will be same like in 1 request, but script changed table prefix, so new insert is neede.

INSERT INTO prefix1_tablename ... INSERT INTO prefix2_tablename ...

In traditional php this is not problem, each request bootstraping from scratch.

Possible add some check if table name for entity changed, just set it null. Or make this "cache" optional. Now it is not possible to keep it stateless in long term app.

beberlei commented 1 year ago

This has nothing to do with openswoole however, changing the table prefix within a request and then using the EntityManager will produce the same problem. It is not supported to change the table prefix after the EntityManager was created.

The listener that you link doesn't even show support for changing the prefix, its created at ctor time and then the listener is passed to EventManager before the EntityManager is created.