Use executeStatement for migration SQL#1552
Use executeStatement for migration SQL#1552christiaan wants to merge 1 commit intodoctrine:3.9.xfrom
Conversation
DbalExecutor now uses Connection::executeStatement (instead of executeQuery) because executeQuery is intended for read-only operations in DBAL. Fixes doctrine#1551
| $this->outputSqlQuery($query, $configuration); | ||
|
|
||
| $stopwatchEvent = $this->stopwatch->start('query'); | ||
| // executeQuery() must be used here because $query might return a result set, for instance REPAIR does |
|
Replacing the comment explaining why -1 for this PR as it will introduce the same regression again. |
|
Ah thanks for pointing that out! I tried searching but could not find the relevant issues/code related to that rather brief comment. Doing a blame on that line also did not really help. So if I understand it correctly Some context; we had some mutations being accidentally executed on the replica and wanted to guard against that in development. (In production this is fixed by using a read only user for the replica connection.) So we added safeguards to our code that when executeQuery is being used it is only used for READ operations as prescribed by the PrimaryReadReplicaConnection. When building in that safeguard our migrations failed. |
|
PDO (and some other DB drivers) have 2 different methods depending on the result of the query (more than on the permission they need):
Running a query returning a result set through the API that does not expect it will generally cause the DB driver to fail. On the other hand, running a query that does not have a result set through the API supporting result sets won't crash (it will return an empty result set). For simple queries,
|
Blame is a limited tool. You should be using the git pickaxe for this. That's how I found about #1071 |
Summary
DbalExecutor now uses Connection::executeStatement (instead of executeQuery) because executeQuery is intended for read-only operations in DBAL.
See https://github.com/doctrine/dbal/blob/05f3985a266bb75c44e621e6a647027016061265/src/Connections/PrimaryReadReplicaConnection.php#L43