queryBatch bug

If you have any 'mechanical' forge related issues/suggestions, pop them in here.

Moderators: RussW, ChiefGoFor

Locked
crewce
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed Oct 31, 2007 10:46 pm

queryBatch bug

Post by crewce » Sun Jul 06, 2008 5:50 pm

You do not have ROLLBACK if something goes wrong with the queries and we need to execute them in transaction mode.
Here, I'll give you a fix.

Code: Select all

function queryBatch( $abort_on_error=true, $p_transaction_safe = false)
	{
		$this->_errorNum = 0;
		$this->_errorMsg = '';
		if ($p_transaction_safe) {
			$this->_sql = rtrim($this->_sql, '; \t\r\n\0');
			$si = $this->getVersion();
			preg_match_all( "/(\d+)\.(\d+)\.(\d+)/i", $si, $m );
			if ($m[1] >= 4) {
				$this->_sql = 'START TRANSACTION;' . $this->_sql . '; COMMIT;';
			} else if ($m[2] >= 23 && $m[3] >= 19) {
				$this->_sql = 'BEGIN WORK;' . $this->_sql . '; COMMIT;';
			} else if ($m[2] >= 23 && $m[3] >= 17) {
				$this->_sql = 'BEGIN;' . $this->_sql . '; COMMIT;';
			}
		}
		$query_split = $this->splitSql($this->_sql);
		$error = 0;
		foreach ($query_split as $command_line) {
			$command_line = trim( $command_line );
			if ($command_line != '') {
				$this->_cursor = mysql_query( $command_line, $this->_resource );
				if (!$this->_cursor) {
					$error = 1;
					$this->_errorNum .= mysql_errno( $this->_resource ) . ' ';
					$this->_errorMsg .= mysql_error( $this->_resource )." SQL=$command_line <br />";
					if ($abort_on_error) {
                                               mysql_query( 'ROLLBACK', $this->_resource ); //new added
						return $this->_cursor;
					}
				}
			}
		}
                if ($error) mysql_query( 'ROLLBACK', $this->_resource ); //new added
		return $error ? false : true;
	}

User avatar
tsimpo
Joomla! Guru
Joomla! Guru
Posts: 527
Joined: Thu Sep 15, 2005 5:09 am
Location: Greece
Contact:

Re: queryBatch bug

Post by tsimpo » Mon Dec 29, 2008 10:54 am

I'm also using queryBatch(), for the first time, and I make a mistake in the third sql in my batch query but the first two wasn't rolled back.

I used of course true on error and safe

queryBatch( true, true )

Is there anything else I have to do for making roll back work?
Joomla sites. http://www.webcase.gr Υπηρεσίες Internet, websites, Joomla! dedicated services.


Locked

Return to “JoomlaCode.org”