Welcome Guest, Not a member yet? Register   Sign In
Re Enable Transactions after using trans_off()
#1

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.
Reply
#2

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

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

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

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().
Reply
#6

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

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.
Reply
#8

(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.
Reply
Reply
#10

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

Thank you.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB