Open DiogoBatistaComponto opened 8 years ago
@DiogoBatistaComponto could you try structuring your code like this?
try {
Capsule::beginTransaction();
Capsule::table('streaming_configuration_table')
->where('id', '1')
->update(
[
'current_table' => 'qwerty',
]
);
Capsule::commit();
} catch (\Exception $e){
Capsule::rollback();
var_dump($e);
}
@arippberger Thanks for the reply but i already tried that code and it does work, i can successfully see the update in the database. but what i want is to force the rollback and see the transaction failing so i can be sure that all operations in that transactions only happen if non of them fails. And this i can not do.
Every time i force the rollback, or force a Exception, rollback doesn't work.
try {
Capsule::beginTransaction();
Capsule::table('streaming_configuration_table')
->where('id', '1')
->update(
[
'current_table' => 'qwerty',
]
);
Capsule::table('streaming_configuration_table')
->where('id', 'SOME_NUMBER_NOT_IN_DB')
->update(
[
'current_table' => 'qwerty',
]
);
Capsule::commit();
} catch (\Exception $e){
Capsule::rollback();
var_dump($e);
}
@DiogoBatistaComponto Can you confirm that this does not update current_table
for me?
Hello @arippberger thank you for your reply, i tried your solution and the outcome was that the first set of code worked and updated the table and the second one didn't sort any kind of result, it didn't insert any record and didn't rollback the update that was done in the first set of code. I think that you wanted to force a SQL exception on the second update and do the rollback but it didn't worked.
Thank you
Hello,
Didn't get a response to this issue, do you have any solutions??
Thank you
Hello, i'm having an issue with transactions, i need to execute some table operations and want to be sure that every update is successful before continue my actions. Since you do not have explicit documentation on Transactions, im using the example below:
composer.json:
Sample code i'm using:
The expected result is that the update will have no effect but it seems that, somehow, the update commits successfully, not being able to rollback.
Can you please help me with this situation?
Thank you, Waiting for your feedback