Re: [Proposal] Add `savepoint()` method to PDO
| From: | Kentaro Takeda via internals | Date: | Mon, 05 Feb 2024 12:35:43 +0000 |
| Subject: | Re: [Proposal] Add `savepoint()` method to PDO | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-122283@lists.php.net to get a copy of this message | ||
Hi Saki,
Aside from a few concerns, I think your proposal is very sensible.
I have long felt a disconnect that while we have
beginTransaction(),
commit(), and rollback() methods, there's no equivalent
functionality for SAVEPOINT in PDO. It seems natural to support
these commonly used transactional features as part of PDO's
functionality.
Having consistent support through PDO would be greatly appreciated
from a user perspective, but I do have concerns regarding the
variations in SQL. The following code is quoted from Laravel:
https://github.com/laravel/framework/blob/v10.43.0/src/Illuminate/Database/Query/Grammars/Grammar.php#L1307-L1310
```php
return 'SAVEPOINT '.$name;
```
While most databases use SAVEPOINT [name], but:
https://github.com/laravel/framework/blob/v10.43.0/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php#L453-L456
```php
return 'SAVE TRANSACTION '.$name;
```
SQL Server uniquely uses SAVE TRANSACTION [name]. There might be
other variations in databases, so full support could be challenging,
which is something to be mindful of.
> change the signature of rollback() to
> rollback(?string $name = null).
This might lead to confusion due to rollback() having multiple
functionalities, as ROLLBACK and ROLLBACK TO [name] target
different rollback operations.
Just as beginTransaction() and savepoint() are separate, perhaps
having a separate method for rolling back to a savepoint might
maintain consistency, for example rollbackToSavepoint(string $name).
Regards.
Kentaro