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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to