mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-25 08:41:53 +02:00
Merge pull request #2492 from nickvergessen/ticket/12570
[ticket/12570] Fix updating a config with the same value * nickvergessen/ticket/12570: [ticket/12570] Keep MySQLi procedural [ticket/12570] Remove test for affected rows after SELECT [ticket/12570] Add a test for set_array() and updating with the same value [ticket/12570] Fix MySQL affectedrows [ticket/12570] Fix MySQLi affectedrows by specifying MYSQLI_CLIENT_FOUND_ROWS [ticket/12570] Add a unit test to show broken sql_affectedrows() [ticket/12570] Add test for updating a config with the same value
This commit is contained in:
commit
d646354b0e
@ -207,7 +207,26 @@ class mysql extends \phpbb\db\driver\mysql_base
|
|||||||
*/
|
*/
|
||||||
function sql_affectedrows()
|
function sql_affectedrows()
|
||||||
{
|
{
|
||||||
return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false;
|
if ($this->db_connect_id)
|
||||||
|
{
|
||||||
|
// We always want the number of matched rows
|
||||||
|
// instead of changed rows, when running an update.
|
||||||
|
// So when mysql_info() returns the number of matched rows
|
||||||
|
// we return that one instead of mysql_affected_rows()
|
||||||
|
$mysql_info = @mysql_info($this->db_connect_id);
|
||||||
|
if ($mysql_info !== false)
|
||||||
|
{
|
||||||
|
$match = array();
|
||||||
|
preg_match('#^Rows matched: (\d)+ Changed: (\d)+ Warnings: (\d)+$#', $mysql_info, $match);
|
||||||
|
if (isset($match[1]))
|
||||||
|
{
|
||||||
|
return $match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return @mysql_affected_rows($this->db_connect_id);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +57,8 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket);
|
$this->db_connect_id = mysqli_init();
|
||||||
|
@mysqli_real_connect($this->db_connect_id, $this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket, MYSQLI_CLIENT_FOUND_ROWS);
|
||||||
|
|
||||||
if ($this->db_connect_id && $this->dbname != '')
|
if ($this->db_connect_id && $this->dbname != '')
|
||||||
{
|
{
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
class phpbb_config_db_text_test extends phpbb_database_test_case
|
class phpbb_config_db_text_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
private $db;
|
/** @var \phpbb\config\db_text */
|
||||||
private $config_text;
|
protected $config_text;
|
||||||
|
|
||||||
public function getDataSet()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
@ -48,6 +48,12 @@ class phpbb_config_db_text_test extends phpbb_database_test_case
|
|||||||
$this->assertSame('24', $this->config_text->get('foo'));
|
$this->assertSame('24', $this->config_text->get('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_set_same_value_get()
|
||||||
|
{
|
||||||
|
$this->config_text->set('foo', '23');
|
||||||
|
$this->assertSame('23', $this->config_text->get('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
public function test_set_get_long_string()
|
public function test_set_get_long_string()
|
||||||
{
|
{
|
||||||
$expected = str_repeat('ABC', 10000);
|
$expected = str_repeat('ABC', 10000);
|
||||||
@ -89,6 +95,8 @@ class phpbb_config_db_text_test extends phpbb_database_test_case
|
|||||||
'baby' => 'phpBB',
|
'baby' => 'phpBB',
|
||||||
// Entry update
|
// Entry update
|
||||||
'bar' => '64',
|
'bar' => '64',
|
||||||
|
// Entry update - same value
|
||||||
|
'foo' => '23',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->config_text->set_array($set_array_param);
|
$this->config_text->set_array($set_array_param);
|
||||||
|
64
tests/dbal/sql_affected_rows_test.php
Normal file
64
tests/dbal/sql_affected_rows_test.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2014 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_dbal_sql_affected_rows_test extends phpbb_database_test_case
|
||||||
|
{
|
||||||
|
/** @var \phpbb\db\driver\driver_interface */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->db = $this->new_dbal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDataSet()
|
||||||
|
{
|
||||||
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_update()
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
||||||
|
SET config_value = 'bertie'";
|
||||||
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$this->assertEquals(2, $this->db->sql_affectedrows());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_update_all_matched_unequal_updated()
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
||||||
|
SET config_value = 'foo'";
|
||||||
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$this->assertEquals(2, $this->db->sql_affectedrows());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_update_same_value_matched_unequal_updated()
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
||||||
|
SET config_value = 'foo'
|
||||||
|
WHERE config_value = 'foo'";
|
||||||
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $this->db->sql_affectedrows());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_insert()
|
||||||
|
{
|
||||||
|
$sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
|
||||||
|
'config_name' => 'bertie',
|
||||||
|
'config_value' => 'rules',
|
||||||
|
));
|
||||||
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $this->db->sql_affectedrows());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user