I'm uploading image file to storage server. Before uploading I should compose filename, which contains AUTOINCREMENT VALUE in it (for example, 12345_filename.jpg).
How could I get autoincrement value before inserting into DB?
I see only one solution
- insert empty row
- get it's autoincrement value
- delete this row
- insert row with real data using autoincrement value from p.1
Is there any other solutions?
The autoincrement value is generated by the database itself, when the insertion is done ; which means you cannot get it before doing the actual insert query.
The solution you proposed is not the one that's often used -- which would be :
whereclause of the
updatequery, to identify which row is being updated.
Of course, as a security precaution, all these operations have to be made in a transaction (to ensure a "all or nothing" behavior)
As pseudo-code :