-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autoincrement via identity columns on Oracle #5443
Conversation
@greg0ire @derrabus if we decide to move forward with this, we need to consider changes in the Oracle allows retrieval of the identity column value as follows: $stmt = $connection->prepare('INSERT INTO AUTO_INCREMENT_TABLE VALUES(DEFAULT) RETURNING ID INTO :ID');
$stmt->bindParam('id', $id);
$stmt->executeStatement();
echo $id, PHP_EOL;
// 1 Despite it not being widespread, personally, I believe it's the most reasonable way of dealing with autogenerated values in SQL. The current interface SomeNewName
{
public function insert(EntityManagerInterface $em, $entity);
} In addition to having autoincrement columns implemented in a more similar way across platforms, this may allow dropping the support of sequences at all, since they are used only as an implementation of autoincrement columns. What do you think? Would you be interested in making the necessary API changes in the ORM? Otherwise, I don't think we can proceed with this change. |
The new API you're suggesting makes perfect sense to me. However, I wonder if a piece of code that uses the DBAL for performing inserts should be aware of how to retrieve the generated ID for the current DBMS. Would it make sense to create an API for that in DBAL, something like a low-level version of |
I tried but couldn't really come up with an abstract DBAL-level API for that. I propose that we implement a working code prototype first and then decide which library will own the new API. Personally, I believe that it should belong to the ORM because when it comes to building SQL, the DBAL isn't aware of any entity metadata while the ORM is. |
Applying "tell, don't ask" here too sounds great on paper 👍 In practice, I've looked at the ORM code, and I've found 4 places where id generators is used:
The 3 first one seem related to insertion, although they are not all located in the same place. The last one is about getting the entity state, and I'm not sure towards what we should migrate it, but maybe you do? |
I'm not familiar with the ORM at all, but the last case looks like a hack to me — determining the state of the entity based on whether or not it has an identifier. Why cannot this state be explicitly updated after a successful attempt to persist the entity? We can agree that the responsibilities of the new method will be (in no particular order):
If this operation succeeds, then something else can update the state of the entity to something appropriate. |
I don't feel up to that task, sorry 😞 |
Closing it for now. |
See #4744, #5396.