PdoDriver: fix pdo connection in exception mode (target >=4.1.0)#293
PdoDriver: fix pdo connection in exception mode (target >=4.1.0)#293
Conversation
src/Dibi/Drivers/PdoDriver.php
Outdated
| } | ||
|
|
||
| $this->affectedRows = null; | ||
| throw $this->createException($this->connection->errorInfo(), $sql, null); |
There was a problem hiding this comment.
I do not like this handling of error cases. Is is done twice, any ideas?
There was a problem hiding this comment.
Is your intention to make it work regardless of ATTR_ERRMODE, ie. with ERRMODE_WARNING and ERRMODE_EXCEPTION together?
Maybe you can use finally:
try {
$res = $this->connection->query($sql);
...
} catch (\PDOException $e) {
} finally {
throw $this->createException(isset($e) ? $e->errorInfo : $this->connection->errorInfo(), $sql);
}There was a problem hiding this comment.
Finally will be executed also on successful case, I have extracted this in main body of the function.
src/Dibi/Drivers/PdoDriver.php
Outdated
|
|
||
| } catch (\PDOException $pdoException) { | ||
| $this->affectedRows = null; | ||
| throw $this->createException($pdoException->errorInfo, $sql, $pdoException); |
There was a problem hiding this comment.
I do not like that I need to pass $previous all around. Any ideas how to do better?
There was a problem hiding this comment.
I think the PDOException does not contain any additional information, so there is no need to pass on the previous one.
There was a problem hiding this comment.
Hmm, as it is implementation detail, no code ever should depend on that. Gonna remove that
1ac208e to
9840c31
Compare
|
There is one more problem to fix, there is also WARNING mode in which dibi probably should mute warnings and handle them by iteself consistently = throwing exception. I would like to write few notes into comments into this function because it handles three things simulatanously and it is not obvious what is does for the first look. |
|
One more thing - I will need to help a little with tests. What approach to go? Run all tests also in warning mode and exception mode? Or create just unit tests for this one function. I'm not shure what happend whan connection dies before |
|
Run all tests in warning mode and exception mode seems better to me.
It's hard to test, I would probably let it go. |
How to do that? Tester does not support running more |
|
Running all tests with different configuration can be made by passing evironemnt variables to tester runner and passing that to individual tests. These evironment variables can be then listened in |
|
@dg It is more complicated then it looked at first time. There are still unhandled self::try(function() {return $this->connection->getAttribute();}, function () {success}, function() {failure});However this leads into weakly typed code as PHP does not support generics. |
|
Another option is to have two drivers, one for exception mode and one for warnings mode. And forbid silent mode (it is nonsense mode). And another one option: to switch PDO to warning mode and back before and after each operation. |
|
As PDO can provide consistent API when configured, I will try to go for switching error modes. Hopefuly that will hot have any side effects. There should be none - as long as there will be no nesting or callbacks from inside of the driver. BTW problem with silent mode is that it is default. Current implementation of PdoDriver relays on silent mode. API that changes by configuration is hell🔥. |
e5e6a36 to
7a49609
Compare
ac73982 to
0ff61a4
Compare
3f93ac5 to
3cbf5e5
Compare
f456e4f to
15a9c98
Compare
45c0839 to
8881eb1
Compare
|
Hi, can I somehow help with this to get it merged? Would be pretty helpful in a project of mine. |
|
@PavelJurasek You can go through the comments and try to solve problems that are left. As I see this now from bigger perspective. Could you please try to implement three PdoDrivers, for each mode? They each have different API and it is huge mess to try to implement it in one class. If you wish I can go through the current proposal if you wish. |
|
@jiripudil Could you please go through these changes? I'm quite busy this week. :) |
|
Bump |
|
Rebased and fixed some of the tests in https://github.com/PavelJurasek/dibi/tree/fix-pdo-connection-in-exception-mode @dg @jkuchar is there something else I could do to push this forward? |
see #292