From fcb50ccf2ef19856ff297b53a1fb2ba34c0309be Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 1 Nov 2023 16:16:30 +0800 Subject: [PATCH] Revert "[10.x] Add support for getting native columns' attributes (#48357)" This reverts commit 85a514632e410ae8f90c2b32c79a2788ba9d1076. --- .../Query/Processors/MySqlProcessor.php | 26 -------------- .../Query/Processors/PostgresProcessor.php | 28 --------------- .../Database/Query/Processors/Processor.php | 13 ------- .../Query/Processors/SQLiteProcessor.php | 30 ---------------- .../Query/Processors/SqlServerProcessor.php | 33 ----------------- src/Illuminate/Database/Schema/Builder.php | 36 ++++--------------- .../Database/Schema/Grammars/MySqlGrammar.php | 22 ------------ .../Schema/Grammars/PostgresGrammar.php | 26 -------------- .../Schema/Grammars/SQLiteGrammar.php | 17 --------- .../Schema/Grammars/SqlServerGrammar.php | 27 -------------- .../Database/Schema/MySqlBuilder.php | 8 ++--- .../Database/Schema/PostgresBuilder.php | 8 ++--- src/Illuminate/Support/Facades/Schema.php | 3 +- .../DatabaseMySQLSchemaBuilderTest.php | 6 ++-- tests/Database/DatabaseMySqlProcessorTest.php | 18 +++------- .../Database/DatabasePostgresBuilderTest.php | 30 ++++++++-------- .../DatabasePostgresProcessorTest.php | 20 +++-------- .../DatabasePostgresSchemaBuilderTest.php | 6 ++-- .../DatabasePostgresSchemaGrammarTest.php | 6 ++-- .../Database/DatabaseSQLiteProcessorTest.php | 18 +++------- tests/Database/DatabaseSchemaBuilderTest.php | 1 - 21 files changed, 54 insertions(+), 328 deletions(-) diff --git a/src/Illuminate/Database/Query/Processors/MySqlProcessor.php b/src/Illuminate/Database/Query/Processors/MySqlProcessor.php index 3aa8c9cb9852..ce9183858d2b 100644 --- a/src/Illuminate/Database/Query/Processors/MySqlProcessor.php +++ b/src/Illuminate/Database/Query/Processors/MySqlProcessor.php @@ -7,8 +7,6 @@ class MySqlProcessor extends Processor /** * Process the results of a column listing query. * - * @deprecated Will be removed in a future Laravel version. - * * @param array $results * @return array */ @@ -18,28 +16,4 @@ public function processColumnListing($results) return ((object) $result)->column_name; }, $results); } - - /** - * Process the results of a columns query. - * - * @param array $results - * @return array - */ - public function processColumns($results) - { - return array_map(function ($result) { - $result = (object) $result; - - return [ - 'name' => $result->name, - 'type_name' => $result->type_name, - 'type' => $result->type, - 'collation' => $result->collation, - 'nullable' => $result->nullable === 'YES', - 'default' => $result->default, - 'auto_increment' => $result->extra === 'auto_increment', - 'comment' => $result->comment, - ]; - }, $results); - } } diff --git a/src/Illuminate/Database/Query/Processors/PostgresProcessor.php b/src/Illuminate/Database/Query/Processors/PostgresProcessor.php index 0ec35de6853b..5956a8fb3148 100755 --- a/src/Illuminate/Database/Query/Processors/PostgresProcessor.php +++ b/src/Illuminate/Database/Query/Processors/PostgresProcessor.php @@ -33,8 +33,6 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu /** * Process the results of a column listing query. * - * @deprecated Will be removed in a future Laravel version. - * * @param array $results * @return array */ @@ -44,30 +42,4 @@ public function processColumnListing($results) return ((object) $result)->column_name; }, $results); } - - /** - * Process the results of a columns query. - * - * @param array $results - * @return array - */ - public function processColumns($results) - { - return array_map(function ($result) { - $result = (object) $result; - - $autoincrement = $result->default !== null && str_starts_with($result->default, 'nextval('); - - return [ - 'name' => $result->name, - 'type_name' => $result->type_name, - 'type' => $result->type, - 'collation' => $result->collation, - 'nullable' => (bool) $result->nullable, - 'default' => $autoincrement ? null : $result->default, - 'auto_increment' => $autoincrement, - 'comment' => $result->comment, - ]; - }, $results); - } } diff --git a/src/Illuminate/Database/Query/Processors/Processor.php b/src/Illuminate/Database/Query/Processors/Processor.php index 8fb8b0e7ab48..0069b436d553 100755 --- a/src/Illuminate/Database/Query/Processors/Processor.php +++ b/src/Illuminate/Database/Query/Processors/Processor.php @@ -39,8 +39,6 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu /** * Process the results of a column listing query. * - * @deprecated Will be removed in a future Laravel version. - * * @param array $results * @return array */ @@ -48,15 +46,4 @@ public function processColumnListing($results) { return $results; } - - /** - * Process the results of a columns query. - * - * @param array $results - * @return array - */ - public function processColumns($results) - { - return $results; - } } diff --git a/src/Illuminate/Database/Query/Processors/SQLiteProcessor.php b/src/Illuminate/Database/Query/Processors/SQLiteProcessor.php index cb851efb4cc6..65da1dff7c26 100644 --- a/src/Illuminate/Database/Query/Processors/SQLiteProcessor.php +++ b/src/Illuminate/Database/Query/Processors/SQLiteProcessor.php @@ -7,8 +7,6 @@ class SQLiteProcessor extends Processor /** * Process the results of a column listing query. * - * @deprecated Will be removed in a future Laravel version. - * * @param array $results * @return array */ @@ -18,32 +16,4 @@ public function processColumnListing($results) return ((object) $result)->name; }, $results); } - - /** - * Process the results of a columns query. - * - * @param array $results - * @return array - */ - public function processColumns($results) - { - $hasPrimaryKey = array_sum(array_column($results, 'primary')) === 1; - - return array_map(function ($result) use ($hasPrimaryKey) { - $result = (object) $result; - - $type = strtolower($result->type); - - return [ - 'name' => $result->name, - 'type_name' => strtok($type, '('), - 'type' => $type, - 'collation' => null, - 'nullable' => (bool) $result->nullable, - 'default' => $result->default, - 'auto_increment' => $hasPrimaryKey && $result->primary && $type === 'integer', - 'comment' => null, - ]; - }, $results); - } } diff --git a/src/Illuminate/Database/Query/Processors/SqlServerProcessor.php b/src/Illuminate/Database/Query/Processors/SqlServerProcessor.php index 0384335ac6db..49476f095594 100755 --- a/src/Illuminate/Database/Query/Processors/SqlServerProcessor.php +++ b/src/Illuminate/Database/Query/Processors/SqlServerProcessor.php @@ -58,8 +58,6 @@ protected function processInsertGetIdForOdbc(Connection $connection) /** * Process the results of a column listing query. * - * @deprecated Will be removed in a future Laravel version. - * * @param array $results * @return array */ @@ -69,35 +67,4 @@ public function processColumnListing($results) return ((object) $result)->name; }, $results); } - - /** - * Process the results of a columns query. - * - * @param array $results - * @return array - */ - public function processColumns($results) - { - return array_map(function ($result) { - $result = (object) $result; - - $type = match ($typeName = $result->type_name) { - 'binary', 'varbinary', 'char', 'varchar', 'nchar', 'nvarchar' => $result->length == -1 ? $typeName.'(max)' : $typeName."($result->length)", - 'decimal', 'numeric' => $typeName."($result->precision,$result->places)", - 'float', 'datetime2', 'datetimeoffset', 'time' => $typeName."($result->precision)", - default => $typeName, - }; - - return [ - 'name' => $result->name, - 'type_name' => $result->type_name, - 'type' => $type, - 'collation' => $result->collation, - 'nullable' => (bool) $result->nullable, - 'default' => $result->default, - 'auto_increment' => (bool) $result->autoincrement, - 'comment' => $result->comment, - ]; - }, $results); - } } diff --git a/src/Illuminate/Database/Schema/Builder.php b/src/Illuminate/Database/Schema/Builder.php index 6597dcf57cb7..a38b526c9a33 100755 --- a/src/Illuminate/Database/Schema/Builder.php +++ b/src/Illuminate/Database/Schema/Builder.php @@ -233,26 +233,13 @@ public function whenTableDoesntHaveColumn(string $table, string $column, Closure * * @param string $table * @param string $column - * @param bool $fullDefinition * @return string */ - public function getColumnType($table, $column, $fullDefinition = false) + public function getColumnType($table, $column) { $table = $this->connection->getTablePrefix().$table; - if (! $this->connection->usingNativeSchemaOperations()) { - return $this->connection->getDoctrineColumn($table, $column)->getType()->getName(); - } - - $columns = $this->getColumns($table); - - foreach ($columns as $value) { - if (strtolower($value['name']) === $column) { - return $fullDefinition ? $value['type'] : $value['type_name']; - } - } - - throw new InvalidArgumentException("There is no column with name '$column' on table '$table'."); + return $this->connection->getDoctrineColumn($table, $column)->getType()->getName(); } /** @@ -263,22 +250,11 @@ public function getColumnType($table, $column, $fullDefinition = false) */ public function getColumnListing($table) { - return array_column($this->getColumns($table), 'name'); - } - - /** - * Get the columns for a given table. - * - * @param string $table - * @return array - */ - public function getColumns($table) - { - $table = $this->connection->getTablePrefix().$table; + $results = $this->connection->selectFromWriteConnection($this->grammar->compileColumnListing( + $this->connection->getTablePrefix().$table + )); - return $this->connection->getPostProcessor()->processColumns( - $this->connection->selectFromWriteConnection($this->grammar->compileColumns($table)) - ); + return $this->connection->getPostProcessor()->processColumnListing($results); } /** diff --git a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php index 7f940b95f975..124aeb7a2fed 100755 --- a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php @@ -78,8 +78,6 @@ public function compileTableExists() /** * Compile the query to determine the list of columns. * - * @deprecated Will be removed in a future Laravel version. - * * @return string */ public function compileColumnListing() @@ -87,26 +85,6 @@ public function compileColumnListing() return 'select column_name as `column_name` from information_schema.columns where table_schema = ? and table_name = ?'; } - /** - * Compile the query to determine the columns. - * - * @param string $database - * @param string $table - * @return string - */ - public function compileColumns($database, $table) - { - return sprintf( - 'select column_name as `name`, data_type as `type_name`, column_type as `type`, ' - .'collation_name as `collation`, is_nullable as `nullable`, ' - .'column_default as `default`, column_comment AS `comment`, extra as `extra` ' - .'from information_schema.columns where table_schema = %s and table_name = %s ' - .'order by ordinal_position asc', - $this->quoteString($database), - $this->quoteString($table) - ); - } - /** * Compile a create table command. * diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index 845e818de542..2efb2541525f 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -81,8 +81,6 @@ public function compileTableExists() /** * Compile the query to determine the list of columns. * - * @deprecated Will be removed in a future Laravel version. - * * @return string */ public function compileColumnListing() @@ -90,30 +88,6 @@ public function compileColumnListing() return 'select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?'; } - /** - * Compile the query to determine the columns. - * - * @param string $database - * @param string $schema - * @param string $table - * @return string - */ - public function compileColumns($database, $schema, $table) - { - return sprintf( - 'select quote_ident(a.attname) as name, t.typname as type_name, format_type(a.atttypid, a.atttypmod) as type, ' - .'(select tc.collcollate from pg_catalog.pg_collation tc where tc.oid = a.attcollation) as collation, ' - .'not a.attnotnull as nullable, ' - .'(select pg_get_expr(adbin, adrelid) from pg_attrdef where c.oid = pg_attrdef.adrelid and pg_attrdef.adnum = a.attnum) as default, ' - .'(select pg_description.description from pg_description where pg_description.objoid = c.oid and a.attnum = pg_description.objsubid) as comment ' - .'from pg_attribute a, pg_class c, pg_type t, pg_namespace n ' - .'where c.relname = %s and n.nspname = %s and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid and n.oid = c.relnamespace ' - .'order by a.attnum', - $this->quoteString($table), - $this->quoteString($schema) - ); - } - /** * Compile a create table command. * diff --git a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php index 60171610d020..9c3b1c9fb61e 100755 --- a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php @@ -39,8 +39,6 @@ public function compileTableExists() /** * Compile the query to determine the list of columns. * - * @deprecated Will be removed in a future Laravel version. - * * @param string $table * @return string */ @@ -49,21 +47,6 @@ public function compileColumnListing($table) return 'pragma table_info('.$this->wrap(str_replace('.', '__', $table)).')'; } - /** - * Compile the query to determine the columns. - * - * @param string $table - * @return string - */ - public function compileColumns($table) - { - return sprintf( - "select name, type, not 'notnull' as 'nullable', dflt_value as 'default', pk as 'primary' " - .'from pragma_table_info(%s) order by cid asc', - $this->wrap(str_replace('.', '__', $table)) - ); - } - /** * Compile a create table command. * diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index d70aedadc0e9..a2b56afacf61 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -79,8 +79,6 @@ public function compileTableExists() /** * Compile the query to determine the list of columns. * - * @deprecated Will be removed in a future Laravel version. - * * @param string $table * @return string */ @@ -89,31 +87,6 @@ public function compileColumnListing($table) return "select name from sys.columns where object_id = object_id('$table')"; } - /** - * Compile the query to determine the columns. - * - * @param string $table - * @return string - */ - public function compileColumns($table) - { - return sprintf( - 'select col.name, type.name as type_name, ' - .'col.max_length as length, col.precision as precision, col.scale as places, ' - .'col.is_nullable as nullable, def.definition as [default], ' - .'col.is_identity as autoincrement, col.collation_name as collation, ' - .'cast(prop.value as nvarchar(max)) as comment ' - .'from sys.columns as col ' - .'join sys.types as type on col.user_type_id = type.user_type_id ' - .'join sys.objects as obj on col.object_id = obj.object_id ' - .'join sys.schemas as scm on obj.schema_id = scm.schema_id ' - .'left join sys.default_constraints def on col.default_object_id = def.object_id and col.object_id = def.parent_object_id ' - ."left join sys.extended_properties as prop on obj.object_id = prop.major_id and col.column_id = prop.minor_id and prop.name = 'MS_Description' " - ."where obj.type = 'U' and obj.name = %s and scm.name = SCHEMA_NAME()", - $this->quoteString($table), - ); - } - /** * Compile a create table command. * diff --git a/src/Illuminate/Database/Schema/MySqlBuilder.php b/src/Illuminate/Database/Schema/MySqlBuilder.php index 3fcb73764fbe..bbb0763a721d 100755 --- a/src/Illuminate/Database/Schema/MySqlBuilder.php +++ b/src/Illuminate/Database/Schema/MySqlBuilder.php @@ -46,20 +46,20 @@ public function hasTable($table) } /** - * Get the columns for a given table. + * Get the column listing for a given table. * * @param string $table * @return array */ - public function getColumns($table) + public function getColumnListing($table) { $table = $this->connection->getTablePrefix().$table; $results = $this->connection->selectFromWriteConnection( - $this->grammar->compileColumns($this->connection->getDatabaseName(), $table) + $this->grammar->compileColumnListing(), [$this->connection->getDatabaseName(), $table] ); - return $this->connection->getPostProcessor()->processColumns($results); + return $this->connection->getPostProcessor()->processColumnListing($results); } /** diff --git a/src/Illuminate/Database/Schema/PostgresBuilder.php b/src/Illuminate/Database/Schema/PostgresBuilder.php index 34a75ceb5fd5..adfbd688ee28 100755 --- a/src/Illuminate/Database/Schema/PostgresBuilder.php +++ b/src/Illuminate/Database/Schema/PostgresBuilder.php @@ -176,22 +176,22 @@ public function getAllTypes() } /** - * Get the columns for a given table. + * Get the column listing for a given table. * * @param string $table * @return array */ - public function getColumns($table) + public function getColumnListing($table) { [$database, $schema, $table] = $this->parseSchemaAndTable($table); $table = $this->connection->getTablePrefix().$table; $results = $this->connection->selectFromWriteConnection( - $this->grammar->compileColumns($database, $schema, $table) + $this->grammar->compileColumnListing(), [$database, $schema, $table] ); - return $this->connection->getPostProcessor()->processColumns($results); + return $this->connection->getPostProcessor()->processColumnListing($results); } /** diff --git a/src/Illuminate/Support/Facades/Schema.php b/src/Illuminate/Support/Facades/Schema.php index 4a87bcc25cec..d4dc8f55dc2f 100755 --- a/src/Illuminate/Support/Facades/Schema.php +++ b/src/Illuminate/Support/Facades/Schema.php @@ -15,9 +15,8 @@ * @method static bool hasColumns(string $table, array $columns) * @method static void whenTableHasColumn(string $table, string $column, \Closure $callback) * @method static void whenTableDoesntHaveColumn(string $table, string $column, \Closure $callback) - * @method static string getColumnType(string $table, string $column, bool $fullDefinition = false) + * @method static string getColumnType(string $table, string $column) * @method static array getColumnListing(string $table) - * @method static array getColumns(string $table) * @method static void table(string $table, \Closure $callback) * @method static void create(string $table, \Closure $callback) * @method static void drop(string $table) diff --git a/tests/Database/DatabaseMySQLSchemaBuilderTest.php b/tests/Database/DatabaseMySQLSchemaBuilderTest.php index 2a89d31957c3..ee9fe903e1b4 100755 --- a/tests/Database/DatabaseMySQLSchemaBuilderTest.php +++ b/tests/Database/DatabaseMySQLSchemaBuilderTest.php @@ -38,11 +38,11 @@ public function testGetColumnListing() $connection->shouldReceive('getDatabaseName')->andReturn('db'); $connection->shouldReceive('getSchemaGrammar')->andReturn($grammar); $connection->shouldReceive('getPostProcessor')->andReturn($processor); - $grammar->shouldReceive('compileColumns')->with('db', 'prefix_table')->once()->andReturn('sql'); - $processor->shouldReceive('processColumns')->once()->andReturn([['name' => 'column']]); + $grammar->shouldReceive('compileColumnListing')->once()->andReturn('sql'); + $processor->shouldReceive('processColumnListing')->once()->andReturn(['column']); $builder = new MySqlBuilder($connection); $connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_'); - $connection->shouldReceive('selectFromWriteConnection')->once()->with('sql')->andReturn([['name' => 'column']]); + $connection->shouldReceive('selectFromWriteConnection')->once()->with('sql', ['db', 'prefix_table'])->andReturn(['column']); $this->assertEquals(['column'], $builder->getColumnListing('table')); } diff --git a/tests/Database/DatabaseMySqlProcessorTest.php b/tests/Database/DatabaseMySqlProcessorTest.php index 5ac56b1ce990..6f7b4bbdb53d 100644 --- a/tests/Database/DatabaseMySqlProcessorTest.php +++ b/tests/Database/DatabaseMySqlProcessorTest.php @@ -7,26 +7,18 @@ class DatabaseMySqlProcessorTest extends TestCase { - public function testProcessColumns() + public function testProcessColumnListing() { $processor = new MySqlProcessor; - $listing = [ - ['name' => 'id', 'type_name' => 'bigint', 'type' => 'bigint', 'collation' => 'collate', 'nullable' => 'YES', 'default' => '', 'extra' => 'auto_increment', 'comment' => 'bar'], - ['name' => 'name', 'type_name' => 'varchar', 'type' => 'varchar(100)', 'collation' => 'collate', 'nullable' => 'NO', 'default' => 'foo', 'extra' => '', 'comment' => ''], - ['name' => 'email', 'type_name' => 'varchar', 'type' => 'varchar(100)', 'collation' => 'collate', 'nullable' => 'YES', 'default' => 'NULL', 'extra' => 'on update CURRENT_TIMESTAMP', 'comment' => 'NULL'], - ]; - $expected = [ - ['name' => 'id', 'type_name' => 'bigint', 'type' => 'bigint', 'collation' => 'collate', 'nullable' => true, 'default' => '', 'auto_increment' => true, 'comment' => 'bar'], - ['name' => 'name', 'type_name' => 'varchar', 'type' => 'varchar(100)', 'collation' => 'collate', 'nullable' => false, 'default' => 'foo', 'auto_increment' => false, 'comment' => ''], - ['name' => 'email', 'type_name' => 'varchar', 'type' => 'varchar(100)', 'collation' => 'collate', 'nullable' => true, 'default' => 'NULL', 'auto_increment' => false, 'comment' => 'NULL'], - ]; - $this->assertEquals($expected, $processor->processColumns($listing)); + $listing = [['column_name' => 'id'], ['column_name' => 'name'], ['column_name' => 'email']]; + $expected = ['id', 'name', 'email']; + $this->assertEquals($expected, $processor->processColumnListing($listing)); // convert listing to objects to simulate PDO::FETCH_CLASS foreach ($listing as &$row) { $row = (object) $row; } - $this->assertEquals($expected, $processor->processColumns($listing)); + $this->assertEquals($expected, $processor->processColumnListing($listing)); } } diff --git a/tests/Database/DatabasePostgresBuilderTest.php b/tests/Database/DatabasePostgresBuilderTest.php index 11c2b9ca41ac..b5e5af603462 100644 --- a/tests/Database/DatabasePostgresBuilderTest.php +++ b/tests/Database/DatabasePostgresBuilderTest.php @@ -146,13 +146,13 @@ public function testGetColumnListingWhenSchemaUnqualifiedAndSearchPathMissing() $connection->shouldReceive('getConfig')->with('schema')->andReturn(null); $grammar = m::mock(PostgresGrammar::class); $connection->shouldReceive('getSchemaGrammar')->once()->andReturn($grammar); - $grammar->shouldReceive('compileColumns')->with('laravel', 'public', 'foo')->andReturn('sql'); - $connection->shouldReceive('selectFromWriteConnection')->with('sql')->andReturn(['countable_result']); + $grammar->shouldReceive('compileColumnListing')->andReturn('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?'); + $connection->shouldReceive('selectFromWriteConnection')->with('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?', ['laravel', 'public', 'foo'])->andReturn(['countable_result']); $connection->shouldReceive('getTablePrefix'); $connection->shouldReceive('getConfig')->with('database')->andReturn('laravel'); $processor = m::mock(PostgresProcessor::class); $connection->shouldReceive('getPostProcessor')->andReturn($processor); - $processor->shouldReceive('processColumns')->andReturn([['name' => 'some_column']]); + $processor->shouldReceive('processColumnListing')->andReturn(['some_column']); $builder = $this->getBuilder($connection); $builder->getColumnListing('foo'); @@ -164,13 +164,13 @@ public function testGetColumnListingWhenSchemaUnqualifiedAndSearchPathFilled() $connection->shouldReceive('getConfig')->with('search_path')->andReturn('myapp,public'); $grammar = m::mock(PostgresGrammar::class); $connection->shouldReceive('getSchemaGrammar')->once()->andReturn($grammar); - $grammar->shouldReceive('compileColumns')->with('laravel', 'myapp', 'foo')->andReturn('sql'); - $connection->shouldReceive('selectFromWriteConnection')->with('sql')->andReturn(['countable_result']); + $grammar->shouldReceive('compileColumnListing')->andReturn('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?'); + $connection->shouldReceive('selectFromWriteConnection')->with('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?', ['laravel', 'myapp', 'foo'])->andReturn(['countable_result']); $connection->shouldReceive('getTablePrefix'); $connection->shouldReceive('getConfig')->with('database')->andReturn('laravel'); $processor = m::mock(PostgresProcessor::class); $connection->shouldReceive('getPostProcessor')->andReturn($processor); - $processor->shouldReceive('processColumns')->andReturn([['name' => 'some_column']]); + $processor->shouldReceive('processColumnListing')->andReturn(['some_column']); $builder = $this->getBuilder($connection); $builder->getColumnListing('foo'); @@ -183,13 +183,13 @@ public function testGetColumnListingWhenSchemaUnqualifiedAndSearchPathIsUserVari $connection->shouldReceive('getConfig')->with('search_path')->andReturn('$user'); $grammar = m::mock(PostgresGrammar::class); $connection->shouldReceive('getSchemaGrammar')->once()->andReturn($grammar); - $grammar->shouldReceive('compileColumns')->with('laravel', 'foouser', 'foo')->andReturn('sql'); - $connection->shouldReceive('selectFromWriteConnection')->with('sql')->andReturn(['countable_result']); + $grammar->shouldReceive('compileColumnListing')->andReturn('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?'); + $connection->shouldReceive('selectFromWriteConnection')->with('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?', ['laravel', 'foouser', 'foo'])->andReturn(['countable_result']); $connection->shouldReceive('getTablePrefix'); $connection->shouldReceive('getConfig')->with('database')->andReturn('laravel'); $processor = m::mock(PostgresProcessor::class); $connection->shouldReceive('getPostProcessor')->andReturn($processor); - $processor->shouldReceive('processColumns')->andReturn([['name' => 'some_column']]); + $processor->shouldReceive('processColumnListing')->andReturn(['some_column']); $builder = $this->getBuilder($connection); $builder->getColumnListing('foo'); @@ -201,13 +201,13 @@ public function testGetColumnListingWhenSchemaQualifiedAndSearchPathMismatches() $connection->shouldReceive('getConfig')->with('search_path')->andReturn('public'); $grammar = m::mock(PostgresGrammar::class); $connection->shouldReceive('getSchemaGrammar')->once()->andReturn($grammar); - $grammar->shouldReceive('compileColumns')->with('laravel', 'myapp', 'foo')->andReturn('sql'); - $connection->shouldReceive('selectFromWriteConnection')->with('sql')->andReturn(['countable_result']); + $grammar->shouldReceive('compileColumnListing')->andReturn('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?'); + $connection->shouldReceive('selectFromWriteConnection')->with('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?', ['laravel', 'myapp', 'foo'])->andReturn(['countable_result']); $connection->shouldReceive('getTablePrefix'); $connection->shouldReceive('getConfig')->with('database')->andReturn('laravel'); $processor = m::mock(PostgresProcessor::class); $connection->shouldReceive('getPostProcessor')->andReturn($processor); - $processor->shouldReceive('processColumns')->andReturn([['name' => 'some_column']]); + $processor->shouldReceive('processColumnListing')->andReturn(['some_column']); $builder = $this->getBuilder($connection); $builder->getColumnListing('myapp.foo'); @@ -219,13 +219,13 @@ public function testGetColumnWhenDatabaseAndSchemaQualifiedAndSearchPathMismatch $connection->shouldReceive('getConfig')->with('search_path')->andReturn('public'); $grammar = m::mock(PostgresGrammar::class); $connection->shouldReceive('getSchemaGrammar')->once()->andReturn($grammar); - $grammar->shouldReceive('compileColumns')->with('mydatabase', 'myapp', 'foo')->andReturn('sql'); - $connection->shouldReceive('selectFromWriteConnection')->with('sql')->andReturn(['countable_result']); + $grammar->shouldReceive('compileColumnListing')->andReturn('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?'); + $connection->shouldReceive('selectFromWriteConnection')->with('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?', ['mydatabase', 'myapp', 'foo'])->andReturn(['countable_result']); $connection->shouldReceive('getTablePrefix'); $connection->shouldReceive('getConfig')->with('database')->andReturn('laravel'); $processor = m::mock(PostgresProcessor::class); $connection->shouldReceive('getPostProcessor')->andReturn($processor); - $processor->shouldReceive('processColumns')->andReturn([['name' => 'some_column']]); + $processor->shouldReceive('processColumnListing')->andReturn(['some_column']); $builder = $this->getBuilder($connection); $builder->getColumnListing('mydatabase.myapp.foo'); diff --git a/tests/Database/DatabasePostgresProcessorTest.php b/tests/Database/DatabasePostgresProcessorTest.php index 8213fc68aba7..6ce284f86de8 100644 --- a/tests/Database/DatabasePostgresProcessorTest.php +++ b/tests/Database/DatabasePostgresProcessorTest.php @@ -7,30 +7,20 @@ class DatabasePostgresProcessorTest extends TestCase { - public function testProcessColumns() + public function testProcessColumnListing() { $processor = new PostgresProcessor; - $listing = [ - ['name' => 'id', 'type_name' => 'int4', 'type' => 'integer', 'collation' => '', 'nullable' => true, 'default' => "nextval('employee_id_seq'::regclass)", 'comment' => ''], - ['name' => 'name', 'type_name' => 'varchar', 'type' => 'character varying(100)', 'collation' => 'collate', 'nullable' => false, 'default' => '', 'comment' => 'foo'], - ['name' => 'balance', 'type_name' => 'numeric', 'type' => 'numeric(8,2)', 'collation' => '', 'nullable' => true, 'default' => '4', 'comment' => 'NULL'], - ['name' => 'birth_date', 'type_name' => 'timestamp', 'type' => 'timestamp(6) without time zone', 'collation' => '', 'nullable' => false, 'default' => '', 'comment' => ''], - ]; - $expected = [ - ['name' => 'id', 'type_name' => 'int4', 'type' => 'integer', 'collation' => '', 'nullable' => true, 'default' => null, 'auto_increment' => true, 'comment' => ''], - ['name' => 'name', 'type_name' => 'varchar', 'type' => 'character varying(100)', 'collation' => 'collate', 'nullable' => false, 'default' => '', 'auto_increment' => false, 'comment' => 'foo'], - ['name' => 'balance', 'type_name' => 'numeric', 'type' => 'numeric(8,2)', 'collation' => '', 'nullable' => true, 'default' => '4', 'auto_increment' => false, 'comment' => 'NULL'], - ['name' => 'birth_date', 'type_name' => 'timestamp', 'type' => 'timestamp(6) without time zone', 'collation' => '', 'nullable' => false, 'default' => '', 'auto_increment' => false, 'comment' => ''], - ]; + $listing = [['column_name' => 'id'], ['column_name' => 'name'], ['column_name' => 'email']]; + $expected = ['id', 'name', 'email']; - $this->assertEquals($expected, $processor->processColumns($listing)); + $this->assertEquals($expected, $processor->processColumnListing($listing)); // convert listing to objects to simulate PDO::FETCH_CLASS foreach ($listing as &$row) { $row = (object) $row; } - $this->assertEquals($expected, $processor->processColumns($listing)); + $this->assertEquals($expected, $processor->processColumnListing($listing)); } } diff --git a/tests/Database/DatabasePostgresSchemaBuilderTest.php b/tests/Database/DatabasePostgresSchemaBuilderTest.php index 448b41138a84..7d917c36fe6b 100755 --- a/tests/Database/DatabasePostgresSchemaBuilderTest.php +++ b/tests/Database/DatabasePostgresSchemaBuilderTest.php @@ -44,11 +44,11 @@ public function testGetColumnListing() $connection->shouldReceive('getConfig')->with('database')->andReturn('db'); $connection->shouldReceive('getConfig')->with('schema')->andReturn('schema'); $connection->shouldReceive('getConfig')->with('search_path')->andReturn('public'); - $grammar->shouldReceive('compileColumns')->with('db', 'public', 'prefix_table')->once()->andReturn('sql'); - $processor->shouldReceive('processColumns')->once()->andReturn([['name' => 'column']]); + $grammar->shouldReceive('compileColumnListing')->once()->andReturn('sql'); + $processor->shouldReceive('processColumnListing')->once()->andReturn(['column']); $builder = new PostgresBuilder($connection); $connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_'); - $connection->shouldReceive('selectFromWriteConnection')->once()->with('sql')->andReturn([['name' => 'column']]); + $connection->shouldReceive('selectFromWriteConnection')->once()->with('sql', ['db', 'public', 'prefix_table'])->andReturn(['column']); $this->assertEquals(['column'], $builder->getColumnListing('table')); } diff --git a/tests/Database/DatabasePostgresSchemaGrammarTest.php b/tests/Database/DatabasePostgresSchemaGrammarTest.php index db139e523280..8ff15e2e14a7 100755 --- a/tests/Database/DatabasePostgresSchemaGrammarTest.php +++ b/tests/Database/DatabasePostgresSchemaGrammarTest.php @@ -1186,11 +1186,11 @@ public function testCompileTableExists() $this->assertSame('select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = \'BASE TABLE\'', $statement); } - public function testCompileColumns() + public function testCompileColumnListing() { - $statement = $this->getGrammar()->compileColumns('db', 'public', 'table'); + $statement = $this->getGrammar()->compileColumnListing(); - $this->assertStringContainsString("where c.relname = 'table' and n.nspname = 'public'", $statement); + $this->assertSame('select column_name from information_schema.columns where table_catalog = ? and table_schema = ? and table_name = ?', $statement); } protected function getConnection() diff --git a/tests/Database/DatabaseSQLiteProcessorTest.php b/tests/Database/DatabaseSQLiteProcessorTest.php index 4aeb4438f7d7..8ab4b2b6520e 100644 --- a/tests/Database/DatabaseSQLiteProcessorTest.php +++ b/tests/Database/DatabaseSQLiteProcessorTest.php @@ -7,28 +7,20 @@ class DatabaseSQLiteProcessorTest extends TestCase { - public function testProcessColumns() + public function testProcessColumnListing() { $processor = new SQLiteProcessor; - $listing = [ - ['name' => 'id', 'type' => 'INTEGER', 'nullable' => '0', 'default' => '', 'primary' => '1'], - ['name' => 'name', 'type' => 'varchar', 'nullable' => '1', 'default' => 'foo', 'primary' => '0'], - ['name' => 'is_active', 'type' => 'tinyint(1)', 'nullable' => '0', 'default' => '1', 'primary' => '0'], - ]; - $expected = [ - ['name' => 'id', 'type_name' => 'integer', 'type' => 'integer', 'collation' => null, 'nullable' => false, 'default' => '', 'auto_increment' => true, 'comment' => null], - ['name' => 'name', 'type_name' => 'varchar', 'type' => 'varchar', 'collation' => null, 'nullable' => true, 'default' => 'foo', 'auto_increment' => false, 'comment' => null], - ['name' => 'is_active', 'type_name' => 'tinyint', 'type' => 'tinyint(1)', 'collation' => null, 'nullable' => false, 'default' => '1', 'auto_increment' => false, 'comment' => null], - ]; + $listing = [['name' => 'id'], ['name' => 'name'], ['name' => 'email']]; + $expected = ['id', 'name', 'email']; - $this->assertEquals($expected, $processor->processColumns($listing)); + $this->assertEquals($expected, $processor->processColumnListing($listing)); // convert listing to objects to simulate PDO::FETCH_CLASS foreach ($listing as &$row) { $row = (object) $row; } - $this->assertEquals($expected, $processor->processColumns($listing)); + $this->assertEquals($expected, $processor->processColumnListing($listing)); } } diff --git a/tests/Database/DatabaseSchemaBuilderTest.php b/tests/Database/DatabaseSchemaBuilderTest.php index 2fdd98e1225b..b22bfd7dc70e 100755 --- a/tests/Database/DatabaseSchemaBuilderTest.php +++ b/tests/Database/DatabaseSchemaBuilderTest.php @@ -77,7 +77,6 @@ public function testGetColumnTypeAddsPrefix() $builder = new Builder($connection); $connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_'); $connection->shouldReceive('getDoctrineColumn')->once()->with('prefix_users', 'id')->andReturn($column); - $connection->shouldReceive('usingNativeSchemaOperations')->once()->andReturn(false); $column->shouldReceive('getType')->once()->andReturn($type); $type->shouldReceive('getName')->once()->andReturn('integer');