From afda00d43422cc59841fb30e385521ceb226e2df Mon Sep 17 00:00:00 2001 From: Matvey Vasenin Date: Mon, 17 Aug 2015 14:44:53 +0300 Subject: [PATCH] add sqllite dummy --- framework/db/ColumnSchemaBuilder.php | 2 +- framework/db/sqlite/ColumnSchemaBuilder.php | 40 ++++++++++++++ framework/db/sqlite/QueryBuilder.php | 52 +++++++++++++++++++ framework/db/sqlite/Schema.php | 8 +++ .../db/sqlite/SqliteQueryBuilderTest.php | 24 +++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 framework/db/sqlite/ColumnSchemaBuilder.php diff --git a/framework/db/ColumnSchemaBuilder.php b/framework/db/ColumnSchemaBuilder.php index 101d8c3ab8..b15c22206e 100644 --- a/framework/db/ColumnSchemaBuilder.php +++ b/framework/db/ColumnSchemaBuilder.php @@ -110,7 +110,7 @@ class ColumnSchemaBuilder extends Object /** * Specify the comment for the column. - * @param $comment the comment + * @param string $comment the comment * @return $this */ public function comment($comment) diff --git a/framework/db/sqlite/ColumnSchemaBuilder.php b/framework/db/sqlite/ColumnSchemaBuilder.php new file mode 100644 index 0000000000..58dae651b3 --- /dev/null +++ b/framework/db/sqlite/ColumnSchemaBuilder.php @@ -0,0 +1,40 @@ + + * @since 2.0.6 + */ +class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder +{ + /** + * Specify the comment for the column. + * @param string $comment the comment + * @return $this + * @throws NotSupportedException this is not supported by SQLite + */ + public function comment($comment) + { + throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); + } + + + /** + * @inheritdoc + */ + protected function buildCommentString() + { + return ''; + } +} diff --git a/framework/db/sqlite/QueryBuilder.php b/framework/db/sqlite/QueryBuilder.php index ac8edca012..bd6df56d8b 100644 --- a/framework/db/sqlite/QueryBuilder.php +++ b/framework/db/sqlite/QueryBuilder.php @@ -275,6 +275,58 @@ class QueryBuilder extends \yii\db\QueryBuilder throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); } + /** + * Builds a SQL command for adding comment to column + * + * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. + * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. + * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. + * @return $this the command object itself + * @throws NotSupportedException this is not supported by SQLite + */ + public function addCommentOnColumn($table, $column, $comment) + { + throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); + } + + /** + * Builds a SQL command for adding comment to table + * + * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. + * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. + * @return $this the command object itself + * @throws NotSupportedException this is not supported by SQLite + */ + public function addCommentOnTable($table, $comment) + { + throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); + } + + /** + * Builds a SQL command for adding comment to column + * + * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. + * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. + * @return $this the command object itself + * @throws NotSupportedException this is not supported by SQLite + */ + public function dropCommentFromColumn($table, $column) + { + throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); + } + + /** + * Builds a SQL command for adding comment to table + * + * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. + * @return $this the command object itself + * @throws NotSupportedException this is not supported by SQLite + */ + public function dropCommentFromTable($table) + { + throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); + } + /** * @inheritdoc */ diff --git a/framework/db/sqlite/Schema.php b/framework/db/sqlite/Schema.php index 2e28896281..4153dc5832 100644 --- a/framework/db/sqlite/Schema.php +++ b/framework/db/sqlite/Schema.php @@ -91,6 +91,14 @@ class Schema extends \yii\db\Schema return new QueryBuilder($this->db); } + /** + * @inheritdoc + */ + public function createColumnSchemaBuilder($type, $length = null) + { + return new ColumnSchemaBuilder($type, $length); + } + /** * Returns all table names in the database. * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. diff --git a/tests/framework/db/sqlite/SqliteQueryBuilderTest.php b/tests/framework/db/sqlite/SqliteQueryBuilderTest.php index 7dccc58ec0..ef14e3b93e 100644 --- a/tests/framework/db/sqlite/SqliteQueryBuilderTest.php +++ b/tests/framework/db/sqlite/SqliteQueryBuilderTest.php @@ -87,6 +87,30 @@ class SqliteQueryBuilderTest extends QueryBuilderTest parent::testAddDropPrimaryKey(); } + public function testCommentOnColumnSchemaBuilder() + { + $this->setExpectedException('yii\base\NotSupportedException'); + $this->string()->comment('comment'); + } + + public function testCommentColumn() + { + $qb = $this->getQueryBuilder(); + + $this->setExpectedException('yii\base\NotSupportedException'); + $qb->addCommentOnColumn('comment', 'text', 'This is my column.'); + $qb->dropCommentFromColumn('comment', 'text'); + } + + public function testCommentTable() + { + $qb = $this->getQueryBuilder(); + + $this->setExpectedException('yii\base\NotSupportedException'); + $qb->addCommentOnTable('comment', 'This is my table.'); + $qb->dropCommentFromTable('comment'); + } + public function testBatchInsert() { $db = $this->getConnection();