Version 3.1.4

This commit is contained in:
Neo committed 2025-12-19 00:32:22 -08:00
1 parent 1d4720f3e2
commit ae5c01cc78
2563 files changed
+283048 -240689

No files matched your search

+189 -49
View File
@@ -1,18 +1,21 @@
<?php
/**
* <pre>
* Invision Power Services
* IP.Board v3.0.5
* IP.Board v3.1.4
* MySQL Database Driver :: Further loads mysql or mysqli client appropriately
* Last Updated: $Date: 2009-10-01 14:35:04 -0400 (Thu, 01 Oct 2009) $
* Last Updated: $Date: 2010-10-06 12:04:54 -0400 (Wed, 06 Oct 2010) $
* </pre>
*
* @author $Author: bfarber $
* @author $Author: mmecham $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Services Kernel
* @link http://www.iinvisionpower.com
* @license http://www.invisionpower.com/community/board/license.html
* @package IP.Board
* @subpackage Kernel
* @link http://www.invisionpower.com
* @since Monday 28th February 2005 16:46
* @version $Revision: 335 $
* @version $Revision: 473 $
*/
/**
@@ -29,14 +32,6 @@ if ( ! class_exists( 'dbMain' ) )
require_once( dirname( __FILE__ ) . '/classDb.php' );
}
/**
* Allow < 4.3.0 PHP client access
*/
if ( ! defined('IPS_MAIN_DB_CLASS_LEGACY') )
{
define('IPS_MAIN_DB_CLASS_LEGACY', ( PHP_VERSION < '4.3.0' ) ? TRUE : FALSE );
}
abstract class db_main_mysql extends dbMain
{
/**
@@ -54,6 +49,15 @@ abstract class db_main_mysql extends dbMain
* @var array Table names cached
*/
protected $cached_tables = array();
/**
* Field name encapsulation character
* @see http://community.invisionpower.com/tracker/issue-20621-postgresql-driver-field-names-not-properly-escaped/
*
* @access public
* @var string
*/
public $fieldNameEncapsulate = '`';
/**
* Delete data from a table
@@ -81,16 +85,16 @@ abstract class db_main_mysql extends dbMain
{
$this->_buildOrderBy( $orderBy );
}
if ( $where AND $limit AND is_array( $limit ) )
{
$this->_buildLimit( $limit[0], $limit[1] );
}
$result = $this->_determineShutdownAndRun( $this->cur_query, $shutdown );
$this->cur_query = '';
return $result;
}
@@ -171,19 +175,19 @@ abstract class db_main_mysql extends dbMain
{
//$dbb = $this->compileUpdateString( $set );
$dbb = array();
foreach( $set as $k => $v )
{
$dbb[] = "{$k}=VALUES({$k})";
}
$dbb = implode( ',', $dbb );
$query = "INSERT INTO " . $this->obj['sql_tbl_prefix'] . $table . " ({$dba['FIELD_NAMES']}) VALUES({$dba['FIELD_VALUES']}) ON DUPLICATE KEY UPDATE " . $dbb;
}
IPSDebug::addLogMessage( $query, 'replaceintolog' );
return $this->_determineShutdownAndRun( $query, $shutdown );
}
@@ -257,6 +261,41 @@ abstract class db_main_mysql extends dbMain
return FALSE;
}
}
/**
* Test to see whether an index exists in a table
*
* @access public
* @param string Index name
* @param string Table name
* @return boolean Field exists or not
*/
public function checkForIndex( $index, $table )
{
$current = $this->return_die;
$this->return_die = true;
$this->error = "";
$return = false;
$indexes = array();
$q = $this->query( "SHOW INDEX FROM " . $this->obj['sql_tbl_prefix'] . $table );
if ( $q AND $this->getTotalRows($q) )
{
while( $check = $this->fetch($q) )
{
$indexes[ $check['Key_name'] ] = $check['Key_name'];
}
}
$this->error = "";
$this->return_die = $current;
$this->error_no = 0;
$this->failed = false;
return ( in_array( $index, $indexes ) ) ? true : false;
}
/**
* Test to see whether a field exists in a table
@@ -366,13 +405,13 @@ abstract class db_main_mysql extends dbMain
* @param string [Optional] Default value
* @return resource Query id
*/
public function addField( $table, $field, $type, $default='' )
public function addField( $table, $field, $type, $default=NULL )
{
$default = $default ? "DEFAULT {$default}" : 'NULL';
$default = $default != NULL ? "DEFAULT {$default}" : 'NULL';
return $this->query( "ALTER TABLE " . $this->obj['sql_tbl_prefix'] . $table . " ADD {$field} {$type} {$default}" );
}
/**
* Add index to database column
*
@@ -386,7 +425,7 @@ abstract class db_main_mysql extends dbMain
public function addIndex( $table, $name, $fieldlist, $isPrimary=false )
{
$fieldlist = ( $fieldlist ) ? $fieldlist : $name;
if ( $isPrimary )
{
return $this->query( "ALTER TABLE " . $this->obj['sql_tbl_prefix'] . $table . " ADD PRIMARY KEY ( " . $fieldlist . ' )' );
@@ -465,6 +504,47 @@ abstract class db_main_mysql extends dbMain
return array();
}
}
/**
* Get array of field names in table
*
* @param string Table name
* @return array SQL tables
*/
public function getFieldNames( $table )
{
//-----------------------------------------
// Inline field name caching
//-----------------------------------------
static $_fields = array();
if( count($_fields[ $table ]) )
{
return $_fields[ $table ];
}
$current = $this->return_die;
$this->return_die = true;
$qid = $this->query( "SHOW FIELDS FROM " . $this->obj['sql_tbl_prefix'] . $table );
$this->return_die = $current;
if( $qid )
{
while( $r = $this->fetch($qid) )
{
$_fields[ $table ][] = $r['Field'];
}
return $_fields[ $table ];
}
else
{
return array();
}
}
/**
* Determine if table already has a fulltext index
@@ -600,7 +680,7 @@ abstract class db_main_mysql extends dbMain
return $return_string;
}
/**
* Build CAST string
*
@@ -609,6 +689,12 @@ abstract class db_main_mysql extends dbMain
*/
public function buildCast( $data, $columnType )
{
/* mySQL does not support casting as VARCHAR, but it isn't needed either */
if( $columnType == 'VARCHAR' )
{
return $data;
}
return "CAST( {$data} AS {$columnType} )";
}
@@ -636,7 +722,7 @@ abstract class db_main_mysql extends dbMain
*/
public function buildRegexp( $column, $data )
{
return "{$column} REGEXP '," . implode( ',|,', $data ) . ",|\\\*'";
return "{$column} REGEXP '," . implode( ',|,', $data ) . ',|\\\*\'';
}
/**
@@ -661,7 +747,44 @@ abstract class db_main_mysql extends dbMain
return $return;
}
/**
* Returns a portion of a WHERE query suitable for use.
* Specific to tables with a field that has a comma separated list of IDs.
*
* @param array Array of perm IDs
* @param string DB field to search in
* @param boolean check for '*' in the field to denote 'global'
* @return mixed Output to screen, or return void
*/
public function buildWherePermission( array $ids, $field='', $incStarCheck=true )
{
/* Just use a LIKE chain for items without a specific implementation */
$where = '( ';
$_or = array();
foreach( $ids as $i )
{
$_or[] = "FIND_IN_SET(" . $i . "," . $field . ")";
}
if ( count( $_or ) )
{
$where .= '( ' . implode( " OR ", $_or ) . ' )';
}
else
{
$where .= "1 = 1";
}
if ( $incStarCheck === true )
{
$where .= ' OR ( ' . $field . '=\'*\' )';
}
return $where . ' )';
}
/**
* Build instr string
*
@@ -733,7 +856,7 @@ abstract class db_main_mysql extends dbMain
{
return "LENGTH(" . $column . ")";
}
/**
* Build lower string
*
@@ -816,6 +939,17 @@ abstract class db_main_mysql extends dbMain
{
return "DATE_FORMAT(" . $column . ", '{$format}')";
}
/**
* Build rand() string
*
* @access public
* @return string SQL-formatted random order string
*/
public function buildRandomOrder()
{
return "RAND()";
}
/**
* Build fulltext search string
@@ -882,19 +1016,19 @@ abstract class db_main_mysql extends dbMain
if( is_array( $table ) )
{
$_tables = array();
foreach( $table as $tbl => $alias )
{
$_tables[] = $this->obj['sql_tbl_prefix'] . $tbl . ' ' . $alias;
}
$table = implode( ', ', $_tables );
}
else
{
$table = $this->obj['sql_tbl_prefix'] . $table;
}
$this->cur_query .= "SELECT {$_calcRows}{$get} FROM " . $table;
if ( $where != "" )
@@ -915,9 +1049,10 @@ abstract class db_main_mysql extends dbMain
$joinleft_array = array();
$where_array = array();
$final_from = array();
$select_array[] = $get;
$from_array[] = $table;
$hasLeft = false;
$hasInner = false;
if ( $where )
{
@@ -938,18 +1073,9 @@ abstract class db_main_mysql extends dbMain
$select_array[] = $join['select'];
}
if ( $join['type'] == 'inner' )
{
# Join is inline
$from_array[] = $join['from'];
if ( $join['where'] )
{
$where_array[] = $join['where'];
}
}
else if ( $join['type'] == 'left' OR !$join['type'] )
if ( !isset($join['type']) OR !$join['type'] OR $join['type'] == 'left' )
{
$hasLeft = true;
# Join is left or not specified (assume left)
$tmp = " LEFT JOIN ";
@@ -967,6 +1093,18 @@ abstract class db_main_mysql extends dbMain
unset( $tmp );
}
else if ( $join['type'] == 'inner' )
{
$hasInner = true;
# Join is inline
$from_array[] = $join['from'];
if ( $join['where'] )
{
$where_array[] = $join['where'];
}
}
else
{
# Not using any other type of join
@@ -986,10 +1124,12 @@ abstract class db_main_mysql extends dbMain
}
}
$get = implode( "," , $select_array );
$table = implode( "," , $final_from );
$where = implode( " AND " , $where_array );
$join = implode( "\n" , $joinleft_array );
$get = implode( "," , $select_array );
#http://bugs.mysql.com/bug.php?id=37925
$table = ( $hasLeft === true && $hasInner === true ) ? '(' . implode( ",", $final_from ) . ')' : implode( ",", $final_from );
$where = implode( " AND " , $where_array );
$join = implode( "\n" , $joinleft_array );
$this->cur_query .= "SELECT {$_calcRows}{$get} FROM {$table}";