spadefoot / kohana-orm-leap

An ORM module for the Kohana PHP framework that is designed to work with all major databases.
http://spadefoot.github.io/kohana-orm-leap/
100 stars 25 forks source link

how to work with transactions? #83

Closed ghost closed 11 years ago

ghost commented 11 years ago

hey guys,

i would like to work with the transaction mode to explicit commit my changes.

i start with this line: DB_Connection_Pool::instance()->get_connection()->begin_transaction();

if a error occured i want to rollback all changes with this: DB_Connection_Pool::instance()->get_connection()->rollback();

in the meantime i work with the DB_ORM syntax to create and change data. the transaction mode does not seem to work.... the queries are always executed and the data will be pushed to the db..... i am using the mysql, oracle and firebird controller. on each database it will not work for me....

thx!

bluesnowman commented 11 years ago

I will look into why you might be experiencing this problem. What class methods are you calling on DB_ORM so that I try to replicate the problem? save()?

bluesnowman commented 11 years ago

@viperneo Which drivers for are you using? Standard? PDO? Improved?

ghost commented 11 years ago

Standard Driver and i will do DBORM::select and if i am inserting something i will create a model with new Model... and call then save().

bluesnowman commented 11 years ago

@viperneo I just tested the following code using two different "id" values: one that works (1) and one that should fail (-1). It looks like everything worked fine for me.

        DB_Connection_Pool::instance()->get_connection('default')->begin_transaction();
        try {
            $model = new Model_Leap_Role();
            $model->id = 1; // Will commit
            //$model->id = -1; // Will rollback
            $model->name = 'NAME';
            $model->description = 'DESCRIPTION';
            $model->save();
            $model->dispose(FALSE);
            unset($model);
            DB_Connection_Pool::instance()->get_connection('default')->commit();
        }
        catch (Exception $ex) {
            DB_Connection_Pool::instance()->get_connection('default')->rollback();
        }