Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
1 parent ae5c01cc78
commit 78706903a2
2641 files changed
+228363 -201264

No files matched your search

+128 -76
View File
@@ -3,19 +3,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.1.4
* IP.Board v3.2.3
* Database Abstraction Layer
* Last Updated: $Date: 2010-09-20 20:20:12 -0400 (Mon, 20 Sep 2010) $
* Last Updated: $Date: 2011-10-10 16:21:29 -0400 (Mon, 10 Oct 2011) $
* </pre>
*
* @author $Author: bfarber $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/community/board/license.html
* @license This is NULLED!
* @package IP.Board
* @subpackage Kernel
* @link http://www.invisionpower.com
* @link http://hatynka.in
* @since Monday 28th February 2005 16:46
* @version $Revision: 467 $
* @version $Revision: 9590 $
*
* Basic Usage Examples
* <code>
@@ -66,6 +66,13 @@ interface interfaceDb
* @return boolean Connection successful
*/
public function connect();
/**
* Return the connection ID
*
* @return resource Connection ID
*/
public function getConnectionId();
/**
* Close database connection
@@ -140,7 +147,7 @@ interface interfaceDb
* Takes array of set commands and generates a SQL formatted query
*
* @param array Set commands (select, from, where, order, limit, etc)
* @return void
* @return @e void
*/
public function build( $data );
@@ -150,7 +157,7 @@ interface interfaceDb
* @param string Name of query file method to use
* @param array Optional arguments to be parsed inside query function
* @param string Optional class name
* @return void
* @return @e void
*/
public function buildFromCache( $method, $args=array(), $class='sql_queries' );
@@ -218,7 +225,7 @@ interface interfaceDb
* Free result set from memory
*
* @param resource [Optional] Query id
* @return void
* @return @e void
*/
public function freeResult( $query_id=null );
@@ -407,7 +414,7 @@ interface interfaceDb
* Set debug mode flag
*
* @param boolean [Optional] Set debug mode on/off
* @return void
* @return @e void
*/
public function setDebugMode( $enable=false );
@@ -421,7 +428,7 @@ interface interfaceDb
/**
* Flushes the currently queued query
*
* @return void
* @return @e void
*/
public function flushQuery();
@@ -430,7 +437,7 @@ interface interfaceDb
*
* @param string File name
* @param string Classname of file
* @return void
* @return @e void
*/
public function loadCacheFile( $filepath, $classname );
@@ -438,7 +445,7 @@ interface interfaceDb
* Checks to see if a query file has been loaded
*
* @param string Classname of file
* @return void
* @return @e void
*/
public function hasLoadedCacheFile( $classname );
@@ -446,7 +453,7 @@ interface interfaceDb
* Set fields that shouldn't be escaped
*
* @param array SQL table fields
* @return void
* @return @e void
*/
public function preventAddSlashes( $fields=array() );
@@ -474,15 +481,6 @@ interface interfaceDb
*/
public function addSlashes( $t );
/**
* Un-escape strings escaped for DB
*
* @param string Text to un-escape
* @return string Un-escaped text
* @deprecated No longer used anywhere, drivers just return the string
*/
public function removeSlashes( $t );
/**
* Build concat string
*
@@ -595,8 +593,16 @@ interface interfaceDb
* @return string [Optional] SQL-formatted "is null" or "is not null" string
*/
public function buildIsNull( $is_null=true );
/**
* Build coalesce statement
*
* @param array Values to check
* @return string SQL-formatted coalesce statement
*/
public function buildCoalesce( $values=array() );
/**
* Build from_unixtime string
*
* @param string Column name
@@ -604,6 +610,14 @@ interface interfaceDb
* @return string SQL-formatted from_unixtime string
*/
public function buildFromUnixtime( $column, $format='' );
/**
* Build unix_timestamp string
*
* @param string Column name
* @return string SQL-formatted unix_timestamp string
*/
public function buildUnixTimestamp( $column );
/**
* Build date_format string
@@ -651,6 +665,13 @@ interface interfaceDb
* @return mixed Output to screen, or return void
*/
public function buildWherePermission( array $ids, $field='', $incStarCheck=true );
/**
* Set Timezone
*
* @param float UTC Offset (e.g. 6 or -4.5)
*/
public function setTimeZone( $offset );
/**
* Logs SQL error message to log file
@@ -658,7 +679,7 @@ interface interfaceDb
* @param string SQL Query
* @param string Data to log (i.e. error message)
* @param integer Timestamp for log
* @return void
* @return @e void
*/
public function writeDebugLog( $query, $data, $endtime );
@@ -818,10 +839,10 @@ abstract class dbMain
/**
* Optimization to stop querying the same loaded cache over and over
*
* @access private
* @access protected
* @var array
*/
private $_triedToLoadCacheFiles = array();
protected $_triedToLoadCacheFiles = array();
/**
* Connection variables set when installed
@@ -834,18 +855,17 @@ abstract class dbMain
/**
* Over-ride guessed data types in insert/update ops
*
* @access public
* @var array Force data types for columns
*/
public $force_data_type = array();
protected $_dataTypes = array();
/**
* Select which fields aren't escaped during insert/update ops
* Select which fields aren't escaped during insert/update ops. Set using preventAddSlashes()
*
* @access public
* @access protected
* @var array Do not escape these fields
*/
public $no_escape_fields = array();
protected $no_escape_fields = array();
/**
* Classname of query cache file
@@ -917,7 +937,7 @@ abstract class dbMain
* db_driver constructor
*
* @access public
* @return void
* @return @e void
*/
public function __construct()
{
@@ -932,7 +952,7 @@ abstract class dbMain
* Global connect class
*
* @access public
* @return void
* @return @e void
*/
public function connect()
{
@@ -963,12 +983,44 @@ abstract class dbMain
{
}
/**
* Force a column data type
*
* @param mixed $column Column name, or an array of column names
* @param string $type Data type to use
* @return @e void
*/
public function setDataType( $column, $type='string' )
{
if( is_array($column) )
{
foreach( $column as $_column )
{
$this->_dataTypes[ $_column ] = $type;
}
}
else
{
$this->_dataTypes[ $column ] = $type;
}
}
/**
* Reset forced data types
*
* @return @e void
*/
public function resetDataTypes()
{
$this->_dataTypes = array();
}
/**
* Takes array of set commands and generates a SQL formatted query
*
* @access public
* @param array Set commands (select, from, where, order, limit, etc)
* @return void
* @return @e void
*/
public function build( $data )
{
@@ -982,34 +1034,34 @@ abstract class dbMain
}
}
if ( isset($data['select']) && $data['select'] )
if ( !empty($data['select']) )
{
$this->_buildSelect( $data['select'], $data['from'], isset($data['where']) ? $data['where'] : '', isset( $data['add_join'] ) ? $data['add_join'] : array(), isset( $data['calcRows'] ) ? $data['calcRows'] : '' );
}
if ( isset($data['update']) && $data['update'] )
if ( !empty($data['update']) )
{
$this->update( $data['update'], $data['set'], isset($data['where']) ? $data['where'] : '', false, true );
return;
}
if ( isset($data['delete']) && $data['delete'] )
if ( !empty($data['delete']) )
{
$this->delete( $data['delete'], $data['where'], $data['order'], $data['limit'], false );
return;
}
if ( isset($data['group']) && $data['group'] )
if ( !empty($data['group']) )
{
$this->_buildGroupBy( $data['group'] );
}
if ( isset($data['having']) && $data['having'] )
if ( !empty($data['having']) )
{
$this->_buildHaving( $data['having'] );
}
if ( isset($data['order']) && $data['order'] )
if ( !empty($data['order']) )
{
$this->_buildOrderBy( $data['order'] );
}
@@ -1060,7 +1112,7 @@ abstract class dbMain
}
}
}
if( $instance )
{
$this->cur_query .= $instance->$method( $args );
@@ -1119,7 +1171,7 @@ abstract class dbMain
$res = $this->execute();
if ( isset($data['select']) AND $data['select'] )
if ( !empty($data['select']) )
{
return $this->fetch( $res );
}
@@ -1218,7 +1270,7 @@ abstract class dbMain
*
* @access public
* @param boolean [Optional] Set debug mode on/off
* @return void
* @return @e void
*/
public function setDebugMode( $enable=false )
{
@@ -1249,7 +1301,7 @@ abstract class dbMain
* Flushes the currently queued query
*
* @access public
* @return void
* @return @e void
*/
public function flushQuery()
{
@@ -1260,7 +1312,7 @@ abstract class dbMain
* Set SQL Prefix
*
* @access protected
* @return void
* @return @e void
*/
protected function _setPrefix()
{
@@ -1278,7 +1330,7 @@ abstract class dbMain
* @access public
* @param string File name
* @param string Classname of file
* @return void
* @return @e void
*/
public function hasLoadedCacheFile( $classname )
{
@@ -1307,7 +1359,7 @@ abstract class dbMain
if ( ! isset( $this->_triedToLoadCacheFiles[ $classname ] ) )
{
/* Try and load it */
if ( ! file_exists( $filepath ) AND $ignoreMissing === FALSE )
if ( ! is_file( $filepath ) AND $ignoreMissing === FALSE )
{
$this->error = "Невозможно найти {$filepath} - завершение!";
@@ -1315,7 +1367,7 @@ abstract class dbMain
}
else if ( $this->hasLoadedCacheFile( $classname ) !== TRUE )
{
require_once( $filepath );
require_once( $filepath );/*noLibHook*/
if( class_exists( $classname ) )
{
@@ -1345,23 +1397,23 @@ abstract class dbMain
if ( $incStarCheck === true )
{
$where = ' OR ( ' . $field . '=\'*\' )';
$where .= ' OR ( ' . $field . '=\'*\' )';
}
return $where;
return "( " . $where . " )";
}
/**
* Load Query cache file
*
* @access protected
* @return void
* @return @e void
*/
protected function _loadCacheFile()
{
if ( $this->obj['query_cache_file'] )
{
require_once( $this->obj['query_cache_file'] );
require_once( $this->obj['query_cache_file'] );/*noLibHook*/
$sql_queries_name = $this->sql_queries_name ? $this->sql_queries_name : 'sql_queries';
@@ -1374,7 +1426,7 @@ abstract class dbMain
*
* @access public
* @param array SQL table fields
* @return void
* @return @e void
*/
public function preventAddSlashes( $fields=array() )
{
@@ -1402,7 +1454,7 @@ abstract class dbMain
$add_slashes = 0;
}
if ( isset($this->no_escape_fields[ $k ]) AND $this->no_escape_fields[ $k ] )
if ( !empty($this->no_escape_fields[ $k ]) )
{
$add_slashes = 0;
}
@@ -1418,21 +1470,21 @@ abstract class dbMain
// Forcing data type?
//-----------------------------------------
if ( isset($this->force_data_type[ $k ]) AND $this->force_data_type[ $k ] )
if ( !empty($this->_dataTypes[ $k ]) )
{
if ( $this->force_data_type[ $k ] == 'string' )
if ( $this->_dataTypes[ $k ] == 'string' )
{
$field_values .= $this->fieldEncapsulate . $v . $this->fieldEncapsulate . ',';
}
else if ( $this->force_data_type[ $k ] == 'int' )
else if ( $this->_dataTypes[ $k ] == 'int' )
{
$field_values .= intval($v).",";
}
else if ( $this->force_data_type[ $k ] == 'float' )
else if ( $this->_dataTypes[ $k ] == 'float' )
{
$field_values .= floatval($v).",";
}
if ( $this->force_data_type[ $k ] == 'null' )
if ( $this->_dataTypes[ $k ] == 'null' )
{
$field_values .= "NULL,";
}
@@ -1487,7 +1539,7 @@ abstract class dbMain
$add_slashes = 0;
}
if ( isset($this->no_escape_fields[ $k ]) && $this->no_escape_fields[ $k ] )
if ( !empty($this->no_escape_fields[ $k ]) )
{
$add_slashes = 0;
}
@@ -1501,13 +1553,13 @@ abstract class dbMain
// Forcing data type?
//-----------------------------------------
if ( isset($this->force_data_type[ $k ]) && $this->force_data_type[ $k ] )
if ( !empty($this->_dataTypes[ $k ]) )
{
if ( $this->force_data_type[ $k ] == 'string' )
if ( $this->_dataTypes[ $k ] == 'string' )
{
$return_string .= $k . '=' . $this->fieldEncapsulate . $v . $this->fieldEncapsulate . ',';
}
else if ( $this->force_data_type[ $k ] == 'int' )
else if ( $this->_dataTypes[ $k ] == 'int' )
{
if ( strstr( $v, 'plus:' ) )
{
@@ -1522,11 +1574,11 @@ abstract class dbMain
$return_string .= $k . "=" . intval($v) . ",";
}
}
else if ( $this->force_data_type[ $k ] == 'float' )
else if ( $this->_dataTypes[ $k ] == 'float' )
{
$return_string .= $k . "=" . floatval($v) . ",";
}
else if ( $this->force_data_type[ $k ] == 'null' )
else if ( $this->_dataTypes[ $k ] == 'null' )
{
$return_string .= $k . "=NULL,";
}
@@ -1550,7 +1602,7 @@ abstract class dbMain
}
$return_string = rtrim( $return_string, "," );
return $return_string;
}
@@ -1581,7 +1633,7 @@ abstract class dbMain
*
* @access protected
* @param string Order by clause
* @return void
* @return @e void
*/
abstract protected function _buildOrderBy( $order );
@@ -1590,7 +1642,7 @@ abstract class dbMain
*
* @access protected
* @param string Having clause
* @return void
* @return @e void
*/
abstract protected function _buildHaving( $having_clause );
@@ -1599,7 +1651,7 @@ abstract class dbMain
*
* @access protected
* @param string Group by clause
* @return void
* @return @e void
*/
abstract protected function _buildGroupBy( $group );
@@ -1609,7 +1661,7 @@ abstract class dbMain
* @access protected
* @param integer Start offset
* @param integer [Optional] Number of records
* @return void
* @return @e void
*/
abstract protected function _buildLimit( $offset, $limit=0 );
@@ -1621,7 +1673,7 @@ abstract class dbMain
* @param string Table name
* @param string [Optional] Where clause
* @param array [Optional] Joined table data
* @return void
* @return @e void
*/
abstract protected function _buildSelect( $get, $table, $where, $add_join=array(), $calcRows=FALSE );
@@ -1629,7 +1681,7 @@ abstract class dbMain
* Generates calc rows in the query if supported / runs count(*) if not
*
* @access protected
* @return void Sets $this->_calcRows
* @return @e void Sets $this->_calcRows
*/
abstract protected function _buildCalcRows();
@@ -1767,7 +1819,7 @@ abstract class dbMain
if( $this->use_template )
{
require_once( DOC_IPS_ROOT_PATH . 'cache/skin_cache/'. $errTemplate . '.php' );
require_once( DOC_IPS_ROOT_PATH . 'cache/skin_cache/'. $errTemplate . '.php' );/*noLibHook*/
$template = new ipsDriverErrorTemplate();
print $template->showError( $errTemplate == 'ipsServerError' ? true : false, $the_error );
}
@@ -1798,7 +1850,7 @@ abstract class dbMain
if( $this->use_template )
{
require_once( DOC_IPS_ROOT_PATH . 'cache/skin_cache/'. $errTemplate . '.php' );
require_once( DOC_IPS_ROOT_PATH . 'cache/skin_cache/'. $errTemplate . '.php' );/*noLibHook*/
$template = new ipsDriverErrorTemplate();
print $template->showError( true, $the_error );
}
@@ -1829,7 +1881,7 @@ abstract class dbMain
* @param string SQL Query
* @param string Data to log (i.e. error message)
* @param integer Timestamp for log
* @return void
* @return @e void
*/
public function writeDebugLog( $query, $data, $endtime, $fileToWrite='', $backTrace=FALSE )
{
@@ -1907,7 +1959,7 @@ abstract class dbMain
* db_driver destructor: Runs shutdown queries and closes connection
*
* @access public
* @return void
* @return @e void
*/
public function __destruct()
{