mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Merge PR #6763 branch 'creocoder-incorrect-checking-sqlite-version'
* creocoder-incorrect-checking-sqlite-version: improved db test, avoid error by accessing db directlry fixed failure on sqlite version check Correct SQLite version checking
This commit is contained in:
@ -66,7 +66,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
|||||||
{
|
{
|
||||||
// SQLite supports batch insert natively since 3.7.11
|
// SQLite supports batch insert natively since 3.7.11
|
||||||
// http://www.sqlite.org/releaselog/3_7_11.html
|
// http://www.sqlite.org/releaselog/3_7_11.html
|
||||||
if (version_compare(\SQLite3::version()['versionString'], '3.7.11', '>=')) {
|
$this->db->open(); // ensure pdo is not null
|
||||||
|
if (version_compare($this->db->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '3.7.11', '>=')) {
|
||||||
return parent::batchInsert($table, $columns, $rows);
|
return parent::batchInsert($table, $columns, $rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ abstract class DatabaseTestCase extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @var Connection
|
* @var Connection
|
||||||
*/
|
*/
|
||||||
protected $db;
|
private $_db;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
@ -28,8 +28,8 @@ abstract class DatabaseTestCase extends TestCase
|
|||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
if ($this->db) {
|
if ($this->_db) {
|
||||||
$this->db->close();
|
$this->_db->close();
|
||||||
}
|
}
|
||||||
$this->destroyApplication();
|
$this->destroyApplication();
|
||||||
}
|
}
|
||||||
@ -41,8 +41,8 @@ abstract class DatabaseTestCase extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function getConnection($reset = true, $open = true)
|
public function getConnection($reset = true, $open = true)
|
||||||
{
|
{
|
||||||
if (!$reset && $this->db) {
|
if (!$reset && $this->_db) {
|
||||||
return $this->db;
|
return $this->_db;
|
||||||
}
|
}
|
||||||
$config = $this->database;
|
$config = $this->database;
|
||||||
if (isset($config['fixture'])) {
|
if (isset($config['fixture'])) {
|
||||||
@ -52,11 +52,11 @@ abstract class DatabaseTestCase extends TestCase
|
|||||||
$fixture = null;
|
$fixture = null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->db = $this->prepareDatabase($config, $fixture, $open);
|
$this->_db = $this->prepareDatabase($config, $fixture, $open);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->markTestSkipped("Something wrong when preparing database: " . $e->getMessage());
|
$this->markTestSkipped("Something wrong when preparing database: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
return $this->db;
|
return $this->_db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepareDatabase($config, $fixture, $open = true)
|
public function prepareDatabase($config, $fixture, $open = true)
|
||||||
|
|||||||
@ -84,7 +84,8 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
|
|||||||
|
|
||||||
public function testBatchInsert()
|
public function testBatchInsert()
|
||||||
{
|
{
|
||||||
if (version_compare(\SQLite3::version()['versionString'], '3.7.11', '>=')) {
|
$db = $this->getConnection();
|
||||||
|
if (version_compare($db->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '3.7.11', '>=')) {
|
||||||
$this->markTestSkipped('This test is only relevant for SQLite < 3.7.11');
|
$this->markTestSkipped('This test is only relevant for SQLite < 3.7.11');
|
||||||
}
|
}
|
||||||
$sql = $this->getQueryBuilder()->batchInsert('{{customer}} t', ['t.id', 't.name'], [[1, 'a'], [2, 'b']]);
|
$sql = $this->getQueryBuilder()->batchInsert('{{customer}} t', ['t.id', 't.name'], [[1, 'a'], [2, 'b']]);
|
||||||
|
|||||||
Reference in New Issue
Block a user