From fff48ef76fbba114a8ee96f6362e76d1cc24cad2 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Tue, 6 Jan 2015 01:27:01 +0300 Subject: [PATCH 1/3] Correct SQLite version checking --- framework/db/sqlite/QueryBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/db/sqlite/QueryBuilder.php b/framework/db/sqlite/QueryBuilder.php index 4014d9b940..ce572355db 100644 --- a/framework/db/sqlite/QueryBuilder.php +++ b/framework/db/sqlite/QueryBuilder.php @@ -66,7 +66,7 @@ class QueryBuilder extends \yii\db\QueryBuilder { // SQLite supports batch insert natively since 3.7.11 // http://www.sqlite.org/releaselog/3_7_11.html - if (version_compare(\SQLite3::version()['versionString'], '3.7.11', '>=')) { + if (version_compare($this->db->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '3.7.11', '>=')) { return parent::batchInsert($table, $columns, $rows); } From f177f1701aea4a7b57db3334e29584e5a1159050 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sat, 10 Jan 2015 22:06:43 +0100 Subject: [PATCH 2/3] fixed failure on sqlite version check ensure PDO instance has been created at this point --- framework/db/sqlite/QueryBuilder.php | 1 + tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/db/sqlite/QueryBuilder.php b/framework/db/sqlite/QueryBuilder.php index ce572355db..7931334806 100644 --- a/framework/db/sqlite/QueryBuilder.php +++ b/framework/db/sqlite/QueryBuilder.php @@ -66,6 +66,7 @@ class QueryBuilder extends \yii\db\QueryBuilder { // SQLite supports batch insert natively since 3.7.11 // http://www.sqlite.org/releaselog/3_7_11.html + $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); } diff --git a/tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php b/tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php index 3d5a861833..34ab18aacd 100644 --- a/tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php +++ b/tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php @@ -84,7 +84,8 @@ class SqliteQueryBuilderTest extends QueryBuilderTest 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'); } $sql = $this->getQueryBuilder()->batchInsert('{{customer}} t', ['t.id', 't.name'], [[1, 'a'], [2, 'b']]); From 0300683bfc30d5bd5e8ab2a052ac76fe320f0ea6 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sat, 10 Jan 2015 22:08:42 +0100 Subject: [PATCH 3/3] improved db test, avoid error by accessing db directlry always use getConnection() --- tests/unit/framework/db/DatabaseTestCase.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/framework/db/DatabaseTestCase.php b/tests/unit/framework/db/DatabaseTestCase.php index 64675fa100..1449f68978 100644 --- a/tests/unit/framework/db/DatabaseTestCase.php +++ b/tests/unit/framework/db/DatabaseTestCase.php @@ -11,7 +11,7 @@ abstract class DatabaseTestCase extends TestCase /** * @var Connection */ - protected $db; + private $_db; protected function setUp() { @@ -28,8 +28,8 @@ abstract class DatabaseTestCase extends TestCase protected function tearDown() { - if ($this->db) { - $this->db->close(); + if ($this->_db) { + $this->_db->close(); } $this->destroyApplication(); } @@ -41,8 +41,8 @@ abstract class DatabaseTestCase extends TestCase */ public function getConnection($reset = true, $open = true) { - if (!$reset && $this->db) { - return $this->db; + if (!$reset && $this->_db) { + return $this->_db; } $config = $this->database; if (isset($config['fixture'])) { @@ -52,11 +52,11 @@ abstract class DatabaseTestCase extends TestCase $fixture = null; } try { - $this->db = $this->prepareDatabase($config, $fixture, $open); + $this->_db = $this->prepareDatabase($config, $fixture, $open); } catch (\Exception $e) { $this->markTestSkipped("Something wrong when preparing database: " . $e->getMessage()); } - return $this->db; + return $this->_db; } public function prepareDatabase($config, $fixture, $open = true)