Master/Detail-Add - There is no active transaction (v2023)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
elonmusk
User
Posts: 48

Master/Detail-Add - There is no active transaction (v2023)

Post by elonmusk »

C:\xampp\htdocs\dev\tw_portal_2023\vendor\doctrine\dbal\src\Driver\PDO\PDOException.php(20): There is no active transaction
When i try to add new entry, after click add button this above error is showing


arbei
User
Posts: 9384

Post by arbei »

You may enable Debug and post the complete stack trace of the exception. If it is raised by your server event, post your complete code for discussion.


elonmusk
User
Posts: 48

Post by elonmusk »

This is the debug code.

#0 C:\xampp\htdocs\athira\dev\tw_portal_2023\vendor\doctrine\dbal\src\Driver\PDO\Connection.php(137): Doctrine\DBAL\Driver\PDO\PDOException::new(Object(PDOException))
#1 C:\xampp\htdocs\athira\dev\tw_portal_2023\vendor\doctrine\dbal\src\Connection.php(1516): Doctrine\DBAL\Driver\PDO\Connection->rollBack()
#2 C:\xampp\htdocs\athira\dev\tw_portal_2023\models\TechWrtgInputAdd.php(1985): Doctrine\DBAL\Connection->rollBack()
#3 C:\xampp\htdocs\athira\dev\tw_portal_2023\models\TechWrtgInputAdd.php(603): PHPMaker2023\technical_writing_automation_1v00_23\TechWrtgInputAdd->addRow(NULL)
#4 C:\xampp\htdocs\athira\dev\tw_portal_2023\controllers\ControllerBase.php(50): PHPMaker2023\technical_writing_automation_1v00_23\TechWrtgInputAdd->run()

arbei
User
Posts: 9384

Post by arbei »

arbei wrote:

If it is raised by your server event, post your complete code for discussion.

If you have Row_Inserting and/or Row_Inserted server event, you may post for discussion.

If not, you may provide more information:

  1. What is the database type? If MySQL, what is the engine of the table? Is it InnoDB?
  2. Are you doing Master/Detail-Add/Copy for the table?
  3. Post your table schema of the master table (and detail tables, if any) so other users can try to reproduce.

Notes:

  1. If InnoDB, transaction is supported. Check the table schema of the table and make sure the engine is not set as MyISAM (which does not support transaction).
  2. The error said no active transaction, but the transaction should be started by $conn->beginTransaction() in TechWrtgInputAdd.php (check source code before line 1985). If you have no Row_Inserting or Grid_Inserting server event for the detail table, then the transaction should be intact and you should be able to rollback. You better check if there is anything preventing the transaction from working.
  3. Make sure no other server events called $conn->commit() or $conn->rollback() otherwise there is no more active transaction.

elonmusk
User
Posts: 48

Post by elonmusk »

MySql and InnoDB

For master table:

public function rowInserting($rsold, &$rsnew) {
    	// Enter your code here
    	// To cancel, set return value to FALSE
    	$userid = CurrentUserID();
    	$slno = ExecuteScalar("SELECT MAX(SLNO) FROM tech_wrtg_input");
    	if (strlen($slno) == 0)
    		$slno = 1;
    	Execute("ALTER TABLE tech_wrtg_input auto_increment =".$slno);
    	$rsnew['VERIFIER_STATUS'] = 'Pending';
    	$rsnew['APPROVAL_STATUS'] = 'Pending';
    	$dept = CurrentUserDept();
    	$tw_arr_emp = array(1277,2374,2224);
    	if ($dept != 'ADM' and $dept != 'HDD' and $dept != 'SDG' and $dept != 'PDN' and $dept != 'PRJ' and !in_array($userid, $tw_arr_emp)){
    		$this->CancelMessage = "Access Denied. Please contact QAC TW team member.";
    		return false;
    	}
    	$_SESSION['po_attachment'] = $rsnew['PO_FILE'];
    	if ($rsnew['ACCESS_GIVEN'] == 'No') {
    		$this->CancelMessage = "You cannot raise this request until access is given to TW Team.";
    		return false;
    	}

    	// Insert document type based on child table
    	if (isset($_GET['showdetail'])) {
    		$_SESSION['tableName'] = $_GET['showdetail'];
    	}
    	$tableName = $_SESSION['tableName'];
    	if (strpos($tableName, 'tech_wrtg_prj_doc') !== false)
    		$rsnew['DOCUMENT_TYPE'] = 'Project Document';
    	if (strpos($tableName, 'tech_wrtg_pdn_doc') !== false)
    		$rsnew['DOCUMENT_TYPE'] = 'Production Document';
    	/*// Validate Document Type to be prepared field If Project Document
    	if (strpos($tableName, 'tech_wrtg_prj_doc') !== false and strlen($rsnew['CHKL_TYPE']) == 0) {
    		$this->CancelMessage = "Please select Document Type to be prepared field.";
    		return false;
    	}*/
    	return TRUE;
    }

    // Row Inserted event
    public function rowInserted($rsold, &$rsnew) {
    	//echo "Row Inserted"
    	$_SESSION['viewpageredirct'] = "RedirectViewPage";
    }

after i commented this line it working fine,

Execute("ALTER TABLE tech_wrtg_input auto_increment =".$slno);

How i execute that query?


arbei
User
Posts: 9384

Post by arbei »

You must not alter a table everytime before you insert a record to the table. Your ALTER TABLE is wrong in syntax. What are you trying to do?

If a field is autocrement, you don't need to set it at all.


Post Reply