Fixed various transaction related issues and changed mssql-odbc name to ... mssql-odbc, hopefully this hasn't been (and won't be) responsible for any problems ...

git-svn-id: file:///svn/phpbb/trunk@2269 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-03-05 02:19:38 +00:00
parent be2532588c
commit 28b38f0547
5 changed files with 99 additions and 29 deletions

View file

@ -94,7 +94,7 @@ class sql_db
{
$this->num_queries++;
if( $transaction == BEGIN_TRANSACTION )
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
if( !odbc_autocommit($this->db_connect_id, false) )
{
@ -195,16 +195,35 @@ class sql_db
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
odbc_commit($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
$this->in_transaction = FALSE;
if ( !@odbc_commit($this->db_connect_id) )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
return false;
}
odbc_autocommit($this->db_connect_id, true);
}
return $this->result;
}
else
{
return false;
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
if ( !@odbc_commit($this->db_connect_id) )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
return false;
}
odbc_autocommit($this->db_connect_id, true);
}
return true;
}
}

View file

@ -22,7 +22,7 @@
if(!defined("SQL_LAYER"))
{
define("SQL_LAYER","mssql");
define("SQL_LAYER","mssql-odbc");
class sql_db
{
@ -93,7 +93,7 @@ class sql_db
{
$this->num_queries++;
if( $transaction == BEGIN_TRANSACTION )
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
if( !odbc_autocommit($this->db_connect_id, false) )
{
@ -190,9 +190,15 @@ class sql_db
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
odbc_commit($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
$this->in_transaction = FALSE;
if ( !odbc_commit($this->db_connect_id) )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
return false;
}
odbc_autocommit($this->db_connect_id, true);
}
odbc_free_result($this->result);
@ -201,7 +207,20 @@ class sql_db
}
else
{
return false;
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
if ( !@odbc_commit($this->db_connect_id) )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
return false;
}
odbc_autocommit($this->db_connect_id, true);
}
return true;
}
}

View file

@ -100,13 +100,13 @@ class sql_db
unset($this->result);
unset($this->row);
if( $query != "" )
if ( $query != "" )
{
$this->num_queries++;
if($transaction == BEGIN_TRANSACTION)
if ( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
if( !mssql_query("BEGIN TRANSACTION", $this->db_connect_id) )
if ( !mssql_query("BEGIN TRANSACTION", $this->db_connect_id) )
{
return false;
}
@ -196,12 +196,32 @@ class sql_db
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
mssql_query("COMMIT", $this->db_connect_id);
$this->in_transaction = FALSE;
if( !@mssql_query("COMMIT", $this->db_connect_id) )
{
@mssql_query("ROLLBACK", $this->db_connect_id);
return false;
}
}
return $this->result;
}
else
{
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
if( !@mssql_query("COMMIT", $this->db_connect_id) )
{
@mssql_query("ROLLBACK", $this->db_connect_id);
return false;
}
}
return true;
}
}
//

View file

@ -105,7 +105,7 @@ class sql_db
if( $query != "" )
{
$this->num_queries++;
if( $transaction == BEGIN_TRANSACTION )
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
$result = mysql_query("BEGIN", $this->db_connect_id);
if(!$result)
@ -117,15 +117,28 @@ class sql_db
$this->query_result = mysql_query($query, $this->db_connect_id);
}
else
{
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$result = mysql_query("COMMIT", $this->db_connect_id);
}
}
if( $this->query_result )
{
unset($this->row[$this->query_result]);
unset($this->rowset[$this->query_result]);
if( $transaction == END_TRANSACTION )
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$result = mysql_query("COMMIT", $this->db_connect_id);
$this->in_transaction = FALSE;
if ( !mysql_query("COMMIT", $this->db_connect_id) )
{
mysql_query("ROLLBACK", $this->db_connect_id);
return false;
}
}
return $this->query_result;

View file

@ -109,7 +109,6 @@ class sql_db
}
}
//
// Query method
//
@ -125,14 +124,14 @@ class sql_db
$query = preg_replace("/LIMIT ([0-9]+),([ 0-9]+)/", "LIMIT \\2 OFFSET \\1", $query);
if( $transaction == BEGIN_TRANSACTION )
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
$result = @pg_exec($this->db_connect_id, "BEGIN");
if( !$result )
$this->in_transaction = TRUE;
if( !@pg_exec($this->db_connect_id, "BEGIN") )
{
return false;
}
$this->in_transaction = TRUE;
}
$this->query_result = @pg_exec($this->db_connect_id, $query);
@ -140,13 +139,13 @@ class sql_db
{
if( $transaction == END_TRANSACTION )
{
$result = @pg_exec($this->db_connect_id, "COMMIT");
if( !$result )
$this->in_transaction = FALSE;
if( !@pg_exec($this->db_connect_id, "COMMIT") )
{
@pg_exec($this->db_connect_id, "ROLLBACK");
return false;
}
$this->in_transaction = FALSE;
}
$this->last_query_text[$this->query_result] = $query;
@ -170,18 +169,18 @@ class sql_db
}
else
{
if( $transaction == END_TRANSACTION )
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$result = @pg_exec($this->db_connect_id, "COMMIT");
if( !$result )
$this->in_transaction = FALSE;
if( !@pg_exec($this->db_connect_id, "COMMIT") )
{
@pg_exec($this->db_connect_id, "ROLLBACK");
return false;
}
$this->in_transaction = FALSE;
}
return false;
return true;
}
}