Is it possible to wrap a mapper insert in a transaction?

38 views
Skip to first unread message

Matt Darby

unread,
Feb 13, 2019, 3:51:13 PM2/13/19
to Fat-Free Framework
Hello

I'm using the SQL mapper to insert a number of records that I want to wrap in a single commit scope. However the mapper actions seem to ignore the rollback in my test code:

$db->begin();
$f3->set('mapper',new mapper($db,'my_table'));
$f3->get('mapper')->copyFrom($someData);
$f3->get('mapper')->insert();

$db->rollback();

Running snipper above a record is inserted. 

Does the mapper support a transaction scope?

Matt

ved

unread,
Feb 13, 2019, 6:12:37 PM2/13/19
to Fat-Free Framework
Try it like this:

$f3->set('mapper',new mapper($db,'my_table'));


$db
->begin();

Matt Darby

unread,
Feb 14, 2019, 2:23:10 AM2/14/19
to Fat-Free Framework

Thanks for the response but the result is still the same.

ved

unread,
Feb 14, 2019, 3:43:19 AM2/14/19
to Fat-Free Framework
Hi,

Does it work as intended if you replace the mapper calls with equivalent exec(raw sql)?
Not exactly sure if the data mappers support transactions but I was under the impression that they did.

xfra35

unread,
Feb 14, 2019, 12:28:52 PM2/14/19
to Fat-Free Framework
Hi,

The mapper does support transactions. But not all engines support it.

For example, if you're using MySQL, MyISAM storage engine doesn't support transactions, while InnoDB does.

Matt Darby

unread,
Feb 14, 2019, 2:24:40 PM2/14/19
to Fat-Free Framework
Many thanks for that - spot on.
Reply all
Reply to author
Forward
0 new messages