CodeIgniter Forums
Re Enable Transactions after using trans_off() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Re Enable Transactions after using trans_off() (/showthread.php?tid=66440)



Re Enable Transactions after using trans_off() - dave friend - 10-22-2016

To disable database transactions at run-time you can call

PHP Code:
$this->db->trans_off(); 

Maybe I am missing something but I don't see any way to reverse this call to allow transaction processing.

The abstract class DB_driver defines trans_off() with this code.

PHP Code:
public function trans_off()
{
 
   $this->trans_enabled FALSE;


The property $trans_enabled is used throughout the class to allow (or not) class methods to proceed. For instance

PHP Code:
public function trans_start($test_mode FALSE)
{
 if ( ! 
$this->trans_enabled)
 {
 return 
FALSE;
 }

 return 
$this->trans_begin($test_mode);


The "issue", if there is one, is that the documentation at Enabling Transactions implies that calling $this->db->trans_start(); will re-start transaction processing after a call to $this->db->trans_off(); But that is not the case as the code snippet above clearly illustrates.


RE: Re Enable Transactions after using trans_off() - Narf - 10-22-2016

"disable" doesn't just mean "stop" or "end", it means you're not allowed to do it.


RE: Re Enable Transactions after using trans_off() - dave friend - 10-22-2016

Ya, I get that. But the example might leave people to believe that the not allowed status is reversed by calling trans_start().


RE: Re Enable Transactions after using trans_off() - Narf - 10-22-2016

That makes no sense, the whole point of trans_off() is to make trans_start() do nothing.


RE: Re Enable Transactions after using trans_off() - dave friend - 10-22-2016

I get that too. I have no argument with the implementation. But look at the documentation link I provided. The example does suggest that after a call to trans_off() you can resume using transactions by calling trans_start(). There's more than one post on SO where their problem was a misunderstanding trans_off().


RE: Re Enable Transactions after using trans_off() - Narf - 10-22-2016

I did look at the link and it doesn't suggest anything like that.


RE: Re Enable Transactions after using trans_off() - dave friend - 10-23-2016

The Enabling Transactions section begins with

Quote:Transactions are enabled automatically the moment you use $this->db->trans_start(). If you would like to disable transactions you can do so using $this->db->trans_off():

which is followed immediately by this example code.

PHP Code:
$this->db->trans_off();

$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->trans_complete(); 

And you don't think that this example suggests, implies or otherwise demonstrates that transactions will be resumed after the call to trans_off()? That has to be because of your intimate knowledge of the source code. Without that knowledge and within the context of "Enabling Transactions" I don't see how the example can be interpreted in any way other than a demonstration of trans_start() as being the opposite of trans_off().

If the point of the example is to explain that the call $this->db->query('AN SQL QUERY...'); will not be handled as a transaction then that needs to be explicitly stated. The fact that
Quote:"disable" doesn't just mean "stop" or "end", it means you're not allowed to do it.
needs to be explained as does the fact that neither trans_start() or trans_begin() will reverse that state.


RE: Re Enable Transactions after using trans_off() - Narf - 10-24-2016

(10-23-2016, 08:20 AM)dave friend Wrote: The Enabling Transactions section begins with

Quote:Transactions are enabled automatically the moment you use $this->db->trans_start(). If you would like to disable transactions you can do so using $this->db->trans_off():

which is followed immediately by this example code.

PHP Code:
$this->db->trans_off();

$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->trans_complete(); 

And you don't think that this example suggests, implies or otherwise demonstrates that transactions will be resumed after the call to trans_off()? That has to be because of your intimate knowledge of the source code. Without that knowledge and within the context of "Enabling Transactions" I don't see how the example can be interpreted in any way other than a demonstration of trans_start() as being the opposite of trans_off().

If the point of the example is to explain that the call $this->db->query('AN SQL QUERY...'); will not be handled as a transaction then that needs to be explicitly stated. The fact that
Quote:"disable" doesn't just mean "stop" or "end", it means you're not allowed to do it.
needs to be explained as does the fact that neither trans_start() or trans_begin() will reverse that state.

I argree that this sentence is confusing:

Quote:Transactions are enabled automatically the moment you use $this->db->trans_start(). If you would like to disable transactions you can do so using $this->db->trans_off():

It is wrong in at least 2 ways.

But the example itself is in no way incorrect, and you did only talk about the example up until now. There's nothing wrong or misleading in the example itself.


RE: Re Enable Transactions after using trans_off() - Narf - 10-24-2016

https://github.com/bcit-ci/CodeIgniter/commit/777bb986d9e252dcc4dde3c76c03b0e0c7c1f8ef


RE: Re Enable Transactions after using trans_off() - dave friend - 10-24-2016

(10-24-2016, 12:23 AM)Narf Wrote: https://github.com/bcit-ci/CodeIgniter/commit/777bb986d9e252dcc4dde3c76c03b0e0c7c1f8ef

Thank you.