From de9568e4621fe42b7802583dd18e96b80d191e03 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Thu, 3 Aug 2023 22:09:08 +0000 Subject: [PATCH 01/21] feat: whereFullText query grammar --- src/Oci8/Query/Grammars/OracleGrammar.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Oci8/Query/Grammars/OracleGrammar.php b/src/Oci8/Query/Grammars/OracleGrammar.php index 0888bd03..d8064e60 100644 --- a/src/Oci8/Query/Grammars/OracleGrammar.php +++ b/src/Oci8/Query/Grammars/OracleGrammar.php @@ -597,6 +597,25 @@ protected function whereInRaw(Builder $query, $where) return '0 = 1'; } + /** + * Compile a "where fulltext" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + public function whereFullText(Builder $query, $where) + { + $columns = collect($where['columns']) + ->map(fn($column) => $this->wrap($column)) + ->implode(' || '); + + // Third parameter CONTAINS() function + $labelSearch = $where['options']['label'] ?? 0; + + return "CONTAINS({$columns}, {$this->parameter($where['value'])}, {$labelSearch}) > 0"; + } + private function resolveClause($column, $values, $type) { $chunks = array_chunk($values, 1000); From 5b76c5b7ed99d7c09f7e5a0bac1813a2ebf6a78a Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Thu, 3 Aug 2023 22:09:48 +0000 Subject: [PATCH 02/21] feat: compileFullText index schema grammar --- src/Oci8/Schema/Grammars/OracleGrammar.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Oci8/Schema/Grammars/OracleGrammar.php b/src/Oci8/Schema/Grammars/OracleGrammar.php index 069ed9cd..e18e52bf 100644 --- a/src/Oci8/Schema/Grammars/OracleGrammar.php +++ b/src/Oci8/Schema/Grammars/OracleGrammar.php @@ -306,6 +306,24 @@ public function compileIndex(Blueprint $blueprint, Fluent $command) return "create index {$command->index} on ".$this->wrapTable($blueprint).' ( '.$this->columnize($command->columns).' )'; } + /** + * Compile a fulltext index key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileFullText(Blueprint $blueprint, Fluent $command): string + { + $indexName = $command->index; + $tableName = $this->wrapTable($blueprint); + $columns = $this->columnize($command->columns); + + $query = "create index $indexName on $tableName ($columns) indextype is ctxsys.context parameters ('sync(on commit)')"; + + return $query; + } + /** * Compile a drop table command. * @@ -326,7 +344,7 @@ public function compileDrop(Blueprint $blueprint, Fluent $command) public function compileDropAllTables() { return 'BEGIN - FOR c IN (SELECT table_name FROM user_tables) LOOP + FOR c IN (SELECT table_name FROM user_tables WHERE secondary = \'N\') LOOP EXECUTE IMMEDIATE (\'DROP TABLE "\' || c.table_name || \'" CASCADE CONSTRAINTS\'); END LOOP; From 042cfc8aa5f77d91859c28ed321ed7d10a17d445 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Thu, 3 Aug 2023 22:13:29 +0000 Subject: [PATCH 03/21] feat-test: whereFullText query --- tests/Database/Oci8QueryBuilderTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Database/Oci8QueryBuilderTest.php b/tests/Database/Oci8QueryBuilderTest.php index f71c50da..160c6c53 100644 --- a/tests/Database/Oci8QueryBuilderTest.php +++ b/tests/Database/Oci8QueryBuilderTest.php @@ -718,6 +718,22 @@ public function testArrayWhereColumn() $this->assertEquals([], $builder->getBindings()); } + public function testWhereFullTextWithoutLabel() + { + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->whereFullText('name', 'johnny'); + $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 0) > 0', $builder->toSql()); + $this->assertEquals(["johnny"], $builder->getBindings()); + } + + public function testWhereFullTextWithLabel() + { + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->whereFullText('name', 'johnny test', ['label' => 1]); + $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 1) > 0', $builder->toSql()); + $this->assertEquals(["johnny test"], $builder->getBindings()); + } + public function testUnions() { $builder = $this->getBuilder(); From bbe901eabf4c61ff1cec309334966b44b26635e6 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Thu, 3 Aug 2023 22:14:17 +0000 Subject: [PATCH 04/21] feat-test: create index fullText in schema --- tests/Database/Oci8SchemaGrammarTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/Database/Oci8SchemaGrammarTest.php b/tests/Database/Oci8SchemaGrammarTest.php index c6253be4..9a69ff98 100644 --- a/tests/Database/Oci8SchemaGrammarTest.php +++ b/tests/Database/Oci8SchemaGrammarTest.php @@ -487,6 +487,17 @@ public function testAddingIndex() $this->assertEquals('create index baz on users ( foo, bar )', $statements[0]); } + public function testAddingFullTextIndex() + { + $blueprint = new Blueprint('users'); + $blueprint->fullText(['firstname', 'lastname'], 'name'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertEquals(1, count($statements)); + + $this->assertEquals("create index name on users (firstname, lastname) indextype is ctxsys.context parameters ('sync(on commit)')", $statements[0]); + } + public function testAddingForeignKey() { $blueprint = new Blueprint('users'); @@ -877,7 +888,7 @@ public function testDropAllTables() $statement = $this->getGrammar()->compileDropAllTables(); $expected = 'BEGIN - FOR c IN (SELECT table_name FROM user_tables) LOOP + FOR c IN (SELECT table_name FROM user_tables WHERE secondary = \'N\') LOOP EXECUTE IMMEDIATE (\'DROP TABLE "\' || c.table_name || \'" CASCADE CONSTRAINTS\'); END LOOP; From a36b31640781e1c0d9675ff9728e4d39cd8119fc Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Thu, 3 Aug 2023 22:17:28 +0000 Subject: [PATCH 05/21] fix-test: change name statement whereFullText --- tests/Database/Oci8QueryBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Database/Oci8QueryBuilderTest.php b/tests/Database/Oci8QueryBuilderTest.php index 160c6c53..155460ef 100644 --- a/tests/Database/Oci8QueryBuilderTest.php +++ b/tests/Database/Oci8QueryBuilderTest.php @@ -729,9 +729,9 @@ public function testWhereFullTextWithoutLabel() public function testWhereFullTextWithLabel() { $builder = $this->getBuilder(); - $builder->select('*')->from('users')->whereFullText('name', 'johnny test', ['label' => 1]); + $builder->select('*')->from('users')->whereFullText('name', 'johnny', ['label' => 1]); $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 1) > 0', $builder->toSql()); - $this->assertEquals(["johnny test"], $builder->getBindings()); + $this->assertEquals(["johnny"], $builder->getBindings()); } public function testUnions() From 30523efcbbb285e02eb2c9b90f46126062495e39 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Thu, 3 Aug 2023 23:09:14 +0000 Subject: [PATCH 06/21] fix: styleci integration yajra/laravel-oci8 --- src/Oci8/Query/Grammars/OracleGrammar.php | 2 +- tests/Database/Oci8QueryBuilderTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Oci8/Query/Grammars/OracleGrammar.php b/src/Oci8/Query/Grammars/OracleGrammar.php index d8064e60..d445b20d 100644 --- a/src/Oci8/Query/Grammars/OracleGrammar.php +++ b/src/Oci8/Query/Grammars/OracleGrammar.php @@ -607,7 +607,7 @@ protected function whereInRaw(Builder $query, $where) public function whereFullText(Builder $query, $where) { $columns = collect($where['columns']) - ->map(fn($column) => $this->wrap($column)) + ->map(fn ($column) => $this->wrap($column)) ->implode(' || '); // Third parameter CONTAINS() function diff --git a/tests/Database/Oci8QueryBuilderTest.php b/tests/Database/Oci8QueryBuilderTest.php index 155460ef..2961fab4 100644 --- a/tests/Database/Oci8QueryBuilderTest.php +++ b/tests/Database/Oci8QueryBuilderTest.php @@ -723,7 +723,7 @@ public function testWhereFullTextWithoutLabel() $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText('name', 'johnny'); $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 0) > 0', $builder->toSql()); - $this->assertEquals(["johnny"], $builder->getBindings()); + $this->assertEquals(['johnny'], $builder->getBindings()); } public function testWhereFullTextWithLabel() @@ -731,7 +731,7 @@ public function testWhereFullTextWithLabel() $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText('name', 'johnny', ['label' => 1]); $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 1) > 0', $builder->toSql()); - $this->assertEquals(["johnny"], $builder->getBindings()); + $this->assertEquals(['johnny'], $builder->getBindings()); } public function testUnions() From 505cd8e5031ee2b2fbf99331dadd791f427e5a04 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 18:21:33 +0000 Subject: [PATCH 07/21] fix: grammar whereFullText multiple parameters with logical operator --- src/Oci8/Query/Grammars/OracleGrammar.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Oci8/Query/Grammars/OracleGrammar.php b/src/Oci8/Query/Grammars/OracleGrammar.php index d445b20d..44148b86 100644 --- a/src/Oci8/Query/Grammars/OracleGrammar.php +++ b/src/Oci8/Query/Grammars/OracleGrammar.php @@ -606,14 +606,13 @@ protected function whereInRaw(Builder $query, $where) */ public function whereFullText(Builder $query, $where) { - $columns = collect($where['columns']) - ->map(fn ($column) => $this->wrap($column)) - ->implode(' || '); + $fullTextClause = collect($where['columns']) + ->map(function ($column, $labelSearch) use ($where) { + return "CONTAINS({$this->wrap($column)}, {$this->parameter($where['value'])}, " . ($labelSearch + 1) . ") > 0"; + }) + ->implode(" {$where['boolean']} "); - // Third parameter CONTAINS() function - $labelSearch = $where['options']['label'] ?? 0; - - return "CONTAINS({$columns}, {$this->parameter($where['value'])}, {$labelSearch}) > 0"; + return $fullTextClause; } private function resolveClause($column, $values, $type) From bde355ef7d25ab03e28e6844133b5b53de7b57c7 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 18:22:06 +0000 Subject: [PATCH 08/21] fix-test: whereFullText with single and multiple parameters --- tests/Database/Oci8QueryBuilderTest.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/Database/Oci8QueryBuilderTest.php b/tests/Database/Oci8QueryBuilderTest.php index 2961fab4..2fd2e224 100644 --- a/tests/Database/Oci8QueryBuilderTest.php +++ b/tests/Database/Oci8QueryBuilderTest.php @@ -718,19 +718,29 @@ public function testArrayWhereColumn() $this->assertEquals([], $builder->getBindings()); } - public function testWhereFullTextWithoutLabel() + public function testWhereFullTextWithSingleParameter() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText('name', 'johnny'); - $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 0) > 0', $builder->toSql()); + $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 1) > 0', $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } - public function testWhereFullTextWithLabel() + public function testWhereFullTextWithMultipleParameters() { $builder = $this->getBuilder(); - $builder->select('*')->from('users')->whereFullText('name', 'johnny', ['label' => 1]); - $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 1) > 0', $builder->toSql()); + $builder->select('*')->from('users')->whereFullText(['firstname', 'lastname'], 'johnny'); + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?, 1) > 0 and CONTAINS("LASTNAME", ?, 2) > 0', + $builder->toSql()); + $this->assertEquals(['johnny'], $builder->getBindings()); + } + + public function testWhereFullTextWithLogicalOrOperator() + { + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->whereFullText(['firstname', 'lastname'], 'johnny', [], 'or'); + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?, 1) > 0 or CONTAINS("LASTNAME", ?, 2) > 0', + $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } From 1a30ba6efa4a3716addea7b57d6464b7a48f55bf Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 18:24:31 +0000 Subject: [PATCH 09/21] fix: styleci integration yajra/laravel-oci8 --- src/Oci8/Query/Grammars/OracleGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Oci8/Query/Grammars/OracleGrammar.php b/src/Oci8/Query/Grammars/OracleGrammar.php index 44148b86..cc89dd67 100644 --- a/src/Oci8/Query/Grammars/OracleGrammar.php +++ b/src/Oci8/Query/Grammars/OracleGrammar.php @@ -608,7 +608,7 @@ public function whereFullText(Builder $query, $where) { $fullTextClause = collect($where['columns']) ->map(function ($column, $labelSearch) use ($where) { - return "CONTAINS({$this->wrap($column)}, {$this->parameter($where['value'])}, " . ($labelSearch + 1) . ") > 0"; + return "CONTAINS({$this->wrap($column)}, {$this->parameter($where['value'])}, ".($labelSearch + 1).') > 0'; }) ->implode(" {$where['boolean']} "); From e796371847f20661e32008283b93b9109a275b4c Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 18:48:15 +0000 Subject: [PATCH 10/21] fix: removed of contains() oracle method --- src/Oci8/Query/Grammars/OracleGrammar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Oci8/Query/Grammars/OracleGrammar.php b/src/Oci8/Query/Grammars/OracleGrammar.php index cc89dd67..6746f71b 100644 --- a/src/Oci8/Query/Grammars/OracleGrammar.php +++ b/src/Oci8/Query/Grammars/OracleGrammar.php @@ -607,8 +607,8 @@ protected function whereInRaw(Builder $query, $where) public function whereFullText(Builder $query, $where) { $fullTextClause = collect($where['columns']) - ->map(function ($column, $labelSearch) use ($where) { - return "CONTAINS({$this->wrap($column)}, {$this->parameter($where['value'])}, ".($labelSearch + 1).') > 0'; + ->map(function ($column) use ($where) { + return "CONTAINS({$this->wrap($column)}, {$this->parameter($where['value'])}) > 0"; }) ->implode(" {$where['boolean']} "); From 61071575bb83ee04c3edabf714d2b4277eb7f3d7 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 18:49:25 +0000 Subject: [PATCH 11/21] feat-test: orWhereFullText added in query grammar tests --- tests/Database/Oci8QueryBuilderTest.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/Database/Oci8QueryBuilderTest.php b/tests/Database/Oci8QueryBuilderTest.php index 2fd2e224..c744406d 100644 --- a/tests/Database/Oci8QueryBuilderTest.php +++ b/tests/Database/Oci8QueryBuilderTest.php @@ -722,7 +722,7 @@ public function testWhereFullTextWithSingleParameter() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText('name', 'johnny'); - $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 1) > 0', $builder->toSql()); + $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?) > 0', $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } @@ -730,7 +730,7 @@ public function testWhereFullTextWithMultipleParameters() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText(['firstname', 'lastname'], 'johnny'); - $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?, 1) > 0 and CONTAINS("LASTNAME", ?, 2) > 0', + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?) > 0 and CONTAINS("LASTNAME", ?) > 0', $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } @@ -739,11 +739,28 @@ public function testWhereFullTextWithLogicalOrOperator() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText(['firstname', 'lastname'], 'johnny', [], 'or'); - $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?, 1) > 0 or CONTAINS("LASTNAME", ?, 2) > 0', + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?) > 0 or CONTAINS("LASTNAME", ?) > 0', $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } + public function testOrWhereFullTextWithSingleParameter() + { + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->orWhereFullText('firstname', 'johnny'); + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?) > 0', $builder->toSql()); + $this->assertEquals(['johnny'], $builder->getBindings()); + } + + public function testOrWhereFullTextWithMultipleParameters() + { + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->orWhereFullText('firstname', 'johnny')->orWhereFullText('lastname', 'white'); + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?) > 0 or CONTAINS("LASTNAME", ?) > 0', + $builder->toSql()); + $this->assertEquals(['johnny', 'white'], $builder->getBindings()); + } + public function testUnions() { $builder = $this->getBuilder(); From d14b07037e4b3f25ecbd2166be984b334ebe4faa Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 22:07:22 +0000 Subject: [PATCH 12/21] fix: labelSearch auto increment in contains() oracle feat --- src/Oci8/Query/Grammars/OracleGrammar.php | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Oci8/Query/Grammars/OracleGrammar.php b/src/Oci8/Query/Grammars/OracleGrammar.php index 6746f71b..a9d560d4 100644 --- a/src/Oci8/Query/Grammars/OracleGrammar.php +++ b/src/Oci8/Query/Grammars/OracleGrammar.php @@ -29,6 +29,11 @@ class OracleGrammar extends Grammar */ protected $maxLength; + /** + * @var int + */ + protected $labelSearchFullText = 1; + /** * Compile a delete statement with joins into SQL. * @@ -606,12 +611,27 @@ protected function whereInRaw(Builder $query, $where) */ public function whereFullText(Builder $query, $where) { + // Build the fullText clause $fullTextClause = collect($where['columns']) - ->map(function ($column) use ($where) { - return "CONTAINS({$this->wrap($column)}, {$this->parameter($where['value'])}) > 0"; + ->map(function ($column, $index) use ($where) { + $labelSearchFullText = $index > 0 ? ++$this->labelSearchFullText : $this->labelSearchFullText; + return "CONTAINS({$this->wrap($column)}, {$this->parameter($where['value'])}, {$labelSearchFullText}) > 0"; }) ->implode(" {$where['boolean']} "); + // Count the total number of columns in the clauses + $fullTextClauseCount = array_reduce($query->wheres, function ($count, $queryWhere) { + return $queryWhere['type'] === "Fulltext" ? $count + count($queryWhere['columns']) : $count; + }, 0); + + // Reset the counter if all columns were used in the clause + if ($fullTextClauseCount === $this->labelSearchFullText) { + $this->labelSearchFullText = 0; + } + + // Increment the counter for the next clause + $this->labelSearchFullText++; + return $fullTextClause; } From 84d4562c566c02f47e1f9ac97625b5ebcc1b5011 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 22:08:01 +0000 Subject: [PATCH 13/21] fix-test: third parameter in contains() oracle feat --- tests/Database/Oci8QueryBuilderTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/Database/Oci8QueryBuilderTest.php b/tests/Database/Oci8QueryBuilderTest.php index c744406d..2942660e 100644 --- a/tests/Database/Oci8QueryBuilderTest.php +++ b/tests/Database/Oci8QueryBuilderTest.php @@ -8,6 +8,7 @@ use Illuminate\Database\Query\Expression as Raw; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\Paginator; +use Illuminate\Support\Facades\DB; use InvalidArgumentException; use Mockery as m; use PHPUnit\Framework\TestCase; @@ -722,7 +723,7 @@ public function testWhereFullTextWithSingleParameter() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText('name', 'johnny'); - $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?) > 0', $builder->toSql()); + $this->assertSame('select * from "USERS" where CONTAINS("NAME", ?, 1) > 0', $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } @@ -730,7 +731,7 @@ public function testWhereFullTextWithMultipleParameters() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText(['firstname', 'lastname'], 'johnny'); - $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?) > 0 and CONTAINS("LASTNAME", ?) > 0', + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?, 1) > 0 and CONTAINS("LASTNAME", ?, 2) > 0', $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } @@ -739,7 +740,7 @@ public function testWhereFullTextWithLogicalOrOperator() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereFullText(['firstname', 'lastname'], 'johnny', [], 'or'); - $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?) > 0 or CONTAINS("LASTNAME", ?) > 0', + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?, 1) > 0 or CONTAINS("LASTNAME", ?, 2) > 0', $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } @@ -748,7 +749,7 @@ public function testOrWhereFullTextWithSingleParameter() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->orWhereFullText('firstname', 'johnny'); - $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?) > 0', $builder->toSql()); + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?, 1) > 0', $builder->toSql()); $this->assertEquals(['johnny'], $builder->getBindings()); } @@ -756,7 +757,7 @@ public function testOrWhereFullTextWithMultipleParameters() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->orWhereFullText('firstname', 'johnny')->orWhereFullText('lastname', 'white'); - $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?) > 0 or CONTAINS("LASTNAME", ?) > 0', + $this->assertSame('select * from "USERS" where CONTAINS("FIRSTNAME", ?, 1) > 0 or CONTAINS("LASTNAME", ?, 2) > 0', $builder->toSql()); $this->assertEquals(['johnny', 'white'], $builder->getBindings()); } From e21871232a972ffa8aa2f39df8f2aaffa567fc70 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 22:10:36 +0000 Subject: [PATCH 14/21] fix: style integration yajra/laravel-oci8 --- src/Oci8/Query/Grammars/OracleGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Oci8/Query/Grammars/OracleGrammar.php b/src/Oci8/Query/Grammars/OracleGrammar.php index a9d560d4..f7648d28 100644 --- a/src/Oci8/Query/Grammars/OracleGrammar.php +++ b/src/Oci8/Query/Grammars/OracleGrammar.php @@ -621,7 +621,7 @@ public function whereFullText(Builder $query, $where) // Count the total number of columns in the clauses $fullTextClauseCount = array_reduce($query->wheres, function ($count, $queryWhere) { - return $queryWhere['type'] === "Fulltext" ? $count + count($queryWhere['columns']) : $count; + return $queryWhere['type'] === 'Fulltext' ? $count + count($queryWhere['columns']) : $count; }, 0); // Reset the counter if all columns were used in the clause From abac01e02729a2eb6a524e7f3ab93df444b62513 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 4 Aug 2023 22:12:18 +0000 Subject: [PATCH 15/21] fix-style: integration yajra/laravel-oci8 --- src/Oci8/Query/Grammars/OracleGrammar.php | 1 + tests/Database/Oci8QueryBuilderTest.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Oci8/Query/Grammars/OracleGrammar.php b/src/Oci8/Query/Grammars/OracleGrammar.php index f7648d28..b425b5ce 100644 --- a/src/Oci8/Query/Grammars/OracleGrammar.php +++ b/src/Oci8/Query/Grammars/OracleGrammar.php @@ -615,6 +615,7 @@ public function whereFullText(Builder $query, $where) $fullTextClause = collect($where['columns']) ->map(function ($column, $index) use ($where) { $labelSearchFullText = $index > 0 ? ++$this->labelSearchFullText : $this->labelSearchFullText; + return "CONTAINS({$this->wrap($column)}, {$this->parameter($where['value'])}, {$labelSearchFullText}) > 0"; }) ->implode(" {$where['boolean']} "); diff --git a/tests/Database/Oci8QueryBuilderTest.php b/tests/Database/Oci8QueryBuilderTest.php index 2942660e..d2896402 100644 --- a/tests/Database/Oci8QueryBuilderTest.php +++ b/tests/Database/Oci8QueryBuilderTest.php @@ -8,7 +8,6 @@ use Illuminate\Database\Query\Expression as Raw; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\Paginator; -use Illuminate\Support\Facades\DB; use InvalidArgumentException; use Mockery as m; use PHPUnit\Framework\TestCase; From 7588aff55211910c1791ebdff2b2eaa42613e23b Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 11 Aug 2023 00:47:28 +0000 Subject: [PATCH 16/21] feat: oracle ctx_ddl preferences implemented --- src/Oci8/Schema/OraclePreferences.php | 151 ++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/Oci8/Schema/OraclePreferences.php diff --git a/src/Oci8/Schema/OraclePreferences.php b/src/Oci8/Schema/OraclePreferences.php new file mode 100644 index 00000000..8d704f26 --- /dev/null +++ b/src/Oci8/Schema/OraclePreferences.php @@ -0,0 +1,151 @@ +connection = $connection; + } + + /** + * Create a preferences values to use in index fullText + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @return null + */ + public function createPreferences(Blueprint $blueprint): void + { + $this->setPreferenceFullText($blueprint); + + $sql = $this->generateSqlCreatePreferences(); + + if (!empty($sql)) { + $this->connection->statement( + "BEGIN $sql END;" + ); + } + } + + /** + * Generate script sql to create preferences + * + * @param ?string $objectNameOracle + * @param ?string $attributeNameOracle + * @return string + */ + protected function generateSqlCreatePreferences( + ?string $objectNameOracle = 'MULTI_COLUMN_DATASTORE', + ?string $attributeNameOracle = 'COLUMNS' + ): string { + $ctxDdlCreatePreferences = []; + + foreach ($this->columns as $key => $columns) { + $preferenceName = $this->preferenceName[$key]; + $formattedColumns = $this->formatMultipleCtxColumns($columns); + + $ctxDdlCreatePreferences[] = "ctx_ddl.create_preference('{$preferenceName}', '{$objectNameOracle}'); + ctx_ddl.set_attribute('{$preferenceName}', '{$attributeNameOracle}', '{$formattedColumns}');"; + } + + return implode(' ', $ctxDdlCreatePreferences); + } + + /** + * Set columns and preference name to class attributes + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @return void + */ + public function setPreferenceFullText(Blueprint $blueprint): void + { + $this->columns = []; + $this->preferenceName = []; + + foreach ($blueprint->getCommands() as $value) { + if ($value['name'] === "fulltext" && count($value['columns']) > 1) { + $this->columns[] = $value['columns']; + $this->preferenceName[] = $value['index'] . '_preference'; + } + } + } + + /** + * Format with "implode" function columns to use in preferences + * + * @param array $columns + * @return string + */ + protected function formatMultipleCtxColumns(array $columns): string + { + return implode(', ', $columns); + } + + /** + * Drop preferences by specified table + * + * @param string $table + * @return void + */ + public function dropPreferencesByTable(string $table): void + { + $sqlDropPreferencesByTable = "BEGIN + FOR c IN (select distinct (substr(cui.idx_name, 1, instr(cui.idx_name, '_', -1, 1) - 1) || '_preference') preference + from + ctxsys.ctx_user_indexes cui + where + cui.idx_table = ?) LOOP + EXECUTE IMMEDIATE 'BEGIN ctx_ddl.drop_preference(:preference); END;' + USING c.preference; + END LOOP; + END;"; + + $this->connection->statement($sqlDropPreferencesByTable, [ + strtoupper($table) + ]); + } + + /** + * Drop all user preferences + * + * @return void + */ + public function dropAllPreferences(): void + { + $sqlDropAllPreferences = "BEGIN + FOR c IN (SELECT pre_name FROM ctx_user_preferences) LOOP + EXECUTE IMMEDIATE 'BEGIN ctx_ddl.drop_preference(:pre_name); END;' + USING c.pre_name; + END LOOP; + END;"; + + $this->connection->statement($sqlDropAllPreferences); + } +} From 6fafdc15419a81b3518eeeb0e6e659be00ac2a14 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 11 Aug 2023 00:48:17 +0000 Subject: [PATCH 17/21] feat-test: oracle ctx_ddl preferences tests --- tests/Database/OraclePreferencesTest.php | 134 +++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 tests/Database/OraclePreferencesTest.php diff --git a/tests/Database/OraclePreferencesTest.php b/tests/Database/OraclePreferencesTest.php new file mode 100644 index 00000000..47c78afd --- /dev/null +++ b/tests/Database/OraclePreferencesTest.php @@ -0,0 +1,134 @@ +getConnection(); + $oraclePreferences = new OraclePreferences($connection); + + $connection->shouldReceive('statement') + ->andReturnUsing(function () { + $this->assertTrue(false, 'A single full-text column cannot create preferences.'); + }); + + $blueprint = new Blueprint('users'); + $blueprint->fullText('name', 'name_search_full_text'); + + $oraclePreferences->createPreferences($blueprint); + + $this->assertTrue(true); + } + + public function testCreatePreferencesWithMultipleFullText() + { + $connection = $this->getConnection(); + $oraclePreferences = new OraclePreferences($connection); + + $expected = "BEGIN ctx_ddl.create_preference('name_preference', 'MULTI_COLUMN_DATASTORE'); + ctx_ddl.set_attribute('name_preference', 'COLUMNS', 'firstname, lastname'); END;"; + + $connection->shouldReceive('statement') + ->once() + ->andReturnUsing(function ($sql) use ($expected) { + $this->assertEquals($expected, $sql); + }); + + $blueprint = new Blueprint('users'); + $blueprint->fullText(['firstname', 'lastname'], 'name'); + + $oraclePreferences->createPreferences($blueprint); + } + + public function testCreatePreferencesWithOtherMultipleFullText() + { + $connection = $this->getConnection(); + $oraclePreferences = new OraclePreferences($connection); + + $preferences['name_preference'] = "ctx_ddl.create_preference('name_preference', 'MULTI_COLUMN_DATASTORE'); + ctx_ddl.set_attribute('name_preference', 'COLUMNS', 'firstname, lastname');"; + $preferences['product_preference'] = "ctx_ddl.create_preference('product_preference', 'MULTI_COLUMN_DATASTORE'); + ctx_ddl.set_attribute('product_preference', 'COLUMNS', 'category, price');"; + + $expected = 'BEGIN ' . implode(' ', $preferences) . ' END;'; + + $connection->shouldReceive('statement') + ->once() + ->andReturnUsing(function ($sql) use ($expected) { + $this->assertEquals($expected, $sql); + }); + + $blueprint = new Blueprint('users_product'); + $blueprint->fullText(['firstname', 'lastname'], 'name'); + $blueprint->fullText(['category', 'price'], 'product'); + + $oraclePreferences->createPreferences($blueprint); + } + + public function testDropAllPreferencesByTable() + { + $connection = $this->getConnection(); + $oraclePreferences = new OraclePreferences($connection); + + $expected = "BEGIN + FOR c IN (select distinct (substr(cui.idx_name, 1, instr(cui.idx_name, '_', -1, 1) - 1) || '_preference') preference + from + ctxsys.ctx_user_indexes cui + where + cui.idx_table = ?) LOOP + EXECUTE IMMEDIATE 'BEGIN ctx_ddl.drop_preference(:preference); END;' + USING c.preference; + END LOOP; + END;"; + + $connection->shouldReceive('statement') + ->once() + ->andReturnUsing(function ($sql, $bindings) use ($expected) { + $this->assertSame($expected, $sql); + $this->assertSame(['USERS'], $bindings); + }); + + $oraclePreferences->dropPreferencesByTable('users'); + } + + public function testDropAllPreferences() + { + $connection = $this->getConnection(); + $oraclePreferences = new OraclePreferences($connection); + + $expected = "BEGIN + FOR c IN (SELECT pre_name FROM ctx_user_preferences) LOOP + EXECUTE IMMEDIATE 'BEGIN ctx_ddl.drop_preference(:pre_name); END;' + USING c.pre_name; + END LOOP; + END;"; + + $connection->shouldReceive('statement') + ->once() + ->andReturnUsing(function ($sql) use ($expected) { + $this->assertEquals($expected, $sql); + }); + + $oraclePreferences->dropAllPreferences(); + } + + protected function getConnection() + { + return m::mock('Illuminate\Database\Connection'); + } +} From da9769528749c9bee1e8eef746340f9c6b017123 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 11 Aug 2023 00:49:15 +0000 Subject: [PATCH 18/21] fix-test: dropFullText items single and multiples --- tests/Database/Oci8SchemaGrammarTest.php | 48 ++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/tests/Database/Oci8SchemaGrammarTest.php b/tests/Database/Oci8SchemaGrammarTest.php index 9a69ff98..288ac0dd 100644 --- a/tests/Database/Oci8SchemaGrammarTest.php +++ b/tests/Database/Oci8SchemaGrammarTest.php @@ -381,6 +381,30 @@ public function testDropTimestamps() $this->assertEquals('alter table users drop ( created_at, updated_at )', $statements[0]); } + public function testSingleDropFullTextByIndex() + { + $blueprint = new Blueprint('users'); + $blueprint->dropFullText('name_index'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertEquals(1, count($statements)); + $this->assertEquals('drop index name_index', $statements[0]); + } + + public function testMultipleDropFullTextByColumns() + { + $blueprint = new Blueprint('users'); + $blueprint->dropFullText(['firstname', 'lastname']); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $expected = "begin for idx_rec in (select idx_name from ctx_user_indexes where idx_text_name in ('FIRSTNAME', 'LASTNAME')) loop + execute immediate 'drop index ' || idx_rec.idx_name; + end loop; end;"; + + $this->assertEquals(1, count($statements)); + $this->assertEquals($expected, $statements[0]); + } + public function testRenameTable() { $blueprint = new Blueprint('users'); @@ -487,15 +511,33 @@ public function testAddingIndex() $this->assertEquals('create index baz on users ( foo, bar )', $statements[0]); } - public function testAddingFullTextIndex() + public function testAddingMSingleColumnFullTextIndex() { $blueprint = new Blueprint('users'); - $blueprint->fullText(['firstname', 'lastname'], 'name'); + $blueprint->fullText(['name'], 'name'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $expected = "begin execute immediate 'create index name on users (name) indextype is + ctxsys.context parameters (''sync(on commit)'')'; end;"; + $this->assertEquals(1, count($statements)); + $this->assertEquals($expected, $statements[0]); + } + + public function testAddingMultipleColumnsFullTextIndex() + { + $blueprint = new Blueprint('users'); + $blueprint->fullText(['firstname', 'lastname'], 'name'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $expectedSql['firstnameIndex'] = "execute immediate 'create index name_0 on users (firstname) indextype is + ctxsys.context parameters (''datastore name_preference sync(on commit)'')';"; + $expectedSql['lastnameIndex'] = "execute immediate 'create index name_1 on users (lastname) indextype is + ctxsys.context parameters (''datastore name_preference sync(on commit)'')';"; + $expected = 'begin ' . implode(' ', $expectedSql) . ' end;'; - $this->assertEquals("create index name on users (firstname, lastname) indextype is ctxsys.context parameters ('sync(on commit)')", $statements[0]); + $this->assertEquals(1, count($statements)); + $this->assertEquals($expected, $statements[0]); } public function testAddingForeignKey() From 61bdcfdba05238b6ba0d722192886161273cd78b Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 11 Aug 2023 00:50:15 +0000 Subject: [PATCH 19/21] feat: dropFullText method implemented && fix fullText create single and multiples indexes --- src/Oci8/Schema/Grammars/OracleGrammar.php | 53 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/Oci8/Schema/Grammars/OracleGrammar.php b/src/Oci8/Schema/Grammars/OracleGrammar.php index e18e52bf..63b2a22f 100644 --- a/src/Oci8/Schema/Grammars/OracleGrammar.php +++ b/src/Oci8/Schema/Grammars/OracleGrammar.php @@ -315,13 +315,31 @@ public function compileIndex(Blueprint $blueprint, Fluent $command) */ public function compileFullText(Blueprint $blueprint, Fluent $command): string { - $indexName = $command->index; $tableName = $this->wrapTable($blueprint); - $columns = $this->columnize($command->columns); + $columns = $command->columns; + $indexBaseName = $command->index; + $preferenceName = $indexBaseName . '_preference'; - $query = "create index $indexName on $tableName ($columns) indextype is ctxsys.context parameters ('sync(on commit)')"; + $sqlStatements = []; - return $query; + foreach ($columns as $key => $column) { + $indexName = $indexBaseName; + $parametersIndex = ''; + + if (count($columns) > 1) { + $indexName .= "_{$key}"; + $parametersIndex = "datastore {$preferenceName} "; + } + + $parametersIndex .= 'sync(on commit)'; + + $sql = "execute immediate 'create index {$indexName} on $tableName ($column) indextype is + ctxsys.context parameters (''$parametersIndex'')';"; + + $sqlStatements[] = $sql; + } + + return 'begin ' . implode(' ', $sqlStatements) . ' end;'; } /** @@ -458,6 +476,33 @@ public function compileDropForeign(Blueprint $blueprint, Fluent $command) return $this->dropConstraint($blueprint, $command, 'foreign'); } + /** + * Compile a drop fulltext index command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropFullText(Blueprint $blueprint, Fluent $command): string + { + $columns = $command->columns; + + if (empty($columns)) { + return $this->compileDropIndex($blueprint, $command); + } + + $columns = array_map(function($column) { + return "'" . strtoupper($column) . "'"; + }, $columns); + $columns = implode(', ', $columns); + + $dropFullTextSql = "for idx_rec in (select idx_name from ctx_user_indexes where idx_text_name in ($columns)) loop + execute immediate 'drop index ' || idx_rec.idx_name; + end loop;"; + + return "begin $dropFullTextSql end;"; + } + /** * Compile a rename table command. * From 5fb284a018fdad219ee5246e3ae64eafef107188 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 11 Aug 2023 00:52:04 +0000 Subject: [PATCH 20/21] feat: ctxDdlPreferences attribute created to call modifications commands --- src/Oci8/Schema/OracleBuilder.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Oci8/Schema/OracleBuilder.php b/src/Oci8/Schema/OracleBuilder.php index 1b778909..91afb56e 100644 --- a/src/Oci8/Schema/OracleBuilder.php +++ b/src/Oci8/Schema/OracleBuilder.php @@ -18,6 +18,11 @@ class OracleBuilder extends Builder */ public $comment; + /** + * @var \Yajra\Oci8\Schema\OraclePreferences + */ + public $ctxDdlPreferences; + /** * @param Connection $connection */ @@ -26,6 +31,7 @@ public function __construct(Connection $connection) parent::__construct($connection); $this->helper = new OracleAutoIncrementHelper($connection); $this->comment = new Comment($connection); + $this->ctxDdlPreferences = new OraclePreferences($connection); } /** @@ -43,6 +49,8 @@ public function create($table, Closure $callback) $callback($blueprint); + $this->ctxDdlPreferences->createPreferences($blueprint); + $this->build($blueprint); $this->comment->setComments($blueprint); @@ -99,6 +107,7 @@ public function table($table, Closure $callback) public function drop($table) { $this->helper->dropAutoIncrementObjects($table); + $this->ctxDdlPreferences->dropPreferencesByTable($table); parent::drop($table); } @@ -109,6 +118,7 @@ public function drop($table) */ public function dropAllTables() { + $this->ctxDdlPreferences->dropAllPreferences(); $this->connection->statement($this->grammar->compileDropAllTables()); } @@ -121,6 +131,7 @@ public function dropAllTables() public function dropIfExists($table) { $this->helper->dropAutoIncrementObjects($table); + $this->ctxDdlPreferences->dropPreferencesByTable($table); parent::dropIfExists($table); } From 8272ef443cb5367ff26f69f91b3fe780555f4f22 Mon Sep 17 00:00:00 2001 From: Jonas Elias Date: Fri, 11 Aug 2023 01:17:37 +0000 Subject: [PATCH 21/21] fix-ci: style yajra/laravel-oci8 --- src/Oci8/Schema/Grammars/OracleGrammar.php | 8 +++---- src/Oci8/Schema/OraclePreferences.php | 26 +++++++++++----------- tests/Database/Oci8SchemaGrammarTest.php | 2 +- tests/Database/OraclePreferencesTest.php | 6 ++--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Oci8/Schema/Grammars/OracleGrammar.php b/src/Oci8/Schema/Grammars/OracleGrammar.php index 63b2a22f..5c6f34ca 100644 --- a/src/Oci8/Schema/Grammars/OracleGrammar.php +++ b/src/Oci8/Schema/Grammars/OracleGrammar.php @@ -318,7 +318,7 @@ public function compileFullText(Blueprint $blueprint, Fluent $command): string $tableName = $this->wrapTable($blueprint); $columns = $command->columns; $indexBaseName = $command->index; - $preferenceName = $indexBaseName . '_preference'; + $preferenceName = $indexBaseName.'_preference'; $sqlStatements = []; @@ -339,7 +339,7 @@ public function compileFullText(Blueprint $blueprint, Fluent $command): string $sqlStatements[] = $sql; } - return 'begin ' . implode(' ', $sqlStatements) . ' end;'; + return 'begin '.implode(' ', $sqlStatements).' end;'; } /** @@ -491,8 +491,8 @@ public function compileDropFullText(Blueprint $blueprint, Fluent $command): stri return $this->compileDropIndex($blueprint, $command); } - $columns = array_map(function($column) { - return "'" . strtoupper($column) . "'"; + $columns = array_map(function ($column) { + return "'".strtoupper($column)."'"; }, $columns); $columns = implode(', ', $columns); diff --git a/src/Oci8/Schema/OraclePreferences.php b/src/Oci8/Schema/OraclePreferences.php index 8d704f26..b146aca0 100644 --- a/src/Oci8/Schema/OraclePreferences.php +++ b/src/Oci8/Schema/OraclePreferences.php @@ -16,17 +16,17 @@ class OraclePreferences protected $connection; /** - * @var array $columns + * @var array */ protected array $columns = []; /** - * @var array $preferenceName + * @var array */ protected array $preferenceName = []; /** - * Constructor method + * Constructor method. * * @return void */ @@ -36,7 +36,7 @@ public function __construct(Connection $connection) } /** - * Create a preferences values to use in index fullText + * Create a preferences values to use in index fullText. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @return null @@ -47,7 +47,7 @@ public function createPreferences(Blueprint $blueprint): void $sql = $this->generateSqlCreatePreferences(); - if (!empty($sql)) { + if (! empty($sql)) { $this->connection->statement( "BEGIN $sql END;" ); @@ -55,7 +55,7 @@ public function createPreferences(Blueprint $blueprint): void } /** - * Generate script sql to create preferences + * Generate script sql to create preferences. * * @param ?string $objectNameOracle * @param ?string $attributeNameOracle @@ -79,7 +79,7 @@ protected function generateSqlCreatePreferences( } /** - * Set columns and preference name to class attributes + * Set columns and preference name to class attributes. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @return void @@ -90,15 +90,15 @@ public function setPreferenceFullText(Blueprint $blueprint): void $this->preferenceName = []; foreach ($blueprint->getCommands() as $value) { - if ($value['name'] === "fulltext" && count($value['columns']) > 1) { + if ($value['name'] === 'fulltext' && count($value['columns']) > 1) { $this->columns[] = $value['columns']; - $this->preferenceName[] = $value['index'] . '_preference'; + $this->preferenceName[] = $value['index'].'_preference'; } } } /** - * Format with "implode" function columns to use in preferences + * Format with "implode" function columns to use in preferences. * * @param array $columns * @return string @@ -109,7 +109,7 @@ protected function formatMultipleCtxColumns(array $columns): string } /** - * Drop preferences by specified table + * Drop preferences by specified table. * * @param string $table * @return void @@ -128,12 +128,12 @@ public function dropPreferencesByTable(string $table): void END;"; $this->connection->statement($sqlDropPreferencesByTable, [ - strtoupper($table) + strtoupper($table), ]); } /** - * Drop all user preferences + * Drop all user preferences. * * @return void */ diff --git a/tests/Database/Oci8SchemaGrammarTest.php b/tests/Database/Oci8SchemaGrammarTest.php index 288ac0dd..1de1d441 100644 --- a/tests/Database/Oci8SchemaGrammarTest.php +++ b/tests/Database/Oci8SchemaGrammarTest.php @@ -534,7 +534,7 @@ public function testAddingMultipleColumnsFullTextIndex() ctxsys.context parameters (''datastore name_preference sync(on commit)'')';"; $expectedSql['lastnameIndex'] = "execute immediate 'create index name_1 on users (lastname) indextype is ctxsys.context parameters (''datastore name_preference sync(on commit)'')';"; - $expected = 'begin ' . implode(' ', $expectedSql) . ' end;'; + $expected = 'begin '.implode(' ', $expectedSql).' end;'; $this->assertEquals(1, count($statements)); $this->assertEquals($expected, $statements[0]); diff --git a/tests/Database/OraclePreferencesTest.php b/tests/Database/OraclePreferencesTest.php index 47c78afd..2423a000 100644 --- a/tests/Database/OraclePreferencesTest.php +++ b/tests/Database/OraclePreferencesTest.php @@ -65,11 +65,11 @@ public function testCreatePreferencesWithOtherMultipleFullText() $preferences['product_preference'] = "ctx_ddl.create_preference('product_preference', 'MULTI_COLUMN_DATASTORE'); ctx_ddl.set_attribute('product_preference', 'COLUMNS', 'category, price');"; - $expected = 'BEGIN ' . implode(' ', $preferences) . ' END;'; + $expected = 'BEGIN '.implode(' ', $preferences).' END;'; $connection->shouldReceive('statement') - ->once() - ->andReturnUsing(function ($sql) use ($expected) { + ->once() + ->andReturnUsing(function ($sql) use ($expected) { $this->assertEquals($expected, $sql); });