1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-10 18:54:08 +02:00

various fixes and alterations

git-svn-id: file:///svn/phpbb/trunk@4118 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen
2003-06-12 17:11:43 +00:00
parent 68f6998a4c
commit dee0f40fd2
7 changed files with 298 additions and 207 deletions

View File

@@ -40,10 +40,7 @@ class sql_db
var $num_queries = 0;
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->server = $sqlserver;
@@ -51,10 +48,21 @@ class sql_db
$this->password = $sqlpassword;
$this->dbname = $database;
$this->db_connect_id = ($this->persistency) ? odbc_pconnect($this->server, $this->user, $this->password) : odbc_connect($this->server, $this->user, $this->password);
$this->db_connect_id = ($this->persistency) ? @odbc_pconnect($this->server, $this->user, $this->password) : @odbc_connect($this->server, $this->user, $this->password);
return ( $this->db_connect_id ) ? $this->db_connect_id : false;
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
function sql_return_on_error($fail = false)
{
$this->return_on_error = $fail;
}
function sql_num_queries()
{
return $this->num_queries;
}
//
// Other base methods
//
@@ -62,12 +70,12 @@ class sql_db
{
if($this->db_connect_id)
{
if( $this->in_transaction )
if($this->in_transaction)
{
@odbc_commit($this->db_connect_id);
}
if( count($this->result_rowset) )
if(count($this->result_rowset))
{
unset($this->result_rowset);
unset($this->field_names);
@@ -89,36 +97,36 @@ class sql_db
//
function sql_query($query = "", $transaction = FALSE)
{
if( $query != "" )
if($query != "")
{
$this->num_queries++;
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
if($transaction == BEGIN_TRANSACTION && !$this->in_transaction)
{
if( !odbc_autocommit($this->db_connect_id, false) )
if(!odbc_autocommit($this->db_connect_id, false))
{
return false;
}
$this->in_transaction = TRUE;
}
if( preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits) )
if(preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits))
{
$query = $limits[1];
if( !empty($limits[2]) )
if(!empty($limits[2]))
{
$row_offset = ( $limits[4] ) ? $limits[3] : "";
$num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
$row_offset = ($limits[4]) ? $limits[3] : "";
$num_rows = ($limits[4]) ? $limits[4] : $limits[3];
$query = "TOP " . ( $row_offset + $num_rows ) . $query;
$query = "TOP " . ($row_offset + $num_rows) . $query;
}
$this->result = odbc_exec($this->db_connect_id, "SELECT $query");
if( $this->result )
if($this->result)
{
if( empty($this->field_names[$this->result]) )
if(empty($this->field_names[$this->result]))
{
for($i = 1; $i < odbc_num_fields($this->result) + 1; $i++)
{
@@ -130,11 +138,11 @@ class sql_db
$this->current_row[$this->result] = 0;
$this->result_rowset[$this->result] = array();
$row_outer = ( isset($row_offset) ) ? $row_offset + 1 : 1;
$row_outer_max = ( isset($num_rows) ) ? $row_offset + $num_rows + 1 : 1E9;
$row_outer = (isset($row_offset)) ? $row_offset + 1 : 1;
$row_outer_max = (isset($num_rows)) ? $row_offset + $num_rows + 1 : 1E9;
$row_inner = 0;
while( odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max )
while(odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max)
{
for($j = 0; $j < count($this->field_names[$this->result]); $j++)
{
@@ -149,16 +157,16 @@ class sql_db
}
}
else if( eregi("^INSERT ", $query) )
else if(eregi("^INSERT ", $query))
{
$this->result = odbc_exec($this->db_connect_id, $query);
if( $this->result )
if($this->result)
{
$result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY");
if( $result_id )
if($result_id)
{
if( odbc_fetch_row($result_id) )
if(odbc_fetch_row($result_id))
{
$this->next_id[$this->db_connect_id] = odbc_result($result_id, 1);
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
@@ -170,15 +178,15 @@ class sql_db
{
$this->result = odbc_exec($this->db_connect_id, $query);
if( $this->result )
if($this->result)
{
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
}
}
if( !$this->result )
if(!$this->result)
{
if( $this->in_transaction )
if($this->in_transaction)
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -188,11 +196,11 @@ class sql_db
return false;
}
if( $transaction == END_TRANSACTION && $this->in_transaction )
if($transaction == END_TRANSACTION && $this->in_transaction)
{
$this->in_transaction = FALSE;
if ( !odbc_commit($this->db_connect_id) )
if (!odbc_commit($this->db_connect_id))
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -207,11 +215,11 @@ class sql_db
}
else
{
if( $transaction == END_TRANSACTION && $this->in_transaction )
if($transaction == END_TRANSACTION && $this->in_transaction)
{
$this->in_transaction = FALSE;
if ( !@odbc_commit($this->db_connect_id) )
if (!@odbc_commit($this->db_connect_id))
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -229,54 +237,54 @@ class sql_db
//
function sql_numrows($query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
return ( $query_id ) ? $this->num_rows[$query_id] : false;
return ($query_id) ? $this->num_rows[$query_id] : false;
}
function sql_numfields($query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
return ( $query_id ) ? count($this->field_names[$query_id]) : false;
return ($query_id) ? count($this->field_names[$query_id]) : false;
}
function sql_fieldname($offset, $query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
return ( $query_id ) ? $this->field_names[$query_id][$offset] : false;
return ($query_id) ? $this->field_names[$query_id][$offset] : false;
}
function sql_fieldtype($offset, $query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
return ( $query_id ) ? $this->field_types[$query_id][$offset] : false;
return ($query_id) ? $this->field_types[$query_id][$offset] : false;
}
function sql_fetchrow($query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
if( $query_id )
if($query_id)
{
return ( $this->num_rows[$query_id] && $this->current_row[$query_id] < $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id][$this->current_row[$query_id]++] : false;
return ($this->num_rows[$query_id] && $this->current_row[$query_id] < $this->num_rows[$query_id]) ? $this->result_rowset[$query_id][$this->current_row[$query_id]++] : false;
}
else
{
@@ -286,14 +294,14 @@ class sql_db
function sql_fetchrowset($query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
if( $query_id )
if($query_id)
{
return ( $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id] : false;
return ($this->num_rows[$query_id]) ? $this->result_rowset[$query_id] : false;
}
else
{
@@ -303,16 +311,16 @@ class sql_db
function sql_fetchfield($field, $row = -1, $query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
if( $query_id )
if($query_id)
{
if( $row < $this->num_rows[$query_id] )
if($row < $this->num_rows[$query_id])
{
$getrow = ( $row == -1 ) ? $this->current_row[$query_id] - 1 : $row;
$getrow = ($row == -1) ? $this->current_row[$query_id] - 1 : $row;
return $this->result_rowset[$query_id][$getrow][$this->field_names[$query_id][$field]];
@@ -330,12 +338,12 @@ class sql_db
function sql_rowseek($offset, $query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
if( $query_id )
if($query_id)
{
$this->current_row[$query_id] = $offset - 1;
return true;
@@ -348,17 +356,17 @@ class sql_db
function sql_nextid()
{
return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
return ($this->next_id[$this->db_connect_id]) ? $this->next_id[$this->db_connect_id] : false;
}
function sql_affectedrows()
{
return ( $this->affected_rows[$this->db_connect_id] ) ? $this->affected_rows[$this->db_connect_id] : false;
return ($this->affected_rows[$this->db_connect_id]) ? $this->affected_rows[$this->db_connect_id] : false;
}
function sql_freeresult($query_id = 0)
{
if( !$query_id )
if(!$query_id)
{
$query_id = $this->result;
}
@@ -372,12 +380,28 @@ class sql_db
return true;
}
function sql_error()
function sql_error($sql = '')
{
$error['code'] = odbc_error($this->db_connect_id);
$error['message'] = odbc_errormsg($this->db_connect_id);
if (!$this->return_on_error)
{
if ($this->transaction)
{
$this->sql_transaction('rollback');
}
return $error;
$this_page = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF'];
$this_page .= '&' . ((!empty($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']);
$message = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @odbc_errormsg() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . htmlspecialchars($this_page) . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />';
trigger_error($message, E_USER_ERROR);
}
$result = array(
'message' => @odbc_errormsg(),
'code' => @odbc_error()
);
return $result;
}
} // class sql_db