Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
+38
-9
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Database SELECT Statement
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 28 Aug 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -53,6 +53,11 @@ class _Select implements \Iterator, \Countable
|
||||
*/
|
||||
protected $multiDimensional = FALSE;
|
||||
|
||||
/**
|
||||
* @brief If read/write sepration is enabled, SELECTs normally go to the read server - this flag will set thia query to use the write server
|
||||
*/
|
||||
protected $useWriteServer = FALSE;
|
||||
|
||||
/**
|
||||
* Constuctor
|
||||
*
|
||||
@@ -60,14 +65,16 @@ class _Select implements \Iterator, \Countable
|
||||
* @param array $binds Binds
|
||||
* @param \IPS\Db $db The database object
|
||||
* @param bool $multiDimensional If TRUE, will return the result as a multidimensional array, with each joined table separately
|
||||
* @param bool $useWriteServer If read/write sepration is enabled, SELECTs normally go to the read server - this flag will set thia query to use the write server
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $query, array $binds, \IPS\Db $db, $multiDimensional = FALSE )
|
||||
public function __construct( $query, array $binds, \IPS\Db $db, $multiDimensional = FALSE, $useWriteServer = FALSE )
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->binds = $binds;
|
||||
$this->db = $db;
|
||||
$this->multiDimensional = $multiDimensional;
|
||||
$this->useWriteServer = $useWriteServer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +95,7 @@ class _Select implements \Iterator, \Countable
|
||||
*/
|
||||
public function forceIndex( $index )
|
||||
{
|
||||
$this->query = preg_replace( '/(FROM `(.+?)`( AS `(.+?)`)?)/', "$1 FORCE INDEX(`" . $index . "`)", $this->query );
|
||||
$this->query = preg_replace( '/(FROM `(.+?)`( AS `(.+?)`)?)/', "$1 FORCE INDEX(`" . $index . "`)", $this->query, 1 );
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -127,8 +134,11 @@ class _Select implements \Iterator, \Countable
|
||||
$query .= $type . ' JOIN';
|
||||
$joinConditionIsOptional = FALSE;
|
||||
break;
|
||||
case 'JOIN':
|
||||
$query .= ' JOIN';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ( $table instanceof \IPS\Db\Select )
|
||||
{
|
||||
$tableQuery = $table->query;
|
||||
@@ -141,7 +151,7 @@ class _Select implements \Iterator, \Countable
|
||||
else
|
||||
{
|
||||
$query .= "( {$tableQuery} ) AS `{$matches[1]}`";
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( is_array( $table ) )
|
||||
{
|
||||
@@ -161,6 +171,18 @@ class _Select implements \Iterator, \Countable
|
||||
return '`' . $col . '`';
|
||||
}, $on ) ) . ' ) ';
|
||||
}
|
||||
else if ( is_array( $on ) AND isset($on[1]) and $on[1] instanceof \IPS\Db\Select )
|
||||
{
|
||||
$query .= ' ON ' . $on[0] . '=(' . $on[1]->query . ')';
|
||||
|
||||
if( count( $on[1]->binds ) )
|
||||
{
|
||||
foreach ( $on[1]->binds as $bind )
|
||||
{
|
||||
$this->joinBinds[] = $bind;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$where = $this->db->compileWhereClause( $on );
|
||||
@@ -308,7 +330,7 @@ class _Select implements \Iterator, \Countable
|
||||
* Get first record
|
||||
*
|
||||
* @return array
|
||||
* @throws \OutOfRangeException
|
||||
* @throws \UnderflowException
|
||||
*/
|
||||
public function first()
|
||||
{
|
||||
@@ -331,12 +353,18 @@ class _Select implements \Iterator, \Countable
|
||||
protected function runQuery()
|
||||
{
|
||||
/* Run the query */
|
||||
$this->stmt = $this->db->preparedQuery( $this->query, array_merge( $this->joinBinds, $this->binds ) );
|
||||
$this->stmt = $this->db->preparedQuery( $this->query, array_merge( $this->joinBinds, $this->binds ), !$this->useWriteServer );
|
||||
|
||||
/* Populate $this->row which we read into */
|
||||
$this->row = array();
|
||||
$params = array();
|
||||
$meta = $this->stmt->result_metadata();
|
||||
|
||||
if ( !$meta )
|
||||
{
|
||||
throw new \IPS\Db\Exception( "Something went wrong. Please try again.", $this->stmt->errno, NULL, $this->query, array_merge( $this->joinBinds, $this->binds ) );
|
||||
}
|
||||
|
||||
while ( $field = $meta->fetch_field() )
|
||||
{
|
||||
if ( $this->multiDimensional )
|
||||
@@ -368,7 +396,7 @@ class _Select implements \Iterator, \Countable
|
||||
/* Set counts */
|
||||
if ( mb_strpos( $this->query, 'SQL_CALC_FOUND_ROWS' ) !== FALSE )
|
||||
{
|
||||
$count = $this->db->query( 'SELECT FOUND_ROWS() AS count;' )->fetch_assoc();
|
||||
$count = $this->db->query( 'SELECT FOUND_ROWS() AS count;', TRUE, TRUE )->fetch_assoc();
|
||||
$this->totalCount = $count['count'];
|
||||
}
|
||||
$this->count = $this->stmt->num_rows;
|
||||
@@ -491,6 +519,7 @@ class _Select implements \Iterator, \Countable
|
||||
$fetch = $this->stmt->fetch();
|
||||
if ( $fetch === NULL )
|
||||
{
|
||||
$this->stmt->close();
|
||||
$this->row = NULL;
|
||||
}
|
||||
$this->key++;
|
||||
|
||||
Reference in new issue
Block a user