aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorPaul S. Owen <psotfx@users.sourceforge.net>2001-07-03 22:47:26 +0000
committerPaul S. Owen <psotfx@users.sourceforge.net>2001-07-03 22:47:26 +0000
commit356f845abc4ed17322c7afc904ba4a67718327d2 (patch)
tree0d2d54971f32ce6b8698802f739982a6db5c11ea /phpBB
parent8baa46e2856552b68938c1e6e8ad9e355bf7f3e9 (diff)
downloadforums-356f845abc4ed17322c7afc904ba4a67718327d2.tar
forums-356f845abc4ed17322c7afc904ba4a67718327d2.tar.gz
forums-356f845abc4ed17322c7afc904ba4a67718327d2.tar.bz2
forums-356f845abc4ed17322c7afc904ba4a67718327d2.tar.xz
forums-356f845abc4ed17322c7afc904ba4a67718327d2.zip
Transaction capability moved to DB classes
git-svn-id: file:///svn/phpbb/trunk@546 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/db/mssql.php87
-rw-r--r--phpBB/db/mysql.php4
-rw-r--r--phpBB/db/odbc.php4
-rw-r--r--phpBB/db/oracle.php4
-rw-r--r--phpBB/db/postgres7.php43
5 files changed, 104 insertions, 38 deletions
diff --git a/phpBB/db/mssql.php b/phpBB/db/mssql.php
index 3809e6a58e..032e00587a 100644
--- a/phpBB/db/mssql.php
+++ b/phpBB/db/mssql.php
@@ -29,6 +29,8 @@ class sql_db
var $db_connect_id;
var $query_result;
+ var $in_transaction = 0;
+ var $transaction_name;
var $query_limit_offset;
var $query_limit_numrows;
var $query_limit_success;
@@ -91,7 +93,7 @@ class sql_db
//
// Query method
//
- function sql_query($query = "")
+ function sql_query($query = "", $transaction = FALSE)
{
//
// Remove any pre-existing queries
@@ -100,27 +102,30 @@ class sql_db
unset($this->row);
if($query != "")
{
+ if($transaction == BEGIN_TRANSACTION)
+ {
+ $result = mssql_query("BEGIN TRANSACTION", $this->db_connect_id);
+ if(!$result)
+ {
+ return false;
+ }
+ $this->in_transaction = TRUE;
+ }
+
//
- // Does query contain any LIMIT code?
- // If so pull out relevant start and num_results
- // This isn't terribly easy with MSSQL, whatever
- // you do will potentially impact performance
- // compared to an 'in-built' limit
+ // Does query contain any LIMIT code? If so pull out relevant start and num_results
+ // This isn't terribly easy with MSSQL, whatever you do will potentially impact
+ // performance compared to an 'in-built' limit
//
- // Another issue is the 'lack' of a returned true
- // value when a query is valid but has no result
- // set (as with all the other DB interfaces).
- // It seems though that it's 'fair' to say that if
- // a query returns a false result (ie. no resource id)
- // then the SQL was valid but had no result set. If the
- // query returns nothing but the rowcount returns
- // something then there's a problem. This
- // may well be a false assumption though ... needs
- // checking under Windows itself.
+ // Another issue is the 'lack' of a returned true value when a query is valid but has
+ // no result set (as with all the other DB interfaces). It seems though that it's
+ // 'fair' to say that if a query returns a false result (ie. no resource id) then the
+ // SQL was valid but had no result set. If the query returns nothing but the rowcount
+ // returns something then there's a problem. This may well be a false assumption though
+ // ... needs checking under Windows itself.
//
if(eregi("LIMIT", $query))
{
- "HERE";
preg_match("/^(.*)LIMIT ([0-9]+)[, ]*([0-9]+)*/s", $query, $limits);
$query = $limits[1];
@@ -135,15 +140,17 @@ class sql_db
$num_rows = $limits[2];
}
- "<br>".$query."<br>";
@mssql_query("SET ROWCOUNT ".($row_offset + $num_rows));
+
$this->query_result = @mssql_query($query, $this->db_connect_id);
+
@mssql_query("SET ROWCOUNT 0");
$this->query_limit_success[$this->query_result] = true;
$this->query_limit_offset[$this->query_result] = -1;
$this->query_limit_numrows[$this->query_result] = $num_rows;
+
if($this->query_result && $row_offset > 0)
{
$result = @mssql_data_seek($this->query_result, $row_offset);
@@ -163,47 +170,69 @@ class sql_db
$next_id_query = @mssql_query("SELECT @@IDENTITY AS this_id");
$this->next_id[$this->query_result] = $this->sql_fetchfield("this_id", -1, $next_id_query);
}
+ else
+ {
+ if($this->in_transaction)
+ {
+ mssql_query("ROLLBACK", $this->db_connect_id);
+ $this->in_transaction = FALSE;
+ }
+ return false;
+ }
+
$this->query_limit_offset[$this->query_result] = -1;
$this->query_limit_numrows[$this->query_result] = -1;
}
else
{
- //
- // This needs a little more work
- // before we take it public. SELECT needs
- // separating out, with other queries
- // (UPDATE, DELETE, etc.) having a uniqid
- // $this-
- //
if(eregi("SELECT", $query))
{
- $this->query_result = @@mssql_query($query, $this->db_connect_id);
+ $this->query_result = @mssql_query($query, $this->db_connect_id);
}
else
{
- $this->query_result = @@mssql_query($query, $this->db_connect_id);
+ $this->query_result = @mssql_query($query, $this->db_connect_id);
if($this->query_result)
{
$this->query_result = uniqid(rand());
}
}
+
if($this->query_result)
{
$affected_query = @mssql_query("SELECT @@ROWCOUNT AS this_count");
+
$this->affected_rows[$this->query_result] = $this->sql_fetchfield("this_count", -1, $affected_query);
+
$this->query_limit_offset[$this->query_result] = -1;
$this->query_limit_numrows[$this->query_result] = -1;
}
else
{
+ if($this->in_transaction)
+ {
+ mssql_query("ROLLBACK", $this->db_connect_id);
+ $this->in_transaction = FALSE;
+ }
return false;
}
}
+ if($transaction == END_TRANSACTION)
+ {
+ $result = mssql_query("COMMIT", $this->db_connect_id);
+ }
+
return $this->query_result;
}
else
{
+ if($transaction == END_TRANSACTION)
+ {
+ $result = mssql_query("COMMIT", $this->db_connect_id);
+ $this->in_transaction = FALSE;
+ }
+
return false;
}
}
@@ -436,7 +465,7 @@ class sql_db
}
if($query_id)
{
- return $this->next_id[$query_id]+1;
+ return $this->next_id[$query_id];
}
else
{
@@ -469,4 +498,4 @@ class sql_db
} // if ... define
-?>
+?> \ No newline at end of file
diff --git a/phpBB/db/mysql.php b/phpBB/db/mysql.php
index 2cf94606d0..9afe8acbe8 100644
--- a/phpBB/db/mysql.php
+++ b/phpBB/db/mysql.php
@@ -94,7 +94,7 @@ class sql_db
//
// Base query method
//
- function sql_query($query = "")
+ function sql_query($query = "", $transaction = FALSE)
{
// Remove any pre-existing queries
unset($this->query_result);
@@ -323,4 +323,4 @@ class sql_db
} // if ... define
-?>
+?> \ No newline at end of file
diff --git a/phpBB/db/odbc.php b/phpBB/db/odbc.php
index 251c218550..6b21346603 100644
--- a/phpBB/db/odbc.php
+++ b/phpBB/db/odbc.php
@@ -117,7 +117,7 @@ class sql_db
//
// Query method
//
- function sql_query($query = "")
+ function sql_query($query = "", $transaction = FALSE)
{
//
// Remove any pre-existing queries
@@ -457,4 +457,4 @@ class sql_db
} // if ... define
-?>
+?> \ No newline at end of file
diff --git a/phpBB/db/oracle.php b/phpBB/db/oracle.php
index 948c5e1949..c26001efc7 100644
--- a/phpBB/db/oracle.php
+++ b/phpBB/db/oracle.php
@@ -84,7 +84,7 @@ class sql_db
//
// Base query method
//
- function sql_query($query = "")
+ function sql_query($query = "", $transaction = FALSE)
{
// Remove any pre-existing queries
unset($this->query_result);
@@ -362,4 +362,4 @@ class sql_db
} // if ... define
-?>
+?> \ No newline at end of file
diff --git a/phpBB/db/postgres7.php b/phpBB/db/postgres7.php
index 08f065f0e7..981439cc10 100644
--- a/phpBB/db/postgres7.php
+++ b/phpBB/db/postgres7.php
@@ -28,7 +28,8 @@ class sql_db
{
var $db_connect_id;
- var $query_result;
+ var $query_result;
+ var $in_transaction = 0;
var $row;
var $rownum = array();
@@ -115,7 +116,7 @@ class sql_db
//
// Query method
//
- function sql_query($query="")
+ function sql_query($query = "", $transaction = FALSE)
{
// Remove any pre-existing queries
unset($this->query_result);
@@ -123,11 +124,32 @@ class sql_db
{
$query = preg_replace("/LIMIT ([0-9]+),([ 0-9]+)/", "LIMIT \\2, \\1", $query);
+ if($transaction == BEGIN_TRANSACTION)
+ {
+ $result = @pg_exec($this->db_connect_id, "BEGIN");
+ if(!$result)
+ {
+ return false;
+ }
+ }
+
$this->query_result = @pg_exec($this->db_connect_id, $query);
if($this->query_result)
{
+ if($transaction == END_TRANSACTION)
+ {
+ $result = @pg_exec($this->db_connect_id, "COMMIT");
+ if(!$result)
+ {
+ @pg_exec($this->db_connect_id, "ROLLBACK");
+ return false;
+ }
+ $this->in_transaction = FALSE;
+ }
+
$this->last_query_text[$this->query_result] = $query;
$this->rownum[$this->query_result] = 0;
+
unset($this->row[$this->query_result]);
unset($this->rowset[$this->query_result]);
@@ -135,11 +157,26 @@ class sql_db
}
else
{
+ if($this->in_transaction)
+ {
+ @pg_exec($this->db_connect_id, "ROLLBACK");
+ }
return false;
}
}
else
{
+ if($transaction == END_TRANSACTION)
+ {
+ $result = @pg_exec($this->db_connect_id, "COMMIT");
+ if(!$result)
+ {
+ @pg_exec($this->db_connect_id, "ROLLBACK");
+ return false;
+ }
+ $this->in_transaction = FALSE;
+ }
+
return false;
}
}
@@ -391,4 +428,4 @@ class sql_db
} // if ... defined
-?>
+?> \ No newline at end of file