BasicEntityPersister getInsertSQL() wrong value in openswoole #7150

Closed
opened 2026-01-22 15:45:37 +01:00 by admin · 3 comments
Owner

Originally created by @PsmaDev on GitHub (May 17, 2023).

/** * {@inheritDoc} */ public function getInsertSQL() { if ($this->insertSql !== null) { return $this->insertSql; }

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; }

Originally created by @PsmaDev on GitHub (May 17, 2023). `/** * {@inheritDoc} */ public function getInsertSQL() { if ($this->insertSql !== null) { return $this->insertSql; }` 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; }`
admin closed this issue 2026-01-22 15:45:37 +01:00
Author
Owner

@derrabus commented on GitHub (May 17, 2023):

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

  • what your're trying to do,
  • how you tried to achieve that
  • what outcome you expected
  • and what actually happened?
@derrabus commented on GitHub (May 17, 2023): I'm really sorry, but I don't understand your request. Can you elaborate a bit more on… * what your're trying to do, * how you tried to achieve that * what outcome you expected * and what actually happened?
Author
Owner

@PsmaDev commented on GitHub (May 17, 2023):

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.

@PsmaDev commented on GitHub (May 17, 2023): 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.
Author
Owner

@beberlei commented on GitHub (May 17, 2023):

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.

@beberlei commented on GitHub (May 17, 2023): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7150